mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-06-28 22:30:04 +00:00
Customize: Allow controls to be registered without any associated settings.
* Improves parity between partials and controls. A partial or control can be settingless if instantiated with `settings` param as empty array (otherwise, if null, then the partial/control ID is used). * Eliminate need to create dummy settings that serve no purpose except to place a control in the UI. * Removes dummy settings for `create_new_menu` and `new_menu_name`. * Introduces `WP_Customize_Control::$capability` and `WP_Customize_Partial::$capability`, and if set checks them in the respective `check_capabilities()` methods. * Prevents PHP fatal error from happening when non-existing settings are provided to control: "Call to a member function `check_capabilities()` on a non-object". * Fixes issue where nav menu items and widgets were no longer working with selective refresh because cap check was failing. See #27355. Fixes #35926. git-svn-id: https://develop.svn.wordpress.org/trunk@36689 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -64,6 +64,18 @@ class WP_Customize_Control {
|
||||
*/
|
||||
public $setting = 'default';
|
||||
|
||||
/**
|
||||
* Capability required to use this control.
|
||||
*
|
||||
* Normally this is empty and the capability is derived from the capabilities
|
||||
* of the associated `$settings`.
|
||||
*
|
||||
* @since 4.5.0
|
||||
* @access public
|
||||
* @var string
|
||||
*/
|
||||
public $capability;
|
||||
|
||||
/**
|
||||
* @access public
|
||||
* @var int
|
||||
@@ -187,7 +199,7 @@ class WP_Customize_Control {
|
||||
$this->instance_number = self::$instance_count;
|
||||
|
||||
// Process settings.
|
||||
if ( empty( $this->settings ) ) {
|
||||
if ( ! isset( $this->settings ) ) {
|
||||
$this->settings = $id;
|
||||
}
|
||||
|
||||
@@ -196,7 +208,7 @@ class WP_Customize_Control {
|
||||
foreach ( $this->settings as $key => $setting ) {
|
||||
$settings[ $key ] = $this->manager->get_setting( $setting );
|
||||
}
|
||||
} else {
|
||||
} else if ( is_string( $this->settings ) ) {
|
||||
$this->setting = $this->manager->get_setting( $this->settings );
|
||||
$settings['default'] = $this->setting;
|
||||
}
|
||||
@@ -299,21 +311,32 @@ class WP_Customize_Control {
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the theme supports the control and check user capabilities.
|
||||
* Checks if the user can use this control.
|
||||
*
|
||||
* Returns false if the user cannot manipulate one of the associated settings,
|
||||
* or if one of the associated settings does not exist. Also returns false if
|
||||
* the associated section does not exist or if its capability check returns
|
||||
* false.
|
||||
*
|
||||
* @since 3.4.0
|
||||
*
|
||||
* @return bool False if theme doesn't support the control or user doesn't have the required permissions, otherwise true.
|
||||
*/
|
||||
final public function check_capabilities() {
|
||||
if ( ! empty( $this->capability ) && ! current_user_can( $this->capability ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach ( $this->settings as $setting ) {
|
||||
if ( ! $setting->check_capabilities() )
|
||||
if ( ! $setting || ! $setting->check_capabilities() ) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
$section = $this->manager->get_section( $this->section );
|
||||
if ( isset( $section ) && ! $section->check_capabilities() )
|
||||
if ( isset( $section ) && ! $section->check_capabilities() ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user