PluginProbe ʕ •ᴥ•ʔ
The Post Grid – Shortcode, Gutenberg Blocks and Elementor Addon for Post Grid / 7.0.1
The Post Grid – Shortcode, Gutenberg Blocks and Elementor Addon for Post Grid v7.0.1
7.9.3 7.9.2 trunk 4.0.0 4.0.1 4.0.2 4.0.3 4.0.4 4.0.5 4.1.0 4.1.1 4.1.2 4.1.3 4.1.4 4.1.5 4.2.0 4.2.1 4.2.2 4.2.3 5.0.0 5.0.1 5.0.2 5.0.3 5.0.4 5.0.5 6.0.0 7.0.0 7.0.1 7.0.2 7.1.0 7.2.0 7.2.1 7.2.10 7.2.11 7.2.2 7.2.3 7.2.4 7.2.5 7.2.6 7.2.7 7.2.8 7.2.9 7.3.0 7.3.1 7.4.0 7.4.1 7.4.2 7.4.3 7.5.0 7.6.0 7.6.1 7.7.0 7.7.1 7.7.10 7.7.11 7.7.12 7.7.13 7.7.14 7.7.15 7.7.16 7.7.17 7.7.18 7.7.19 7.7.2 7.7.20 7.7.21 7.7.22 7.7.3 7.7.4 7.7.5 7.7.6 7.7.7 7.7.8 7.7.9 7.8.0 7.8.1 7.8.2 7.8.3 7.8.4 7.8.5 7.8.6 7.8.7 7.8.8 7.8.9 7.9.0 7.9.1
the-post-grid / app / Controllers / Admin / MetaController.php
the-post-grid / app / Controllers / Admin Last commit date
AdminAjaxController.php 3 years ago MetaController.php 3 years ago NoticeController.php 3 years ago PostTypeController.php 3 years ago SettingsController.php 3 years ago UpgradeController.php 3 years ago
MetaController.php
481 lines
1 <?php
2 /**
3 * Meta Controller class.
4 *
5 * @package RT_TPG
6 */
7
8 namespace RT\ThePostGrid\Controllers\Admin;
9
10 use RT\ThePostGrid\Helpers\Fns;
11 use RT\ThePostGrid\Helpers\Options;
12
13 // Do not allow directly accessing this file.
14 if ( ! defined( 'ABSPATH' ) ) {
15 exit( 'This script cannot be accessed directly.' );
16 }
17
18 /**
19 * Meta Controller class.
20 */
21 class MetaController {
22 /**
23 * Class constructor
24 */
25 public function __construct() {
26 add_action( 'admin_head', [ $this, 'admin_head' ] );
27 add_action( 'edit_form_after_title', [ $this, 'tpg_sc_after_title' ] );
28 add_action( 'admin_enqueue_scripts', [ $this, 'admin_enqueue_scripts' ] );
29 add_action( 'save_post', [ $this, 'save_post' ], 10, 2 );
30 add_filter( 'manage_edit-rttpg_columns', [ $this, 'arrange_rttpg_columns' ] );
31 add_action( 'manage_rttpg_posts_custom_column', [ $this, 'manage_rttpg_columns' ], 10, 2 );
32 }
33
34 /**
35 * manage Column
36 *
37 * @param string $column Column.
38 * @return void
39 */
40 public function manage_rttpg_columns( $column ) {
41 switch ( $column ) {
42 case 'shortcode':
43 echo '<input type="text" onfocus="this.select();" readonly="readonly" value="[the-post-grid id=&quot;' . get_the_ID() . '&quot; title=&quot;' . get_the_title() . '&quot;]" class="large-text code rt-code-sc">';
44 break;
45 default:
46 break;
47 }
48 }
49
50 /**
51 * Arrange Columns
52 *
53 * @param array $columns Columns.
54 * @return array
55 */
56 public function arrange_rttpg_columns( $columns ) {
57 $shortcode = [ 'shortcode' => esc_html__( 'Shortcode', 'the-post-grid' ) ];
58
59 return array_slice( $columns, 0, 2, true ) + $shortcode + array_slice( $columns, 1, null, true );
60 }
61
62 /**
63 * Admin Scripts
64 *
65 * @return void
66 */
67 public function admin_enqueue_scripts() {
68
69 global $pagenow, $typenow;
70
71 if ( 'tpg_builder' === $typenow ) {
72 wp_enqueue_style( 'rt-tpg-admin' );
73 }
74
75 if ( ! in_array( $pagenow, [ 'post.php', 'post-new.php' ], true ) ) {
76 return;
77 }
78
79 if ( rtTPG()->post_type !== $typenow ) {
80 return;
81 }
82
83 wp_dequeue_script( 'autosave' );
84 wp_enqueue_media();
85
86 $select2Id = 'rt-select2';
87 if ( class_exists( 'Avada' ) ) {
88 $select2Id = 'select2-avada-js';
89 }
90
91 // scripts.
92 wp_enqueue_script(
93 [
94 'jquery',
95 'jquery-ui-datepicker',
96 'wp-color-picker',
97 $select2Id,
98 'imagesloaded',
99 'rt-isotope-js',
100 'rt-tpg-admin',
101 'rt-tpg-admin-preview',
102 ]
103 );
104
105 // styles.
106 wp_enqueue_style(
107 [
108 'wp-color-picker',
109 'rt-select2',
110 'rt-fontawsome',
111 'rt-tpg-admin',
112 'rt-tpg-admin-preview',
113 ]
114 );
115
116 wp_localize_script(
117 'rt-tpg-admin',
118 'rttpg',
119 [
120 'nonceID' => esc_attr( rtTPG()->nonceId() ),
121 'nonce' => esc_attr( wp_create_nonce( rtTPG()->nonceText() ) ),
122 'ajaxurl' => esc_url( admin_url( 'admin-ajax.php' ) ),
123 ]
124 );
125
126 }
127
128 /**
129 * Add Metabox.
130 *
131 * @return void
132 */
133 public function admin_head() {
134 add_meta_box(
135 'rttpg_meta',
136 esc_html__( 'Short Code Generator', 'the-post-grid' ),
137 [ $this, 'rttpg_meta_settings_selection' ],
138 rtTPG()->post_type,
139 'normal',
140 'high'
141 );
142
143 add_meta_box(
144 rtTPG()->post_type . '_sc_preview_meta',
145 esc_html__( 'Layout Preview', 'the-post-grid' ),
146 [ $this, 'tpg_sc_preview_selection' ],
147 rtTPG()->post_type,
148 'normal',
149 'high'
150 );
151
152 add_meta_box(
153 'rt_plugin_sc_pro_information',
154 esc_html__( 'Documentation', 'the-post-grid' ),
155 [ $this, 'rt_plugin_sc_pro_information' ],
156 rtTPG()->post_type,
157 'side',
158 'low'
159 );
160 }
161
162 /**
163 * Marketing.
164 *
165 * @param string $post Post.
166 * @return void
167 */
168 public function rt_plugin_sc_pro_information( $post ) {
169 $html = '';
170
171 if ( 'settings' === $post ) {
172 $html .= '<div class="rt-document-box rt-update-pro-btn-wrap">
173 <a href="' . esc_url( rtTpg()->proLink() ) . '" target="_blank" class="rt-update-pro-btn">' . esc_html__( 'Update Pro To Get More Features', 'the-post-grid' ) . '</a>
174 </div>';
175 } else {
176 if ( ! rtTPG()->hasPro() ) {
177 $html .= sprintf(
178 '<div class="rt-document-box"><div class="rt-box-icon"><i class="dashicons dashicons-megaphone"></i></div><div class="rt-box-content"><h3 class="rt-box-title">%1$s</h3>%2$s</div></div>',
179 esc_html__( 'Pro Features', 'the-post-grid' ),
180 Options::get_pro_feature_list()
181 );
182 }
183 }
184
185 $html .= sprintf(
186 '<div class="rt-document-box">
187 <div class="rt-box-icon"><i class="dashicons dashicons-media-document"></i></div>
188 <div class="rt-box-content">
189 <h3 class="rt-box-title">%1$s</h3>
190 <p>%2$s</p>
191 <a href="' . esc_url( rtTpg()->docLink() ) . '" target="_blank" class="rt-admin-btn">%1$s</a>
192 </div>
193 </div>',
194 esc_html__( 'Documentation', 'the-post-grid' ),
195 esc_html__( 'Get started by spending some time with the documentation we included step by step process with screenshots with video.', 'the-post-grid' )
196 );
197
198 $rtContact = 'https://www.radiustheme.com/contact/';
199 $rtFb = 'https://www.facebook.com/groups/234799147426640/';
200 $rtsite = 'https://www.radiustheme.com/';
201
202 $html .= '<div class="rt-document-box">
203 <div class="rt-box-icon"><i class="dashicons dashicons-sos"></i></div>
204 <div class="rt-box-content">
205 <h3 class="rt-box-title">Need Help?</h3>
206 <p>Stuck with something? Please create a
207 <a href="' . esc_url( $rtContact ) . '">ticket here</a> or post on <a href="' . esc_url( $rtFb ) . '">facebook group</a>. For emergency case join our <a href="' . esc_url( $rtsite ) . '">live chat</a>.</p>
208 <a href="' . esc_url( $rtContact ) . '" target="_blank" class="rt-admin-btn">' . esc_html__( 'Get Support', 'the-post-grid' ) . '</a>
209 </div>
210 </div>';
211
212 Fns::print_html( $html );
213 }
214
215 /**
216 * Preview
217 *
218 * @return void
219 */
220 public function tpg_sc_preview_selection() {
221 $html = null;
222 $html .= "<div class='rt-response'></div>";
223 $html .= "<div id='tpg-preview-container'></div>";
224
225 Fns::print_html( $html, true );
226 }
227
228 /**
229 * Text after title
230 *
231 * @param object $post Post object.
232 * @return void
233 */
234 public function tpg_sc_after_title( $post ) {
235 if ( rtTPG()->post_type !== $post->post_type ) {
236 return;
237 }
238
239 $html = null;
240 $html .= '<div class="postbox rt-after-title" style="margin-bottom: 0;"><div class="inside">';
241 $html .= '<p>
242 <input type="text" onfocus="this.select();" readonly="readonly" value="[the-post-grid id=&quot;' . absint( $post->ID ) . '&quot; title=&quot;' . esc_attr( $post->post_title ) . '&quot;]" class="large-text code rt-code-sc">
243 <input type="text" onfocus="this.select();" readonly="readonly" value="&#60;&#63;php echo do_shortcode( &#39;[the-post-grid id=&quot;' . absint( $post->ID ) . '&quot; title=&quot;' . esc_attr( $post->post_title ) . '&quot;]&#39; ); &#63;&#62;" class="large-text code rt-code-sc">
244 </p>';
245 $html .= '</div></div>';
246
247 Fns::print_html( $html, true );
248 }
249
250 /**
251 * Meta settings
252 *
253 * @param object $post Post object.
254 * @return void
255 */
256 public function rttpg_meta_settings_selection( $post ) {
257 $last_tab = trim( get_post_meta( $post->ID, '_tpg_last_active_tab', true ) );
258 $last_tab = $last_tab ? $last_tab : 'sc-post-post-source';
259 $post = [
260 'post' => $post,
261 ];
262
263 wp_nonce_field( rtTPG()->nonceText(), rtTPG()->nonceId() );
264
265 $html = null;
266 $html .= '<div id="sc-tabs" class="rttpg-wrapper rt-tab-container rt-setting-holder">';
267 $html .= sprintf(
268 '<ul class="rt-tab-nav">
269 <li%s><a href="#sc-post-post-source">%s</a></li>
270 <li%s><a href="#sc-post-layout-settings">%s</a></li>
271 <li%s><a href="#sc-settings">%s</a></li>
272 <li%s><a href="#sc-field-selection">%s</a></li>
273 <li%s><a href="#sc-style">%s</a></li>
274 </ul>',
275 'sc-post-post-source' === $last_tab ? ' class="active"' : '',
276 esc_html__( 'Query Build', 'the-post-grid' ),
277 'sc-post-layout-settings' === $last_tab ? ' class="active"' : '',
278 esc_html__( 'Layout Settings', 'the-post-grid' ),
279 'sc-settings' === $last_tab ? ' class="active"' : '',
280 esc_html__( 'Settings', 'the-post-grid' ),
281 'sc-field-selection' === $last_tab ? ' class="active"' : '',
282 esc_html__( 'Field Selection', 'the-post-grid' ),
283 'sc-style' === $last_tab ? ' class="active"' : '',
284 esc_html__( 'Style', 'the-post-grid' )
285 );
286
287 // Query Build tab.
288 $html .= sprintf( '<div id="sc-post-post-source" class="rt-tab-content"%s>', 'sc-post-post-source' === $last_tab ? ' style="display:block"' : '' );
289 $html .= Fns::view( 'settings.post-source', $post, true );
290 $html .= '</div>';
291
292 // Layout Setting tab.
293 $html .= sprintf( '<div id="sc-post-layout-settings" class="rt-tab-content"%s>', 'sc-post-layout-settings' === $last_tab ? ' style="display:block"' : '' );
294 $html .= Fns::view( 'settings.layout-settings', $post, true );
295 $html .= '</div>';
296
297 // Settings tab.
298 $html .= sprintf( '<div id="sc-settings" class="rt-tab-content"%s>', 'sc-settings' === $last_tab ? ' style="display:block"' : '' );
299 $html .= Fns::view( 'settings.sc-settings', $post, true );
300 $html .= '</div>';
301
302 // Field Selection tab.
303 $html .= sprintf( '<div id="sc-field-selection" class="rt-tab-content"%s>', 'sc-field-selection' === $last_tab ? ' style="display:block"' : '' );
304 $html .= Fns::view( 'settings.item-fields', $post, true );
305 $html .= '</div>';
306
307 // Style tab.
308 $html .= sprintf( '<div id="sc-style" class="rt-tab-content"%s>', 'sc-style' === $last_tab ? ' style="display:block"' : '' );
309 $html .= Fns::view( 'settings.style', $post, true );
310 $html .= '</div>';
311 $html .= sprintf( '<input type="hidden" id="_tpg_last_active_tab" name="_tpg_last_active_tab" value="%s"/>', $last_tab );
312 $html .= '</div>';
313
314 Fns::print_html( $html, true );
315 }
316
317 /**
318 * Save meta box.
319 *
320 * @param int $post_id Post ID.
321 * @param object $post Post object.
322 * @return mixed
323 */
324 public function save_post( $post_id, $post ) {
325 if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
326 return $post_id;
327 }
328
329 if ( ! Fns::verifyNonce() ) {
330 return $post_id;
331 }
332
333 if ( rtTPG()->post_type !== $post->post_type ) {
334 return $post_id;
335 }
336
337 $mates = Fns::rtAllOptionFields();
338
339 foreach ( $mates as $metaKey => $field ) {
340 $rValue = ! empty( $_REQUEST[ $metaKey ] ) ? $_REQUEST[ $metaKey ] : null;
341 $value = Fns::sanitize( $field, $rValue );
342
343 if ( empty( $field['multiple'] ) ) {
344 update_post_meta( $post_id, $metaKey, $value );
345 } else {
346 delete_post_meta( $post_id, $metaKey );
347 if ( is_array( $value ) && ! empty( $value ) ) {
348 foreach ( $value as $item ) {
349 add_post_meta( $post_id, $metaKey, $item );
350 }
351 }
352 }
353 }
354
355 $post_filter = ( isset( $_REQUEST['post_filter'] ) ? array_map( 'sanitize_text_field', wp_unslash( $_REQUEST['post_filter'] ) ) : [] );
356 $advFilter = Options::rtTPAdvanceFilters();
357
358 foreach ( $advFilter['post_filter']['options'] as $filter => $fValue ) {
359 if ( $filter == 'tpg_taxonomy' ) {
360 delete_post_meta( $post_id, $filter );
361
362 if ( ! empty( $_REQUEST[ $filter ] ) && is_array( $_REQUEST[ $filter ] ) ) {
363 foreach ( $_REQUEST[ $filter ] as $tax ) {
364 if ( in_array( $filter, $post_filter ) ) {
365 add_post_meta( $post_id, $filter, trim( $tax ) );
366 }
367
368 delete_post_meta( $post_id, 'term_' . $tax );
369
370 $tt = isset( $_REQUEST[ 'term_' . $tax ] ) ? $_REQUEST[ 'term_' . $tax ] : [];
371
372 if ( is_array( $tt ) && ! empty( $tt ) && in_array( $filter, $post_filter ) ) {
373 foreach ( $tt as $termID ) {
374 add_post_meta( $post_id, 'term_' . $tax, trim( $termID ) );
375 }
376 }
377
378 $tto = isset( $_REQUEST[ 'term_operator_' . $tax ] ) ? sanitize_text_field( wp_unslash( $_REQUEST[ 'term_operator_' . $tax ] ) ) : null;
379
380 if ( $tto ) {
381 update_post_meta( $post_id, 'term_operator_' . $tax, trim( $tto ) );
382 }
383 }
384
385 $filterCount = isset( $_REQUEST[ $filter ] ) ? $_REQUEST[ $filter ] : [];
386 $tr = isset( $_REQUEST['taxonomy_relation'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['taxonomy_relation'] ) ) : null;
387
388 if ( count( $filterCount ) > 1 && $tr ) {
389 update_post_meta( $post_id, 'taxonomy_relation', trim( $tr ) );
390 } else {
391 delete_post_meta( $post_id, 'taxonomy_relation' );
392 }
393 }
394 } elseif ( $filter == 'author' ) {
395 delete_post_meta( $post_id, 'author' );
396
397 $authors = ( isset( $_REQUEST['author'] ) ? array_map( 'sanitize_text_field', wp_unslash( $_REQUEST['author'] ) ) : [] );
398
399 if ( is_array( $authors ) && ! empty( $authors ) && in_array( 'author', $post_filter ) ) {
400 foreach ( $authors as $authorID ) {
401 add_post_meta( $post_id, 'author', trim( $authorID ) );
402 }
403 }
404 } elseif ( $filter == 'tpg_post_status' ) {
405 delete_post_meta( $post_id, $filter );
406
407 $statuses = isset( $_REQUEST[ $filter ] ) ? $_REQUEST[ $filter ] : [];
408
409 if ( is_array( $statuses ) && ! empty( $statuses ) && in_array( $filter, $post_filter ) ) {
410 foreach ( $statuses as $post_status ) {
411 add_post_meta( $post_id, $filter, trim( $post_status ) );
412 }
413 }
414 } elseif ( $filter == 's' ) {
415 delete_post_meta( $post_id, 's' );
416
417 $s = ( isset( $_REQUEST['s'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['s'] ) ) : null );
418
419 if ( $s && in_array( 's', $post_filter ) ) {
420 update_post_meta( $post_id, 's', sanitize_text_field( trim( $s ) ) );
421 }
422 } elseif ( $filter == 'order' ) {
423 if ( in_array( 'order', $post_filter ) ) {
424 $order = ( isset( $_REQUEST['order'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['order'] ) ) : null );
425 $order_by = ( isset( $_REQUEST['order_by'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['order_by'] ) ) : null );
426 $tpg_meta_key = isset( $_REQUEST['tpg_meta_key'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['tpg_meta_key'] ) ) : null;
427
428 if ( $order && in_array( 'order', $post_filter ) ) {
429 update_post_meta( $post_id, 'order', sanitize_text_field( trim( $order ) ) );
430 }
431
432 if ( $order_by && in_array( 'order', $post_filter ) ) {
433 update_post_meta( $post_id, 'order_by', sanitize_text_field( trim( $order_by ) ) );
434 }
435
436 if ( in_array( $order_by, array_keys( Options::rtMetaKeyType() ) ) && $tpg_meta_key && in_array( 'order', $post_filter ) ) {
437 update_post_meta( $post_id, 'tpg_meta_key', sanitize_text_field( trim( $tpg_meta_key ) ) );
438 } else {
439 delete_post_meta( $post_id, 'tpg_meta_key' );
440 }
441 } else {
442 delete_post_meta( $post_id, 'order' );
443 delete_post_meta( $post_id, 'tpg_meta_key' );
444 delete_post_meta( $post_id, 'order_by' );
445 }
446 } elseif ( $filter == 'date_range' ) {
447 if ( in_array( 'date_range', $post_filter ) ) {
448 $start = ! empty( $_REQUEST[ $filter . '_start' ] ) ? sanitize_text_field( wp_unslash( $_REQUEST[ $filter . '_start' ] ) ) : null;
449 $end = ! empty( $_REQUEST[ $filter . '_end' ] ) ? sanitize_text_field( wp_unslash( $_REQUEST[ $filter . '_end' ] ) ) : null;
450
451 update_post_meta( $post_id, $filter . '_start', trim( $start ) );
452 update_post_meta( $post_id, $filter . '_end', trim( $end ) );
453 } else {
454 delete_post_meta( $post_id, $filter . '_start' );
455 delete_post_meta( $post_id, $filter . '_end' );
456 }
457 }
458 }
459
460 // Extra css.
461 $extraFields = Options::extraStyle();
462 $extraTypes = [ 'color', 'size', 'weight', 'alignment' ];
463
464 foreach ( $extraFields as $key => $title ) {
465 foreach ( $extraTypes as $type ) {
466 $newKew = $key . "_{$type}";
467 if ( isset( $_REQUEST[ $newKew ] ) ) {
468 $value = sanitize_text_field( wp_unslash( $_REQUEST[ $newKew ] ) );
469
470 update_post_meta( $post_id, $newKew, $value );
471 }
472 }
473 }
474
475 if ( isset( $_POST['_tpg_last_active_tab'] ) && $active_tab = sanitize_text_field( wp_unslash( $_POST['_tpg_last_active_tab'] ) ) ) {
476 update_post_meta( $post_id, '_tpg_last_active_tab', $active_tab );
477 }
478
479 }
480 }
481