Warning: Illegal string offset ‘singular_name’ in class-post-type.php:215
-
I encountered this warning:
llegal string offset ‘singular_name’ in \wp-content\plugins\wpfront-user-role-editor\includes\post-type\class-post-type.php:215I looked to see why this was happening.
To do so, I looked at what $this->post_type_args[$post_type] looks like.
This is what I got:array ( 'label' => 'Vc Templates', 'public' => false, 'publicly_queryable' => false, 'exclude_from_search' => false, 'show_ui' => false, 'show_in_menu' => false, 'menu_position' => 10, 'menu_icon' => 'dashicons-admin-page', 'hierarchical' => false, 'taxonomies' => array ( ), 'has_archive' => false, 'rewrite' => false, 'query_var' => false, 'show_in_nav_menus' => false, )This post type is registered by the WPBakery Pagebuilder.
This appears to be the same data passed to the register_post_type function in /plugins/js_composer/include/classes/core/shared-templates/class-vc-shared-templates.php:150ff
Since the “labels” key is optional and so is its descendant “singular_name”, PHP has to create new entries and that seems to cause the warning.
I have changed the function as follows:
/** * Fetches the singular name after registration if it does not exist. WP does not supply it as part of the arguments. * * @param type $post_type * * @param type $post_type_object * @return type */ public function registered_post_type($post_type, $post_type_object) { if (empty($this->post_type_args[$post_type])) { return; } if (!empty($this->post_type_args[$post_type]['labels']['singular_name'])) { return; } else{ $this->post_type_args[$post_type] = ['labels' => ['singular_name' => $post_type_object->labels->singular_name]]; }Now the warning is gone and everything runs smoothly on my development system.
However, since my change would be overwritten in the next update of your plugin, I would like to ask you to check the problem and use the code I provided if necessary.Kind regards
Alexander Behling
The topic ‘Warning: Illegal string offset ‘singular_name’ in class-post-type.php:215’ is closed to new replies.