[Resolved] PHP Notices

Home Forums Support PHP Notices

This topic contains 17 replies, has 3 voices, and was last updated by  Tom 2 days, 1 hour ago.

Viewing 15 posts - 1 through 15 (of 18 total)
  • Author
    Posts
  • #1090915

    Kim

    Hi there, I just saw in the log that we get a bunch of those notices:

    [03-Dec-2019 05:01:43 UTC] PHP Notice: Trying to get property ‘ID’ of non-object in /home/wp/disk/wordpress/wp-content/plugins/gp-premium/elements/class-hooks.php(180) : eval()’d code on line 2
    [03-Dec-2019 05:01:43 UTC] PHP Notice: Undefined variable: post in /home/wp/disk/wordpress/wp-content/plugins/gp-premium/elements/class-hooks.php(180) : eval()’d code on line 2

    Is this something to worry about? Anything I can do?

    Many thanks in advance!

    #1091270

    David Customer Support

    Hi there,

    do you have any PHP functions in the GP Hooks Element?

    #1092134

    Kim

    Yes, I do. I think the issue is coming from this one:

    <div class="wpsp-related-posts grid-container">
    	<h3>Das könnte Sie auch interessieren</h3>
    <?php
    if ( is_single() ) {
        $cats =  get_the_category();
        $cat = $cats[0];
    } else {
        $cat = get_category( get_query_var( 'cat' ) );
    }
    
    $cat_slug = $cat->slug;
    $list = get_page_by_title( 'related', 'OBJECT', 'wp_show_posts' );
    wpsp_display( $list->ID, 'tax_term="' . $cat_slug . '"' );
    ?>
    </div>

    I use it to show related posts at the single blog pages. It’s from the forum.

    #1092139

    Kim

    …or this one:

    <?php 
    $terms = get_the_terms( $post->ID, 'product_cat' );
    if ( $terms && ! is_wp_error( $terms ) ) :
        if ( ! empty( $terms ) ) {
            echo '<span class="woo-custom-category">' . $terms[0]->name . '</span>';
        }?>
    <?php endif;?>

    It’s used to display the Categories of a product on archive pages.

    #1092308

    David Customer Support

    I would think the second one is the issue – simplest way is to Quick Edit the element and Save as Draft and see if the notice disappears.

    #1092546

    Kim

    Yes, the second one is causing the issue. Do you have any clue what could be the reason? It’s from this post:

    https://generatepress.com/forums/topic/woocommerce-display-category-name-above-product-titel/

    #1093464

    David Customer Support

    Can you try changing this line:

    if ( ! empty( $terms ) ) {

    for:

    if ( isset( $terms ) ) {

    #1095316

    Kim

    Hi David, unfortunately this doesn’t solve the issue. Do you have another idea?

    #1096146

    Tom Lead Developer

    Can you try replacing this:

    wpsp_display( $list->ID, 'tax_term="' . $cat_slug . '"' );

    With this:

    if ( is_object( $list ) ) {
        wpsp_display( $list->ID, 'tax_term="' . $cat_slug . '"' );
    }

    I’m not seeing a $post variable (as per the second notice) – maybe a different hook?

    #1096200

    Kim

    Hi Tom, I’ve tested again and it is definitely coming from this one:

    <?php 
    $terms = get_the_terms( $post->ID, 'product_cat' );
    if ( $terms && ! is_wp_error( $terms ) ) :
        if ( isset( $terms ) ) {
            echo '<span class="woo-custom-category">' . $terms[0]->name . '</span>';
        }?>
    <?php endif;?>
    #1096590

    Tom Lead Developer

    So there you’re using $post, but it’s not defined.

    You can do this instead:

    <?php 
    $terms = get_the_terms( get_the_ID(), 'product_cat' );
    if ( $terms && ! is_wp_error( $terms ) ) :
        if ( isset( $terms ) ) {
            echo '<span class="woo-custom-category">' . $terms[0]->name . '</span>';
        }?>
    <?php endif;?>
    #1096801

    Kim

    Thank very much your for the fix 🙂

    #1096804

    Kim

    Sorry for asking again. This is another issue I just saw:

    PHP message: PHP Warning: array_key_exists() expects parameter 2 to be array, bool given in /home/wp/disk/wordpress/wp-content/plugins/gp-premium/typography/functions/migration.php on line 170

    Is it Theme-related or a Hosting issue?

    Best regards!

    #1097164

    Tom Lead Developer

    Hmm, I’m assuming it’s a hosting issue as no one else is experiencing that issue. Parameter 2 in that case should definitely be an array.

    Are you using the generate_number_of_fonts anywhere?

    #1097249

    Kim

    No, actually this one is not in use

Viewing 15 posts - 1 through 15 (of 18 total)

You must be logged in to reply to this topic.