PMCS Caught Error: Undefined constant

  • Hello,

    I have a site using GP with polylang and some custom post types.
    For the second language, i have a white page when i load the site (here is the “main” site : https://www.saporissimo.fr/, and here is the second language : https://www.saporissimo.be/.)

    When i activate the wordpress logs, i get this error :
    PMCS Caught Error: Undefined constant “recettes” in /home/hliv2260/public_html/saporissimo/wp-content/plugins/gp-premium/elements/class-hooks.php(215) : eval()’d code on line 11
    recettes beeing a custom post type i created for the website.

    Any idea what causes the white page, and how i can fix it ?

    Thanks
    Best regards

  • Hi there,

    It looks like there may be an issue with the snippet added to the Hook Element. Could you share the full code you added there so we can check for any possible errors?

  • The problematic element seems to be that one :
    <?php
    global $post;
    $page_id = get_queried_object_id();

    global $wp_query;
    if ( $wp_query->is_tax || $wp_query->is_tag ) {
    if ( function_exists( ‘pll_current_language’ ) ) {
    $page_id = pll_get_term( $page_id, ‘fr’ );
    }
    $frpost = get_term_link($page_id);
    } elseif($wp_query->is_archive-recettes) {
    $frpost = ‘https://www.saporissimo.fr/recettes/&#8217;;
    } else {
    if ( function_exists( ‘pll_current_language’ ) ) {
    $page_id = pll_get_post( $page_id, ‘fr’ );
    }
    $frpost = get_the_permalink($page_id);
    }

    if($frpost) {
    echo ‘<link rel=”canonical” href=”‘.$frpost.'”>’;
    }
    ?>

    It used to work, but not anymore.
    Can we still use php in hook elements ?

  • Your code has some issues. Can you try replacing it with the code below?

    <?php
    $page_id = get_queried_object_id();
    $frpost = '';
    
    if ( is_tax() || is_tag() ) {
    
        if ( function_exists( 'pll_get_term' ) ) {
            $page_id = pll_get_term( $page_id, 'fr' );
        }
    
        if ( $page_id ) {
            $frpost = get_term_link( $page_id );
        }
    
    } elseif ( is_post_type_archive( 'recettes' ) ) {
    
        $frpost = 'https://www.saporissimo.fr/recettes/';
    
    } else {
    
        if ( function_exists( 'pll_get_post' ) ) {
            $page_id = pll_get_post( $page_id, 'fr' );
        }
    
        if ( $page_id ) {
            $frpost = get_permalink( $page_id );
        }
    }
    
    if ( ! empty( $frpost ) && ! is_wp_error( $frpost ) ) {
        echo '<link rel="canonical" href="' . esc_url( $frpost ) . '">' . "\n";
    }
    ?>
  • Hello Ying,

    Works like a charm, thanks for the feedback.

    Best regards

  • You are welcome   🙂

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