[wp-trac] [WordPress Trac] #30960: Error in taxonomy.php - serialization of closure not allwed

WordPress Trac noreply at wordpress.org
Fri Jan 9 00:37:36 UTC 2015


#30960: Error in taxonomy.php - serialization of closure not allwed
---------------------------+-----------------------------
 Reporter:  stracker.phil  |      Owner:
     Type:  defect (bug)   |     Status:  new
 Priority:  normal         |  Milestone:  Awaiting Review
Component:  General        |    Version:  4.1
 Severity:  normal         |   Keywords:
  Focuses:                 |
---------------------------+-----------------------------
 Error:

 '''Fatal Error: Uncaught Exception 'exception' With Message 'serialization
 Of 'closure' Is Not Allowed' In Wp-includes/taxonomy.php On Line 1673'''


 ----

 I could not create a code snippet to reproduce the error, however on my
 website it happens when these 3 factors are combined:

 1) A custom Post-Type is defined that uses a closure, i.e. this is my
 code:

 {{{
 $type = 'posttype';
 $data = array( ... );

 $data['register_meta_box_cb'] = function( $post ) use ( $type ) {
         do_action( 'my-metaboxes-' . $type, $post );
 };
 register_post_type( $type, $data );
 }}}

 2) The action "pre_get_posts" calls the function "get_categories()", i.e.:

 {{{
 add_action( 'pre_get_posts', 'check_type' );
 public function check_type() {
         $items = get_categories( 'get=all' );
 }
 }}}

 3) When opening the Archive page of the custom post type the above error
 is displayed, i.e. "example.org/posttype/"

 ----

 Proposed solution:

 The file taxonomy.php line 1673 contains
 {{{
 serialize($GLOBALS['wp_filter']['list_terms_exclusions'])
 }}}

 The error is fixed by using {{{json_encode()}}} instead of
 {{{serialize()}}}

--
Ticket URL: <https://core.trac.wordpress.org/ticket/30960>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list