Archived topic
Fatal error when previewing a post after saving as draft
6 replies · Started by Steven on August 14, 2020
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
Hi there,
Looks like there is a code error in one of the hook element.
Can you try disabling them first?
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.
Here's an example of a post without the apostrophe in its category if that helps:
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.
That did the trick - THANK YOU!
You're welcome :)