[Resolved] Warning: Undefined variable $post

Home Forums Support [Resolved] Warning: Undefined variable $post

Home Forums Support Warning: Undefined variable $post

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #2158561
    John

    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

    #2158569
    Fernando
    Customer Support

    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. 🙂

    #2158948
    John

    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

    #2158956
    David
    Staff
    Customer Support

    Hi there,

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

    #2158963
    John

    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>
    #2158982
    David
    Staff
    Customer Support

    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;

    #2159090
    John

    You da man David, thanks a ton 🙂
    Problem resolved

    #2159092
    David
    Staff
    Customer Support
Viewing 8 posts - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.