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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion php/class-customize-posts-plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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, 1 );
add_filter( 'customize_loaded_components', array( $this, 'filter_customize_loaded_components' ), 100, 2 );
add_action( 'customize_register', array( $this, 'load_support_classes' ) );

Expand Down Expand Up @@ -120,18 +121,36 @@ 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.
* @return array Components.
*/
function add_posts_to_customize_loaded_components( $components ) {
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, true ) ) {
$wp_customize->posts = new WP_Customize_Posts( $wp_customize );
}

return $components;
}
Expand All @@ -145,6 +164,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';
Expand Down
2 changes: 1 addition & 1 deletion php/class-wp-customize-featured-image-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ public function setup_selective_refresh() {
* @return false|array Partial args or false if not a match.
*/
public function filter_customize_dynamic_partial_args( $partial_args, $partial_id ) {
if ( preg_match( WP_Customize_Postmeta_Setting::SETTING_ID_PATTERN, $partial_id, $matches ) && $matches['meta_key'] === $this->meta_key ) {
if ( class_exists( 'WP_Customize_Postmeta_Setting' ) && preg_match( WP_Customize_Postmeta_Setting::SETTING_ID_PATTERN, $partial_id, $matches ) && $matches['meta_key'] === $this->meta_key ) {
if ( false === $partial_args ) {
$partial_args = array();
}
Expand Down