• Resolved JDDunn9

    (@jddunn9)


    I have a script that uses a GET variable. If there is no GET variable ( mysite.com/widget/ ) it displays what I would expect. If I do use it though, ( mysite.com/widget/?id=5 ) then it displays all the PHP code, including the [insert_php] parts. It also works fine if I use a made up GET name like mysite.com/widget/?madup=5.

    I put the code in the HTML section of the page, not the View part, and the PHP code works fine if I put it in it’s own file and execute it. Any idea what could be wrong?

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

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

    (@willbontrager)

    JDDunn9, post the code you are testing with. I’ll try to duplicate the issue.

    Will

    Thread Starter JDDunn9

    (@jddunn9)

    After further testing, it looks like it wasn’t the GET variable, it was the code executed if it was set. It looks like the code breaks if you try to use the increment operator “++”. For example, this code also breaks on me.

    $i = 0;
    $i++;

    Plugin Author WillBontrager

    (@willbontrager)

    Insert PHP uses the eval() function to run the PHP code between [insert_php] tags.

    When eval() runs, the code is subject to the environment it is running in, the rest of the WP code used to process the page. Which may be why the $_GET[‘id’] was misbehaving earlier. Don’t know without seeing the code you were using. I think id is used to determine which post to publish.

    I don’t know why $i is misbehaving. $ti works fine.

    [insert_php]
    $ti=0;
    $ti++;
    echo $ti;
    [/insert_php]

    Suggest trying a different variable name when the current one behaves different than expected.

    Will

    Plugin Author WillBontrager

    (@willbontrager)

    Gratuitous content so the system will accept the “resolved” checkbox.

    1. When i put my set of codes inbetween [insert_php][/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>
    “;
    }
    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.”
    “;
    }
    foreach ( $contact as $key4 => $value ) {
    if($key == $key1 && $key1 == $key2 && $key2 == $key3 && $key3 == $key4){
    echo “<span style=’font-weight:lighter;’>Direct:</span>”.” “.$value.”</span>

    “;
    }
    }
    }
    }
    }
    }
    [/insert_php]
    </p>
    <div class=”clear”></div>

    2. My output is coming correctly.But, the problem is along with my output, some codes are also displaying at the end.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Displays PHP Code’ is closed to new replies.