PluginProbe
SellKit – Funnel builder and checkout optimizer for WooCommerce to sell more, faster / 1.3.2
SellKit – Funnel builder and checkout optimizer for WooCommerce to sell more, faster v1.3.2
2.6.0 trunk 1.1.0 1.1.4 1.2.1 1.2.2 1.2.3 1.2.5 1.2.9 1.3.1 1.3.2 1.5.0 1.5.1 1.5.4 1.5.7 1.5.8 1.5.9 1.6.2 1.6.5 1.6.8 1.7.2 1.7.4 1.7.5 1.7.9 1.8.1 All 42 releases
sellkit / sellkit.php

sellkit.php in SellKit – Funnel builder and checkout optimizer for WooCommerce to sell more, faster 1.3.2, at sellkit.php

646 lines 13.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: Sellkit
4 * Plugin URI: https://getsellkit.com/
5 * Description: Build unlimited sales funnels, one-click order bumps and upsells, custom thank you pages, and more. The free version of SellKit also offers a huge round of features to optimize your WooCommerce store: build and style single or multi-step checkout pages with advanced styling options. Add, remove & reorder form fields. Fasten the form submission process with pre-populated form data, Instant form validation, and removing cart page. All this and more is 100% free and for an unlimited number of sites.
6 * Version: 1.3.2
7 * Author: Artbees
8 * Author URI: https://artbees.net
9 * Text Domain: sellkit
10 * License: GPL2
11 *
12 * @package Sellkit
13 */
14
15 use Sellkit\Admin\Funnel\Funnel;
16 use Sellkit\Admin\Settings\Sellkit_Admin_Settings;
17 use Sellkit\Contact_Segmentation\Conditions;
18 use Sellkit\Contact_Segmentation\Operators;
19 use Sellkit\Core\Install;
20 use Sellkit\Database;
21 use Sellkit\Product_Meta_Key\Sellkit_Product_Meta_Key;
22
23 defined( 'ABSPATH' ) || die();
24
25 /**
26 * Check If sellkit Class exists.
27 *
28 * @SuppressWarnings(PHPMD.ExcessiveClassComplexity)
29 */
30 if ( ! class_exists( 'Sellkit' ) ) {
31
32 /**
33 * SellKit class.
34 *
35 * @since 1.1.0
36 */
37 class Sellkit {
38
39 /**
40 * Class instance.
41 *
42 * @since 1.1.0
43 * @var Sellkit
44 */
45 private static $instance = null;
46
47 /**
48 * The plugin version number.
49 *
50 * @since 1.1.0
51 *
52 * @access private
53 * @var string
54 */
55 private static $version;
56
57 /**
58 * The plugin basename.
59 *
60 * @since 1.1.0
61 *
62 * @access private
63 * @var string
64 */
65 private static $plugin_basename;
66
67 /**
68 * The plugin name.
69 *
70 * @since 1.1.0
71 *
72 * @access private
73 * @var string
74 */
75 private static $plugin_name;
76
77 /**
78 * The plugin directory.
79 *
80 * @since 1.1.0
81 *
82 * @access private
83 * @var string
84 */
85 public static $plugin_dir;
86
87 /**
88 * The plugin URL.
89 *
90 * @since 1.1.0
91 *
92 * @access private
93 * @var string
94 */
95 private static $plugin_url;
96
97 /**
98 * The plugin assets URL.
99 *
100 * @since 1.1.0
101 * @access public
102 *
103 * @var string
104 */
105 public static $plugin_assets_url;
106
107 /**
108 * Database object.
109 *
110 * @since 1.1.0
111 * @access public
112 * @var Database
113 */
114 public $db;
115
116 /**
117 * Sellkit menus.
118 *
119 * @since 1.1.0
120 * @var array Sellkit menus.
121 */
122 public $sellkit_menus = [
123 'sellkit-dashboard',
124 'sellkit-funnel',
125 'sellkit-settings',
126 ];
127
128 /**
129 * Has pro plugin or not.
130 *
131 * @since 1.1.0
132 * @var array Checks if has pro or not.
133 */
134 public $has_pro = false;
135
136 /**
137 * Get a class instance.
138 *
139 * @since 1.1.0
140 *
141 * @return Sellkit Class
142 */
143 public static function get_instance() {
144 if ( is_null( self::$instance ) ) {
145 self::$instance = new self();
146 }
147
148 return self::$instance;
149 }
150
151 /**
152 * Class constructor.
153 *
154 * @since 1.1.0
155 */
156 public function __construct() {
157 $this->define_constants();
158
159 $this->load_files( [
160 'functions',
161 'funnel/analytics/data-updater',
162 'funnel/class',
163 'funnel/steps',
164 'db',
165 ] );
166
167 $this->db = new Database();
168
169 add_action( 'plugins_loaded', [ $this, 'check_if_has_sellkit_pro' ], 11 );
170 add_action( 'plugins_loaded', [ $this, 'plugins_loaded' ] );
171 add_action( 'init', [ $this, 'init' ] );
172 add_action( 'admin_init', [ $this, 'admin_init' ] );
173 add_action( 'admin_menu', [ $this, 'register_admin_menu' ] );
174 add_action( 'admin_menu', [ $this, 'register_admin_settings_menu' ], 12 );
175
176 // Editor script.
177 add_action( 'elementor/editor/before_enqueue_scripts', [ $this, 'enqueue_editor_script' ] );
178
179 // Register activation hook.
180 register_activation_hook( __FILE__, array( $this, 'activation' ) );
181
182 if ( ! $this->is_sellkit_screen() ) {
183 return;
184 }
185
186 add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_admin_scripts' ] );
187 add_action( 'admin_head', [ $this, 'remove_notice_for_sellkit_pages' ] );
188 add_filter( 'admin_body_class', [ $this, 'sellkit_admin_body_class' ] );
189 }
190
191 /**
192 * Has sellKit pro.
193 *
194 * @since 1.1.0
195 */
196 public function check_if_has_sellkit_pro() {
197 if ( class_exists( 'Sellkit_Pro' ) ) {
198 $this->has_pro = true;
199 }
200 }
201
202 /**
203 * Defines constants used by the plugin.
204 *
205 * @since 1.1.0
206 */
207 protected function define_constants() {
208 $plugin_data = get_file_data( __FILE__, array( 'Plugin Name', 'Version' ), 'sellkit' );
209
210 self::$plugin_basename = plugin_basename( __FILE__ );
211 self::$plugin_name = array_shift( $plugin_data );
212 self::$version = array_shift( $plugin_data );
213 self::$plugin_dir = trailingslashit( plugin_dir_path( __FILE__ ) );
214 self::$plugin_url = trailingslashit( plugin_dir_url( __FILE__ ) );
215 self::$plugin_assets_url = trailingslashit( self::$plugin_url . 'assets' );
216 }
217
218 /**
219 * Plugins loaded.
220 *
221 * @since 1.1.0
222 */
223 public function plugins_loaded() {
224 $this->load_files( [
225 'elementor/class',
226 'admin/class-promote-sellkit-pro',
227 ] );
228 }
229
230 /**
231 * Do some stuff on plugin activation.
232 *
233 * @since NEXT
234 * @return void
235 */
236 public function activation() {
237 $this->load_files( [
238 'core/libraries/wp-async-request',
239 'core/libraries/wp-background-process',
240 'core/install',
241 ] );
242
243 Install::check_database_tables();
244
245 if ( empty( sellkit_get_option( 'current_db_version' ) ) ) {
246 sellkit_update_option( 'current_db_version', '1.2.3' ); // @since 1.2.3
247 }
248
249 if ( ! wp_next_scheduled( 'sellkit_update_rfm_score' ) ) {
250 wp_schedule_event( time(), 'twicedaily', 'sellkit_update_rfm_score' );
251 }
252 }
253
254 /**
255 * Adding sellkit class to body.
256 *
257 * @param string $classes Sellkit the sellkit class.
258 * @return string
259 */
260 public function sellkit_admin_body_class( $classes ) {
261 return "{$classes} sellkit";
262 }
263
264 /**
265 * Initialize admin.
266 *
267 * @since 1.1.0
268 */
269 public function admin_init() {
270 $this->load_files( [
271 'admin/class-notices',
272 'admin/class',
273 ] );
274
275 $this->load_files( [
276 'admin/utilities',
277 'admin/class-components',
278 'admin/components/class-list-table',
279 'admin/components/class-filters',
280 'admin/components/class-analytics',
281 'admin/class-posts',
282 'admin/settings/class-settings',
283 'admin/class-custom-tables',
284 'admin/funnel/class',
285 'core/install',
286 ] );
287 }
288
289 /**
290 * Initialize.
291 *
292 * @since 1.1.0
293 */
294 public function init() {
295 $this->load_files( [
296 'admin/class-steps',
297 'utilities/functions',
298 'contact-segmentation/class',
299 'dynamic-keywords/class',
300 'core/libraries/wp-async-request',
301 'core/libraries/wp-background-process',
302 'settings/class',
303 'contact-segmentation/rfm/class',
304 'admin/settings/integration/class',
305 ] );
306
307 // Register post types.
308 $post_types = [
309 // 'sellkit-analytics',
310 'sellkit-funnels',
311 ];
312
313 foreach ( $post_types as $post_type ) {
314 register_post_type( $post_type, [
315 'public' => false,
316 ] );
317 }
318
319 load_plugin_textdomain( 'sellkit', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
320 }
321
322 /**
323 * Enqueue editor scripts.
324 *
325 * @since 1.1.0
326 * @return void
327 */
328 public function enqueue_editor_script() {
329 wp_enqueue_script(
330 'sellkit-editor',
331 sellkit()->plugin_url() . 'assets/dist/js/editor.min.js',
332 [ 'jquery' ],
333 self::$version,
334 true
335 );
336 }
337
338 /**
339 * Enqueue admin scripts.
340 *
341 * @since 1.1.0
342 */
343 public function enqueue_admin_scripts() {
344 $page = ! empty( $_GET['page'] ) ? $_GET['page'] : ''; // phpcs:ignore
345
346 if ( ! in_array( $page, $this->sellkit_menus, true ) ) {
347 return false;
348 }
349
350 wp_enqueue_editor();
351
352 wp_enqueue_script(
353 'sellkit',
354 sellkit()->plugin_url() . 'assets/dist/admin/sellkit.js',
355 [ 'lodash', 'wp-element', 'wp-i18n', 'wp-util' ],
356 sellkit()->version(),
357 true
358 );
359
360 wp_localize_script(
361 'sellkit',
362 'sellkit',
363 $this->get_localize_data()
364 );
365
366 wp_enqueue_style(
367 'sellkit',
368 sellkit()->plugin_url() . 'assets/dist/admin/sellkit.css',
369 [],
370 sellkit()->version()
371 );
372
373 wp_set_script_translations( 'sellkit', 'sellkit', sellkit()->plugin_dir() . 'languages' );
374
375 $page = sellkit_htmlspecialchars( INPUT_GET, 'page' );
376 }
377
378 /**
379 * Register admin menu.
380 *
381 * @since 1.1.0
382 * @SuppressWarnings(PHPMD.NPathComplexity)
383 */
384 public function register_admin_menu() {
385 $menu_name = esc_html__( 'Sellkit', 'sellkit' );
386 $initial_page = 'sellkit-dashboard';
387 $submenu = [
388 'sellkit-dashboard' => esc_html__( 'Dashboard', 'sellkit' ),
389 'sellkit-funnel' => esc_html__( 'Funnels', 'sellkit' ),
390 ];
391
392 $submenu = apply_filters( 'sellkit_sub_menu', $submenu );
393
394 $svg_file = wp_remote_get( self::plugin_url() . 'assets/img/icons/sellkit-dashboard.svg' );
395
396 add_menu_page(
397 $menu_name,
398 $menu_name,
399 'manage_options',
400 $initial_page,
401 [ $this, 'register_admin_menu_callback' ],
402 'data:image/svg+xml;base64,' . base64_encode( wp_remote_retrieve_body( $svg_file ) ),
403 '58.1'
404 );
405
406 foreach ( $submenu as $slug => $title ) {
407 add_submenu_page(
408 $initial_page,
409 "{$menu_name} {$title}",
410 $title,
411 'edit_theme_options',
412 $slug,
413 [ $this, 'register_admin_menu_callback' ]
414 );
415 }
416 }
417
418 /**
419 * Adds settings menu.
420 *
421 * @since 1.1.0
422 */
423 public function register_admin_settings_menu() {
424 add_submenu_page(
425 'sellkit-dashboard',
426 esc_html__( 'Sellkit', 'sellkit' ) . ' ' . esc_html__( 'Settings', 'sellkit' ),
427 esc_html__( 'Settings', 'sellkit' ),
428 'edit_theme_options',
429 'sellkit-settings',
430 [ $this, 'register_admin_menu_callback' ]
431 );
432 }
433
434 /**
435 * Register admin menu callback.
436 *
437 * @since 1.1.0
438 */
439 public function register_admin_menu_callback() {
440 ?>
441 <div id="wrap" class="wrap">
442 <!-- It's required for notices, otherwise WP adds the notices wherever it finds the first heading element. -->
443 <h1></h1>
444 <div id="sellkit-root"></div>
445 </div>
446 <?php
447 }
448
449 /**
450 * Check if in SellKit pages.
451 *
452 * @since 1.1.0
453 *
454 * @return boolean SellKit screen.
455 */
456 private function is_sellkit_screen() {
457 $page = sellkit_htmlspecialchars( INPUT_GET, 'page' );
458
459 return (
460 is_admin() &&
461 isset( $page ) &&
462 strpos( $page, 'sellkit' ) !== false
463 );
464 }
465
466 /**
467 * Get localize data.
468 *
469 * @since 1.1.0
470 *
471 * @return array
472 */
473 public function get_localize_data() {
474 return [
475 'nonce' => wp_create_nonce( 'sellkit' ),
476 'assetsUrl' => self::$plugin_assets_url,
477 'dynamicKeywords' => Sellkit_Dynamic_Keywords::$keywords['contact_segmentation'],
478 'defaultFunnelSteps' => Sellkit_Admin_Steps::get_default_funnel_steps(),
479 'woocommerceSettings' => $this->get_woocommerce_settings_data(),
480 'contactSegmentation' => [
481 'conditionsOperators' => Operators::$condition_operator_names,
482 'operators' => Operators::$names,
483 'conditionsData' => Conditions::$data,
484 ],
485 'adminUrl' => admin_url(),
486 'url' => site_url(),
487 'timezones' => timezone_identifiers_list(),
488 'defaultSettings' => [
489 'defaultTimezone' => get_option( 'timezone_string' ),
490 ],
491 'elementorActivation' => class_exists( 'Elementor\Plugin' ) ? true : false,
492 'funnelsTemplateSource' => Funnel::SELLKIT_FUNNELS_TEMPLATE_SOURCE,
493 'removedContentBoxes' => Sellkit_Admin_Settings::get_removed_content_box(),
494 'sellkitProIsActive' => $this->has_pro,
495 'wcIsActivated' => $this->has_valid_dependencies(),
496 ];
497 }
498
499 /**
500 * Get woocommerce settings data.
501 *
502 * @since 1.1.0
503 *
504 * @return array|boolean
505 */
506 public function get_woocommerce_settings_data() {
507 if ( ! class_exists( 'WooCommerce' ) ) {
508 return false;
509 }
510
511 return [
512 'currencyFormatNumDecimals' => wc_get_price_decimals(),
513 'currencySymbol' => html_entity_decode( get_woocommerce_currency_symbol() ),
514 'currencyFormatDecimalSep' => wc_get_price_decimal_separator(),
515 'currencyFormatThousandSep' => wc_get_price_thousand_separator(),
516 'currencyPosition' => get_option( 'woocommerce_currency_pos' ),
517 'productDefaultThumbnail' => wc_placeholder_img_src(),
518 ];
519 }
520
521 /**
522 * Remove notices.
523 *
524 * @since 1.1.0
525 */
526 public function remove_notice_for_sellkit_pages() {
527 remove_all_actions( 'admin_notices' );
528 }
529
530 /**
531 * Sellkit dependencies.
532 *
533 * @since 1.1.0
534 */
535 public function has_valid_dependencies() {
536 if ( ! class_exists( 'woocommerce' ) ) {
537 return false;
538 }
539
540 return true;
541 }
542
543 /**
544 * Loads specified PHP files from the plugin includes directory.
545 *
546 * @since 1.1.0
547 *
548 * @param array $file_names The names of the files to be loaded in the includes directory.
549 */
550 public function load_files( $file_names = array() ) {
551
552 foreach ( $file_names as $file_name ) {
553 $path = self::plugin_dir() . 'includes/' . $file_name . '.php';
554
555 if ( file_exists( $path ) ) {
556 require_once $path;
557 }
558 }
559 }
560
561 /**
562 * Returns the version number of the plugin.
563 *
564 * @since 1.1.0
565 *
566 * @return string
567 */
568 public function version() {
569 return self::$version;
570 }
571
572 /**
573 * Returns the plugin basename.
574 *
575 * @since 1.1.0
576 *
577 * @return string
578 */
579 public function plugin_basename() {
580 return self::$plugin_basename;
581 }
582
583 /**
584 * Returns the plugin name.
585 *
586 * @since 1.1.0
587 *
588 * @return string
589 */
590 public function plugin_name() {
591 return self::$plugin_name;
592 }
593
594 /**
595 * Returns the plugin directory.
596 *
597 * @since 1.1.0
598 *
599 * @return string
600 */
601 public function plugin_dir() {
602 return self::$plugin_dir;
603 }
604
605 /**
606 * Returns the plugin URL.
607 *
608 * @since 1.1.0
609 *
610 * @return string
611 */
612 public function plugin_url() {
613 return self::$plugin_url;
614 }
615
616 /**
617 * Returns the plugin assets URL.
618 *
619 * @since 1.1.0
620 *
621 * @return string
622 */
623 public function plugin_assets_url() {
624 return self::$plugin_assets_url;
625 }
626 }
627 }
628
629 if ( ! function_exists( 'sellkit' ) ) {
630 /**
631 * Initialize the Sellkit.
632 *
633 * @since 1.1.0
634 */
635 function sellkit() {
636 return Sellkit::get_instance();
637 }
638 }
639
640 /**
641 * Initialize the Sellkit application.
642 *
643 * @since 1.1.0
644 */
645 sellkit();
646