[wp-trac] [WordPress Trac] #37469: WP_Post_Type class causes fatal error for themes/plugins that cast post objects as stdClass

WordPress Trac noreply at wordpress.org
Tue Jul 26 15:40:41 UTC 2016


#37469: WP_Post_Type class causes fatal error for themes/plugins that cast post
objects as stdClass
-------------------------------+-----------------------------
 Reporter:  modernnerd         |      Owner:
     Type:  defect (bug)       |     Status:  new
 Priority:  normal             |  Milestone:  Awaiting Review
Component:  Posts, Post Types  |    Version:  trunk
 Severity:  normal             |   Keywords:
  Focuses:                     |
-------------------------------+-----------------------------
 In 4.6beta1 and onwards, the new WP_Post_Type class is causing a fatal
 error in the Genesis theme framework on all admin pages if the site has an
 active custom post type:

 {{{
 [26-Jul-2016 12:00:47 UTC] PHP Fatal error:  Uncaught TypeError: Argument
 1 passed to Genesis_Admin_CPT_Archive_Settings::__construct() must be an
 instance of stdClass, instance of WP_Post_Type given, called in
 /Users/nickcernis/www/trunk/wp-content/themes/genesis/lib/admin/menu.php
 on line 122 and defined in /Users/nickcernis/www/trunk/wp-
 content/themes/genesis/lib/admin/cpt-archive-settings.php:38
 Stack trace:
 #0 /Users/nickcernis/www/trunk/wp-
 content/themes/genesis/lib/admin/menu.php(122):
 Genesis_Admin_CPT_Archive_Settings->__construct(Object(WP_Post_Type))
 #1 /Users/nickcernis/www/trunk/wp-includes/plugin.php(524):
 genesis_add_cpt_archive_page('')
 #2 /Users/nickcernis/www/trunk/wp-admin/includes/menu.php(149):
 do_action('admin_menu', '')
 #3 /Users/nickcernis/www/trunk/wp-admin/menu.php(282):
 require_once('/Users/nickcern...')
 #4 /Users/nickcernis/www/trunk/wp-admin/admin.php(138):
 require('/Users/nickcern...')
 #5 /Users/nickcernis/www/trunk/wp-admin/plugins.php(10):
 require_once('/Users/nickcern...')
 #6 {main}
   thrown in /Users/nickcernis/www/trunk/wp-
 content/themes/genesis/lib/admin/cpt-archive-settings.php on line 38
 }}}

 This is because `get_post_type_object` now returns an instance of
 WP_Post_Type rather than the stdClass that Genesis previously expected.
 From `genesis/lib/admin/cpt-archive-settings.php` line 38:

 {{{
 public function __construct( stdClass $post_type ) {
 }}}

 At present, this will cause all sites running Genesis that have a custom
 post type active to white screen on admin pages when WordPress 4.6 is
 released.

 Steps to reproduce:

 <ol>
 <li>Install https://wordpress.org/plugins/wordpress-beta-tester/ and
 update to the latest nightly.
 <li>Activate Genesis or the Genesis Sample child theme.
 <li>Add some CPT boilerplate to functions.php: http://d.pr/n/LSYM+
 <li>Visit any admin page, which produces the fatal error.
 </ol>

 I am happy to share a copy of Genesis for testing purposes with any
 contributor that would like to help to review this.

 Reporting because — although this can be remedied in Genesis by not
 casting `$post_type` as an `stdClass` — this may also affect other themes
 and plugins that cast the type and do not expect that type to change. Am
 unsure if it is the responsibility of plugin/theme authors or WP core to
 fix this, so all advice is appreciated.

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


More information about the wp-trac mailing list