| Conditions | 7 |
| Paths | 7 |
| Total Lines | 28 |
| Code Lines | 16 |
| Lines | 3 |
| Ratio | 10.71 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 1 |
| 1 | <?php |
||
| 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 ) ); |
||
| 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 |