PluginProbe
SellKit – Funnel builder and checkout optimizer for WooCommerce to sell more, faster / 1.1.4
SellKit – Funnel builder and checkout optimizer for WooCommerce to sell more, faster v1.1.4
2.7.0 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 All 43 releases
sellkit / sellkit.php

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

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