jetpack
7 years ago
class.wpcom-json-api-add-widget-endpoint.php
8 years ago
class.wpcom-json-api-autosave-post-v1-1-endpoint.php
8 years ago
class.wpcom-json-api-bulk-delete-post-endpoint.php
8 years ago
class.wpcom-json-api-bulk-restore-post-endpoint.php
8 years ago
class.wpcom-json-api-bulk-update-comments-endpoint.php
7 years ago
class.wpcom-json-api-comment-endpoint.php
7 years ago
class.wpcom-json-api-delete-media-endpoint.php
8 years ago
class.wpcom-json-api-delete-media-v1-1-endpoint.php
8 years ago
class.wpcom-json-api-edit-media-v1-2-endpoint.php
7 years ago
class.wpcom-json-api-get-autosave-v1-1-endpoint.php
8 years ago
class.wpcom-json-api-get-comment-counts-endpoint.php
7 years ago
class.wpcom-json-api-get-comment-endpoint.php
8 years ago
class.wpcom-json-api-get-comment-history-endpoint.php
8 years ago
class.wpcom-json-api-get-comments-tree-endpoint.php
8 years ago
class.wpcom-json-api-get-comments-tree-v1-1-endpoint.php
8 years ago
class.wpcom-json-api-get-comments-tree-v1-2-endpoint.php
8 years ago
class.wpcom-json-api-get-customcss.php
8 years ago
class.wpcom-json-api-get-media-endpoint.php
8 years ago
class.wpcom-json-api-get-media-v1-1-endpoint.php
8 years ago
class.wpcom-json-api-get-media-v1-2-endpoint.php
8 years ago
class.wpcom-json-api-get-post-counts-v1-1-endpoint.php
8 years ago
class.wpcom-json-api-get-post-endpoint.php
8 years ago
class.wpcom-json-api-get-post-v1-1-endpoint.php
8 years ago
class.wpcom-json-api-get-site-endpoint.php
7 years ago
class.wpcom-json-api-get-site-v1-2-endpoint.php
8 years ago
class.wpcom-json-api-get-taxonomies-endpoint.php
8 years ago
class.wpcom-json-api-get-taxonomy-endpoint.php
8 years ago
class.wpcom-json-api-get-term-endpoint.php
8 years ago
class.wpcom-json-api-list-comments-endpoint.php
7 years ago
class.wpcom-json-api-list-embeds-endpoint.php
8 years ago
class.wpcom-json-api-list-media-endpoint.php
8 years ago
class.wpcom-json-api-list-media-v1-1-endpoint.php
8 years ago
class.wpcom-json-api-list-media-v1-2-endpoint.php
8 years ago
class.wpcom-json-api-list-post-type-taxonomies-endpoint.php
8 years ago
class.wpcom-json-api-list-post-types-endpoint.php
8 years ago
class.wpcom-json-api-list-posts-endpoint.php
8 years ago
class.wpcom-json-api-list-posts-v1-1-endpoint.php
8 years ago
class.wpcom-json-api-list-posts-v1-2-endpoint.php
8 years ago
class.wpcom-json-api-list-roles-endpoint.php
8 years ago
class.wpcom-json-api-list-shortcodes-endpoint.php
8 years ago
class.wpcom-json-api-list-terms-endpoint.php
8 years ago
class.wpcom-json-api-list-users-endpoint.php
8 years ago
class.wpcom-json-api-menus-v1-1-endpoint.php
8 years ago
class.wpcom-json-api-post-endpoint.php
7 years ago
class.wpcom-json-api-post-v1-1-endpoint.php
8 years ago
class.wpcom-json-api-render-embed-endpoint.php
8 years ago
class.wpcom-json-api-render-embed-reversal-endpoint.php
8 years ago
class.wpcom-json-api-render-endpoint.php
9 years ago
class.wpcom-json-api-render-shortcode-endpoint.php
8 years ago
class.wpcom-json-api-sharing-buttons-endpoint.php
8 years ago
class.wpcom-json-api-site-settings-endpoint.php
7 years ago
class.wpcom-json-api-site-settings-v1-2-endpoint.php
7 years ago
class.wpcom-json-api-site-settings-v1-3-endpoint.php
7 years ago
class.wpcom-json-api-site-settings-v1-4-endpoint.php
7 years ago
class.wpcom-json-api-site-user-endpoint.php
8 years ago
class.wpcom-json-api-taxonomy-endpoint.php
7 years ago
class.wpcom-json-api-update-comment-endpoint.php
8 years ago
class.wpcom-json-api-update-customcss.php
8 years ago
class.wpcom-json-api-update-media-endpoint.php
8 years ago
class.wpcom-json-api-update-media-v1-1-endpoint.php
8 years ago
class.wpcom-json-api-update-post-endpoint.php
7 years ago
class.wpcom-json-api-update-post-v1-1-endpoint.php
7 years ago
class.wpcom-json-api-update-post-v1-2-endpoint.php
7 years ago
class.wpcom-json-api-update-site-homepage-endpoint.php
8 years ago
class.wpcom-json-api-update-site-logo-endpoint.php
8 years ago
class.wpcom-json-api-update-taxonomy-endpoint.php
8 years ago
class.wpcom-json-api-update-term-endpoint.php
7 years ago
class.wpcom-json-api-update-user-endpoint.php
7 years ago
class.wpcom-json-api-upload-media-endpoint.php
8 years ago
class.wpcom-json-api-upload-media-v1-1-endpoint.php
8 years ago
class.wpcom-json-api-get-post-endpoint.php
82 lines
| 1 | <?php |
| 2 | |
| 3 | new WPCOM_JSON_API_Get_Post_Endpoint( array( |
| 4 | 'description' => 'Get a single post (by ID).', |
| 5 | 'group' => 'posts', |
| 6 | 'stat' => 'posts:1', |
| 7 | 'new_version' => '1.1', |
| 8 | 'max_version' => '1', |
| 9 | 'method' => 'GET', |
| 10 | 'path' => '/sites/%s/posts/%d', |
| 11 | 'path_labels' => array( |
| 12 | '$site' => '(int|string) Site ID or domain', |
| 13 | '$post_ID' => '(int) The post ID', |
| 14 | ), |
| 15 | |
| 16 | 'example_request' => 'https://public-api.wordpress.com/rest/v1/sites/en.blog.wordpress.com/posts/7' |
| 17 | ) ); |
| 18 | |
| 19 | new WPCOM_JSON_API_Get_Post_Endpoint( array( |
| 20 | 'description' => 'Get a single post (by name)', |
| 21 | 'group' => '__do_not_document', |
| 22 | 'stat' => 'posts:name', |
| 23 | 'method' => 'GET', |
| 24 | 'path' => '/sites/%s/posts/name:%s', |
| 25 | 'path_labels' => array( |
| 26 | '$site' => '(int|string) Site ID or domain', |
| 27 | '$post_name' => '(string) The post name (a.k.a. slug)', |
| 28 | ), |
| 29 | |
| 30 | 'example_request' => 'https://public-api.wordpress.com/rest/v1/sites/en.blog.wordpress.com/posts/name:blogging-and-stuff', |
| 31 | ) ); |
| 32 | |
| 33 | new WPCOM_JSON_API_Get_Post_Endpoint( array( |
| 34 | 'description' => 'Get a single post (by slug).', |
| 35 | 'group' => 'posts', |
| 36 | 'stat' => 'posts:slug', |
| 37 | 'new_version' => '1.1', |
| 38 | 'max_version' => '1', |
| 39 | 'method' => 'GET', |
| 40 | 'path' => '/sites/%s/posts/slug:%s', |
| 41 | 'path_labels' => array( |
| 42 | '$site' => '(int|string) Site ID or domain', |
| 43 | '$post_slug' => '(string) The post slug (a.k.a. sanitized name)', |
| 44 | ), |
| 45 | |
| 46 | 'example_request' => 'https://public-api.wordpress.com/rest/v1/sites/en.blog.wordpress.com/posts/slug:blogging-and-stuff', |
| 47 | ) ); |
| 48 | |
| 49 | class WPCOM_JSON_API_Get_Post_Endpoint extends WPCOM_JSON_API_Post_Endpoint { |
| 50 | // /sites/%s/posts/%d -> $blog_id, $post_id |
| 51 | // /sites/%s/posts/name:%s -> $blog_id, $post_id // not documented |
| 52 | // /sites/%s/posts/slug:%s -> $blog_id, $post_id |
| 53 | function callback( $path = '', $blog_id = 0, $post_id = 0 ) { |
| 54 | $blog_id = $this->api->switch_to_blog_and_validate_user( $this->api->get_blog_id( $blog_id ) ); |
| 55 | if ( is_wp_error( $blog_id ) ) { |
| 56 | return $blog_id; |
| 57 | } |
| 58 | |
| 59 | $args = $this->query_args(); |
| 60 | |
| 61 | if ( false === strpos( $path, '/posts/slug:' ) && false === strpos( $path, '/posts/name:' ) ) { |
| 62 | $get_by = 'ID'; |
| 63 | } else { |
| 64 | $get_by = 'name'; |
| 65 | } |
| 66 | |
| 67 | $return = $this->get_post_by( $get_by, $post_id, $args['context'] ); |
| 68 | if ( !$return || is_wp_error( $return ) ) { |
| 69 | return $return; |
| 70 | } |
| 71 | |
| 72 | if ( ! $this->current_user_can_access_post_type( $return['type'], $args['context'] ) ) { |
| 73 | return new WP_Error( 'unknown_post', 'Unknown post', 404 ); |
| 74 | } |
| 75 | |
| 76 | /** This action is documented in json-endpoints/class.wpcom-json-api-site-settings-endpoint.php */ |
| 77 | do_action( 'wpcom_json_api_objects', 'posts' ); |
| 78 | |
| 79 | return $return; |
| 80 | } |
| 81 | } |
| 82 |