request = $request; if ( ! current_user_can( 'install_plugins' ) || ! current_user_can( 'install_themes' ) ) { return new WP_Error( 'rest_forbidden', __( 'Sorry, you are not allowed to import global settings.', 'templately' ), [ 'status' => rest_authorization_required_code() ] ); } return parent::permission_check( $request ); } public function register_routes() { $this->post( 'import/global-settings', [ $this, 'import_global_settings' ], [ 'id' => [ 'required' => true, ], 'isAi' => [ 'required' => false, ], ] ); } public function import_global_settings() { $id = $this->get_param( 'id', 0, 'absint' ); $isAi = Helper::sanitize( $this->get_param( 'isAi', false, null ), 'boolean' ); if ( empty( $id ) ) { return $this->error( 'invalid_id', __( 'A valid pack id is required.', 'templately' ), 'import/global-settings', 400 ); } $data = ( new PackInfoFetcher() )->fetch( $id, $isAi ); if ( is_wp_error( $data ) ) { return $this->error( 'api_error', $data->get_error_message(), 'import/global-settings', 500 ); } $settings = []; if ( isset( $data['data']['settings'] ) ) { $settings = json_decode( $data['data']['settings'], true ); } return $this->success( [ 'settings' => $settings ] ); } }