-
Notifications
You must be signed in to change notification settings - Fork 37
Issue #132 : Allow filtering to disable 'posts' component. #219
Conversation
A new filter adds 'posts' to the array of components in the Customizer. WP_Customize_Posts is only instantiated if 'posts' is still present. So a filter may remove 'posts', to disable it.
@kienstra this is looking good. Regarding the fatal error, the fix should be simple. At the top of if ( ! isset( $wp_customize->posts ) ) {
return;
} That should do it. We just have to account for the same situation as another plugin that looks for whether the posts component is enabled. |
$wp_customize->posts is now only set if 'posts' isn't removed with a filter. And before, removing it caused an error. So if #wp_customize->posts is not set, return from load_support_classes.
WP_Customize_Posts may not be instantiated if a filter removes 'posts'. So the class WP_Customize_Postmeta_Setting may not exist. In this case, it would cause a fatal error, when accessing its property. So begin the conditional with class_exists().
Hi @westonruter, |
* | ||
* @param array $components Components. | ||
* @param WP_Customize_Manager $wp_customize Manager. | ||
* @return array Components. | ||
*/ | ||
function filter_customize_loaded_components( $components, $wp_customize ) { | ||
require_once dirname( __FILE__ ) . '/class-wp-customize-posts.php'; | ||
$wp_customize->posts = new WP_Customize_Posts( $wp_customize ); | ||
if ( in_array( 'posts', $components ) ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a third true
argument to in_array()
for strict checking.
Remove $wp_customize param and its DocBlock line--it's not used. And reduce argument count in add_filter to 1. Also, add 3rd argument true to in_array for strict evaluation.
Thanks For Review Hi @westonruter, |
@westonruter,
Could you please review this pull request for Issue #132?
The new filter
add_posts_to_customize_loaded_components
adds'posts'
to the array of components in the Customizer.And
WP_Customize_Posts
is only instantiated if'posts'
is still present.So a later filter may remove
'posts'
, to disable it.One issue I noticed is that if a filter does remove
'posts'
, it causes a fatal error:Notice: Undefined property: WP_Customize_Manager::$posts in /srv/www/wordpress-develop/src/wp-content/plugins/wp-customize-posts/php/class-customize-posts-plugin.php on line 179 Fatal error: Call to a member function add_support() on a non-object in /srv/www/wordpress-develop/src/wp-content/plugins/wp-customize-posts/php/class-customize-posts-plugin.php on line 179
Removing the action on line #71 removed that error, but there was another fatal error.
I could have missed something here.
Fixes #132.