PluginProbe
Adminify – White Label, Admin Menu Editor, Login Customizer / 4.1.3
Adminify – White Label, Admin Menu Editor, Login Customizer v4.1.3
4.3.1 4.3.0 4.2.26 4.2.25 4.2.24 4.2.23 4.2.22 4.2.21 4.2.20 4.2.19 4.2.18 4.2.17 4.2.16 4.2.15 4.2.14 4.2.13 4.2.12 4.2.11 4.2.10 4.2.9 4.2.8 4.2.7 4.2.6 4.2.5 4.1.17 All 164 releases
adminify / Libs / adminify-framework / classes / shortcode-options.class.php

shortcode-options.class.php in Adminify – White Label, Admin Menu Editor, Login Customizer 4.1.3, at Libs/adminify-framework/classes/shortcode-options.class.php

303 lines 11.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php if ( ! defined( 'ABSPATH' ) ) { die; } // Cannot access directly.
2 /**
3 *
4 * Shortcoder Class
5 *
6 * @since 1.0.0
7 * @version 1.0.0
8 *
9 */
10 if ( ! class_exists( 'ADMINIFY_Shortcoder' ) ) {
11 class ADMINIFY_Shortcoder extends ADMINIFY_Abstract{
12
13 // constans
14 public $unique = '';
15 public $abstract = 'shortcoder';
16 public $blocks = array();
17 public $sections = array();
18 public $pre_tabs = array();
19 public $pre_sections = array();
20 public $args = array(
21 'button_title' => 'Add Shortcode',
22 'select_title' => 'Select a shortcode',
23 'insert_title' => 'Insert Shortcode',
24 'show_in_editor' => true,
25 'show_in_custom' => false,
26 'defaults' => array(),
27 'class' => '',
28 'gutenberg' => array(
29 'title' => 'ADMINIFY Shortcodes',
30 'description' => 'ADMINIFY Shortcode Block',
31 'icon' => 'screenoptions',
32 'category' => 'widgets',
33 'keywords' => array( 'shortcode', 'adminify', 'insert' ),
34 'placeholder' => 'Write shortcode here...',
35 ),
36 );
37
38 // run shortcode construct
39 public function __construct( $key, $params = array() ) {
40
41 $this->unique = $key;
42 $this->args = apply_filters( "adminify_{$this->unique}_args", wp_parse_args( $params['args'], $this->args ), $this );
43 $this->sections = apply_filters( "adminify_{$this->unique}_sections", $params['sections'], $this );
44 $this->pre_tabs = $this->pre_tabs( $this->sections );
45 $this->pre_sections = $this->pre_sections( $this->sections );
46
47 add_action( 'admin_footer', array( $this, 'add_footer_modal_shortcode' ) );
48 add_action( 'customize_controls_print_footer_scripts', array( $this, 'add_footer_modal_shortcode' ) );
49 add_action( 'wp_ajax_adminify-get-shortcode-'. $this->unique, array( $this, 'get_shortcode' ) );
50
51 if ( ! empty( $this->args['show_in_editor'] ) ) {
52
53 $name = str_replace( '_', '-', sanitize_title( $this->unique ) );
54
55 ADMINIFY::$shortcode_instances[] = wp_parse_args( array( 'name' => 'adminify/'. $name, 'modal_id' => $this->unique ), $this->args );
56
57 // elementor editor support
58 if ( ADMINIFY::is_active_plugin( 'elementor/elementor.php' ) ) {
59 add_action( 'elementor/editor/before_enqueue_scripts', array( 'ADMINIFY', 'add_admin_enqueue_scripts' ) );
60 add_action( 'elementor/editor/footer', array( 'ADMINIFY_Field_icon', 'add_footer_modal_icon' ) );
61 add_action( 'elementor/editor/footer', array( $this, 'add_footer_modal_shortcode' ) );
62 }
63
64 }
65
66 }
67
68 // instance
69 public static function instance( $key, $params = array() ) {
70 return new self( $key, $params );
71 }
72
73 // get default value
74 public function get_default( $field ) {
75
76 $default = ( isset( $field['default'] ) ) ? $field['default'] : '';
77 $default = ( isset( $this->args['defaults'][$field['id']] ) ) ? $this->args['defaults'][$field['id']] : $default;
78
79 return $default;
80
81 }
82
83 public function add_footer_modal_shortcode() {
84
85 if( ! wp_script_is( 'adminify' ) ) {
86 return;
87 }
88
89 $class = ( $this->args['class'] ) ? ' '. esc_attr( $this->args['class'] ) : '';
90 $has_select = ( count( $this->pre_tabs ) > 1 ) ? true : false;
91 $single_usage = ( ! $has_select ) ? ' adminify-shortcode-single' : '';
92 $hide_header = ( ! $has_select ) ? ' hidden' : '';
93
94 ?>
95 <div id="adminify-modal-<?php echo esc_attr( $this->unique ); ?>" class="wp-core-ui adminify-modal adminify-shortcode hidden<?php echo esc_attr( $single_usage . $class ); ?>" data-modal-id="<?php echo esc_attr( $this->unique ); ?>" data-nonce="<?php echo esc_attr( wp_create_nonce( 'adminify_shortcode_nonce' ) ); ?>">
96 <div class="adminify-modal-table">
97 <div class="adminify-modal-table-cell">
98 <div class="adminify-modal-overlay"></div>
99 <div class="adminify-modal-inner">
100 <div class="adminify-modal-title">
101 <?php echo $this->args['button_title']; ?>
102 <div class="adminify-modal-close"></div>
103 </div>
104 <?php
105
106 echo '<div class="adminify-modal-header'. esc_attr( $hide_header ) .'">';
107 echo '<select>';
108 echo ( $has_select ) ? '<option value="">'. esc_attr( $this->args['select_title'] ) .'</option>' : '';
109
110 $tab_key = 1;
111
112 foreach ( $this->pre_tabs as $tab ) {
113
114 if ( ! empty( $tab['subs'] ) ) {
115
116 echo '<optgroup label="'. esc_attr( $tab['title'] ) .'">';
117
118 foreach ( $tab['subs'] as $sub ) {
119
120 $view = ( ! empty( $sub['view'] ) ) ? ' data-view="'. esc_attr( $sub['view'] ) .'"' : '';
121 $shortcode = ( ! empty( $sub['shortcode'] ) ) ? ' data-shortcode="'. esc_attr( $sub['shortcode'] ) .'"' : '';
122 $group = ( ! empty( $sub['group_shortcode'] ) ) ? ' data-group="'. esc_attr( $sub['group_shortcode'] ) .'"' : '';
123
124 echo '<option value="'. esc_attr( $tab_key ) .'"'. $view . $shortcode . $group .'>'. esc_attr( $sub['title'] ) .'</option>';
125
126 $tab_key++;
127
128 }
129
130 echo '</optgroup>' ;
131
132 } else {
133
134 $view = ( ! empty( $tab['view'] ) ) ? ' data-view="'. esc_attr( $tab['view'] ) .'"' : '';
135 $shortcode = ( ! empty( $tab['shortcode'] ) ) ? ' data-shortcode="'. esc_attr( $tab['shortcode'] ) .'"' : '';
136 $group = ( ! empty( $tab['group_shortcode'] ) ) ? ' data-group="'. esc_attr( $tab['group_shortcode'] ) .'"' : '';
137
138 echo '<option value="'. esc_attr( $tab_key ) .'"'. $view . $shortcode . $group .'>'. esc_attr( $tab['title'] ) .'</option>';
139
140 $tab_key++;
141
142 }
143
144 }
145
146 echo '</select>';
147 echo '</div>';
148
149 ?>
150 <div class="adminify-modal-content">
151 <div class="adminify-modal-loading"><div class="adminify-loading"></div></div>
152 <div class="adminify-modal-load"></div>
153 </div>
154 <div class="adminify-modal-insert-wrapper hidden"><a href="#" class="button button-primary adminify-modal-insert"><?php echo $this->args['insert_title']; ?></a></div>
155 </div>
156 </div>
157 </div>
158 </div>
159 <?php
160 }
161
162 public function get_shortcode() {
163
164 ob_start();
165
166 $nonce = ( ! empty( $_POST[ 'nonce' ] ) ) ? sanitize_text_field( wp_unslash( $_POST[ 'nonce' ] ) ) : '';
167 $shortcode_key = ( ! empty( $_POST[ 'shortcode_key' ] ) ) ? sanitize_text_field( wp_unslash( $_POST[ 'shortcode_key' ] ) ) : '';
168
169 if ( ! empty( $shortcode_key ) && wp_verify_nonce( $nonce, 'adminify_shortcode_nonce' ) ) {
170
171 $unallows = array( 'group', 'repeater', 'sorter' );
172 $section = $this->pre_sections[$shortcode_key-1];
173 $shortcode = ( ! empty( $section['shortcode'] ) ) ? $section['shortcode'] : '';
174 $view = ( ! empty( $section['view'] ) ) ? $section['view'] : 'normal';
175
176 if ( ! empty( $section ) ) {
177
178 //
179 // View: normal
180 if ( ! empty( $section['fields'] ) && $view !== 'repeater' ) {
181
182 echo '<div class="adminify-fields">';
183
184 echo ( ! empty( $section['description'] ) ) ? '<div class="adminify-field adminify-section-description">'. $section['description'] .'</div>' : '';
185
186 foreach ( $section['fields'] as $field ) {
187
188 if ( in_array( $field['type'], $unallows ) ) { $field['_notice'] = true; }
189
190 // Extra tag improves for spesific fields (border, spacing, dimensions etc...)
191 $field['tag_prefix'] = ( ! empty( $field['tag_prefix'] ) ) ? $field['tag_prefix'] .'_' : '';
192
193 $field_default = ( isset( $field['id'] ) ) ? $this->get_default( $field ) : '';
194
195 ADMINIFY::field( $field, $field_default, $shortcode, 'shortcode' );
196
197 }
198
199 echo '</div>';
200
201 }
202
203 //
204 // View: group and repeater fields
205 $repeatable_fields = ( $view === 'repeater' && ! empty( $section['fields'] ) ) ? $section['fields'] : array();
206 $repeatable_fields = ( $view === 'group' && ! empty( $section['group_fields'] ) ) ? $section['group_fields'] : $repeatable_fields;
207
208 if ( ! empty( $repeatable_fields ) ) {
209
210 $button_title = ( ! empty( $section['button_title'] ) ) ? ' '. $section['button_title'] : esc_html__( 'Add New', 'adminify' );
211 $inner_shortcode = ( ! empty( $section['group_shortcode'] ) ) ? $section['group_shortcode'] : $shortcode;
212
213 echo '<div class="adminify--repeatable">';
214
215 echo '<div class="adminify--repeat-shortcode">';
216
217 echo '<div class="adminify-repeat-remove fas fa-times"></div>';
218
219 echo '<div class="adminify-fields">';
220
221 foreach ( $repeatable_fields as $field ) {
222
223 if ( in_array( $field['type'], $unallows ) ) { $field['_notice'] = true; }
224
225 // Extra tag improves for spesific fields (border, spacing, dimensions etc...)
226 $field['tag_prefix'] = ( ! empty( $field['tag_prefix'] ) ) ? $field['tag_prefix'] .'_' : '';
227
228 $field_default = ( isset( $field['id'] ) ) ? $this->get_default( $field ) : '';
229
230 ADMINIFY::field( $field, $field_default, $inner_shortcode.'[0]', 'shortcode' );
231
232 }
233
234 echo '</div>';
235
236 echo '</div>';
237
238 echo '</div>';
239
240 echo '<div class="adminify--repeat-button-block"><a class="button adminify--repeat-button" href="#"><i class="fas fa-plus-circle"></i> '. $button_title .'</a></div>';
241
242 }
243
244 }
245
246 } else {
247 echo '<div class="adminify-field adminify-error-text">'. esc_html__( 'Error: Invalid nonce verification.', 'adminify' ) .'</div>';
248 }
249
250 wp_send_json_success( array( 'content' => ob_get_clean() ) );
251
252 }
253
254 // Once editor setup for gutenberg and media buttons
255 public static function once_editor_setup() {
256
257 if ( function_exists( 'register_block_type' ) ) {
258 add_action( 'enqueue_block_editor_assets', array( 'ADMINIFY_Shortcoder', 'add_guteberg_blocks' ) );
259 }
260
261 if ( adminify_wp_editor_api() ) {
262 add_action( 'media_buttons', array( 'ADMINIFY_Shortcoder', 'add_media_buttons' ) );
263 }
264
265 }
266
267 // Add gutenberg blocks.
268 public static function add_guteberg_blocks() {
269
270 $depends = array( 'wp-blocks', 'wp-element', 'wp-components' );
271
272 if ( wp_script_is( 'wp-edit-widgets' ) ) {
273 $depends[] = 'wp-edit-widgets';
274 } else {
275 $depends[] = 'wp-edit-post';
276 }
277
278 wp_enqueue_script( 'adminify-gutenberg-block', ADMINIFY::include_plugin_url( 'assets/js/gutenberg.js' ), $depends );
279
280 wp_localize_script( 'adminify-gutenberg-block', 'adminify_gutenberg_blocks', ADMINIFY::$shortcode_instances );
281
282 foreach ( ADMINIFY::$shortcode_instances as $block ) {
283
284 register_block_type( $block['name'], array(
285 'editor_script' => 'adminify-gutenberg-block',
286 ) );
287
288 }
289
290 }
291
292 // Add media buttons
293 public static function add_media_buttons( $editor_id ) {
294
295 foreach ( ADMINIFY::$shortcode_instances as $value ) {
296 echo '<a href="#" class="button button-primary adminify-shortcode-button" data-editor-id="'. esc_attr( $editor_id ) .'" data-modal-id="'. esc_attr( $value['modal_id'] ) .'">'. esc_html( $value['button_title'] ) .'</a>';
297 }
298
299 }
300
301 }
302 }
303