當前位置: 首頁>>代碼示例>>PHP>>正文


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怎麽用?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.');
//.........這裏部分代碼省略.........
開發者ID:CompositeUK,項目名稱:clone.WordPress-Develop,代碼行數:101,代碼來源:manager.php


注:本文中的WP_Customize_Manager::find_changeset_post_id方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。