WordPress.org

Support

Support » Plugins and Hacks » Insert PHP » [Resolved] Php code displaying in the output.

[Resolved] Php code displaying in the output.

  • 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/

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author WillBontrager

    @willbontrager

    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

    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.

    Plugin Author WillBontrager

    @willbontrager

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

    Will

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘[Resolved] Php code displaying in the output.’ is closed to new replies.
Skip to toolbar