PluginProbe
SellKit – Funnel builder and checkout optimizer for WooCommerce to sell more, faster / 1.2.2
SellKit – Funnel builder and checkout optimizer for WooCommerce to sell more, faster v1.2.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.2.2, at sellkit.php

660 lines 14.0 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.2.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 if ( ! $this->has_valid_dependencies() ) {
225 return false;
226 }
227
228 $this->load_files( [
229 'elementor/class',
230 ] );
231 }
232
233 /**
234 * Do some stuff on plugin activation.
235 *
236 * @since NEXT
237 * @return void
238 */
239 public function activation() {
240 $this->load_files( [
241 'core/libraries/wp-async-request',
242 'core/libraries/wp-background-process',
243 'core/install',
244 ] );
245
246 Install::check_database_tables();
247
248 if ( empty( sellkit_get_option( 'current_db_version' ) ) ) {
249 sellkit_update_option( 'current_db_version', '1.2.1' );
250 }
251
252 if ( ! wp_next_scheduled( 'sellkit_update_rfm_score' ) ) {
253 wp_schedule_event( time(), 'twicedaily', 'sellkit_update_rfm_score' );
254 }
255 }
256
257 /**
258 * Adding sellkit class to body.
259 *
260 * @param string $classes Sellkit the sellkit class.
261 * @return string
262 */
263 public function sellkit_admin_body_class( $classes ) {
264 return "{$classes} sellkit";
265 }
266
267 /**
268 * Initialize admin.
269 *
270 * @since 1.1.0
271 */
272 public function admin_init() {
273 $this->load_files( [
274 'admin/class-notices',
275 'admin/class',
276 ] );
277
278 if ( ! $this->has_valid_dependencies() ) {
279 return false;
280 }
281
282 $this->load_files( [
283 'admin/utilities',
284 'admin/class-components',
285 'admin/components/class-list-table',
286 'admin/components/class-filters',
287 'admin/components/class-analytics',
288 'admin/class-posts',
289 'admin/settings/class-settings',
290 'admin/class-custom-tables',
291 'admin/funnel/class',
292 'core/install',
293 ] );
294 }
295
296 /**
297 * Initialize.
298 *
299 * @since 1.1.0
300 */
301 public function init() {
302 if ( ! $this->has_valid_dependencies() ) {
303 return false;
304 }
305
306 $this->load_files( [
307 'admin/class-steps',
308 'utilities/functions',
309 'contact-segmentation/class',
310 'dynamic-keywords/class',
311 'core/libraries/wp-async-request',
312 'core/libraries/wp-background-process',
313 'settings/class',
314 'contact-segmentation/rfm/class',
315 'admin/settings/integration/class',
316 ] );
317
318 // Register post types.
319 $post_types = [
320 // 'sellkit-analytics',
321 'sellkit-funnels',
322 ];
323
324 foreach ( $post_types as $post_type ) {
325 register_post_type( $post_type, [
326 'public' => false,
327 ] );
328 }
329 }
330
331 /**
332 * Enqueue editor scripts.
333 *
334 * @since 1.1.0
335 * @return void
336 */
337 public function enqueue_editor_script() {
338 wp_enqueue_script(
339 'sellkit-editor',
340 sellkit()->plugin_url() . 'assets/dist/js/editor.min.js',
341 [ 'jquery' ],
342 self::$version,
343 true
344 );
345 }
346
347 /**
348 * Enqueue admin scripts.
349 *
350 * @since 1.1.0
351 */
352 public function enqueue_admin_scripts() {
353 if ( ! $this->has_valid_dependencies() ) {
354 return false;
355 }
356
357 $page = ! empty( $_GET['page'] ) ? $_GET['page'] : ''; // phpcs:ignore
358
359 if ( ! in_array( $page, $this->sellkit_menus, true ) ) {
360 return false;
361 }
362
363 wp_enqueue_editor();
364
365 wp_enqueue_script(
366 'sellkit',
367 sellkit()->plugin_url() . 'assets/dist/admin/sellkit.js',
368 [ 'lodash', 'wp-element', 'wp-i18n', 'wp-util' ],
369 sellkit()->version(),
370 true
371 );
372
373 wp_localize_script(
374 'sellkit',
375 'sellkit',
376 $this->get_localize_data()
377 );
378
379 wp_enqueue_style(
380 'sellkit',
381 sellkit()->plugin_url() . 'assets/dist/admin/sellkit.css',
382 [],
383 sellkit()->version()
384 );
385
386 wp_set_script_translations( 'sellkit', 'sellkit', sellkit()->plugin_dir() . 'languages' );
387
388 $page = sellkit_htmlspecialchars( INPUT_GET, 'page' );
389 }
390
391 /**
392 * Register admin menu.
393 *
394 * @since 1.1.0
395 * @SuppressWarnings(PHPMD.NPathComplexity)
396 */
397 public function register_admin_menu() {
398 if ( ! $this->has_valid_dependencies() ) {
399 return false;
400 }
401
402 $menu_name = esc_html__( 'Sellkit', 'sellkit' );
403 $initial_page = 'sellkit-dashboard';
404 $submenu = [
405 'sellkit-dashboard' => esc_html__( 'Dashboard', 'sellkit' ),
406 'sellkit-funnel' => esc_html__( 'Funnels', 'sellkit' ),
407 ];
408
409 $svg_file = wp_remote_get( self::plugin_url() . 'assets/img/icons/sellkit-dashboard.svg' );
410
411 add_menu_page(
412 $menu_name,
413 $menu_name,
414 'manage_options',
415 $initial_page,
416 [ $this, 'register_admin_menu_callback' ],
417 'data:image/svg+xml;base64,' . base64_encode( wp_remote_retrieve_body( $svg_file ) ),
418 '58.1'
419 );
420
421 foreach ( $submenu as $slug => $title ) {
422 add_submenu_page(
423 $initial_page,
424 "{$menu_name} {$title}",
425 $title,
426 'edit_theme_options',
427 $slug,
428 [ $this, 'register_admin_menu_callback' ]
429 );
430 }
431 }
432
433 /**
434 * Adds settings menu.
435 *
436 * @since 1.1.0
437 */
438 public function register_admin_settings_menu() {
439 add_submenu_page(
440 'sellkit-dashboard',
441 esc_html__( 'Sellkit', 'sellkit' ) . ' ' . esc_html__( 'Settings', 'sellkit' ),
442 esc_html__( 'Settings', 'sellkit' ),
443 'edit_theme_options',
444 'sellkit-settings',
445 [ $this, 'register_admin_menu_callback' ]
446 );
447 }
448
449 /**
450 * Register admin menu callback.
451 *
452 * @since 1.1.0
453 */
454 public function register_admin_menu_callback() {
455 ?>
456 <div id="wrap" class="wrap">
457 <!-- It's required for notices, otherwise WP adds the notices wherever it finds the first heading element. -->
458 <h1></h1>
459 <div id="sellkit-root"></div>
460 </div>
461 <?php
462 }
463
464 /**
465 * Check if in SellKit pages.
466 *
467 * @since 1.1.0
468 *
469 * @return boolean SellKit screen.
470 */
471 private function is_sellkit_screen() {
472 $page = sellkit_htmlspecialchars( INPUT_GET, 'page' );
473
474 return (
475 is_admin() &&
476 isset( $page ) &&
477 strpos( $page, 'sellkit' ) !== false
478 );
479 }
480
481 /**
482 * Get localize data.
483 *
484 * @since 1.1.0
485 *
486 * @return array
487 */
488 public function get_localize_data() {
489 return [
490 'nonce' => wp_create_nonce( 'sellkit' ),
491 'assetsUrl' => self::$plugin_assets_url,
492 'dynamicKeywords' => Sellkit_Dynamic_Keywords::$keywords['contact_segmentation'],
493 'defaultFunnelSteps' => Sellkit_Admin_Steps::get_default_funnel_steps(),
494 'woocommerceSettings' => $this->get_woocommerce_settings_data(),
495 'contactSegmentation' => [
496 'conditionsOperators' => Operators::$condition_operator_names,
497 'operators' => Operators::$names,
498 'conditionsData' => Conditions::$data,
499 ],
500 'adminUrl' => admin_url(),
501 'url' => site_url(),
502 'timezones' => timezone_identifiers_list(),
503 'defaultSettings' => [
504 'defaultTimezone' => get_option( 'timezone_string' ),
505 ],
506 'elementorActivation' => class_exists( 'Elementor\Plugin' ) ? true : false,
507 'funnelsTemplateSource' => Funnel::SELLKIT_FUNNELS_TEMPLATE_SOURCE,
508 'removedContentBoxes' => Sellkit_Admin_Settings::get_removed_content_box(),
509 'sellkitProIsActive' => $this->has_pro,
510 ];
511 }
512
513 /**
514 * Get woocommerce settings data.
515 *
516 * @since 1.1.0
517 *
518 * @return array|boolean
519 */
520 public function get_woocommerce_settings_data() {
521 if ( ! class_exists( 'WooCommerce' ) ) {
522 return false;
523 }
524
525 return [
526 'currencyFormatNumDecimals' => wc_get_price_decimals(),
527 'currencySymbol' => html_entity_decode( get_woocommerce_currency_symbol() ),
528 'currencyFormatDecimalSep' => wc_get_price_decimal_separator(),
529 'currencyFormatThousandSep' => wc_get_price_thousand_separator(),
530 'currencyPosition' => get_option( 'woocommerce_currency_pos' ),
531 'productDefaultThumbnail' => wc_placeholder_img_src(),
532 ];
533 }
534
535 /**
536 * Remove notices.
537 *
538 * @since 1.1.0
539 */
540 public function remove_notice_for_sellkit_pages() {
541 remove_all_actions( 'admin_notices' );
542 }
543
544 /**
545 * Sellkit dependencies.
546 *
547 * @since 1.1.0
548 */
549 public function has_valid_dependencies() {
550 if ( ! class_exists( 'woocommerce' ) ) {
551 return false;
552 }
553
554 return true;
555 }
556
557 /**
558 * Loads specified PHP files from the plugin includes directory.
559 *
560 * @since 1.1.0
561 *
562 * @param array $file_names The names of the files to be loaded in the includes directory.
563 */
564 public function load_files( $file_names = array() ) {
565
566 foreach ( $file_names as $file_name ) {
567 $path = self::plugin_dir() . 'includes/' . $file_name . '.php';
568
569 if ( file_exists( $path ) ) {
570 require_once $path;
571 }
572 }
573 }
574
575 /**
576 * Returns the version number of the plugin.
577 *
578 * @since 1.1.0
579 *
580 * @return string
581 */
582 public function version() {
583 return self::$version;
584 }
585
586 /**
587 * Returns the plugin basename.
588 *
589 * @since 1.1.0
590 *
591 * @return string
592 */
593 public function plugin_basename() {
594 return self::$plugin_basename;
595 }
596
597 /**
598 * Returns the plugin name.
599 *
600 * @since 1.1.0
601 *
602 * @return string
603 */
604 public function plugin_name() {
605 return self::$plugin_name;
606 }
607
608 /**
609 * Returns the plugin directory.
610 *
611 * @since 1.1.0
612 *
613 * @return string
614 */
615 public function plugin_dir() {
616 return self::$plugin_dir;
617 }
618
619 /**
620 * Returns the plugin URL.
621 *
622 * @since 1.1.0
623 *
624 * @return string
625 */
626 public function plugin_url() {
627 return self::$plugin_url;
628 }
629
630 /**
631 * Returns the plugin assets URL.
632 *
633 * @since 1.1.0
634 *
635 * @return string
636 */
637 public function plugin_assets_url() {
638 return self::$plugin_assets_url;
639 }
640 }
641 }
642
643 if ( ! function_exists( 'sellkit' ) ) {
644 /**
645 * Initialize the Sellkit.
646 *
647 * @since 1.1.0
648 */
649 function sellkit() {
650 return Sellkit::get_instance();
651 }
652 }
653
654 /**
655 * Initialize the Sellkit application.
656 *
657 * @since 1.1.0
658 */
659 sellkit();
660