Automattic\WooCommerce\Admin\API
OnboardingThemes::activate_theme()
Activate the requested theme.
Method of the class: OnboardingThemes{}
No Hooks.
Return
WP_Error|Array
. Theme activation status.
Usage
$OnboardingThemes = new OnboardingThemes(); $OnboardingThemes->activate_theme( $request );
- $request(WP_REST_Request) (required)
- Full details about the request.
OnboardingThemes::activate_theme() OnboardingThemes::activate theme code WC 9.7.1
public function activate_theme( $request ) { $theme = sanitize_text_field( $request['theme'] ); require_once ABSPATH . 'wp-admin/includes/theme.php'; $installed_themes = wp_get_themes(); if ( ! in_array( $theme, array_keys( $installed_themes ), true ) ) { /* translators: %s: theme slug (example: woocommerce-services) */ return new \WP_Error( 'woocommerce_rest_invalid_theme', sprintf( __( 'Invalid theme %s.', 'woocommerce' ), $theme ), 404 ); } $result = switch_theme( $theme ); if ( ! is_null( $result ) ) { return new \WP_Error( 'woocommerce_rest_invalid_theme', sprintf( __( 'The requested theme could not be activated.', 'woocommerce' ), $theme ), 500 ); } return( array( 'slug' => $theme, 'name' => $installed_themes[ $theme ]->get( 'Name' ), 'status' => 'success', ) ); }