Make WordPress Core

Opened 5 years ago

Closed 5 years ago

#24034 closed defect (bug) (fixed)

Filtering show_post_format_ui and returning false results in a fatal error

Reported by: tlovett1 Owned by: SergeyBiryukov
Milestone: 3.6 Priority: normal
Severity: normal Version: 3.6
Component: Post Formats Keywords: has-patch commit
Focuses: Cc:


Title says it all. Filtering and returning false results in this error on the post edit screen:

Catchable fatal error: Object of class CLASS_ADDING_FILTER could not be converted to string in /srv/www/trunk/wp-admin/edit-form-advanced.php on line 409

My patch simple declares $post_format_options outside of the if statement. Since the variable was getting checked with empty() and it wasn't initialized, it was passing through the check resulting in a fatal error.

Attachments (1)

patch-post-format-filter-fix.diff (725 bytes) - added by tlovett1 5 years ago.
Patch moves $post_format_options outside of if statement checking show_post_format_ui filter

Download all attachments as: .zip

Change History (6)

5 years ago

Patch moves $post_format_options outside of if statement checking show_post_format_ui filter

#1 @nacin
5 years ago

I see how this could be a notice, but I think I'm missing how it fatals. Could you give us a snippet of code with the filter that triggers this?

#2 @SergeyBiryukov
5 years ago

An empty() check doesn't require the variable to be initialized.

From the error message, looks like you're redefining the $post_format_options global with your class.

#3 @tlovett1
5 years ago

Yep, just caught this. False alarm. I globalized a variable $post_format_options in a plugin. The variable should still be moved outside the conditional, however. It is very possible people will globalize a variable called $post_format_options.

#4 @SergeyBiryukov
5 years ago

  • Keywords commit added
  • Milestone changed from Awaiting Review to 3.6

Reproduced the error with this snippet:

add_filter( 'show_post_format_ui', '__return_false' );
$post_format_options = new stdClass;

patch-post-format-filter-fix.diff makes sense to me.

#5 @SergeyBiryukov
5 years ago

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

In 24011:

Make sure the variables are always defined. props tlovett1, danielbachhuber. fixes #24034. fixes #24112.

Note: See TracTickets for help on using tickets.