[Resolved] Fatal error when previewing a post after saving as draft

Home Forums Support [Resolved] Fatal error when previewing a post after saving as draft

Home Forums Support Fatal error when previewing a post after saving as draft

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #1402987
    Steven

    Haven’t run into this before today. Not sure what changed. We did quite a bit of testing before, but it seems it might be related to previewing a post before it’s published.

    Fatal error: Uncaught Error: syntax error, unexpected ‘s’ (T_STRING)
    in /nas/content/live/bhamprod/wp-content/plugins/gp-premium/elements/class-hooks.php(196) : eval()’d code on line 3

    Call stack:

    GeneratePress_Hook::execute_hook()
    wp-includes/class-wp-hook.php:287
    WP_Hook::apply_filters()
    wp-includes/class-wp-hook.php:311
    WP_Hook::do_action()
    wp-includes/plugin.php:478
    do_action()
    wp-content/themes/generatepress/single.php:22
    include()
    wp-includes/template-loader.php:106
    require_once()
    wp-blog-header.php:19
    require()
    index.php:17

    #1402990
    Leo
    Staff
    Customer Support

    Hi there,

    Looks like there is a code error in one of the hook element.

    Can you try disabling them first?

    #1403126
    Steven

    Thanks for the lead, Leo. We’ve narrowed it down to the following element:

    Hook = generate_before_main_content
    Execute shortcodes = selected
    Execute PHP = selected

    <?php 
    $start = '<div id="cob-breadcrumb-header" aria-label="You are here breadcrumb navigation"><i class="fas fa-home"></i> ';
    $breadcrumb = '(wpseo_breadcrumb) //placing parenthesis instead of brackets as support forum won't allow shortcodes';
    $breadcrumb = htmlentities($breadcrumb);
    $end = '</div>';
    
    if ( generate_show_title()) {
         echo $start . $breadcrumb .  $end ;
    }
    ?>

    When a post category includes an apostrophe (e.g. Mayor’s Office), the fatal error occurs. When there’s no apostrophe, the element works as expected. We tried adding the htmlentities to the $breadcrumb variable to try to deal with the apostrophe, but it didn’t seem to make a difference.

    If we’re understanding the error message correctly, the following section is where it’s getting hung up in class-hooks.php:

    if ( $this->php && GeneratePress_Elements_Helper::should_execute_php() ) {
    			ob_start();
    			eval( '?>' . $content . '<?php ' ); // phpcs:ignore -- Using eval() to execute PHP.
    			echo ob_get_clean(); // phpcs:ignore -- Escaping not necessary.
    		} else {
    			echo $content; // phpcs:ignore -- Escaping not necessary.
    		}
    
    	}

    Here’s a link to our dev site so you can continue to see the error since we need to remove the link originally added to this topic as it’s on our production site.

    #1403134
    Steven

    Here’s an example of a post without the apostrophe in its category if that helps:

    https://bhamdev.wpengine.com/news/2020/enjoy-late-summer-days-with-bellingham-parks-recreation-programs

    #1403173
    Tom
    Lead Developer
    Lead Developer

    Try this, instead:

    <?php 
    $start = '<div id="cob-breadcrumb-header" aria-label="You are here breadcrumb navigation"><i class="fas fa-home"></i> ';
    $end = '</div>';
    
    if ( generate_show_title()) {
         echo $start . do_shortcode( '(wpseo_breadcrumb)' ) .  $end ; //placing parenthesis instead of brackets as support forum won't allow shortcodes
    }
    ?>

    Then un-check the Execute Shortcodes option.

    #1403254
    Steven

    That did the trick – THANK YOU!

    #1403307
    Tom
    Lead Developer
    Lead Developer

    You’re welcome 🙂

Viewing 7 posts - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.