本文整理汇总了PHP中WP_Customize_Manager::set_post_value方法的典型用法代码示例。如果您正苦于以下问题:PHP WP_Customize_Manager::set_post_value方法的具体用法?PHP WP_Customize_Manager::set_post_value怎么用?PHP WP_Customize_Manager::set_post_value使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WP_Customize_Manager
的用法示例。
在下文中一共展示了WP_Customize_Manager::set_post_value方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1:
function set_customized_post_data( $customized ) {
$_POST['customized'] = wp_slash( wp_json_encode( $customized ) );
if ( $this->manager ) {
foreach ( $customized as $id => $value ) {
$this->manager->set_post_value( $id, $value );
}
}
}
示例2: array
/**
* Test protected update() method via the save() method, for deleted menu.
*
* @see WP_Customize_Nav_Menu_Item_Setting::update()
*/
function test_save_deleted()
{
do_action('customize_register', $this->wp_customize);
$menu_id = wp_create_nav_menu('Primary');
$post_id = $this->factory->post->create(array('post_title' => 'Hello World'));
$item_ids = array();
for ($i = 0; $i < 5; $i += 1) {
$item_id = wp_update_nav_menu_item($menu_id, 0, array('menu-item-type' => 'post_type', 'menu-item-object' => 'post', 'menu-item-object-id' => $post_id, 'menu-item-title' => "Item {$i}", 'menu-item-status' => 'publish', 'menu-item-position' => $i + 1));
$item_ids[] = $item_id;
}
$delete_item_id = $item_ids[2];
$setting_id = "nav_menu_item[{$delete_item_id}]";
$setting = new WP_Customize_Nav_Menu_Item_Setting($this->wp_customize, $setting_id);
$this->wp_customize->set_post_value($setting_id, false);
$current_items = wp_get_nav_menu_items($menu_id);
$this->assertContains($delete_item_id, wp_list_pluck($current_items, 'db_id'));
$setting->save();
$preview_items = wp_get_nav_menu_items($menu_id);
$this->assertNotEquals(count($current_items), count($preview_items));
$this->assertContains($delete_item_id, wp_list_pluck($current_items, 'db_id'));
// Verify the Ajax responses is being amended.
$save_response = apply_filters('customize_save_response', array());
$this->assertArrayHasKey('nav_menu_item_updates', $save_response);
$update_result = array_shift($save_response['nav_menu_item_updates']);
$this->assertArrayHasKey('post_id', $update_result);
$this->assertArrayHasKey('previous_post_id', $update_result);
$this->assertArrayHasKey('error', $update_result);
$this->assertArrayHasKey('status', $update_result);
$this->assertEquals($delete_item_id, $update_result['post_id']);
$this->assertNull($update_result['previous_post_id']);
$this->assertNull($update_result['error']);
$this->assertEquals('deleted', $update_result['status']);
}
示例3: array
/**
* Test save_nav_menus_created_posts.
*
* @covers WP_Customize_Nav_Menus::save_nav_menus_created_posts()
*/
function test_save_nav_menus_created_posts()
{
$menus = new WP_Customize_Nav_Menus($this->wp_customize);
do_action('customize_register', $this->wp_customize);
$post_ids = $this->factory()->post->create_many(3, array('post_status' => 'auto-draft', 'post_type' => 'post', 'post_name' => 'auto-draft'));
$pre_published_post_id = $this->factory()->post->create(array('post_status' => 'publish'));
$setting_id = 'nav_menus_created_posts';
$this->wp_customize->set_post_value($setting_id, array_merge($post_ids, array($pre_published_post_id)));
$setting = $this->wp_customize->get_setting($setting_id);
$this->assertInstanceOf('WP_Customize_Filter_Setting', $setting);
$this->assertEquals(array($menus, 'sanitize_nav_menus_created_posts'), $setting->sanitize_callback);
$this->assertEquals($post_ids, $setting->post_value());
foreach ($post_ids as $post_id) {
$this->assertEquals('auto-draft', get_post_status($post_id));
}
$save_action_count = did_action('customize_save_nav_menus_created_posts');
$setting->save();
$this->assertEquals($save_action_count + 1, did_action('customize_save_nav_menus_created_posts'));
foreach ($post_ids as $post_id) {
$this->assertEquals('publish', get_post_status($post_id));
}
// Ensure that unique slugs were assigned.
$posts = array_map('get_post', $post_ids);
$post_names = wp_list_pluck($posts, 'post_name');
$this->assertEqualSets($post_names, array_unique($post_names));
}
示例4: array
/**
* Test protected update() method via the save() method, for deleted menu.
*
* @see WP_Customize_Nav_Menu_Setting::update()
*/
function test_save_deleted()
{
do_action('customize_register', $this->wp_customize);
$menu_name = 'Lorem Ipsum';
$menu_id = wp_create_nav_menu($menu_name);
$setting_id = "nav_menu[{$menu_id}]";
$setting = new WP_Customize_Nav_Menu_Setting($this->wp_customize, $setting_id);
$nav_menu_options = $this->get_nav_menu_items_option();
$nav_menu_options['auto_add'][] = $menu_id;
update_option('nav_menu_options', $nav_menu_options);
$menu = wp_get_nav_menu_object($menu_id);
$this->assertEquals($menu_name, $menu->name);
$this->wp_customize->set_post_value($setting_id, false);
$setting->save();
$this->assertFalse(wp_get_nav_menu_object($menu_id));
$save_response = apply_filters('customize_save_response', array());
$this->assertArrayHasKey('nav_menu_updates', $save_response);
$update_result = array_shift($save_response['nav_menu_updates']);
$this->assertArrayHasKey('term_id', $update_result);
$this->assertArrayHasKey('previous_term_id', $update_result);
$this->assertArrayHasKey('error', $update_result);
$this->assertArrayHasKey('status', $update_result);
$this->assertArrayHasKey('saved_value', $update_result);
$this->assertNull($update_result['saved_value']);
$this->assertEquals($menu_id, $update_result['term_id']);
$this->assertNull($update_result['previous_term_id']);
$this->assertNull($update_result['error']);
$this->assertEquals('deleted', $update_result['status']);
$nav_menu_options = $this->get_nav_menu_items_option();
$this->assertNotContains($menu_id, $nav_menu_options['auto_add']);
}
示例5: array
/**
* Test save_nav_menus_created_posts.
*
* @covers WP_Customize_Nav_Menus::save_nav_menus_created_posts()
*/
function test_save_nav_menus_created_posts()
{
$menus = new WP_Customize_Nav_Menus($this->wp_customize);
do_action('customize_register', $this->wp_customize);
$post_ids = array();
for ($i = 0; $i < 3; $i += 1) {
$r = $menus->insert_auto_draft_post(array('post_title' => 'Auto Draft ' . $i, 'post_type' => 'post', 'post_name' => 'auto-draft-' . $i));
$this->assertInstanceOf('WP_Post', $r);
$post_ids[] = $r->ID;
}
$pre_published_post_id = $this->factory()->post->create(array('post_status' => 'publish'));
$setting_id = 'nav_menus_created_posts';
$this->wp_customize->set_post_value($setting_id, array_merge($post_ids, array($pre_published_post_id)));
$setting = $this->wp_customize->get_setting($setting_id);
$this->assertInstanceOf('WP_Customize_Filter_Setting', $setting);
$this->assertEquals(array($menus, 'sanitize_nav_menus_created_posts'), $setting->sanitize_callback);
$this->assertEquals($post_ids, $setting->post_value());
foreach ($post_ids as $post_id) {
$this->assertEquals('auto-draft', get_post_status($post_id));
$this->assertEmpty(get_post($post_id)->post_name);
$this->assertNotEmpty(get_post_meta($post_id, '_customize_draft_post_name', true));
}
$save_action_count = did_action('customize_save_nav_menus_created_posts');
$setting->save();
$this->assertEquals($save_action_count + 1, did_action('customize_save_nav_menus_created_posts'));
foreach ($post_ids as $post_id) {
$this->assertEquals('publish', get_post_status($post_id));
$this->assertRegExp('/^auto-draft-\\d+$/', get_post($post_id)->post_name);
$this->assertEmpty(get_post_meta($post_id, '_customize_draft_post_name', true));
}
// Ensure that unique slugs were assigned.
$posts = array_map('get_post', $post_ids);
$post_names = wp_list_pluck($posts, 'post_name');
$this->assertEqualSets($post_names, array_unique($post_names));
}
示例6: array
/**
* Test customize_preview_settings() method.
*
* @see WP_Customize_Manager::customize_preview_settings()
*/
function test_customize_preview_settings() {
wp_set_current_user( self::factory()->user->create( array( 'role' => 'administrator' ) ) );
$this->manager->register_controls();
$this->manager->prepare_controls();
$this->manager->set_post_value( 'foo', 'bar' );
$_POST['customize_messenger_channel'] = 'preview-0';
ob_start();
$this->manager->customize_preview_settings();
$content = ob_get_clean();
$this->assertEquals( 1, preg_match( '/var _wpCustomizeSettings = ({.+});/', $content, $matches ) );
$settings = json_decode( $matches[1], true );
$this->assertArrayHasKey( 'theme', $settings );
$this->assertArrayHasKey( 'url', $settings );
$this->assertArrayHasKey( 'channel', $settings );
$this->assertArrayHasKey( 'activePanels', $settings );
$this->assertArrayHasKey( 'activeSections', $settings );
$this->assertArrayHasKey( 'activeControls', $settings );
$this->assertArrayHasKey( 'nonce', $settings );
$this->assertArrayHasKey( '_dirty', $settings );
$this->assertArrayHasKey( 'preview', $settings['nonce'] );
$this->assertEquals( array( 'foo' ), $settings['_dirty'] );
}
示例7: array
/**
* Test WP_Customize_Nav_Menu_Item_Setting::value_as_wp_post_nav_menu_item().
*
* @see WP_Customize_Nav_Menu_Item_Setting::value_as_wp_post_nav_menu_item()
*/
function test_value_as_wp_post_nav_menu_item()
{
$post_id = self::factory()->post->create();
$setting = new WP_Customize_Nav_Menu_Item_Setting($this->wp_customize, 'nav_menu_item[123]');
$post_value = array('object_id' => $post_id, 'object' => 'post', 'menu_item_parent' => 0, 'position' => 2, 'type' => 'custom_type', 'title' => 'Hello \\o/ o\'o World', 'url' => '', 'target' => '', 'attr_title' => '">att \\o/ o\'o empted <b>baddie</b>', 'description' => 'Attempted \\o/ o\'o <b>markup</b>', 'classes' => '', 'xfn' => '', 'status' => 'publish', 'original_title' => '', 'nav_menu_term_id' => 0, '_invalid' => false);
$this->wp_customize->set_post_value($setting->id, $post_value);
$setting->preview();
$nav_menu_item = $setting->value_as_wp_post_nav_menu_item();
$this->assertEquals('Custom Link', $nav_menu_item->type_label);
add_filter('wp_setup_nav_menu_item', array($this, 'filter_type_label'));
$nav_menu_item = $setting->value_as_wp_post_nav_menu_item();
$this->assertEquals('Custom Label', $nav_menu_item->type_label);
$this->assertObjectNotHasAttribute('nav_menu_term_id', $nav_menu_item);
$this->assertObjectNotHasAttribute('status', $nav_menu_item);
$this->assertEquals('publish', $nav_menu_item->post_status);
$this->assertEquals('nav_menu_item', $nav_menu_item->post_type);
$this->assertObjectNotHasAttribute('position', $nav_menu_item);
$this->assertEquals($post_value['position'], $nav_menu_item->menu_order);
$this->assertEquals($post_value['title'], $nav_menu_item->post_title);
$this->assertEquals(123, $nav_menu_item->ID);
$this->assertEquals(123, $nav_menu_item->db_id);
$this->assertEquals(wp_get_current_user()->ID, $nav_menu_item->post_author);
$this->assertObjectHasAttribute('type_label', $nav_menu_item);
$expected = apply_filters('nav_menu_attr_title', wp_unslash(apply_filters('excerpt_save_pre', wp_slash($post_value['attr_title']))));
$this->assertEquals($expected, $nav_menu_item->attr_title);
$this->assertEquals('Attempted \\o/ o’o markup', $nav_menu_item->description);
}
示例8: array
/**
* @see \WP_Customize_Setting::save()
*/
function test_customize_widgets_save()
{
$initial_search_widgets = get_option('widget_search');
$widget_id = 'search-2';
$setting_id = 'widget_search[2]';
$override_widget_data = array('title' => 'Buscar');
$sanitized_widget_instance = $this->customize_manager->widgets->sanitize_widget_js_instance($override_widget_data);
$this->customize_manager->set_post_value($setting_id, $sanitized_widget_instance);
$widget_post = $this->widget_posts->get_widget_post($widget_id);
$this->assertEquals($initial_search_widgets[2], $this->widget_posts->get_widget_instance_data($widget_post));
do_action('customize_save', $this->customize_manager);
foreach ($this->customize_manager->settings() as $setting) {
/** @var \WP_Customize_Setting $setting */
$setting->save();
}
do_action('customize_save_after', $this->customize_manager);
$saved_data = $this->widget_posts->get_widget_instance_data($this->widget_posts->get_widget_post($widget_id));
$this->assertEquals($override_widget_data, $saved_data, 'Overridden widget data should be saved.');
$this->assertEquals($initial_search_widgets[3], $this->widget_posts->get_widget_instance_data($this->widget_posts->get_widget_post('search-3')), 'Untouched widget instance should remain intact.');
}
开发者ID:BE-Webdesign,项目名称:wp-customize-widgets-plus,代码行数:23,代码来源:test-class-widget-posts-with-customizer.php
示例9: array
/**
* Test WP_Customize_Nav_Menu_Item_Setting::value_as_wp_post_nav_menu_item() where title is empty.
*
* @ticket 38015
* @see WP_Customize_Nav_Menu_Item_Setting::value_as_wp_post_nav_menu_item()
*/
function test_value_as_wp_post_nav_menu_item_with_empty_title()
{
$original_title = 'The Original Title';
$post_id = self::factory()->post->create(array('post_title' => $original_title));
$setting = new WP_Customize_Nav_Menu_Item_Setting($this->wp_customize, 'nav_menu_item[123]');
$post_value = array_merge($setting->default, array('object_id' => $post_id, 'object' => 'post', 'type' => 'post_type', 'status' => 'publish', 'nav_menu_term_id' => 0));
$this->wp_customize->set_post_value($setting->id, $post_value);
$setting->preview();
$nav_menu_item = $setting->value_as_wp_post_nav_menu_item();
$this->assertEquals($original_title, $nav_menu_item->title);
}
示例10: 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());
}
示例11: filter_heartbeat_received
/**
* Filter for heartbeat data sent from client.
*
* @filter heartbeat_received
*
* @param array $response Data to send back to client.
* @param array $data Data sent from client.
* @param string $screen_id Current screen.
* @return array
*/
public function filter_heartbeat_received($response, $data, $screen_id)
{
$is_customize_concurrency = 'customize' === $screen_id && isset($data[self::SLUG]['last_update_timestamp_cursor']) && intval($data[self::SLUG]['last_update_timestamp_cursor']) > time() - $this->config('lock_window_seconds');
if (!$is_customize_concurrency) {
return $response;
}
if (empty($this->customize_manager)) {
require_once ABSPATH . WPINC . '/class-wp-customize-manager.php';
$GLOBALS['wp_customize'] = new \WP_Customize_Manager();
$this->customize_manager = $GLOBALS['wp_customize'];
}
do_action('customize_register', $this->customize_manager);
$next_update_timestamp_cursor = time();
$last_update_timestamp_cursor = absint($data[self::SLUG]['last_update_timestamp_cursor']);
$query_vars = array('post_type' => self::POST_TYPE, 'date_query' => array(array('after' => gmdate('c', $last_update_timestamp_cursor), 'inclusive' => true, 'column' => 'post_date_gmt')), 'posts_per_page' => 50);
$query = new \WP_Query($query_vars);
$setting_updates = array();
foreach ($query->posts as $post) {
if (intval($post->post_author) === intval(get_current_user_id())) {
continue;
}
$setting_id = $post->post_name;
$setting = $this->get_setting($setting_id);
$value = json_decode($post->post_content_filtered, true);
if (!$this->customize_manager->get_setting($setting_id)) {
$this->customize_manager->add_setting($setting);
$this->customize_manager->set_post_value($setting_id, $value);
$setting->preview();
}
/*
* @todo This filter is prevented from applying due to optimized-widget-registration.
* Make sure we account for why. Heartbeat may need to send the active widgets.
*/
if (!preg_match('/sidebars_widgets\\]?\\[/', $setting_id)) {
$value = apply_filters("customize_sanitize_js_{$setting_id}", $value, $setting);
}
$args = array('post_id' => $post->ID, 'post_status' => $post->post_status, 'post_author' => $this->get_preview_user_data($post->post_author), 'post_date' => strtotime($post->post_date_gmt), 'value' => $value, 'transport' => $setting->transport);
$setting_updates[$post->post_name] = $args;
}
/**
* Filters which settings have been updated.
*
* @param array $setting_updates Sanitized post values.
* @return array
*/
$setting_updates = apply_filters('customize_concurrency_settings', $setting_updates);
$response[self::SLUG] = array('next_update_timestamp_cursor' => $next_update_timestamp_cursor, 'old_last_update_timestamp_cursor' => $last_update_timestamp_cursor, 'setting_updates' => $setting_updates);
return $response;
}
示例12: array
/**
* Test update filter on WP_Customize_Custom_CSS_Setting.
*
* @covers WP_Customize_Custom_CSS_Setting::update()
*/
function test_update_filter()
{
$original_css = 'body { color:red; }';
$post_id = $this->factory()->post->create(array('post_title' => $this->setting->stylesheet, 'post_name' => $this->setting->stylesheet, 'post_content' => $original_css, 'post_status' => 'publish', 'post_type' => 'custom_css'));
$overridden_css = 'body { color:green; }';
$this->wp_customize->set_post_value($this->setting->id, $overridden_css);
$post = get_post($post_id);
$original_title = $post->post_title;
add_filter('update_custom_css_data', array($this, 'filter_update_custom_css_data'), 10, 3);
$this->setting->save();
$post = get_post($post_id);
$this->assertEquals($original_title, $post->post_title);
$this->assertContains($overridden_css, $post->post_content);
$this->assertContains('/* filtered post_content */', $post->post_content);
$this->assertContains('/* filtered post_content_filtered */', $post->post_content_filtered);
}
示例13:
/**
* @see WP_Customize_Widget_Setting::update()
*/
function test_save()
{
$widget_data = $this->get_sample_widget_instance_data('archives');
$args = $this->customize_manager->widgets->get_setting_args($widget_data['setting_id']);
$setting = new WP_Customize_Widget_Setting($this->customize_manager, $widget_data['setting_id'], $args);
$value = $setting->value();
$override_title = 'BAR UPDATED VALUE';
$this->assertNotEquals($value['title'], $override_title);
$value['title'] = $override_title;
$this->customize_manager->set_post_value($setting->id, $this->customize_manager->widgets->sanitize_widget_js_instance($value));
$setting->save();
$saved_value = $setting->value();
$this->assertEquals($override_title, $saved_value['title']);
$instances = get_option('widget_archives');
$this->assertEquals($saved_value, $instances[$widget_data['number']]);
}
开发者ID:BE-Webdesign,项目名称:wp-customize-widgets-plus,代码行数:19,代码来源:test-class-wp-customize-widget-setting.php
示例14: array
/**
* Test WP_Customize_Manager::set_post_value().
*
* @see WP_Customize_Manager::set_post_value()
*/
function test_set_post_value()
{
$this->manager->add_setting('foo', array('sanitize_callback' => array($this, 'sanitize_foo_for_test_set_post_value')));
$setting = $this->manager->get_setting('foo');
$this->assertEmpty($this->captured_customize_post_value_set_actions);
add_action('customize_post_value_set', array($this, 'capture_customize_post_value_set_actions'), 10, 3);
add_action('customize_post_value_set_foo', array($this, 'capture_customize_post_value_set_actions'), 10, 2);
$this->manager->set_post_value($setting->id, '123abc');
$this->assertCount(2, $this->captured_customize_post_value_set_actions);
$this->assertEquals('customize_post_value_set_foo', $this->captured_customize_post_value_set_actions[0]['action']);
$this->assertEquals('customize_post_value_set', $this->captured_customize_post_value_set_actions[1]['action']);
$this->assertEquals(array('123abc', $this->manager), $this->captured_customize_post_value_set_actions[0]['args']);
$this->assertEquals(array($setting->id, '123abc', $this->manager), $this->captured_customize_post_value_set_actions[1]['args']);
$unsanitized = $this->manager->unsanitized_post_values();
$this->assertArrayHasKey($setting->id, $unsanitized);
$this->assertEquals('123abc', $unsanitized[$setting->id]);
$this->assertEquals(123, $setting->post_value());
}
示例15: compact
/**
* 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->assertFalse($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();
}