Skip to content
This repository has been archived by the owner on Dec 16, 2022. It is now read-only.

Issue #132 : Allow filtering to disable 'posts' component. #219

Merged
merged 5 commits into from
Aug 17, 2016

Conversation

kienstra
Copy link
Contributor

@kienstra kienstra commented Aug 17, 2016

@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.

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.
@westonruter
Copy link
Contributor

@kienstra this is looking good. Regarding the fatal error, the fix should be simple. At the top of load_support_classes try adding:

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.

@westonruter westonruter added this to the 0.8 milestone Aug 17, 2016
Ryan Kienstra added 2 commits August 17, 2016 03:12
$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().
@kienstra
Copy link
Contributor Author

Hi @westonruter,
Thanks for helping with this, especially so quickly. The commits above took care of errors locally, when 'posts' is removed from $components.

*
* @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 ) ) {
Copy link
Contributor

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.

Ryan Kienstra added 2 commits August 17, 2016 13:14
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.
@kienstra
Copy link
Contributor Author

Thanks For Review
Commit To Apply Feedback

Hi @westonruter,
Thanks for your feedback. I should have caught those points with a PHPCS check. The commit above makes the corrections.

@westonruter westonruter merged commit 68d00aa into develop Aug 17, 2016
@westonruter westonruter deleted the feature/allow-removing-posts-component branch August 17, 2016 17:51
@westonruter westonruter modified the milestones: 0.7.1, 0.8 Sep 1, 2016
@westonruter westonruter restored the feature/allow-removing-posts-component branch September 1, 2016 22:33
@westonruter westonruter modified the milestones: 0.8, 0.7.1 Sep 1, 2016
@valendesigns valendesigns deleted the feature/allow-removing-posts-component branch August 23, 2017 02:07
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants