PluginProbe
SellKit – Funnel builder and checkout optimizer for WooCommerce to sell more, faster / trunk
SellKit – Funnel builder and checkout optimizer for WooCommerce to sell more, faster vtrunk
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 / includes / dynamic-keywords / class.php

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

119 lines 2.4 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 }
51
52 /**
53 * Get keywords.
54 *
55 * @since 1.1.0
56 * @param string $keyword_id keyword id.
57 * @param string $keyword_title keyword title.
58 * @param string $type keyword type name.
59 */
60 public static function get_keywords( $keyword_id, $keyword_title, $type ) {
61 $keyword_id = 'sellkit' . str_replace( '_', '-', $keyword_id );
62
63 if ( 'order_keyword' === $type ) {
64 self::$keywords[ $type ][ $keyword_id ] = $keyword_title;
65
66 return;
67 }
68
69 self::$keywords[ $type ][ $keyword_id ] = $keyword_title;
70 }
71
72 /**
73 * Loads all of the keywords.
74 *
75 * @since 1.1.0
76 */
77 public function load_keywords() {
78 sellkit()->load_files( [
79 'dynamic-keywords/keywords/keyword-base',
80 'dynamic-keywords/contact-segmentation/contact-base',
81 ] );
82
83 $path = trailingslashit( sellkit()->plugin_dir() . 'includes/dynamic-keywords' );
84
85 $file_paths = glob( $path . '*/*.php' );
86
87 foreach ( $file_paths as $file_path ) {
88 if ( ! file_exists( $file_path ) ) {
89 continue;
90 }
91
92 require_once $file_path;
93
94 $file_name = str_replace( '.php', '', basename( $file_path ) );
95 $keyword_class = str_replace( '-', ' ', $file_name );
96 $keyword_class = str_replace( ' ', '_', ucwords( $keyword_class ) );
97
98 if ( ! class_exists( $keyword_class ) ) {
99 $keyword_class = "Sellkit\Dynamic_Keywords\Contact_Segmentation\\{$keyword_class}";
100 }
101
102 if (
103 ! class_exists( $keyword_class ) ||
104 ( 'keyword-base' === $file_name || 'contact-base' === $file_name )
105 ) {
106 continue;
107 }
108
109 $keyword = new $keyword_class();
110
111 $this->get_keywords( $keyword->get_id(), $keyword->get_title(), $keyword->get_keywords_type() );
112
113 add_shortcode( "sellkit-{$file_name}", [ $keyword, 'render_content' ] );
114 }
115 }
116 }
117
118 Sellkit_Dynamic_Keywords::get_instance();
119