summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/jetpack/json-endpoints/class.wpcom-json-api-get-autosave-v1-1-endpoint.php')
-rw-r--r--plugins/jetpack/json-endpoints/class.wpcom-json-api-get-autosave-v1-1-endpoint.php88
1 files changed, 55 insertions, 33 deletions
diff --git a/plugins/jetpack/json-endpoints/class.wpcom-json-api-get-autosave-v1-1-endpoint.php b/plugins/jetpack/json-endpoints/class.wpcom-json-api-get-autosave-v1-1-endpoint.php
index 9970120a..51ffba52 100644
--- a/plugins/jetpack/json-endpoints/class.wpcom-json-api-get-autosave-v1-1-endpoint.php
+++ b/plugins/jetpack/json-endpoints/class.wpcom-json-api-get-autosave-v1-1-endpoint.php
@@ -1,37 +1,53 @@
-<?php
+<?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName
+/**
+ * WPCOM_JSON_API_Get_Autosave_v1_1_Endpoint
+ *
+ * @package automattic/jetpack
+ */
-new WPCOM_JSON_API_Get_Autosave_v1_1_Endpoint( array(
- 'description' => 'Get the most recent autosave for a post.',
- 'group' => '__do_not_document',
- 'stat' => 'posts:autosave',
- 'min_version' => '1.1',
- 'method' => 'GET',
- 'path' => '/sites/%s/posts/%d/autosave',
- 'path_labels' => array(
- '$site' => '(int|string) Site ID or domain',
- '$post_ID' => '(int) The post ID',
- ),
- 'response_format' => array(
- 'ID' => '(int) autodraft post ID',
- 'post_ID' => '(int) post ID',
- 'author_ID' => '(int) author ID',
- 'title' => '(HTML) The post title.',
- 'content' => '(HTML) The post content.',
- 'excerpt' => '(HTML) The post excerpt.',
- 'preview_URL' => '(string) preview URL for the post',
- 'modified' => '(ISO 8601 datetime) modified time',
- ),
+new WPCOM_JSON_API_Get_Autosave_v1_1_Endpoint(
+ array(
+ 'description' => 'Get the most recent autosave for a post.',
+ 'group' => '__do_not_document',
+ 'stat' => 'posts:autosave',
+ 'min_version' => '1.1',
+ 'method' => 'GET',
+ 'path' => '/sites/%s/posts/%d/autosave',
+ 'path_labels' => array(
+ '$site' => '(int|string) Site ID or domain',
+ '$post_ID' => '(int) The post ID',
+ ),
+ 'response_format' => array(
+ 'ID' => '(int) autodraft post ID',
+ 'post_ID' => '(int) post ID',
+ 'author_ID' => '(int) author ID',
+ 'title' => '(HTML) The post title.',
+ 'content' => '(HTML) The post content.',
+ 'excerpt' => '(HTML) The post excerpt.',
+ 'preview_URL' => '(string) preview URL for the post',
+ 'modified' => '(ISO 8601 datetime) modified time',
+ ),
- 'example_request' => 'https://public-api.wordpress.com/rest/v1.1/sites/82974409/posts/1/autosave',
-) );
+ 'example_request' => 'https://public-api.wordpress.com/rest/v1.1/sites/82974409/posts/1/autosave',
+ )
+);
+// phpcs:disable PEAR.NamingConventions.ValidClassName.Invalid
+/**
+ * Class WPCOM_JSON_API_Get_Autosave_v1_1_Endpoint
+ */
class WPCOM_JSON_API_Get_Autosave_v1_1_Endpoint extends WPCOM_JSON_API_Post_v1_1_Endpoint {
- function __construct( $args ) {
- parent::__construct( $args );
- }
-
- // /sites/%s/posts/%d/autosave -> $blog_id, $post_id
- function callback( $path = '', $blog_id = 0, $post_id = 0 ) {
+ /**
+ * Get Autosave callback
+ * /sites/%s/posts/%d/autosave -> $blog_id, $post_id
+ *
+ * @param string $path Path.
+ * @param int $blog_id Blog ID.
+ * @param int $post_id Post ID.
+ *
+ * @return array|int|mixed|WP_Error
+ */
+ public function callback( $path = '', $blog_id = 0, $post_id = 0 ) {
$blog_id = $this->api->switch_to_blog_and_validate_user( $this->api->get_blog_id( $blog_id ) );
if ( is_wp_error( $blog_id ) ) {
@@ -52,8 +68,14 @@ class WPCOM_JSON_API_Get_Autosave_v1_1_Endpoint extends WPCOM_JSON_API_Post_v1_1
if ( $autosave ) {
$preview_url = add_query_arg( 'preview', 'true', get_permalink( $post->ID ) );
- $nonce = wp_create_nonce( 'post_preview_' . $post->ID );
- $preview_url = add_query_arg( array( 'preview_id' => $auto_ID, 'preview_nonce' => $nonce ), $preview_url );
+ $nonce = wp_create_nonce( 'post_preview_' . $post->ID );
+ $preview_url = add_query_arg(
+ array(
+ 'preview_id' => $post->ID,
+ 'preview_nonce' => $nonce,
+ ),
+ $preview_url
+ );
return array(
'ID' => $autosave->ID,
@@ -63,7 +85,7 @@ class WPCOM_JSON_API_Get_Autosave_v1_1_Endpoint extends WPCOM_JSON_API_Post_v1_1
'content' => $autosave->post_content,
'excerpt' => $autosave->post_excerpt,
'preview_URL' => $preview_url,
- 'modified' => $this->format_date( $autosave->post_modified_gmt, $autosave->post_modified )
+ 'modified' => $this->format_date( $autosave->post_modified_gmt, $autosave->post_modified ),
);
} else {
return new WP_Error( 'not_found', 'No autosaves exist for this post', 404 );