本文整理汇总了PHP中mysql_to_rfc3339函数的典型用法代码示例。如果您正苦于以下问题:PHP mysql_to_rfc3339函数的具体用法?PHP mysql_to_rfc3339怎么用?PHP mysql_to_rfc3339使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了mysql_to_rfc3339函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: prepare_date_response
/**
* Check the post_date_gmt or modified_gmt and prepare any post or
* modified date for single post output.
*
* @param string $date_gmt
* @param string|null $date
* @return string|null ISO8601/RFC3339 formatted datetime.
*/
protected function prepare_date_response($date_gmt, $date = null)
{
if ('0000-00-00 00:00:00' === $date_gmt) {
return null;
}
if (isset($date)) {
return mysql_to_rfc3339($date);
}
return mysql_to_rfc3339($date_gmt);
}
示例2: wc_rest_prepare_date_response
/**
* Parses and formats a MySQL datetime (Y-m-d H:i:s) for ISO8601/RFC3339.
*
* Requered WP 4.4 or later.
* See https://developer.wordpress.org/reference/functions/mysql_to_rfc3339/
*
* @since 2.6.0
* @param string $date
* @return string|null ISO8601/RFC3339 formatted datetime.
*/
function wc_rest_prepare_date_response($date)
{
// Check if mysql_to_rfc3339 exists first!
if (!function_exists('mysql_to_rfc3339')) {
return null;
}
// Return null if $date is empty/zeros.
if ('0000-00-00 00:00:00' === $date || empty($date)) {
return null;
}
// Return the formatted datetime.
return mysql_to_rfc3339($date);
}
示例3: wc_rest_prepare_date_response
/**
* Parses and formats a MySQL datetime (Y-m-d H:i:s) for ISO8601/RFC3339.
*
* Required WP 4.4 or later.
* See https://developer.wordpress.org/reference/functions/mysql_to_rfc3339/
*
* @since 2.6.0
* @param string $date
* @return string|null ISO8601/RFC3339 formatted datetime.
*/
function wc_rest_prepare_date_response($date)
{
if (false === strpos($date, '-')) {
$date = date('Y-m-d H:i:s', $date);
}
// Check if mysql_to_rfc3339 exists first!
if (!function_exists('mysql_to_rfc3339')) {
return null;
}
// Return null if $date is empty/zeros.
if ('0000-00-00 00:00:00' === $date || empty($date)) {
return null;
}
// Return the formatted datetime.
return mysql_to_rfc3339($date);
}
示例4: wc_rest_prepare_date_response
/**
* Parses and formats a MySQL datetime (Y-m-d H:i:s) for ISO8601/RFC3339.
*
* Requered WP 4.4 or later.
* See https://developer.wordpress.org/reference/functions/mysql_to_rfc3339/
*
* @since 2.6.0
* @param string $date_gmt
* @param string|null $date
* @return string|null ISO8601/RFC3339 formatted datetime.
*/
function wc_rest_prepare_date_response($date_gmt, $date = null)
{
// Check if mysql_to_rfc3339 exists first!
if (!function_exists('mysql_to_rfc3339')) {
return null;
}
// Use the date if passed.
if (isset($date)) {
return mysql_to_rfc3339($date);
}
// Return null if $date_gmt is empty/zeros.
if ('0000-00-00 00:00:00' === $date_gmt) {
return null;
}
// Return the formatted datetime.
return mysql_to_rfc3339($date_gmt);
}
示例5: test_mysql_to_rfc3339
/**
* @ticket 36054
* @dataProvider datetime_provider
*/
function test_mysql_to_rfc3339($expected, $actual)
{
$date_return = mysql_to_rfc3339($actual);
$this->assertTrue(is_string($date_return), 'The date return must be a string');
$this->assertNotEmpty($date_return, 'The date return could not be an empty string');
$this->assertEquals($expected, $date_return, 'The date does not match');
$this->assertEquals(new DateTime($expected), new DateTime($date_return), 'The date is not the same after the call method');
}
示例6: check_post_data
protected function check_post_data($post, $data, $context)
{
$post_type_obj = get_post_type_object($post->post_type);
// Standard fields
$this->assertEquals($post->ID, $data['id']);
$this->assertEquals($post->post_name, $data['slug']);
$this->assertEquals(get_permalink($post->ID), $data['link']);
if ('0000-00-00 00:00:00' === $post->post_date_gmt) {
$this->assertNull($data['date']);
} else {
$this->assertEquals(mysql_to_rfc3339($post->post_date), $data['date']);
}
if ('0000-00-00 00:00:00' === $post->post_modified_gmt) {
$this->assertNull($data['modified']);
} else {
$this->assertEquals(mysql_to_rfc3339($post->post_modified), $data['modified']);
}
// author
if (post_type_supports($post->post_type, 'author')) {
$this->assertEquals($post->post_author, $data['author']);
} else {
$this->assertEmpty($data['author']);
}
// post_parent
if ($post_type_obj->hierarchical) {
$this->assertArrayHasKey('parent', $data);
if ($post->post_parent) {
if (is_int($data['parent'])) {
$this->assertEquals($post->post_parent, $data['parent']);
} else {
$this->assertEquals($post->post_parent, $data['parent']['id']);
$this->check_get_post_response($data['parent'], get_post($data['parent']['id']), 'view-parent');
}
} else {
$this->assertEmpty($data['parent']);
}
} else {
$this->assertFalse(isset($data['parent']));
}
// page attributes
if ($post_type_obj->hierarchical && post_type_supports($post->post_type, 'page-attributes')) {
$this->assertEquals($post->menu_order, $data['menu_order']);
} else {
$this->assertFalse(isset($data['menu_order']));
}
// Comments
if (post_type_supports($post->post_type, 'comments')) {
$this->assertEquals($post->comment_status, $data['comment_status']);
$this->assertEquals($post->ping_status, $data['ping_status']);
} else {
$this->assertFalse(isset($data['comment_status']));
$this->assertFalse(isset($data['ping_status']));
}
if ('post' === $post->post_type) {
$this->assertEquals(is_sticky($post->ID), $data['sticky']);
}
if ('page' === $post->post_type) {
$this->assertEquals(get_page_template_slug($post->ID), $data['template']);
}
if (post_type_supports($post->post_type, 'thumbnail')) {
$this->assertEquals((int) get_post_thumbnail_id($post->ID), $data['featured_image']);
} else {
$this->assertFalse(isset($data['featured_image']));
}
// Check post format.
if (post_type_supports($post->post_type, 'post-formats')) {
$post_format = get_post_format($post->ID);
if (empty($post_format)) {
$this->assertEquals('standard', $data['format']);
} else {
$this->assertEquals(get_post_format($post->ID), $data['format']);
}
} else {
$this->assertFalse(isset($data['format']));
}
// Check filtered values.
if (post_type_supports($post->post_type, 'title')) {
$this->assertEquals(get_the_title($post->ID), $data['title']['rendered']);
if ('edit' === $context) {
$this->assertEquals($post->post_title, $data['title']['raw']);
} else {
$this->assertFalse(isset($data['title']['raw']));
}
} else {
$this->assertFalse(isset($data['title']));
}
if (post_type_supports($post->post_type, 'editor')) {
// TODO: apply content filter for more accurate testing.
$this->assertEquals(wpautop($post->post_content), $data['content']['rendered']);
if ('edit' === $context) {
$this->assertEquals($post->post_content, $data['content']['raw']);
} else {
$this->assertFalse(isset($data['content']['raw']));
}
} else {
$this->assertFalse(isset($data['content']));
}
if (post_type_supports($post->post_type, 'excerpt')) {
if (empty($post->post_password)) {
// TODO: apply excerpt filter for more accurate testing.
//.........这里部分代码省略.........
开发者ID:misfist,项目名称:missdrepants-network,代码行数:101,代码来源:class-wp-test-rest-post-type-controller-testcase.php
示例7: create_entity_from_wpdb_result
/**
* Changes database results into REST API entities
* @param \EEM_Base $model
* @param array $db_row like results from $wpdb->get_results()
* @param string $include string indicating which fields to include in the response,
* including fields on related entities.
* Eg, when querying for events, an include string like:
* "...&include=EVT_name,EVT_desc,Datetime, Datetime.Ticket.TKT_ID, Datetime.Ticket.TKT_name, Datetime.Ticket.TKT_price"
* instructs us to only include the event's name and description,
* each related datetime, and each related datetime's ticket's name and price.
* Eg json would be:
* '{
* "EVT_ID":12,
* "EVT_name":"star wars party",
* "EVT_desc":"this is the party you are looking for...",
* "datetimes":[{
* "DTT_ID":123,...,
* "tickets":[{
* "TKT_ID":234,
* "TKT_name":"student rate",
* "TKT_price":32.0
* },...]
* }]
* }',
* ie, events with all their associated datetimes
* (including ones that are trashed) embedded in the json object,
* and each datetime also has each associated ticket embedded in its json object.
* @param string $context one of the return values from EEM_Base::valid_cap_contexts()
* @return array ready for being converted into json for sending to client
*/
public function create_entity_from_wpdb_result($model, $db_row, $include, $context)
{
if ($include == null) {
$include = '*';
}
if ($context == null) {
$context = \EEM_Base::caps_read;
}
$result = $model->deduce_fields_n_values_from_cols_n_values($db_row);
$result = array_intersect_key($result, $this->get_model_version_info()->fields_on_model_in_this_version($model));
foreach ($result as $field_name => $raw_field_value) {
$field_obj = $model->field_settings_for($field_name);
$field_value = $field_obj->prepare_for_set_from_db($raw_field_value);
if ($this->is_subclass_of_one($field_obj, $this->get_model_version_info()->fields_ignored())) {
unset($result[$field_name]);
} elseif ($this->is_subclass_of_one($field_obj, $this->get_model_version_info()->fields_that_have_rendered_format())) {
$result[$field_name] = array('raw' => $field_obj->prepare_for_get($field_value), 'rendered' => $field_obj->prepare_for_pretty_echoing($field_value));
} elseif ($this->is_subclass_of_one($field_obj, $this->get_model_version_info()->fields_that_have_pretty_format())) {
$result[$field_name] = array('raw' => $field_obj->prepare_for_get($field_value), 'pretty' => $field_obj->prepare_for_pretty_echoing($field_value));
} elseif ($field_obj instanceof \EE_Datetime_Field) {
if ($raw_field_value instanceof \DateTime) {
$raw_field_value = $raw_field_value->format('c');
}
$result[$field_name] = mysql_to_rfc3339($raw_field_value);
} else {
$value_prepared = $field_obj->prepare_for_get($field_value);
$result[$field_name] = $value_prepared === INF ? EE_INF_IN_DB : $value_prepared;
}
}
if ($model instanceof \EEM_CPT_Base) {
$attachment = wp_get_attachment_image_src(get_post_thumbnail_id($db_row[$model->get_primary_key_field()->get_qualified_column()]), 'full');
$result['featured_image_url'] = !empty($attachment) ? $attachment[0] : null;
$result['link'] = get_permalink($db_row[$model->get_primary_key_field()->get_qualified_column()]);
}
//add links to related data
$result['_links'] = array('self' => array(array('href' => $this->get_versioned_link_to(\EEH_Inflector::pluralize_and_lower($model->get_this_model_name()) . '/' . $result[$model->primary_key_name()]))), 'collection' => array(array('href' => $this->get_versioned_link_to(\EEH_Inflector::pluralize_and_lower($model->get_this_model_name())))));
global $wp_rest_server;
if ($model instanceof \EEM_CPT_Base && $wp_rest_server instanceof \WP_REST_Server && $wp_rest_server->get_route_options('/wp/v2/posts')) {
$result['_links'][\EED_Core_Rest_Api::ee_api_link_namespace . 'self_wp_post'] = array(array('href' => rest_url('/wp/v2/posts/' . $db_row[$model->get_primary_key_field()->get_qualified_column()]), 'single' => true));
}
//filter fields if specified
$includes_for_this_model = $this->extract_includes_for_this_model($include);
if (!empty($includes_for_this_model)) {
if ($model->has_primary_key_field()) {
//always include the primary key
$includes_for_this_model[] = $model->primary_key_name();
}
$result = array_intersect_key($result, array_flip($includes_for_this_model));
}
//add meta links and possibly include related models
$relation_settings = apply_filters('FHEE__Read__create_entity_from_wpdb_result__related_models_to_include', $model->relation_settings());
foreach ($relation_settings as $relation_name => $relation_obj) {
$related_model_part = $this->get_related_entity_name($relation_name, $relation_obj);
if (empty($includes_for_this_model) || isset($includes_for_this_model['meta'])) {
$result['_links'][\EED_Core_Rest_Api::ee_api_link_namespace . $related_model_part] = array(array('href' => $this->get_versioned_link_to(\EEH_Inflector::pluralize_and_lower($model->get_this_model_name()) . '/' . $result[$model->primary_key_name()] . '/' . $related_model_part), 'single' => $relation_obj instanceof \EE_Belongs_To_Relation ? true : false));
}
$related_fields_to_include = $this->extract_includes_for_this_model($include, $relation_name);
if ($related_fields_to_include) {
$pretend_related_request = new \WP_REST_Request();
$pretend_related_request->set_query_params(array('caps' => $context, 'include' => $this->extract_includes_for_this_model($include, $relation_name)));
$related_results = $this->get_entities_from_relation($result[$model->primary_key_name()], $relation_obj, $pretend_related_request);
$result[$related_model_part] = $related_results instanceof \WP_Error ? null : $related_results;
}
}
$result = apply_filters('FHEE__Read__create_entity_from_wpdb_results__entity_before_inaccessible_field_removal', $result, $model, $context);
$result_without_inaccessible_fields = Capabilities::filter_out_inaccessible_entity_fields($result, $model, $context, $this->get_model_version_info());
$this->_set_debug_info('inaccessible fields', array_keys(array_diff_key($result, $result_without_inaccessible_fields)));
return apply_filters('FHEE__Read__create_entity_from_wpdb_results__entity_return', $result_without_inaccessible_fields, $model, $context);
}
示例8: test_update_post_ignore_readonly
public function test_update_post_ignore_readonly()
{
wp_set_current_user(self::$editor_id);
$new_content = rand_str();
$expected_modified = current_time('mysql');
$request = new WP_REST_Request('PUT', sprintf('/wp/v2/posts/%d', self::$post_id));
$params = $this->set_post_data(array('modified' => '2010-06-01T02:00:00Z', 'content' => $new_content));
$request->set_body_params($params);
$response = $this->server->dispatch($request);
// The readonly modified param should be ignored, request should be a success.
$data = $response->get_data();
$new_post = get_post($data['id']);
$this->assertEquals($new_content, $data['content']['raw']);
$this->assertEquals($new_content, $new_post->post_content);
// The modified date should equal the current time.
$this->assertEquals(date('Y-m-d', strtotime(mysql_to_rfc3339($expected_modified))), date('Y-m-d', strtotime($data['modified'])));
$this->assertEquals(date('Y-m-d', strtotime($expected_modified)), date('Y-m-d', strtotime($new_post->post_modified)));
}
示例9: prepare_item_for_response
/**
* Prepare a single comment output for response.
*
* @param object $comment Comment object.
* @param WP_REST_Request $request Request object.
* @return WP_REST_Response
*/
public function prepare_item_for_response($comment, $request)
{
$data = array('id' => (int) $comment->comment_ID, 'post' => (int) $comment->comment_post_ID, 'parent' => (int) $comment->comment_parent, 'author' => (int) $comment->user_id, 'author_name' => $comment->comment_author, 'author_email' => $comment->comment_author_email, 'author_url' => $comment->comment_author_url, 'author_ip' => $comment->comment_author_IP, 'author_avatar_urls' => rest_get_avatar_urls($comment->comment_author_email), 'author_user_agent' => $comment->comment_agent, 'date' => mysql_to_rfc3339($comment->comment_date), 'date_gmt' => mysql_to_rfc3339($comment->comment_date_gmt), 'content' => array('rendered' => apply_filters('comment_text', $comment->comment_content, $comment), 'raw' => $comment->comment_content), 'karma' => (int) $comment->comment_karma, 'link' => get_comment_link($comment), 'status' => $this->prepare_status_response($comment->comment_approved), 'type' => get_comment_type($comment->comment_ID));
$context = !empty($request['context']) ? $request['context'] : 'view';
$data = $this->filter_response_by_context($data, $context);
$data = $this->add_additional_fields_to_object($data, $request);
// Wrap the data in a response object
$response = rest_ensure_response($data);
$response->add_links($this->prepare_links($comment));
/**
* Filter a comment returned from the API.
*
* Allows modification of the comment right before it is returned.
*
* @param WP_REST_Response $response The response object.
* @param object $comment The original comment object.
* @param WP_REST_Request $request Request used to generate the response.
*/
return apply_filters('rest_prepare_comment', $response, $comment, $request);
}
示例10: check_comment_data
protected function check_comment_data($data, $context, $links)
{
$comment = get_comment($data['id']);
$this->assertEquals($comment->comment_ID, $data['id']);
$this->assertEquals($comment->comment_post_ID, $data['post']);
$this->assertEquals($comment->comment_parent, $data['parent']);
$this->assertEquals($comment->user_id, $data['author']);
$this->assertEquals($comment->comment_author, $data['author_name']);
$this->assertEquals($comment->comment_author_url, $data['author_url']);
$this->assertEquals(wpautop($comment->comment_content), $data['content']['rendered']);
$this->assertEquals(mysql_to_rfc3339($comment->comment_date), $data['date']);
$this->assertEquals(mysql_to_rfc3339($comment->comment_date_gmt), $data['date_gmt']);
$this->assertEquals(get_comment_link($comment), $data['link']);
$this->assertContains('author_avatar_urls', $data);
$this->assertEqualSets(array('self', 'collection', 'up'), array_keys($links));
if ('edit' === $context) {
$this->assertEquals($comment->comment_author_email, $data['author_email']);
$this->assertEquals($comment->comment_author_IP, $data['author_ip']);
$this->assertEquals($comment->comment_agent, $data['author_user_agent']);
$this->assertEquals($comment->comment_content, $data['content']['raw']);
$this->assertEquals($comment->comment_karma, $data['karma']);
}
if ('edit' !== $context) {
$this->assertArrayNotHasKey('author_email', $data);
$this->assertArrayNotHasKey('author_ip', $data);
$this->assertArrayNotHasKey('author_user_agent', $data);
$this->assertArrayNotHasKey('raw', $data['content']);
$this->assertArrayNotHasKey('karma', $data);
}
}
示例11: check_post_data
protected function check_post_data($post, $data, $context, $links)
{
$post_type_obj = get_post_type_object($post->post_type);
// Standard fields
$this->assertEquals($post->ID, $data['id']);
$this->assertEquals($post->post_name, $data['slug']);
$this->assertEquals(get_permalink($post->ID), $data['link']);
if ('0000-00-00 00:00:00' === $post->post_date_gmt) {
$this->assertNull($data['date_gmt']);
}
$this->assertEquals(mysql_to_rfc3339($post->post_date), $data['date']);
if ('0000-00-00 00:00:00' === $post->post_modified_gmt) {
$this->assertNull($data['modified_gmt']);
}
$this->assertEquals(mysql_to_rfc3339($post->post_modified), $data['modified']);
// author
if (post_type_supports($post->post_type, 'author')) {
$this->assertEquals($post->post_author, $data['author']);
} else {
$this->assertEmpty($data['author']);
}
// post_parent
if ($post_type_obj->hierarchical) {
$this->assertArrayHasKey('parent', $data);
if ($post->post_parent) {
if (is_int($data['parent'])) {
$this->assertEquals($post->post_parent, $data['parent']);
} else {
$this->assertEquals($post->post_parent, $data['parent']['id']);
$this->check_get_post_response($data['parent'], get_post($data['parent']['id']), 'view-parent');
}
} else {
$this->assertEmpty($data['parent']);
}
} else {
$this->assertFalse(isset($data['parent']));
}
// page attributes
if ($post_type_obj->hierarchical && post_type_supports($post->post_type, 'page-attributes')) {
$this->assertEquals($post->menu_order, $data['menu_order']);
} else {
$this->assertFalse(isset($data['menu_order']));
}
// Comments
if (post_type_supports($post->post_type, 'comments')) {
$this->assertEquals($post->comment_status, $data['comment_status']);
$this->assertEquals($post->ping_status, $data['ping_status']);
} else {
$this->assertFalse(isset($data['comment_status']));
$this->assertFalse(isset($data['ping_status']));
}
if ('post' === $post->post_type) {
$this->assertEquals(is_sticky($post->ID), $data['sticky']);
}
if ('post' === $post->post_type && 'edit' === $context) {
$this->assertEquals($post->post_password, $data['password']);
}
if ('page' === $post->post_type) {
$this->assertEquals(get_page_template_slug($post->ID), $data['template']);
}
if (post_type_supports($post->post_type, 'thumbnail')) {
$this->assertEquals((int) get_post_thumbnail_id($post->ID), $data['featured_media']);
} else {
$this->assertFalse(isset($data['featured_media']));
}
// Check post format.
if (post_type_supports($post->post_type, 'post-formats')) {
$post_format = get_post_format($post->ID);
if (empty($post_format)) {
$this->assertEquals('standard', $data['format']);
} else {
$this->assertEquals(get_post_format($post->ID), $data['format']);
}
} else {
$this->assertFalse(isset($data['format']));
}
// Check filtered values.
if (post_type_supports($post->post_type, 'title')) {
add_filter('protected_title_format', array($this, 'protected_title_format'));
$this->assertEquals(get_the_title($post->ID), $data['title']['rendered']);
remove_filter('protected_title_format', array($this, 'protected_title_format'));
if ('edit' === $context) {
$this->assertEquals($post->post_title, $data['title']['raw']);
} else {
$this->assertFalse(isset($data['title']['raw']));
}
} else {
$this->assertFalse(isset($data['title']));
}
if (post_type_supports($post->post_type, 'editor')) {
// TODO: apply content filter for more accurate testing.
if (!$post->post_password) {
$this->assertEquals(wpautop($post->post_content), $data['content']['rendered']);
}
if ('edit' === $context) {
$this->assertEquals($post->post_content, $data['content']['raw']);
} else {
$this->assertFalse(isset($data['content']['raw']));
}
} else {
//.........这里部分代码省略.........
开发者ID:aaemnnosttv,项目名称:develop.git.wordpress.org,代码行数:101,代码来源:testcase-rest-post-type-controller.php
示例12: prepare_item_for_response
/**
* Prepare a single comment output for response.
*
* @param object $comment Comment object.
* @param WP_REST_Request $request Request object.
* @return WP_REST_Response
*/
public function prepare_item_for_response($comment, $request)
{
$data = array('id' => (int) $comment->comment_ID, 'post' => (int) $comment->comment_post_ID, 'parent' => (int) $comment->comment_parent, 'author' => (int) $comment->user_id, 'author_name' => $comment->comment_author, 'author_email' => $comment->comment_author_email, 'author_url' => $comment->comment_author_url, 'author_ip' => $comment->comment_author_IP, 'author_avatar_urls' => rest_get_avatar_urls($comment->comment_author_email), 'author_user_agent' => $comment->comment_agent, 'date' => mysql_to_rfc3339($comment->comment_date), 'date_gmt' => mysql_to_rfc3339($comment->comment_date_gmt), 'content' => array('rendered' => apply_filters('comment_text', $comment->comment_content, $comment), 'raw' => $comment->comment_content), 'karma' => (int) $comment->comment_karma, 'link' => get_comment_link($comment), 'status' => $this->prepare_status_response($comment->comment_approved), 'type' => get_comment_type($comment->comment_ID));
$context = !empty($request['context']) ? $request['context'] : 'view';
$data = $this->filter_response_by_context($data, $context);
$data = $this->add_additional_fields_to_object($data, $request);
// Wrap the data in a response object
$data = rest_ensure_response($data);
$data->add_links($this->prepare_links($comment));
return apply_filters('rest_prepare_comment', $data, $comment, $request);
}
示例13: check_get_revision_response
protected function check_get_revision_response($response, $revision)
{
if ($response instanceof WP_REST_Response) {
$links = $response->get_links();
$response = $response->get_data();
} else {
$this->assertArrayHasKey('_links', $response);
$links = $response['_links'];
}
$this->assertEquals($revision->post_author, $response['author']);
$rendered_content = apply_filters('the_content', $revision->post_content);
$this->assertEquals($rendered_content, $response['content']['rendered']);
$this->assertEquals(mysql_to_rfc3339($revision->post_date), $response['date']);
$this->assertEquals(mysql_to_rfc3339($revision->post_date_gmt), $response['date_gmt']);
$rendered_excerpt = apply_filters('the_excerpt', apply_filters('get_the_excerpt', $revision->post_excerpt, $revision));
$this->assertEquals($rendered_excerpt, $response['excerpt']['rendered']);
$rendered_guid = apply_filters('get_the_guid', $revision->guid);
$this->assertEquals($rendered_guid, $response['guid']['rendered']);
$this->assertEquals($revision->ID, $response['id']);
$this->assertEquals(mysql_to_rfc3339($revision->post_modified), $response['modified']);
$this->assertEquals(mysql_to_rfc3339($revision->post_modified_gmt), $response['modified_gmt']);
$this->assertEquals($revision->post_name, $response['slug']);
$rendered_title = get_the_title($revision->ID);
$this->assertEquals($rendered_title, $response['title']['rendered']);
$parent = get_post($revision->post_parent);
$parent_controller = new WP_REST_Posts_Controller($parent->post_type);
$parent_object = get_post_type_object($parent->post_type);
$parent_base = !empty($parent_object->rest_base) ? $parent_object->rest_base : $parent_object->name;
$this->assertEquals(rest_url('/wp/v2/' . $parent_base . '/' . $revision->post_parent), $links['parent'][0]['href']);
}
示例14: check_get_revision_response
protected function check_get_revision_response($response, $revision)
{
if ($response instanceof WP_REST_Response) {
$links = $response->get_links();
$response = $response->get_data();
} else {
$this->assertArrayHasKey('_links', $response);
$links = $response['_links'];
}
$this->assertEquals($revision->post_author, $response['author']);
$this->assertEquals($revision->post_content, $response['content']);
$this->assertEquals(mysql_to_rfc3339($revision->post_date), $response['date']);
$this->assertEquals(mysql_to_rfc3339($revision->post_date_gmt), $response['date_gmt']);
$this->assertEquals($revision->post_excerpt, $response['excerpt']);
$this->assertEquals($revision->guid, $response['guid']);
$this->assertEquals($revision->ID, $response['id']);
$this->assertEquals(mysql_to_rfc3339($revision->post_modified), $response['modified']);
$this->assertEquals(mysql_to_rfc3339($revision->post_modified_gmt), $response['modified_gmt']);
$this->assertEquals($revision->post_name, $response['slug']);
$this->assertEquals($revision->post_title, $response['title']);
$parent = get_post($revision->post_parent);
$parent_controller = new WP_REST_Posts_Controller($parent->post_type);
$parent_base = $parent_controller->get_post_type_base($parent->post_type);
$this->assertEquals(rest_url('wp/' . $parent_base . '/' . $revision->post_parent), $links['parent'][0]['href']);
}
示例15: prepare_date_response
/**
* Checks the post_date_gmt or modified_gmt and prepare any post or
* modified date for single post output.
*
* @since 4.7.0
* @access protected
*
* @param string $date_gmt GMT publication time.
* @param string|null $date Optional. Local publication time. Default null.
* @return string|null ISO8601/RFC3339 formatted datetime.
*/
protected function prepare_date_response($date_gmt, $date = null)
{
// Use the date if passed.
if (isset($date)) {
return mysql_to_rfc3339($date);
}
// Return null if $date_gmt is empty/zeros.
if ('0000-00-00 00:00:00' === $date_gmt) {
return null;
}
// Return the formatted datetime.
return mysql_to_rfc3339($date_gmt);
}