PluginProbe
Swatchly – Product Variation Swatches for WooCommerce / 1.4.5
Swatchly – Product Variation Swatches for WooCommerce v1.4.5
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.4.5, at swatchly.php

245 lines 6.6 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.4.5
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.4.5';
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 ( !function_exists( 'get_current_screen' ) ){
105 require_once ABSPATH . '/wp-admin/includes/screen.php';
106 }
107
108 if( is_admin() ){
109 require_once SWATCHLY_PATH .'/includes/Admin/recommendations/init.php';
110 require_once SWATCHLY_PATH .'/includes/Admin/Diagnostic_Data.php';
111 require_once SWATCHLY_PATH .'/includes/Admin/Notices.php';
112 require_once SWATCHLY_PATH .'/includes/Admin/Swatchly_Trial.php';
113 }
114 }
115
116 /**
117 * First initialization of the plugin
118 *
119 * @since 1.0.0
120 */
121 private function run() {
122 register_activation_hook( __FILE__, array( $this, 'register_activation_hook_cb' ) );
123
124 if ( ! is_plugin_active( 'woocommerce/woocommerce.php' ) ) {
125 add_action( 'admin_notices', array( $this, 'build_dependencies_notice' ) );
126 } else {
127 // Set up localisation.
128 add_action( 'init', array( $this, 'load_plugin_textdomain' ) );
129
130 // Finally initialize this plugin
131 add_action( 'plugins_loaded', array( $this, 'init' ) );
132
133 // Redirect to welcome page after activate the plugin
134 add_action('admin_init', array( $this, 'redirect_after_activate') );
135 }
136 }
137
138 /**
139 * Do stuff upon plugin activation
140 *
141 * @since 1.0.0
142 */
143 public function register_activation_hook_cb() {
144 // deactivate the free plugin if active
145 if( is_plugin_active('swatchly-pro/swatchly-pro.php') ){
146 add_action('update_option_active_plugins', function(){
147 deactivate_plugins('swatchly-pro/swatchly-pro.php');
148 });
149 }
150
151 $installed = get_option( 'swatchly_installed' );
152
153 if ( ! $installed ) {
154 update_option( 'swatchly_installed', time() );
155 }
156
157 update_option( 'swatchly_version', SWATCHLY_VERSION );
158
159 // It sets a transient that will be used to redirect the user to the welcome page after
160 // activating the plugin.
161 set_transient( 'swatchly_do_activation_redirect', true, 30 );
162 }
163
164 /**
165 * It checks if a transient exists, if it does, it deletes it and redirects to the welcome page
166 *
167 * @return the value of the transient.
168 */
169 public function redirect_after_activate(){
170 $woolentor_status = is_plugin_active('woolentor-addons/woolentor_addons_elementor.php');
171
172 // return when woolentor is already active
173 if( $woolentor_status ){
174 return;
175 }
176
177 if ( current_user_can('manage_options') && get_transient('swatchly_do_activation_redirect') ) {
178 delete_transient( 'swatchly_do_activation_redirect' );
179
180 exit( esc_url(wp_redirect("admin.php?page=swatchly-admin")) );
181 }
182 }
183
184 /**
185 * Load the plugin textdomain
186 *
187 * @since 1.0.0
188 */
189 public function load_plugin_textdomain() {
190 load_plugin_textdomain( 'swatchly', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' );
191 }
192
193 /**
194 * Initialize this plugin
195 *
196 * @since 1.0.0
197 */
198 public function init() {
199 new Swatchly\Helper();
200 new Swatchly\Admin\Global_Settings();
201 new Swatchly\Frontend\Woo_Config();
202
203 if ( is_admin() ) {
204 new Swatchly\Admin();
205 } elseif( !swatchly_get_option('disable_plugin') ) {
206 new Swatchly\Frontend();
207 new Swatchly\Compatibility\Elementor();
208 }
209 }
210
211 /**
212 * Output a admin notice when build dependencies not met
213 *
214 * @since 1.0.0
215 */
216 public function build_dependencies_notice() {
217 $message = sprintf(
218 /*
219 * translators:
220 * 1: Swatchly.
221 * 2: WooCommerce.
222 */
223 esc_html__( '%1$s plugin requires the %2$s plugin to be installed and activated in order to work.', 'swatchly' ),
224 '<strong>' . esc_html__( 'Swatchly', 'swatchly' ) . '</strong>',
225 '<strong>' . esc_html__( 'WooCommerce', 'swatchly' ) . '</strong>'
226 );
227
228 printf( '<div class="notice notice-warning"><p>%1$s</p></div>', wp_kses_post($message) );
229 }
230
231 }
232
233 /**
234 * Returns the main instance of Swatchly
235 *
236 * @since 1.0.0
237 */
238
239 function swatchly() { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.FunctionNameInvalid
240 return Swatchly::instance();
241 }
242
243 // Kick-off the plugin
244 swatchly();
245