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

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