Merge pull request #22536 from woocommerce/update/21524

Delay `woocommerce_loaded` hook until all plugins are loaded.
This commit is contained in:
Mike Jolley 2019-02-18 11:57:20 +00:00 committed by GitHub
commit fdd8a354e0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 10 deletions

View File

@ -154,7 +154,18 @@ final class WooCommerce {
$this->define_constants();
$this->includes();
$this->init_hooks();
}
/**
* When WP has loaded all plugins, trigger the `woocommerce_loaded` hook.
*
* This ensures `woocommerce_loaded` is called only after all other plugins
* are loaded, to avoid issues caused by plugin directory naming changing
* the load order. See #21524 for details.
*
* @since 3.6.0
*/
public function on_plugins_loaded() {
do_action( 'woocommerce_loaded' );
}
@ -166,6 +177,8 @@ final class WooCommerce {
private function init_hooks() {
register_activation_hook( WC_PLUGIN_FILE, array( 'WC_Install', 'install' ) );
register_shutdown_function( array( $this, 'log_errors' ) );
add_action( 'plugins_loaded', array( $this, 'on_plugins_loaded' ), -1 );
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 );
@ -183,7 +196,7 @@ final class WooCommerce {
*/
public function log_errors() {
$error = error_get_last();
if ( in_array( $error['type'], array( E_ERROR, E_PARSE, E_COMPILE_ERROR, E_USER_ERROR, E_RECOVERABLE_ERROR ) ) ) {
if ( in_array( $error['type'], array( E_ERROR, E_PARSE, E_COMPILE_ERROR, E_USER_ERROR, E_RECOVERABLE_ERROR ), true ) ) {
$logger = wc_get_logger();
$logger->critical(
/* translators: 1: error message 2: file name and path 3: line number */
@ -525,7 +538,11 @@ final class WooCommerce {
* Ensure theme and server variable compatibility and setup image sizes.
*/
public function setup_environment() {
/* @deprecated 2.2 Use WC()->template_path() instead. */
/**
* WC_TEMPLATE_PATH constant.
*
* @deprecated 2.2 Use WC()->template_path() instead.
*/
$this->define( 'WC_TEMPLATE_PATH', $this->template_path() );
$this->add_thumbnail_support();
@ -564,7 +581,11 @@ final class WooCommerce {
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.
/**
* Legacy image sizes.
*
* @deprecated These sizes will be removed 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'] );

View File

@ -12,9 +12,7 @@
* @package WooCommerce
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
defined( 'ABSPATH' ) || exit;
// Define WC_PLUGIN_FILE.
if ( ! defined( 'WC_PLUGIN_FILE' ) ) {
@ -27,14 +25,12 @@ if ( ! class_exists( 'WooCommerce' ) ) {
}
/**
* Main instance of WooCommerce.
*
* Returns the main instance of WC to prevent the need to use globals.
* Returns the main instance of WC.
*
* @since 2.1
* @return WooCommerce
*/
function WC() {
function WC() { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.FunctionNameInvalid
return WooCommerce::instance();
}