PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 12.8.3
Jetpack – WP Security, Backup, Speed, & Growth v12.8.3
12.0.3 12.1.3 12.2.3 12.3.2 12.4.2 12.5.2 12.6.4 12.7.3 12.8.3 12.9.5 13.0.2 13.1.5 13.2.4 13.3.3 13.4.5 13.5.2 13.6.2 13.7.2 13.8.3 13.9.2 14.0.1 14.1.1 14.2.2 14.3.1 14.4.2 All 500 releases
jetpack / json-endpoints / class.wpcom-json-api-bulk-delete-post-endpoint.php
class.wpcom-json-api-bulk-delete-post-endpoint.php
86 lines 2.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName
2 /**
3 * Bulk delete posts on a site.
4 *
5 * Endpoint: /sites/%s/posts/delete
6 */
7
8 new WPCOM_JSON_API_Bulk_Delete_Post_Endpoint(
9 array(
10 'description' => 'Delete multiple posts. Note: If the trash is enabled, this request will send non-trashed posts to the trash. Trashed posts will be permanently deleted.',
11 'group' => 'posts',
12 'stat' => 'posts:1:bulk-delete',
13 'min_version' => '1.1',
14 'max_version' => '1.1',
15 'method' => 'POST',
16 'path' => '/sites/%s/posts/delete',
17 'path_labels' => array(
18 '$site' => '(int|string) Site ID or domain',
19 ),
20 'request_format' => array(
21 'post_ids' => '(array|string) An array, or comma-separated list, of Post IDs to delete or trash.',
22 ),
23
24 'response_format' => array(
25 'results' => '(object) An object containing results, ',
26 ),
27
28 'example_request' => 'https://public-api.wordpress.com/rest/v1.1/sites/82974409/posts/delete',
29
30 'example_request_data' => array(
31 'headers' => array(
32 'authorization' => 'Bearer YOUR_API_TOKEN',
33 ),
34
35 'body' => array(
36 'post_ids' => array( 881, 882 ),
37 ),
38
39 ),
40 )
41 );
42
43 /**
44 * Bulk delete post endpoint class.
45 */
46 class WPCOM_JSON_API_Bulk_Delete_Post_Endpoint extends WPCOM_JSON_API_Update_Post_v1_1_Endpoint {
47 /**
48 *
49 * API callback.
50 *
51 * @param string $path - the path.
52 * @param int $blog_id - the blog ID.
53 * @param int $post_id - the post ID.
54 */
55 public function callback( $path = '', $blog_id = 0, $post_id = 0 ) {
56 $blog_id = $this->api->switch_to_blog_and_validate_user( $this->api->get_blog_id( $blog_id ) );
57 if ( is_wp_error( $blog_id ) ) {
58 return $blog_id;
59 }
60
61 $input = $this->input();
62
63 if ( is_array( $input['post_ids'] ) ) {
64 $post_ids = (array) $input['post_ids'];
65 } elseif ( ! empty( $input['post_ids'] ) ) {
66 $post_ids = explode( ',', $input['post_ids'] );
67 } else {
68 $post_ids = array();
69 }
70
71 if ( count( $post_ids ) < 1 ) {
72 return new WP_Error( 'empty_post_ids', 'The request must include post_ids' );
73 }
74
75 $result = array(
76 'results' => array(),
77 );
78
79 foreach ( $post_ids as $post_id ) {
80 $result['results'][ $post_id ] = $this->delete_post( $path, $blog_id, $post_id );
81 }
82
83 return $result;
84 }
85 }
86