PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 12.3.2
Jetpack – WP Security, Backup, Speed, & Growth v12.3.2
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 12.3.2, at json-endpoints/jetpack/class.jetpack-json-api-modules-modify-endpoint.php

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