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