rankmath / seo-by-rank-math

Rank Math is a revolutionary WordPress SEO Plugin that combines the features of many SEO tools and lets you multiply your traffic in the easiest way possible :bulb: :chart_with_upwards_trend: →
https://rankmath.com
107 stars 52 forks source link

Fatal error: Uncaught Error: Attempt to assign property "labels" on bool #99

Closed alexsancho closed 2 years ago

alexsancho commented 2 years ago

There's a problem behind the logic that adds the admin menu, you can reproduce the problem installing Captivate Sync™ plugin, this plugin uses a wordpress page as cpt archive and modifies the wp_query to return is_archive as true, in this case Rank Math detects the page as term archive and the function add_taxonomy_menu tries to get taxonomy labels from queried object, this generates a fatal error because the queried object is a page.

I've suggest to check the queried object before trying to access an invalid property, something like this should work

`

/**
 * Add taxonomy menu
 */
private function add_taxonomy_menu() {
    $term = get_queried_object();
        if ( empty( $term ) ) {
            return;
        }

    if($term instanceof \WP_Term) {
        $labels = get_taxonomy_labels( get_taxonomy( $term->taxonomy ) );
        $this->add_sub_menu(
            'tax',
            [
                /* translators: Taxonomy Singular Name */
                'title'    => sprintf( esc_html__( 'SEO Settings for %s', 'rank-math' ), $labels->name ),
                'href'     => Helper::get_admin_url( 'options-titles#setting-panel-taxonomy-' . $term->taxonomy ),
                'meta'     => [ 'title' => esc_html__( 'Edit SEO settings for this archive page', 'rank-math' ) ],
                'priority' => 35,
            ]
        );
    }
}

`

pratikrm commented 2 years ago

Closing this issue as it is fixed in v1.0.78