'plugin-information', 'plugin' => 'woocommerce', 'TB_iframe' => 'true', 'width' => '640', 'height' => '500', ); printf( '

%2$s %4$s

', 'notice notice-error', wp_kses( __( 'Variation Swatches for WooCommerce is an add-on of ', 'woo-variation-swatches' ), array( 'strong' => array() ) ), esc_url( add_query_arg( $args, admin_url( 'plugin-install.php' ) ) ), esc_html__( 'WooCommerce', 'woo-variation-swatches' ) ); } } add_action( 'admin_notices', 'woo_variation_swatches_missing_wc_notice' ); /** * Returns the main instance. */ function woo_variation_swatches() { if ( ! class_exists( 'WooCommerce', false ) ) { return false; } if ( function_exists( 'woo_variation_swatches_pro' ) && woo_variation_swatches_using_correct_pro_version() ) { return woo_variation_swatches_pro(); } return Woo_Variation_Swatches::instance(); } add_action( 'plugins_loaded', 'woo_variation_swatches' ); /** * Check is using correct version of pro plugin. * * @return bool */ function woo_variation_swatches_using_correct_pro_version(): bool { return defined( 'WOO_VARIATION_SWATCHES_PRO_PLUGIN_VERSION' ) && ( version_compare( constant('WOO_VARIATION_SWATCHES_PRO_PLUGIN_VERSION'), constant( 'WOO_VARIATION_SWATCHES_MINIMUM_COMPATIBLE_PRO_PLUGIN_VERSION' ) ) >= 0 ); } /** * Prevent activating pro old version. * * @return void */ function woo_variation_swatches_deactivate_pro() { if ( woo_variation_swatches_using_correct_pro_version() ) { return; } if ( ! function_exists( 'is_plugin_active' ) ) { require_once ABSPATH . 'wp-admin/includes/plugin.php'; } if ( is_plugin_active( 'woo-variation-swatches-pro/woo-variation-swatches-pro.php' ) ) { // Suppress "Plugin activated." notice. unset($_GET['activate']); // phpcs:ignore WordPress.Security.NonceVerification.Recommended // Display notice why pro version cannot activate. add_action('admin_notices', 'woo_variation_swatches_deactivate_notice_pro'); // Deactivate the plugin silently, Prevent deactivation hooks from running. deactivate_plugins( 'woo-variation-swatches-pro/woo-variation-swatches-pro.php', true ); } } /** * Prevent Pro plugin. * * @return void */ function woo_variation_swatches_deactivate_notice_pro() { if ( woo_variation_swatches_using_correct_pro_version() ) { return; } /* translators: %s: Pro Plugin Version */ $notice_text = sprintf(esc_html__('You are running older version of "Variation Swatches for WooCommerce - Pro". Please upgrade to %s or upper and continue.', 'woo-variation-swatches'), esc_html(constant( 'WOO_VARIATION_SWATCHES_MINIMUM_COMPATIBLE_PRO_PLUGIN_VERSION' ))); printf( '

%2$s

', 'notice notice-error', esc_html($notice_text) ); } /** * Show notice on plugin row. * * @param string $plugin_file Refer to {@see 'plugin_row_meta'} filter. * @param array $plugin_data Refer to {@see 'plugin_row_meta'} filter. * * @return void */ function woo_variation_swatches_row_meta_notice_pro( string $plugin_file, array $plugin_data) { if ( plugin_basename( WOO_VARIATION_SWATCHES_MAYBE_PRO_PLUGIN_FILE ) === $plugin_file ) { $current_version = $plugin_data['Version']; if ( version_compare( $current_version, constant( 'WOO_VARIATION_SWATCHES_MINIMUM_COMPATIBLE_PRO_PLUGIN_VERSION' ), '<' ) ) { /* translators: %s: Pro Plugin Version */ $notice_text = sprintf(esc_html__('You are running older version of "Variation Swatches for WooCommerce - Pro". Please upgrade to %s or upper.', 'woo-variation-swatches'), esc_html(constant( 'WOO_VARIATION_SWATCHES_MINIMUM_COMPATIBLE_PRO_PLUGIN_VERSION' ))); printf( '

%s

', esc_html($notice_text) ); } } } /** * HPOS compatibility declaration. * * @return void */ function woo_variation_swatches_hpos_compatibility() { if ( class_exists( \Automattic\WooCommerce\Utilities\FeaturesUtil::class ) ) { \Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility( 'custom_order_tables', __FILE__, true ); } } add_action( 'before_woocommerce_init', 'woo_variation_swatches_hpos_compatibility' ); add_action( 'plugins_loaded', 'woo_variation_swatches_deactivate_pro', 9 ); add_action( 'after_plugin_row_meta', 'woo_variation_swatches_row_meta_notice_pro', 10, 2 );