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

658 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.5.7
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 add_action( 'requests-curl.before_request', [ $this, 'actions_before_curl_requests' ], 9999 );
181
182 // Register activation hook.
183 register_activation_hook( __FILE__, array( $this, 'activation' ) );
184
185 if ( ! $this->is_sellkit_screen() ) {
186 return;
187 }
188
189 add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_admin_scripts' ] );
190 add_action( 'admin_head', [ $this, 'remove_notice_for_sellkit_pages' ] );
191 add_filter( 'admin_body_class', [ $this, 'sellkit_admin_body_class' ] );
192 }
193
194 /**
195 * Actions before all curl requests.
196 *
197 * @since 1.5.4
198 * @return void
199 */
200 public function actions_before_curl_requests() {
201 session_write_close();
202 }
203
204 /**
205 * Has sellKit pro.
206 *
207 * @since 1.1.0
208 */
209 public function check_if_has_sellkit_pro() {
210 if ( class_exists( 'Sellkit_Pro' ) ) {
211 $this->has_pro = true;
212 }
213 }
214
215 /**
216 * Defines constants used by the plugin.
217 *
218 * @since 1.1.0
219 */
220 protected function define_constants() {
221 $plugin_data = get_file_data( __FILE__, array( 'Plugin Name', 'Version' ), 'sellkit' );
222
223 self::$plugin_basename = plugin_basename( __FILE__ );
224 self::$plugin_name = array_shift( $plugin_data );
225 self::$version = array_shift( $plugin_data );
226 self::$plugin_dir = trailingslashit( plugin_dir_path( __FILE__ ) );
227 self::$plugin_url = trailingslashit( plugin_dir_url( __FILE__ ) );
228 self::$plugin_assets_url = trailingslashit( self::$plugin_url . 'assets' );
229 }
230
231 /**
232 * Plugins loaded.
233 *
234 * @since 1.1.0
235 */
236 public function plugins_loaded() {
237 $this->load_files( [
238 'elementor/class',
239 'admin/class-promote-sellkit-pro',
240 ] );
241 }
242
243 /**
244 * Do some stuff on plugin activation.
245 *
246 * @since NEXT
247 * @return void
248 */
249 public function activation() {
250 $this->load_files( [
251 'core/libraries/wp-async-request',
252 'core/libraries/wp-background-process',
253 'core/install',
254 ] );
255
256 Install::check_database_tables();
257
258 if ( empty( sellkit_get_option( 'current_db_version' ) ) ) {
259 sellkit_update_option( 'current_db_version', '1.2.7' ); // @since 1.5.0
260 }
261
262 if ( ! wp_next_scheduled( 'sellkit_update_rfm_score' ) ) {
263 wp_schedule_event( time(), 'twicedaily', 'sellkit_update_rfm_score' );
264 }
265 }
266
267 /**
268 * Adding sellkit class to body.
269 *
270 * @param string $classes Sellkit the sellkit class.
271 * @return string
272 */
273 public function sellkit_admin_body_class( $classes ) {
274 return "{$classes} sellkit";
275 }
276
277 /**
278 * Initialize admin.
279 *
280 * @since 1.1.0
281 */
282 public function admin_init() {
283 $this->load_files( [
284 'admin/class-notices',
285 'admin/class',
286 ] );
287
288 $this->load_files( [
289 'admin/utilities',
290 'admin/class-components',
291 'admin/components/class-list-table',
292 'admin/components/class-filters',
293 'admin/components/class-analytics',
294 'admin/class-posts',
295 'admin/settings/class-settings',
296 'admin/class-custom-tables',
297 'admin/funnel/class',
298 'core/install',
299 ] );
300 }
301
302 /**
303 * Initialize.
304 *
305 * @since 1.1.0
306 */
307 public function init() {
308 $this->load_files( [
309 'admin/class-steps',
310 'utilities/functions',
311 'contact-segmentation/class',
312 'dynamic-keywords/class',
313 'core/libraries/wp-async-request',
314 'core/libraries/wp-background-process',
315 'settings/class',
316 'contact-segmentation/rfm/class',
317 'admin/settings/integration/class',
318 ] );
319
320 // Register post types.
321 $post_types = [
322 // 'sellkit-analytics',
323 'sellkit-funnels',
324 ];
325
326 foreach ( $post_types as $post_type ) {
327 register_post_type( $post_type, [
328 'public' => false,
329 ] );
330 }
331
332 load_plugin_textdomain( 'sellkit', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
333 }
334
335 /**
336 * Enqueue editor scripts.
337 *
338 * @since 1.1.0
339 * @return void
340 */
341 public function enqueue_editor_script() {
342 wp_enqueue_script(
343 'sellkit-editor',
344 sellkit()->plugin_url() . 'assets/dist/js/editor.min.js',
345 [ 'jquery' ],
346 self::$version,
347 true
348 );
349 }
350
351 /**
352 * Enqueue admin scripts.
353 *
354 * @since 1.1.0
355 */
356 public function enqueue_admin_scripts() {
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
389 /**
390 * Register admin menu.
391 *
392 * @since 1.1.0
393 * @SuppressWarnings(PHPMD.NPathComplexity)
394 */
395 public function register_admin_menu() {
396 $menu_name = esc_html__( 'Sellkit', 'sellkit' );
397 $initial_page = 'sellkit-dashboard';
398 $submenu = [
399 'sellkit-dashboard' => esc_html__( 'Dashboard', 'sellkit' ),
400 'sellkit-funnel' => esc_html__( 'Funnels', 'sellkit' ),
401 ];
402
403 $submenu = apply_filters( 'sellkit_sub_menu', $submenu );
404
405 $svg_file = wp_remote_get( self::plugin_url() . 'assets/img/icons/sellkit-dashboard.svg' );
406
407 add_menu_page(
408 $menu_name,
409 $menu_name,
410 'manage_options',
411 $initial_page,
412 [ $this, 'register_admin_menu_callback' ],
413 'data:image/svg+xml;base64,' . base64_encode( wp_remote_retrieve_body( $svg_file ) ),
414 '58.1'
415 );
416
417 foreach ( $submenu as $slug => $title ) {
418 add_submenu_page(
419 $initial_page,
420 "{$menu_name} {$title}",
421 $title,
422 'edit_theme_options',
423 $slug,
424 [ $this, 'register_admin_menu_callback' ]
425 );
426 }
427 }
428
429 /**
430 * Adds settings menu.
431 *
432 * @since 1.1.0
433 */
434 public function register_admin_settings_menu() {
435 add_submenu_page(
436 'sellkit-dashboard',
437 esc_html__( 'Sellkit', 'sellkit' ) . ' ' . esc_html__( 'Settings', 'sellkit' ),
438 esc_html__( 'Settings', 'sellkit' ),
439 'edit_theme_options',
440 'sellkit-settings',
441 [ $this, 'register_admin_menu_callback' ]
442 );
443 }
444
445 /**
446 * Register admin menu callback.
447 *
448 * @since 1.1.0
449 */
450 public function register_admin_menu_callback() {
451 ?>
452 <div id="wrap" class="wrap">
453 <!-- It's required for notices, otherwise WP adds the notices wherever it finds the first heading element. -->
454 <h1></h1>
455 <div id="sellkit-root"></div>
456 </div>
457 <?php
458 }
459
460 /**
461 * Check if in SellKit pages.
462 *
463 * @since 1.1.0
464 *
465 * @return boolean SellKit screen.
466 */
467 private function is_sellkit_screen() {
468 $page = sellkit_htmlspecialchars( INPUT_GET, 'page' );
469
470 return (
471 is_admin() &&
472 isset( $page ) &&
473 strpos( $page, 'sellkit' ) !== false
474 );
475 }
476
477 /**
478 * Get localize data.
479 *
480 * @since 1.1.0
481 *
482 * @return array
483 */
484 public function get_localize_data() {
485 return [
486 'nonce' => wp_create_nonce( 'sellkit' ),
487 'assetsUrl' => self::$plugin_assets_url,
488 'dynamicKeywords' => Sellkit_Dynamic_Keywords::$keywords['contact_segmentation'],
489 'defaultFunnelSteps' => Sellkit_Admin_Steps::get_default_funnel_steps(),
490 'woocommerceSettings' => $this->get_woocommerce_settings_data(),
491 'contactSegmentation' => [
492 'conditionsOperators' => Operators::$condition_operator_names,
493 'operators' => Operators::$names,
494 'conditionsData' => Conditions::$data,
495 'browserLanguages' => Conditions\Browser_Language::browser_languages_array(),
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 'wcIsActivated' => $this->has_valid_dependencies(),
508 ];
509 }
510
511 /**
512 * Get woocommerce settings data.
513 *
514 * @since 1.1.0
515 *
516 * @return array|boolean
517 */
518 public function get_woocommerce_settings_data() {
519 if ( ! class_exists( 'WooCommerce' ) ) {
520 return false;
521 }
522
523 return [
524 'currencyFormatNumDecimals' => wc_get_price_decimals(),
525 'currencySymbol' => html_entity_decode( get_woocommerce_currency_symbol() ),
526 'currencyFormatDecimalSep' => wc_get_price_decimal_separator(),
527 'currencyFormatThousandSep' => wc_get_price_thousand_separator(),
528 'currencyPosition' => get_option( 'woocommerce_currency_pos' ),
529 'productDefaultThumbnail' => wc_placeholder_img_src(),
530 ];
531 }
532
533 /**
534 * Remove notices.
535 *
536 * @since 1.1.0
537 */
538 public function remove_notice_for_sellkit_pages() {
539 remove_all_actions( 'admin_notices' );
540 }
541
542 /**
543 * Sellkit dependencies.
544 *
545 * @since 1.1.0
546 */
547 public function has_valid_dependencies() {
548 if ( ! class_exists( 'woocommerce' ) ) {
549 return false;
550 }
551
552 return true;
553 }
554
555 /**
556 * Loads specified PHP files from the plugin includes directory.
557 *
558 * @since 1.1.0
559 *
560 * @param array $file_names The names of the files to be loaded in the includes directory.
561 */
562 public function load_files( $file_names = array() ) {
563
564 foreach ( $file_names as $file_name ) {
565 $path = self::plugin_dir() . 'includes/' . $file_name . '.php';
566
567 if ( file_exists( $path ) ) {
568 require_once $path;
569 }
570 }
571 }
572
573 /**
574 * Returns the version number of the plugin.
575 *
576 * @since 1.1.0
577 *
578 * @return string
579 */
580 public function version() {
581 return self::$version;
582 }
583
584 /**
585 * Returns the plugin basename.
586 *
587 * @since 1.1.0
588 *
589 * @return string
590 */
591 public function plugin_basename() {
592 return self::$plugin_basename;
593 }
594
595 /**
596 * Returns the plugin name.
597 *
598 * @since 1.1.0
599 *
600 * @return string
601 */
602 public function plugin_name() {
603 return self::$plugin_name;
604 }
605
606 /**
607 * Returns the plugin directory.
608 *
609 * @since 1.1.0
610 *
611 * @return string
612 */
613 public function plugin_dir() {
614 return self::$plugin_dir;
615 }
616
617 /**
618 * Returns the plugin URL.
619 *
620 * @since 1.1.0
621 *
622 * @return string
623 */
624 public function plugin_url() {
625 return self::$plugin_url;
626 }
627
628 /**
629 * Returns the plugin assets URL.
630 *
631 * @since 1.1.0
632 *
633 * @return string
634 */
635 public function plugin_assets_url() {
636 return self::$plugin_assets_url;
637 }
638 }
639 }
640
641 if ( ! function_exists( 'sellkit' ) ) {
642 /**
643 * Initialize the Sellkit.
644 *
645 * @since 1.1.0
646 */
647 function sellkit() {
648 return Sellkit::get_instance();
649 }
650 }
651
652 /**
653 * Initialize the Sellkit application.
654 *
655 * @since 1.1.0
656 */
657 sellkit();
658