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. Built from https://develop.svn.wordpress.org/trunk@36689 git-svn-id: http://core.svn.wordpress.org/trunk@36656 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
@@ -89,6 +89,18 @@ class WP_Customize_Partial {
|
||||
*/
|
||||
public $primary_setting;
|
||||
|
||||
/**
|
||||
* Capability required to edit this partial.
|
||||
*
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* Render callback.
|
||||
*
|
||||
@@ -157,7 +169,7 @@ class WP_Customize_Partial {
|
||||
}
|
||||
|
||||
// Process settings.
|
||||
if ( empty( $this->settings ) ) {
|
||||
if ( ! isset( $this->settings ) ) {
|
||||
$this->settings = array( $id );
|
||||
} else if ( is_string( $this->settings ) ) {
|
||||
$this->settings = array( $this->settings );
|
||||
@@ -299,6 +311,9 @@ class WP_Customize_Partial {
|
||||
* or if one of the associated settings does not exist.
|
||||
*/
|
||||
final public function check_capabilities() {
|
||||
if ( ! empty( $this->capability ) && ! current_user_can( $this->capability ) ) {
|
||||
return false;
|
||||
}
|
||||
foreach ( $this->settings as $setting_id ) {
|
||||
$setting = $this->component->manager->get_setting( $setting_id );
|
||||
if ( ! $setting || ! $setting->check_capabilities() ) {
|
||||
|
||||
Reference in New Issue
Block a user