Changeset 42343 for trunk/src/wp-includes/class-wp-widget.php
- Timestamp:
- 11/30/2017 11:09:33 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/class-wp-widget.php
r41688 r42343 111 111 */ 112 112 public function widget( $args, $instance ) { 113 die( 'function WP_Widget::widget() must be over-ridden in a sub-class.');113 die( 'function WP_Widget::widget() must be over-ridden in a sub-class.' ); 114 114 } 115 115 … … 141 141 */ 142 142 public function form( $instance ) { 143 echo '<p class="no-options-widget">' . __( 'There are no options for this widget.') . '</p>';143 echo '<p class="no-options-widget">' . __( 'There are no options for this widget.' ) . '</p>'; 144 144 return 'noform'; 145 145 } … … 161 161 */ 162 162 public function __construct( $id_base, $name, $widget_options = array(), $control_options = array() ) { 163 $this->id_base = empty($id_base) ? preg_replace( '/(wp_)?widget_/', '', strtolower(get_class($this)) ) : strtolower($id_base); 164 $this->name = $name; 165 $this->option_name = 'widget_' . $this->id_base; 166 $this->widget_options = wp_parse_args( $widget_options, array( 'classname' => $this->option_name, 'customize_selective_refresh' => false ) ); 163 $this->id_base = empty( $id_base ) ? preg_replace( '/(wp_)?widget_/', '', strtolower( get_class( $this ) ) ) : strtolower( $id_base ); 164 $this->name = $name; 165 $this->option_name = 'widget_' . $this->id_base; 166 $this->widget_options = wp_parse_args( 167 $widget_options, array( 168 'classname' => $this->option_name, 169 'customize_selective_refresh' => false, 170 ) 171 ); 167 172 $this->control_options = wp_parse_args( $control_options, array( 'id_base' => $this->id_base ) ); 168 173 } … … 200 205 * @return string Name attribute for $field_name 201 206 */ 202 public function get_field_name( $field_name) {207 public function get_field_name( $field_name ) { 203 208 if ( false === $pos = strpos( $field_name, '[' ) ) { 204 209 return 'widget-' . $this->id_base . '[' . $this->number . '][' . $field_name . ']'; … … 231 236 public function _register() { 232 237 $settings = $this->get_settings(); 233 $empty = true;238 $empty = true; 234 239 235 240 // When $settings is an array-like object, get an intrinsic array for use with array_keys(). … … 263 268 * instances of the same class. 264 269 */ 265 public function _set( $number) {270 public function _set( $number ) { 266 271 $this->number = $number; 267 $this->id = $this->id_base . '-' . $number;272 $this->id = $this->id_base . '-' . $number; 268 273 } 269 274 … … 276 281 */ 277 282 public function _get_display_callback() { 278 return array( $this, 'display_callback');283 return array( $this, 'display_callback' ); 279 284 } 280 285 … … 287 292 */ 288 293 public function _get_update_callback() { 289 return array( $this, 'update_callback');294 return array( $this, 'update_callback' ); 290 295 } 291 296 … … 298 303 */ 299 304 public function _get_form_callback() { 300 return array( $this, 'form_callback');305 return array( $this, 'form_callback' ); 301 306 } 302 307 … … 317 322 public function is_preview() { 318 323 global $wp_customize; 319 return ( isset( $wp_customize ) && $wp_customize->is_preview() ) 324 return ( isset( $wp_customize ) && $wp_customize->is_preview() ); 320 325 } 321 326 … … 393 398 394 399 // We need to update the data 395 if ( $this->updated ) 400 if ( $this->updated ) { 396 401 return; 397 398 if ( isset($_POST['delete_widget']) && $_POST['delete_widget'] ) { 402 } 403 404 if ( isset( $_POST['delete_widget'] ) && $_POST['delete_widget'] ) { 399 405 // Delete the settings for this instance of the widget 400 if ( isset( $_POST['the-widget-id']) )406 if ( isset( $_POST['the-widget-id'] ) ) { 401 407 $del_id = $_POST['the-widget-id']; 402 else408 } else { 403 409 return; 404 405 if ( isset($wp_registered_widgets[$del_id]['params'][0]['number']) ) { 406 $number = $wp_registered_widgets[$del_id]['params'][0]['number']; 407 408 if ( $this->id_base . '-' . $number == $del_id ) 409 unset($all_instances[$number]); 410 } 411 412 if ( isset( $wp_registered_widgets[ $del_id ]['params'][0]['number'] ) ) { 413 $number = $wp_registered_widgets[ $del_id ]['params'][0]['number']; 414 415 if ( $this->id_base . '-' . $number == $del_id ) { 416 unset( $all_instances[ $number ] ); 417 } 410 418 } 411 419 } else { 412 if ( isset( $_POST['widget-' . $this->id_base]) && is_array($_POST['widget-' . $this->id_base]) ) {413 $settings = $_POST[ 'widget-' . $this->id_base];414 } elseif ( isset( $_POST['id_base']) && $_POST['id_base'] == $this->id_base ) {415 $num = $_POST['multi_number'] ? (int) $_POST['multi_number'] : (int) $_POST['widget_number'];420 if ( isset( $_POST[ 'widget-' . $this->id_base ] ) && is_array( $_POST[ 'widget-' . $this->id_base ] ) ) { 421 $settings = $_POST[ 'widget-' . $this->id_base ]; 422 } elseif ( isset( $_POST['id_base'] ) && $_POST['id_base'] == $this->id_base ) { 423 $num = $_POST['multi_number'] ? (int) $_POST['multi_number'] : (int) $_POST['widget_number']; 416 424 $settings = array( $num => array() ); 417 425 } else { … … 420 428 421 429 foreach ( $settings as $number => $new_instance ) { 422 $new_instance = stripslashes_deep( $new_instance);423 $this->_set( $number);424 425 $old_instance = isset( $all_instances[$number]) ? $all_instances[$number] : array();430 $new_instance = stripslashes_deep( $new_instance ); 431 $this->_set( $number ); 432 433 $old_instance = isset( $all_instances[ $number ] ) ? $all_instances[ $number ] : array(); 426 434 427 435 $was_cache_addition_suspended = wp_suspend_cache_addition(); … … 451 459 $instance = apply_filters( 'widget_update_callback', $instance, $new_instance, $old_instance, $this ); 452 460 if ( false !== $instance ) { 453 $all_instances[ $number] = $instance;461 $all_instances[ $number ] = $instance; 454 462 } 455 463 … … 458 466 } 459 467 460 $this->save_settings( $all_instances);468 $this->save_settings( $all_instances ); 461 469 $this->updated = true; 462 470 } … … 476 484 */ 477 485 public function form_callback( $widget_args = 1 ) { 478 if ( is_numeric( $widget_args) )486 if ( is_numeric( $widget_args ) ) { 479 487 $widget_args = array( 'number' => $widget_args ); 480 481 $widget_args = wp_parse_args( $widget_args, array( 'number' => -1 ) ); 488 } 489 490 $widget_args = wp_parse_args( $widget_args, array( 'number' => -1 ) ); 482 491 $all_instances = $this->get_settings(); 483 492 484 493 if ( -1 == $widget_args['number'] ) { 485 494 // We echo out a form where 'number' can be set later 486 $this->_set( '__i__');495 $this->_set( '__i__' ); 487 496 $instance = array(); 488 497 } else { 489 $this->_set( $widget_args['number']);498 $this->_set( $widget_args['number'] ); 490 499 $instance = $all_instances[ $widget_args['number'] ]; 491 500 } … … 505 514 $return = null; 506 515 if ( false !== $instance ) { 507 $return = $this->form( $instance);516 $return = $this->form( $instance ); 508 517 509 518 /** … … 537 546 */ 538 547 public function _register_one( $number = -1 ) { 539 wp_register_sidebar_widget( $this->id, $this->name,$this->_get_display_callback(), $this->widget_options, array( 'number' => $number ) );548 wp_register_sidebar_widget( $this->id, $this->name, $this->_get_display_callback(), $this->widget_options, array( 'number' => $number ) ); 540 549 _register_widget_update_callback( $this->id_base, $this->_get_update_callback(), $this->control_options, array( 'number' => -1 ) ); 541 _register_widget_form_callback( $this->id, $this->name,$this->_get_form_callback(), $this->control_options, array( 'number' => $number ) );550 _register_widget_form_callback( $this->id, $this->name, $this->_get_form_callback(), $this->control_options, array( 'number' => $number ) ); 542 551 } 543 552
Note: See TracChangeset
for help on using the changeset viewer.