PluginProbe ʕ •ᴥ•ʔ
The Post Grid – Shortcode, Gutenberg Blocks and Elementor Addon for Post Grid / 7.0.2
The Post Grid – Shortcode, Gutenberg Blocks and Elementor Addon for Post Grid v7.0.2
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
482 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-flaticon',
112 'rt-tpg-admin',
113 'rt-tpg-admin-preview',
114 ]
115 );
116
117 wp_localize_script(
118 'rt-tpg-admin',
119 'rttpg',
120 [
121 'nonceID' => esc_attr( rtTPG()->nonceId() ),
122 'nonce' => esc_attr( wp_create_nonce( rtTPG()->nonceText() ) ),
123 'ajaxurl' => esc_url( admin_url( 'admin-ajax.php' ) ),
124 ]
125 );
126
127 }
128
129 /**
130 * Add Metabox.
131 *
132 * @return void
133 */
134 public function admin_head() {
135 add_meta_box(
136 'rttpg_meta',
137 esc_html__( 'Short Code Generator', 'the-post-grid' ),
138 [ $this, 'rttpg_meta_settings_selection' ],
139 rtTPG()->post_type,
140 'normal',
141 'high'
142 );
143
144 add_meta_box(
145 rtTPG()->post_type . '_sc_preview_meta',
146 esc_html__( 'Layout Preview', 'the-post-grid' ),
147 [ $this, 'tpg_sc_preview_selection' ],
148 rtTPG()->post_type,
149 'normal',
150 'high'
151 );
152
153 add_meta_box(
154 'rt_plugin_sc_pro_information',
155 esc_html__( 'Documentation', 'the-post-grid' ),
156 [ $this, 'rt_plugin_sc_pro_information' ],
157 rtTPG()->post_type,
158 'side',
159 'low'
160 );
161 }
162
163 /**
164 * Marketing.
165 *
166 * @param string $post Post.
167 * @return void
168 */
169 public function rt_plugin_sc_pro_information( $post ) {
170 $html = '';
171
172 if ( 'settings' === $post ) {
173 $html .= '<div class="rt-document-box rt-update-pro-btn-wrap">
174 <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>
175 </div>';
176 } else {
177 if ( ! rtTPG()->hasPro() ) {
178 $html .= sprintf(
179 '<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>',
180 esc_html__( 'Pro Features', 'the-post-grid' ),
181 Options::get_pro_feature_list()
182 );
183 }
184 }
185
186 $html .= sprintf(
187 '<div class="rt-document-box">
188 <div class="rt-box-icon"><i class="dashicons dashicons-media-document"></i></div>
189 <div class="rt-box-content">
190 <h3 class="rt-box-title">%1$s</h3>
191 <p>%2$s</p>
192 <a href="' . esc_url( rtTpg()->docLink() ) . '" target="_blank" class="rt-admin-btn">%1$s</a>
193 </div>
194 </div>',
195 esc_html__( 'Documentation', 'the-post-grid' ),
196 esc_html__( 'Get started by spending some time with the documentation we included step by step process with screenshots with video.', 'the-post-grid' )
197 );
198
199 $rtContact = 'https://www.radiustheme.com/contact/';
200 $rtFb = 'https://www.facebook.com/groups/234799147426640/';
201 $rtsite = 'https://www.radiustheme.com/';
202
203 $html .= '<div class="rt-document-box">
204 <div class="rt-box-icon"><i class="dashicons dashicons-sos"></i></div>
205 <div class="rt-box-content">
206 <h3 class="rt-box-title">Need Help?</h3>
207 <p>Stuck with something? Please create a
208 <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>
209 <a href="' . esc_url( $rtContact ) . '" target="_blank" class="rt-admin-btn">' . esc_html__( 'Get Support', 'the-post-grid' ) . '</a>
210 </div>
211 </div>';
212
213 Fns::print_html( $html );
214 }
215
216 /**
217 * Preview
218 *
219 * @return void
220 */
221 public function tpg_sc_preview_selection() {
222 $html = null;
223 $html .= "<div class='rt-response'></div>";
224 $html .= "<div id='tpg-preview-container'></div>";
225
226 Fns::print_html( $html, true );
227 }
228
229 /**
230 * Text after title
231 *
232 * @param object $post Post object.
233 * @return void
234 */
235 public function tpg_sc_after_title( $post ) {
236 if ( rtTPG()->post_type !== $post->post_type ) {
237 return;
238 }
239
240 $html = null;
241 $html .= '<div class="postbox rt-after-title" style="margin-bottom: 0;"><div class="inside">';
242 $html .= '<p>
243 <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">
244 <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">
245 </p>';
246 $html .= '</div></div>';
247
248 Fns::print_html( $html, true );
249 }
250
251 /**
252 * Meta settings
253 *
254 * @param object $post Post object.
255 * @return void
256 */
257 public function rttpg_meta_settings_selection( $post ) {
258 $last_tab = trim( get_post_meta( $post->ID, '_tpg_last_active_tab', true ) );
259 $last_tab = $last_tab ? $last_tab : 'sc-post-post-source';
260 $post = [
261 'post' => $post,
262 ];
263
264 wp_nonce_field( rtTPG()->nonceText(), rtTPG()->nonceId() );
265
266 $html = null;
267 $html .= '<div id="sc-tabs" class="rttpg-wrapper rt-tab-container rt-setting-holder">';
268 $html .= sprintf(
269 '<ul class="rt-tab-nav">
270 <li%s><a href="#sc-post-post-source">%s</a></li>
271 <li%s><a href="#sc-post-layout-settings">%s</a></li>
272 <li%s><a href="#sc-settings">%s</a></li>
273 <li%s><a href="#sc-field-selection">%s</a></li>
274 <li%s><a href="#sc-style">%s</a></li>
275 </ul>',
276 'sc-post-post-source' === $last_tab ? ' class="active"' : '',
277 esc_html__( 'Query Build', 'the-post-grid' ),
278 'sc-post-layout-settings' === $last_tab ? ' class="active"' : '',
279 esc_html__( 'Layout Settings', 'the-post-grid' ),
280 'sc-settings' === $last_tab ? ' class="active"' : '',
281 esc_html__( 'Settings', 'the-post-grid' ),
282 'sc-field-selection' === $last_tab ? ' class="active"' : '',
283 esc_html__( 'Field Selection', 'the-post-grid' ),
284 'sc-style' === $last_tab ? ' class="active"' : '',
285 esc_html__( 'Style', 'the-post-grid' )
286 );
287
288 // Query Build tab.
289 $html .= sprintf( '<div id="sc-post-post-source" class="rt-tab-content"%s>', 'sc-post-post-source' === $last_tab ? ' style="display:block"' : '' );
290 $html .= Fns::view( 'settings.post-source', $post, true );
291 $html .= '</div>';
292
293 // Layout Setting tab.
294 $html .= sprintf( '<div id="sc-post-layout-settings" class="rt-tab-content"%s>', 'sc-post-layout-settings' === $last_tab ? ' style="display:block"' : '' );
295 $html .= Fns::view( 'settings.layout-settings', $post, true );
296 $html .= '</div>';
297
298 // Settings tab.
299 $html .= sprintf( '<div id="sc-settings" class="rt-tab-content"%s>', 'sc-settings' === $last_tab ? ' style="display:block"' : '' );
300 $html .= Fns::view( 'settings.sc-settings', $post, true );
301 $html .= '</div>';
302
303 // Field Selection tab.
304 $html .= sprintf( '<div id="sc-field-selection" class="rt-tab-content"%s>', 'sc-field-selection' === $last_tab ? ' style="display:block"' : '' );
305 $html .= Fns::view( 'settings.item-fields', $post, true );
306 $html .= '</div>';
307
308 // Style tab.
309 $html .= sprintf( '<div id="sc-style" class="rt-tab-content"%s>', 'sc-style' === $last_tab ? ' style="display:block"' : '' );
310 $html .= Fns::view( 'settings.style', $post, true );
311 $html .= '</div>';
312 $html .= sprintf( '<input type="hidden" id="_tpg_last_active_tab" name="_tpg_last_active_tab" value="%s"/>', $last_tab );
313 $html .= '</div>';
314
315 Fns::print_html( $html, true );
316 }
317
318 /**
319 * Save meta box.
320 *
321 * @param int $post_id Post ID.
322 * @param object $post Post object.
323 * @return mixed
324 */
325 public function save_post( $post_id, $post ) {
326 if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
327 return $post_id;
328 }
329
330 if ( ! Fns::verifyNonce() ) {
331 return $post_id;
332 }
333
334 if ( rtTPG()->post_type !== $post->post_type ) {
335 return $post_id;
336 }
337
338 $mates = Fns::rtAllOptionFields();
339
340 foreach ( $mates as $metaKey => $field ) {
341 $rValue = ! empty( $_REQUEST[ $metaKey ] ) ? $_REQUEST[ $metaKey ] : null;
342 $value = Fns::sanitize( $field, $rValue );
343
344 if ( empty( $field['multiple'] ) ) {
345 update_post_meta( $post_id, $metaKey, $value );
346 } else {
347 delete_post_meta( $post_id, $metaKey );
348 if ( is_array( $value ) && ! empty( $value ) ) {
349 foreach ( $value as $item ) {
350 add_post_meta( $post_id, $metaKey, $item );
351 }
352 }
353 }
354 }
355
356 $post_filter = ( isset( $_REQUEST['post_filter'] ) ? array_map( 'sanitize_text_field', wp_unslash( $_REQUEST['post_filter'] ) ) : [] );
357 $advFilter = Options::rtTPAdvanceFilters();
358
359 foreach ( $advFilter['post_filter']['options'] as $filter => $fValue ) {
360 if ( $filter == 'tpg_taxonomy' ) {
361 delete_post_meta( $post_id, $filter );
362
363 if ( ! empty( $_REQUEST[ $filter ] ) && is_array( $_REQUEST[ $filter ] ) ) {
364 foreach ( $_REQUEST[ $filter ] as $tax ) {
365 if ( in_array( $filter, $post_filter ) ) {
366 add_post_meta( $post_id, $filter, trim( $tax ) );
367 }
368
369 delete_post_meta( $post_id, 'term_' . $tax );
370
371 $tt = isset( $_REQUEST[ 'term_' . $tax ] ) ? $_REQUEST[ 'term_' . $tax ] : [];
372
373 if ( is_array( $tt ) && ! empty( $tt ) && in_array( $filter, $post_filter ) ) {
374 foreach ( $tt as $termID ) {
375 add_post_meta( $post_id, 'term_' . $tax, trim( $termID ) );
376 }
377 }
378
379 $tto = isset( $_REQUEST[ 'term_operator_' . $tax ] ) ? sanitize_text_field( wp_unslash( $_REQUEST[ 'term_operator_' . $tax ] ) ) : null;
380
381 if ( $tto ) {
382 update_post_meta( $post_id, 'term_operator_' . $tax, trim( $tto ) );
383 }
384 }
385
386 $filterCount = isset( $_REQUEST[ $filter ] ) ? $_REQUEST[ $filter ] : [];
387 $tr = isset( $_REQUEST['taxonomy_relation'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['taxonomy_relation'] ) ) : null;
388
389 if ( count( $filterCount ) > 1 && $tr ) {
390 update_post_meta( $post_id, 'taxonomy_relation', trim( $tr ) );
391 } else {
392 delete_post_meta( $post_id, 'taxonomy_relation' );
393 }
394 }
395 } elseif ( $filter == 'author' ) {
396 delete_post_meta( $post_id, 'author' );
397
398 $authors = ( isset( $_REQUEST['author'] ) ? array_map( 'sanitize_text_field', wp_unslash( $_REQUEST['author'] ) ) : [] );
399
400 if ( is_array( $authors ) && ! empty( $authors ) && in_array( 'author', $post_filter ) ) {
401 foreach ( $authors as $authorID ) {
402 add_post_meta( $post_id, 'author', trim( $authorID ) );
403 }
404 }
405 } elseif ( $filter == 'tpg_post_status' ) {
406 delete_post_meta( $post_id, $filter );
407
408 $statuses = isset( $_REQUEST[ $filter ] ) ? $_REQUEST[ $filter ] : [];
409
410 if ( is_array( $statuses ) && ! empty( $statuses ) && in_array( $filter, $post_filter ) ) {
411 foreach ( $statuses as $post_status ) {
412 add_post_meta( $post_id, $filter, trim( $post_status ) );
413 }
414 }
415 } elseif ( $filter == 's' ) {
416 delete_post_meta( $post_id, 's' );
417
418 $s = ( isset( $_REQUEST['s'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['s'] ) ) : null );
419
420 if ( $s && in_array( 's', $post_filter ) ) {
421 update_post_meta( $post_id, 's', sanitize_text_field( trim( $s ) ) );
422 }
423 } elseif ( $filter == 'order' ) {
424 if ( in_array( 'order', $post_filter ) ) {
425 $order = ( isset( $_REQUEST['order'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['order'] ) ) : null );
426 $order_by = ( isset( $_REQUEST['order_by'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['order_by'] ) ) : null );
427 $tpg_meta_key = isset( $_REQUEST['tpg_meta_key'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['tpg_meta_key'] ) ) : null;
428
429 if ( $order && in_array( 'order', $post_filter ) ) {
430 update_post_meta( $post_id, 'order', sanitize_text_field( trim( $order ) ) );
431 }
432
433 if ( $order_by && in_array( 'order', $post_filter ) ) {
434 update_post_meta( $post_id, 'order_by', sanitize_text_field( trim( $order_by ) ) );
435 }
436
437 if ( in_array( $order_by, array_keys( Options::rtMetaKeyType() ) ) && $tpg_meta_key && in_array( 'order', $post_filter ) ) {
438 update_post_meta( $post_id, 'tpg_meta_key', sanitize_text_field( trim( $tpg_meta_key ) ) );
439 } else {
440 delete_post_meta( $post_id, 'tpg_meta_key' );
441 }
442 } else {
443 delete_post_meta( $post_id, 'order' );
444 delete_post_meta( $post_id, 'tpg_meta_key' );
445 delete_post_meta( $post_id, 'order_by' );
446 }
447 } elseif ( $filter == 'date_range' ) {
448 if ( in_array( 'date_range', $post_filter ) ) {
449 $start = ! empty( $_REQUEST[ $filter . '_start' ] ) ? sanitize_text_field( wp_unslash( $_REQUEST[ $filter . '_start' ] ) ) : null;
450 $end = ! empty( $_REQUEST[ $filter . '_end' ] ) ? sanitize_text_field( wp_unslash( $_REQUEST[ $filter . '_end' ] ) ) : null;
451
452 update_post_meta( $post_id, $filter . '_start', trim( $start ) );
453 update_post_meta( $post_id, $filter . '_end', trim( $end ) );
454 } else {
455 delete_post_meta( $post_id, $filter . '_start' );
456 delete_post_meta( $post_id, $filter . '_end' );
457 }
458 }
459 }
460
461 // Extra css.
462 $extraFields = Options::extraStyle();
463 $extraTypes = [ 'color', 'size', 'weight', 'alignment' ];
464
465 foreach ( $extraFields as $key => $title ) {
466 foreach ( $extraTypes as $type ) {
467 $newKew = $key . "_{$type}";
468 if ( isset( $_REQUEST[ $newKew ] ) ) {
469 $value = sanitize_text_field( wp_unslash( $_REQUEST[ $newKew ] ) );
470
471 update_post_meta( $post_id, $newKew, $value );
472 }
473 }
474 }
475
476 if ( isset( $_POST['_tpg_last_active_tab'] ) && $active_tab = sanitize_text_field( wp_unslash( $_POST['_tpg_last_active_tab'] ) ) ) {
477 update_post_meta( $post_id, '_tpg_last_active_tab', $active_tab );
478 }
479
480 }
481 }
482