PluginProbe ʕ •ᴥ•ʔ
ElementsKit Elementor Addons – Advanced Widgets & Templates Addons for Elementor / 4.0.1
ElementsKit Elementor Addons – Advanced Widgets & Templates Addons for Elementor v4.0.1
4.0.2 4.0.1 4.0.0 3.10.02 3.10.01 3.9.10 3.9.9 3.9.8 3.9.7 3.9.5 3.9.6 3.9.3 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.3.0 2.3.1 2.3.1.1 2.3.2 2.3.3 2.3.4 2.3.5 2.3.6 2.3.7 2.4.0 2.5.0 2.5.1 2.5.10 2.5.2 2.5.3 2.5.4 2.5.5 2.5.6 2.5.7 2.5.8 2.5.9 2.6.0 2.6.1 2.6.2 2.6.3 2.7.0 2.7.2 2.7.3 2.7.4 2.7.5 2.8.0 2.8.1 2.8.5 2.8.6 2.8.7 2.8.8 2.9.0 2.9.1 2.9.2 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.1.0 3.1.1 3.1.2 3.1.3 3.1.4 3.2.0 3.2.1 3.2.2 3.2.3 3.2.4 3.2.5 3.2.6 3.2.7 3.2.8 3.2.9 3.3.0 3.3.1 3.3.2 3.3.3 3.3.4 3.3.5 3.3.6 3.3.7 3.3.8 3.3.9 3.4.0 3.4.1 3.4.2 3.4.3 3.4.4 3.4.5 3.4.6 3.4.7 3.4.8 3.4.9 3.5.0 3.5.1 3.5.2 3.5.3 3.5.4 3.5.5 3.5.6 3.6.0 3.6.1 3.7.0 3.7.1 3.7.2 3.7.3 3.7.4 3.7.5 3.7.6 3.7.7 3.7.8 3.7.9 3.8.0 3.8.1 3.8.2 3.9.0 3.9.1 3.9.2 trunk 1.2.6 1.2.7 1.2.9 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.8 1.3.9 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.7 1.4.8 1.4.9 1.5.0 1.5.1 1.5.10 1.5.11 1.5.12 1.5.2 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.5.9 2.0.0 2.0.1 2.0.10 2.0.11 2.0.12 2.0.13 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.0.8 2.0.9 2.0.9.1 2.0.9.2 2.0.9.3
elementskit-lite / modules / elementskit-icon-pack / init.php
elementskit-lite / modules / elementskit-icon-pack Last commit date
assets 3 weeks ago icon-list.php 3 weeks ago icons.php 2 years ago init.php 4 months ago
init.php
194 lines
1 <?php
2 namespace ElementsKit_Lite\Modules\ElementsKit_Icon_Pack;
3
4 defined('ABSPATH') || exit;
5
6 class Init {
7 public static function get_url() {
8 return \ElementsKit_Lite::module_url() . 'elementskit-icon-pack/';
9 }
10
11 public static function get_dir() {
12 return \ElementsKit_Lite::module_dir() . 'elementskit-icon-pack/';
13 }
14
15 public function __construct() {
16 add_action( 'admin_enqueue_scripts', [$this, 'enqueue_admin_icon_css'] );
17
18 if (!self::is_svg_icon_experiment()) {
19 add_action('elementor/frontend/before_enqueue_scripts', array($this, 'enqueue_frontend'));
20 }
21
22 add_action('elementor/preview/enqueue_styles', array($this, 'enqueue_frontend'));
23 add_filter('elementor/icons_manager/additional_tabs', array($this, 'register_icon_pack_to_elementor'));
24 add_filter('elementor/widget/render_content', array($this, 'filter_widget_content'), 10, 2);
25 }
26
27 // Enqueue admin CSS for widget icons
28 public function enqueue_admin_icon_css( $hook ) {
29 if ( $hook !== 'elementor_page_elementor-element-manager' ) {
30 return;
31 }
32
33 wp_enqueue_style( 'widget-icons', \ElementsKit_Lite::widget_url() . 'init/assets/css/editor.css', [], \ElementsKit_Lite::version() );
34
35 // Inline CSS to adjust icon display in Elementor's Element Manager
36 $css = 'td .ekit-widget-icon{max-width:13px;overflow:hidden;min-height:auto;font-size:inherit;}td .ekit-widget-icon:after{display:none}';
37 wp_add_inline_style( 'widget-icons', $css );
38 }
39
40 public function enqueue_frontend() {
41 wp_enqueue_style( 'elementor-icons-ekiticons', self::get_url() . 'assets/css/ekiticons.css', array(), \ElementsKit_Lite::version() );
42 }
43
44 public function register_icon_pack_to_elementor($font) {
45 $font_new['ekiticons'] = array(
46 'name' => 'ekiticons',
47 'label' => esc_html__('ElementsKit Icon Pack', 'elementskit-lite'),
48 'prefix' => 'icon-',
49 'displayPrefix' => 'icon',
50 'labelIcon' => 'icon icon-ekit',
51 'ver' => \ElementsKit_Lite::version(),
52 'fetchJson' => self::get_url() . 'assets/js/ekiticons.json',
53 'native' => true,
54 );
55
56 if (!self::is_svg_icon_experiment()) {
57 $font_new['ekiticons']['url'] = self::get_url() . 'assets/css/ekiticons.css';
58 } else {
59 $font_new['ekiticons']['enqueue'] = [self::get_url() . 'assets/css/ekiticons.css'];
60 }
61
62 return array_merge($font, $font_new);
63 }
64
65 public function filter_widget_content($widget_content, $widget) {
66 // Check if it's in Elementor editor
67 if ( \Elementor\Plugin::$instance->editor->is_edit_mode() ) {
68 return $widget_content; // return normal content
69 }
70
71 $ekit_svg_icon = self::is_svg_icon_experiment();
72
73 // Match all <i> tags with class containing "icon icon-"
74 if ($ekit_svg_icon && strpos($widget_content, 'icon icon-') !== false) {
75 $widget_content = self::replace_icon_tags($widget_content);
76 }
77
78 return $widget_content;
79 }
80
81 public static function is_svg_icon_experiment() {
82 $elementskit_options = get_option( 'elementskit_options' );
83 $inline_svg = $elementskit_options['user_data']['inline_svg']['is_enable'] ?? false;
84 return apply_filters( 'elementskit_font_icon_inline_svg', $inline_svg );
85 }
86
87 public static function replace_icon_tags( string $widget_content ): string {
88 return preg_replace_callback(
89 '/<i[^>]*class="([^"]*)"[^>]*><\/i>/',
90 function ( array $matches ): string {
91 $original_tag = $matches[0];
92 $class_string = $matches[1];
93
94 // Bail early if this is not an ElementsKit icon tag
95 if ( strpos( $class_string, 'icon icon-' ) === false ) {
96 return $original_tag;
97 }
98
99 // Extract the icon name e.g. "icon icon-down-arrow1" → "down-arrow1"
100 preg_match( '/icon icon-([^\s"]+)/', $class_string, $icon_matches );
101 $icon_name = $icon_matches[1] ?? '';
102
103 // Generate the ElementsKit icon HTML
104 $icon_html = self::get_icon_html( [
105 'library' => 'ekiticons',
106 'value' => 'icon icon-' . $icon_name,
107 ] );
108
109 if ( empty( $icon_html ) ) {
110 return $original_tag;
111 }
112
113 // Strip the "icon icon-{name}" segment to get any remaining classes
114 $extra_classes = trim( preg_replace( '/\s*icon icon-[^\s"]+\s*/', ' ', $class_string ) );
115
116 // Prepend extra classes to the generated icon HTML if any exist
117 if ( ! empty( $extra_classes ) ) {
118 $icon_html = str_replace( 'class="', 'class="' . $extra_classes . ' ', $icon_html );
119 }
120
121 return $icon_html;
122 },
123 $widget_content
124 );
125 }
126
127 public static function get_svg_icon($icon, $attributes = []) {
128 // go for ekit svg icon
129 $file = \ElementsKit_Lite::module_dir() . 'elementskit-icon-pack/' . 'assets/json/icons.json';
130 $get_file_content = \Elementor\Utils::file_get_contents($file);
131
132 // check condition for svg icon
133 if (!$get_file_content) {
134 return '';
135 }
136
137 $icons = json_decode($get_file_content, true);
138 $icon_name = str_replace('icon icon-', '', $icon['value']);
139 $svg = isset($icons[$icon_name]) ? $icons[$icon_name] : false;
140
141 if ( empty($svg['paths']) ) {
142 return '';
143 }
144
145 $attributes['class'][] = 'ekit-svg-icon';
146 $attributes['class'][] = sprintf('icon-%s', $icon_name);
147 $attributes['viewBox'] = $svg['viewBox'];
148 $attributes['xmlns'] = 'http://www.w3.org/2000/svg';
149
150 $svg_html = sprintf('<svg %s>', \Elementor\Utils::render_html_attributes($attributes));
151
152 foreach ($svg['paths'] as $path) {
153 $svg_html .= sprintf('<path d="%s"></path>', esc_attr($path));
154 }
155
156 $svg_html .= '</svg>';
157
158 return $svg_html;
159 }
160
161 public static function get_icon_html($icon, $attributes = [], $tag = 'i') {
162 if ( empty( $icon['library'] ) ) {
163 return '';
164 }
165
166 if ( 'ekiticons' === $icon['library'] && self::is_svg_icon_experiment() ) {
167 $content = self::get_svg_icon($icon, $attributes);
168
169 if ( ! empty( $content ) ) {
170 return $content;
171 }
172 } else {
173 return \Elementor\Icons_Manager::try_get_icon_html($icon, $attributes, $tag);
174 }
175 }
176
177 public static function icon($icon, $attributes = [], $tag = 'i') {
178 if ( empty( $icon['library'] ) ) {
179 return '';
180 }
181
182 if ( 'ekiticons' === $icon['library'] && self::is_svg_icon_experiment() ) {
183 $content = self::get_svg_icon($icon, $attributes);
184
185 if ( ! empty( $content ) ) {
186 \Elementor\Utils::print_unescaped_internal_string($content);
187 return true;
188 }
189 } else {
190 \Elementor\Icons_Manager::render_icon($icon, $attributes, $tag);
191 }
192 }
193 }
194