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

646 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.5.1
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 'db',
161 'functions',
162 'funnel/analytics/data-updater',
163 'funnel/class',
164 'funnel/contacts/base-contacts',
165 'funnel/steps',
166 ] );
167
168 $this->db = new Database();
169
170 add_action( 'plugins_loaded', [ $this, 'check_if_has_sellkit_pro' ], 11 );
171 add_action( 'plugins_loaded', [ $this, 'plugins_loaded' ] );
172 add_action( 'init', [ $this, 'init' ] );
173 add_action( 'admin_init', [ $this, 'admin_init' ] );
174 add_action( 'admin_menu', [ $this, 'register_admin_menu' ] );
175 add_action( 'admin_menu', [ $this, 'register_admin_settings_menu' ], 12 );
176
177 // Editor script.
178 add_action( 'elementor/editor/before_enqueue_scripts', [ $this, 'enqueue_editor_script' ] );
179
180 // Register activation hook.
181 register_activation_hook( __FILE__, array( $this, 'activation' ) );
182
183 if ( ! $this->is_sellkit_screen() ) {
184 return;
185 }
186
187 add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_admin_scripts' ] );
188 add_action( 'admin_head', [ $this, 'remove_notice_for_sellkit_pages' ] );
189 add_filter( 'admin_body_class', [ $this, 'sellkit_admin_body_class' ] );
190 }
191
192 /**
193 * Has sellKit pro.
194 *
195 * @since 1.1.0
196 */
197 public function check_if_has_sellkit_pro() {
198 if ( class_exists( 'Sellkit_Pro' ) ) {
199 $this->has_pro = true;
200 }
201 }
202
203 /**
204 * Defines constants used by the plugin.
205 *
206 * @since 1.1.0
207 */
208 protected function define_constants() {
209 $plugin_data = get_file_data( __FILE__, array( 'Plugin Name', 'Version' ), 'sellkit' );
210
211 self::$plugin_basename = plugin_basename( __FILE__ );
212 self::$plugin_name = array_shift( $plugin_data );
213 self::$version = array_shift( $plugin_data );
214 self::$plugin_dir = trailingslashit( plugin_dir_path( __FILE__ ) );
215 self::$plugin_url = trailingslashit( plugin_dir_url( __FILE__ ) );
216 self::$plugin_assets_url = trailingslashit( self::$plugin_url . 'assets' );
217 }
218
219 /**
220 * Plugins loaded.
221 *
222 * @since 1.1.0
223 */
224 public function plugins_loaded() {
225 $this->load_files( [
226 'elementor/class',
227 'admin/class-promote-sellkit-pro',
228 ] );
229 }
230
231 /**
232 * Do some stuff on plugin activation.
233 *
234 * @since NEXT
235 * @return void
236 */
237 public function activation() {
238 $this->load_files( [
239 'core/libraries/wp-async-request',
240 'core/libraries/wp-background-process',
241 'core/install',
242 ] );
243
244 Install::check_database_tables();
245
246 if ( empty( sellkit_get_option( 'current_db_version' ) ) ) {
247 sellkit_update_option( 'current_db_version', '1.2.7' ); // @since 1.5.0
248 }
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 'admin/class',
274 ] );
275
276 $this->load_files( [
277 'admin/utilities',
278 'admin/class-components',
279 'admin/components/class-list-table',
280 'admin/components/class-filters',
281 'admin/components/class-analytics',
282 'admin/class-posts',
283 'admin/settings/class-settings',
284 'admin/class-custom-tables',
285 'admin/funnel/class',
286 'core/install',
287 ] );
288 }
289
290 /**
291 * Initialize.
292 *
293 * @since 1.1.0
294 */
295 public function init() {
296 $this->load_files( [
297 'admin/class-steps',
298 'utilities/functions',
299 'contact-segmentation/class',
300 'dynamic-keywords/class',
301 'core/libraries/wp-async-request',
302 'core/libraries/wp-background-process',
303 'settings/class',
304 'contact-segmentation/rfm/class',
305 'admin/settings/integration/class',
306 ] );
307
308 // Register post types.
309 $post_types = [
310 // 'sellkit-analytics',
311 'sellkit-funnels',
312 ];
313
314 foreach ( $post_types as $post_type ) {
315 register_post_type( $post_type, [
316 'public' => false,
317 ] );
318 }
319
320 load_plugin_textdomain( 'sellkit', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
321 }
322
323 /**
324 * Enqueue editor scripts.
325 *
326 * @since 1.1.0
327 * @return void
328 */
329 public function enqueue_editor_script() {
330 wp_enqueue_script(
331 'sellkit-editor',
332 sellkit()->plugin_url() . 'assets/dist/js/editor.min.js',
333 [ 'jquery' ],
334 self::$version,
335 true
336 );
337 }
338
339 /**
340 * Enqueue admin scripts.
341 *
342 * @since 1.1.0
343 */
344 public function enqueue_admin_scripts() {
345 $page = ! empty( $_GET['page'] ) ? $_GET['page'] : ''; // phpcs:ignore
346
347 if ( ! in_array( $page, $this->sellkit_menus, true ) ) {
348 return false;
349 }
350
351 wp_enqueue_editor();
352
353 wp_enqueue_script(
354 'sellkit',
355 sellkit()->plugin_url() . 'assets/dist/admin/sellkit.js',
356 [ 'lodash', 'wp-element', 'wp-i18n', 'wp-util' ],
357 sellkit()->version(),
358 true
359 );
360
361 wp_localize_script(
362 'sellkit',
363 'sellkit',
364 $this->get_localize_data()
365 );
366
367 wp_enqueue_style(
368 'sellkit',
369 sellkit()->plugin_url() . 'assets/dist/admin/sellkit.css',
370 [],
371 sellkit()->version()
372 );
373
374 wp_set_script_translations( 'sellkit', 'sellkit', sellkit()->plugin_dir() . 'languages' );
375 }
376
377 /**
378 * Register admin menu.
379 *
380 * @since 1.1.0
381 * @SuppressWarnings(PHPMD.NPathComplexity)
382 */
383 public function register_admin_menu() {
384 $menu_name = esc_html__( 'Sellkit', 'sellkit' );
385 $initial_page = 'sellkit-dashboard';
386 $submenu = [
387 'sellkit-dashboard' => esc_html__( 'Dashboard', 'sellkit' ),
388 'sellkit-funnel' => esc_html__( 'Funnels', 'sellkit' ),
389 ];
390
391 $submenu = apply_filters( 'sellkit_sub_menu', $submenu );
392
393 $svg_file = wp_remote_get( self::plugin_url() . 'assets/img/icons/sellkit-dashboard.svg' );
394
395 add_menu_page(
396 $menu_name,
397 $menu_name,
398 'manage_options',
399 $initial_page,
400 [ $this, 'register_admin_menu_callback' ],
401 'data:image/svg+xml;base64,' . base64_encode( wp_remote_retrieve_body( $svg_file ) ),
402 '58.1'
403 );
404
405 foreach ( $submenu as $slug => $title ) {
406 add_submenu_page(
407 $initial_page,
408 "{$menu_name} {$title}",
409 $title,
410 'edit_theme_options',
411 $slug,
412 [ $this, 'register_admin_menu_callback' ]
413 );
414 }
415 }
416
417 /**
418 * Adds settings menu.
419 *
420 * @since 1.1.0
421 */
422 public function register_admin_settings_menu() {
423 add_submenu_page(
424 'sellkit-dashboard',
425 esc_html__( 'Sellkit', 'sellkit' ) . ' ' . esc_html__( 'Settings', 'sellkit' ),
426 esc_html__( 'Settings', 'sellkit' ),
427 'edit_theme_options',
428 'sellkit-settings',
429 [ $this, 'register_admin_menu_callback' ]
430 );
431 }
432
433 /**
434 * Register admin menu callback.
435 *
436 * @since 1.1.0
437 */
438 public function register_admin_menu_callback() {
439 ?>
440 <div id="wrap" class="wrap">
441 <!-- It's required for notices, otherwise WP adds the notices wherever it finds the first heading element. -->
442 <h1></h1>
443 <div id="sellkit-root"></div>
444 </div>
445 <?php
446 }
447
448 /**
449 * Check if in SellKit pages.
450 *
451 * @since 1.1.0
452 *
453 * @return boolean SellKit screen.
454 */
455 private function is_sellkit_screen() {
456 $page = sellkit_htmlspecialchars( INPUT_GET, 'page' );
457
458 return (
459 is_admin() &&
460 isset( $page ) &&
461 strpos( $page, 'sellkit' ) !== false
462 );
463 }
464
465 /**
466 * Get localize data.
467 *
468 * @since 1.1.0
469 *
470 * @return array
471 */
472 public function get_localize_data() {
473 return [
474 'nonce' => wp_create_nonce( 'sellkit' ),
475 'assetsUrl' => self::$plugin_assets_url,
476 'dynamicKeywords' => Sellkit_Dynamic_Keywords::$keywords['contact_segmentation'],
477 'defaultFunnelSteps' => Sellkit_Admin_Steps::get_default_funnel_steps(),
478 'woocommerceSettings' => $this->get_woocommerce_settings_data(),
479 'contactSegmentation' => [
480 'conditionsOperators' => Operators::$condition_operator_names,
481 'operators' => Operators::$names,
482 'conditionsData' => Conditions::$data,
483 'browserLanguages' => Conditions\Browser_Language::browser_languages_array(),
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