Changeset 37476 for trunk/src/wp-includes/class-wp-customize-setting.php
- Timestamp:
- 05/20/2016 09:09:40 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/class-wp-customize-setting.php
r37350 r37476 60 60 * @var callback 61 61 */ 62 public $validate_callback = ''; 62 63 public $sanitize_callback = ''; 63 64 public $sanitize_js_callback = ''; … … 143 144 } 144 145 146 if ( $this->validate_callback ) { 147 add_filter( "customize_validate_{$this->id}", $this->validate_callback, 10, 3 ); 148 } 145 149 if ( $this->sanitize_callback ) { 146 150 add_filter( "customize_sanitize_{$this->id}", $this->sanitize_callback, 10, 2 ); … … 465 469 * 466 470 * @since 3.4.0 467 * 468 * @return false|void False if cap check fails or value isn't set. 471 * @since 4.6.0 Return the result of updating the value. 472 * 473 * @return false|void False if cap check fails or value isn't set or is invalid. 469 474 */ 470 475 final public function save() { 471 476 $value = $this->post_value(); 472 477 473 if ( ! $this->check_capabilities() || ! isset( $value ) ) 478 if ( ! $this->check_capabilities() || ! isset( $value ) ) { 474 479 return false; 480 } 475 481 476 482 /** … … 484 490 * @param WP_Customize_Setting $this WP_Customize_Setting instance. 485 491 */ 486 do_action( 'customize_save_' . $this->id_data[ 'base'], $this );492 do_action( 'customize_save_' . $this->id_data['base'], $this ); 487 493 488 494 $this->update( $value ); … … 495 501 * 496 502 * @param mixed $default A default value which is used as a fallback. Default is null. 497 * @return mixed The default value on failure, otherwise the sanitized value.503 * @return mixed The default value on failure, otherwise the sanitized and validated value. 498 504 */ 499 505 final public function post_value( $default = null ) { … … 506 512 * @since 3.4.0 507 513 * 508 * @param string|array $value The value to sanitize.509 * @return string|array|null Null if an input isn't valid, otherwise the sanitized value.514 * @param string|array $value The value to sanitize. 515 * @return string|array|null|WP_Error Sanitized value, or `null`/`WP_Error` if invalid. 510 516 */ 511 517 public function sanitize( $value ) { … … 520 526 */ 521 527 return apply_filters( "customize_sanitize_{$this->id}", $value, $this ); 528 } 529 530 /** 531 * Validate an input. 532 * 533 * @since 4.6.0 534 * @access public 535 * @see WP_REST_Request::has_valid_params() 536 * 537 * @param mixed $value Value to validate. 538 * @return true|WP_Error 539 */ 540 public function validate( $value ) { 541 if ( is_wp_error( $value ) ) { 542 return $value; 543 } 544 if ( is_null( $value ) ) { 545 return new WP_Error( 'invalid_value', __( 'Invalid value.' ) ); 546 } 547 548 $validity = new WP_Error(); 549 550 /** 551 * Validate a Customize setting value. 552 * 553 * Plugins should amend the `$validity` object via its `WP_Error::add()` method. 554 * 555 * @since 4.6.0 556 * 557 * @param WP_Error $validity Filtered from `true` to `WP_Error` when invalid. 558 * @param mixed $value Value of the setting. 559 * @param WP_Customize_Setting $this WP_Customize_Setting instance. 560 */ 561 $validity = apply_filters( "customize_validate_{$this->id}", $validity, $value, $this ); 562 563 if ( is_wp_error( $validity ) && empty( $validity->errors ) ) { 564 $validity = true; 565 } 566 return $validity; 522 567 } 523 568 … … 701 746 702 747 /** 748 * Get the data to export to the client via JSON. 749 * 750 * @since 4.6.0 751 * 752 * @return array Array of parameters passed to JavaScript. 753 */ 754 public function json() { 755 return array( 756 'value' => $this->js_value(), 757 'transport' => $this->transport, 758 'dirty' => $this->dirty, 759 'type' => $this->type, 760 ); 761 } 762 763 /** 703 764 * Validate user capabilities whether the theme supports the setting. 704 765 *
Note: See TracChangeset
for help on using the changeset viewer.