本文整理汇总了PHP中WP_Customize_Manager::find_changeset_post_id方法的典型用法代码示例。如果您正苦于以下问题:PHP WP_Customize_Manager::find_changeset_post_id方法的具体用法?PHP WP_Customize_Manager::find_changeset_post_id怎么用?PHP WP_Customize_Manager::find_changeset_post_id使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WP_Customize_Manager
的用法示例。
在下文中一共展示了WP_Customize_Manager::find_changeset_post_id方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: array
/**
* Test WP_Customize_Manager::save_changeset_post().
*
* @ticket 30937
* @covers WP_Customize_Manager::save_changeset_post()
*/
function test_save_changeset_post_without_theme_activation()
{
global $wp_customize;
wp_set_current_user(self::$admin_user_id);
$did_action = array('customize_save_validation_before' => did_action('customize_save_validation_before'), 'customize_save' => did_action('customize_save'), 'customize_save_after' => did_action('customize_save_after'));
$uuid = wp_generate_uuid4();
$wp_customize = $manager = new WP_Customize_Manager(array('changeset_uuid' => $uuid));
$wp_customize = $manager;
$manager->register_controls();
$manager->set_post_value('blogname', 'Changeset Title');
$manager->set_post_value('blogdescription', 'Changeset Tagline');
$pre_saved_data = array('blogname' => array('value' => 'Overridden Changeset Title'), 'blogdescription' => array('custom' => 'something'));
$date = gmdate('Y') + 1 . '-12-01 00:00:00';
$r = $manager->save_changeset_post(array('status' => 'auto-draft', 'title' => 'Auto Draft', 'date_gmt' => $date, 'data' => $pre_saved_data));
$this->assertInternalType('array', $r);
$this->assertEquals($did_action['customize_save_validation_before'] + 1, did_action('customize_save_validation_before'));
$post_id = $manager->find_changeset_post_id($uuid);
$this->assertNotNull($post_id);
$saved_data = json_decode(get_post($post_id)->post_content, true);
$this->assertEquals($manager->unsanitized_post_values(), wp_list_pluck($saved_data, 'value'));
$this->assertEquals($pre_saved_data['blogname']['value'], $saved_data['blogname']['value']);
$this->assertEquals($pre_saved_data['blogdescription']['custom'], $saved_data['blogdescription']['custom']);
foreach ($saved_data as $setting_id => $setting_params) {
$this->assertArrayHasKey('type', $setting_params);
$this->assertEquals('option', $setting_params['type']);
$this->assertArrayHasKey('user_id', $setting_params);
$this->assertEquals(self::$admin_user_id, $setting_params['user_id']);
}
$this->assertEquals('Auto Draft', get_post($post_id)->post_title);
$this->assertEquals('auto-draft', get_post($post_id)->post_status);
$this->assertEquals($date, get_post($post_id)->post_date_gmt);
$this->assertNotEquals('Changeset Title', get_option('blogname'));
$this->assertArrayHasKey('setting_validities', $r);
// Test saving with invalid settings, ensuring transaction blocked.
$previous_saved_data = $saved_data;
$manager->add_setting('foo_unauthorized', array('capability' => 'do_not_allow'));
$manager->add_setting('baz_illegal', array('validate_callback' => array($this, 'return_illegal_error')));
$r = $manager->save_changeset_post(array('status' => 'auto-draft', 'data' => array('blogname' => array('value' => 'OK'), 'foo_unauthorized' => array('value' => 'No'), 'bar_unknown' => array('value' => 'No'), 'baz_illegal' => array('value' => 'No'))));
$this->assertInstanceOf('WP_Error', $r);
$this->assertEquals('transaction_fail', $r->get_error_code());
$this->assertInternalType('array', $r->get_error_data());
$this->assertArrayHasKey('setting_validities', $r->get_error_data());
$error_data = $r->get_error_data();
$this->assertArrayHasKey('blogname', $error_data['setting_validities']);
$this->assertTrue($error_data['setting_validities']['blogname']);
$this->assertArrayHasKey('foo_unauthorized', $error_data['setting_validities']);
$this->assertInstanceOf('WP_Error', $error_data['setting_validities']['foo_unauthorized']);
$this->assertEquals('unauthorized', $error_data['setting_validities']['foo_unauthorized']->get_error_code());
$this->assertArrayHasKey('bar_unknown', $error_data['setting_validities']);
$this->assertInstanceOf('WP_Error', $error_data['setting_validities']['bar_unknown']);
$this->assertEquals('unrecognized', $error_data['setting_validities']['bar_unknown']->get_error_code());
$this->assertArrayHasKey('baz_illegal', $error_data['setting_validities']);
$this->assertInstanceOf('WP_Error', $error_data['setting_validities']['baz_illegal']);
$this->assertEquals('illegal', $error_data['setting_validities']['baz_illegal']->get_error_code());
// Since transactional, ensure no changes have been made.
$this->assertEquals($previous_saved_data, json_decode(get_post($post_id)->post_content, true));
// Attempt a non-transactional/incremental update.
$wp_customize = $manager = new WP_Customize_Manager(array('changeset_uuid' => $uuid));
$wp_customize = $manager;
$manager->register_controls();
// That is, register settings.
$r = $manager->save_changeset_post(array('status' => null, 'data' => array('blogname' => array('value' => 'Non-Transactional \\o/ <script>unsanitized</script>'), 'bar_unknown' => array('value' => 'No'))));
$this->assertInternalType('array', $r);
$this->assertArrayHasKey('setting_validities', $r);
$this->assertTrue($r['setting_validities']['blogname']);
$this->assertInstanceOf('WP_Error', $r['setting_validities']['bar_unknown']);
$saved_data = json_decode(get_post($post_id)->post_content, true);
$this->assertNotEquals($previous_saved_data, $saved_data);
$this->assertEquals('Non-Transactional \\o/ <script>unsanitized</script>', $saved_data['blogname']['value']);
// Ensure the filter applies.
$customize_changeset_save_data_call_count = $this->customize_changeset_save_data_call_count;
add_filter('customize_changeset_save_data', array($this, 'filter_customize_changeset_save_data'), 10, 2);
$manager->save_changeset_post(array('status' => null, 'data' => array('blogname' => array('value' => 'Filtered'))));
$this->assertEquals($customize_changeset_save_data_call_count + 1, $this->customize_changeset_save_data_call_count);
// Publish the changeset: actions will be doubled since also trashed.
$expected_actions = array('wp_trash_post' => 1, 'clean_post_cache' => 2, 'transition_post_status' => 2, 'publish_to_trash' => 1, 'trash_customize_changeset' => 1, 'edit_post' => 2, 'save_post_customize_changeset' => 2, 'save_post' => 2, 'wp_insert_post' => 2, 'trashed_post' => 1);
$action_counts = array();
foreach (array_keys($expected_actions) as $action_name) {
$action_counts[$action_name] = did_action($action_name);
}
$wp_customize = $manager = new WP_Customize_Manager(array('changeset_uuid' => $uuid));
do_action('customize_register', $wp_customize);
$manager->add_setting('scratchpad', array('type' => 'option', 'capability' => 'exist'));
$manager->get_setting('blogname')->capability = 'exist';
$original_capabilities = wp_list_pluck($manager->settings(), 'capability');
wp_set_current_user(self::$subscriber_user_id);
$r = $manager->save_changeset_post(array('status' => 'publish', 'data' => array('blogname' => array('value' => 'Do it live \\o/'), 'scratchpad' => array('value' => '<script>console.info( "HELLO" )</script>'))));
$this->assertInternalType('array', $r);
$this->assertEquals('Do it live \\o/', get_option('blogname'));
$this->assertEquals('trash', get_post_status($post_id));
// Auto-trashed.
$this->assertEquals($original_capabilities, wp_list_pluck($manager->settings(), 'capability'));
$this->assertContains('<script>', get_post($post_id)->post_content);
$this->assertEquals($manager->changeset_uuid(), get_post($post_id)->post_name, 'Expected that the "__trashed" suffix to not be added.');
//.........这里部分代码省略.........