PluginProbe ʕ •ᴥ•ʔ
Shortcodes and extra features for Phlox theme / 2.17.4
Shortcodes and extra features for Phlox theme v2.17.4
2.17.21 2.17.20 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.0.6 1.0.9 1.1.0 1.3.0 1.3.1 1.3.10 1.3.14 1.3.2 1.3.3 1.3.6 1.4.0 1.4.1 1.4.2 1.5.0 1.5.2 1.6.0 1.6.2 1.6.4 1.7.0 1.7.2 2.10.0 2.10.1 2.10.3 2.10.5 2.10.7 2.10.8 2.10.9 2.11.0 2.11.1 2.11.2 2.12.0 2.14.0 2.15.0 2.15.2 2.15.4 2.15.5 2.15.6 2.15.7 2.15.8 2.15.9 2.16.0 2.16.1 2.16.2 2.16.3 2.16.4 2.17.0 2.17.1 2.17.12 2.17.13 2.17.14 2.17.15 2.17.16 2.17.2 2.17.3 2.17.4 2.17.5 2.17.6 2.17.8 2.17.9 2.4.12 2.4.13 2.4.14 2.4.16 2.4.18 2.4.19 2.4.9 2.5.0 2.5.1 2.5.10 2.5.11 2.5.12 2.5.13 2.5.14 2.5.15 2.5.16 2.5.17 2.5.19 2.5.2 2.5.20 2.5.3 2.5.7 2.5.8 2.5.9 2.6.0 2.6.1 2.6.10 2.6.12 2.6.13 2.6.14 2.6.15 2.6.16 2.6.17 2.6.19 2.6.2 2.6.20 2.6.4 2.6.5 2.6.7 2.7.0 2.7.1 2.7.10 2.7.11 2.7.12 2.7.13 2.7.14 2.7.2 2.7.3 2.7.4 2.7.5 2.7.6 2.7.7 2.7.8 2.7.9 2.8.0 2.8.1 2.8.2 2.8.3 2.8.4 2.8.5 2.8.6 2.8.7 2.8.9 2.9.0 2.9.12 2.9.14 2.9.15 2.9.16 2.9.17 2.9.18 2.9.19 2.9.2 2.9.20 2.9.21 2.9.22 2.9.3 2.9.4 2.9.5 2.9.6 2.9.7 2.9.8
auxin-elements / includes / classes / class-auxin-widget-shortcode-map.php
auxin-elements / includes / classes Last commit date
class-auxels-admin-assets.php 1 year ago class-auxels-archive-menu-links.php 1 year ago class-auxels-envato-elements.php 1 year ago class-auxels-import-parser.php 3 years ago class-auxels-import.php 3 years ago class-auxels-search-post-type.php 1 year ago class-auxels-wc-attribute-nav-menu.php 1 year ago class-auxin-admin-dashboard.php 1 year ago class-auxin-demo-importer.php 1 year ago class-auxin-dependency-sorting.php 3 years ago class-auxin-import.php 1 year ago class-auxin-install.php 1 year ago class-auxin-master-nav-menu-admin.php 1 year ago class-auxin-page-template.php 1 year ago class-auxin-permalink.php 1 year ago class-auxin-plugin-requirements.php 3 years ago class-auxin-post-type-base.php 1 year ago class-auxin-svg-support-allowedattributes.php 7 years ago class-auxin-svg-support-allowedtags.php 7 years ago class-auxin-svg-support.php 1 year ago class-auxin-walker-nav-menu-back.php 1 year ago class-auxin-welcome-sections.php 1 year ago class-auxin-welcome.php 1 year ago class-auxin-whitelabel.php 3 years ago class-auxin-widget-indie.php 1 year ago class-auxin-widget-shortcode-map.php 1 year ago class-auxin-widget.php 1 year ago
class-auxin-widget-shortcode-map.php
267 lines
1 <?php
2 /**
3 * Adds Theme Widgets (elements), shortcodes and visual elements
4 *
5 *
6 * @package Auxin
7 * @license LICENSE.txt
8 * @author averta
9 * @link http://phlox.pro/
10 * @copyright (c) 2010-2025 averta
11 */
12
13 // no direct access allowed
14 if ( ! defined('ABSPATH') ) exit;
15
16
17
18
19 class Auxin_Widget_Shortcode_Map {
20
21 /**
22 * Instance of this class.
23 *
24 * @var object
25 */
26 protected static $instance = null;
27
28 /**
29 * The Master list of all shortcodes and widgets
30 *
31 * @var array
32 */
33 private $master_array = array();
34
35 /**
36 * The Master list of all shortcodes
37 *
38 * @var array
39 */
40 public $master_shortcode_array = array();
41
42
43
44 public function __construct(){
45 add_action('auxin_loaded', array( $this, 'auxin_framework_loaded' ) );
46 }
47
48
49
50 public function auxin_framework_loaded(){
51
52 add_action( 'widgets_init' , array( $this, 'add_widgets' ) );
53
54 // map and add all shortcodes
55 $this->add_shortcodes();
56 }
57
58
59
60 /**
61 * Collects and stores elements info
62 */
63 public function get_master_array(){
64
65 if( empty( $this->master_array ) ){
66
67 $master_array = apply_filters( 'auxin_master_array_shortcodes', array() );
68
69 foreach ( $master_array as $element_id => $element_info ) {
70 // determines whether the widget should be generated or not
71 $element_info['is_widget'] = isset( $element_info['is_widget'] ) && $element_info['is_widget'] === false ? false : true;
72 // determines whether the shortcode should be added or not
73 $element_info['is_shortcode'] = isset( $element_info['is_shortcode'] ) && $element_info['is_shortcode'] === false ? false : true;
74
75 // make sure icon is set
76 $element_info['icon'] = isset( $element_info['icon'] ) && ! empty( $element_info['icon'] ) ? $element_info['icon'] : 'dashicons dashicons-admin-generic';
77
78 // make sure key in master array is base name of elements, in this case we can find elements in this array faster
79 $this->master_array[ $element_info['base'] ] = $element_info;
80 }
81 }
82
83 return $this->master_array;
84 }
85
86 /**
87 * Register all allowed widgets
88 */
89 public function add_widgets() {
90
91 $master_array = $this->get_master_array();
92
93 foreach ( $master_array as $element_id => $element_info ) {
94
95 // Add a widget if it was allowed
96 if( $element_info['is_widget'] ) {
97 $widget_info = $this->generate_widget_array( $element_info );
98 global $wp_widget_factory;
99 $wp_widget_factory->widgets[ $element_info['base'] ] = new Auxin_Widget( $widget_info );
100 }
101
102 }
103 }
104
105
106 /**
107 * Adds all collected shortcodes
108 */
109 private function add_shortcodes() {
110
111 $shortcode_array_list = $this->get_master_shortcode_array();
112
113 foreach ( $shortcode_array_list as $shortcode_index => $shortcode_array ) {
114 add_shortcode( $shortcode_array['base'], $shortcode_array['auxin_output_callback'] );
115 }
116 }
117
118 protected function remove_empty_nodes_recuresively( $array ){
119 $cleared_array = array();
120
121 foreach( $array as $key => $node ) {
122 if( is_array( $node ) ){
123 $cleared_array[ $key ] = $this->remove_empty_nodes_recuresively( $node );
124 } elseif ( ! empty( $node ) || $node === false ){
125 $cleared_array[ $key ] = $array[ $key ];
126 }
127 }
128
129 return $cleared_array;
130 }
131
132
133 /**
134 * Get list of allowed shortcodes
135 */
136 public function get_master_shortcode_array(){
137 $this->get_master_array();
138
139 if( empty( $this->master_shortcode_array ) ){
140 foreach ( $this->master_array as $element_id => $element_info ) {
141 // Collect the shortcode if it was allowed
142 if( $element_info['is_shortcode'] ){
143 $this->master_shortcode_array[] = $this->generate_shortcode_array( $element_info );
144 }
145 }
146 }
147
148 return $this->master_shortcode_array;
149 }
150
151
152 /**
153 * Sanitize and proper
154 *
155 * @param [type] $element_info [description]
156 * @return [type] [description]
157 */
158 protected function sanitize_element_info( $element_info ){
159
160 }
161
162
163 /**
164 * Generates shortcode info
165 */
166 protected function generate_shortcode_array( $element_info ){
167
168 $shortcode_array['base'] = $element_info['base'];
169 $shortcode_array['is_shortcode'] = $element_info['is_shortcode'];
170
171 $shortcode_array['auxin_output_callback'] = $element_info['auxin_output_callback'];
172
173 foreach ( $element_info['params'] as $param_id => $param ) {
174 if( isset( $param['def_value'] ) ){
175 $shortcode_array['params'][ $param['param_name'] ] = $param['def_value'];
176 } else {
177 $shortcode_array['params'][ $param['param_name'] ] = '';
178 }
179 }
180
181 return $shortcode_array;
182 }
183
184
185 /**
186 * Generates widget info
187 */
188 protected function generate_widget_array( $element_info ){
189 $widget_array = array();
190
191 $widget_array['base_ID'] = $element_info['base'];
192 $widget_array['name'] = $element_info['name'];
193 $widget_array['is_widget'] = $element_info['is_widget'];
194
195 /**
196 * This filter makes the others able to override element output function
197 */
198 $widget_array['auxin_output_callback'] = apply_filters( 'auxin_element_output_callback', $element_info['auxin_output_callback'], 'widget' );
199 $widget_array['args']['description'] = $element_info['description'];
200 $widget_array['args']['panels_groups'] = array('auxin');
201
202 if( ! empty( $element_info['icon'] ) ) {
203 $widget_array['args']['panels_icon'] = $element_info['icon'];
204 }
205
206 foreach ( $element_info['params'] as $param_id => $param ) {
207 $widget_params = array();
208
209 $widget_params['name'] = $param['heading'];
210 $widget_params['id'] = $param['param_name'];
211 $widget_params['type'] = $param['type'];
212
213 if( !empty( $param['std'] ) ) {
214 $widget_params['value'] = $param['std'];
215 }
216 elseif( !empty( $param['def_value'] ) ) {
217 $widget_params['value'] = $param['def_value'];
218 }
219 elseif( 1 ) {
220 $widget_params['value'] = isset( $param['value'] ) ? $param['value'] : '';
221 }
222 if( $widget_params['type'] == 'aux_visual_select' ) {
223 $widget_params['choices'] = $param['choices'];
224 }
225 if( isset( $param['description'] ) ) {
226 $widget_params['description'] = $param['description'];
227 }
228 if( isset( $param['dependency'] ) ) {
229 $widget_params['dependency'] = $param['dependency'];
230 }
231 // special param for aux_taxonomy field type
232 if( isset( $param['taxonomy'] ) ) {
233 $widget_params['taxonomy'] = $param['taxonomy'];
234 }
235 // TODO: It shoould convert to array an array when dependency js writes
236 // $widget_params['dependency'] = array( $param['dependency'] );
237
238 if( in_array( $param['type'], array( 'select', 'dropdown', 'aux_select2_multiple', 'aux_select2_single' ) ) ) {
239 $widget_params['options'] = $param['value'];
240 }
241
242 // lets set a key for each param, for improving search in array
243 $widget_array['params'][ $widget_params['id'] ] = $widget_params;
244 }
245
246 return $widget_array;
247 }
248
249
250 /**
251 * Return an instance of this class.
252 *
253 * @return object A single instance of this class.
254 */
255 public static function get_instance() {
256
257 // If the single instance hasn't been set, set it now.
258 if ( null == self::$instance ) {
259 self::$instance = new self;
260 }
261
262 return self::$instance;
263 }
264
265 }
266
267