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

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