• Resolved jamieComerford

    (@jamiecomerford)


    Hi there

    i am relatively new to php and server side scripting. I am trying to include an if/if else statement in of my pages on my wordpress website.

    i am using the replacement shortcode ‘[insert_php]’ and ‘[/insert_php]’ instead of the php beginning header and footer.

    What i would like to do is get the current users username and then just display some text if it is==’admin’. If the user name is==’volunteer’ display some other text.

    What i have so far is:

    [insert_php]
    $current_user=wp_get_current_user();
    echo $current_user->user_login . ‘
    ‘;
    [/insert_php]

    This just displays the username of the user logged in but how do i include an if/if else statement? I have tried multiple iterations such as below with no success.

    [insert_php]
    $current_user=wp_get_current_user();
    [/insert_php]
    [insert_php]
    if($current_user==’admin’) :
    echo $current_user->user_login . ‘
    ‘;
    endif;
    [/insert_php]

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

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

    (@willbontrager)

    The PHP code works with the plugin only when it isn’t broken up. In other words, it needs to be all one block of PHP code, complete in itself.

    The reason is because the code between the [insert_php] and [/insert_php] markers are processed separately, unlike a regular PHP page where the entire page is scanned and processed.

    This works:

    [insert_php]
    if(true) {
    echo "other stuff";
    }
    [/insert_php]

    But this, because each chunk isn’t complete in itself, will not work within the PHP plugin.

    [insert_php] if(true): [/insert_php]
    other stuff
    [insert_php] endif;[/insert_php]

    And neither will this work.

    [insert_php]
    if(true){
    [/insert_php]
    other stuff
    [insert_php]
    }
    [/insert_php]

    Insert PHP will successfully process only PHP code complete within itself between [insert_php] and [/insert_php] markers.

    Will

    Plugin Author WillBontrager

    (@willbontrager)

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

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘If statement’ is closed to new replies.