From e4bf9b3d78716589f59cc4f1d3210b12d6a832fd Mon Sep 17 00:00:00 2001 From: Aristeides Stathopoulos Date: Tue, 11 Jul 2017 02:53:54 +0300 Subject: [PATCH] Properly define constants after moving class outside main plugin file. --- includes/class-woocommerce.php | 11 ++++------- woocommerce.php | 15 +++++++++++++++ 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/includes/class-woocommerce.php b/includes/class-woocommerce.php index c6721568d95..5b1949aa7c9 100644 --- a/includes/class-woocommerce.php +++ b/includes/class-woocommerce.php @@ -161,7 +161,7 @@ final class WooCommerce { * @since 2.3 */ private function init_hooks() { - register_activation_hook( __FILE__, array( 'WC_Install', 'install' ) ); + 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 ); @@ -194,9 +194,6 @@ final class WooCommerce { private function define_constants() { $upload_dir = wp_upload_dir(); - $this->define( 'WC_PLUGIN_FILE', __FILE__ ); - $this->define( 'WC_ABSPATH', dirname( __FILE__ ) . '/' ); - $this->define( 'WC_PLUGIN_BASENAME', plugin_basename( __FILE__ ) ); $this->define( 'WC_VERSION', $this->version ); $this->define( 'WOOCOMMERCE_VERSION', $this->version ); $this->define( 'WC_ROUNDING_PRECISION', 4 ); @@ -466,7 +463,7 @@ final class WooCommerce { unload_textdomain( 'woocommerce' ); load_textdomain( 'woocommerce', WP_LANG_DIR . '/woocommerce/woocommerce-' . $locale . '.mo' ); - load_plugin_textdomain( 'woocommerce', false, plugin_basename( dirname( __FILE__ ) ) . '/i18n/languages' ); + load_plugin_textdomain( 'woocommerce', false, plugin_basename( dirname( WC_PLUGIN_FILE ) ) . '/i18n/languages' ); } /** @@ -512,7 +509,7 @@ final class WooCommerce { * @return string */ public function plugin_url() { - return untrailingslashit( plugins_url( '/', __FILE__ ) ); + return untrailingslashit( plugins_url( '/', WC_PLUGIN_FILE ) ); } /** @@ -520,7 +517,7 @@ final class WooCommerce { * @return string */ public function plugin_path() { - return untrailingslashit( plugin_dir_path( __FILE__ ) ); + return untrailingslashit( plugin_dir_path( WC_PLUGIN_FILE ) ); } /** diff --git a/woocommerce.php b/woocommerce.php index 68987862ec5..f700af07e3e 100644 --- a/woocommerce.php +++ b/woocommerce.php @@ -20,6 +20,21 @@ if ( ! defined( 'ABSPATH' ) ) { exit; // Exit if accessed directly. } +// Define WC_PLUGIN_FILE. +if ( ! defined( 'WC_PLUGIN_FILE' ) ) { + define( 'WC_PLUGIN_FILE', __FILE__ ); +} + +// Define WC_ABSPATH. +if ( ! defined( 'WC_ABSPATH' ) ) { + define( 'WC_ABSPATH', dirname( __FILE__ ) . '/' ); +} + +// Define WC_PLUGIN_BASENAME. +if ( ! defined( 'WC_PLUGIN_BASENAME' ) ) { + define( 'WC_PLUGIN_BASENAME', plugin_basename( __FILE__ ) ); +} + // Include the main WooCommerce class. if ( ! class_exists( 'WooCommerce' ) ) { include_once dirname( __FILE__ ) . '/includes/class-woocommerce.php';