PluginProbe
Swatchly – Product Variation Swatches for WooCommerce / 1.0.9
Swatchly – Product Variation Swatches for WooCommerce v1.0.9
1.4.16 1.4.15 1.4.14 trunk 1.0.5 1.0.7 1.0.9 1.1.0 1.1.1 1.1.2 1.1.4 1.1.5 1.1.6 1.1.7 1.1.8 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 All 49 releases
swatchly / swatchly.php

swatchly.php in Swatchly – Product Variation Swatches for WooCommerce 1.0.9, at swatchly.php

208 lines 5.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Plugin Name: Swatchly - Variation Swatches for WooCommerce Products
4 * Plugin URI: https://plugindemo.hasthemes.com/swatchly/
5 * Description: Variation Swatches for WooCommerce Products
6 * Version: 1.0.9
7 * Author: HasThemes
8 * Author URI: https://hasthemes.com
9 * License: GPL v2 or later
10 * License URI: https://www.gnu.org/licenses/gpl-2.0.html
11 * Text Domain: swatchly
12 * Domain Path: /languages
13 */
14
15 // If this file is accessed directly, exit
16 if ( ! defined( 'ABSPATH' ) ) {
17 exit;
18 }
19
20 /**
21 * Main class
22 *
23 * @since 1.0.0
24 */
25 final class Swatchly {
26
27 /**
28 * Version
29 *
30 * @since 1.0.0
31 */
32 public $version = '1.0.9';
33
34 /**
35 * The single instance of the class
36 *
37 * @since 1.0.0
38 */
39 protected static $_instance = null;
40
41 /**
42 * Main Instance
43 *
44 * Ensures only one instance of this pluin is loaded
45 *
46 * @since 1.0.0
47 */
48 public static function instance() {
49 if ( is_null( self::$_instance ) ) {
50 self::$_instance = new self();
51 }
52 return self::$_instance;
53 }
54
55 /**
56 * Constructor
57 *
58 * @since 1.0.0
59 */
60 private function __construct() {
61 $this->define_constants();
62 $this->includes();
63 $this->run();
64 }
65
66 /**
67 * Define the required constants
68 *
69 * @since 1.0.0
70 */
71 private function define_constants() {
72 define( 'SWATCHLY_VERSION', $this->version );
73 define( 'SWATCHLY_FILE', __FILE__ );
74 define( 'SWATCHLY_PATH', __DIR__ );
75 define( 'SWATCHLY_URL', plugins_url( '', SWATCHLY_FILE ) );
76 define( 'SWATCHLY_ASSETS', SWATCHLY_URL . '/assets' );
77 }
78
79 /**
80 * Include required core files
81 *
82 * @since 1.0.0
83 */
84 public function includes() {
85 /**
86 * Including Codestar Framework.
87 */
88 if ( ! class_exists( 'CSF' ) ) {
89 require_once SWATCHLY_PATH .'/libs/codestar-framework/codestar-framework.php';
90 }
91
92 /**
93 * Composer autoload file.
94 */
95 require_once SWATCHLY_PATH . '/vendor/autoload.php';
96
97 /**
98 * Including plugin file for secutiry purpose
99 */
100 if ( ! function_exists( 'is_plugin_active' ) ) {
101 include_once ABSPATH . 'wp-admin/includes/plugin.php';
102 }
103
104 if( is_admin() ){
105 require_once SWATCHLY_PATH .'/includes/Admin/recommendations/init.php';
106 }
107 }
108
109 /**
110 * First initialization of the plugin
111 *
112 * @since 1.0.0
113 */
114 private function run() {
115 register_activation_hook( __FILE__, array( $this, 'register_activation_hook_cb' ) );
116
117 if ( ! is_plugin_active( 'woocommerce/woocommerce.php' ) ) {
118 add_action( 'admin_notices', array( $this, 'build_dependencies_notice' ) );
119 } else {
120 // Set up localisation.
121 add_action( 'plugins_loaded', array( $this, 'load_plugin_textdomain' ) );
122
123 // Finally initialize this plugin
124 add_action( 'plugins_loaded', array( $this, 'init' ) );
125 }
126 }
127
128 /**
129 * Do stuff upon plugin activation
130 *
131 * @since 1.0.0
132 */
133 public function register_activation_hook_cb() {
134 // deactivate the free plugin if active
135 if( is_plugin_active('swatchly-pro/swatchly-pro.php') ){
136 add_action('update_option_active_plugins', function(){
137 deactivate_plugins('swatchly-pro/swatchly-pro.php');
138 });
139 }
140
141 $installed = get_option( 'swatchly_installed' );
142
143 if ( ! $installed ) {
144 update_option( 'swatchly_installed', time() );
145 }
146
147 update_option( 'swatchly_version', SWATCHLY_VERSION );
148 }
149
150 /**
151 * Load the plugin textdomain
152 *
153 * @since 1.0.0
154 */
155 public function load_plugin_textdomain() {
156 load_plugin_textdomain( 'swatchly', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' );
157 }
158
159 /**
160 * Initialize this plugin
161 *
162 * @since 1.0.0
163 */
164 public function init() {
165 new Swatchly\Admin\Global_Settings();
166 new Swatchly\Frontend\Woo_Config();
167
168 if ( is_admin() ) {
169 new Swatchly\Admin();
170 } elseif( !swatchly_get_option('disable_plugin') ) {
171 new Swatchly\Frontend();
172 }
173 }
174
175 /**
176 * Output a admin notice when build dependencies not met
177 *
178 * @since 1.0.0
179 */
180 public function build_dependencies_notice() {
181 $message = sprintf(
182 /*
183 * translators:
184 * 1: Swatchly.
185 * 2: WooCommerce.
186 */
187 esc_html__( '%1$s plugin requires the %2$s plugin to be installed and activated in order to work.', 'swatchly' ),
188 '<strong>' . esc_html__( 'Swatchly', 'swatchly' ) . '</strong>',
189 '<strong>' . esc_html__( 'WooCommerce', 'swatchly' ) . '</strong>'
190 );
191
192 printf( '<div class="notice notice-warning"><p>%1$s</p></div>', $message );
193 }
194
195 }
196
197 /**
198 * Returns the main instance of Swatchly
199 *
200 * @since 1.0.0
201 */
202
203 function swatchly() { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.FunctionNameInvalid
204 return Swatchly::instance();
205 }
206
207 // Kick-off the plugin
208 swatchly();