PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 16.3-a.5
Jetpack – WP Security, Backup, Speed, & Growth v16.3-a.5
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 13.7.2 13.8.3 All 506 releases
jetpack / json-endpoints / jetpack / class.jetpack-json-api-modules-modify-endpoint.php

class.jetpack-json-api-modules-modify-endpoint.php in Jetpack – WP Security, Backup, Speed, & Growth 16.3-a.5, at json-endpoints/jetpack/class.jetpack-json-api-modules-modify-endpoint.php

106 lines 2.4 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 if ( ! defined( 'ABSPATH' ) ) {
4 exit( 0 );
5 }
6
7 /**
8 * Modules modify endpoint class.
9 *
10 * POST /sites/%s/jetpack/modules/%s/activate
11 * POST /sites/%s/jetpack/modules/%s
12 * POST /sites/%s/jetpack/modules
13 *
14 * @phan-constructor-used-for-side-effects
15 */
16 class Jetpack_JSON_API_Modules_Modify_Endpoint extends Jetpack_JSON_API_Modules_Endpoint {
17 /**
18 * Needed capabilities.
19 *
20 * @var string
21 */
22 protected $needed_capabilities = 'activate_plugins';
23
24 /**
25 * The action.
26 *
27 * @var string
28 */
29 protected $action = 'default_action';
30
31 /**
32 * Keeps track of module logs.
33 *
34 * @var array
35 */
36 public $log;
37
38 /**
39 * The default action.
40 */
41 public function default_action() {
42 $args = $this->input();
43 if ( isset( $args['active'] ) && is_bool( $args['active'] ) ) {
44 if ( $args['active'] ) {
45 return $this->activate_module();
46 } else {
47 return $this->deactivate_module();
48 }
49 }
50
51 return true;
52 }
53
54 /**
55 * Activate module.
56 *
57 * @return bool|WP_Error
58 */
59 protected function activate_module() {
60 foreach ( $this->modules as $module ) {
61 if ( Jetpack::is_module_active( $module ) ) {
62 $error = __( 'The Jetpack Module is already activated.', 'jetpack' );
63 $this->log[ $module ][] = $error;
64 continue;
65 }
66 $result = Jetpack::activate_module( $module, false, false );
67 if ( false === $result || ! Jetpack::is_module_active( $module ) ) {
68 $error = __( 'There was an error while activating the module.', 'jetpack' );
69 $this->log[ $module ][] = $error;
70 }
71 }
72
73 if ( ! $this->bulk && isset( $error ) ) {
74 return new WP_Error( 'activation_error', $error, 400 );
75 }
76
77 return true;
78 }
79
80 /**
81 * Deactivate module.
82 *
83 * @return bool|WP_Error
84 */
85 protected function deactivate_module() {
86 foreach ( $this->modules as $module ) {
87 if ( ! Jetpack::is_module_active( $module ) ) {
88 $error = __( 'The Jetpack Module is already deactivated.', 'jetpack' );
89 $this->log[ $module ] = $error;
90 continue;
91 }
92 $result = Jetpack::deactivate_module( $module );
93 if ( false === $result || Jetpack::is_module_active( $module ) ) {
94 $error = __( 'There was an error while deactivating the module.', 'jetpack' );
95 $this->log[ $module ] = $error;
96 }
97 }
98
99 if ( ! $this->bulk && isset( $error ) ) {
100 return new WP_Error( 'deactivation_error', $error, 400 );
101 }
102
103 return true;
104 }
105 }
106