From 98c1fbd2ea89a4958a2613bb013d709bef716c12 Mon Sep 17 00:00:00 2001 From: Tim Hughes Date: Thu, 19 Nov 2020 14:44:07 +0000 Subject: [PATCH] Version 1.0.3 bump (#296) --- CHANGELOG.txt | 127 +-- classic-commerce.php | 360 ++++---- includes/class-woocommerce.php | 1442 ++++++++++++++++---------------- 3 files changed, 968 insertions(+), 961 deletions(-) diff --git a/CHANGELOG.txt b/CHANGELOG.txt index aed2a6c955..f6353fda3c 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -1,60 +1,67 @@ -== Changelog == - -= 1.0.1 - 2020-10-17 -Fixed: CC icon not showing in some installations #289 - -= 1.0.0 - 2020-10-01 -New: Complete new set of sample products created specifically for CC #284 -Updated: All documentation links now point to classiccommerce.cc #274, #278, #281 -Fixed: CC icon wasn't turning blue on hover #265 -Updated: Update manager updated to v2 #264 -Updated: node-sass and handlebars dependencies #258, #259 -Improved: Stock levels are now hidden on the dashboard widget if inventory is disabled #261 -Improved: Additional checks made during build process #269 -Tweaks: Some well-hidden instances of WC purple changes to CC aqua #270, #271 - -= 1.0.0-rc.2 - 2020-08-29 -Fixed: Corrected color of two images to CC aqua, missed in rc1. #255 - -= 1.0.0-rc.1 - 2020-08-29 -Fixed: Incorrect escaping of strings in setup wizard and order edit page. #244 -Improved: Better checks and improved messaging when invalid file type chosen for CSV tax import. #245 -Improved: CSS tweaks to enhance CC branding. New CC aqua color introduced. #247 -Improved: Big improvements to CC build process. #250, #251 -Tweaked: Removed all references to old ClassicPress-Research repository. #249 - -= 1.0.0-beta.1 - 2020-05-16 -Improved automated testing on GitHub (#174) -Coding standards improvements (#174) -Added user agent (#202) -Various CSS tweaks -Various spacing and capitalization tweaks -Rename logo and icon image files as per CP naming standard (#210) -Updates to CodePotent Update Manager (#215) -Comb out remnant css after Install wizard + Jetpack + woo services removal (#204) -Backport security fixes from WC 3.8.0 and below (#218, #219, #220, #221, #222, #225, #228, #229, #230) -Improved compatibility with PHP 7.4, ready for upcoming ClassicPress 1.2.0 (#225) -Changed composer.json "type" back to "wordpress-plugin" for greater compatibility (#239, #240) - -= 1.0.0-alpha.3 - 2020-01-20 -NEW: Add usage tracking notice & opt-out -NEW: Change template path to look for classic-commerce in theme folder -UPDATE: Improve CC/Woo activation logic -UPDATE: Change compatibility plugin warning message -FIX: Fix deactivating WC/CC issue and change notice -FIX: Prevent PHP fatal error when trying to activate WC while CC is still active -FIX: Fix for CC admin menu icon display issues -FiX: Prevent the compatibility plugin notice from appearing when it shouldn't -Other minor tweaks - -= 1.0.0-alpha.2 - 2019-12-29 -Fix for issues #159 and #162 - notices displaying when they shouldn't - -= 1.0.0-alpha1 - 2019-12-28 -First alpha release of Classic Commerce - -= 0.1.0 - 2018-05-24 = -WIP - Forking and documenting Classic Commerce 0.1.0 - -= WooCommerce 3.4.5 - 2018-08-29 = -[See changelog archive for all versions](https://raw.githubusercontent.com/ClassicPress-plugins/classic-commerce/master/CHANGELOG-Archive.txt). +== Changelog == + += 1.0.3 - 2020-11-19 +Fixed: Fix for failing travis builds #294 +Fixed: Backport of WC security fix [e711a44](https://github.com/woocommerce/woocommerce/commit/e711a447feaf3d6020204e4319fdd5ba47c3f0b9). See [this post](See changelog archive for all versions](https://developer.woocommerce.com/2020/11/05/woocommerce-4-6-2-fix-release/). #293 +Fixed: Update email template override to use classic-commerce directory instead of woocommerce #292 + += 1.0.2 - No release + += 1.0.1 - 2020-10-17 +Fixed: CC icon not showing in some installations #289 + += 1.0.0 - 2020-10-01 +New: Complete new set of sample products created specifically for CC #284 +Updated: All documentation links now point to classiccommerce.cc #274, #278, #281 +Fixed: CC icon wasn't turning blue on hover #265 +Updated: Update manager updated to v2 #264 +Updated: node-sass and handlebars dependencies #258, #259 +Improved: Stock levels are now hidden on the dashboard widget if inventory is disabled #261 +Improved: Additional checks made during build process #269 +Tweaks: Some well-hidden instances of WC purple changes to CC aqua #270, #271 + += 1.0.0-rc.2 - 2020-08-29 +Fixed: Corrected color of two images to CC aqua, missed in rc1. #255 + += 1.0.0-rc.1 - 2020-08-29 +Fixed: Incorrect escaping of strings in setup wizard and order edit page. #244 +Improved: Better checks and improved messaging when invalid file type chosen for CSV tax import. #245 +Improved: CSS tweaks to enhance CC branding. New CC aqua color introduced. #247 +Improved: Big improvements to CC build process. #250, #251 +Tweaked: Removed all references to old ClassicPress-Research repository. #249 + += 1.0.0-beta.1 - 2020-05-16 +Improved automated testing on GitHub (#174) +Coding standards improvements (#174) +Added user agent (#202) +Various CSS tweaks +Various spacing and capitalization tweaks +Rename logo and icon image files as per CP naming standard (#210) +Updates to CodePotent Update Manager (#215) +Comb out remnant css after Install wizard + Jetpack + woo services removal (#204) +Backport security fixes from WC 3.8.0 and below (#218, #219, #220, #221, #222, #225, #228, #229, #230) +Improved compatibility with PHP 7.4, ready for upcoming ClassicPress 1.2.0 (#225) +Changed composer.json "type" back to "wordpress-plugin" for greater compatibility (#239, #240) + += 1.0.0-alpha.3 - 2020-01-20 +NEW: Add usage tracking notice & opt-out +NEW: Change template path to look for classic-commerce in theme folder +UPDATE: Improve CC/Woo activation logic +UPDATE: Change compatibility plugin warning message +FIX: Fix deactivating WC/CC issue and change notice +FIX: Prevent PHP fatal error when trying to activate WC while CC is still active +FIX: Fix for CC admin menu icon display issues +FiX: Prevent the compatibility plugin notice from appearing when it shouldn't +Other minor tweaks + += 1.0.0-alpha.2 - 2019-12-29 +Fix for issues #159 and #162 - notices displaying when they shouldn't + += 1.0.0-alpha1 - 2019-12-28 +First alpha release of Classic Commerce + += 0.1.0 - 2018-05-24 = +WIP - Forking and documenting Classic Commerce 0.1.0 + += WooCommerce 3.4.5 - 2018-08-29 = +[See changelog archive for all versions](https://raw.githubusercontent.com/ClassicPress-plugins/classic-commerce/master/CHANGELOG-Archive.txt). diff --git a/classic-commerce.php b/classic-commerce.php index 0769b156d9..46763b2406 100644 --- a/classic-commerce.php +++ b/classic-commerce.php @@ -1,180 +1,180 @@ -'; - echo '

'; - echo esc_html__( 'You must deactivate WooCommerce before activating Classic Commerce.', 'classic-commerce' ); - echo '

'; - echo '

'; - echo esc_html__( 'Classic Commerce has not been activated.', 'classic-commerce' ); - echo '

'; - echo ''; -} - -/** - * Shows an error message when Classic Commerce is active and the user attempts - * to activate WooCommerce. - * - * WooCommerce and Classic Commerce cannot both be active at once. - * - * @return void - */ -function cc_wc_activate_attempted_notice() { - echo '
'; - echo '

'; - echo esc_html__( 'You must deactivate Classic Commerce before activating WooCommerce.', 'classic-commerce' ); - echo '

'; - echo '

'; - echo esc_html__( 'WooCommerce has not been activated.', 'classic-commerce' ); - echo '

'; - echo '
'; -} - -$_cc_can_load = true; - -// Check if WooCommerce is already active. In this case we need to block -// Classic Commerce from being activated to avoid fatal errors. -if ( - file_exists( WP_PLUGIN_DIR . '/woocommerce/woocommerce.php' ) && - // Make sure we are really looking at WooCommerce and not the compatibility plugin! - file_exists( WP_PLUGIN_DIR . '/woocommerce/includes/class-woocommerce.php' ) && - is_plugin_active( 'woocommerce/woocommerce.php' ) -) { - - // WooCommerce is already active. Show an admin notice. - add_action( 'admin_notices', 'cc_wc_already_active_notice' ); - - // Deactivate Classic Commerce. - deactivate_plugins( array( 'classic-commerce/classic-commerce.php' ) ); - - // Avoid showing a "Plugin activated" message in the admin screen. - // See also src/wp-admin/plugins.php in core. - unset( $_GET['activate'] ); - - // Do not proceed further with Classic Commerce loading. - $_cc_can_load = false; - -} else if ( - // Check if this is a request that would activate WooCommerce. Since - // Classic Commerce is already active then we also need to prevent - // WooCommerce from being activated, again to avoid fatal errors. - // - // Plugin activation happens after plugins load and after `init` so we need - // to check for the presence of the related request parameters here. - // - // See also src/wp-admin/plugins.php in core. - is_admin() && - strpos( $_SERVER['REQUEST_URI'], '/plugins.php' ) !== false && - ( isset( $_REQUEST['action'] ) || isset( $_REQUEST['action2'] ) ) && - // Make sure we are really looking at WooCommerce and not the compatibility plugin! - file_exists( WP_PLUGIN_DIR . '/woocommerce/includes/class-woocommerce.php' ) -) { - $is_activate_woo_request = false; - - // Check if the user tried to activate WooCommerce by itself. - if ( - isset( $_GET['action'] ) && - $_GET['action'] === 'activate' && - isset( $_GET['plugin'] ) && - $_GET['plugin'] === 'woocommerce/woocommerce.php' - ) { - $is_activate_woo_request = true; - } - - // Check if the user tried to activate WooCommerce using either of the two - // "Bulk Actions" dropdown boxes. - if ( - ( - ( isset( $_POST['action'] ) && $_POST['action'] === 'activate-selected' ) || - ( isset( $_POST['action2'] ) && $_POST['action2'] === 'activate-selected' ) - ) && - isset( $_POST['checked'] ) && - in_array( 'woocommerce/woocommerce.php', (array) wp_unslash( $_POST['checked'] ) ) - ) { - $is_activate_woo_request = true; - } - - if ( $is_activate_woo_request ) { - // Show an admin notice. - add_action( 'admin_notices', 'cc_wc_activate_attempted_notice' ); - - // Block WooCommerce from being activated. - unset( $_GET['action'] ); - unset( $_POST['action'] ); - unset( $_REQUEST['action'] ); - unset( $_POST['action2'] ); - unset( $_REQUEST['action2'] ); - - // Proceed normally with the Classic Commerce loading process below. - } -} - -if ( $_cc_can_load ) { - - //////////////////////////////////////////// - // BEGIN CLASSIC COMMERCE LOADING PROCESS // - //////////////////////////////////////////// - - // Load the Update Client to manage Classic Commerce updates. - include_once dirname( __FILE__ ) . '/includes/class-wc-update-client.php'; - - // Define WC_PLUGIN_FILE. - if ( ! defined( 'WC_PLUGIN_FILE' ) ) { - define( 'WC_PLUGIN_FILE', __FILE__ ); - } - - // Include the main WooCommerce class. - if ( ! class_exists( 'WooCommerce' ) ) { - include_once dirname( __FILE__ ) . '/includes/class-woocommerce.php'; - } - - /** - * Main instance of WooCommerce. - * - * Returns the main instance of WC to prevent the need to use globals. - * - * @since 2.1 - * @return WooCommerce - */ - function wc() { - return WooCommerce::instance(); - } - - // Global for backwards compatibility. - $GLOBALS['woocommerce'] = wc(); - - ////////////////////////////////////////// - // END CLASSIC COMMERCE LOADING PROCESS // - ////////////////////////////////////////// - -} - -// Do not add any new code here! All code required to load Classic Commerce -// must go inside the "CLASSIC COMMERCE LOADING PROCESS" block above. +'; + echo '

'; + echo esc_html__( 'You must deactivate WooCommerce before activating Classic Commerce.', 'classic-commerce' ); + echo '

'; + echo '

'; + echo esc_html__( 'Classic Commerce has not been activated.', 'classic-commerce' ); + echo '

'; + echo ''; +} + +/** + * Shows an error message when Classic Commerce is active and the user attempts + * to activate WooCommerce. + * + * WooCommerce and Classic Commerce cannot both be active at once. + * + * @return void + */ +function cc_wc_activate_attempted_notice() { + echo '
'; + echo '

'; + echo esc_html__( 'You must deactivate Classic Commerce before activating WooCommerce.', 'classic-commerce' ); + echo '

'; + echo '

'; + echo esc_html__( 'WooCommerce has not been activated.', 'classic-commerce' ); + echo '

'; + echo '
'; +} + +$_cc_can_load = true; + +// Check if WooCommerce is already active. In this case we need to block +// Classic Commerce from being activated to avoid fatal errors. +if ( + file_exists( WP_PLUGIN_DIR . '/woocommerce/woocommerce.php' ) && + // Make sure we are really looking at WooCommerce and not the compatibility plugin! + file_exists( WP_PLUGIN_DIR . '/woocommerce/includes/class-woocommerce.php' ) && + is_plugin_active( 'woocommerce/woocommerce.php' ) +) { + + // WooCommerce is already active. Show an admin notice. + add_action( 'admin_notices', 'cc_wc_already_active_notice' ); + + // Deactivate Classic Commerce. + deactivate_plugins( array( 'classic-commerce/classic-commerce.php' ) ); + + // Avoid showing a "Plugin activated" message in the admin screen. + // See also src/wp-admin/plugins.php in core. + unset( $_GET['activate'] ); + + // Do not proceed further with Classic Commerce loading. + $_cc_can_load = false; + +} else if ( + // Check if this is a request that would activate WooCommerce. Since + // Classic Commerce is already active then we also need to prevent + // WooCommerce from being activated, again to avoid fatal errors. + // + // Plugin activation happens after plugins load and after `init` so we need + // to check for the presence of the related request parameters here. + // + // See also src/wp-admin/plugins.php in core. + is_admin() && + strpos( $_SERVER['REQUEST_URI'], '/plugins.php' ) !== false && + ( isset( $_REQUEST['action'] ) || isset( $_REQUEST['action2'] ) ) && + // Make sure we are really looking at WooCommerce and not the compatibility plugin! + file_exists( WP_PLUGIN_DIR . '/woocommerce/includes/class-woocommerce.php' ) +) { + $is_activate_woo_request = false; + + // Check if the user tried to activate WooCommerce by itself. + if ( + isset( $_GET['action'] ) && + $_GET['action'] === 'activate' && + isset( $_GET['plugin'] ) && + $_GET['plugin'] === 'woocommerce/woocommerce.php' + ) { + $is_activate_woo_request = true; + } + + // Check if the user tried to activate WooCommerce using either of the two + // "Bulk Actions" dropdown boxes. + if ( + ( + ( isset( $_POST['action'] ) && $_POST['action'] === 'activate-selected' ) || + ( isset( $_POST['action2'] ) && $_POST['action2'] === 'activate-selected' ) + ) && + isset( $_POST['checked'] ) && + in_array( 'woocommerce/woocommerce.php', (array) wp_unslash( $_POST['checked'] ) ) + ) { + $is_activate_woo_request = true; + } + + if ( $is_activate_woo_request ) { + // Show an admin notice. + add_action( 'admin_notices', 'cc_wc_activate_attempted_notice' ); + + // Block WooCommerce from being activated. + unset( $_GET['action'] ); + unset( $_POST['action'] ); + unset( $_REQUEST['action'] ); + unset( $_POST['action2'] ); + unset( $_REQUEST['action2'] ); + + // Proceed normally with the Classic Commerce loading process below. + } +} + +if ( $_cc_can_load ) { + + //////////////////////////////////////////// + // BEGIN CLASSIC COMMERCE LOADING PROCESS // + //////////////////////////////////////////// + + // Load the Update Client to manage Classic Commerce updates. + include_once dirname( __FILE__ ) . '/includes/class-wc-update-client.php'; + + // Define WC_PLUGIN_FILE. + if ( ! defined( 'WC_PLUGIN_FILE' ) ) { + define( 'WC_PLUGIN_FILE', __FILE__ ); + } + + // Include the main WooCommerce class. + if ( ! class_exists( 'WooCommerce' ) ) { + include_once dirname( __FILE__ ) . '/includes/class-woocommerce.php'; + } + + /** + * Main instance of WooCommerce. + * + * Returns the main instance of WC to prevent the need to use globals. + * + * @since 2.1 + * @return WooCommerce + */ + function wc() { + return WooCommerce::instance(); + } + + // Global for backwards compatibility. + $GLOBALS['woocommerce'] = wc(); + + ////////////////////////////////////////// + // END CLASSIC COMMERCE LOADING PROCESS // + ////////////////////////////////////////// + +} + +// Do not add any new code here! All code required to load Classic Commerce +// must go inside the "CLASSIC COMMERCE LOADING PROCESS" block above. diff --git a/includes/class-woocommerce.php b/includes/class-woocommerce.php index 5b1e6ab558..ae3adb7834 100644 --- a/includes/class-woocommerce.php +++ b/includes/class-woocommerce.php @@ -1,721 +1,721 @@ -$key(); - } - } - - /** - * Classic Commerce Constructor. - */ - public function __construct() { - $this->define_constants(); - $this->includes(); - $this->init_hooks(); - - do_action( 'woocommerce_loaded' ); - } - - /** - * Hook into actions and filters. - * - * @since WC-2.3 - */ - private function init_hooks() { - register_activation_hook( WC_PLUGIN_FILE, array( 'WC_Install', 'install' ) ); - register_shutdown_function( array( $this, 'log_errors' ) ); - add_action( 'after_setup_theme', array( $this, 'setup_environment' ) ); - add_action( 'after_setup_theme', array( $this, 'include_template_functions' ), 11 ); - add_action( 'init', array( $this, 'init' ), 0 ); - add_action( 'init', array( 'WC_Shortcodes', 'init' ) ); - add_action( 'init', array( 'WC_Emails', 'init_transactional_emails' ) ); - add_action( 'init', array( $this, 'wpdb_table_fix' ), 0 ); - add_action( 'init', array( $this, 'add_image_sizes' ) ); - add_action( 'switch_blog', array( $this, 'wpdb_table_fix' ), 0 ); - add_action( 'admin_head', array( $this, 'load_icon_style' ) ); - } - - /** - * Some plugins block loading of menu.css causing the CC menu icon to display incorrectly. - * Here we add the necessary style to ensure the icon style is loaded. - */ - public function load_icon_style() { - echo ''; - } - - /** - * Ensures fatal errors are logged so they can be picked up in the status report. - * - * @since WC-3.2.0 - */ - public function log_errors() { - $error = error_get_last(); - if ( $error && in_array( $error['type'], array( E_ERROR, E_PARSE, E_COMPILE_ERROR, E_USER_ERROR, E_RECOVERABLE_ERROR ) ) ) { - $logger = wc_get_logger(); - $logger->critical( - /* translators: 1: error message 2: file name and path 3: line number */ - sprintf( __( '%1$s in %2$s on line %3$s', 'classic-commerce' ), $error['message'], $error['file'], $error['line'] ) . PHP_EOL, - array( - 'source' => 'fatal-errors', - ) - ); - do_action( 'woocommerce_shutdown_error', $error ); - } - } - - /** - * Define WC Constants. - */ - private function define_constants() { - $upload_dir = wp_upload_dir( null, false ); - - $this->define( 'WC_ABSPATH', dirname( WC_PLUGIN_FILE ) . '/' ); - $this->define( 'WC_PLUGIN_BASENAME', plugin_basename( WC_PLUGIN_FILE ) ); - $this->define( 'WC_VERSION', $this->version ); - $this->define( 'WOOCOMMERCE_VERSION', $this->version ); - $this->define( 'WC_ROUNDING_PRECISION', 6 ); - $this->define( 'WC_DISCOUNT_ROUNDING_MODE', 2 ); - $this->define( 'WC_TAX_ROUNDING_MODE', 'yes' === get_option( 'woocommerce_prices_include_tax', 'no' ) ? 2 : 1 ); - $this->define( 'WC_DELIMITER', '|' ); - $this->define( 'WC_LOG_DIR', $upload_dir['basedir'] . '/wc-logs/' ); - $this->define( 'WC_SESSION_CACHE_GROUP', 'wc_session_id' ); - $this->define( 'WC_TEMPLATE_DEBUG_MODE', false ); - } - - /** - * Define constant if not already set. - * - * @param string $name Constant name. - * @param string|bool $value Constant value. - */ - private function define( $name, $value ) { - if ( ! defined( $name ) ) { - define( $name, $value ); - } - } - - /** - * What type of request is this? - * - * @param string $type admin, ajax, cron or frontend. - * @return bool - */ - private function is_request( $type ) { - switch ( $type ) { - case 'admin': - return is_admin(); - case 'ajax': - return defined( 'DOING_AJAX' ); - case 'cron': - return defined( 'DOING_CRON' ); - case 'frontend': - return ( ! is_admin() || defined( 'DOING_AJAX' ) ) && ! defined( 'DOING_CRON' ) && ! defined( 'REST_REQUEST' ); - } - } - - /** - * 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'; - - /** - * 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'; - include_once WC_ABSPATH . 'includes/interfaces/class-wc-customer-download-data-store-interface.php'; - include_once WC_ABSPATH . 'includes/interfaces/class-wc-customer-download-log-data-store-interface.php'; - include_once WC_ABSPATH . 'includes/interfaces/class-wc-object-data-store-interface.php'; - include_once WC_ABSPATH . 'includes/interfaces/class-wc-order-data-store-interface.php'; - include_once WC_ABSPATH . 'includes/interfaces/class-wc-order-item-data-store-interface.php'; - include_once WC_ABSPATH . 'includes/interfaces/class-wc-order-item-product-data-store-interface.php'; - include_once WC_ABSPATH . 'includes/interfaces/class-wc-order-item-type-data-store-interface.php'; - include_once WC_ABSPATH . 'includes/interfaces/class-wc-order-refund-data-store-interface.php'; - include_once WC_ABSPATH . 'includes/interfaces/class-wc-payment-token-data-store-interface.php'; - include_once WC_ABSPATH . 'includes/interfaces/class-wc-product-data-store-interface.php'; - include_once WC_ABSPATH . 'includes/interfaces/class-wc-product-variable-data-store-interface.php'; - 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'; - include_once WC_ABSPATH . 'includes/interfaces/class-wc-webhooks-data-store-interface.php'; - include_once WC_ABSPATH . 'includes/interfaces/class-wc-queue-interface.php'; - - /** - * Abstract classes. - */ - include_once WC_ABSPATH . 'includes/abstracts/abstract-wc-data.php'; - include_once WC_ABSPATH . 'includes/abstracts/abstract-wc-object-query.php'; - include_once WC_ABSPATH . 'includes/abstracts/abstract-wc-payment-token.php'; - include_once WC_ABSPATH . 'includes/abstracts/abstract-wc-product.php'; - include_once WC_ABSPATH . 'includes/abstracts/abstract-wc-order.php'; - include_once WC_ABSPATH . 'includes/abstracts/abstract-wc-settings-api.php'; - include_once WC_ABSPATH . 'includes/abstracts/abstract-wc-shipping-method.php'; - include_once WC_ABSPATH . 'includes/abstracts/abstract-wc-payment-gateway.php'; - include_once WC_ABSPATH . 'includes/abstracts/abstract-wc-integration.php'; - 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'; - include_once WC_ABSPATH . 'includes/abstracts/abstract-wc-privacy.php'; - - /** - * Core classes. - */ - include_once WC_ABSPATH . 'includes/wc-core-functions.php'; - include_once WC_ABSPATH . 'includes/class-wc-datetime.php'; - include_once WC_ABSPATH . 'includes/class-wc-post-types.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/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-meta-data.php'; - include_once WC_ABSPATH . 'includes/class-wc-order-factory.php'; - include_once WC_ABSPATH . 'includes/class-wc-order-query.php'; - include_once WC_ABSPATH . 'includes/class-wc-product-factory.php'; - include_once WC_ABSPATH . 'includes/class-wc-product-query.php'; - include_once WC_ABSPATH . 'includes/class-wc-payment-tokens.php'; - include_once WC_ABSPATH . 'includes/class-wc-shipping-zone.php'; - include_once WC_ABSPATH . 'includes/gateways/class-wc-payment-gateway-cc.php'; - include_once WC_ABSPATH . 'includes/gateways/class-wc-payment-gateway-echeck.php'; - include_once WC_ABSPATH . 'includes/class-wc-countries.php'; - include_once WC_ABSPATH . 'includes/class-wc-integrations.php'; - include_once WC_ABSPATH . 'includes/class-wc-cache-helper.php'; - include_once WC_ABSPATH . 'includes/class-wc-https.php'; - include_once WC_ABSPATH . 'includes/class-wc-deprecated-action-hooks.php'; - include_once WC_ABSPATH . 'includes/class-wc-deprecated-filter-hooks.php'; - include_once WC_ABSPATH . 'includes/class-wc-background-emailer.php'; - include_once WC_ABSPATH . 'includes/class-wc-discounts.php'; - include_once WC_ABSPATH . 'includes/class-wc-cart-totals.php'; - include_once WC_ABSPATH . 'includes/customizer/class-wc-shop-customizer.php'; - include_once WC_ABSPATH . 'includes/class-wc-regenerate-images.php'; - include_once WC_ABSPATH . 'includes/class-wc-privacy.php'; - include_once WC_ABSPATH . 'includes/class-wc-structured-data.php'; - include_once WC_ABSPATH . 'includes/class-wc-shortcodes.php'; - include_once WC_ABSPATH . 'includes/class-wc-logger.php'; - include_once WC_ABSPATH . 'includes/queue/class-wc-action-queue.php'; - include_once WC_ABSPATH . 'includes/queue/class-wc-queue.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'; - include_once WC_ABSPATH . 'includes/data-stores/class-wc-product-grouped-data-store-cpt.php'; - include_once WC_ABSPATH . 'includes/data-stores/class-wc-product-variable-data-store-cpt.php'; - include_once WC_ABSPATH . 'includes/data-stores/class-wc-product-variation-data-store-cpt.php'; - include_once WC_ABSPATH . 'includes/data-stores/abstract-wc-order-item-type-data-store.php'; - include_once WC_ABSPATH . 'includes/data-stores/class-wc-order-item-data-store.php'; - include_once WC_ABSPATH . 'includes/data-stores/class-wc-order-item-coupon-data-store.php'; - include_once WC_ABSPATH . 'includes/data-stores/class-wc-order-item-fee-data-store.php'; - include_once WC_ABSPATH . 'includes/data-stores/class-wc-order-item-product-data-store.php'; - include_once WC_ABSPATH . 'includes/data-stores/class-wc-order-item-shipping-data-store.php'; - include_once WC_ABSPATH . 'includes/data-stores/class-wc-order-item-tax-data-store.php'; - include_once WC_ABSPATH . 'includes/data-stores/class-wc-payment-token-data-store.php'; - include_once WC_ABSPATH . 'includes/data-stores/class-wc-customer-data-store.php'; - include_once WC_ABSPATH . 'includes/data-stores/class-wc-customer-data-store-session.php'; - include_once WC_ABSPATH . 'includes/data-stores/class-wc-customer-download-data-store.php'; - include_once WC_ABSPATH . 'includes/data-stores/class-wc-customer-download-log-data-store.php'; - include_once WC_ABSPATH . 'includes/data-stores/class-wc-shipping-zone-data-store.php'; - include_once WC_ABSPATH . 'includes/data-stores/abstract-wc-order-data-store-cpt.php'; - 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'; - include_once WC_ABSPATH . 'includes/data-stores/class-wc-webhook-data-store.php'; - - /** - * REST API. - */ - include_once WC_ABSPATH . 'includes/legacy/class-wc-legacy-api.php'; - include_once WC_ABSPATH . 'includes/class-wc-api.php'; - include_once WC_ABSPATH . 'includes/class-wc-auth.php'; - include_once WC_ABSPATH . 'includes/class-wc-register-wp-admin-settings.php'; - - /** - * Libraries - */ - include_once WC_ABSPATH . 'includes/libraries/action-scheduler/action-scheduler.php'; - - if ( defined( 'WP_CLI' ) && WP_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(); - } - - $this->theme_support_includes(); - $this->query = new WC_Query(); - $this->api = new WC_API(); - } - - /** - * Include classes for theme support. - * - * @since WC-3.3.0 - */ - private function theme_support_includes() { - if ( wc_is_active_theme( array( 'classicpress-twentyseventeen', 'classicpress-twentysixteen', 'classicpress-twentyfifteen', 'twentyseventeen', 'twentysixteen', 'twentyfifteen' ) ) ) { - switch ( get_template() ) { - case 'classicpress-twentyfifteen': - include_once WC_ABSPATH . 'includes/theme-support/class-wc-twenty-fifteen.php'; - break; - case 'classicpress-twentysixteen': - include_once WC_ABSPATH . 'includes/theme-support/class-wc-twenty-sixteen.php'; - break; - case 'classicpress-twentyseventeen': - include_once WC_ABSPATH . 'includes/theme-support/class-wc-twenty-seventeen.php'; - break; - case 'twentyfifteen': - include_once WC_ABSPATH . 'includes/theme-support/class-wc-twenty-fifteen.php'; - break; - case 'twentysixteen': - include_once WC_ABSPATH . 'includes/theme-support/class-wc-twenty-sixteen.php'; - break; - case 'twentyseventeen': - include_once WC_ABSPATH . 'includes/theme-support/class-wc-twenty-seventeen.php'; - break; - } - } - } - - /** - * Include required frontend files. - */ - public function frontend_includes() { - include_once WC_ABSPATH . 'includes/wc-cart-functions.php'; - include_once WC_ABSPATH . 'includes/wc-notice-functions.php'; - include_once WC_ABSPATH . 'includes/wc-template-hooks.php'; - include_once WC_ABSPATH . 'includes/class-wc-template-loader.php'; - include_once WC_ABSPATH . 'includes/class-wc-frontend-scripts.php'; - include_once WC_ABSPATH . 'includes/class-wc-form-handler.php'; - include_once WC_ABSPATH . 'includes/class-wc-cart.php'; - include_once WC_ABSPATH . 'includes/class-wc-tax.php'; - include_once WC_ABSPATH . 'includes/class-wc-shipping-zones.php'; - include_once WC_ABSPATH . 'includes/class-wc-customer.php'; - include_once WC_ABSPATH . 'includes/class-wc-embed.php'; - include_once WC_ABSPATH . 'includes/class-wc-session-handler.php'; - } - - /** - * Function used to Init Classic Commerce Template Functions - This makes them pluggable by plugins and themes. - */ - public function include_template_functions() { - include_once WC_ABSPATH . 'includes/wc-template-functions.php'; - } - - /** - * Init Classic Commerce when WordPress Initialises. - */ - public function init() { - // Before init action. - do_action( 'before_woocommerce_init' ); - - // Set up localisation. - $this->load_plugin_textdomain(); - - // Load class instances. - $this->product_factory = new WC_Product_Factory(); - $this->order_factory = new WC_Order_Factory(); - $this->countries = new WC_Countries(); - $this->integrations = new WC_Integrations(); - $this->structured_data = new WC_Structured_Data(); - $this->deprecated_hook_handlers['actions'] = new WC_Deprecated_Action_Hooks(); - $this->deprecated_hook_handlers['filters'] = new WC_Deprecated_Filter_Hooks(); - - // Classes/actions loaded for the frontend and for ajax requests. - if ( $this->is_request( 'frontend' ) ) { - // Session class, handles session data for users - can be overwritten if custom handler is needed. - $session_class = apply_filters( 'woocommerce_session_handler', 'WC_Session_Handler' ); - $this->session = new $session_class(); - $this->session->init(); - - $this->customer = new WC_Customer( get_current_user_id(), true ); - // Cart needs the customer info. - $this->cart = new WC_Cart(); - - // Customer should be saved during shutdown. - add_action( 'shutdown', array( $this->customer, 'save' ), 10 ); - } - - $this->load_webhooks(); - - // Init action. - do_action( 'woocommerce_init' ); - } - - /** - * Load Localisation files. - * - * Note: the first-loaded translation file overrides any following ones if the same translation is present. - * - * Locales found in: - * - WP_LANG_DIR/woocommerce/woocommerce-LOCALE.mo - * - WP_LANG_DIR/plugins/woocommerce-LOCALE.mo - */ - public function load_plugin_textdomain() { - $locale = is_admin() && function_exists( 'get_user_locale' ) ? get_user_locale() : get_locale(); - $locale = apply_filters( 'plugin_locale', $locale, 'classic-commerce' ); - - unload_textdomain( 'classic-commerce' ); - load_textdomain( 'classic-commerce', WP_LANG_DIR . '/classic-commerce/classic-commerce-' . $locale . '.mo' ); - load_plugin_textdomain( 'classic-commerce', false, plugin_basename( dirname( WC_PLUGIN_FILE ) ) . '/i18n/languages' ); - } - - /** - * Ensure theme and server variable compatibility and setup image sizes. - */ - public function setup_environment() { - /* @deprecated WC-2.2 Use WC()->template_path() instead. */ - $this->define( 'WC_TEMPLATE_PATH', $this->template_path() ); - - $this->add_thumbnail_support(); - } - - /** - * Ensure post thumbnail support is turned on. - */ - private function add_thumbnail_support() { - if ( ! current_theme_supports( 'post-thumbnails' ) ) { - add_theme_support( 'post-thumbnails' ); - } - add_post_type_support( 'product', 'thumbnail' ); - } - - /** - * Add WC Image sizes to WP. - * - * As of 3.3, image sizes can be registered via themes using add_theme_support for woocommerce - * and defining an array of args. If these are not defined, we will use defaults. This is - * handled in wc_get_image_size function. - * - * 3.3 sizes: - * - * woocommerce_thumbnail - Used in product listings. We assume these work for a 3 column grid layout. - * woocommerce_single - Used on single product pages for the main image. - * - * @since WC-2.3 - */ - public function add_image_sizes() { - $thumbnail = wc_get_image_size( 'thumbnail' ); - $single = wc_get_image_size( 'single' ); - $gallery_thumbnail = wc_get_image_size( 'gallery_thumbnail' ); - - add_image_size( 'woocommerce_thumbnail', $thumbnail['width'], $thumbnail['height'], $thumbnail['crop'] ); - add_image_size( 'woocommerce_single', $single['width'], $single['height'], $single['crop'] ); - add_image_size( 'woocommerce_gallery_thumbnail', $gallery_thumbnail['width'], $gallery_thumbnail['height'], $gallery_thumbnail['crop'] ); - - // Registered for bw compat. @todo remove in 4.0. - add_image_size( 'shop_catalog', $thumbnail['width'], $thumbnail['height'], $thumbnail['crop'] ); - add_image_size( 'shop_single', $single['width'], $single['height'], $single['crop'] ); - add_image_size( 'shop_thumbnail', $gallery_thumbnail['width'], $gallery_thumbnail['height'], $gallery_thumbnail['crop'] ); - } - - /** - * Get the plugin url. - * - * @return string - */ - public function plugin_url() { - return untrailingslashit( plugins_url( '/', WC_PLUGIN_FILE ) ); - } - - /** - * Get the plugin path. - * - * @return string - */ - public function plugin_path() { - return untrailingslashit( plugin_dir_path( WC_PLUGIN_FILE ) ); - } - - /** - * Get the template path. - * - * @return string - */ - public function template_path() { - $templatepath = file_exists( get_stylesheet_directory() . '/classic-commerce/' ) ? 'classic-commerce/' : 'woocommerce/'; - return apply_filters( 'woocommerce_template_path', $templatepath ); - } - - /** - * Get Ajax URL. - * - * @return string - */ - public function ajax_url() { - return admin_url( 'admin-ajax.php', 'relative' ); - } - - /** - * Return the WC API URL for a given request. - * - * @param string $request Requested endpoint. - * @param bool|null $ssl If should use SSL, null if should auto detect. Default: null. - * @return string - */ - public function api_request_url( $request, $ssl = null ) { - if ( is_null( $ssl ) ) { - $scheme = wp_parse_url( home_url(), PHP_URL_SCHEME ); - } elseif ( $ssl ) { - $scheme = 'https'; - } else { - $scheme = 'http'; - } - - if ( strstr( get_option( 'permalink_structure' ), '/index.php/' ) ) { - $api_request_url = trailingslashit( home_url( '/index.php/wc-api/' . $request, $scheme ) ); - } elseif ( get_option( 'permalink_structure' ) ) { - $api_request_url = trailingslashit( home_url( '/wc-api/' . $request, $scheme ) ); - } else { - $api_request_url = add_query_arg( 'wc-api', $request, trailingslashit( home_url( '', $scheme ) ) ); - } - - return esc_url_raw( apply_filters( 'woocommerce_api_request_url', $api_request_url, $request, $ssl ) ); - } - - /** - * Load & enqueue active webhooks. - * - * @since WC-2.2 - */ - private function load_webhooks() { - - if ( ! is_blog_installed() ) { - return; - } - - wc_load_webhooks(); - } - - /** - * Classic Commerce Payment Token Meta API and Term/Order item Meta - set table names. - */ - public function wpdb_table_fix() { - global $wpdb; - $wpdb->payment_tokenmeta = $wpdb->prefix . 'woocommerce_payment_tokenmeta'; - $wpdb->order_itemmeta = $wpdb->prefix . 'woocommerce_order_itemmeta'; - $wpdb->tables[] = 'woocommerce_payment_tokenmeta'; - $wpdb->tables[] = 'woocommerce_order_itemmeta'; - - if ( get_option( 'db_version' ) < 34370 ) { - $wpdb->woocommerce_termmeta = $wpdb->prefix . 'woocommerce_termmeta'; - $wpdb->tables[] = 'woocommerce_termmeta'; - } - } - - /** - * Generates user agent - * - * @param string $webhook Optional webhook (eg Hookshot). - * @return string - */ - public static function user_agent_header( $webhook = '' ) { - if ( ! empty( $webhook ) ) { - $webhook = ' ' . $webhook; - } - return sprintf( 'WooCommerce/%s%s (compatible; Classic Commerce/%s)', WC()->version, $webhook, WC()->cc_version ); - } - - /** - * Get queue instance. - * - * @return WC_Queue_Interface - */ - public function queue() { - return WC_Queue::instance(); - } - - /** - * Get Checkout Class. - * - * @return WC_Checkout - */ - public function checkout() { - return WC_Checkout::instance(); - } - - /** - * Get gateways class. - * - * @return WC_Payment_Gateways - */ - public function payment_gateways() { - return WC_Payment_Gateways::instance(); - } - - /** - * Get shipping class. - * - * @return WC_Shipping - */ - public function shipping() { - return WC_Shipping::instance(); - } - - /** - * Email Class. - * - * @return WC_Emails - */ - public function mailer() { - return WC_Emails::instance(); - } -} +$key(); + } + } + + /** + * Classic Commerce Constructor. + */ + public function __construct() { + $this->define_constants(); + $this->includes(); + $this->init_hooks(); + + do_action( 'woocommerce_loaded' ); + } + + /** + * Hook into actions and filters. + * + * @since WC-2.3 + */ + private function init_hooks() { + register_activation_hook( WC_PLUGIN_FILE, array( 'WC_Install', 'install' ) ); + register_shutdown_function( array( $this, 'log_errors' ) ); + add_action( 'after_setup_theme', array( $this, 'setup_environment' ) ); + add_action( 'after_setup_theme', array( $this, 'include_template_functions' ), 11 ); + add_action( 'init', array( $this, 'init' ), 0 ); + add_action( 'init', array( 'WC_Shortcodes', 'init' ) ); + add_action( 'init', array( 'WC_Emails', 'init_transactional_emails' ) ); + add_action( 'init', array( $this, 'wpdb_table_fix' ), 0 ); + add_action( 'init', array( $this, 'add_image_sizes' ) ); + add_action( 'switch_blog', array( $this, 'wpdb_table_fix' ), 0 ); + add_action( 'admin_head', array( $this, 'load_icon_style' ) ); + } + + /** + * Some plugins block loading of menu.css causing the CC menu icon to display incorrectly. + * Here we add the necessary style to ensure the icon style is loaded. + */ + public function load_icon_style() { + echo ''; + } + + /** + * Ensures fatal errors are logged so they can be picked up in the status report. + * + * @since WC-3.2.0 + */ + public function log_errors() { + $error = error_get_last(); + if ( $error && in_array( $error['type'], array( E_ERROR, E_PARSE, E_COMPILE_ERROR, E_USER_ERROR, E_RECOVERABLE_ERROR ) ) ) { + $logger = wc_get_logger(); + $logger->critical( + /* translators: 1: error message 2: file name and path 3: line number */ + sprintf( __( '%1$s in %2$s on line %3$s', 'classic-commerce' ), $error['message'], $error['file'], $error['line'] ) . PHP_EOL, + array( + 'source' => 'fatal-errors', + ) + ); + do_action( 'woocommerce_shutdown_error', $error ); + } + } + + /** + * Define WC Constants. + */ + private function define_constants() { + $upload_dir = wp_upload_dir( null, false ); + + $this->define( 'WC_ABSPATH', dirname( WC_PLUGIN_FILE ) . '/' ); + $this->define( 'WC_PLUGIN_BASENAME', plugin_basename( WC_PLUGIN_FILE ) ); + $this->define( 'WC_VERSION', $this->version ); + $this->define( 'WOOCOMMERCE_VERSION', $this->version ); + $this->define( 'WC_ROUNDING_PRECISION', 6 ); + $this->define( 'WC_DISCOUNT_ROUNDING_MODE', 2 ); + $this->define( 'WC_TAX_ROUNDING_MODE', 'yes' === get_option( 'woocommerce_prices_include_tax', 'no' ) ? 2 : 1 ); + $this->define( 'WC_DELIMITER', '|' ); + $this->define( 'WC_LOG_DIR', $upload_dir['basedir'] . '/wc-logs/' ); + $this->define( 'WC_SESSION_CACHE_GROUP', 'wc_session_id' ); + $this->define( 'WC_TEMPLATE_DEBUG_MODE', false ); + } + + /** + * Define constant if not already set. + * + * @param string $name Constant name. + * @param string|bool $value Constant value. + */ + private function define( $name, $value ) { + if ( ! defined( $name ) ) { + define( $name, $value ); + } + } + + /** + * What type of request is this? + * + * @param string $type admin, ajax, cron or frontend. + * @return bool + */ + private function is_request( $type ) { + switch ( $type ) { + case 'admin': + return is_admin(); + case 'ajax': + return defined( 'DOING_AJAX' ); + case 'cron': + return defined( 'DOING_CRON' ); + case 'frontend': + return ( ! is_admin() || defined( 'DOING_AJAX' ) ) && ! defined( 'DOING_CRON' ) && ! defined( 'REST_REQUEST' ); + } + } + + /** + * 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'; + + /** + * 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'; + include_once WC_ABSPATH . 'includes/interfaces/class-wc-customer-download-data-store-interface.php'; + include_once WC_ABSPATH . 'includes/interfaces/class-wc-customer-download-log-data-store-interface.php'; + include_once WC_ABSPATH . 'includes/interfaces/class-wc-object-data-store-interface.php'; + include_once WC_ABSPATH . 'includes/interfaces/class-wc-order-data-store-interface.php'; + include_once WC_ABSPATH . 'includes/interfaces/class-wc-order-item-data-store-interface.php'; + include_once WC_ABSPATH . 'includes/interfaces/class-wc-order-item-product-data-store-interface.php'; + include_once WC_ABSPATH . 'includes/interfaces/class-wc-order-item-type-data-store-interface.php'; + include_once WC_ABSPATH . 'includes/interfaces/class-wc-order-refund-data-store-interface.php'; + include_once WC_ABSPATH . 'includes/interfaces/class-wc-payment-token-data-store-interface.php'; + include_once WC_ABSPATH . 'includes/interfaces/class-wc-product-data-store-interface.php'; + include_once WC_ABSPATH . 'includes/interfaces/class-wc-product-variable-data-store-interface.php'; + 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'; + include_once WC_ABSPATH . 'includes/interfaces/class-wc-webhooks-data-store-interface.php'; + include_once WC_ABSPATH . 'includes/interfaces/class-wc-queue-interface.php'; + + /** + * Abstract classes. + */ + include_once WC_ABSPATH . 'includes/abstracts/abstract-wc-data.php'; + include_once WC_ABSPATH . 'includes/abstracts/abstract-wc-object-query.php'; + include_once WC_ABSPATH . 'includes/abstracts/abstract-wc-payment-token.php'; + include_once WC_ABSPATH . 'includes/abstracts/abstract-wc-product.php'; + include_once WC_ABSPATH . 'includes/abstracts/abstract-wc-order.php'; + include_once WC_ABSPATH . 'includes/abstracts/abstract-wc-settings-api.php'; + include_once WC_ABSPATH . 'includes/abstracts/abstract-wc-shipping-method.php'; + include_once WC_ABSPATH . 'includes/abstracts/abstract-wc-payment-gateway.php'; + include_once WC_ABSPATH . 'includes/abstracts/abstract-wc-integration.php'; + 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'; + include_once WC_ABSPATH . 'includes/abstracts/abstract-wc-privacy.php'; + + /** + * Core classes. + */ + include_once WC_ABSPATH . 'includes/wc-core-functions.php'; + include_once WC_ABSPATH . 'includes/class-wc-datetime.php'; + include_once WC_ABSPATH . 'includes/class-wc-post-types.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/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-meta-data.php'; + include_once WC_ABSPATH . 'includes/class-wc-order-factory.php'; + include_once WC_ABSPATH . 'includes/class-wc-order-query.php'; + include_once WC_ABSPATH . 'includes/class-wc-product-factory.php'; + include_once WC_ABSPATH . 'includes/class-wc-product-query.php'; + include_once WC_ABSPATH . 'includes/class-wc-payment-tokens.php'; + include_once WC_ABSPATH . 'includes/class-wc-shipping-zone.php'; + include_once WC_ABSPATH . 'includes/gateways/class-wc-payment-gateway-cc.php'; + include_once WC_ABSPATH . 'includes/gateways/class-wc-payment-gateway-echeck.php'; + include_once WC_ABSPATH . 'includes/class-wc-countries.php'; + include_once WC_ABSPATH . 'includes/class-wc-integrations.php'; + include_once WC_ABSPATH . 'includes/class-wc-cache-helper.php'; + include_once WC_ABSPATH . 'includes/class-wc-https.php'; + include_once WC_ABSPATH . 'includes/class-wc-deprecated-action-hooks.php'; + include_once WC_ABSPATH . 'includes/class-wc-deprecated-filter-hooks.php'; + include_once WC_ABSPATH . 'includes/class-wc-background-emailer.php'; + include_once WC_ABSPATH . 'includes/class-wc-discounts.php'; + include_once WC_ABSPATH . 'includes/class-wc-cart-totals.php'; + include_once WC_ABSPATH . 'includes/customizer/class-wc-shop-customizer.php'; + include_once WC_ABSPATH . 'includes/class-wc-regenerate-images.php'; + include_once WC_ABSPATH . 'includes/class-wc-privacy.php'; + include_once WC_ABSPATH . 'includes/class-wc-structured-data.php'; + include_once WC_ABSPATH . 'includes/class-wc-shortcodes.php'; + include_once WC_ABSPATH . 'includes/class-wc-logger.php'; + include_once WC_ABSPATH . 'includes/queue/class-wc-action-queue.php'; + include_once WC_ABSPATH . 'includes/queue/class-wc-queue.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'; + include_once WC_ABSPATH . 'includes/data-stores/class-wc-product-grouped-data-store-cpt.php'; + include_once WC_ABSPATH . 'includes/data-stores/class-wc-product-variable-data-store-cpt.php'; + include_once WC_ABSPATH . 'includes/data-stores/class-wc-product-variation-data-store-cpt.php'; + include_once WC_ABSPATH . 'includes/data-stores/abstract-wc-order-item-type-data-store.php'; + include_once WC_ABSPATH . 'includes/data-stores/class-wc-order-item-data-store.php'; + include_once WC_ABSPATH . 'includes/data-stores/class-wc-order-item-coupon-data-store.php'; + include_once WC_ABSPATH . 'includes/data-stores/class-wc-order-item-fee-data-store.php'; + include_once WC_ABSPATH . 'includes/data-stores/class-wc-order-item-product-data-store.php'; + include_once WC_ABSPATH . 'includes/data-stores/class-wc-order-item-shipping-data-store.php'; + include_once WC_ABSPATH . 'includes/data-stores/class-wc-order-item-tax-data-store.php'; + include_once WC_ABSPATH . 'includes/data-stores/class-wc-payment-token-data-store.php'; + include_once WC_ABSPATH . 'includes/data-stores/class-wc-customer-data-store.php'; + include_once WC_ABSPATH . 'includes/data-stores/class-wc-customer-data-store-session.php'; + include_once WC_ABSPATH . 'includes/data-stores/class-wc-customer-download-data-store.php'; + include_once WC_ABSPATH . 'includes/data-stores/class-wc-customer-download-log-data-store.php'; + include_once WC_ABSPATH . 'includes/data-stores/class-wc-shipping-zone-data-store.php'; + include_once WC_ABSPATH . 'includes/data-stores/abstract-wc-order-data-store-cpt.php'; + 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'; + include_once WC_ABSPATH . 'includes/data-stores/class-wc-webhook-data-store.php'; + + /** + * REST API. + */ + include_once WC_ABSPATH . 'includes/legacy/class-wc-legacy-api.php'; + include_once WC_ABSPATH . 'includes/class-wc-api.php'; + include_once WC_ABSPATH . 'includes/class-wc-auth.php'; + include_once WC_ABSPATH . 'includes/class-wc-register-wp-admin-settings.php'; + + /** + * Libraries + */ + include_once WC_ABSPATH . 'includes/libraries/action-scheduler/action-scheduler.php'; + + if ( defined( 'WP_CLI' ) && WP_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(); + } + + $this->theme_support_includes(); + $this->query = new WC_Query(); + $this->api = new WC_API(); + } + + /** + * Include classes for theme support. + * + * @since WC-3.3.0 + */ + private function theme_support_includes() { + if ( wc_is_active_theme( array( 'classicpress-twentyseventeen', 'classicpress-twentysixteen', 'classicpress-twentyfifteen', 'twentyseventeen', 'twentysixteen', 'twentyfifteen' ) ) ) { + switch ( get_template() ) { + case 'classicpress-twentyfifteen': + include_once WC_ABSPATH . 'includes/theme-support/class-wc-twenty-fifteen.php'; + break; + case 'classicpress-twentysixteen': + include_once WC_ABSPATH . 'includes/theme-support/class-wc-twenty-sixteen.php'; + break; + case 'classicpress-twentyseventeen': + include_once WC_ABSPATH . 'includes/theme-support/class-wc-twenty-seventeen.php'; + break; + case 'twentyfifteen': + include_once WC_ABSPATH . 'includes/theme-support/class-wc-twenty-fifteen.php'; + break; + case 'twentysixteen': + include_once WC_ABSPATH . 'includes/theme-support/class-wc-twenty-sixteen.php'; + break; + case 'twentyseventeen': + include_once WC_ABSPATH . 'includes/theme-support/class-wc-twenty-seventeen.php'; + break; + } + } + } + + /** + * Include required frontend files. + */ + public function frontend_includes() { + include_once WC_ABSPATH . 'includes/wc-cart-functions.php'; + include_once WC_ABSPATH . 'includes/wc-notice-functions.php'; + include_once WC_ABSPATH . 'includes/wc-template-hooks.php'; + include_once WC_ABSPATH . 'includes/class-wc-template-loader.php'; + include_once WC_ABSPATH . 'includes/class-wc-frontend-scripts.php'; + include_once WC_ABSPATH . 'includes/class-wc-form-handler.php'; + include_once WC_ABSPATH . 'includes/class-wc-cart.php'; + include_once WC_ABSPATH . 'includes/class-wc-tax.php'; + include_once WC_ABSPATH . 'includes/class-wc-shipping-zones.php'; + include_once WC_ABSPATH . 'includes/class-wc-customer.php'; + include_once WC_ABSPATH . 'includes/class-wc-embed.php'; + include_once WC_ABSPATH . 'includes/class-wc-session-handler.php'; + } + + /** + * Function used to Init Classic Commerce Template Functions - This makes them pluggable by plugins and themes. + */ + public function include_template_functions() { + include_once WC_ABSPATH . 'includes/wc-template-functions.php'; + } + + /** + * Init Classic Commerce when WordPress Initialises. + */ + public function init() { + // Before init action. + do_action( 'before_woocommerce_init' ); + + // Set up localisation. + $this->load_plugin_textdomain(); + + // Load class instances. + $this->product_factory = new WC_Product_Factory(); + $this->order_factory = new WC_Order_Factory(); + $this->countries = new WC_Countries(); + $this->integrations = new WC_Integrations(); + $this->structured_data = new WC_Structured_Data(); + $this->deprecated_hook_handlers['actions'] = new WC_Deprecated_Action_Hooks(); + $this->deprecated_hook_handlers['filters'] = new WC_Deprecated_Filter_Hooks(); + + // Classes/actions loaded for the frontend and for ajax requests. + if ( $this->is_request( 'frontend' ) ) { + // Session class, handles session data for users - can be overwritten if custom handler is needed. + $session_class = apply_filters( 'woocommerce_session_handler', 'WC_Session_Handler' ); + $this->session = new $session_class(); + $this->session->init(); + + $this->customer = new WC_Customer( get_current_user_id(), true ); + // Cart needs the customer info. + $this->cart = new WC_Cart(); + + // Customer should be saved during shutdown. + add_action( 'shutdown', array( $this->customer, 'save' ), 10 ); + } + + $this->load_webhooks(); + + // Init action. + do_action( 'woocommerce_init' ); + } + + /** + * Load Localisation files. + * + * Note: the first-loaded translation file overrides any following ones if the same translation is present. + * + * Locales found in: + * - WP_LANG_DIR/woocommerce/woocommerce-LOCALE.mo + * - WP_LANG_DIR/plugins/woocommerce-LOCALE.mo + */ + public function load_plugin_textdomain() { + $locale = is_admin() && function_exists( 'get_user_locale' ) ? get_user_locale() : get_locale(); + $locale = apply_filters( 'plugin_locale', $locale, 'classic-commerce' ); + + unload_textdomain( 'classic-commerce' ); + load_textdomain( 'classic-commerce', WP_LANG_DIR . '/classic-commerce/classic-commerce-' . $locale . '.mo' ); + load_plugin_textdomain( 'classic-commerce', false, plugin_basename( dirname( WC_PLUGIN_FILE ) ) . '/i18n/languages' ); + } + + /** + * Ensure theme and server variable compatibility and setup image sizes. + */ + public function setup_environment() { + /* @deprecated WC-2.2 Use WC()->template_path() instead. */ + $this->define( 'WC_TEMPLATE_PATH', $this->template_path() ); + + $this->add_thumbnail_support(); + } + + /** + * Ensure post thumbnail support is turned on. + */ + private function add_thumbnail_support() { + if ( ! current_theme_supports( 'post-thumbnails' ) ) { + add_theme_support( 'post-thumbnails' ); + } + add_post_type_support( 'product', 'thumbnail' ); + } + + /** + * Add WC Image sizes to WP. + * + * As of 3.3, image sizes can be registered via themes using add_theme_support for woocommerce + * and defining an array of args. If these are not defined, we will use defaults. This is + * handled in wc_get_image_size function. + * + * 3.3 sizes: + * + * woocommerce_thumbnail - Used in product listings. We assume these work for a 3 column grid layout. + * woocommerce_single - Used on single product pages for the main image. + * + * @since WC-2.3 + */ + public function add_image_sizes() { + $thumbnail = wc_get_image_size( 'thumbnail' ); + $single = wc_get_image_size( 'single' ); + $gallery_thumbnail = wc_get_image_size( 'gallery_thumbnail' ); + + add_image_size( 'woocommerce_thumbnail', $thumbnail['width'], $thumbnail['height'], $thumbnail['crop'] ); + add_image_size( 'woocommerce_single', $single['width'], $single['height'], $single['crop'] ); + add_image_size( 'woocommerce_gallery_thumbnail', $gallery_thumbnail['width'], $gallery_thumbnail['height'], $gallery_thumbnail['crop'] ); + + // Registered for bw compat. @todo remove in 4.0. + add_image_size( 'shop_catalog', $thumbnail['width'], $thumbnail['height'], $thumbnail['crop'] ); + add_image_size( 'shop_single', $single['width'], $single['height'], $single['crop'] ); + add_image_size( 'shop_thumbnail', $gallery_thumbnail['width'], $gallery_thumbnail['height'], $gallery_thumbnail['crop'] ); + } + + /** + * Get the plugin url. + * + * @return string + */ + public function plugin_url() { + return untrailingslashit( plugins_url( '/', WC_PLUGIN_FILE ) ); + } + + /** + * Get the plugin path. + * + * @return string + */ + public function plugin_path() { + return untrailingslashit( plugin_dir_path( WC_PLUGIN_FILE ) ); + } + + /** + * Get the template path. + * + * @return string + */ + public function template_path() { + $templatepath = file_exists( get_stylesheet_directory() . '/classic-commerce/' ) ? 'classic-commerce/' : 'woocommerce/'; + return apply_filters( 'woocommerce_template_path', $templatepath ); + } + + /** + * Get Ajax URL. + * + * @return string + */ + public function ajax_url() { + return admin_url( 'admin-ajax.php', 'relative' ); + } + + /** + * Return the WC API URL for a given request. + * + * @param string $request Requested endpoint. + * @param bool|null $ssl If should use SSL, null if should auto detect. Default: null. + * @return string + */ + public function api_request_url( $request, $ssl = null ) { + if ( is_null( $ssl ) ) { + $scheme = wp_parse_url( home_url(), PHP_URL_SCHEME ); + } elseif ( $ssl ) { + $scheme = 'https'; + } else { + $scheme = 'http'; + } + + if ( strstr( get_option( 'permalink_structure' ), '/index.php/' ) ) { + $api_request_url = trailingslashit( home_url( '/index.php/wc-api/' . $request, $scheme ) ); + } elseif ( get_option( 'permalink_structure' ) ) { + $api_request_url = trailingslashit( home_url( '/wc-api/' . $request, $scheme ) ); + } else { + $api_request_url = add_query_arg( 'wc-api', $request, trailingslashit( home_url( '', $scheme ) ) ); + } + + return esc_url_raw( apply_filters( 'woocommerce_api_request_url', $api_request_url, $request, $ssl ) ); + } + + /** + * Load & enqueue active webhooks. + * + * @since WC-2.2 + */ + private function load_webhooks() { + + if ( ! is_blog_installed() ) { + return; + } + + wc_load_webhooks(); + } + + /** + * Classic Commerce Payment Token Meta API and Term/Order item Meta - set table names. + */ + public function wpdb_table_fix() { + global $wpdb; + $wpdb->payment_tokenmeta = $wpdb->prefix . 'woocommerce_payment_tokenmeta'; + $wpdb->order_itemmeta = $wpdb->prefix . 'woocommerce_order_itemmeta'; + $wpdb->tables[] = 'woocommerce_payment_tokenmeta'; + $wpdb->tables[] = 'woocommerce_order_itemmeta'; + + if ( get_option( 'db_version' ) < 34370 ) { + $wpdb->woocommerce_termmeta = $wpdb->prefix . 'woocommerce_termmeta'; + $wpdb->tables[] = 'woocommerce_termmeta'; + } + } + + /** + * Generates user agent + * + * @param string $webhook Optional webhook (eg Hookshot). + * @return string + */ + public static function user_agent_header( $webhook = '' ) { + if ( ! empty( $webhook ) ) { + $webhook = ' ' . $webhook; + } + return sprintf( 'WooCommerce/%s%s (compatible; Classic Commerce/%s)', WC()->version, $webhook, WC()->cc_version ); + } + + /** + * Get queue instance. + * + * @return WC_Queue_Interface + */ + public function queue() { + return WC_Queue::instance(); + } + + /** + * Get Checkout Class. + * + * @return WC_Checkout + */ + public function checkout() { + return WC_Checkout::instance(); + } + + /** + * Get gateways class. + * + * @return WC_Payment_Gateways + */ + public function payment_gateways() { + return WC_Payment_Gateways::instance(); + } + + /** + * Get shipping class. + * + * @return WC_Shipping + */ + public function shipping() { + return WC_Shipping::instance(); + } + + /** + * Email Class. + * + * @return WC_Emails + */ + public function mailer() { + return WC_Emails::instance(); + } +}