Function in admin_cols throws PHP error on custom post type list
herrschuessler opened this issue · 5 comments
I have a taxonomy assigned to a custom post type with a custom admin_cols function, like this:
register_extended_taxonomy(
'tax_x',
[ 'cpt_x' ],
[
'public' => true,
'hierarchical' => true,
'admin_cols' => [
'my_column' => [
'title' => 'My Function',
'function' => function( $term_id ) {
// Do something ...
},
],
],
],
);
The custom column shows up on the taxonomy listing in the admin area, but when I open the post type listing for the corresponding post typ, I get the PHP error (via Query Monitor): Uncaught Exception: Serialization of 'Closure' is not allowed – wp-includes/class-wp-object-cache.php:465
, and when editing a custom post, the taxonomy meta box is not showing in the block editor.
The error disapears after removing the my_column
part from above.
Edit: The meta box not showing was due to missing the meta_box
key in the arguments, sorry.
Can you get a full stack trace for that error please? This should be available from your PHP error log file, or by installing Xdebug.
Cheers!
Sorry, should have done that in the first place. Looking at the stack trace, it looks like the problem is related to Debug Bar.
[07-Jun-2021 08:13:19 UTC] PHP Fatal error: Uncaught Exception: Serialization of 'Closure' is not allowed in /wp-includes/class-wp-object-cache.php:465
Stack trace:
#0 /wp-includes/class-wp-object-cache.php(465): serialize(Array)
#1 /wp-content/plugins/debug-bar/panels/class-debug-bar-object-cache.php(18): WP_Object_Cache->stats()
#2 /wp-content/plugins/debug-bar/debug-bar.php(370): Debug_Bar_Object_Cache->render()
#3 /wp-includes/class-wp-hook.php(292): Debug_Bar->render('')
#4 /wp-includes/class-wp-hook.php(316): WP_Hook->apply_filters(NULL, Array)
#5 /wp-includes/plugin.php(484): WP_Hook->do_action(Array)
#6 /wp-admin/admin-footer.php(78): do_action('admin_footer', '')
#7 /wp-admin/edit.php(489): require_once('/www/htdocs/...')
#8 {main}
thrown in /wp-includes/class-wp-object-cache.php on line 465
After disabling that plugin, the error goes away. Sorry again for not checking that.
I've done some testing and I'm unable to reproduce this problem, but judging by the stack trace I'd say this is a problem in Debug Bar where it's trying to serialize a closure.
@herrschuessler A long time ago, but just wondered if you found solution to this? as I'm getting the same.