golden hour
/home/godaofbq/oxygenhyperbaric.com/wp-content/plugins/woocommerce/src/Admin/API
⬆️ Go Up
Upload
File/Folder
Size
Actions
AI
-
Del
OK
Coupons.php
2.15 KB
Del
OK
CustomAttributeTraits.php
3.4 KB
Del
OK
Customers.php
2.11 KB
Del
OK
Data.php
939 B
Del
OK
DataCountries.php
1.12 KB
Del
OK
DataDownloadIPs.php
4.15 KB
Del
OK
Experiments.php
1.82 KB
Del
OK
Features.php
1.7 KB
Del
OK
Init.php
8.97 KB
Del
OK
LaunchYourStore.php
5.15 KB
Del
OK
Leaderboards.php
18.22 KB
Del
OK
Marketing.php
4.84 KB
Del
OK
MarketingCampaignTypes.php
6.02 KB
Del
OK
MarketingCampaigns.php
9.64 KB
Del
OK
MarketingChannels.php
5.74 KB
Del
OK
MarketingOverview.php
3.36 KB
Del
OK
MarketingRecommendations.php
5.94 KB
Del
OK
MobileAppMagicLink.php
2.1 KB
Del
OK
NoteActions.php
2.39 KB
Del
OK
Notes.php
25.79 KB
Del
OK
Notice.php
2.38 KB
Del
OK
OnboardingFreeExtensions.php
2.58 KB
Del
OK
OnboardingPlugins.php
12.84 KB
Del
OK
OnboardingProductTypes.php
1.8 KB
Del
OK
OnboardingProducts.php
1.94 KB
Del
OK
OnboardingProfile.php
18.38 KB
Del
OK
OnboardingTasks.php
32.02 KB
Del
OK
OnboardingThemes.php
5.49 KB
Del
OK
Options.php
10 KB
Del
OK
Orders.php
10.13 KB
Del
OK
PaymentGatewaySuggestions.php
5.86 KB
Del
OK
Plugins.php
21.22 KB
Del
OK
ProductAttributeTerms.php
4.36 KB
Del
OK
ProductAttributes.php
4.46 KB
Del
OK
ProductCategories.php
458 B
Del
OK
ProductForm.php
3.06 KB
Del
OK
ProductReviews.php
1.3 KB
Del
OK
ProductVariations.php
6.03 KB
Del
OK
Products.php
9.73 KB
Del
OK
ProductsLowInStock.php
17.56 KB
Del
OK
Reports
-
Del
OK
SettingOptions.php
878 B
Del
OK
Settings.php
4.2 KB
Del
OK
ShippingPartnerSuggestions.php
5.74 KB
Del
OK
Taxes.php
4.9 KB
Del
OK
Templates
-
Del
OK
Themes.php
6.12 KB
Del
OK
Edit: OnboardingPlugins.php
<?php /** * REST API Onboarding Profile Controller * * Handles requests to /onboarding/profile */ namespace Automattic\WooCommerce\Admin\API; defined( 'ABSPATH' ) || exit; use ActionScheduler; use Automattic\Jetpack\Connection\Manager; use Automattic\WooCommerce\Admin\Features\Features; use Automattic\WooCommerce\Admin\PluginsHelper; use WC_REST_Data_Controller; use WP_Error; use WP_REST_Request; use WP_REST_Response; /** * Onboarding Plugins controller. * * @internal * @extends WC_REST_Data_Controller */ class OnboardingPlugins extends WC_REST_Data_Controller { /** * Endpoint namespace. * * @var string */ protected $namespace = 'wc-admin'; /** * Route base. * * @var string */ protected $rest_base = 'onboarding/plugins'; /** * Register routes. */ public function register_routes() { register_rest_route( $this->namespace, '/' . $this->rest_base . '/install-and-activate-async', array( array( 'methods' => 'POST', 'callback' => array( $this, 'install_and_activate_async' ), 'permission_callback' => array( $this, 'can_install_and_activate_plugins' ), 'args' => array( 'plugins' => array( 'description' => 'A list of plugins to install', 'type' => 'array', 'items' => 'string', 'sanitize_callback' => function ( $value ) { return array_map( function ( $value ) { return sanitize_text_field( $value ); }, $value ); }, 'required' => true, ), 'source' => array( 'description' => 'The source of the request', 'type' => 'string', 'sanitize_callback' => 'sanitize_text_field', 'required' => false, ), ), ), 'schema' => array( $this, 'get_install_async_schema' ), ) ); register_rest_route( $this->namespace, '/' . $this->rest_base . '/install-and-activate', array( array( 'methods' => 'POST', 'callback' => array( $this, 'install_and_activate' ), 'permission_callback' => array( $this, 'can_install_and_activate_plugins' ), ), 'schema' => array( $this, 'get_install_activate_schema' ), ) ); register_rest_route( $this->namespace, '/' . $this->rest_base . '/scheduled-installs/(?P<job_id>\w+)', array( array( 'methods' => 'GET', 'callback' => array( $this, 'get_scheduled_installs' ), 'permission_callback' => array( $this, 'can_install_plugins' ), ), 'schema' => array( $this, 'get_install_async_schema' ), ) ); // This is an experimental endpoint and is subject to change in the future. register_rest_route( $this->namespace, '/' . $this->rest_base . '/jetpack-authorization-url', array( array( 'methods' => 'GET', 'callback' => array( $this, 'get_jetpack_authorization_url' ), 'permission_callback' => array( $this, 'can_install_plugins' ), 'args' => array( 'redirect_url' => array( 'description' => 'The URL to redirect to after authorization', 'type' => 'string', 'sanitize_callback' => 'sanitize_text_field', 'required' => true, ), 'from' => array( 'description' => 'from value for the jetpack authorization page', 'type' => 'string', 'sanitize_callback' => 'sanitize_text_field', 'required' => false, 'default' => 'woocommerce-onboarding', ), ), ), ) ); add_action( 'woocommerce_plugins_install_error', array( $this, 'log_plugins_install_error' ), 10, 4 ); add_action( 'woocommerce_plugins_install_api_error', array( $this, 'log_plugins_install_api_error' ), 10, 2 ); } /** * Install and activate a plugin. * * @param WP_REST_Request $request WP Request object. * * @return WP_REST_Response */ public function install_and_activate( WP_REST_Request $request ) { $response = array(); $response['install'] = PluginsHelper::install_plugins( $request->get_param( 'plugins' ) ); $response['activate'] = PluginsHelper::activate_plugins( $response['install']['installed'] ); return new WP_REST_Response( $response ); } /** * Queue plugin install request. * * @param WP_REST_Request $request WP_REST_Request object. * * @return array */ public function install_and_activate_async( WP_REST_Request $request ) { $plugins = $request->get_param( 'plugins' ); $source = $request->get_param( 'source' ); $job_id = uniqid(); WC()->queue()->add( 'woocommerce_plugins_install_and_activate_async_callback', array( $plugins, $job_id, $source ) ); $plugin_status = array(); foreach ( $plugins as $plugin ) { $plugin_status[ $plugin ] = array( 'status' => 'pending', 'errors' => array(), ); } return array( 'job_id' => $job_id, 'status' => 'pending', 'plugins' => $plugin_status, ); } /** * Returns current status of given job. * * @param WP_REST_Request $request WP_REST_Request object. * * @return array|WP_REST_Response */ public function get_scheduled_installs( WP_REST_Request $request ) { $job_id = $request->get_param( 'job_id' ); $actions = WC()->queue()->search( array( 'hook' => 'woocommerce_plugins_install_and_activate_async_callback', 'search' => $job_id, 'orderby' => 'date', 'order' => 'DESC', ) ); $actions = array_filter( PluginsHelper::get_action_data( $actions ), function ( $action ) use ( $job_id ) { return $action['job_id'] === $job_id; } ); if ( empty( $actions ) ) { return new WP_REST_Response( null, 404 ); } $response = array( 'job_id' => $actions[0]['job_id'], 'status' => $actions[0]['status'], ); $option = get_option( 'woocommerce_onboarding_plugins_install_and_activate_async_' . $job_id ); if ( isset( $option['plugins'] ) ) { $response['plugins'] = $option['plugins']; } return $response; } /** * Return Jetpack authorization URL. * * @param WP_REST_Request $request WP_REST_Request object. * * @return array */ public function get_jetpack_authorization_url( WP_REST_Request $request ) { $manager = new Manager( 'woocommerce' ); $errors = new WP_Error(); // Register the site to wp.com. if ( ! $manager->is_connected() ) { $result = $manager->try_registration(); if ( is_wp_error( $result ) ) { $errors->add( $result->get_error_code(), $result->get_error_message() ); } } $redirect_url = $request->get_param( 'redirect_url' ); $calypso_env = defined( 'WOOCOMMERCE_CALYPSO_ENVIRONMENT' ) && in_array( WOOCOMMERCE_CALYPSO_ENVIRONMENT, array( 'development', 'wpcalypso', 'horizon', 'stage' ), true ) ? WOOCOMMERCE_CALYPSO_ENVIRONMENT : 'production'; $authorization_url = $manager->get_authorization_url( null, $redirect_url ); $authorization_url = add_query_arg( 'locale', $this->get_wpcom_locale(), $authorization_url ); if ( Features::is_enabled( 'use-wp-horizon' ) ) { $calypso_env = 'horizon'; } $color_scheme = get_user_option( 'admin_color', get_current_user_id() ); if ( ! $color_scheme ) { // The default Core color schema is 'fresh'. $color_scheme = 'fresh'; } return array( 'success' => ! $errors->has_errors(), 'errors' => $errors->get_error_messages(), 'color_scheme' => $color_scheme, 'url' => add_query_arg( array( 'from' => $request->get_param( 'from' ), 'calypso_env' => $calypso_env, ), $authorization_url, ), ); } /** * Return a locale string for wpcom. * * @return string */ private function get_wpcom_locale() { // List of locales that should be used with region code. $locale_to_lang = array( 'bre' => 'br', 'de_AT' => 'de-at', 'de_CH' => 'de-ch', 'de' => 'de_formal', 'el' => 'el-po', 'en_GB' => 'en-gb', 'es_CL' => 'es-cl', 'es_MX' => 'es-mx', 'fr_BE' => 'fr-be', 'fr_CA' => 'fr-ca', 'nl_BE' => 'nl-be', 'nl' => 'nl_formal', 'pt_BR' => 'pt-br', 'sr' => 'sr_latin', 'zh_CN' => 'zh-cn', 'zh_HK' => 'zh-hk', 'zh_SG' => 'zh-sg', 'zh_TW' => 'zh-tw', ); $system_locale = get_locale(); if ( isset( $locale_to_lang[ $system_locale ] ) ) { // Return the locale with region code if it's in the list. return $locale_to_lang[ $system_locale ]; } // If the locale is not in the list, return the language code only. return explode( '_', $system_locale )[0]; } /** * Check whether the current user has permission to install plugins * * @return WP_Error|boolean */ public function can_install_plugins() { if ( ! current_user_can( 'install_plugins' ) ) { return new WP_Error( 'woocommerce_rest_cannot_update', __( 'Sorry, you cannot manage plugins.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); } return true; } /** * Check whether the current user has permission to install and activate plugins * * @return WP_Error|boolean */ public function can_install_and_activate_plugins() { if ( ! current_user_can( 'install_plugins' ) || ! current_user_can( 'activate_plugins' ) ) { return new WP_Error( 'woocommerce_rest_cannot_update', __( 'Sorry, you cannot manage plugins.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); } return true; } /** * JSON Schema for both install-async and scheduled-installs endpoints. * * @return array */ public function get_install_async_schema() { return array( '$schema' => 'http://json-schema.org/draft-04/schema#', 'title' => 'Install Async Schema', 'type' => 'object', 'properties' => array( 'type' => 'object', 'properties' => array( 'job_id' => 'integer', 'status' => array( 'type' => 'string', 'enum' => array( 'pending', 'complete', 'failed' ), ), ), ), ); } /** * JSON Schema for install-and-activate endpoint. * * @return array */ public function get_install_activate_schema() { $error_schema = array( 'type' => 'object', 'patternProperties' => array( '^.*$' => array( 'type' => 'string', ), ), 'items' => array( 'type' => 'string', ), ); $install_schema = array( 'type' => 'object', 'properties' => array( 'installed' => array( 'type' => 'array', 'items' => array( 'type' => 'string', ), ), 'results' => array( 'type' => 'array', 'items' => array( 'type' => 'string', ), ), 'errors' => array( 'type' => 'object', 'properties' => array( 'errors' => $error_schema, 'error_data' => $error_schema, ), ), ), ); $activate_schema = array( 'type' => 'object', 'properties' => array( 'activated' => array( 'type' => 'array', 'items' => array( 'type' => 'string', ), ), 'active' => array( 'type' => 'array', 'items' => array( 'type' => 'string', ), ), 'errors' => array( 'type' => 'object', 'properties' => array( 'errors' => $error_schema, 'error_data' => $error_schema, ), ), ), ); return array( '$schema' => 'http://json-schema.org/draft-04/schema#', 'title' => 'Install and Activate Schema', 'type' => 'object', 'properties' => array( 'type' => 'object', 'properties' => array( 'install' => $install_schema, 'activate' => $activate_schema, ), ), ); } public function log_plugins_install_error( $slug, $api, $result, $upgrader ) { $properties = array( 'error_message' => sprintf( /* translators: %s: plugin slug (example: woocommerce-services) */ __( 'The requested plugin `%s` could not be installed.', 'woocommerce' ), $slug ), 'type' => 'plugin_info_api_error', 'slug' => $slug, 'api_version' => $api->version, 'api_download_link' => $api->download_link, 'upgrader_skin_message' => implode( ',', $upgrader->skin->get_upgrade_messages() ), 'result' => is_wp_error( $result ) ? $result->get_error_message() : 'null', ); wc_admin_record_tracks_event( 'coreprofiler_install_plugin_error', $properties ); } public function log_plugins_install_api_error( $slug, $api ) { $properties = array( 'error_message' => sprintf( // translators: %s: plugin slug (example: woocommerce-services). __( 'The requested plugin `%s` could not be installed. Plugin API call failed.', 'woocommerce' ), $slug ), 'type' => 'plugin_install_error', 'api_error_message' => $api->get_error_message(), 'slug' => $slug, ); wc_admin_record_tracks_event( 'coreprofiler_install_plugin_error', $properties ); } }
Save