[wp-trac] [WordPress Trac] #33543: Problems when certain labels are not set for a post type

WordPress Trac noreply at wordpress.org
Tue Aug 25 16:36:35 UTC 2015


#33543: Problems when certain labels are not set for a post type
-------------------------------+-----------------------------
 Reporter:  bobbingwide        |      Owner:
     Type:  defect (bug)       |     Status:  new
 Priority:  normal             |  Milestone:  Awaiting Review
Component:  Posts, Post Types  |    Version:  trunk
 Severity:  normal             |   Keywords:
  Focuses:                     |
-------------------------------+-----------------------------
 Related #19257

 I upgraded to WordPress 4.3 and started getting the following Notices when
 trying to edit or add new posts and pages.


 For pages...
 {{{
 Notice: Undefined property: stdClass::$featured_image in wp-
 includes\media.php on line 3084
 Notice: Undefined property: stdClass::$set_featured_image in wp-
 includes\media.php on line 3085
 }}}
 and for posts two more
 {{{
 Notice: Undefined property: stdClass::$featured_image in wp-admin\edit-
 form-advanced.php on line 223
 Notice: Undefined property: stdClass::$featured_image in wp-admin\edit-
 form-advanced.php on line 382
 }}}

 I tracked the problem down to some of my own code where I was overriding
 the definition of the post type.
 Since my labels array did not have entries for the new properties, the
 post_type_object no longer had values for these fields.

 The resulting effect were the Notices produced when WP_DEBUG was set to
 true
 which led to the Featured Image meta box not being shown.

 === Workarounds ===
 1. Don't override the labels when updating a post type
 2. Automagically create the missing labels
 3. Delete and recreate the post type override
 4. Set WP_DEBUG to false

 === Preferred solution ===
 Test for the existence of the property, rather than blindly assigning from
 the $post_type_object.
 {{{
 'setFeaturedImageTitle' => $post_type_object->labels->featured_image,
 'setFeaturedImage'      => $post_type_object->labels->set_featured_image,
 }}}

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


More information about the wp-trac mailing list