Jetpack_JSON_API_Modules_Modify_Endpoint

The Jetpack by WordPress.com Jetpack JSON API Modules Modify Endpoint class.

Defined (1)

The class is defined in the following location(s).

/json-endpoints/jetpack/class.jetpack-json-api-modules-modify-endpoint.php  
  1. class Jetpack_JSON_API_Modules_Modify_Endpoint extends Jetpack_JSON_API_Modules_Endpoint { 
  2. // POST /sites/%s/jetpack/modules/%s/activate 
  3. // POST /sites/%s/jetpack/modules/%s 
  4. // POST /sites/%s/jetpack/modules 
  5.  
  6. protected $needed_capabilities = 'activate_plugins'; 
  7. protected $action = 'default_action'; 
  8.  
  9. public function default_action() { 
  10. $args = $this->input(); 
  11. if ( isset( $args['active'] ) && is_bool( $args['active'] ) ) { 
  12. if ( $args['active'] ) { 
  13. return $this->activate_module(); 
  14. } else { 
  15. return $this->deactivate_module(); 
  16.  
  17. return true; 
  18.  
  19. protected function activate_module() { 
  20. foreach ( $this->modules as $module ) { 
  21. if ( Jetpack::is_module_active( $module ) ) { 
  22. $error = $this->log[ $module ][] = __( 'The Jetpack Module is already activated.', 'jetpack' ); 
  23. continue; 
  24. $result = Jetpack::activate_module( $module, false, false ); 
  25. if ( false === $result || ! Jetpack::is_module_active( $module ) ) { 
  26. $error = $this->log[ $module ][] = __( 'There was an error while activating the module.', 'jetpack' ); 
  27.  
  28. if ( ! $this->bulk && isset( $error ) ) { 
  29. return new WP_Error( 'activation_error', $error, 400 ); 
  30.  
  31. return true; 
  32.  
  33. protected function deactivate_module() { 
  34. foreach ( $this->modules as $module ) { 
  35. if ( ! Jetpack::is_module_active( $module ) ) { 
  36. $error = $this->log[ $module ][] = __( 'The Jetpack Module is already deactivated.', 'jetpack' ); 
  37. continue; 
  38. $result = Jetpack::deactivate_module( $module ); 
  39. if ( false === $result || Jetpack::is_module_active( $module ) ) { 
  40. $error = $this->log[ $module ][] = __( 'There was an error while deactivating the module.', 'jetpack' ); 
  41.  
  42. if ( ! $this->bulk && isset( $error ) ) { 
  43. return new WP_Error( 'deactivation_error', $error, 400 ); 
  44.  
  45. return true; 
  46.