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 | class WPCOM_JSON_API_Get_Post_Endpoint extends WPCOM_JSON_API_Post_Endpoint { |
||
| 3 | // /sites/%s/posts/%d -> $blog_id, $post_id |
||
| 4 | // /sites/%s/posts/name:%s -> $blog_id, $post_id // not documented |
||
| 5 | // /sites/%s/posts/slug:%s -> $blog_id, $post_id |
||
| 6 | function callback( $path = '', $blog_id = 0, $post_id = 0 ) { |
||
| 7 | $blog_id = $this->api->switch_to_blog_and_validate_user( $this->api->get_blog_id( $blog_id ) ); |
||
|
0 ignored issues
–
show
Coding Style
introduced
by
Loading history...
|
|||
| 8 | if ( is_wp_error( $blog_id ) ) { |
||
| 9 | return $blog_id; |
||
| 10 | } |
||
| 11 | |||
| 12 | $args = $this->query_args(); |
||
| 13 | |||
| 14 | if ( false === strpos( $path, '/posts/slug:' ) && false === strpos( $path, '/posts/name:' ) ) { |
||
| 15 | $get_by = 'ID'; |
||
| 16 | } else { |
||
| 17 | $get_by = 'name'; |
||
| 18 | } |
||
| 19 | |||
| 20 | $return = $this->get_post_by( $get_by, $post_id, $args['context'] ); |
||
| 21 | if ( !$return || is_wp_error( $return ) ) { |
||
| 22 | return $return; |
||
| 23 | } |
||
| 24 | |||
| 25 | View Code Duplication | if ( ! $this->current_user_can_access_post_type( $return['type'], $args['context'] ) ) { |
|
| 26 | return new WP_Error( 'unknown_post', 'Unknown post', 404 ); |
||
| 27 | } |
||
| 28 | |||
| 29 | /** This action is documented in json-endpoints/class.wpcom-json-api-site-settings-endpoint.php */ |
||
| 30 | do_action( 'wpcom_json_api_objects', 'posts' ); |
||
| 31 | |||
| 32 | return $return; |
||
| 33 | } |
||
| 34 | } |
||
| 35 |