Site logo

Archived topic

Warning: Undefined variable $post

7 replies · Started by John on March 17, 2022

Viewing posts 1–8 of 8

Hi there,
since the last WP update I get this warning/error underneath the posts.

Warning: Undefined variable $post in ****************/wp-content/plugins/gp-premium/elements/class-hooks.php(215) : eval()'d code on line 3

Warning: Attempt to read property "ID" on null in ****************wp-content/plugins/gp-premium/elements/class-hooks.php(215) : eval()'d code on line 3

screenshot

Hi John,

I can see that you have custom functions in Hook Elements. One of them maybe causing the issue.

To determine the cause, can you try disabling your Hook Elements one by one starting with ones with functions and see if the issue will still exist?

Kindly let us know how it goes. :)

Hi Fernando :)

thanks a bunch for your input and advice. Indeed, it was the custom Hook for them Sharing buttons.
Would it possible to share the code with you in order to help me to identify the conflict?

Thanks in advance for your time & effort, is greatly appreciated
John

Hi there,

for sure - paste the code in your next reply, and before submitting - highlight the code and click the Code button.

Hi David,

thanks for chiming in :)

<?php /* Template for share buttons. */
$title = htmlspecialchars(urlencode(html_entity_decode(get_the_title())));
$url = urlencode(get_permalink($post->ID));?>
<div class="share-buttons clearfix">
	<a class="facebook" href="#" onclick="window.open('https://www.facebook.com/sharer.php?u=<?php echo $url; ?>&t=<?php echo $title; ?>', 'facebookShare', 'width=626,height=436'); return false;" title="<?php esc_html_e('Κοινοποιήστε στο Facebook'); ?>">
		<span class="share-button"><i class="fab fa-facebook-f"></i></span>
	</a>
	<a class="twitter" href="#" onclick="window.open('https://twitter.com/share?text=<?php echo $title; ?>:&url=<?php echo $url; ?>', 'twitterShare', 'width=626,height=436'); return false;" title="<?php esc_html_e('Τιτιβήστε'); ?>">
		<span class="share-button"><i class="fab fa-twitter"></i></span>
	</a>
			<a class="email" href="mailto:?subject=<?php echo htmlspecialchars(rawurlencode(html_entity_decode(get_the_title()))); ?>&body=<?php echo $url; ?>" title="<?php esc_html_e('Αποστολή μέσω email', ); ?>" target="_blank">
		<span class="share-button"><i class="far fa-envelope"></i></span>
	</a></div>

You need to declare the global variable for the $post - so before this line:

$title = htmlspecialchars(urlencode(html_entity_decode(get_the_title())));

add:

global $post;

You da man David, thanks a ton :)
Problem resolved

Glad to hear that!

This archived topic is closed to new replies.