| 1 |
<?php |
| 2 |
/** |
| 3 |
* Plugin Name: Smart Swatches |
| 4 |
* Plugin URI: https://shapedplugin.com/smart-swatches-for-woocommerce/ |
| 5 |
* Description: Generate vibrant color, image, and button variation swatches to showcase product attributes in a visually appealing manner for the WooCommerce shop. |
| 6 |
* Version: 1.0.12 |
| 7 |
* Author: ShapedPlugin, LLC |
| 8 |
* Author URI: https://shapedplugin.com/ |
| 9 |
* License: GPLv3 |
| 10 |
* License URI: http://www.gnu.org/licenses/gpl-3.0.html |
| 11 |
* Text Domain: smart-swatches |
| 12 |
* Domain Path: /languages |
| 13 |
* Requires Plugins: woocommerce |
| 14 |
* WC requires at least: 5.5.0 |
| 15 |
* WC tested up to: 11.0.0 |
| 16 |
* |
| 17 |
* @link https://shapedplugin.com |
| 18 |
* @since 1.0.0 |
| 19 |
* @package Smart_Swatches |
| 20 |
* @wordpress-plugin |
| 21 |
*/ |
| 22 |
|
| 23 |
// If this file is called directly, abort. |
| 24 |
if ( ! defined( 'WPINC' ) ) { |
| 25 |
exit; // Cannot access directly. |
| 26 |
} |
| 27 |
|
| 28 |
class_exists( 'ShapedPlugin\SmartSwatches\SmartSwatches' ) || require_once __DIR__ . '/vendor/autoload.php'; |
| 29 |
|
| 30 |
// Define constants. |
| 31 |
if ( ! defined( 'SMART_SWATCHES_VERSION' ) ) { |
| 32 |
define( 'SMART_SWATCHES_VERSION', '1.0.12' ); |
| 33 |
} |
| 34 |
|
| 35 |
if ( ! defined( 'SMART_SWATCHES_FILE' ) ) { |
| 36 |
define( 'SMART_SWATCHES_FILE', __FILE__ ); |
| 37 |
} |
| 38 |
|
| 39 |
if ( ! defined( 'SMART_SWATCHES_URL' ) ) { |
| 40 |
define( 'SMART_SWATCHES_URL', plugin_dir_url( __FILE__ ) . 'src/' ); |
| 41 |
} |
| 42 |
|
| 43 |
if ( ! defined( 'SMART_SWATCHES_BASE' ) ) { |
| 44 |
define( 'SMART_SWATCHES_BASE', plugin_basename( __FILE__ ) ); |
| 45 |
} |
| 46 |
|
| 47 |
if ( ! defined( 'SMART_SWATCHES_PATH' ) ) { |
| 48 |
define( 'SMART_SWATCHES_PATH', plugin_dir_path( __FILE__ ) ); |
| 49 |
} |
| 50 |
|
| 51 |
use ShapedPlugin\SmartSwatches\SmartSwatches; |
| 52 |
// Declare that the plugin is compatible with WooCommerce High-Performance order storage feature. |
| 53 |
add_action( |
| 54 |
'before_woocommerce_init', |
| 55 |
function () { |
| 56 |
if ( class_exists( \Automattic\WooCommerce\Utilities\FeaturesUtil::class ) ) { |
| 57 |
\Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility( 'custom_order_tables', __FILE__, true ); |
| 58 |
} |
| 59 |
} |
| 60 |
); |
| 61 |
|
| 62 |
if ( ! function_exists( 'smart_swatches_is_woocommerce_active' ) ) { |
| 63 |
/** |
| 64 |
* Check is WooCommerce active. |
| 65 |
* |
| 66 |
* @return bool |
| 67 |
*/ |
| 68 |
function smart_swatches_is_woocommerce_active() { |
| 69 |
$active_plugins = (array) get_option( 'active_plugins', array() ); |
| 70 |
if ( is_multisite() ) { |
| 71 |
$active_plugins = array_merge( $active_plugins, get_site_option( 'active_sitewide_plugins', array() ) ); |
| 72 |
} |
| 73 |
return in_array( 'woocommerce/woocommerce.php', $active_plugins, true ) || array_key_exists( 'woocommerce/woocommerce.php', $active_plugins ) || class_exists( 'WooCommerce' ); |
| 74 |
} |
| 75 |
} |
| 76 |
|
| 77 |
/** |
| 78 |
* Show admin notice if WooCommerce is not activated. |
| 79 |
* |
| 80 |
* @since 1.0.0 |
| 81 |
*/ |
| 82 |
function smart_swatches_free_wc_admin_notice() { |
| 83 |
$link = esc_url( |
| 84 |
add_query_arg( |
| 85 |
array( |
| 86 |
'tab' => 'plugin-information', |
| 87 |
'plugin' => 'woocommerce', |
| 88 |
'TB_iframe' => 'true', |
| 89 |
'width' => '640', |
| 90 |
'height' => '500', |
| 91 |
), |
| 92 |
admin_url( 'plugin-install.php' ) |
| 93 |
) |
| 94 |
); |
| 95 |
$outline = '<div class="error"><p>' . wp_kses_post( 'You must install and activate <a class="thickbox open-plugin-details-modal" href="' . esc_url( $link ) . '"><strong>WooCommerce</strong></a> plugin to make the <strong>Smart Swatches</strong> work.', 'smart-swatches' ) . '</p></div>'; |
| 96 |
echo wp_kses_post( $outline ); |
| 97 |
} |
| 98 |
|
| 99 |
/** |
| 100 |
* Init the SmartSwatches plugin. |
| 101 |
* |
| 102 |
* @since 1.0.0 |
| 103 |
*/ |
| 104 |
function smart_swatches_launch_smart_swatches_free() { |
| 105 |
if ( ! defined( 'SHAPEDPLIUGIN_OFFER_BANNER_LOADED' ) ) { |
| 106 |
define( 'SHAPEDPLIUGIN_OFFER_BANNER_LOADED', true ); |
| 107 |
|
| 108 |
/** |
| 109 |
* Responsible for generating admin offer banner. |
| 110 |
*/ |
| 111 |
ShapedPlugin\SmartSwatches\Admin\ShapedPlugin_Offer_Banner::instance(); |
| 112 |
} |
| 113 |
|
| 114 |
// Launch the plugin. |
| 115 |
if ( ! smart_swatches_is_woocommerce_active() ) { |
| 116 |
add_action( 'admin_notices', 'smart_swatches_free_wc_admin_notice' ); |
| 117 |
} else { |
| 118 |
return SmartSwatches::instance(); |
| 119 |
} |
| 120 |
} |
| 121 |
|
| 122 |
/** |
| 123 |
* Pro version check. |
| 124 |
* |
| 125 |
* @return boolean |
| 126 |
*/ |
| 127 |
function is_smart_swatches_pro_active() { |
| 128 |
include_once ABSPATH . 'wp-admin/includes/plugin.php'; |
| 129 |
if ( ( is_plugin_active( 'smart-swatches-pro/smart-swatches-pro.php' ) || is_plugin_active_for_network( 'smart-swatches-pro/smart-swatches-pro.php' ) ) ) { |
| 130 |
return true; |
| 131 |
} |
| 132 |
} |
| 133 |
|
| 134 |
// Launch the plugin if Smart Swatches Pro is not active. |
| 135 |
if ( ! is_smart_swatches_pro_active() ) { |
| 136 |
smart_swatches_launch_smart_swatches_free(); |
| 137 |
} |
| 138 |
|