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

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