本文整理汇总了PHP中WP_Customize_Setting类的典型用法代码示例。如果您正苦于以下问题:PHP WP_Customize_Setting类的具体用法?PHP WP_Customize_Setting怎么用?PHP WP_Customize_Setting使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了WP_Customize_Setting类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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();
}
示例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);
}
示例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() );
}
示例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());
}
示例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);
}
}
示例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());
}
示例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());
}
示例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]);
}
}
示例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);
}
}
}
示例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'));
}
}
}
示例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();
}
示例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');
}
}
}
示例14: value
public function value()
{
$value = parent::value();
if (!is_array($value)) {
$value = array();
}
return $value;
}
示例15: __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