Site logo

[Resolved] eval() d code 5 error within element hook

Home Forums Support [Resolved] eval() d code 5 error within element hook

Home Forums Support eval() d code 5 error within element hook

Viewing 15 posts - 1 through 15 (of 29 total)
  • Author
    Posts
  • #1296596
    Steve

    Hi, I recently received great advise on here regarding how to use GP element hooks to create a wrapper around page content. Within this hook I had to include a shortcode which for some reason didn’t fire with just the execute shortcode option selected so I used an action in functions.php and it then worked.

    However, I’m not convinced it’s resolving fully as I receive an eval()’d code: 5 error ‘Trying to get property of non-object’. I used an advanced custom field to place the shortcode dynamically into each page and have this code included within the hook itself:

    <?php
    	    $page = get_page_by_path('my-slug');
    get_field('mixcloud_playlist_code', $page->ID);
    	?>

    I’m pretty sure I found this snippet on the ACF website but cannot seem to re-find it now. My hunch is the ‘my-slug’ part is not fully resolving. I tried changing it to $page = get_page_by_path($page_slug);but that doesn’t seem to work either.

    Just as an aside; the mixcloud FooterWidget player functionality works as intended only in Firefox. In Chrome & Safari it shows this error and I suspect this issue may be the problem for them.

    Any advise would be much appreciated.

    #1296964
    Tom
    Lead Developer
    Lead Developer

    Hi there,

    When you do this: $page->ID

    You assume that $page is an object. In this case, it’s not, which is why you’re seeing an error.

    Try this:

    $page = get_page_by_path('my-slug');
    
    if ( is_object( $page ) ) {
        get_field('mixcloud_playlist_code', $page->ID);
    }
    #1297090
    Steve

    Thank you for the speedy response, Tom!
    When I used that I lost the output of the mixcloud shortcode contained within the ACF. I thought I’d solved it by using:

           
    	$page = get_page_by_path('my-slug');
             if (is_singular ( 'dj' )) {
            get_field('mixcloud_playlist_code', $page->ID);
            }

    which references the custom post type but then realised it still threw the same error.
    Any other suggestions?

    #1297304
    Tom
    Lead Developer
    Lead Developer

    You could try this:

    $page = get_page_by_path('my-slug');
    $page_id = is_object( $page ) ? $page->ID : '';
    
    get_field('mixcloud_playlist_code', $page_id);
    #1297324
    Steve

    Thank you, Tom. That fixed it 🙂

    #1297337
    Tom
    Lead Developer
    Lead Developer

    You’re welcome 🙂

    #1313819
    Steve

    Hi Tom, out of nowhere today, my shortcode contained within the ACF has stopped parsing. I validated the shortcode itself outside of the ACF and that works fine. The output I’m now seeing on each page is your code above so am thinking possibly something may have changed with this? Would it be possible to take a quick look? Much appreciated. I al;so have this code in my functions.php:

    function my_acf_format_value( $value, $post_id, $field ) {
        // Render shortcodes in all textarea values.
        return do_shortcode( $value );
    }
    // Apply to fields named "mixcloud_playlist_code".
    add_filter('acf/format_value/name=mixcloud_playlist_code', 'my_acf_format_value', 10, 3);
    #1313903
    David
    Staff
    Customer Support

    Hi there,

    can you check that the Hook is still executing PHP ?

    #1313964
    Steve

    Hi David, I’ve just checked the PHP error log and see this:
    PHP Notice: Constant DISALLOW_FILE_MODS already defined in /var/www/vhosts/mysite.uk/httpdocs/wp-includes/functions.php on line 9
    Just prior to that I was attempting to import a group of users using the Cimy User Management plugin with threw an error of:
    PHP Notice: Undefined index: db_sort_by in /var/www/vhosts/mysite.uk/httpdocs/wp-content/plugins/cimy-user-manager/cimy_user_manager.php on line 353
    Do you suppose this may have an effect on the PHP in my hooks?
    Here’s a grab of the console for the page. It does appear as if the second part of the PHP is not firing:

    #1314539
    Tom
    Lead Developer
    Lead Developer

    Yea, that looks like something is preventing the PHP from executing on the front-end. It could have to do with the DISALLOW_FILE_MODS notice you’re seeing there.

    #1315069
    Steve

    I’ve done a lot of reading on this issue since yesterday and as yet cannot fathom where to look for the bad code. Has anyone else experienced this or know of a plugin I could use to investigate in more detail?

    #1315207
    Steve

    Just as a footnote; I thought to clear the PHP error log. When I then reload the page in question I don’t see any new errors in the log but the PHP doesn’t fire in the hook. As you can see in the screengrab from the console output, something is commenting out the first part of the PHP code. Does anyone have any ideas as to what could be doing this?

    #1315392
    Steve

    So, I’ve now done a few things:

    Upgraded server to run PHP 7.3.18
    Created a test page with just the shortcode & that works.
    Then created a Hook with a simple PHP test code. That didn’t work and has the same commenting out of the PHP code.

    Does this not indicate the issue is related directly to the GP Hooks?

    #1315419
    David
    Staff
    Customer Support

    Looking at the DISALLOW_FILE_MODS that Tom pointed out – its says that this is already being declared in your root functions.php:

    PHP Notice: Constant DISALLOW_FILE_MODS already defined in /var/www/vhosts/mysite.uk/httpdocs/wp-includes/functions.php on line 9

    If you’re site has a function that is disallowing file mods then the Hook will not execute PHP.

    #1315517
    Steve

    I’ve just downloaded all plugins and performed a search for DISALLOW_FILE_MODS. It came back with 7 mentions of the words in 3 files in Jetpack but no declarations. I tried disabling Jetpack but the error is still there. Is there any other way I can run a test or scan my WordPress install for this?

Viewing 15 posts - 1 through 15 (of 29 total)
  • The topic ‘eval() d code 5 error within element hook’ is closed to new replies.