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_v1_1_Endpoint extends WPCOM_JSON_API_Post_v1_1_Endpoint { |
||
| 3 | // /sites/%s/posts/%d -> $blog_id, $post_id |
||
| 4 | // /sites/%s/posts/slug:%s -> $blog_id, $post_id |
||
| 5 | function callback( $path = '', $blog_id = 0, $post_id = 0 ) { |
||
| 6 | $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...
|
|||
| 7 | if ( is_wp_error( $blog_id ) ) { |
||
| 8 | return $blog_id; |
||
| 9 | } |
||
| 10 | |||
| 11 | $args = $this->query_args(); |
||
| 12 | |||
| 13 | if ( false !== strpos( $path, '/posts/slug:' ) ) { |
||
| 14 | $post_id = $this->get_platform()->get_site( $blog_id )->get_post_id_by_name( $post_id ); |
||
|
0 ignored issues
–
show
|
|||
| 15 | if ( is_wp_error( $post_id ) ) { |
||
| 16 | return $post_id; |
||
| 17 | } |
||
| 18 | } |
||
| 19 | |||
| 20 | if ( defined( 'IS_WPCOM' ) && IS_WPCOM && |
||
| 21 | ! in_array( get_post_type( $post_id ), array( false, 'post', 'page', 'revision' ) ) ) { |
||
| 22 | $this->load_theme_functions(); |
||
| 23 | } |
||
| 24 | |||
| 25 | $return = $this->get_post_by( 'ID', $post_id, $args['context'] ); |
||
| 26 | |||
| 27 | if ( !$return || is_wp_error( $return ) ) { |
||
| 28 | return $return; |
||
| 29 | } |
||
| 30 | |||
| 31 | View Code Duplication | if ( ! $this->current_user_can_access_post_type( $return['type'], $args['context'] ) ) { |
|
| 32 | return new WP_Error( 'unknown_post', 'Unknown post', 404 ); |
||
| 33 | } |
||
| 34 | |||
| 35 | /** This action is documented in json-endpoints/class.wpcom-json-api-site-settings-endpoint.php */ |
||
| 36 | do_action( 'wpcom_json_api_objects', 'posts' ); |
||
| 37 | |||
| 38 | return $return; |
||
| 39 | } |
||
| 40 | } |
||
| 41 |