Conditionally add messages in customiser

This commit is contained in:
Mike Jolley 2018-02-14 17:25:52 +00:00
parent 7ae0f6c274
commit d841cf3f27
3 changed files with 22 additions and 8 deletions

View File

@ -183,7 +183,7 @@ class WC_REST_System_Status_Tools_Controller extends WC_REST_Controller {
);
// Jetpack does the image resizing heavy lifting so you don't have to.
if ( ( class_exists( 'Jetpack' ) && Jetpack::is_module_active( 'photon' ) ) || ! apply_filters( 'woocommerce_background_image_regeneration', ! is_multisite() ) ) {
if ( ( class_exists( 'Jetpack' ) && Jetpack::is_module_active( 'photon' ) ) || ! apply_filters( 'woocommerce_background_image_regeneration', true ) ) {
unset( $tools['regenerate_thumbnails'] );
}

View File

@ -47,16 +47,19 @@ class WC_Regenerate_Images {
return;
}
// Regenerate thumbnails in the background after settings change. Not ran on multisite to avoid multiple simultanious jobs, and not required when Jetpack Photon is in use.
if ( apply_filters( 'woocommerce_background_image_regeneration', ! is_multisite() ) ) {
if ( apply_filters( 'woocommerce_background_image_regeneration', true ) ) {
include_once WC_ABSPATH . 'includes/class-wc-regenerate-images-request.php';
self::$background_process = new WC_Regenerate_Images_Request();
add_action( 'admin_init', array( __CLASS__, 'regenerating_notice' ) );
add_action( 'woocommerce_hide_regenerating_thumbnails_notice', array( __CLASS__, 'dismiss_regenerating_notice' ) );
add_action( 'customize_save_after', array( __CLASS__, 'maybe_regenerate_images' ) );
add_action( 'after_switch_theme', array( __CLASS__, 'maybe_regenerate_images' ) );
// Regenerate thumbnails in the background after settings changes. Not ran on multisite to avoid multiple simultanious jobs.
if ( ! is_multisite() ) {
add_action( 'customize_save_after', array( __CLASS__, 'maybe_regenerate_images' ) );
add_action( 'after_switch_theme', array( __CLASS__, 'maybe_regenerate_images' ) );
}
}
}

View File

@ -443,12 +443,23 @@ class WC_Shop_Customizer {
* @param WP_Customize_Manager $wp_customize Theme Customizer object.
*/
private function add_product_images_section( $wp_customize ) {
if ( class_exists( 'Jetpack' ) && Jetpack::is_module_active( 'photon' ) ) {
$regen_description = ''; // Nothing to report; Jetpack will handle magically.
} elseif ( apply_filters( 'woocommerce_background_image_regeneration', true ) && ! is_multisite() ) {
$regen_description = __( 'After publishing your changes, new image sizes will be generated automatically.', 'woocommerce' );
} elseif ( apply_filters( 'woocommerce_background_image_regeneration', true ) && is_multisite() ) {
$regen_description = sprintf( __( 'After publishing your changes, new image sizes may not be shown until you regenerate thumbnails. You can do this from the <a href="%1$s" target="_blank">tools section in WooCommerce</a> or by using a plugin such as <a href="%2$s" target="_blank">Regenerate Thumbnails</a>.', 'woocommerce' ), admin_url( 'admin.php?page=wc-status&tab=tools' ), 'https://en-gb.wordpress.org/plugins/regenerate-thumbnails/' );
} else {
$regen_description = sprintf( __( 'After publishing your changes, new image sizes may not be shown until you <a href="%2$s" target="_blank">Regenerate Thumbnails</a>.', 'woocommerce' ), 'https://en-gb.wordpress.org/plugins/regenerate-thumbnails/' );
}
$wp_customize->add_section(
'woocommerce_product_images',
array(
'title' => __( 'Product Images', 'woocommerce' ),
'priority' => 20,
'panel' => 'woocommerce',
'title' => __( 'Product Images', 'woocommerce' ),
'description' => $regen_description,
'priority' => 20,
'panel' => 'woocommerce',
)
);