PluginProbe ʕ •ᴥ•ʔ
The Post Grid – Shortcode, Gutenberg Blocks and Elementor Addon for Post Grid / 4.1.2
The Post Grid – Shortcode, Gutenberg Blocks and Elementor Addon for Post Grid v4.1.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 4 years ago MetaController.php 4 years ago NoticeController.php 4 years ago PostTypeController.php 4 years ago SettingsController.php 4 years ago UpgradeController.php 4 years ago
MetaController.php
379 lines
1 <?php
2
3
4 namespace RT\ThePostGrid\Controllers\Admin;
5
6
7 use RT\ThePostGrid\Helpers\Fns;
8 use RT\ThePostGrid\Helpers\Options;
9
10 class MetaController {
11 function __construct() {
12 // actions
13 add_action( 'admin_head', array( $this, 'admin_head' ) );
14 add_action( 'edit_form_after_title', array( $this, 'tpg_sc_after_title' ) );
15 add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) );
16 add_action( 'save_post', array( $this, 'save_post' ), 10, 2 );
17 add_filter( 'manage_edit-rttpg_columns', array( $this, 'arrange_rttpg_columns' ) );
18 add_action( 'manage_rttpg_posts_custom_column', array( $this, 'manage_rttpg_columns' ), 10, 2 );
19 }
20
21 public function manage_rttpg_columns( $column ) {
22 switch ( $column ) {
23 case 'shortcode':
24 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">';
25 break;
26 default:
27 break;
28 }
29 }
30
31 function arrange_rttpg_columns( $columns ) {
32 $shortcode = array( 'shortcode' => __( 'Shortcode', 'the-post-grid' ) );
33
34 return array_slice( $columns, 0, 2, true ) + $shortcode + array_slice( $columns, 1, null, true );
35 }
36
37 function admin_enqueue_scripts() {
38
39 global $pagenow, $typenow;
40
41 if ( $typenow == 'tpg_builder' ) {
42 wp_enqueue_style( 'rt-tpg-admin' );
43 }
44
45 // validate page
46 if ( ! in_array( $pagenow, array( 'post.php', 'post-new.php' ) ) ) {
47 return;
48 }
49
50 if ( $typenow != rtTPG()->post_type ) {
51 return;
52 }
53
54 wp_dequeue_script( 'autosave' );
55 wp_enqueue_media();
56
57 $select2Id = 'rt-select2';
58 if ( class_exists( 'WPSEO_Admin_Asset_Manager' ) && class_exists( 'Avada' ) ) {
59 $select2Id = 'yoast-seo-select2';
60 } elseif ( class_exists( 'WPSEO_Admin_Asset_Manager' ) ) {
61 $select2Id = 'yoast-seo-select2';
62 } elseif ( class_exists( 'Avada' ) ) {
63 $select2Id = 'select2-avada-js';
64 }
65
66 // scripts
67 wp_enqueue_script( array(
68 'jquery',
69 'jquery-ui-datepicker',
70 'wp-color-picker',
71 $select2Id,
72 'imagesloaded',
73 'rt-isotope-js',
74 'rt-tpg-admin',
75 'rt-tpg-admin-preview',
76 ) );
77
78 // styles
79 wp_enqueue_style( array(
80 'wp-color-picker',
81 'rt-select2',
82 'rt-fontawsome',
83 'rt-tpg-admin',
84 'rt-tpg-admin-preview',
85 ) );
86
87 wp_localize_script( 'rt-tpg-admin', 'rttpg',
88 array(
89 'nonceID' => rtTPG()->nonceId(),
90 'nonce' => wp_create_nonce( rtTPG()->nonceText() ),
91 'ajaxurl' => admin_url( 'admin-ajax.php' )
92 ) );
93
94 }
95
96 function admin_head() {
97
98 add_meta_box(
99 'rttpg_meta',
100 __( 'Short Code Generator', 'the-post-grid' ),
101 array( $this, 'rttpg_meta_settings_selection' ),
102 rtTPG()->post_type,
103 'normal',
104 'high' );
105
106 add_meta_box(
107 rtTPG()->post_type . '_sc_preview_meta',
108 __( 'Layout Preview', 'the-post-grid' ),
109 array( $this, 'tpg_sc_preview_selection' ),
110 rtTPG()->post_type,
111 'normal',
112 'high' );
113
114 add_meta_box(
115 'rt_plugin_sc_pro_information',
116 __( 'Documentation', 'the-post-grid' ),
117 array( $this, 'rt_plugin_sc_pro_information' ),
118 rtTPG()->post_type,
119 'side',
120 'low'
121 );
122
123 }
124
125 function rt_plugin_sc_pro_information( $post ) {
126 $html = '';
127 if ( $post === 'settings' ) {
128 $html .= '<div class="rt-document-box rt-update-pro-btn-wrap">
129 <a href="https://www.radiustheme.com/the-post-grid-pro-for-wordpress/" target="_blank" class="rt-update-pro-btn">' . __( "Update Pro To Get More Features", "the-post-grid" ) . '</a>
130 </div>';
131 } else {
132 if ( ! rtTPG()->hasPro() ) {
133 $html .= sprintf( '<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">Pro Features</h3>%s</div></div>', Options::get_pro_feature_list() );
134 }
135 }
136 $html .= sprintf( '<div class="rt-document-box">
137 <div class="rt-box-icon"><i class="dashicons dashicons-media-document"></i></div>
138 <div class="rt-box-content">
139 <h3 class="rt-box-title">%1$s</h3>
140 <p>%2$s</p>
141 <a href="https://www.radiustheme.com/docs/the-post-grid/" target="_blank" class="rt-admin-btn">%1$s</a>
142 </div>
143 </div>',
144 __( "Documentation", 'the-post-grid' ),
145 __( "Get started by spending some time with the documentation we included step by step process with screenshots with video.", 'the-post-grid' )
146 );
147
148 $html .= '<div class="rt-document-box">
149 <div class="rt-box-icon"><i class="dashicons dashicons-sos"></i></div>
150 <div class="rt-box-content">
151 <h3 class="rt-box-title">Need Help?</h3>
152 <p>Stuck with something? Please create a
153 <a href="https://www.radiustheme.com/contact/">ticket here</a> or post on <a href="https://www.facebook.com/groups/234799147426640/">facebook group</a>. For emergency case join our <a href="https://www.radiustheme.com/">live chat</a>.</p>
154 <a href="https://www.radiustheme.com/contact/" target="_blank" class="rt-admin-btn">' . __( "Get Support", "the-post-grid" ) . '</a>
155 </div>
156 </div>';
157
158 echo $html;
159 }
160
161 /**
162 * Preview section
163 */
164 function tpg_sc_preview_selection() {
165 $html = null;
166 $html .= "<div class='rt-response'></div>";
167 $html .= "<div id='tpg-preview-container'></div>";
168 echo $html;
169
170 }
171
172
173 function tpg_sc_after_title( $post ) {
174
175 if ( rtTPG()->post_type !== $post->post_type ) {
176 return;
177 }
178 $html = null;
179 $html .= '<div class="postbox rt-after-title" style="margin-bottom: 0;"><div class="inside">';
180 $html .= '<p><input type="text" onfocus="this.select();" readonly="readonly" value="[the-post-grid id=&quot;' . $post->ID . '&quot; title=&quot;' . $post->post_title . '&quot;]" class="large-text code rt-code-sc">
181 <input type="text" onfocus="this.select();" readonly="readonly" value="&#60;&#63;php echo do_shortcode( &#39;[the-post-grid id=&quot;' . $post->ID . '&quot; title=&quot;' . $post->post_title . '&quot;]&#39; ); &#63;&#62;" class="large-text code rt-code-sc">
182 </p>';
183 $html .= '</div></div>';
184
185 echo $html;
186 }
187
188 function rttpg_meta_settings_selection( $post ) {
189
190 $last_tab = trim( get_post_meta( $post->ID, '_tpg_last_active_tab', true ) );
191 $last_tab = $last_tab ? $last_tab : 'sc-post-post-source';
192 $post = array(
193 'post' => $post
194 );
195 wp_nonce_field( rtTPG()->nonceText(), rtTPG()->nonceId() );
196 $html = null;
197 $html .= '<div id="sc-tabs" class="rttpg-wrapper rt-tab-container rt-setting-holder">';
198 $html .= sprintf( '<ul class="rt-tab-nav">
199 <li%s><a href="#sc-post-post-source">%s</a></li>
200 <li%s><a href="#sc-post-layout-settings">%s</a></li>
201 <li%s><a href="#sc-settings">%s</a></li>
202 <li%s><a href="#sc-field-selection">%s</a></li>
203 <li%s><a href="#sc-style">%s</a></li>
204 </ul>',
205 $last_tab == "sc-post-post-source" ? ' class="active"' : '',
206 __( 'Query Build', 'the-post-grid' ),
207 $last_tab == "sc-post-layout-settings" ? ' class="active"' : '',
208 __( 'Layout Settings', 'the-post-grid' ),
209 $last_tab == "sc-settings" ? ' class="active"' : '',
210 __( 'Settings', 'the-post-grid' ),
211 $last_tab == "sc-field-selection" ? ' class="active"' : '',
212 __( 'Field Selection', 'the-post-grid' ),
213 $last_tab == "sc-style" ? ' class="active"' : '',
214 __( 'Style', 'the-post-grid' )
215 );
216
217 $html .= sprintf( '<div id="sc-post-post-source" class="rt-tab-content"%s>', $last_tab == "sc-post-post-source" ? ' style="display:block"' : '' );
218 $html .= Fns::view( 'settings.post-source', $post, true );
219 $html .= '</div>';
220
221 $html .= sprintf( '<div id="sc-post-layout-settings" class="rt-tab-content"%s>', $last_tab == "sc-post-layout-settings" ? ' style="display:block"' : '' );
222 $html .= Fns::view( 'settings.layout-settings', $post, true );
223 $html .= '</div>';
224
225 $html .= sprintf( '<div id="sc-settings" class="rt-tab-content"%s>', $last_tab == "sc-settings" ? ' style="display:block"' : '' );
226 $html .= Fns::view( 'settings.sc-settings', $post, true );
227 $html .= '</div>';
228
229 $html .= sprintf( '<div id="sc-field-selection" class="rt-tab-content"%s>', $last_tab == "sc-field-selection" ? ' style="display:block"' : '' );
230 $html .= Fns::view( 'settings.item-fields', $post, true );
231 $html .= '</div>';
232
233 $html .= sprintf( '<div id="sc-style" class="rt-tab-content"%s>', $last_tab == "sc-style" ? ' style="display:block"' : '' );
234 $html .= Fns::view( 'settings.style', $post, true );
235 $html .= '</div>';
236 $html .= sprintf( '<input type="hidden" id="_tpg_last_active_tab" name="_tpg_last_active_tab" value="%s"/>', $last_tab );
237 $html .= '</div>';
238 echo $html;
239 }
240
241 function save_post( $post_id, $post ) {
242
243 if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
244 return $post_id;
245 }
246
247 if ( ! Fns::verifyNonce() ) {
248 return $post_id;
249 }
250
251 if ( rtTPG()->post_type != $post->post_type ) {
252 return $post_id;
253 }
254
255 $mates = Fns::rtAllOptionFields();
256 foreach ( $mates as $metaKey => $field ) {
257 $rValue = ! empty( $_REQUEST[ $metaKey ] ) ? $_REQUEST[ $metaKey ] : null;
258 $value = Fns::sanitize( $field, $rValue );
259 if ( empty( $field['multiple'] ) ) {
260 update_post_meta( $post_id, $metaKey, $value );
261 } else {
262 delete_post_meta( $post_id, $metaKey );
263 if ( is_array( $value ) && ! empty( $value ) ) {
264 foreach ( $value as $item ) {
265 add_post_meta( $post_id, $metaKey, $item );
266 }
267 }
268 }
269 }
270
271 $post_filter = ( isset( $_REQUEST['post_filter'] ) ? $_REQUEST['post_filter'] : array() );
272 $advFilter = Options::rtTPAdvanceFilters();
273 foreach ( $advFilter['post_filter']['options'] as $filter => $fValue ) {
274 if ( $filter == 'tpg_taxonomy' ) {
275 delete_post_meta( $post_id, $filter );
276 if ( ! empty( $_REQUEST[ $filter ] ) && is_array( $_REQUEST[ $filter ] ) ) {
277 foreach ( $_REQUEST[ $filter ] as $tax ) {
278 if ( in_array( $filter, $post_filter ) ) {
279 add_post_meta( $post_id, $filter, trim( $tax ) );
280 }
281 delete_post_meta( $post_id, 'term_' . $tax );
282 $tt = isset( $_REQUEST[ 'term_' . $tax ] ) ? $_REQUEST[ 'term_' . $tax ] : array();
283 if ( is_array( $tt ) && ! empty( $tt ) && in_array( $filter, $post_filter ) ) {
284 foreach ( $tt as $termID ) {
285 add_post_meta( $post_id, 'term_' . $tax, trim( $termID ) );
286 }
287 }
288 $tto = isset( $_REQUEST[ 'term_operator_' . $tax ] ) ? $_REQUEST[ 'term_operator_' . $tax ] : null;
289 if ( $tto ) {
290 update_post_meta( $post_id, 'term_operator_' . $tax, trim( $tto ) );
291 }
292 }
293 $filterCount = isset( $_REQUEST[ $filter ] ) ? $_REQUEST[ $filter ] : array();
294 $tr = isset( $_REQUEST['taxonomy_relation'] ) ? $_REQUEST['taxonomy_relation'] : null;
295 if ( count( $filterCount ) > 1 && $tr ) {
296 update_post_meta( $post_id, 'taxonomy_relation', trim( $tr ) );
297 } else {
298 delete_post_meta( $post_id, 'taxonomy_relation' );
299 }
300
301 }
302 } else if ( $filter == 'author' ) {
303 delete_post_meta( $post_id, 'author' );
304 $authors = isset( $_REQUEST['author'] ) ? $_REQUEST['author'] : array();
305 if ( is_array( $authors ) && ! empty( $authors ) && in_array( 'author', $post_filter ) ) {
306 foreach ( $authors as $authorID ) {
307 add_post_meta( $post_id, 'author', trim( $authorID ) );
308 }
309 }
310 } else if ( $filter == 'tpg_post_status' ) {
311 delete_post_meta( $post_id, $filter );
312 $statuses = isset( $_REQUEST[ $filter ] ) ? $_REQUEST[ $filter ] : array();
313 if ( is_array( $statuses ) && ! empty( $statuses ) && in_array( $filter, $post_filter ) ) {
314 foreach ( $statuses as $post_status ) {
315 add_post_meta( $post_id, $filter, trim( $post_status ) );
316 }
317 }
318 } else if ( $filter == 's' ) {
319 delete_post_meta( $post_id, 's' );
320 $s = isset( $_REQUEST['s'] ) ? $_REQUEST['s'] : null;
321 if ( $s && in_array( 's', $post_filter ) ) {
322 update_post_meta( $post_id, 's', sanitize_text_field( trim( $s ) ) );
323 }
324 } else if ( $filter == 'order' ) {
325 if ( in_array( 'order', $post_filter ) ) {
326 $order = isset( $_REQUEST['order'] ) ? $_REQUEST['order'] : null;
327 if ( $order && in_array( 'order', $post_filter ) ) {
328 update_post_meta( $post_id, 'order', sanitize_text_field( trim( $order ) ) );
329 }
330 $order_by = isset( $_REQUEST['order_by'] ) ? $_REQUEST['order_by'] : null;
331 if ( $order_by && in_array( 'order', $post_filter ) ) {
332 update_post_meta( $post_id, 'order_by', sanitize_text_field( trim( $order_by ) ) );
333 }
334 $tpg_meta_key = isset( $_REQUEST['tpg_meta_key'] ) ? $_REQUEST['tpg_meta_key'] : null;
335 if ( in_array( $order_by, array_keys( Options::rtMetaKeyType() ) ) && $tpg_meta_key && in_array( 'order', $post_filter ) ) {
336 update_post_meta( $post_id, 'tpg_meta_key', sanitize_text_field( trim( $tpg_meta_key ) ) );
337 } else {
338 delete_post_meta( $post_id, 'tpg_meta_key' );
339 }
340 } else {
341 delete_post_meta( $post_id, 'order' );
342 delete_post_meta( $post_id, 'tpg_meta_key' );
343 delete_post_meta( $post_id, 'order_by' );
344 }
345 } else if ( $filter == 'date_range' ) {
346 if ( in_array( 'date_range', $post_filter ) ) {
347 $start = ! empty( $_REQUEST[ $filter . '_start' ] ) ? $_REQUEST[ $filter . '_start' ] : null;
348 $end = ! empty( $_REQUEST[ $filter . '_end' ] ) ? $_REQUEST[ $filter . '_end' ] : null;
349 update_post_meta( $post_id, $filter . '_start', trim( $start ) );
350 update_post_meta( $post_id, $filter . '_end', trim( $end ) );
351 } else {
352 delete_post_meta( $post_id, $filter . '_start' );
353 delete_post_meta( $post_id, $filter . '_end' );
354 }
355 }
356 }
357
358 // Extra css
359
360 $extraFields = Options::extraStyle();
361 $extraTypes = array( 'color', 'size', 'weight', 'alignment' );
362
363 foreach ( $extraFields as $key => $title ) {
364 foreach ( $extraTypes as $type ) {
365 $newKew = $key . "_{$type}";
366 if ( isset( $_REQUEST[ $newKew ] ) ) {
367 $value = trim( $_REQUEST[ $newKew ] );
368 update_post_meta( $post_id, $newKew, $value );
369 }
370 }
371 }
372
373
374 if ( isset( $_POST['_tpg_last_active_tab'] ) && $active_tab = trim( $_POST['_tpg_last_active_tab'] ) ) {
375 update_post_meta( $post_id, '_tpg_last_active_tab', $_POST['_tpg_last_active_tab'] );
376 }
377
378 } // end function
379 }