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


PHP WP_Customize_Manager::validate_setting_values方法代码示例

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


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

示例1: array

 /**
  * Test WP_Customize_Manager::validate_setting_values().
  *
  * @see WP_Customize_Manager::validate_setting_values()
  */
 function test_validate_setting_values()
 {
     $default_value = 'foo_default';
     $setting = $this->manager->add_setting('foo', array('validate_callback' => array($this, 'filter_customize_validate_foo'), 'sanitize_callback' => array($this, 'filter_customize_sanitize_foo')));
     $post_value = 'bar';
     $this->manager->set_post_value('foo', $post_value);
     $this->assertEmpty($this->manager->validate_setting_values($this->manager->unsanitized_post_values()));
     $this->manager->set_post_value('foo', 'return_wp_error_in_sanitize');
     $invalid_settings = $this->manager->validate_setting_values($this->manager->unsanitized_post_values());
     $this->assertCount(1, $invalid_settings);
     $this->assertArrayHasKey($setting->id, $invalid_settings);
     $this->assertInstanceOf('WP_Error', $invalid_settings[$setting->id]);
     $error = $invalid_settings[$setting->id];
     $this->assertEquals('invalid_value_in_sanitize', $error->get_error_code());
     $this->assertEquals(array('source' => 'filter_customize_sanitize_foo'), $error->get_error_data());
     $this->manager->set_post_value('foo', 'return_null_in_sanitize');
     $invalid_settings = $this->manager->validate_setting_values($this->manager->unsanitized_post_values());
     $this->assertCount(1, $invalid_settings);
     $this->assertArrayHasKey($setting->id, $invalid_settings);
     $this->assertInstanceOf('WP_Error', $invalid_settings[$setting->id]);
     $this->assertNull($invalid_settings[$setting->id]->get_error_data());
     $post_value = '<script>evil</script>';
     $this->manager->set_post_value('foo', $post_value);
     $invalid_settings = $this->manager->validate_setting_values($this->manager->unsanitized_post_values());
     $this->assertCount(1, $invalid_settings);
     $this->assertArrayHasKey($setting->id, $invalid_settings);
     $this->assertInstanceOf('WP_Error', $invalid_settings[$setting->id]);
     $error = $invalid_settings[$setting->id];
     $this->assertEquals('invalid_value_in_validate', $error->get_error_code());
     $this->assertEquals(array('source' => 'filter_customize_validate_foo'), $error->get_error_data());
 }
开发者ID:ntwb,项目名称:wordpress-travis,代码行数:36,代码来源:manager.php

示例2: array

 /**
  * Test the WP_Customize_Manager::validate_setting_values() method to make sure that the validation and sanitization are done in the right order.
  *
  * @ticket 37247
  */
 function test_validate_setting_values_validation_sanitization_order()
 {
     $setting = $this->manager->add_setting('numeric', array('validate_callback' => array($this, 'filter_customize_validate_numeric'), 'sanitize_callback' => array($this, 'filter_customize_sanitize_numeric')));
     $post_value = '42';
     $this->manager->set_post_value('numeric', $post_value);
     $validities = $this->manager->validate_setting_values($this->manager->unsanitized_post_values());
     $this->assertCount(1, $validities);
     $this->assertEquals(array('numeric' => true), $validities);
 }
开发者ID:atimmer,项目名称:wordpress-develop-mirror,代码行数:14,代码来源:manager.php

示例3: handle_render_partials_request

 /**
  * Handles the Ajax request to return the rendered partials for the requested placements.
  *
  * @since 4.5.0
  * @access public
  */
 public function handle_render_partials_request()
 {
     if (!$this->is_render_partials_request()) {
         return;
     }
     /*
      * Note that is_customize_preview() returning true will entail that the
      * user passed the 'customize' capability check and the nonce check, since
      * WP_Customize_Manager::setup_theme() is where the previewing flag is set.
      */
     if (!is_customize_preview()) {
         wp_send_json_error('expected_customize_preview', 403);
     } else {
         if (!isset($_POST['partials'])) {
             wp_send_json_error('missing_partials', 400);
         }
     }
     $partials = json_decode(wp_unslash($_POST['partials']), true);
     if (!is_array($partials)) {
         wp_send_json_error('malformed_partials');
     }
     $this->add_dynamic_partials(array_keys($partials));
     /**
      * Fires immediately before partials are rendered.
      *
      * Plugins may do things like call wp_enqueue_scripts() and gather a list of the scripts
      * and styles which may get enqueued in the response.
      *
      * @since 4.5.0
      *
      * @param WP_Customize_Selective_Refresh $this     Selective refresh component.
      * @param array                          $partials Placements' context data for the partials rendered in the request.
      *                                                 The array is keyed by partial ID, with each item being an array of
      *                                                 the placements' context data.
      */
     do_action('customize_render_partials_before', $this, $partials);
     set_error_handler(array($this, 'handle_error'), error_reporting());
     $contents = array();
     foreach ($partials as $partial_id => $container_contexts) {
         $this->current_partial_id = $partial_id;
         if (!is_array($container_contexts)) {
             wp_send_json_error('malformed_container_contexts');
         }
         $partial = $this->get_partial($partial_id);
         if (!$partial || !$partial->check_capabilities()) {
             $contents[$partial_id] = null;
             continue;
         }
         $contents[$partial_id] = array();
         // @todo The array should include not only the contents, but also whether the container is included?
         if (empty($container_contexts)) {
             // Since there are no container contexts, render just once.
             $contents[$partial_id][] = $partial->render(null);
         } else {
             foreach ($container_contexts as $container_context) {
                 $contents[$partial_id][] = $partial->render($container_context);
             }
         }
     }
     $this->current_partial_id = null;
     restore_error_handler();
     /**
      * Fires immediately after partials are rendered.
      *
      * Plugins may do things like call wp_footer() to scrape scripts output and return them
      * via the {@see 'customize_render_partials_response'} filter.
      *
      * @since 4.5.0
      *
      * @param WP_Customize_Selective_Refresh $this     Selective refresh component.
      * @param array                          $partials Placements' context data for the partials rendered in the request.
      *                                                 The array is keyed by partial ID, with each item being an array of
      *                                                 the placements' context data.
      */
     do_action('customize_render_partials_after', $this, $partials);
     $response = array('contents' => $contents);
     if (defined('WP_DEBUG_DISPLAY') && WP_DEBUG_DISPLAY) {
         $response['errors'] = $this->triggered_errors;
     }
     $setting_validities = $this->manager->validate_setting_values($this->manager->unsanitized_post_values());
     $exported_setting_validities = array_map(array($this->manager, 'prepare_setting_validity_for_js'), $setting_validities);
     $response['setting_validities'] = $exported_setting_validities;
     /**
      * Filters the response from rendering the partials.
      *
      * Plugins may use this filter to inject `$scripts` and `$styles`, which are dependencies
      * for the partials being rendered. The response data will be available to the client via
      * the `render-partials-response` JS event, so the client can then inject the scripts and
      * styles into the DOM if they have not already been enqueued there.
      *
      * If plugins do this, they'll need to take care for any scripts that do `document.write()`
      * and make sure that these are not injected, or else to override the function to no-op,
      * or else the page will be destroyed.
      *
//.........这里部分代码省略.........
开发者ID:aaemnnosttv,项目名称:develop.git.wordpress.org,代码行数:101,代码来源:class-wp-customize-selective-refresh.php


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