当前位置: 首页>>代码示例>>PHP>>正文


PHP WP_Customize_Setting::validate方法代码示例

本文整理汇总了PHP中WP_Customize_Setting::validate方法的典型用法代码示例。如果您正苦于以下问题:PHP WP_Customize_Setting::validate方法的具体用法?PHP WP_Customize_Setting::validate怎么用?PHP WP_Customize_Setting::validate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在WP_Customize_Setting的用法示例。


在下文中一共展示了WP_Customize_Setting::validate方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: test_validate

 /**
  * Test validate.
  *
  * @see WP_Customize_Setting::validate()
  */
 public function test_validate()
 {
     $setting = new WP_Customize_Setting($this->manager, 'name', array('type' => 'key', 'validate_callback' => array($this, 'filter_validate_for_test_validate')));
     $validity = $setting->validate('BAD!');
     $this->assertInstanceOf('WP_Error', $validity);
     $this->assertEquals('invalid_key', $validity->get_error_code());
 }
开发者ID:atimmer,项目名称:wordpress-develop-mirror,代码行数:12,代码来源:setting.php

示例2: post_value

 /**
  * Returns the sanitized value for a given setting from the request's POST data.
  *
  * @since 3.4.0
  * @since 4.1.1 Introduced the `$default` parameter.
  * @since 4.6.0 `$default` is now returned early when the setting post value is invalid.
  * @access public
  *
  * @see WP_REST_Server::dispatch()
  * @see WP_Rest_Request::sanitize_params()
  * @see WP_Rest_Request::has_valid_params()
  *
  * @param WP_Customize_Setting $setting A WP_Customize_Setting derived object.
  * @param mixed                $default Value returned $setting has no post value (added in 4.2.0)
  *                                      or the post value is invalid (added in 4.6.0).
  * @return string|mixed $post_value Sanitized value or the $default provided.
  */
 public function post_value($setting, $default = null)
 {
     $post_values = $this->unsanitized_post_values();
     if (!array_key_exists($setting->id, $post_values)) {
         return $default;
     }
     $value = $post_values[$setting->id];
     $valid = $setting->validate($value);
     if (is_wp_error($valid)) {
         return $default;
     }
     $value = $setting->sanitize($value);
     if (is_null($value) || is_wp_error($value)) {
         return $default;
     }
     return $value;
 }
开发者ID:inpsyde,项目名称:wordpress-dev,代码行数:34,代码来源:class-wp-customize-manager.php

示例3: validate

 /**
  * Validate CSS.
  *
  * Checks for imbalanced braces, brackets, and comments.
  * Notifications are rendered when the customizer state is saved.
  *
  * @todo There are cases where valid CSS can be incorrectly marked as invalid when strings or comments include balancing characters. To fix, CSS tokenization needs to be used.
  *
  * @since 4.7.0
  * @access public
  *
  * @param string $css The input string.
  * @return true|WP_Error True if the input was validated, otherwise WP_Error.
  */
 public function validate($css)
 {
     $validity = new WP_Error();
     if (preg_match('#</?\\w+#', $css)) {
         $validity->add('illegal_markup', __('Markup is not allowed in CSS.'));
     }
     $imbalanced = false;
     // Make sure that there is a closing brace for each opening brace.
     if (!$this->validate_balanced_characters('{', '}', $css)) {
         $validity->add('imbalanced_curly_brackets', __('Your curly brackets <code>{}</code> are imbalanced. Make sure there is a closing <code>}</code> for every opening <code>{</code>.'));
         $imbalanced = true;
     }
     // Ensure brackets are balanced.
     if (!$this->validate_balanced_characters('[', ']', $css)) {
         $validity->add('imbalanced_braces', __('Your brackets <code>[]</code> are imbalanced. Make sure there is a closing <code>]</code> for every opening <code>[</code>.'));
         $imbalanced = true;
     }
     // Ensure parentheses are balanced.
     if (!$this->validate_balanced_characters('(', ')', $css)) {
         $validity->add('imbalanced_parentheses', __('Your parentheses <code>()</code> are imbalanced. Make sure there is a closing <code>)</code> for every opening <code>(</code>.'));
         $imbalanced = true;
     }
     // Ensure single quotes are equal.
     if (!$this->validate_equal_characters('\'', $css)) {
         $validity->add('unequal_single_quotes', __('Your single quotes <code>\'</code> are uneven. Make sure there is a closing <code>\'</code> for every opening <code>\'</code>.'));
         $imbalanced = true;
     }
     // Ensure single quotes are equal.
     if (!$this->validate_equal_characters('"', $css)) {
         $validity->add('unequal_double_quotes', __('Your double quotes <code>"</code> are uneven. Make sure there is a closing <code>"</code> for every opening <code>"</code>.'));
         $imbalanced = true;
     }
     /*
      * Make sure any code comments are closed properly.
      *
      * The first check could miss stray an unpaired comment closing figure, so if
      * The number appears to be balanced, then check for equal numbers
      * of opening/closing comment figures.
      *
      * Although it may initially appear redundant, we use the first method
      * to give more specific feedback to the user.
      */
     $unclosed_comment_count = $this->validate_count_unclosed_comments($css);
     if (0 < $unclosed_comment_count) {
         $validity->add('unclosed_comment', sprintf(_n('There is %s unclosed code comment. Close each comment with <code>*/</code>.', 'There are %s unclosed code comments. Close each comment with <code>*/</code>.', $unclosed_comment_count), $unclosed_comment_count));
         $imbalanced = true;
     } elseif (!$this->validate_balanced_characters('/*', '*/', $css)) {
         $validity->add('imbalanced_comments', __('There is an extra <code>*/</code>, indicating an end to a comment.  Be sure that there is an opening <code>/*</code> for every closing <code>*/</code>.'));
         $imbalanced = true;
     }
     if ($imbalanced && $this->is_possible_content_error($css)) {
         $validity->add('possible_false_positive', __('Imbalanced/unclosed character errors can be caused by <code>content: "";</code> declarations. You may need to remove this or add it to a custom CSS file.'));
     }
     if (empty($validity->errors)) {
         $validity = parent::validate($css);
     }
     return $validity;
 }
开发者ID:aaemnnosttv,项目名称:develop.git.wordpress.org,代码行数:72,代码来源:class-wp-customize-custom-css-setting.php


注:本文中的WP_Customize_Setting::validate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。