PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 16.3
Jetpack – WP Security, Backup, Speed, & Growth v16.3
16.3 16.3-beta 16.3-a.5 16.3-a.7 16.3-a.3 16.3-a.1 16.2 16.2-beta 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 All 508 releases
← All changes | json-endpoints/class.wpcom-json-api-bulk-restore-post-endpoint.php +89 -0 16.2-beta → 16.3 View file →
@@ -1,0 +1,89 @@
1 +<?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName
2 +/**
3 + * Endpoint: /sites/%s/posts/restore
4 + */
5 +
6 +if ( ! defined( 'ABSPATH' ) ) {
7 + exit( 0 );
8 +}
9 +
10 +new WPCOM_JSON_API_Bulk_Restore_Post_Endpoint(
11 + array(
12 + 'description' => 'Restore multiple posts.',
13 + 'group' => 'posts',
14 + 'stat' => 'posts:1:bulk-restore',
15 + 'min_version' => '1.1',
16 + 'max_version' => '1.1',
17 + 'method' => 'POST',
18 + 'path' => '/sites/%s/posts/restore',
19 + 'path_labels' => array(
20 + '$site' => '(int|string) Site ID or domain',
21 + ),
22 + 'request_format' => array(
23 + 'post_ids' => '(array|string) An array, or comma-separated list, of Post IDs to restore.',
24 + ),
25 +
26 + 'response_format' => array(
27 + 'results' => '(object) An object containing results, ',
28 + ),
29 +
30 + 'example_request' => 'https://public-api.wordpress.com/rest/v1.1/sites/82974409/posts/restore',
31 +
32 + 'example_request_data' => array(
33 + 'headers' => array(
34 + 'authorization' => 'Bearer YOUR_API_TOKEN',
35 + ),
36 +
37 + 'body' => array(
38 + 'post_ids' => array( 881, 882 ),
39 + ),
40 +
41 + ),
42 + )
43 +);
44 +
45 +/**
46 + * Bulk restore post endpoint class.
47 + *
48 + * @phan-constructor-used-for-side-effects
49 + */
50 +class WPCOM_JSON_API_Bulk_Restore_Post_Endpoint extends WPCOM_JSON_API_Update_Post_v1_1_Endpoint {
51 + /**
52 + *
53 + * API callback.
54 + *
55 + * @param string $path - the path.
56 + * @param int $blog_id - the blog ID.
57 + * @param object $object - parameter is for making the method signature compatible with its parent class method.
58 + */
59 + public function callback( $path = '', $blog_id = 0, $object = null ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
60 + $blog_id = $this->api->switch_to_blog_and_validate_user( $this->api->get_blog_id( $blog_id ) );
61 + if ( is_wp_error( $blog_id ) ) {
62 + return $blog_id;
63 + }
64 +
65 + $input = $this->input();
66 +
67 + if ( is_array( $input['post_ids'] ) ) {
68 + $post_ids = (array) $input['post_ids'];
69 + } elseif ( ! empty( $input['post_ids'] ) ) {
70 + $post_ids = explode( ',', $input['post_ids'] );
71 + } else {
72 + $post_ids = array();
73 + }
74 +
75 + if ( count( $post_ids ) < 1 ) {
76 + return new WP_Error( 'empty_post_ids', 'The request must include post_ids' );
77 + }
78 +
79 + $result = array(
80 + 'results' => array(),
81 + );
82 +
83 + foreach ( $post_ids as $post_id ) {
84 + $result['results'][ $post_id ] = $this->restore_post( $path, $blog_id, $post_id );
85 + }
86 +
87 + return $result;
88 + }
89 +}