WordPress.org

Ready to get started?Download WordPress

Forums

Insert PHP
[resolved] Php code displaying in the output. (4 posts)

  1. nvijaya
    Member
    Posted 7 months ago #

    1. First of all, want to thank for giving such wonderful plugin.
    For me every thing worked fine except some issues.

    2. The set of i used in between [insert_php] and [/insert_php]-

    <p align="left">
    [insert_php]
    $name = get_post_custom_values('staff_name');
    $image = get_post_custom_values('staff_image');
    $info = get_post_custom_values('staff_info');
    $email = get_post_custom_values('staff_email');
    $contact = get_post_custom_values('staff_contact');
    foreach ( $image as $key => $value ) {
    echo $value;
    foreach ( $name as $key1 => $value ) {
    if($key == $key1){
    echo "<span class='staff_name'>".$value." "."| </span>";
    }
    foreach ( $info as $key2 => $value ) {
    if($key ==  $key1 && $key1 == $key2){
    echo "<span class='staff_info'>"." ".$value."</span><br />";
    }
    foreach ( $email as $key3 => $value ) {
    if($key == $key1 && $key1 == $key2 && $key2 == $key3){
    echo "<span class='staff_detail'><span style='font-weight:lighter;'>Email:</span>"." ".$value."<br />";
    }
    foreach ( $contact as $key4 => $value ) {
    if($key == $key1 && $key1 == $key2 && $key2 == $key3 && $key3 == $key4){
    echo "<span style='font-weight:lighter;'>Direct:</span>"." ".$value."</span><br /><br /><br /><br /><br /><br />";
    }
    }
    }
    }
    }
    }
    [/insert_php]
    </p>
    <div class="clear"></div>

    3. I am getting the correct output, but, at the end of the output i am getting php code also.Please help me out to solve this issue.

    http://wordpress.org/plugins/insert-php/

  2. WillBontrager
    Member
    Plugin Author

    Posted 7 months ago #

    nvijaya, the PHP code runs with errors.

    The PHP code used with Insert PHP needs to be able to run independently before it will run without errors within Insert PHP.

    If you put this into a file named test.php

    <?php
    $name = get_post_custom_values('staff_name');
    $image = get_post_custom_values('staff_image');
    $info = get_post_custom_values('staff_info');
    $email = get_post_custom_values('staff_email');
    $contact = get_post_custom_values('staff_contact');
    foreach ( $image as $key => $value ) {
    echo $value;
    foreach ( $name as $key1 => $value ) {
    if($key == $key1){
    echo "<span class='staff_name'>".$value." "."| </span>";
    }
    foreach ( $info as $key2 => $value ) {
    if($key ==  $key1 && $key1 == $key2){
    echo "<span class='staff_info'>"." ".$value."</span><br />";
    }
    foreach ( $email as $key3 => $value ) {
    if($key == $key1 && $key1 == $key2 && $key2 == $key3){
    echo "<span class='staff_detail'><span style='font-weight:lighter;'>Email:</span>"." ".$value."<br />";
    }
    foreach ( $contact as $key4 => $value ) {
    if($key == $key1 && $key1 == $key2 && $key2 == $key3 && $key3 == $key4){
    echo "<span style='font-weight:lighter;'>Direct:</span>"." ".$value."</span><br /><br /><br /><br /><br /><br />";
    }
    }
    }
    }
    }
    }
    ?>

    Then load test.php to your server and type its URL into your browser. You'll see what I mean.

    The error I noticed immediately is the code between the [insert_php][/insert_php] tags calls a function get_post_custom_values(). Yet, there is no such function available in the code between the [insert_php][/insert_php] tags.

    I think get_post_custom_values() is a WordPress function. Unfortunately, WordPress functions aren't available to PHP code between the [insert_php][/insert_php] tags.

    Intuitively, a person could think WordPress functions would be available for use here as they are available for use in WordPress plugins. But that's not the case. The code between [insert_php][/insert_php] tags is never made a part of the plugin. Instead, Insert PHP runs the code within an eval() statement.

    Once your PHP code runs independently on a page by itself, then it can be used with Insert PHP.

    Will

  3. nvijaya
    Member
    Posted 7 months ago #

    1. Thanks a lot for your immediate response.Yes, your right "get_post_custom_values()" is a wordpress function.And, also i tried to run the code independently,but, it won't.

    2. So, i tried to get the value through "Post" method of php.Now, everything works fine.

    3.Once again want to mention, very nice and compatable plugin.

  4. WillBontrager
    Member
    Plugin Author

    Posted 7 months ago #

    You're welcome, nvijaya. And thank you for your kind words.

    Will

Reply

You must log in to post.

About this Plugin

About this Topic