WordPress.org

Make WordPress Core

Opened 23 months ago

Closed 23 months ago

Last modified 23 months ago

#35242 closed defect (bug) (fixed)

PHP Noticed caused by Customizer if widgets panel removed

Reported by: DJPaul Owned by: westonruter
Milestone: 4.5 Priority: normal
Severity: normal Version: 4.4
Component: Customize Keywords: has-patch
Focuses: Cc:

Description

If $wp_customize->remove_panel( 'widgets' ); is done, the Customizer throws a PHP Notice:

PHP Notice: Trying to get property of non-object in /srv/www/buddypress.dev/src/wp-includes/class-wp-customize-widgets.php on line 716

Tested on 4.4 SVN branch.

Attachments (3)

35242.diff (846 bytes) - added by voldemortensen 23 months ago.
35242(1).diff (846 bytes) - added by voldemortensen 23 months ago.
35242.2.diff (1.1 KB) - added by DrewAPicture 23 months ago.

Download all attachments as: .zip

Change History (14)

#1 @johnbillion
23 months ago

  • Keywords needs-patch added

#2 @ericlewis
23 months ago

  • Keywords needs-patch removed

Hi @DJPaul — there's a special way to remove a Customizer component.

Perhaps we need to review documentation here, to point developers in the right direction?

#3 @DJPaul
23 months ago

Thanks. I discovered the remove_panel method from a blog post on make/core. Maybe the docblock for remove_panel could say don't use this to remove the core widgets or nav menus panels, maybe.

#4 follow-up: @voldemortensen
23 months ago

  • Keywords has-patch added

35242.diff adds a _doing_it_wrong warning. Thoughts?

#5 in reply to: ↑ 4 @westonruter
23 months ago

Replying to voldemortensen:

35242.diff adds a _doing_it_wrong warning. Thoughts?

Good idea.

Feedback:

#6 @voldemortensen
23 months ago

Thanks for the feedback, updated the patch.

#7 @westonruter
23 months ago

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

In 36216:

Customizer: Call _doing_it_wrong() if widgets or nav_menus are manually removed via WP_Customize_Manager::remove_panel().

Advise that the customize_loaded_components filter should be used instead.

Props voldemortensen.
See #33552.
Fixes #35242.

#8 @DrewAPicture
23 months ago

  • Milestone changed from Awaiting Review to 4.5
  • Resolution fixed deleted
  • Status changed from closed to reopened

Following [36216]:

  • Instead of arbitrarily linking a Trac comment, let's link to the code reference page for the hook where I have conveniently added simplified versions of the examples from comment:12:ticket:33552 :-)
  • <code>customize_loaded_components</code> shouldn't be translatable
  • The string is missing a translator comment for the specifiers

All of the above are done in 35242.2.diff.

#9 @westonruter
23 months ago

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

In 36219:

Customizer: Improve _doing_it_wrong() message when widgets or nav_menus are manually removed via WP_Customize_Manager::remove_panel().

  • Link to code reference page for customize_loaded_components instead of linking to a Trac comment.
  • Remove HTML code from being included in translated string.
  • Add missing translator comment for the specifiers in the translated string.

Amends [36216].
Props DrewAPicture.
Fixes #35242.

This ticket was mentioned in Slack in #core-customize by drew. View the logs.


23 months ago

#11 @westonruter
23 months ago

In 36262:

Customizer: Re-use list of components to eliminate code duplication.

Introduces protected WP_Customize_Manager::$components to store list of loaded core components filtered by customize_loaded_components.

Props DrewAPicture.
See #35242
See #33552.
Fixes #35354.

Note: See TracTickets for help on using tickets.