Bug: Admin Dashboard 2.2 Data, Call to undefined property breaks backend page

  • lukas
    Participant
    2 years ago #31154

    I`ve registered a bug for my configured wpsolr pro plugin instance. After first configuration on the data tab, the submit button and some additional options are missing. Here the error in the wordpress debug.log:

    [01-Oct-2022 18:14:16 UTC] PHP Fatal error:  Uncaught Error: Call to undefined method wpsolr\core\classes\models\taxonomy\WPSOLR_Model_Meta_Type_Taxonomy::has_attachments() in /var/www/html/wp-content/plugins/wpsolr-pro/wpsolr/core/dashboard/dashboard_settings.inc.php:662
    Stack trace:
    #0 /var/www/html/wp-content/plugins/wpsolr-pro/wpsolr/core/dashboard/dashboard.php(469): include()
    #1 /var/www/html/wp-includes/class-wp-hook.php(307): fun_set_solr_options('')
    #2 /var/www/html/wp-includes/class-wp-hook.php(331): WP_Hook->apply_filters('', Array)
    #3 /var/www/html/wp-includes/plugin.php(476): WP_Hook->do_action(Array)
    #4 /var/www/html/wp-admin/admin.php(259): do_action('toplevel_page_s...')
    #5 {main}
      thrown in /var/www/html/wp-content/plugins/wpsolr-pro/wpsolr/core/dashboard/dashboard_settings.inc.php on line 662

    As a quick fix for my self, I’ve extended the condition by checking for the property which is not available (wpsolr-pro/wpsolr/core/dashboard/dashboard_settings.inc.php:662).
    Has anyone noticed the same behaviour?

    wpsolr
    Keymaster
    2 years ago #31155

    This is strange, because it looks like a taxonomy has custom fields or taxonomies.

    This is the condition that had to be true to get to the error code line:

    $is_post_type = ! ( empty( $model_type_fields ) && empty( $model_type_taxonomies ) );
    if ($is_post_type) {
    ...
    $model_type_object->has_attachments()
    ...
    }
    wpsolr
    Keymaster
    2 years ago #31156

    I fixed the issue in WPSOLR 22.4. You can keep your workaround in the meantime.

    lukas
    Participant
    2 years ago #31158

    Maybe because taxonomies could be hierarchical? My custom taxonomy has acf fields, but thats not off standard.

    wpsolr
    Keymaster
    2 years ago #31159

    Both should not be an issue.
    If you can identify which taxonomy is causing the error, we could perhaps find the real problem.

    lukas
    Participant
    2 years ago #31160

    I debug a little bit further and come back with my taxonomy 😉

    wpsolr
    Keymaster
    2 years ago #31161

    Try to find which of $model_type_fields or $model_type_taxonomies is not empty, and what data it contains.

    lukas
    Participant
    2 years ago #31162

    I’m a little bit confused, because almost every entity doesn’t has the property has_attachments (post types) but just one taxonomy (the last one) triggers a fatal error. Here the configuration in my theme:

    $args = [
    		'hierarchical'      => false,
    		'labels'            => [
    			'name'              => _x( 'Magazin Ausgaben', 'taxonomy general name', 'r' ),
    			'singular_name'     => _x( 'Magazin Ausgabe', 'taxonomy singular name', 'r' ),
    		],
    		'show_ui'           => true,
    		'show_admin_column' => true,
    		'query_var'         => true,
    		'rewrite'           => [
    			'with_front' => false,
    			'hierarchical' => false,
    		],
    	];
    	register_taxonomy( 'magazine', [ 'post' ], $args );

    While debugging this taxonomy, the following variables has values:

    $model_type_object => wpsolr\core\classes\models\taxonomy\WPSOLR_Model_Meta_Type_Taxonomy {#13554 ▼
      #label: "Magazin Ausgaben"
      #table_name: "term_taxonomy"
      #column_id: "term_id"
      #column_last_updated: null
      #indexing_sql: null
      #type: "magazine"
    }
    $model_type_taxonomies => array:1 [▼
      0 => "location"
    ]

    $model_type_fields => []
    Is there anything not as expected?

    lukas
    Participant
    2 years ago #31163

    Some of my taxonomies has “shared post types” they relate to one ore more post types.

    wpsolr
    Keymaster
    2 years ago #31164

    Is “magazine” the taxonomy with issue?

    lukas
    Participant
    2 years ago #31165

    Right, seems like that.

    lukas
    Participant
    2 years ago #31166

    But the code should break at the first default post type “post”. Every object before hasn’t the property. So its a bit strange …

    wpsolr
    Keymaster
    2 years ago #31168

    If it is a taxonomies, how can it have taxonomies?

    $model_type_taxonomies => array:1 [▼
    0 => “location”
    ]

    ($model_type_taxonomies is calculated with get_object_taxonomies(), whom first argument is a post type)

    Just silly, but you would not have a post type with the same slug as a taxonomy?

    lukas
    Participant
    2 years ago #31172

    No, I just have this taxonomy registered as above, no post type with this name.

    lukas
    Participant
    2 years ago #31174

    I found the problem. I’ve registered my taxonomy as a taxonomy for the taxonomy “location”. WordPress doesn’t check the taxonomy post type handlers again, so get_object_taxonomies matched. Thank you for your hint 😉
    Its fixed, but the extra check in dashboard.php isn’t bad to keep the backend functional.

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

You must be logged in to reply to this topic.