Skip to content

Commit

Permalink
Merge pull request #21 from newfold-labs/add/jetpack-module-toggle-su…
Browse files Browse the repository at this point in the history
…pport

Added method to toggle jetpack modules
  • Loading branch information
arunshenoy99 authored Aug 28, 2024
2 parents e8c85fc + 7904aa5 commit 61d852a
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions includes/Data/Plugins.php
Original file line number Diff line number Diff line change
Expand Up @@ -225,4 +225,26 @@ public static function wc_prevent_redirect_on_activation() {
\delete_transient( '_wc_activation_redirect' );
}

/**
* Activate or Deactivate Jetpack modules.
*
* @param string $module the name of the module to activate
* @param string $active the status of the module, pass true to activate and false to deactivate
*
* @return boolean
*/
public static function toggle_jetpack_module( $module, $active = true ) {
$request = new \WP_REST_Request(
'POST',
'/jetpack/v4/settings'
);
$request->set_header( 'Content-Type', 'application/json' );
$request->set_body( wp_json_encode( array( $module => $active ) ) );
$response = \rest_do_request( $request );

if ( 200 !== $response->status ) {
return false;
}
return true;
}
}

0 comments on commit 61d852a

Please sign in to comment.