Make WordPress Core

Opened 9 years ago

Closed 8 years ago

Last modified 8 years ago

#33543 closed defect (bug) (fixed)

Featured image meta box absent due to Notices caused by missing labels

Reported by: bobbingwide's profile bobbingwide Owned by: sergeybiryukov's profile SergeyBiryukov
Milestone: 4.4 Priority: normal
Severity: normal Version: 4.3
Component: Posts, Post Types Keywords: has-patch commit
Focuses: Cc:


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.


  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,

Attachments (1)

33543.patch (1.9 KB) - added by SergeyBiryukov 8 years ago.

Download all attachments as: .zip

Change History (12)

#1 @bobbingwide
9 years ago

  • Summary changed from Problems when certain labels are not set for a post type to Featured image meta box absent due to Notices caused by missing labels

This ticket was mentioned in Slack in #core by bobbingwide. View the logs.

9 years ago

#3 @johnbillion
9 years ago

  • Keywords reporter-feedback added
  • Version changed from trunk to 4.3

How are you overriding the labels for the Post and Page post types?

For custom post types, if you only specify some of the labels then the remaining labels use the default values (see get_post_type_labels()).

#4 @bobbingwide
9 years ago

  • Keywords reporter-feedback removed

Hi John, in my particular case the override is done via a direct update to the post type definition using previously saved values loaded from the option table.
So I didn't have values for the new labels.

I could however have been misusing the "post_type_labels_{$post_type}" filter and deleting the fields from the array. You can use that method to recreate the problem.

#5 @SergeyBiryukov
8 years ago

  • Keywords has-patch commit added
  • Milestone changed from Awaiting Review to 4.4

Sounds like we need to merge filtered labels with the defaults using the same approach as in [32511].

See 33543.patch.

#6 @SergeyBiryukov
8 years ago

  • Owner set to SergeyBiryukov
  • Resolution set to fixed
  • Status changed from new to closed

In 33776:

In get_post_type_labels(), ensure that filtered labels contain all required default values.

fixes #33543.

#7 @bobbingwide
8 years ago

  • Resolution fixed deleted
  • Status changed from closed to reopened

Hi, the patch doesn't fix the problem originally reported.
It only caters for the naughty filter function.

Direct updates to global $wp_post_types can still be used to remove the labels.
So I will still have to use one or more of my workarounds.

My preferred solution is still required for routines which perform direct updates.

Please review this comment before re-closing.

#8 @SergeyBiryukov
8 years ago

Overriding the labels in $wp_post_types global directly for built-in post types doest not seem like a good practice, I think the notices are probably to be expected in that case.

#9 follow-up: @bobbingwide
8 years ago

But the notices lead to the Featured image meta-box no longer being displayed.
The code worked fine in 4.2, and was broken in 4.3.

As an aside, in my opinion, the setting up of labels is done far too early.
The fewer that are set at start up the better.
Not that I advocate deleting them once they've been defined.

Perhaps you should defer running the filter and the merge until needed in media.php?

Should there also be an array_merge after 'media_view_strings'?

#10 @wonderboymusic
8 years ago

  • Resolution set to fixed
  • Status changed from reopened to closed

Overriding the global directly voids your warranty. There is no way for us to observe mutations there.

#11 in reply to: ↑ 9 @SergeyBiryukov
8 years ago

Replying to bobbingwide:

Should there also be an array_merge after 'media_view_strings'?

I think it's unlikely for someone to reconstruct the whole array there from scratch, since it's much larger than the one with post labels.

Note: See TracTickets for help on using tickets.