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 / includes / dynamic-keywords / class.php

class.php in SellKit – Funnel builder and checkout optimizer for WooCommerce to sell more, faster 1.1.4, at includes/dynamic-keywords/class.php

141 lines 2.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 defined( 'ABSPATH' ) || die();
4
5 /**
6 * Dynamic Keywords class.
7 *
8 * @since 1.1.0
9 */
10 class Sellkit_Dynamic_Keywords {
11
12 /**
13 * Class instance.
14 *
15 * @since 1.1.0
16 * @var Sellkit_Dynamic_Keywords
17 */
18 private static $instance = null;
19
20 /**
21 * Keywords.
22 *
23 * @var array
24 * @since 1.1.0
25 */
26 public static $keywords = [];
27
28 /**
29 * Get a class instance.
30 *
31 * @since 1.1.0
32 *
33 * @return Sellkit_Dynamic_Keywords Class
34 */
35 public static function get_instance() {
36 if ( is_null( self::$instance ) ) {
37 self::$instance = new self();
38 }
39
40 return self::$instance;
41 }
42
43 /**
44 * Class constructor.
45 *
46 * @since 1.1.0
47 */
48 public function __construct() {
49 $this->load_keywords();
50 $this->register_keywords();
51 }
52
53 /**
54 * Get keywords.
55 *
56 * @since 1.1.0
57 * @param string $keyword_id keyword id.
58 * @param string $keyword_title keyword title.
59 * @param string $type keyword type name.
60 */
61 public static function get_keywords( $keyword_id, $keyword_title, $type ) {
62 $keyword_id = 'sellkit' . str_replace( '_', '-', $keyword_id );
63
64 if ( 'order_keyword' === $type ) {
65 self::$keywords[ $type ][ $keyword_id ] = $keyword_title;
66
67 return;
68 }
69
70 self::$keywords[ $type ][ $keyword_id ] = $keyword_title;
71 }
72
73 /**
74 * Loads all of the keywords.
75 *
76 * @since 1.1.0
77 */
78 public function load_keywords() {
79 sellkit()->load_files( [
80 'dynamic-keywords/keywords/keyword-base',
81 'dynamic-keywords/contact-segmentation/contact-base',
82 ] );
83
84 $path = trailingslashit( sellkit()->plugin_dir() . 'includes/dynamic-keywords' );
85
86 $file_paths = glob( $path . '*/*.php' );
87
88 foreach ( $file_paths as $file_path ) {
89 if ( ! file_exists( $file_path ) ) {
90 continue;
91 }
92
93 require_once $file_path;
94
95 $file_name = str_replace( '.php', '', basename( $file_path ) );
96 $keyword_class = str_replace( '-', ' ', $file_name );
97 $keyword_class = str_replace( ' ', '_', ucwords( $keyword_class ) );
98
99 if ( ! class_exists( $keyword_class ) ) {
100 $keyword_class = "Sellkit\Dynamic_Keywords\Contact_Segmentation\\{$keyword_class}";
101 }
102
103 if (
104 ! class_exists( $keyword_class ) ||
105 ( 'keyword-base' === $file_name || 'contact-base' === $file_name )
106 ) {
107 continue;
108 }
109
110 $keyword = new $keyword_class();
111
112 $this->get_keywords( $keyword->get_id(), $keyword->get_title(), $keyword->get_keywords_type() );
113
114 $content = 'shortcode_content';
115
116 if ( 'contact_segmentation' === $keyword->get_keywords_type() ) {
117 $condition = $keyword->render_content();
118 }
119
120 if ( ! empty( $condition ) ) {
121 $content = 'render_content';
122 }
123
124 add_shortcode( "sellkit-{$file_name}", [ $keyword, $content ] );
125 }
126 }
127
128 /**
129 * Register keywords.
130 *
131 * @since 1.1.0
132 */
133 private function register_keywords() {
134 $keywords = self::$keywords;
135
136 return $keywords;
137 }
138 }
139
140 Sellkit_Dynamic_Keywords::get_instance();
141