Automattic /
jetpack
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
| 2 | |||
| 3 | new WPCOM_JSON_API_Get_Autosave_v1_1_Endpoint( array( |
||
| 4 | 'description' => 'Get the most recent autosave for a post.', |
||
| 5 | 'group' => '__do_not_document', |
||
| 6 | 'stat' => 'posts:autosave', |
||
| 7 | 'min_version' => '1.1', |
||
| 8 | 'method' => 'GET', |
||
| 9 | 'path' => '/sites/%s/posts/%d/autosave', |
||
| 10 | 'path_labels' => array( |
||
| 11 | '$site' => '(int|string) Site ID or domain', |
||
| 12 | '$post_ID' => '(int) The post ID', |
||
| 13 | ), |
||
| 14 | 'response_format' => array( |
||
| 15 | 'ID' => '(int) autodraft post ID', |
||
| 16 | 'post_ID' => '(int) post ID', |
||
| 17 | 'author_ID' => '(int) author ID', |
||
| 18 | 'title' => '(HTML) The post title.', |
||
| 19 | 'content' => '(HTML) The post content.', |
||
| 20 | 'excerpt' => '(HTML) The post excerpt.', |
||
| 21 | 'preview_URL' => '(string) preview URL for the post', |
||
| 22 | 'modified' => '(ISO 8601 datetime) modified time', |
||
| 23 | ), |
||
| 24 | |||
| 25 | 'example_request' => 'https://public-api.wordpress.com/rest/v1.1/sites/82974409/posts/1/autosave', |
||
| 26 | ) ); |
||
| 27 | |||
| 28 | class WPCOM_JSON_API_Get_Autosave_v1_1_Endpoint extends WPCOM_JSON_API_Post_v1_1_Endpoint { |
||
| 29 | function __construct( $args ) { |
||
| 30 | parent::__construct( $args ); |
||
| 31 | } |
||
| 32 | |||
| 33 | // /sites/%s/posts/%d/autosave -> $blog_id, $post_id |
||
| 34 | function callback( $path = '', $blog_id = 0, $post_id = 0 ) { |
||
| 35 | |||
| 36 | $blog_id = $this->api->switch_to_blog_and_validate_user( $this->api->get_blog_id( $blog_id ) ); |
||
| 37 | if ( is_wp_error( $blog_id ) ) { |
||
| 38 | return $blog_id; |
||
| 39 | } |
||
| 40 | |||
| 41 | $post = get_post( $post_id ); |
||
| 42 | |||
| 43 | if ( ! $post || is_wp_error( $post ) ) { |
||
| 44 | return new WP_Error( 'unknown_post', 'Unknown post', 404 ); |
||
|
0 ignored issues
–
show
|
|||
| 45 | } |
||
| 46 | |||
| 47 | if ( ! current_user_can( 'edit_post', $post->ID ) ) { |
||
| 48 | return new WP_Error( 'unauthorized', 'User cannot edit post', 403 ); |
||
|
0 ignored issues
–
show
The call to
WP_Error::__construct() has too many arguments starting with 'unauthorized'.
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue. If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. In this case you can add the Loading history...
|
|||
| 49 | } |
||
| 50 | |||
| 51 | $autosave = wp_get_post_autosave( $post->ID ); |
||
| 52 | |||
| 53 | if ( $autosave ) { |
||
| 54 | $preview_url = add_query_arg( 'preview', 'true', get_permalink( $post->ID ) ); |
||
| 55 | $nonce = wp_create_nonce( 'post_preview_' . $post->ID ); |
||
| 56 | $preview_url = add_query_arg( array( 'preview_id' => $auto_ID, 'preview_nonce' => $nonce ), $preview_url ); |
||
| 57 | |||
| 58 | return array( |
||
| 59 | 'ID' => $autosave->ID, |
||
| 60 | 'author_ID' => $autosave->post_author, |
||
| 61 | 'post_ID' => $autosave->post_parent, |
||
| 62 | 'title' => $autosave->post_title, |
||
| 63 | 'content' => $autosave->post_content, |
||
| 64 | 'excerpt' => $autosave->post_excerpt, |
||
| 65 | 'preview_URL' => $preview_url, |
||
| 66 | 'modified' => $this->format_date( $autosave->post_modified_gmt, $autosave->post_modified ) |
||
| 67 | ); |
||
| 68 | } else { |
||
| 69 | return new WP_Error( 'not_found', 'No autosaves exist for this post', 404 ); |
||
|
0 ignored issues
–
show
The call to
WP_Error::__construct() has too many arguments starting with 'not_found'.
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue. If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. In this case you can add the Loading history...
|
|||
| 70 | } |
||
| 71 | } |
||
| 72 | } |
||
| 73 |
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.
In this case you can add the
@ignorePhpDoc annotation to the duplicate definition and it will be ignored.