diff --git a/includes/admin/class-wc-admin-assets.php b/includes/admin/class-wc-admin-assets.php index d11035f41d0..69d6540eb05 100644 --- a/includes/admin/class-wc-admin-assets.php +++ b/includes/admin/class-wc-admin-assets.php @@ -12,7 +12,7 @@ if ( ! defined( 'ABSPATH' ) ) { exit; } -if ( ! class_exists( 'WC_Admin_Assets' ) ) : +if ( ! class_exists( 'WC_Admin_Assets', false ) ) : /** * WC_Admin_Assets Class. diff --git a/includes/admin/class-wc-admin-dashboard.php b/includes/admin/class-wc-admin-dashboard.php index a74cca22d16..8cc088d5432 100644 --- a/includes/admin/class-wc-admin-dashboard.php +++ b/includes/admin/class-wc-admin-dashboard.php @@ -12,7 +12,7 @@ if ( ! defined( 'ABSPATH' ) ) { exit; // Exit if accessed directly } -if ( ! class_exists( 'WC_Admin_Dashboard' ) ) : +if ( ! class_exists( 'WC_Admin_Dashboard', false ) ) : /** * WC_Admin_Dashboard Class. diff --git a/includes/admin/class-wc-admin-duplicate-product.php b/includes/admin/class-wc-admin-duplicate-product.php index e2cb996b1d3..6c457453ec9 100644 --- a/includes/admin/class-wc-admin-duplicate-product.php +++ b/includes/admin/class-wc-admin-duplicate-product.php @@ -12,7 +12,7 @@ if ( ! defined( 'ABSPATH' ) ) { * @version 2.7.0 */ -if ( ! class_exists( 'WC_Admin_Duplicate_Product' ) ) : +if ( ! class_exists( 'WC_Admin_Duplicate_Product', false ) ) : /** * WC_Admin_Duplicate_Product Class. diff --git a/includes/admin/class-wc-admin-help.php b/includes/admin/class-wc-admin-help.php index de4d012dcad..e9315b7b990 100644 --- a/includes/admin/class-wc-admin-help.php +++ b/includes/admin/class-wc-admin-help.php @@ -12,7 +12,7 @@ if ( ! defined( 'ABSPATH' ) ) { exit; // Exit if accessed directly } -if ( ! class_exists( 'WC_Admin_Help' ) ) : +if ( ! class_exists( 'WC_Admin_Help', false ) ) : /** * WC_Admin_Help Class. diff --git a/includes/admin/class-wc-admin-importers.php b/includes/admin/class-wc-admin-importers.php index 7b6ac91cd71..0ed3c2fd9ed 100644 --- a/includes/admin/class-wc-admin-importers.php +++ b/includes/admin/class-wc-admin-importers.php @@ -12,7 +12,7 @@ if ( ! defined( 'ABSPATH' ) ) { exit; } -if ( ! class_exists( 'WC_Admin_Importers' ) ) : +if ( ! class_exists( 'WC_Admin_Importers', false ) ) : /** * WC_Admin_Importers Class. diff --git a/includes/admin/class-wc-admin-menus.php b/includes/admin/class-wc-admin-menus.php index a97553bfef8..7d05de347c7 100644 --- a/includes/admin/class-wc-admin-menus.php +++ b/includes/admin/class-wc-admin-menus.php @@ -12,7 +12,7 @@ if ( ! defined( 'ABSPATH' ) ) { exit; } -if ( ! class_exists( 'WC_Admin_Menus' ) ) : +if ( ! class_exists( 'WC_Admin_Menus', false ) ) : /** * WC_Admin_Menus Class. diff --git a/includes/admin/class-wc-admin-permalink-settings.php b/includes/admin/class-wc-admin-permalink-settings.php index 8b2a13566ec..4969ab1ed75 100644 --- a/includes/admin/class-wc-admin-permalink-settings.php +++ b/includes/admin/class-wc-admin-permalink-settings.php @@ -13,7 +13,7 @@ if ( ! defined( 'ABSPATH' ) ) { exit; } -if ( ! class_exists( 'WC_Admin_Permalink_Settings' ) ) : +if ( ! class_exists( 'WC_Admin_Permalink_Settings', false ) ) : /** * WC_Admin_Permalink_Settings Class. diff --git a/includes/admin/class-wc-admin-post-types.php b/includes/admin/class-wc-admin-post-types.php index 1c238cb1d9a..a42d978d96a 100644 --- a/includes/admin/class-wc-admin-post-types.php +++ b/includes/admin/class-wc-admin-post-types.php @@ -12,7 +12,7 @@ if ( ! defined( 'ABSPATH' ) ) { exit; } -if ( ! class_exists( 'WC_Admin_Post_Types' ) ) : +if ( ! class_exists( 'WC_Admin_Post_Types', false ) ) : /** * WC_Admin_Post_Types Class. diff --git a/includes/admin/class-wc-admin-profile.php b/includes/admin/class-wc-admin-profile.php index 1e56ba2d06e..63c5b2481a0 100644 --- a/includes/admin/class-wc-admin-profile.php +++ b/includes/admin/class-wc-admin-profile.php @@ -12,7 +12,7 @@ if ( ! defined( 'ABSPATH' ) ) { exit; // Exit if accessed directly } -if ( ! class_exists( 'WC_Admin_Profile' ) ) : +if ( ! class_exists( 'WC_Admin_Profile', false ) ) : /** * WC_Admin_Profile Class. diff --git a/includes/admin/class-wc-admin-reports.php b/includes/admin/class-wc-admin-reports.php index d5bbaa04b0e..d8a6028572c 100644 --- a/includes/admin/class-wc-admin-reports.php +++ b/includes/admin/class-wc-admin-reports.php @@ -14,7 +14,7 @@ if ( ! defined( 'ABSPATH' ) ) { exit; // Exit if accessed directly } -if ( ! class_exists( 'WC_Admin_Reports' ) ) : +if ( ! class_exists( 'WC_Admin_Reports', false ) ) : /** * WC_Admin_Reports Class. diff --git a/includes/admin/class-wc-admin-settings.php b/includes/admin/class-wc-admin-settings.php index dc8824688c2..a3140c0ee10 100644 --- a/includes/admin/class-wc-admin-settings.php +++ b/includes/admin/class-wc-admin-settings.php @@ -12,7 +12,7 @@ if ( ! defined( 'ABSPATH' ) ) { exit; } -if ( ! class_exists( 'WC_Admin_Settings' ) ) : +if ( ! class_exists( 'WC_Admin_Settings', false ) ) : /** * WC_Admin_Settings Class. diff --git a/includes/admin/settings/class-wc-settings-accounts.php b/includes/admin/settings/class-wc-settings-accounts.php index b1aa0db50d3..7af52dd3693 100644 --- a/includes/admin/settings/class-wc-settings-accounts.php +++ b/includes/admin/settings/class-wc-settings-accounts.php @@ -12,7 +12,7 @@ if ( ! defined( 'ABSPATH' ) ) { exit; // Exit if accessed directly } -if ( ! class_exists( 'WC_Settings_Accounts' ) ) : +if ( ! class_exists( 'WC_Settings_Accounts', false ) ) : /** * WC_Settings_Accounts. diff --git a/includes/admin/settings/class-wc-settings-api.php b/includes/admin/settings/class-wc-settings-api.php index b08e76b9885..281e03a6b5f 100644 --- a/includes/admin/settings/class-wc-settings-api.php +++ b/includes/admin/settings/class-wc-settings-api.php @@ -12,7 +12,7 @@ if ( ! defined( 'ABSPATH' ) ) { exit; // Exit if accessed directly } -if ( ! class_exists( 'WC_Settings_Rest_API' ) ) : +if ( ! class_exists( 'WC_Settings_Rest_API', false ) ) : /** * WC_Settings_Rest_API. diff --git a/includes/admin/settings/class-wc-settings-checkout.php b/includes/admin/settings/class-wc-settings-checkout.php index 3ad34fbeba8..eda8c207e3f 100644 --- a/includes/admin/settings/class-wc-settings-checkout.php +++ b/includes/admin/settings/class-wc-settings-checkout.php @@ -12,7 +12,7 @@ if ( ! defined( 'ABSPATH' ) ) { exit; } -if ( ! class_exists( 'WC_Settings_Payment_Gateways' ) ) : +if ( ! class_exists( 'WC_Settings_Payment_Gateways', false ) ) : /** * WC_Settings_Payment_Gateways. diff --git a/includes/admin/settings/class-wc-settings-emails.php b/includes/admin/settings/class-wc-settings-emails.php index 0c6227677e2..f1bc96c71ad 100644 --- a/includes/admin/settings/class-wc-settings-emails.php +++ b/includes/admin/settings/class-wc-settings-emails.php @@ -12,7 +12,7 @@ if ( ! defined( 'ABSPATH' ) ) { exit; // Exit if accessed directly } -if ( ! class_exists( 'WC_Settings_Emails' ) ) : +if ( ! class_exists( 'WC_Settings_Emails', false ) ) : /** * WC_Settings_Emails. diff --git a/includes/admin/settings/class-wc-settings-general.php b/includes/admin/settings/class-wc-settings-general.php index ad7ad411bf3..e93da58efea 100644 --- a/includes/admin/settings/class-wc-settings-general.php +++ b/includes/admin/settings/class-wc-settings-general.php @@ -12,7 +12,7 @@ if ( ! defined( 'ABSPATH' ) ) { exit; // Exit if accessed directly } -if ( ! class_exists( 'WC_Settings_General' ) ) : +if ( ! class_exists( 'WC_Settings_General', false ) ) : /** * WC_Admin_Settings_General. diff --git a/includes/admin/settings/class-wc-settings-integrations.php b/includes/admin/settings/class-wc-settings-integrations.php index aecffe335bf..88c07721e42 100644 --- a/includes/admin/settings/class-wc-settings-integrations.php +++ b/includes/admin/settings/class-wc-settings-integrations.php @@ -12,7 +12,7 @@ if ( ! defined( 'ABSPATH' ) ) { exit; // Exit if accessed directly } -if ( ! class_exists( 'WC_Settings_Integrations' ) ) : +if ( ! class_exists( 'WC_Settings_Integrations', false ) ) : /** * WC_Settings_Integrations. diff --git a/includes/admin/settings/class-wc-settings-page.php b/includes/admin/settings/class-wc-settings-page.php index 7831649cc5f..e0e906cc704 100644 --- a/includes/admin/settings/class-wc-settings-page.php +++ b/includes/admin/settings/class-wc-settings-page.php @@ -12,7 +12,7 @@ if ( ! defined( 'ABSPATH' ) ) { exit; // Exit if accessed directly } -if ( ! class_exists( 'WC_Settings_Page' ) ) : +if ( ! class_exists( 'WC_Settings_Page', false ) ) : /** * WC_Settings_Page. diff --git a/includes/admin/settings/class-wc-settings-products.php b/includes/admin/settings/class-wc-settings-products.php index 813366caa06..fe937651718 100644 --- a/includes/admin/settings/class-wc-settings-products.php +++ b/includes/admin/settings/class-wc-settings-products.php @@ -12,7 +12,7 @@ if ( ! defined( 'ABSPATH' ) ) { exit; // Exit if accessed directly } -if ( ! class_exists( 'WC_Settings_Products' ) ) : +if ( ! class_exists( 'WC_Settings_Products', false ) ) : /** * WC_Settings_Products. diff --git a/includes/admin/settings/class-wc-settings-shipping.php b/includes/admin/settings/class-wc-settings-shipping.php index f22f7b8f778..7e2281ea058 100644 --- a/includes/admin/settings/class-wc-settings-shipping.php +++ b/includes/admin/settings/class-wc-settings-shipping.php @@ -12,7 +12,7 @@ if ( ! defined( 'ABSPATH' ) ) { exit; } -if ( ! class_exists( 'WC_Settings_Shipping' ) ) : +if ( ! class_exists( 'WC_Settings_Shipping', false ) ) : /** * WC_Settings_Shipping. diff --git a/includes/admin/settings/class-wc-settings-tax.php b/includes/admin/settings/class-wc-settings-tax.php index 97a9efb4998..afaa3f77b06 100644 --- a/includes/admin/settings/class-wc-settings-tax.php +++ b/includes/admin/settings/class-wc-settings-tax.php @@ -12,7 +12,7 @@ if ( ! defined( 'ABSPATH' ) ) { exit; } -if ( ! class_exists( 'WC_Settings_Tax' ) ) : +if ( ! class_exists( 'WC_Settings_Tax', false ) ) : /** * WC_Settings_Tax. diff --git a/includes/admin/wc-admin-functions.php b/includes/admin/wc-admin-functions.php index c7d32a6181b..0e2aa839a9a 100644 --- a/includes/admin/wc-admin-functions.php +++ b/includes/admin/wc-admin-functions.php @@ -132,7 +132,7 @@ function wc_create_page( $slug, $option = '', $page_title = '', $page_content = */ function woocommerce_admin_fields( $options ) { - if ( ! class_exists( 'WC_Admin_Settings' ) ) { + if ( ! class_exists( 'WC_Admin_Settings', false ) ) { include( dirname( __FILE__ ) . '/class-wc-admin-settings.php' ); } @@ -147,7 +147,7 @@ function woocommerce_admin_fields( $options ) { */ function woocommerce_update_options( $options, $data = null ) { - if ( ! class_exists( 'WC_Admin_Settings' ) ) { + if ( ! class_exists( 'WC_Admin_Settings', false ) ) { include( dirname( __FILE__ ) . '/class-wc-admin-settings.php' ); } @@ -163,7 +163,7 @@ function woocommerce_update_options( $options, $data = null ) { */ function woocommerce_settings_get_option( $option_name, $default = '' ) { - if ( ! class_exists( 'WC_Admin_Settings' ) ) { + if ( ! class_exists( 'WC_Admin_Settings', false ) ) { include( dirname( __FILE__ ) . '/class-wc-admin-settings.php' ); } diff --git a/includes/class-wc-api.php b/includes/class-wc-api.php index 15bacd6f6aa..9afe97028f1 100644 --- a/includes/class-wc-api.php +++ b/includes/class-wc-api.php @@ -14,10 +14,6 @@ if ( ! defined( 'ABSPATH' ) ) { exit; } -if ( ! class_exists( 'WC_Legacy_API' ) ) { - include_once( dirname( __FILE__ ) . '/class-wc-legacy-api.php' ); -} - class WC_API extends WC_Legacy_API { /** diff --git a/includes/class-wc-auth.php b/includes/class-wc-auth.php index 54a9c38e5de..d1999600e35 100644 --- a/includes/class-wc-auth.php +++ b/includes/class-wc-auth.php @@ -9,13 +9,10 @@ * @package WooCommerce/API * @since 2.4.0 */ - if ( ! defined( 'ABSPATH' ) ) { exit; } -if ( ! class_exists( 'WC_Auth' ) ) : - class WC_Auth { /** @@ -402,7 +399,4 @@ class WC_Auth { } } } - -endif; - -return new WC_Auth(); +new WC_Auth(); diff --git a/includes/class-wc-autoloader.php b/includes/class-wc-autoloader.php index 84fa49db77a..b6c7416a5ea 100644 --- a/includes/class-wc-autoloader.php +++ b/includes/class-wc-autoloader.php @@ -1,5 +1,4 @@ get_file_name_from_class( $class ); $path = ''; @@ -87,7 +91,7 @@ class WC_Autoloader { $path = $this->include_path . 'log-handlers/'; } - if ( empty( $path ) || ( ! $this->load_file( $path . $file ) && strpos( $class, 'wc_' ) === 0 ) ) { + if ( empty( $path ) || ! $this->load_file( $path . $file ) ) { $this->load_file( $this->include_path . $file ); } } diff --git a/includes/class-wc-background-updater.php b/includes/class-wc-background-updater.php index 1a408c82e75..0eec0045ff2 100644 --- a/includes/class-wc-background-updater.php +++ b/includes/class-wc-background-updater.php @@ -11,13 +11,17 @@ * @category Class * @author WooThemes */ - if ( ! defined( 'ABSPATH' ) ) { exit; } -include_once( dirname( __FILE__ ) . '/libraries/wp-async-request.php' ); -include_once( dirname( __FILE__ ) . '/libraries/wp-background-process.php' ); +if ( ! class_exists( 'WP_Async_Request', false ) ) { + include_once( dirname( __FILE__ ) . '/libraries/wp-async-request.php' ); +} + +if ( ! class_exists( 'WP_Background_Process', false ) ) { + include_once( dirname( __FILE__ ) . '/libraries/wp-background-process.php' ); +} /** * WC_Background_Updater Class. diff --git a/includes/class-wc-cli.php b/includes/class-wc-cli.php index d5ff5fceddb..25292c8ac35 100644 --- a/includes/class-wc-cli.php +++ b/includes/class-wc-cli.php @@ -1,4 +1,8 @@ identifier = $this->prefix . '_' . $this->action; - - add_action( 'wp_ajax_' . $this->identifier, array( $this, 'maybe_handle' ) ); - add_action( 'wp_ajax_nopriv_' . $this->identifier, array( $this, 'maybe_handle' ) ); - } - - /** - * Set data used during the request - * - * @param array $data Data. - * - * @return $this - */ - public function data( $data ) { - $this->data = $data; - - return $this; - } - - /** - * Dispatch the async request - * - * @return array|WP_Error - */ - public function dispatch() { - $url = add_query_arg( $this->get_query_args(), $this->get_query_url() ); - $args = $this->get_post_args(); - - return wp_remote_post( esc_url_raw( $url ), $args ); - } - - /** - * Get query args - * - * @return array - */ - protected function get_query_args() { - if ( property_exists( $this, 'query_args' ) ) { - return $this->query_args; - } - - return array( - 'action' => $this->identifier, - 'nonce' => wp_create_nonce( $this->identifier ), - ); - } - - /** - * Get query URL - * - * @return string - */ - protected function get_query_url() { - if ( property_exists( $this, 'query_url' ) ) { - return $this->query_url; - } - - return admin_url( 'admin-ajax.php' ); - } - - /** - * Get post args - * - * @return array - */ - protected function get_post_args() { - if ( property_exists( $this, 'post_args' ) ) { - return $this->post_args; - } - - return array( - 'timeout' => 0.01, - 'blocking' => false, - 'body' => $this->data, - 'cookies' => $_COOKIE, - 'sslverify' => apply_filters( 'https_local_ssl_verify', false ), - ); - } - - /** - * Maybe handle - * - * Check for correct nonce and pass to handler. - */ - public function maybe_handle() { - // Don't lock up other requests while processing - session_write_close(); - - check_ajax_referer( $this->identifier, 'nonce' ); - - $this->handle(); - - wp_die(); - } - - /** - * Handle - * - * Override this method to perform any actions required - * during the async request. - */ - abstract protected function handle(); + /** + * Initiate new async request + */ + public function __construct() { + $this->identifier = $this->prefix . '_' . $this->action; + add_action( 'wp_ajax_' . $this->identifier, array( $this, 'maybe_handle' ) ); + add_action( 'wp_ajax_nopriv_' . $this->identifier, array( $this, 'maybe_handle' ) ); } + + /** + * Set data used during the request + * + * @param array $data Data. + * + * @return $this + */ + public function data( $data ) { + $this->data = $data; + + return $this; + } + + /** + * Dispatch the async request + * + * @return array|WP_Error + */ + public function dispatch() { + $url = add_query_arg( $this->get_query_args(), $this->get_query_url() ); + $args = $this->get_post_args(); + + return wp_remote_post( esc_url_raw( $url ), $args ); + } + + /** + * Get query args + * + * @return array + */ + protected function get_query_args() { + if ( property_exists( $this, 'query_args' ) ) { + return $this->query_args; + } + + return array( + 'action' => $this->identifier, + 'nonce' => wp_create_nonce( $this->identifier ), + ); + } + + /** + * Get query URL + * + * @return string + */ + protected function get_query_url() { + if ( property_exists( $this, 'query_url' ) ) { + return $this->query_url; + } + + return admin_url( 'admin-ajax.php' ); + } + + /** + * Get post args + * + * @return array + */ + protected function get_post_args() { + if ( property_exists( $this, 'post_args' ) ) { + return $this->post_args; + } + + return array( + 'timeout' => 0.01, + 'blocking' => false, + 'body' => $this->data, + 'cookies' => $_COOKIE, + 'sslverify' => apply_filters( 'https_local_ssl_verify', false ), + ); + } + + /** + * Maybe handle + * + * Check for correct nonce and pass to handler. + */ + public function maybe_handle() { + // Don't lock up other requests while processing + session_write_close(); + + check_ajax_referer( $this->identifier, 'nonce' ); + + $this->handle(); + + wp_die(); + } + + /** + * Handle + * + * Override this method to perform any actions required + * during the async request. + */ + abstract protected function handle(); } diff --git a/includes/libraries/wp-background-process.php b/includes/libraries/wp-background-process.php index 3b7e76f0f04..e63d8a05d84 100644 --- a/includes/libraries/wp-background-process.php +++ b/includes/libraries/wp-background-process.php @@ -1,504 +1,500 @@ cron_hook_identifier = $this->identifier . '_cron'; + $this->cron_interval_identifier = $this->identifier . '_cron_interval'; - $this->cron_hook_identifier = $this->identifier . '_cron'; - $this->cron_interval_identifier = $this->identifier . '_cron_interval'; + add_action( $this->cron_hook_identifier, array( $this, 'handle_cron_healthcheck' ) ); + add_filter( 'cron_schedules', array( $this, 'schedule_cron_healthcheck' ) ); + } - add_action( $this->cron_hook_identifier, array( $this, 'handle_cron_healthcheck' ) ); - add_filter( 'cron_schedules', array( $this, 'schedule_cron_healthcheck' ) ); + /** + * Dispatch + * + * @access public + * @return void + */ + public function dispatch() { + // Schedule the cron healthcheck. + $this->schedule_event(); + + // Perform remote post. + return parent::dispatch(); + } + + /** + * Push to queue + * + * @param mixed $data Data. + * + * @return $this + */ + public function push_to_queue( $data ) { + $this->data[] = $data; + + return $this; + } + + /** + * Save queue + * + * @return $this + */ + public function save() { + $key = $this->generate_key(); + + if ( ! empty( $this->data ) ) { + update_site_option( $key, $this->data ); } - /** - * Dispatch - * - * @access public - * @return void - */ - public function dispatch() { - // Schedule the cron healthcheck. - $this->schedule_event(); + return $this; + } - // Perform remote post. - return parent::dispatch(); + /** + * Update queue + * + * @param string $key Key. + * @param array $data Data. + * + * @return $this + */ + public function update( $key, $data ) { + if ( ! empty( $data ) ) { + update_site_option( $key, $data ); } - /** - * Push to queue - * - * @param mixed $data Data. - * - * @return $this - */ - public function push_to_queue( $data ) { - $this->data[] = $data; + return $this; + } - return $this; - } + /** + * Delete queue + * + * @param string $key Key. + * + * @return $this + */ + public function delete( $key ) { + delete_site_option( $key ); - /** - * Save queue - * - * @return $this - */ - public function save() { - $key = $this->generate_key(); + return $this; + } - if ( ! empty( $this->data ) ) { - update_site_option( $key, $this->data ); - } + /** + * Generate key + * + * Generates a unique key based on microtime. Queue items are + * given a unique key so that they can be merged upon save. + * + * @param int $length Length. + * + * @return string + */ + protected function generate_key( $length = 64 ) { + $unique = md5( microtime() . rand() ); + $prepend = $this->identifier . '_batch_'; - return $this; - } + return substr( $prepend . $unique, 0, $length ); + } - /** - * Update queue - * - * @param string $key Key. - * @param array $data Data. - * - * @return $this - */ - public function update( $key, $data ) { - if ( ! empty( $data ) ) { - update_site_option( $key, $data ); - } - - return $this; - } - - /** - * Delete queue - * - * @param string $key Key. - * - * @return $this - */ - public function delete( $key ) { - delete_site_option( $key ); - - return $this; - } - - /** - * Generate key - * - * Generates a unique key based on microtime. Queue items are - * given a unique key so that they can be merged upon save. - * - * @param int $length Length. - * - * @return string - */ - protected function generate_key( $length = 64 ) { - $unique = md5( microtime() . rand() ); - $prepend = $this->identifier . '_batch_'; - - return substr( $prepend . $unique, 0, $length ); - } - - /** - * Maybe process queue - * - * Checks whether data exists within the queue and that - * the process is not already running. - */ - public function maybe_handle() { - // Don't lock up other requests while processing - session_write_close(); - - if ( $this->is_process_running() ) { - // Background process already running. - wp_die(); - } - - if ( $this->is_queue_empty() ) { - // No data to process. - wp_die(); - } - - check_ajax_referer( $this->identifier, 'nonce' ); - - $this->handle(); + /** + * Maybe process queue + * + * Checks whether data exists within the queue and that + * the process is not already running. + */ + public function maybe_handle() { + // Don't lock up other requests while processing + session_write_close(); + if ( $this->is_process_running() ) { + // Background process already running. wp_die(); } - /** - * Is queue empty - * - * @return bool - */ - protected function is_queue_empty() { - global $wpdb; - - $table = $wpdb->options; - $column = 'option_name'; - - if ( is_multisite() ) { - $table = $wpdb->sitemeta; - $column = 'meta_key'; - } - - $key = $this->identifier . '_batch_%'; - - $count = $wpdb->get_var( $wpdb->prepare( " - SELECT COUNT(*) - FROM {$table} - WHERE {$column} LIKE %s - ", $key ) ); - - return ( $count > 0 ) ? false : true; + if ( $this->is_queue_empty() ) { + // No data to process. + wp_die(); } - /** - * Is process running - * - * Check whether the current process is already running - * in a background process. - */ - protected function is_process_running() { - if ( get_site_transient( $this->identifier . '_process_lock' ) ) { - // Process already running. - return true; - } + check_ajax_referer( $this->identifier, 'nonce' ); - return false; + $this->handle(); + + wp_die(); + } + + /** + * Is queue empty + * + * @return bool + */ + protected function is_queue_empty() { + global $wpdb; + + $table = $wpdb->options; + $column = 'option_name'; + + if ( is_multisite() ) { + $table = $wpdb->sitemeta; + $column = 'meta_key'; } - /** - * Lock process - * - * Lock the process so that multiple instances can't run simultaneously. - * Override if applicable, but the duration should be greater than that - * defined in the time_exceeded() method. - */ - protected function lock_process() { - $this->start_time = time(); // Set start time of current process. + $key = $this->identifier . '_batch_%'; - $lock_duration = ( property_exists( $this, 'queue_lock_time' ) ) ? $this->queue_lock_time : 60; // 1 minute - $lock_duration = apply_filters( $this->identifier . '_queue_lock_time', $lock_duration ); + $count = $wpdb->get_var( $wpdb->prepare( " + SELECT COUNT(*) + FROM {$table} + WHERE {$column} LIKE %s + ", $key ) ); - set_site_transient( $this->identifier . '_process_lock', microtime(), $lock_duration ); + return ( $count > 0 ) ? false : true; + } + + /** + * Is process running + * + * Check whether the current process is already running + * in a background process. + */ + protected function is_process_running() { + if ( get_site_transient( $this->identifier . '_process_lock' ) ) { + // Process already running. + return true; } - /** - * Unlock process - * - * Unlock the process so that other instances can spawn. - * - * @return $this - */ - protected function unlock_process() { - delete_site_transient( $this->identifier . '_process_lock' ); + return false; + } - return $this; + /** + * Lock process + * + * Lock the process so that multiple instances can't run simultaneously. + * Override if applicable, but the duration should be greater than that + * defined in the time_exceeded() method. + */ + protected function lock_process() { + $this->start_time = time(); // Set start time of current process. + + $lock_duration = ( property_exists( $this, 'queue_lock_time' ) ) ? $this->queue_lock_time : 60; // 1 minute + $lock_duration = apply_filters( $this->identifier . '_queue_lock_time', $lock_duration ); + + set_site_transient( $this->identifier . '_process_lock', microtime(), $lock_duration ); + } + + /** + * Unlock process + * + * Unlock the process so that other instances can spawn. + * + * @return $this + */ + protected function unlock_process() { + delete_site_transient( $this->identifier . '_process_lock' ); + + return $this; + } + + /** + * Get batch + * + * @return stdClass Return the first batch from the queue + */ + protected function get_batch() { + global $wpdb; + + $table = $wpdb->options; + $column = 'option_name'; + $key_column = 'option_id'; + $value_column = 'option_value'; + + if ( is_multisite() ) { + $table = $wpdb->sitemeta; + $column = 'meta_key'; + $key_column = 'meta_id'; + $value_column = 'meta_value'; } - /** - * Get batch - * - * @return stdClass Return the first batch from the queue - */ - protected function get_batch() { - global $wpdb; + $key = $this->identifier . '_batch_%'; - $table = $wpdb->options; - $column = 'option_name'; - $key_column = 'option_id'; - $value_column = 'option_value'; + $query = $wpdb->get_row( $wpdb->prepare( " + SELECT * + FROM {$table} + WHERE {$column} LIKE %s + ORDER BY {$key_column} ASC + LIMIT 1 + ", $key ) ); - if ( is_multisite() ) { - $table = $wpdb->sitemeta; - $column = 'meta_key'; - $key_column = 'meta_id'; - $value_column = 'meta_value'; - } + $batch = new stdClass(); + $batch->key = $query->$column; + $batch->data = maybe_unserialize( $query->$value_column ); - $key = $this->identifier . '_batch_%'; + return $batch; + } - $query = $wpdb->get_row( $wpdb->prepare( " - SELECT * - FROM {$table} - WHERE {$column} LIKE %s - ORDER BY {$key_column} ASC - LIMIT 1 - ", $key ) ); + /** + * Handle + * + * Pass each queue item to the task handler, while remaining + * within server memory and time limit constraints. + */ + protected function handle() { + $this->lock_process(); - $batch = new stdClass(); - $batch->key = $query->$column; - $batch->data = maybe_unserialize( $query->$value_column ); + do { + $batch = $this->get_batch(); - return $batch; - } + foreach ( $batch->data as $key => $value ) { + $task = $this->task( $value ); - /** - * Handle - * - * Pass each queue item to the task handler, while remaining - * within server memory and time limit constraints. - */ - protected function handle() { - $this->lock_process(); - - do { - $batch = $this->get_batch(); - - foreach ( $batch->data as $key => $value ) { - $task = $this->task( $value ); - - if ( false !== $task ) { - $batch->data[ $key ] = $task; - } else { - unset( $batch->data[ $key ] ); - } - - if ( $this->time_exceeded() || $this->memory_exceeded() ) { - // Batch limits reached. - break; - } - } - - // Update or delete current batch. - if ( ! empty( $batch->data ) ) { - $this->update( $batch->key, $batch->data ); + if ( false !== $task ) { + $batch->data[ $key ] = $task; } else { - $this->delete( $batch->key ); + unset( $batch->data[ $key ] ); } - } while ( ! $this->time_exceeded() && ! $this->memory_exceeded() && ! $this->is_queue_empty() ); - $this->unlock_process(); + if ( $this->time_exceeded() || $this->memory_exceeded() ) { + // Batch limits reached. + break; + } + } - // Start next batch or complete process. - if ( ! $this->is_queue_empty() ) { - $this->dispatch(); + // Update or delete current batch. + if ( ! empty( $batch->data ) ) { + $this->update( $batch->key, $batch->data ); } else { - $this->complete(); + $this->delete( $batch->key ); } + } while ( ! $this->time_exceeded() && ! $this->memory_exceeded() && ! $this->is_queue_empty() ); + + $this->unlock_process(); + + // Start next batch or complete process. + if ( ! $this->is_queue_empty() ) { + $this->dispatch(); + } else { + $this->complete(); + } + } + + /** + * Memory exceeded + * + * Ensures the batch process never exceeds 90% + * of the maximum WordPress memory. + * + * @return bool + */ + protected function memory_exceeded() { + $memory_limit = $this->get_memory_limit() * 0.9; // 90% of max memory + $current_memory = memory_get_usage( true ); + $return = false; + + if ( $current_memory >= $memory_limit ) { + $return = true; } - /** - * Memory exceeded - * - * Ensures the batch process never exceeds 90% - * of the maximum WordPress memory. - * - * @return bool - */ - protected function memory_exceeded() { - $memory_limit = $this->get_memory_limit() * 0.9; // 90% of max memory - $current_memory = memory_get_usage( true ); - $return = false; + return apply_filters( $this->identifier . '_memory_exceeded', $return ); + } - if ( $current_memory >= $memory_limit ) { - $return = true; - } - - return apply_filters( $this->identifier . '_memory_exceeded', $return ); + /** + * Get memory limit + * + * @return int + */ + protected function get_memory_limit() { + if ( function_exists( 'ini_get' ) ) { + $memory_limit = ini_get( 'memory_limit' ); + } else { + // Sensible default. + $memory_limit = '128M'; } - /** - * Get memory limit - * - * @return int - */ - protected function get_memory_limit() { - if ( function_exists( 'ini_get' ) ) { - $memory_limit = ini_get( 'memory_limit' ); - } else { - // Sensible default. - $memory_limit = '128M'; - } - - if ( ! $memory_limit || -1 === $memory_limit ) { - // Unlimited, set to 32GB. - $memory_limit = '32000M'; - } - - return intval( $memory_limit ) * 1024 * 1024; + if ( ! $memory_limit || -1 === $memory_limit ) { + // Unlimited, set to 32GB. + $memory_limit = '32000M'; } - /** - * Time exceeded. - * - * Ensures the batch never exceeds a sensible time limit. - * A timeout limit of 30s is common on shared hosting. - * - * @return bool - */ - protected function time_exceeded() { - $finish = $this->start_time + apply_filters( $this->identifier . '_default_time_limit', 20 ); // 20 seconds - $return = false; + return intval( $memory_limit ) * 1024 * 1024; + } - if ( time() >= $finish ) { - $return = true; - } + /** + * Time exceeded. + * + * Ensures the batch never exceeds a sensible time limit. + * A timeout limit of 30s is common on shared hosting. + * + * @return bool + */ + protected function time_exceeded() { + $finish = $this->start_time + apply_filters( $this->identifier . '_default_time_limit', 20 ); // 20 seconds + $return = false; - return apply_filters( $this->identifier . '_time_exceeded', $return ); + if ( time() >= $finish ) { + $return = true; } - /** - * Complete. - * - * Override if applicable, but ensure that the below actions are - * performed, or, call parent::complete(). - */ - protected function complete() { - // Unschedule the cron healthcheck. - $this->clear_scheduled_event(); + return apply_filters( $this->identifier . '_time_exceeded', $return ); + } + + /** + * Complete. + * + * Override if applicable, but ensure that the below actions are + * performed, or, call parent::complete(). + */ + protected function complete() { + // Unschedule the cron healthcheck. + $this->clear_scheduled_event(); + } + + /** + * Schedule cron healthcheck + * + * @access public + * @param mixed $schedules Schedules. + * @return mixed + */ + public function schedule_cron_healthcheck( $schedules ) { + $interval = apply_filters( $this->identifier . '_cron_interval', 5 ); + + if ( property_exists( $this, 'cron_interval' ) ) { + $interval = apply_filters( $this->identifier . '_cron_interval', $this->cron_interval_identifier ); } - /** - * Schedule cron healthcheck - * - * @access public - * @param mixed $schedules Schedules. - * @return mixed - */ - public function schedule_cron_healthcheck( $schedules ) { - $interval = apply_filters( $this->identifier . '_cron_interval', 5 ); + // Adds every 5 minutes to the existing schedules. + $schedules[ $this->identifier . '_cron_interval' ] = array( + 'interval' => MINUTE_IN_SECONDS * $interval, + 'display' => sprintf( __( 'Every %d minutes', 'woocommerce' ), $interval ), + ); - if ( property_exists( $this, 'cron_interval' ) ) { - $interval = apply_filters( $this->identifier . '_cron_interval', $this->cron_interval_identifier ); - } - - // Adds every 5 minutes to the existing schedules. - $schedules[ $this->identifier . '_cron_interval' ] = array( - 'interval' => MINUTE_IN_SECONDS * $interval, - 'display' => sprintf( __( 'Every %d minutes', 'woocommerce' ), $interval ), - ); - - return $schedules; - } - - /** - * Handle cron healthcheck - * - * Restart the background process if not already running - * and data exists in the queue. - */ - public function handle_cron_healthcheck() { - if ( $this->is_process_running() ) { - // Background process already running. - exit; - } - - if ( $this->is_queue_empty() ) { - // No data to process. - $this->clear_scheduled_event(); - exit; - } - - $this->handle(); + return $schedules; + } + /** + * Handle cron healthcheck + * + * Restart the background process if not already running + * and data exists in the queue. + */ + public function handle_cron_healthcheck() { + if ( $this->is_process_running() ) { + // Background process already running. exit; } - /** - * Schedule event - */ - protected function schedule_event() { - if ( ! wp_next_scheduled( $this->cron_hook_identifier ) ) { - wp_schedule_event( time(), $this->cron_interval_identifier, $this->cron_hook_identifier ); - } + if ( $this->is_queue_empty() ) { + // No data to process. + $this->clear_scheduled_event(); + exit; } - /** - * Clear scheduled event - */ - protected function clear_scheduled_event() { - $timestamp = wp_next_scheduled( $this->cron_hook_identifier ); + $this->handle(); - if ( $timestamp ) { - wp_unschedule_event( $timestamp, $this->cron_hook_identifier ); - } + exit; + } + + /** + * Schedule event + */ + protected function schedule_event() { + if ( ! wp_next_scheduled( $this->cron_hook_identifier ) ) { + wp_schedule_event( time(), $this->cron_interval_identifier, $this->cron_hook_identifier ); } + } - /** - * Cancel Process - * - * Stop processing queue items, clear cronjob and delete batch. - * - */ - public function cancel_process() { - if ( ! $this->is_queue_empty() ) { - $batch = $this->get_batch(); - - $this->delete( $batch->key ); - - wp_clear_scheduled_hook( $this->cron_hook_identifier ); - } + /** + * Clear scheduled event + */ + protected function clear_scheduled_event() { + $timestamp = wp_next_scheduled( $this->cron_hook_identifier ); + if ( $timestamp ) { + wp_unschedule_event( $timestamp, $this->cron_hook_identifier ); } + } - /** - * Task - * - * Override this method to perform any actions required on each - * queue item. Return the modified item for further processing - * in the next pass through. Or, return false to remove the - * item from the queue. - * - * @param mixed $item Queue item to iterate over. - * - * @return mixed - */ - abstract protected function task( $item ); + /** + * Cancel Process + * + * Stop processing queue items, clear cronjob and delete batch. + * + */ + public function cancel_process() { + if ( ! $this->is_queue_empty() ) { + $batch = $this->get_batch(); + + $this->delete( $batch->key ); + + wp_clear_scheduled_hook( $this->cron_hook_identifier ); + } } + + /** + * Task + * + * Override this method to perform any actions required on each + * queue item. Return the modified item for further processing + * in the next pass through. Or, return false to remove the + * item from the queue. + * + * @param mixed $item Queue item to iterate over. + * + * @return mixed + */ + abstract protected function task( $item ); + } diff --git a/includes/walkers/class-product-cat-dropdown-walker.php b/includes/walkers/class-product-cat-dropdown-walker.php index f3e366066c0..5b43118a792 100644 --- a/includes/walkers/class-product-cat-dropdown-walker.php +++ b/includes/walkers/class-product-cat-dropdown-walker.php @@ -13,7 +13,7 @@ if ( ! defined( 'ABSPATH' ) ) { exit; // Exit if accessed directly } -if ( ! class_exists( 'WC_Product_Cat_Dropdown_Walker' ) ) : +if ( ! class_exists( 'WC_Product_Cat_Dropdown_Walker', false ) ) : class WC_Product_Cat_Dropdown_Walker extends Walker { diff --git a/includes/walkers/class-product-cat-list-walker.php b/includes/walkers/class-product-cat-list-walker.php index 4fc2ecd5c96..91e214587eb 100644 --- a/includes/walkers/class-product-cat-list-walker.php +++ b/includes/walkers/class-product-cat-list-walker.php @@ -13,7 +13,7 @@ if ( ! defined( 'ABSPATH' ) ) { exit; // Exit if accessed directly } -if ( ! class_exists( 'WC_Product_Cat_List_Walker' ) ) : +if ( ! class_exists( 'WC_Product_Cat_List_Walker', false ) ) : class WC_Product_Cat_List_Walker extends Walker { diff --git a/includes/wc-core-functions.php b/includes/wc-core-functions.php index 827e038a40d..5db0a13cc4d 100644 --- a/includes/wc-core-functions.php +++ b/includes/wc-core-functions.php @@ -29,6 +29,8 @@ include( 'wc-account-functions.php' ); include( 'wc-term-functions.php' ); include( 'wc-attribute-functions.php' ); include( 'wc-rest-functions.php' ); +include( 'wc-widget-functions.php' ); +include( 'wc-webhook-functions.php' ); /** * Filters on data used in admin and frontend. diff --git a/includes/wc-deprecated-functions.php b/includes/wc-deprecated-functions.php index 6d451edc902..2897d00d17f 100644 --- a/includes/wc-deprecated-functions.php +++ b/includes/wc-deprecated-functions.php @@ -14,16 +14,6 @@ if ( ! defined( 'ABSPATH' ) ) { exit; } -include_once( 'abstracts/abstract-wc-deprecated-hooks.php' ); -include_once( 'class-wc-deprecated-action-hooks.php' ); -include_once( 'class-wc-deprecated-filter-hooks.php' ); - -function wc_initialize_deprecated_hook_handlers() { - WC()->deprecated_hook_handlers['actions'] = new WC_Deprecated_Action_Hooks(); - WC()->deprecated_hook_handlers['filters'] = new WC_Deprecated_Filter_Hooks(); -} -add_action( 'woocommerce_init', 'wc_initialize_deprecated_hook_handlers' ); - /** * Runs a deprecated action with notice only if used. * diff --git a/includes/wc-term-functions.php b/includes/wc-term-functions.php index 0e79e58bd0f..d354b63ee4e 100644 --- a/includes/wc-term-functions.php +++ b/includes/wc-term-functions.php @@ -234,7 +234,7 @@ function wc_product_dropdown_categories( $args = array(), $deprecated_hierarchic function wc_walk_category_dropdown_tree() { $args = func_get_args(); - if ( ! class_exists( 'WC_Product_Cat_Dropdown_Walker' ) ) { + if ( ! class_exists( 'WC_Product_Cat_Dropdown_Walker', false ) ) { include_once( WC()->plugin_path() . '/includes/walkers/class-product-cat-dropdown-walker.php' ); } diff --git a/woocommerce.php b/woocommerce.php index 7e75b313f1e..b31091ebdfd 100644 --- a/woocommerce.php +++ b/woocommerce.php @@ -252,41 +252,14 @@ final class WooCommerce { * Include required core files used in admin and on the frontend. */ public function includes() { + /** + * Class autoloader. + */ include_once( WC_ABSPATH . 'includes/class-wc-autoloader.php' ); - include_once( WC_ABSPATH . 'includes/wc-core-functions.php' ); - include_once( WC_ABSPATH . 'includes/class-wc-register-wp-admin-settings.php' ); - include_once( WC_ABSPATH . 'includes/wc-widget-functions.php' ); - include_once( WC_ABSPATH . 'includes/wc-webhook-functions.php' ); - include_once( WC_ABSPATH . 'includes/class-wc-install.php' ); - include_once( WC_ABSPATH . 'includes/class-wc-geolocation.php' ); - include_once( WC_ABSPATH . 'includes/class-wc-download-handler.php' ); - include_once( WC_ABSPATH . 'includes/class-wc-comments.php' ); - include_once( WC_ABSPATH . 'includes/class-wc-post-data.php' ); - include_once( WC_ABSPATH . 'includes/class-wc-ajax.php' ); - include_once( WC_ABSPATH . 'includes/abstracts/abstract-wc-data.php' ); // WC_Data for CRUD - include_once( WC_ABSPATH . 'includes/class-wc-data-exception.php' ); - - if ( $this->is_request( 'admin' ) ) { - include_once( WC_ABSPATH . 'includes/admin/class-wc-admin.php' ); - } - - if ( $this->is_request( 'frontend' ) ) { - $this->frontend_includes(); - } - - if ( $this->is_request( 'frontend' ) || $this->is_request( 'cron' ) ) { - include_once( WC_ABSPATH . 'includes/class-wc-session-handler.php' ); - } - - if ( $this->is_request( 'cron' ) && 'yes' === get_option( 'woocommerce_allow_tracking', 'no' ) ) { - include_once( WC_ABSPATH . 'includes/class-wc-tracker.php' ); - } - - include_once( WC_ABSPATH . 'includes/class-wc-query.php' ); // The main query class - include_once( WC_ABSPATH . 'includes/class-wc-api.php' ); // API Class - include_once( WC_ABSPATH . 'includes/class-wc-auth.php' ); // Auth Class - include_once( WC_ABSPATH . 'includes/class-wc-post-types.php' ); // Registers post types + /** + * Interfaces. + */ include_once( WC_ABSPATH . 'includes/interfaces/class-wc-abstract-order-data-store-interface.php' ); include_once( WC_ABSPATH . 'includes/interfaces/class-wc-coupon-data-store-interface.php' ); include_once( WC_ABSPATH . 'includes/interfaces/class-wc-customer-data-store-interface.php' ); @@ -303,6 +276,11 @@ final class WooCommerce { include_once( WC_ABSPATH . 'includes/interfaces/class-wc-shipping-zone-data-store-interface.php' ); include_once( WC_ABSPATH . 'includes/interfaces/class-wc-logger-interface.php' ); include_once( WC_ABSPATH . 'includes/interfaces/class-wc-log-handler-interface.php' ); + + /** + * Abstract classes. + */ + include_once( WC_ABSPATH . 'includes/abstracts/abstract-wc-data.php' ); // WC_Data for CRUD include_once( WC_ABSPATH . 'includes/abstracts/abstract-wc-payment-token.php' ); // Payment Tokens include_once( WC_ABSPATH . 'includes/abstracts/abstract-wc-product.php' ); // Products include_once( WC_ABSPATH . 'includes/abstracts/abstract-wc-order.php' ); // Orders @@ -311,6 +289,24 @@ final class WooCommerce { include_once( WC_ABSPATH . 'includes/abstracts/abstract-wc-payment-gateway.php' ); // A Payment gateway include_once( WC_ABSPATH . 'includes/abstracts/abstract-wc-integration.php' ); // An integration with a service include_once( WC_ABSPATH . 'includes/abstracts/abstract-wc-log-handler.php' ); + include_once( WC_ABSPATH . 'includes/abstracts/abstract-wc-deprecated-hooks.php' ); + include_once( WC_ABSPATH . 'includes/abstracts/abstract-wc-session.php' ); + + /** + * Core classes. + */ + include_once( WC_ABSPATH . 'includes/wc-core-functions.php' ); + include_once( WC_ABSPATH . 'includes/class-wc-post-types.php' ); // Registers post types + include_once( WC_ABSPATH . 'includes/class-wc-install.php' ); + include_once( WC_ABSPATH . 'includes/class-wc-geolocation.php' ); + include_once( WC_ABSPATH . 'includes/class-wc-download-handler.php' ); + include_once( WC_ABSPATH . 'includes/class-wc-comments.php' ); + include_once( WC_ABSPATH . 'includes/class-wc-post-data.php' ); + include_once( WC_ABSPATH . 'includes/class-wc-ajax.php' ); + include_once( WC_ABSPATH . 'includes/class-wc-emails.php' ); + include_once( WC_ABSPATH . 'includes/class-wc-data-exception.php' ); + include_once( WC_ABSPATH . 'includes/class-wc-query.php' ); + include_once( WC_ABSPATH . 'includes/class-wc-order-factory.php' ); // Order factory include_once( WC_ABSPATH . 'includes/class-wc-product-factory.php' ); // Product factory include_once( WC_ABSPATH . 'includes/class-wc-payment-tokens.php' ); // Payment tokens controller include_once( WC_ABSPATH . 'includes/class-wc-shipping-zone.php' ); @@ -320,7 +316,13 @@ final class WooCommerce { include_once( WC_ABSPATH . 'includes/class-wc-integrations.php' ); // Loads integrations include_once( WC_ABSPATH . 'includes/class-wc-cache-helper.php' ); // Cache Helper include_once( WC_ABSPATH . 'includes/class-wc-https.php' ); // https Helper - include_once( WC_ABSPATH . 'includes/class-wc-data-store.php' ); // WC_Data_Store for CRUD + include_once( WC_ABSPATH . 'includes/class-wc-deprecated-action-hooks.php' ); + include_once( WC_ABSPATH . 'includes/class-wc-deprecated-filter-hooks.php' ); + + /** + * Data stores - used to store and retrieve CRUD object data from the database. + */ + include_once( WC_ABSPATH . 'includes/class-wc-data-store.php' ); include_once( WC_ABSPATH . 'includes/data-stores/class-wc-data-store-wp.php' ); include_once( WC_ABSPATH . 'includes/data-stores/class-wc-coupon-data-store-cpt.php' ); include_once( WC_ABSPATH . 'includes/data-stores/class-wc-product-data-store-cpt.php' ); @@ -343,9 +345,32 @@ final class WooCommerce { include_once( WC_ABSPATH . 'includes/data-stores/class-wc-order-data-store-cpt.php' ); include_once( WC_ABSPATH . 'includes/data-stores/class-wc-order-refund-data-store-cpt.php' ); + /** + * REST API. + */ + include_once( WC_ABSPATH . 'includes/class-wc-legacy-api.php' ); + include_once( WC_ABSPATH . 'includes/class-wc-api.php' ); // API Class + include_once( WC_ABSPATH . 'includes/class-wc-auth.php' ); // Auth Class + include_once( WC_ABSPATH . 'includes/class-wc-register-wp-admin-settings.php' ); + if ( defined( 'WP_CLI' ) && WP_CLI ) { - include_once( WC_ABSPATH . 'includes/class-wc-cli.php' ); - new WC_CLI; + include_once( WC_ABSPATH . 'includes/class-wc-cli.php' ); + } + + if ( $this->is_request( 'admin' ) ) { + include_once( WC_ABSPATH . 'includes/admin/class-wc-admin.php' ); + } + + if ( $this->is_request( 'frontend' ) ) { + $this->frontend_includes(); + } + + if ( $this->is_request( 'frontend' ) || $this->is_request( 'cron' ) ) { + include_once( WC_ABSPATH . 'includes/class-wc-session-handler.php' ); + } + + if ( $this->is_request( 'cron' ) && 'yes' === get_option( 'woocommerce_allow_tracking', 'no' ) ) { + include_once( WC_ABSPATH . 'includes/class-wc-tracker.php' ); } $this->query = new WC_Query(); @@ -393,11 +418,13 @@ final class WooCommerce { $this->load_plugin_textdomain(); // Load class instances. - $this->product_factory = new WC_Product_Factory(); // Product Factory to create new product instances - $this->order_factory = new WC_Order_Factory(); // Order Factory to create new order instances - $this->countries = new WC_Countries(); // Countries class - $this->integrations = new WC_Integrations(); // Integrations class - $this->structured_data = new WC_Structured_Data(); // Structured Data class, generates and handles structured data + $this->product_factory = new WC_Product_Factory(); // Product Factory to create new product instances + $this->order_factory = new WC_Order_Factory(); // Order Factory to create new order instances + $this->countries = new WC_Countries(); // Countries class + $this->integrations = new WC_Integrations(); // Integrations class + $this->structured_data = new WC_Structured_Data(); // Structured Data class, generates and handles structured data + $this->deprecated_hook_handlers['actions'] = new WC_Deprecated_Action_Hooks(); + $this->deprecated_hook_handlers['filters'] = new WC_Deprecated_Filter_Hooks(); // Session class, handles session data for users - can be overwritten if custom handler is needed. if ( $this->is_request( 'frontend' ) || $this->is_request( 'cron' ) ) {