Support Forum
Support › MB Custom Post Type › Fatal Error with PHP 8.2Resolved
Hi MetaBox Team,
I'm getting the following fatal error below when navigating to admin > settings > permalinks.
The error is only thrown when the Meta Box AIO plugin is enabled, when disabled it doesn't throw the error.
When I comment out the four lines of code at class-wp-rewrite.php on line 1036 that use the operand '&', then the error goes away and the permalink page works. Do you have any ideas why this might be happening?
[22-Nov-2023 20:44:06 UTC] PHP Fatal error: Uncaught TypeError: Unsupported operand types: string & int in /home/cust_path/wp-includes/class-wp-rewrite.php:1036
Stack trace:
#0 /home/cust_path/wp-includes/class-wp-rewrite.php(1410): WP_Rewrite->generate_rewrite_rules('/tool/%tool%', 'EP_PERMALINK', true, true, false, true, true)
#1 /home/cust_path/wp-includes/class-wp-rewrite.php(1509): WP_Rewrite->rewrite_rules()
#2 /home/cust_path/wp-includes/class-wp-rewrite.php(1493): WP_Rewrite->refresh_rewrite_rules()
#3 /home/cust_path/wp-includes/class-wp.php(163): WP_Rewrite->wp_rewrite_rules()
#4 /home/cust_path/wp-includes/class-wp.php(813): WP->parse_request('')
#5 /home/cust_path/wp-includes/functions.php(1336): WP->main('')
#6 /home/cust_path/wp-blog-header.php(16): wp()
#7 /home/cust_path/index.php(17): require('/home/...')
#8 {main}
thrown in /home/cust_path/wp-includes/class-wp-rewrite.php on line 1036
Thanks!
Hello,
If the issue relates to the plugin/extension MB Custom Post Type when registering the custom post type, can you please generate the PHP code and add it to the file functions.php in the theme or child theme folder and check this issue again? This extension helps you to register the post types, taxonomies with UI instead of using the WordPress function register_post_type()
.
Refer to the documentation
https://docs.metabox.io/extensions/meta-box-builder/#getting-php-code
https://developer.wordpress.org/reference/functions/register_post_type/
Hi Peter,
Thanks for the feedback! I tried using the code that the plugin generates in my functions.php but the code it generates is full of issues. For example some of the args generated are:
'editor' => block,
'custom_fields' => [object Object],
'custom-field-group' => [object Object],
Obviously none of those values are valid PHP types. Also why would the rest of the application work fine without adding that code to the functions.php?
This seems more like a PHP version issue. I'm not having the issue in PHP 7. It seems as though other plugins have faced similar issues.
I'm not really sure if the issue is related to the MB Custom Post Type extension, I just thought that might be the closest category I could correlate the issue to. Is it possible to have someone on the dev team take a quick peek at this to see if its a scenario where PHP 8 is the underlying cause?
Thanks~
Hi Peter,
Continuation from above thread... I also found this thread on you site as it looks like other MB users are running into the same issue. Do you recall if the dev team was able to isolate a fix on the MetaBox end?
Thanks
Hi Bluemoon75,
I replied in the other thread, I think it's useful to repost it here as I think it's related to your issue.
---
Regarding your issue, I think the problem was in the 2.6.x version of MB Custom Post Types & Custom Taxonomies plugin. We released version 2.6.0 which had a new feature to allow you to edit post types registered in WP core (like post and page) and post types registered by other plugins. The way it works is replicating those post types in the plugin's post type list, so you can edit them as usual.
I *guess* in your case, when you upgraded the plugin, it replicated some post types registered by other plugin. Those post types had some rewrite options that were available in MB Custom Post Types & Custom Taxonomies and caused the bug.
We reverted this feature in 2.6.2, but the replicated post types are still in the DB.
One way to resolve this is go to Post Types and remove all post types that were not created by you manually. The other way is what you did by updating the settings for them.
I hope this clarifies things and what happended behind the scene.
Hi Anh,
Thanks for the feedback!
Actually I just installed the plugin about 4-5 days ago, so I have not had a chance to upgrade yet. However I did use the toolset migrator to migrate the settings. So I'm assuming that would be equivalent to a type getting "registered" incorrectly? Below is a small snippet from the JSON export. I'm *assuming* that some of this data is probably incorrect?
"register_meta_box_cb": "",
"permalink_epmask": "EP_PERMALINK",
"update": false,
"_builtin": false,
"_toolset_edit_last": 1696873299,
"_wpcf_author_id": 2,
"wpcf-post-type": "tool",
"icon": "dashicons-database",
"editor": "block",
"custom_fields": {
"wpcf-ref-status": true,
"wpcf-ref-platform": true,
"wpcf-ref-admin-link": true
},
"custom-field-group": {
"6": true,
"1654": true,
"1695": true,
"1864": true
},
I see the entry for "wpcf-post-type" in the wp_options table as a serialized array. Am I able to just update the values in the array (if so which ones)? I know how the serialized arrays work with string key lengths so I can adjust accordingly without breaking things, or is it safer/easier to just delete the post type using the Meta Box Builder and re-create it without loosing any data.
Thanks again for your time!
Oh, I see. Looks like Toolset store JSON differently from us, and when import, we imported them all. Let me take a note on this to prevent same thing happening in the future.
> I see the entry for "wpcf-post-type" in the wp_options table as a serialized array.
It's from Toolset. We don't use wp_options
to store post type configs.
> is it safer/easier to just delete the post type using the Meta Box Builder and re-create it without loosing any data.
Yes, it's the safer and better way to deal with conflicts.
Thanks that worked! I removed the post type and readded it and that resolved the issue. This thread can be marked as resolved.
Cheers~