This repository has been archived by the owner on Dec 16, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 37
Issue #132 : Allow filtering to disable 'posts' component. #219
Merged
Merged
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
09ed3d0
Issue #132 : Allow filtering to disable 'posts' component.
3a905e8
Issue #132 : Prevent error from using an undefined property.
7dc44b8
Issue #32 : Avoid an error by using class_exists().
da1f2bc
Issue #132 : Apply Weston's feedback - arguments and strict checking.
2eed0c2
Issue #132 : Correct PHPCS error by removing extra space.
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -66,6 +66,7 @@ public function __construct() { | |
add_action( 'wp_default_styles', array( $this, 'register_styles' ), 11 ); | ||
add_action( 'init', array( $this, 'register_customize_draft' ) ); | ||
add_filter( 'user_has_cap', array( $this, 'grant_customize_capability' ), 10, 3 ); | ||
add_filter( 'customize_loaded_components', array( $this, 'add_posts_to_customize_loaded_components' ), 0, 2 ); | ||
add_filter( 'customize_loaded_components', array( $this, 'filter_customize_loaded_components' ), 100, 2 ); | ||
add_action( 'customize_register', array( $this, 'load_support_classes' ) ); | ||
|
||
|
@@ -120,18 +121,37 @@ function grant_customize_capability( $allcaps, $caps, $args ) { | |
return $allcaps; | ||
} | ||
|
||
/** | ||
* Add 'posts' to array of components that Customizer loads. | ||
* | ||
* A later filter may remove this, to avoid loading this component. | ||
* | ||
* @param array $components Components. | ||
* @param WP_Customize_Manager $wp_customize Manager. | ||
* @return array Components. | ||
*/ | ||
function add_posts_to_customize_loaded_components( $components, $wp_customize ) { | ||
array_push( $components, 'posts' ); | ||
|
||
return $components; | ||
} | ||
|
||
/** | ||
* Bootstrap. | ||
* | ||
* This will be part of the WP_Customize_Manager::__construct() or another such class constructor in #coremerge. | ||
* Only instantiate WP_Customize_Posts if 'posts' is present in $components. | ||
* This will allow disabling 'posts' through filtering. | ||
* | ||
* @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 commentThe reason will be displayed to describe this comment to others. Learn more. Add a third |
||
$wp_customize->posts = new WP_Customize_Posts( $wp_customize ); | ||
} | ||
|
||
return $components; | ||
} | ||
|
@@ -145,6 +165,10 @@ function filter_customize_loaded_components( $components, $wp_customize ) { | |
*/ | ||
function load_support_classes( $wp_customize ) { | ||
|
||
if ( ! isset( $wp_customize->posts ) ) { | ||
return; | ||
} | ||
|
||
// Theme & Plugin Support. | ||
require_once dirname( __FILE__ ) . '/class-customize-posts-support.php'; | ||
require_once dirname( __FILE__ ) . '/class-customize-posts-plugin-support.php'; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Remove
$wp_customize
arg and corresponding phpdoc, as the param is not used.