Changeset 29051 for trunk/src/wp-includes/class-wp-customize-control.php
- Timestamp:
- 07/09/2014 11:57:29 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/class-wp-customize-control.php
r28980 r29051 86 86 public $type = 'text'; 87 87 88 /** 89 * Callback 90 * 91 * @since 4.0.0 92 * 93 * @access public 94 * @see WP_Customize_Control::active() 95 * @var callable Callback is called with one argument, the instance of 96 * WP_Customize_Control, and returns bool to indicate whether 97 * the control is active (such as it relates to the URL 98 * currently being previewed). 99 */ 100 public $active_callback = ''; 88 101 89 102 /** … … 103 116 $keys = array_keys( get_object_vars( $this ) ); 104 117 foreach ( $keys as $key ) { 105 if ( isset( $args[ $key ] ) ) 118 if ( isset( $args[ $key ] ) ) { 106 119 $this->$key = $args[ $key ]; 120 } 107 121 } 108 122 109 123 $this->manager = $manager; 110 124 $this->id = $id; 125 if ( empty( $this->active_callback ) ) { 126 $this->active_callback = array( $this, 'active_callback' ); 127 } 111 128 112 129 // Process settings. 113 if ( empty( $this->settings ) ) 130 if ( empty( $this->settings ) ) { 114 131 $this->settings = $id; 132 } 115 133 116 134 $settings = array(); … … 133 151 public function enqueue() {} 134 152 153 /** 154 * Check whether control is active to current customizer preview. 155 * 156 * @since 4.0.0 157 * 158 * @return bool 159 */ 160 public final function active() { 161 $control = $this; 162 $active = call_user_func( $this->active_callback, $this ); 163 164 /** 165 * Filter response of WP_Customize_Control::active(). 166 * 167 * @since 4.0.0 168 * 169 * @param bool $active 170 * @param WP_Customize_Control $control 171 */ 172 $active = apply_filters( 'customize_control_active', $active, $control ); 173 174 return $active; 175 } 176 177 /** 178 * Default callback used when invoking WP_Customize_Control::active(). 179 * 180 * Subclasses can override this with their specific logic, or they may 181 * provide an 'active_callback' argument to the constructor. 182 * 183 * @return bool 184 */ 185 public function active_callback() { 186 return true; 187 } 135 188 136 189 /** … … 144 197 */ 145 198 public final function value( $setting_key = 'default' ) { 146 if ( isset( $this->settings[ $setting_key ] ) ) 199 if ( isset( $this->settings[ $setting_key ] ) ) { 147 200 return $this->settings[ $setting_key ]->value(); 201 } 148 202 } 149 203 … … 160 214 161 215 $this->json['type'] = $this->type; 216 $this->json['active'] = $this->active(); 162 217 } 163 218 … … 257 312 } 258 313 259 314 /** 260 315 * Render the custom attributes for the control's input element. 261 316 * … … 996 1051 <?php 997 1052 } 1053 1054 /** 1055 * @return bool 1056 */ 1057 function active_callback() { 1058 return $this->manager->widgets->is_sidebar_rendered( $this->sidebar_id ); 1059 } 998 1060 } 999 1061 … … 1036 1098 echo $this->manager->widgets->get_widget_control( $args ); 1037 1099 } 1100 1101 /** 1102 * @return bool 1103 */ 1104 function active_callback() { 1105 return $this->manager->widgets->is_widget_rendered( $this->widget_id ); 1106 } 1038 1107 } 1039 1108
Note: See TracChangeset
for help on using the changeset viewer.