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

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