Need help fixing some PHP error

Can you please tell me what I need to do to fix this error. I have tried removing the initial php tag but got a worse error.
Parse error: syntax error, unexpected ‘<‘ in /home/mary/public_html/mary-content/plugins/insert-php/insert_php.php(48) : eval()’d code on line 1

just fyi there is another error, the same as the first but with syntax error, unexpected ‘&’ in /home/mary/public_html/mary-content/plugins/insert-php/insert_php.php(48)

FTP Access given in chat.

  • Panos
    • SLS

    Hello @mary!

    How are you doing ?

    This is comming from a plugin that allows to insert some php code in pages and posts. It provides a shortcode [insert_php] which can be used in any page/post in order to add your php.

    That shortcode calls the eval() function which is requores valid php code to be used and you should include the php tags ( <?php nor ?> )

    I see you already have the staff login enabled. Could please let us know in which blog in your multisite ( blog name or id would do ) and what page/post (again post title or id will do) you are using the shortcode? I am guessing that there is some invalid characters in the code and would like to have a closer look :slight_smile:

    Thanks!

  • Panos
    • SLS

    Hi Mary!

    Thanks for sending the links :slight_smile:

    WordPress editor adds some paragraph tags which are not visible from the Visual mode of the editor. They can be seen when switching to the Text(HTML) mode. I have removed all these extra tags and both pages seem ok now.

    Could you please check and let us know if they are good on your side too?

    Thanks!

  • Panos
    • SLS

    So sorry to hear you got issues with this again, and sorry I wasn't very clear on how to avoid getting such errors.

    As mentioned the code entered in the shortcode's content has to be valid php code. There are three possible reasons that result to invalid code.
    1st. The php code it's self has errors. There's nothing specific I can suggest here as each error can be different

    2nd. If you are copying code from a website the text may contain invalid characters. For example if you copy from this page https://codex.wordpress.org/Function_Reference/get_userdata the following:

    $user_info = get_userdata(1);
          echo 'Username: ' . $user_info->user_login . "\n";
          echo 'User roles: ' . implode(', ', $user_info->roles) . "\n";
          echo 'User ID: ' . $user_info->ID . "\n";

    and paste it directly to the WordPress editor it will be translated to:

    <pre>$user_info = get_userdata(1);
          echo 'Username: ' . $user_info->user_login . "\n";
          echo 'User roles: ' . implode(', ', $user_info->roles) . "\n";
          echo 'User ID: ' . $user_info->ID . "\n";</pre>

    Notice the <pre>and instead of $user_info->roles it has $user_info-& gt ;roles. This is invalid php code.

    Easiest way to avoid this is by pasting it to WP Editor's Text mode. Another way is to first paste this code to a text editor like notepad, then copy again and paste to WordPress Editor (again in Text mode).

    3rd. The WordPress editor may add new paragraphs when pasting it in the Visual mode. So in this case you'll need to use the Text mode.

    You can try find the issue on your own, by going to the page that has the issue and switch to editor mode like in the following screenshot:

    Then paste again the php code you need and check for errors.

    If you still have doubt or issue still insists please let us know and share page link again :slight_smile:

    Thanks!

  • Mary
    • Wisp of the WP Loop

    Thank you Panos. I quite understood the problem. The issue is that I had simply removed the extra blank lines at the bottom of the page, and saved it.

    By doing so I lost the correct code, so by copying and pasting into the Text Editor it didn't make a difference, because I was copying the corrupted code, and I didn't know what the correct code was.

    That's why I was asking what changes had been made to fix it so that if I forget and for some reason the same thing happens, I will know how to fix it.

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.