• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP WP_Customize_Setting类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: test_value

 /**
  * @see WP_Customize_Widget_Setting::value()
  */
 function test_value()
 {
     $id_base = 'categories';
     $sample_data = $this->get_sample_widget_instance_data($id_base);
     $old_setting = new \WP_Customize_Setting($this->customize_manager, $sample_data['setting_id'], array('type' => 'option'));
     $args = $this->customize_manager->widgets->get_setting_args($sample_data['setting_id']);
     $new_setting = new WP_Customize_Widget_Setting($this->customize_manager, $sample_data['setting_id'], $args);
     $this->assertEquals($sample_data['instance'], $old_setting->value());
     $this->assertEquals($old_setting->value(), $new_setting->value());
 }
开发者ID:BE-Webdesign,项目名称:wp-customize-widgets-plus,代码行数:13,代码来源:test-class-wp-customize-widget-setting.php


示例2: setUp

 function setUp()
 {
     parent::setUp();
     require_once ABSPATH . WPINC . '/class-wp-customize-manager.php';
     add_theme_support('customize-selective-refresh-widgets');
     $user_id = self::factory()->user->create(array('role' => 'administrator'));
     wp_set_current_user($user_id);
     $GLOBALS['wp_customize'] = new WP_Customize_Manager();
     $this->manager = $GLOBALS['wp_customize'];
     unset($GLOBALS['_wp_sidebars_widgets']);
     // clear out cache set by wp_get_sidebars_widgets()
     $sidebars_widgets = wp_get_sidebars_widgets();
     $this->assertEqualSets(array('wp_inactive_widgets', 'sidebar-1'), array_keys(wp_get_sidebars_widgets()));
     $this->assertContains('search-2', $sidebars_widgets['sidebar-1']);
     $this->assertContains('categories-2', $sidebars_widgets['sidebar-1']);
     $this->assertArrayHasKey(2, get_option('widget_search'));
     $widget_categories = get_option('widget_categories');
     $this->assertArrayHasKey(2, $widget_categories);
     $this->assertEquals('', $widget_categories[2]['title']);
     // @todo We should not be including a theme anyway
     remove_action('after_setup_theme', 'twentyfifteen_setup');
     remove_action('after_setup_theme', 'twentysixteen_setup');
     remove_action('customize_register', 'twentysixteen_customize_register', 11);
     $this->backup_registered_sidebars = $GLOBALS['wp_registered_sidebars'];
     // Reset protected static var on class.
     WP_Customize_Setting::reset_aggregated_multidimensionals();
 }
开发者ID:atimmer,项目名称:wordpress-develop-mirror,代码行数:27,代码来源:widgets.php


示例3: menu_customizer_preview_nav_menu

/**
 * Preview changes made to a nav menu.
 *
 * Filters nav menu display to show customized items in the customized order.
 *
 * @since Menu Customizer 0.0
 *
 * @param array                $value   Array of the menu items to preview, in order.
 * @param WP_Customize_Setting $setting WP_Customize_Setting instance.
 */
function menu_customizer_preview_nav_menu($setting)
{
    $menu_id = str_replace('nav_menu_', '', $setting->id);
    // Ensure that $menu_id is valid.
    $menu_id = (int) $menu_id;
    $menu = wp_get_nav_menu_object($menu_id);
    if (!$menu || !$menu_id) {
        return new WP_Error('invalid_menu_id', __('Invalid menu ID.'));
    }
    if (is_wp_error($menu)) {
        return $menu;
    }
    $menu_id = $menu->term_id;
    // @todo don't use a closure for PHP 5.2
    add_filter('wp_get_nav_menu_items', function ($items, $menu, $args) use($menu_id, $setting) {
        $preview_menu_id = $menu->term_id;
        if ($menu_id == $preview_menu_id) {
            $new_ids = $setting->post_value();
            $new_items = array();
            $i = 0;
            // For each item, get object and update menu order property.
            foreach ($new_ids as $item_id) {
                $item = get_post($item_id);
                $item = wp_setup_nav_menu_item($item);
                $item->menu_order = $i;
                $new_items[] = $item;
                $i++;
            }
            return $new_items;
        } else {
            return $items;
        }
    }, 10, 3);
}
开发者ID:dauidus,项目名称:woof,代码行数:44,代码来源:menu-customizer.php


示例4: test_non_posted_setting_applying_default_value_in_preview

	/**
	 * Test specific fix for setting's default value not applying on preview window
	 *
	 * @ticket 30988
	 */
	function test_non_posted_setting_applying_default_value_in_preview() {
		$type = 'option';
		$name = 'unset_option_without_post_value';
		$default = "default_value_{$name}";
		$setting = new WP_Customize_Setting( $this->manager, $name, compact( 'type', 'default' ) );
		$this->assertEquals( $this->undefined, get_option( $name, $this->undefined ) );
		$this->assertEquals( $default, $setting->value() );
		$setting->preview();
		$this->assertEquals( $default, get_option( $name, $this->undefined ), sprintf( 'Expected get_option(%s) to return setting default: %s.', $name, $default ) );
		$this->assertEquals( $default, $setting->value() );
	}
开发者ID:staylor,项目名称:develop.svn.wordpress.org,代码行数:16,代码来源:setting.php


示例5: 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:pbearne,项目名称:contrib2core,代码行数:12,代码来源:setting.php


示例6: set_wp2android_theme_menu

 function set_wp2android_theme_menu($wp_customize)
 {
     $setting = new WP_Customize_Setting($wp_customize, 'wp2android_theme_menu', array('default' => ''));
     $menu = $setting->post_value();
     $wp_customize->add_setting($setting);
     if (!empty($menu)) {
         wp2android_plugin_menus()->setMenu($menu);
     }
 }
开发者ID:apppressers,项目名称:apppressers.github.io,代码行数:9,代码来源:switcher.php


示例7: _save_post_id

 /**
  * Save data in special option for better performance in query
  *
  * @param \WP_Customize_Setting $setting
  */
 protected function _save_post_id($setting)
 {
     Posts::update($setting->id, $setting->post_value());
 }
开发者ID:Viktor777,项目名称:wp-customize-builder,代码行数:9,代码来源:Post.php


示例8: test_multidimensional_value_when_previewed

 /**
  * Ensure that WP_Customize_Setting::value() can return a previewed value for aggregated multidimensionals.
  *
  * @ticket 37294
  */
 public function test_multidimensional_value_when_previewed()
 {
     WP_Customize_Setting::reset_aggregated_multidimensionals();
     $initial_value = 456;
     set_theme_mod('nav_menu_locations', array('primary' => $initial_value));
     $setting_id = 'nav_menu_locations[primary]';
     $setting = new WP_Customize_Setting($this->manager, $setting_id);
     $this->assertEquals($initial_value, $setting->value());
     $override_value = -123456;
     $this->manager->set_post_value($setting_id, $override_value);
     $setting->preview();
     $this->assertEquals($override_value, $setting->value());
 }
开发者ID:atimmer,项目名称:wordpress-develop-mirror,代码行数:18,代码来源:setting.php


示例9: post_value

 /**
  * Decode the $_POST['customized'] values for a specific Customize Setting.
  *
  * @since 3.4.0
  *
  * @param WP_Customize_Setting $setting A WP_Customize_Setting derived object
  * @return string $post_value Sanitized value
  */
 public function post_value($setting)
 {
     if (!isset($this->_post_values)) {
         if (isset($_POST['customized'])) {
             $this->_post_values = json_decode(wp_unslash($_POST['customized']), true);
         } else {
             $this->_post_values = false;
         }
     }
     if (isset($this->_post_values[$setting->id])) {
         return $setting->sanitize($this->_post_values[$setting->id]);
     }
 }
开发者ID:hachi4,项目名称:WordPress,代码行数:21,代码来源:class-wp-customize-manager.php


示例10: save_nav_menus_created_posts

 /**
  * Publish the auto-draft posts that were created for nav menu items.
  *
  * The post IDs will have been sanitized by already by
  * `WP_Customize_Nav_Menu_Items::sanitize_nav_menus_created_posts()` to
  * remove any post IDs for which the user cannot publish or for which the
  * post is not an auto-draft.
  *
  * @since 4.7.0
  * @access public
  *
  * @param WP_Customize_Setting $setting Customizer setting object.
  */
 public function save_nav_menus_created_posts($setting)
 {
     $post_ids = $setting->post_value();
     if (!empty($post_ids)) {
         foreach ($post_ids as $post_id) {
             wp_publish_post($post_id);
         }
     }
 }
开发者ID:nicholasgriffintn,项目名称:WordPress,代码行数:22,代码来源:class-wp-customize-nav-menus.php


示例11: save_nav_menus_created_posts

 /**
  * Publish the auto-draft posts that were created for nav menu items.
  *
  * The post IDs will have been sanitized by already by
  * `WP_Customize_Nav_Menu_Items::sanitize_nav_menus_created_posts()` to
  * remove any post IDs for which the user cannot publish or for which the
  * post is not an auto-draft.
  *
  * @since 4.7.0
  * @access public
  *
  * @param WP_Customize_Setting $setting Customizer setting object.
  */
 public function save_nav_menus_created_posts($setting)
 {
     $post_ids = $setting->post_value();
     if (!empty($post_ids)) {
         foreach ($post_ids as $post_id) {
             // Note that wp_publish_post() cannot be used because unique slugs need to be assigned.
             wp_update_post(array('ID' => $post_id, 'post_status' => 'publish'));
         }
     }
 }
开发者ID:aaemnnosttv,项目名称:develop.git.wordpress.org,代码行数:23,代码来源:class-wp-customize-nav-menus.php


示例12: test_previewing_with_switch_to_blog

	/**
	 * Ensure that previewing a setting is disabled when the current blog is switched.
	 *
	 * @ticket 31428
	 * @group multisite
	 */
	function test_previewing_with_switch_to_blog() {
		if ( ! is_multisite() ) {
			$this->markTestSkipped( 'Cannot test WP_Customize_Setting::is_current_blog_previewed() with switch_to_blog() if not on multisite.' );
		}

		$type = 'option';
		$name = 'blogdescription';
		$post_value = rand_str();
		$this->manager->set_post_value( $name, $post_value );
		$setting = new WP_Customize_Setting( $this->manager, $name, compact( 'type' ) );
		$this->assertNull( $setting->is_current_blog_previewed() );
		$setting->preview();
		$this->assertTrue( $setting->is_current_blog_previewed() );

		$blog_id = $this->factory->blog->create();
		switch_to_blog( $blog_id );
		$this->assertFalse( $setting->is_current_blog_previewed() );
		$this->assertNotEquals( $post_value, $setting->value() );
		$this->assertNotEquals( $post_value, get_option( $name ) );
		restore_current_blog();
	}
开发者ID:staylor,项目名称:develop.svn.wordpress.org,代码行数:27,代码来源:setting.php


示例13: save_nav_menus_created_posts

 /**
  * Publish the auto-draft posts that were created for nav menu items.
  *
  * The post IDs will have been sanitized by already by
  * `WP_Customize_Nav_Menu_Items::sanitize_nav_menus_created_posts()` to
  * remove any post IDs for which the user cannot publish or for which the
  * post is not an auto-draft.
  *
  * @since 4.7.0
  * @access public
  *
  * @param WP_Customize_Setting $setting Customizer setting object.
  */
 public function save_nav_menus_created_posts($setting)
 {
     $post_ids = $setting->post_value();
     if (!empty($post_ids)) {
         foreach ($post_ids as $post_id) {
             $target_status = 'attachment' === get_post_type($post_id) ? 'inherit' : 'publish';
             $args = array('ID' => $post_id, 'post_status' => $target_status);
             $post_name = get_post_meta($post_id, '_customize_draft_post_name', true);
             if ($post_name) {
                 $args['post_name'] = $post_name;
             }
             // Note that wp_publish_post() cannot be used because unique slugs need to be assigned.
             wp_update_post(wp_slash($args));
             delete_post_meta($post_id, '_customize_draft_post_name');
         }
     }
 }
开发者ID:CompositeUK,项目名称:clone.WordPress-Core,代码行数:30,代码来源:class-wp-customize-nav-menus.php


示例14: 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


示例15: test_option_autoloading

 /**
  * @ticket 33499
  */
 function test_option_autoloading()
 {
     global $wpdb;
     wp_set_current_user(self::factory()->user->create(array('role' => 'administrator')));
     $name = 'autoloaded1';
     $setting = new WP_Customize_Setting($this->manager, $name, array('type' => 'option'));
     $value = 'value1';
     $this->manager->set_post_value($setting->id, $value);
     $setting->save();
     $autoload = $wpdb->get_var($wpdb->prepare("SELECT autoload FROM {$wpdb->options} WHERE option_name = %s", $setting->id));
     $this->assertEquals('yes', $autoload);
     $this->assertEquals($value, get_option($name));
     $name = 'autoloaded2';
     $setting = new WP_Customize_Setting($this->manager, $name, array('type' => 'option', 'autoload' => true));
     $value = 'value2';
     $this->manager->set_post_value($setting->id, $value);
     $setting->save();
     $autoload = $wpdb->get_var($wpdb->prepare("SELECT autoload FROM {$wpdb->options} WHERE option_name = %s", $setting->id));
     $this->assertEquals('yes', $autoload);
     $this->assertEquals($value, get_option($name));
     $name = 'not-autoloaded1';
     $setting = new WP_Customize_Setting($this->manager, $name, array('type' => 'option', 'autoload' => false));
     $value = 'value3';
     $this->manager->set_post_value($setting->id, $value);
     $setting->save();
     $autoload = $wpdb->get_var($wpdb->prepare("SELECT autoload FROM {$wpdb->options} WHERE option_name = %s", $setting->id));
     $this->assertEquals('no', $autoload);
     $this->assertEquals($value, get_option($name));
     $id_base = 'multi-not-autoloaded';
     $setting1 = new WP_Customize_Setting($this->manager, $id_base . '[foo]', array('type' => 'option'));
     $setting2 = new WP_Customize_Setting($this->manager, $id_base . '[bar]', array('type' => 'option', 'autoload' => false));
     $this->manager->set_post_value($setting1->id, 'value1');
     $this->manager->set_post_value($setting2->id, 'value2');
     $setting1->save();
     $autoload = $wpdb->get_var($wpdb->prepare("SELECT autoload FROM {$wpdb->options} WHERE option_name = %s", $id_base));
     $this->assertEquals('no', $autoload, 'Even though setting1 did not indicate autoload (thus normally true), since another multidimensional option setting of the base did say autoload=false, it should be autoload=no');
 }
开发者ID:boonebgorges,项目名称:develop.wordpress,代码行数:40,代码来源:setting.php


示例16: post_value

 /**
  * Return the sanitized value for a given setting from the request's POST data.
  *
  * @since 3.4.0
  * @since 4.1.1 Introduced 'default' parameter.
  *
  * @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).
  * @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 $setting->sanitize($post_values[$setting->id]);
     } else {
         return $default;
     }
 }
开发者ID:RA2WP,项目名称:RA2WP,代码行数:19,代码来源:class-wp-customize-manager.php


示例17: save_nav_menus_created_posts

 /**
  * Publish the auto-draft posts that were created for nav menu items.
  *
  * The post IDs will have been sanitized by already by
  * `WP_Customize_Nav_Menu_Items::sanitize_nav_menus_created_posts()` to
  * remove any post IDs for which the user cannot publish or for which the
  * post is not an auto-draft.
  *
  * @since 4.7.0
  * @access public
  *
  * @param WP_Customize_Setting $setting Customizer setting object.
  */
 public function save_nav_menus_created_posts($setting)
 {
     $post_ids = $setting->post_value();
     if (!empty($post_ids)) {
         foreach ($post_ids as $post_id) {
             $target_status = 'attachment' === get_post_type($post_id) ? 'inherit' : 'publish';
             // Note that wp_publish_post() cannot be used because unique slugs need to be assigned.
             wp_update_post(array('ID' => $post_id, 'post_status' => $target_status));
         }
     }
 }
开发者ID:johnpbloch,项目名称:wordpress,代码行数:24,代码来源:class-wp-customize-nav-menus.php


示例18: value

 public function value()
 {
     $value = parent::value();
     if (!is_array($value)) {
         $value = array();
     }
     return $value;
 }
开发者ID:sayedwp,项目名称:supernova,代码行数:8,代码来源:class-nova-settings-repeater-setting.php


示例19: __construct

 /**
  * WP_Customize_REST_Resource_Setting constructor.
  *
  * @param \WP_Customize_Manager $manager Manager.
  * @param string                $id      Setting ID.
  * @param array                 $args    Setting args.
  * @throws Exception If the ID is in an invalid format.
  */
 public function __construct($manager, $id, $args = array())
 {
     if (!isset($args['sanitize_callback'])) {
         $args['sanitize_callback'] = array($this, 'sanitize');
     }
     if (!preg_match('#^rest_resource\\[(?P<route>.+?)]$#', $id, $matches)) {
         throw new Exception('Illegal setting id: ' . $id);
     }
     $this->route = trim($matches['route'], '/');
     if (!isset($args['plugin']) || !$args['plugin'] instanceof Plugin) {
         throw new Exception(sprintf('Missing plugin arg for %s', get_class($this)));
     }
     parent::__construct($manager, $id, $args);
 }
开发者ID:xwp,项目名称:wp-customize-rest-resources,代码行数:22,代码来源:class-wp-customize-rest-resource-setting.php


示例20: __construct

 /**
  * Constructor.
  *
  * Any supplied $args override class property defaults.
  *
  * @param \WP_Customize_Manager $manager Manager instance.
  * @param string                $id      An specific ID of the setting. Can be a
  *                                       theme mod or option name.
  * @param array                 $args    Setting arguments.
  * @throws Exception If $id is not valid for a widget.
  */
 public function __construct(\WP_Customize_Manager $manager, $id, array $args = array())
 {
     unset($args['type']);
     if (!preg_match(static::WIDGET_SETTING_ID_PATTERN, $id, $matches)) {
         throw new Exception("Illegal widget setting ID: {$id}");
     }
     $this->widget_id_base = $matches['widget_id_base'];
     if (isset($matches['widget_number'])) {
         $this->widget_number = intval($matches['widget_number']);
     }
     parent::__construct($manager, $id, $args);
     if (empty($this->widget_posts)) {
         throw new Exception('Missing argument: widget_posts');
     }
 }
开发者ID:BE-Webdesign,项目名称:wp-customize-widgets-plus,代码行数:26,代码来源:class-wp-customize-widget-setting.php



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP WP_Date_Query类代码示例发布时间:2022-05-23
下一篇:
PHP WP_Customize_Manager类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap