· 6 years ago · Sep 16, 2019, 06:42 AM
1<?php
2
3
4/**
5 * globals to hold the state for all pages
6 */
7global $tdb_state_single_page, $tdb_state_single, $tdb_state_category, $tdb_state_author, $tdb_state_search, $tdb_state_date, $tdb_state_tag, $tdb_state_attachment;
8
9// load the config
10require_once "tdb_util.php";
11require_once "tdb_config.php";
12add_action('tdc_loaded', array('tdb_config', 'on_tdc_loaded'), 10); //the theme runs on 9 priority... so we can change stuff if we want
13
14
15require_once "tdb_state_base.php";
16require_once "tdb_state_template.php";
17require_once "tdb_state_content.php";
18require_once "tdb_state.php"; // state for the cloud template plugin, used on single post templates > autoload(inf) posts feature.
19require_once "tdb_global_wp_query.php";
20
21
22require_once "tdb_module.php";
23require_once "tdb_ajax.php";
24require_once "tdb_cpt.php"; // load the cpt things
25require_once "tdb_menu.php"; // load the td menu shortcode support
26
27// make the page state
28require_once TDB_TEMPLATE_BUILDER_DIR . "/state/page/tdb_state_single_page.php";
29$tdb_state_single_page = new tdb_state_single_page();
30
31// make the single post state
32require_once TDB_TEMPLATE_BUILDER_DIR . "/state/single/tdb_state_single.php";
33$tdb_state_single = new tdb_state_single(); // the state already comes with default data
34
35// the category state
36require_once TDB_TEMPLATE_BUILDER_DIR . "/state/category/tdb_state_category.php";
37$tdb_state_category = new tdb_state_category(); // the state already comes with default data
38
39// the author state
40require_once TDB_TEMPLATE_BUILDER_DIR . "/state/author/tdb_state_author.php";
41$tdb_state_author = new tdb_state_author(); // the state already comes with default data
42
43// the search state
44require_once TDB_TEMPLATE_BUILDER_DIR . "/state/search/tdb_state_search.php";
45$tdb_state_search = new tdb_state_search(); // the state already comes with default data
46
47// the date state
48require_once TDB_TEMPLATE_BUILDER_DIR . "/state/date/tdb_state_date.php";
49$tdb_state_date = new tdb_state_date(); // the state already comes with default data
50
51// the tag state
52require_once TDB_TEMPLATE_BUILDER_DIR . "/state/tag/tdb_state_tag.php";
53$tdb_state_tag = new tdb_state_tag(); // the state already comes with default data
54
55// the attachment state
56require_once TDB_TEMPLATE_BUILDER_DIR . "/state/attachment/tdb_state_attachment.php";
57$tdb_state_attachment = new tdb_state_attachment(); // the state already comes with default data
58
59// theme panel vue endpoint
60require_once TDB_TEMPLATE_BUILDER_DIR . "/includes/panel/tdb_panel_vue.php";
61
62/**
63 * Load the single state for now
64 * - template_include runs after template_redirect!
65 */
66require_once TDB_TEMPLATE_BUILDER_DIR . "/state/tdb_state_loader.php";
67add_action('template_redirect', array('tdb_state_loader', 'on_template_redirect_load_state')); // we use this for front end. (we need the global wp_query)
68add_action('tdc_loaded', array('tdb_state_loader', 'on_tdc_loaded_load_state')); // we use this for ajax and composer iframe. (we don't have the global wp_query while editing)
69
70/**
71 * Set the tdb_state
72 */
73$tdb_action = tdb_util::get_get_val( 'tdb_action' );
74if ( false === $tdb_action ) {
75 tdb_state::set_is_ajax( false );
76} else {
77 tdb_state::set_is_ajax( true );
78}
79
80/**
81 * Modify the main query for wp templates pages
82 * - we need to do this to set the shortcode posts limit and get the right pagination
83 * - we need this on 'tdc_loaded' beacuse we need to use the is_live_editor_ajax/is_live_editor_iframe methods to check for composer's iframe and ajax rendering blocks @see tdc_state
84 * - on tdc_init hook where this functions file is loaded we're to early to use this methods
85 */
86add_action('tdc_loaded', function() {
87
88 /**
89 * DISQUS plugin compatibility
90 * this prevents disqus from loading on composer iframe/ajax requests and on autoloaded posts or if posts autoload feature is enabled
91 */
92 if ( tdc_state::is_live_editor_iframe() ||
93 tdc_state::is_live_editor_ajax() ||
94 tdb_state::is_ajax()
95 ) {
96 add_filter( 'dsq_can_load', '__return_false' );
97 }
98
99 /**
100 * DISQUS plugin compatibility
101 * this hook determines if a cloud single post template uses the 'tdb_single_comments' shortcode
102 * ..and prevents disqus from trying to load if it doesn't use the 'tdb_single_comments' comments
103 */
104 add_action( 'pre_get_posts', function( $query ) {
105
106 if ( is_admin() ||
107 ! $query->is_main_query() ||
108 tdc_state::is_live_editor_ajax() ||
109 tdc_state::is_live_editor_iframe() ||
110 td_util::is_mobile_theme()
111 )
112 return;
113
114 if ( is_single() ) {
115 //print_r($query);
116
117 if ( isset( $query->query['post_type'] ) && $query->query['post_type'] !== 'post' ) {
118 return;
119 }
120
121 if ( isset( $query->query['name'] ) ) {
122 $post_obj = get_page_by_path( $query->query['name'], OBJECT, 'post' );
123 }
124
125 $post_id = '';
126 if ( !empty( $post_obj ) ) {
127 $post_id = $post_obj->ID;
128 }
129
130 // check if we have a specific template set on the current post
131 $td_post_theme_settings = td_util::get_post_meta_array( $post_id, 'td_post_theme_settings' );
132
133 $tdb_template_id = '';
134
135 if ( !empty( $td_post_theme_settings['td_post_template'] ) ) {
136 $single_template_id = $td_post_theme_settings['td_post_template'];
137
138 if ( td_global::is_tdb_template( $single_template_id ) ) {
139
140 // make sure the template exists, maybe it was deleted or something
141 if ( td_global::is_tdb_template( $single_template_id, true ) ) {
142
143 $tdb_template_id = td_global::tdb_get_template_id($single_template_id);
144
145 } else {
146 // just reset the post template here, the panel default post template will kick in and load, if available
147 $td_post_theme_settings['td_post_template'] = '';
148 update_post_meta( $post_id, 'td_post_theme_settings', $td_post_theme_settings );
149 }
150 }
151 } else {
152
153 // read the global setting
154 $default_template_id = td_util::get_option('td_default_site_post_template');
155
156 // check the default template
157 if ( td_global::is_tdb_template( $default_template_id ) ) {
158
159 // make sure the template exists, maybe it was deleted or something
160 if ( td_global::is_tdb_template( $default_template_id, true ) ) {
161
162 // load the default tdb template
163 $tdb_template_id = td_global::tdb_get_template_id($default_template_id);
164
165 } else {
166
167 // if we have an non-existent cloud template update the default site wide post template
168 td_util::update_option('td_default_site_post_template', '' );
169 }
170
171 }
172 }
173
174 if ( !empty( $tdb_template_id ) ) {
175
176 // load the cloud template
177 $wp_query_template = new WP_Query( array(
178 'p' => $tdb_template_id,
179 'post_type' => 'tdb_templates',
180 )
181 );
182 }
183
184 // if we have a template look for the 'tdb_single_comments' shortcode
185 if ( !empty( $wp_query_template ) && $wp_query_template->have_posts() ) {
186 $tdb_single_comments = tdb_util::get_shortcode( $wp_query_template->post->post_content, 'tdb_single_comments' );
187
188 if ( ! $tdb_single_comments || td_util::get_option('tdb_p_autoload_status', 'off') === 'on' ) {
189 add_filter( 'dsq_can_load', '__return_false' );
190 }
191 }
192
193 }
194
195 });
196
197 /**
198 * the autoload(infinite) posts script.
199 * it's needed and loaded just on frontend
200 */
201 if ( !tdb_state::is_ajax() && !tdc_state::is_live_editor_ajax() && !tdc_state::is_live_editor_iframe() && !td_util::is_mobile_theme() ) {
202 add_filter('wp_enqueue_scripts', function(){
203 if ( TDB_DEPLOY_MODE == 'dev' ) {
204 wp_enqueue_script( 'tdbAutoload', TDB_URL . '/assets/js/tdbAutoload.js', array( 'jquery', 'underscore' ), TD_CLOUD_LIBRARY, true);
205 } else {
206 wp_enqueue_script( 'tdb_js_posts_autoload', TDB_URL . '/assets/js/js_posts_autoload.min.js', array( 'jquery', 'underscore' ), TD_CLOUD_LIBRARY, true );
207 }
208 });
209 }
210
211 add_action( 'pre_get_posts', function( $query ) {
212 if ( ! is_admin() && ! $query->is_main_query() )
213 return;
214
215 $orderby = $query->get('orderby');
216
217 if ( 'tdb_template_type' == $orderby ) {
218 $query->set( 'meta_key', 'tdb_template_type' );
219 }
220
221 $template_type = $query->get('template_type');
222
223 if ( ! empty( $template_type ) ) {
224 $query->set( 'meta_key', 'tdb_template_type' );
225 $query->set( 'meta_value', $template_type );
226 }
227 });
228
229 /**
230 * - filter 'wpseo_title' is used by WordPress SEO plugin and, by default, it returns a seo title that hasn't the page number inside of it,
231 * when it's used on td pages [those who have a custom pagination]. At that seo title is added the page info, and just for pages greater than 1
232 */
233 add_action( 'pre_get_posts', function($query) {
234
235 if( is_page() && $query->is_main_query() ){
236
237 $page_id = isset($query->queried_object) ? $query->queried_object->ID : $query->query_vars['page_id'];
238
239 // load the page template
240 $page_template = new WP_Query(array(
241 'p' => $page_id,
242 'post_type' => 'page',
243 )
244 );
245
246 if (!empty($page_template)) {
247
248 // get the page template
249 $_wp_page_template = get_post_meta($page_id, '_wp_page_template', true);
250
251 $tdb_is_loop = tdb_util::get_shortcode($page_template->post->post_content, 'tdb_loop');
252 $tdb_is_loop_2 = tdb_util::get_shortcode($page_template->post->post_content, 'tdb_loop_2');
253
254 // don't apply on page-pagebuilder-latest.php
255 if ( 'page-pagebuilder-latest.php' !== $_wp_page_template & $tdb_is_loop === true || $tdb_is_loop_2 === true ) {
256 add_filter('wpseo_title', 'td_wpseo_title_for_loop', 11, 1);
257
258 function td_wpseo_title_for_loop($seo_title){
259
260 $td_page = (get_query_var('page')) ? get_query_var('page') : 1; //rewrite the global var
261 $td_paged = (get_query_var('paged')) ? get_query_var('paged') : 1; //rewrite the global var
262
263 if ($td_paged > $td_page) {
264 $local_paged = $td_paged;
265 } else {
266 $local_paged = $td_page;
267 }
268
269 // the custom title is when the pagination is greater than 1
270 if ($local_paged > 1) {
271 return $seo_title . ' - ' . __td('Page', TD_THEME_NAME) . ' ' . $local_paged;
272 }
273
274 return $seo_title;
275 }
276 }
277 }
278
279 }
280
281 } );
282
283 /**
284 * Head canonical links on pages with numbered pagination (loop shortcode).
285 *
286 */
287 add_action( 'wp_head', function() {
288
289 global $tdb_state_single_page;
290
291 if( is_main_query() && is_page() ){
292
293 global $wp_query;
294
295 $page_id = isset($wp_query->queried_object) ? $wp_query->queried_object->ID : $wp_query->query_vars['page_id'];
296
297 // load the page template
298 $page_template = new WP_Query(array(
299 'p' => $page_id,
300 'post_type' => 'page',
301 )
302 );
303
304 if (! empty($page_template)) {
305
306 // get the page template
307 $_wp_page_template = get_post_meta($page_id, '_wp_page_template', true);
308
309 $tdb_is_loop_pagination = tdb_util::get_shortcode_att($page_template->post->post_content, 'tdb_loop','ajax_pagination');
310 $tdb_is_loop_2_pagination = tdb_util::get_shortcode_att($page_template->post->post_content, 'tdb_loop_2','ajax_pagination');
311
312 // don't apply on page-pagebuilder-latest.php
313 if ( 'page-pagebuilder-latest.php' !== $_wp_page_template && $tdb_is_loop_pagination === 'numbered' ) {
314
315 $atts = array();
316
317 $limit = tdb_util::get_shortcode_att($page_template->post->post_content, 'tdb_loop', 'limit');
318 if (!empty($limit)) {
319 $atts['post_ids'] = $limit;
320 }
321 $offset = tdb_util::get_shortcode_att($page_template->post->post_content, 'tdb_loop', 'offset');
322 if (!empty($offset)) {
323 $atts['post_ids'] = $offset;
324 }
325 $post_ids = tdb_util::get_shortcode_att($page_template->post->post_content, 'tdb_loop', 'post_ids');
326 if (!empty($post_ids)) {
327 $atts['post_ids'] = $post_ids;
328 }
329
330 $atts = array(
331 'limit' => $limit,
332 'offset' => $offset,
333 'post_ids' => $post_ids
334 );
335
336 $loop_data = $tdb_state_single_page->loop->__invoke($atts);
337
338 }
339
340 // don't apply on page-pagebuilder-latest.php
341 if ( 'page-pagebuilder-latest.php' !== $_wp_page_template && $tdb_is_loop_2_pagination === 'numbered' ) {
342
343 $atts = array();
344
345 $limit = tdb_util::get_shortcode_att($page_template->post->post_content, 'tdb_loop_2', 'limit');
346 if (!empty($limit)) {
347 $atts['post_ids'] = $limit;
348 }
349 $offset = tdb_util::get_shortcode_att($page_template->post->post_content, 'tdb_loop_2', 'offset');
350 if (!empty($offset)) {
351 $atts['post_ids'] = $offset;
352 }
353 $post_ids = tdb_util::get_shortcode_att($page_template->post->post_content, 'tdb_loop_2', 'post_ids');
354 if (!empty($post_ids)) {
355 $atts['post_ids'] = $post_ids;
356 }
357
358 $atts = array(
359 'limit' => $limit,
360 'offset' => $offset,
361 'post_ids' => $post_ids
362 );
363
364 $loop_data = $tdb_state_single_page->loop->__invoke($atts);
365
366 }
367
368 if (!empty($loop_data)) {
369
370 $max_page = (int)$loop_data ["loop_pagination"]['max_page'];
371
372 $td_page = get_query_var('page') ? get_query_var('page') : 1; //rewrite the global var
373 $td_paged = get_query_var('paged') ? get_query_var('paged') : 1; //rewrite the global var
374
375 $td_page = intval($td_page);
376 $td_paged = intval($td_paged);
377
378 //paged works on single pages, page - works on homepage
379 if ($td_paged > $td_page) {
380 $paged = $td_paged;
381 } else {
382 $paged = $td_page;
383 }
384
385 // Remove the wp action links
386 remove_action('wp_head', 'rel_canonical');
387 remove_action('wp_head', 'adjacent_posts_rel_link_wp_head');
388
389 if (class_exists('WPSEO_Frontend')) {
390 // Remove the canonical action of the Yoast SEO plugin
391 remove_action('wpseo_head', array(WPSEO_Frontend::get_instance(), 'canonical'), 20);
392 }
393
394 if (!is_amp_endpoint()) {
395 echo '<link rel="canonical" href="' . get_pagenum_link($paged) . '"/>';
396
397
398 if ($paged > 1) {
399 echo '<link rel="prev" href="' . get_pagenum_link($paged - 1) . '"/>';
400 }
401 if ($paged < $max_page) {
402 echo '<link rel="next" href="' . get_pagenum_link($paged + 1) . '"/>';
403 }}
404 }
405
406 }
407 }
408 }, 1);
409
410
411 add_action( 'pre_get_posts', 'tdb_modify_main_query_for_wp_templates_page' );
412 function tdb_modify_main_query_for_wp_templates_page( $query ) {
413
414 // checking for main query ONLY ON frontend - Does not run on ajax or TDC iFrame!!!
415 if( ( !is_admin() && $query->is_main_query() && !tdc_state::is_live_editor_ajax() && !tdc_state::is_live_editor_iframe()) ) {
416
417 $template_id = '';
418
419 if ( is_category() && ! td_util::is_mobile_theme() ) {
420
421 $current_category_obj = '';
422 $current_category_id = '';
423
424 if ( isset( $query->query['cat'] ) ) {
425 $current_category_obj = get_category( $query->query['cat'] );
426 } elseif( isset( $query->query_vars['category_name'] ) ) {
427 $current_category_obj = get_category_by_slug( $query->query_vars['category_name'] );
428 }
429
430 if ( !empty( $current_category_obj ) ) {
431 $current_category_id = $current_category_obj->cat_ID;
432 }
433
434 // read the individual cat template
435 $tdb_individual_category_template = td_util::get_category_option( $current_category_id, 'tdb_category_template' );
436
437 // read the global template
438 $tdb_category_template = td_options::get( 'tdb_category_template' );
439
440 if ( !empty( $tdb_individual_category_template ) && td_global::is_tdb_template( $tdb_individual_category_template, true ) ) {
441 $template_id = td_global::tdb_get_template_id( $tdb_individual_category_template );
442 } else {
443 if ( td_global::is_tdb_template( $tdb_category_template, true ) ) {
444 $template_id = td_global::tdb_get_template_id( $tdb_category_template );
445 }
446 }
447
448
449 } elseif ( is_author() && ! td_util::is_mobile_theme() ) {
450
451 // user templates
452 $tdb_author_templates = td_util::get_option('tdb_author_templates');
453 // author id
454 $author_id = '';
455 if (!empty($query->query_vars['author'])) {
456 $author_id = $query->query_vars['author'];
457 } else if(!empty($query->query_vars['author_name'])) {
458 $user = get_user_by('slug', $query->query_vars['author_name']);
459 if( $user ){
460 $author_id = $user->ID;
461 }
462 }
463
464 if ( !empty( $tdb_author_templates[$author_id] ) && td_global::is_tdb_template( $tdb_author_templates[$author_id], true ) ) {
465 // individual author template
466 $template_id = td_global::tdb_get_template_id( $tdb_author_templates[$author_id] );
467 } else {
468 // default template
469 $tdb_author_template = td_options::get('tdb_author_template');
470 if ( td_global::is_tdb_template( $tdb_author_template, true ) ) {
471 $template_id = td_global::tdb_get_template_id( $tdb_author_template );
472 }
473 }
474
475 } elseif ( is_search() && ! td_util::is_mobile_theme() ) {
476
477 // read the template
478 $tdb_search_template = td_options::get( 'tdb_search_template' );
479 if ( td_global::is_tdb_template( $tdb_search_template, true ) ) {
480 $template_id = td_global::tdb_get_template_id( $tdb_search_template );
481 }
482
483 } elseif ( is_date() && ! td_util::is_mobile_theme() ) {
484
485 // read the template
486 $tdb_date_template = td_options::get( 'tdb_date_template' );
487 if ( td_global::is_tdb_template( $tdb_date_template, true ) ) {
488 $template_id = td_global::tdb_get_template_id( $tdb_date_template );
489 }
490 } elseif ( is_tag() && ! td_util::is_mobile_theme() ) {
491
492 // read the default tag template
493 $tdb_tag_template = td_options::get( 'tdb_tag_template' );
494 if ( td_global::is_tdb_template( $tdb_tag_template, true ) ) {
495 $template_id = td_global::tdb_get_template_id( $tdb_tag_template );
496 }
497
498 } elseif ( is_page() && ! td_util::is_mobile_theme() ) {
499
500 $page_id = isset($query->queried_object) ? $query->queried_object->ID : $query->query_vars['page_id'];
501
502 // load the page template
503 $page_template = new WP_Query( array(
504 'p' => $page_id,
505 'post_type' => 'page',
506 )
507 );
508
509 if ( !empty( $page_template ) && $page_template->have_posts() ) {
510 $offset = tdb_util::get_shortcode_att( $page_template->post->post_content, 'tdb_loop','offset' );
511 tdb_state_template::set_template_loop_offset( (int)$offset );
512 }
513 }
514
515 if ( !empty( $template_id ) ) {
516
517 // load the tdb template
518 $wp_query_template = new WP_Query( array(
519 'p' => $template_id,
520 'post_type' => 'tdb_templates',
521 )
522 );
523 }
524
525 // if we have a template
526 if ( !empty( $wp_query_template ) && $wp_query_template->have_posts() ) {
527
528 /**
529 * set the tdb_template_overwrite filter
530 * this runs in the theme and is used by plugins to tell the theme not to do the default modifications for the main query on category pages
531 * @see td_modify_main_query_for_category_page in ..\theme\includes\wp_booster\td_wp_booster_functions.php
532 */
533 add_filter( 'tdb_category_template_query_overwrite', function() {
534 return true;
535 });
536
537 // set the template query
538 tdb_state_template::set_wp_query( $wp_query_template );
539
540 $limit = tdb_util::get_shortcode_att( $wp_query_template->post->post_content, 'tdb_loop','limit' );
541
542 if ( empty($limit) )
543 $limit = get_option('posts_per_page');
544
545 $offset = tdb_util::get_shortcode_att( $wp_query_template->post->post_content, 'tdb_loop','offset' );
546 tdb_state_template::set_template_loop_offset( intval($offset) );
547
548 // detect and handle pagination
549 if ( $query->is_paged ) {
550
551 // if we have an offset, manually determine page query offset (offset + current page (minus one) x posts per page)
552 if ( !empty($offset) )
553 $offset = $offset + ( ($query->query_vars['paged']-1) * $limit );
554 }
555
556 // exclude certain posts or pages from your posts loop
557 $post_ids = tdb_util::get_shortcode_att( $wp_query_template->post->post_content, 'tdb_loop','post_ids' );
558
559 if ( !empty($post_ids) ) {
560
561 // split posts ids string
562 $post_ids_array = explode (',', $post_ids);
563 $posts_not_in = array();
564 $posts_in = array();
565
566 // split ids
567 foreach ($post_ids_array as $post_id) {
568 $post_id = trim($post_id);
569
570 // check if the ID is actually a number
571 if (is_numeric($post_id)) {
572 if (intval($post_id) < 0) {
573 $posts_not_in[] = str_replace('-', '', $post_id);
574 } else {
575 $posts_in[] = $post_id;
576 }
577 }
578 }
579
580 // don't pass an empty post__in because it will return has_posts()
581 if (!empty($posts_in)) {
582 $query->set( 'post__in', $posts_in );
583 $query->set( 'orderby', 'post__in' );
584 }
585
586 // set the posts to exclude if any
587 if (!empty($posts_not_in)) {
588 $query->set( 'post__not_in', $posts_not_in );
589 }
590 }
591
592 $sort = tdb_util::get_shortcode_att( $wp_query_template->post->post_content, 'tdb_loop','sort' );
593 switch ($sort) {
594 case 'oldest_posts':
595 $query->set( 'order', 'ASC' );
596 break;
597
598 case 'modified_date':
599 $query->set( 'orderby', 'post_modified' );
600 break;
601
602 case 'alphabetical_order':
603 $query->set( 'orderby', 'title' );
604 $query->set( 'order', 'ASC' );
605 break;
606
607 case 'popular':
608 $query->set( 'meta_key', td_page_views::$post_view_counter_key );
609 $query->set( 'orderby', 'meta_value_num' );
610 $query->set( 'order', 'DESC' );
611 break;
612
613 case 'popular7':
614 $query->set( 'meta_query', array(
615 'relation' => 'AND',
616 array(
617 'key' => td_page_views::$post_view_counter_7_day_total,
618 'type' => 'numeric'
619 ),
620 array(
621 'key' => td_page_views::$post_view_counter_7_day_last_date,
622 'value' => (date('U') - 604800), // current date minus 7 days
623 'type' => 'numeric',
624 'compare' => '>'
625 )
626 ) );
627 $query->set( 'orderby', td_page_views::$post_view_counter_7_day_total );
628 $query->set( 'order', 'DESC' );
629 break;
630
631 case 'review_high':
632 $query->set( 'meta_key', 'td_review_key' );
633 $query->set( 'orderby', 'meta_value_num' );
634 $query->set( 'order', 'DESC' );
635 break;
636
637 case 'comment_count':
638 $query->set( 'orderby', 'comment_count' );
639 $query->set( 'order', 'DESC' );
640 break;
641 }
642
643 // set the query limit/offset/sort
644 $query->set( 'main_query_offset', true );
645 $query->set( 'offset', $offset );
646 $query->set( 'posts_per_page', $limit );
647 }
648 }
649 }
650
651 add_filter( 'found_posts', 'tdb_on_found_posts_adjust_offset_pagination', 10, 2 );
652 function tdb_on_found_posts_adjust_offset_pagination( $found_posts, $query ) {
653
654 if( $query->get('main_query_offset') ) {
655 $offset = tdb_state_template::get_template_loop_offset();
656 return $found_posts - $offset;
657 }
658
659 return $found_posts;
660 }
661
662});
663
664
665/**
666 * resources loaded just on ajax autoloaded(infinite) posts
667 */
668if ( tdb_state::is_ajax() ) {
669
670 // do not show the admin bar on autoload posts ajax calls
671 add_filter('show_admin_bar', '__return_false');
672
673 // enqueue for posts autoload(infinite) ajax loaded posts
674 add_filter('wp_enqueue_scripts', function(){
675
676 // load the js
677 if ( TDB_DEPLOY_MODE == 'dev' ) {
678 wp_enqueue_script( 'tdbAutoloadAjax', TDB_URL . '/assets/js/tdbAutoloadAjax.js', array( 'jquery' ), TD_CLOUD_LIBRARY, true);
679 } else {
680 wp_enqueue_script( 'tdb_js_posts_autoload_ajax', TDB_URL . '/assets/js/js_posts_autoload_ajax.min.js', array( 'jquery', 'underscore' ), TD_CLOUD_LIBRARY, true );
681 }
682
683 // load the css
684 if ( TDB_DEPLOY_MODE == 'dev' ) {
685 wp_enqueue_style( 'tdb_autoload_ajax', TDB_URL . '/td_less_style.css.php?part=less_ajax', false, TD_CLOUD_LIBRARY );
686 } else {
687 wp_enqueue_style( 'tdb_posts_autoload_ajax_style', TDB_URL . '/assets/css/tdb_less_ajax.css', false, TD_CLOUD_LIBRARY );
688 }
689 });
690}
691
692
693/**
694 * when posting a comment on a ajax autoloaded posts make sure the redirect sets the ajax state
695 */
696add_filter('comment_post_redirect', function( $url ){
697
698 if ( strpos( $_SERVER["HTTP_REFERER"], '?tdb_action=tdb_ajax' ) !== false ) {
699 $url = add_query_arg( 'tdb_action', 'tdb_ajax', $url );
700 }
701
702 return $url;
703});
704
705
706/**
707 * redirect the view template
708 * - template_include runs after template_redirect
709 * - RUNS BEFORE the one that we have in the theme @see on_td_wp_booster_functions.php
710 * - The theme does nothing on single pages when it detects a template builder template so we have to do all the work here
711 */
712add_filter( 'template_include', 'tdb_on_template_include' );
713function tdb_on_template_include( $original_template ) {
714
715
716 // we are viewing a single post template
717 if ( is_singular( array( 'tdb_templates' ) ) && ! td_util::is_mobile_theme() ) {
718
719 add_filter( 'the_content', function( $content ) {
720 if ( td_util::is_template_header() ) {
721
722 global $post;
723 $tdb_template_type = get_post_meta( $post->ID, 'tdb_template_type', true );
724
725 if ( 'header' === $tdb_template_type ) {
726 return '';
727 }
728 return $content;
729 }
730 return $content;
731 });
732
733 return TDB_TEMPLATE_BUILDER_DIR . '/wp_templates/tdb_view_template.php';
734 }
735
736 // we are viewing a single page template
737 if ( is_singular( array( 'attachment' ) ) && ! td_util::is_mobile_theme() ) {
738
739 $template_id = '';
740
741 // read template
742 $tdb_attachment_template = td_options::get( 'tdb_attachment_template' );
743 if ( td_global::is_tdb_template( $tdb_attachment_template, true ) ) {
744 $template_id = td_global::tdb_get_template_id( $tdb_attachment_template );
745 }
746
747 if ( !empty( $template_id ) ) {
748
749 // load the tdb template
750 $wp_query_template = new WP_Query( array(
751 'p' => $template_id,
752 'post_type' => 'tdb_templates',
753 )
754 );
755 }
756
757 // do not redirect the theme template if we don't find the template
758 // the template was probably deleted or something
759 if ( empty( $wp_query_template ) || !$wp_query_template->have_posts() ) {
760 return $original_template; // do nothing if the template is not found!
761 }
762
763 // save our template wp_query & load
764 tdb_state_template::set_wp_query( $wp_query_template );
765
766 // do the redirect
767 return TDB_TEMPLATE_BUILDER_DIR . '/wp_templates/tdb_view_attachment.php';
768 }
769
770 // we are viewing a category template
771 if ( is_category() && ! td_util::is_mobile_theme() ) {
772
773 $template_id = '';
774 $current_category_obj = '';
775
776 $cat_query_var = get_query_var('cat');
777 $category_name_query_var = get_query_var('category_name');
778 $current_category_id = '';
779
780 if ( !empty( $cat_query_var ) ) {
781 $current_category_obj = get_category( $cat_query_var );
782 } elseif( !empty( $category_name_query_var ) ) {
783 $current_category_obj = get_category_by_slug( $category_name_query_var );
784 }
785
786 if ( !empty( $current_category_obj ) ) {
787 $current_category_id = $current_category_obj->cat_ID;
788 }
789
790 // read the individual cat template
791 $tdb_individual_category_template = td_util::get_category_option( $current_category_id, 'tdb_category_template' );
792
793 // read the global template
794 $tdb_category_template = td_options::get( 'tdb_category_template' );
795
796 if ( empty( $tdb_individual_category_template ) ) {
797
798 if ( td_global::is_tdb_template( $tdb_category_template, true ) ) {
799 $template_id = td_global::tdb_get_template_id( $tdb_category_template );
800 }
801
802 } else {
803
804 if ( td_global::is_tdb_template( $tdb_individual_category_template, true ) ) {
805 $template_id = td_global::tdb_get_template_id( $tdb_individual_category_template );
806
807 } else if ( 'theme_templates' === $tdb_individual_category_template ) {
808
809 // do nothing if the template is not found!
810 return $original_template;
811
812 } else if ( td_global::is_tdb_template( $tdb_category_template, true ) ) {
813
814 // look and set the global cat cloud template if we have an individual category but it's not found
815 $template_id = td_global::tdb_get_template_id( $tdb_category_template );
816
817 }
818 }
819
820 // if we don't have a template return the original temp
821 if ( !empty( $template_id ) ) {
822
823 // load the tdb template
824 $wp_query_template = new WP_Query( array(
825 'p' => $template_id,
826 'post_type' => 'tdb_templates',
827 )
828 );
829 }
830
831 // do not redirect the theme template if we don't find the template
832 // the template was probably deleted or something
833 if ( empty( $wp_query_template ) || !$wp_query_template->have_posts() ) {
834 return $original_template; // do nothing if the template is not found!
835 }
836
837 return TDB_TEMPLATE_BUILDER_DIR . '/wp_templates/tdb_view_category.php';
838 }
839
840 // we are viewing a author template
841 if ( is_author() && ! td_util::is_mobile_theme() ) {
842
843 // user templates
844 $tdb_author_templates = td_util::get_option('tdb_author_templates');
845 // author id
846 $author_query_var = get_query_var('author');
847 $author_name_query_var = get_query_var('author_name');
848 $author_id = '';
849 if (!empty($author_query_var)) {
850 $author_id = $author_query_var;
851 } else if(!empty($author_name_query_var)) {
852 $user = get_user_by('login', $author_name_query_var);
853 if( $user ){
854 $author_id = $user->ID;
855 }
856 }
857
858 if ( !empty( $tdb_author_templates[$author_id] ) && td_global::is_tdb_template( $tdb_author_templates[$author_id], true ) ) {
859 return TDB_TEMPLATE_BUILDER_DIR . '/wp_templates/tdb_view_author.php';
860 }
861
862 // read template
863 $template_id = td_options::get( 'tdb_author_template' );
864 if (td_global::is_tdb_template($template_id, true)) {
865 return TDB_TEMPLATE_BUILDER_DIR . '/wp_templates/tdb_view_author.php';
866 }
867 }
868
869 // we are viewing a search template
870 if ( is_search() && ! td_util::is_mobile_theme() ) {
871
872 // read template
873 $tdb_search_template = td_options::get( 'tdb_search_template' );
874 if ( td_global::is_tdb_template( $tdb_search_template, true ) ) {
875 return TDB_TEMPLATE_BUILDER_DIR . '/wp_templates/tdb_view_search.php';
876 }
877
878 }
879
880 // we are viewing a date template
881 if ( is_date() && ! td_util::is_mobile_theme() ) {
882
883 // read template
884 $tdb_date_template = td_options::get( 'tdb_date_template' );
885 if ( td_global::is_tdb_template( $tdb_date_template, true ) ) {
886 return TDB_TEMPLATE_BUILDER_DIR . '/wp_templates/tdb_view_date.php';
887 }
888
889 }
890
891 // we are viewing a tag template
892 if ( is_tag() && ! td_util::is_mobile_theme() ) {
893
894 // read template
895 $tdb_tag_template = td_options::get( 'tdb_tag_template' );
896 if ( td_global::is_tdb_template( $tdb_tag_template, true ) ) {
897 return TDB_TEMPLATE_BUILDER_DIR . '/wp_templates/tdb_view_tag.php';
898 }
899
900 }
901
902 // we are viewing a 404 template
903 if ( is_404() && ! td_util::is_mobile_theme() ) {
904
905 $template_id = '';
906
907 // read template
908 $tdb_404_template = td_options::get( 'tdb_404_template' );
909 if ( td_global::is_tdb_template( $tdb_404_template, true ) ) {
910 $template_id = td_global::tdb_get_template_id( $tdb_404_template );
911 }
912
913 if ( !empty( $template_id ) ) {
914
915 // load the tdb template
916 $wp_query_template = new WP_Query( array(
917 'p' => $template_id,
918 'post_type' => 'tdb_templates',
919 )
920 );
921 }
922
923 // do not redirect the theme template if we don't find the template
924 // the template was probably deleted or something
925 if ( empty( $wp_query_template ) || !$wp_query_template->have_posts() ) {
926 return $original_template; // do nothing if the template is not found!
927 }
928
929 // save our template wp_query & load
930 tdb_state_template::set_wp_query( $wp_query_template );
931
932 // do the redirect
933 return TDB_TEMPLATE_BUILDER_DIR . '/wp_templates/tdb_view_404.php';
934 }
935
936 return $original_template;
937}
938
939
940/**
941 * This hook is in the theme, it allows us to provide a redirect for the single pages on the front end
942 * we run it on the post template if set and on the global template if no post template is set. Not the best solution...
943 * in: the template id
944 * out: the new template path
945 */
946add_filter('td_single_override', function($template_id) {
947
948 // load the tdb template
949 $wp_query_template = new WP_Query( array(
950 'p' => $template_id,
951 'post_type' => 'tdb_templates',
952 )
953 );
954
955 // do not redirect the theme template if we don't find the template
956 // the template was probably deleted or something
957 if (!$wp_query_template->have_posts()) {
958 return $template_id; // do nothing if the template is not found!
959 }
960
961 // save our template wp_query & load
962 tdb_state_template::set_wp_query($wp_query_template);
963
964 // do the redirect
965 return TDB_TEMPLATE_BUILDER_DIR . '/wp_templates/tdb_view_single.php';
966});
967
968
969/**
970 * JS: add tdb_globals to wp-admin
971 */
972add_filter('admin_head', function(){
973
974 if ( td_util::is_mobile_theme() ) {
975 return;
976 }
977
978 $tdb_globals = array (
979 'wpRestNonce' => wp_create_nonce('wp_rest'),
980 'wpRestUrl' => rest_url(),
981 'permalinkStructure' => get_option('permalink_structure'),
982 'tdbTemplateType' => tdc_util::get_get_val('tdbTemplateType')
983 );
984
985 ?>
986 <script>
987 window.tdb_globals = <?php echo json_encode( $tdb_globals );?>;
988 </script>
989
990 <style>
991 body.post-type-tdb_templates .page-title-action {
992 display: none;
993 }
994 </style>
995 <?php
996});
997
998/**
999 * JS: add the tdb_globals for frontend also..
1000 * @note: this is need for autoload(infinite) posts ajax calls
1001 */
1002add_filter('wp_head', function (){
1003
1004 if ( td_util::is_mobile_theme() ) {
1005 return;
1006 }
1007
1008 $tdb_globals = array (
1009 'wpRestNonce' => wp_create_nonce('wp_rest'),
1010 'wpRestUrl' => rest_url(),
1011 'permalinkStructure' => get_option('permalink_structure'),
1012 );
1013
1014 if ( ! tdb_state::is_ajax() ) {
1015 $tdb_globals['isAjax'] = false;
1016 $tdb_globals['isAdminBarShowing'] = is_admin_bar_showing();
1017
1018 $tdb_p_autoload_scroll_percent = intval( td_util::get_option('tdb_p_autoload_scroll_percent', 50 ) );
1019
1020 if ( tdb_util::check_in_range( $tdb_p_autoload_scroll_percent, 1, 100 ) ) {
1021 $tdb_globals['autoloadScrollPercent'] = $tdb_p_autoload_scroll_percent;
1022 } else {
1023 $tdb_globals['autoloadScrollPercent'] = 50;
1024 }
1025
1026 global $post;
1027
1028 if ( is_singular('post') ) {
1029
1030 $tdb_globals['postAutoloadStatus'] = td_util::get_option('tdb_p_autoload_status', 'off');
1031
1032 if ( !empty($post) ){
1033 $tdb_globals['origPostEditUrl'] = get_edit_post_link($post->ID);
1034 }
1035 }
1036
1037 } else {
1038 $tdb_globals['isAjax'] = true;
1039 }
1040
1041 ?>
1042 <script>
1043 window.tdb_globals = <?php echo json_encode( $tdb_globals );?>;
1044 </script>
1045 <?php
1046});
1047
1048
1049/**
1050 * Get the template id to get icon fonts
1051 */
1052add_filter( 'tdc_filter_icon_fonts_post_id', function( $post_id ) {
1053 if ( tdb_state_template::has_wp_query() ) {
1054 return tdb_state_template::get_wp_query()->post->ID;
1055 }
1056 return $post_id;
1057
1058}, 10, 1);
1059
1060
1061/**
1062 * Get the template id to get google fonts
1063 */
1064add_filter( 'td_filter_google_fonts_post_id', function( $post_id ) {
1065 if ( tdb_state_template::has_wp_query() ) {
1066 return tdb_state_template::get_wp_query()->post->ID;
1067 }
1068 return $post_id;
1069
1070}, 10, 1);
1071
1072
1073/**
1074 * ADD Edit links to all the editable WP templates
1075 */
1076add_action('admin_bar_menu', 'tdb_on_admin_bar_menu', 50);
1077function tdb_on_admin_bar_menu() {
1078 global $wp_admin_bar, $post, $wp_query;
1079
1080 if ( td_util::is_mobile_theme() ) {
1081 return;
1082 }
1083
1084 if ( is_user_logged_in() && current_user_can( 'switch_themes' ) && is_admin_bar_showing() ) {
1085
1086 if ( tdb_state_content::has_wp_query() ) {
1087
1088 $tdbLoadDataFromId = '';
1089 switch( tdb_state_template::get_template_type() ) {
1090 case 'single':
1091 $tdbLoadDataFromId = tdb_state_content::get_wp_query()->post->ID;
1092 break;
1093
1094 case 'category':
1095 $tdbLoadDataFromId = tdb_state_content::get_wp_query()->queried_object_id;
1096 break;
1097
1098 case 'author':
1099 $tdbLoadDataFromId = tdb_state_content::get_wp_query()->query_vars['author'];
1100 break;
1101
1102 case 'search':
1103 $tdbLoadDataFromId = tdb_state_content::get_wp_query()->query_vars['s'];
1104 break;
1105
1106 case 'date':
1107 $tdbLoadDataFromId = tdb_state_content::get_wp_query()->query_vars['year'];
1108 break;
1109
1110 case 'tag':
1111 $tdbLoadDataFromId = tdb_state_content::get_wp_query()->query_vars['tag_id'];
1112 break;
1113
1114 case 'attachment':
1115 $tdbLoadDataFromId = tdb_state_content::get_wp_query()->queried_object->ID;
1116 break;
1117 }
1118 // edit single page
1119 $wp_admin_bar->add_menu(
1120 array(
1121 'id' => 'tdb_template_builder',
1122 'title' => 'Edit template',
1123 'href' => admin_url( 'post.php?post_id=' . tdb_state_template::get_wp_query()->post->ID . '&td_action=tdc&tdbLoadDataFromId=' . $tdbLoadDataFromId . '&tdbTemplateType=' . tdb_state_template::get_template_type() . '&prev_url=' . rawurlencode(tdc_util::get_current_url()) ),
1124 'meta' => array(
1125 'title' => 'Edit the single post template. This template is used by ALL the posts of your website!'
1126 ),
1127 )
1128 );
1129 } elseif ( tdb_state_template::has_wp_query() ) {
1130
1131 // edit template
1132 $wp_admin_bar->add_menu(
1133 array(
1134 'id' => 'tdb_template_builder',
1135 'title' => 'Edit template',
1136 'href' => admin_url( 'post.php?post_id=' . tdb_state_template::get_wp_query()->post->ID . '&td_action=tdc&tdbTemplateType=' . tdb_state_template::get_template_type() . '&prev_url=' . rawurlencode(tdc_util::get_current_url() )),
1137 'meta' => array(
1138 'title' => 'Edit the ' . tdb_state_template::get_template_type() . ' template.'
1139 ),
1140 )
1141 );
1142 } elseif (
1143 ( is_singular( 'post' ) && ! is_admin() ) ||
1144 is_singular( 'attachment' ) ||
1145 ( is_category() && ! is_admin() ) ||
1146 ( is_author() && ! is_admin() ) ||
1147 ( is_search() && ! is_admin() ) ||
1148 ( is_date() && ! is_admin() ) ||
1149 ( is_tag() && ! is_admin() ) ||
1150 is_404()
1151 ) {
1152 $wp_admin_bar->add_menu(
1153 array(
1154 'id' => 'tdb_template_builder_disabled',
1155 'title' => 'Edit template',
1156 'href' => '#',
1157 'meta' => array(
1158 'title' => 'Please select a tagDiv Builder template.'
1159 ),
1160 )
1161 );
1162 }
1163
1164 }
1165}
1166
1167
1168// add the load template button on the welcome screen of td-composer
1169add_action('tdc_welcome_panel_text', function() {
1170 if (tdc_util::get_get_val('tdbTemplateType') !== false) {
1171 ?>
1172 <div class="tdc-start-tips">
1173 <p>OR</p>
1174 </div>
1175 <div class="tdc-sidebar-w-button tdb-load-template" title="Import Pre-designed Templates from tagDiv Cloud Library">Load Template</div>
1176 <?php
1177 }
1178});
1179
1180
1181
1182add_action('admin_footer', 'tdb_on_wp_admin_footer');
1183function tdb_on_wp_admin_footer () {
1184 require_once('tdb_template_import.php');
1185}
1186
1187
1188$tdbTemplateType = @$_GET['tdbTemplateType'];
1189$post_type = @$_GET['post_type'];
1190
1191if ( ! empty( $tdbTemplateType ) || ( ! empty( $post_type ) && 'tdb_templates' === $post_type ) ) {
1192
1193 // enqueue for wp-admin
1194 add_action( 'admin_enqueue_scripts', function () {
1195
1196 // load the css
1197 if ( TDB_DEPLOY_MODE == 'dev' ) {
1198 wp_enqueue_style( 'tdb_wp_admin', TDB_URL . '/td_less_style.css.php?part=wp_admin_main', false, TD_CLOUD_LIBRARY );
1199 } else {
1200 wp_enqueue_style( 'tdb_wp_admin', TDB_URL . '/assets/css/tdb_wp_admin.css', false, TD_CLOUD_LIBRARY );
1201 }
1202
1203 // load the vue modal js
1204 if ( TDB_DEPLOY_MODE == 'dev' ) {
1205 tdb_util::enqueue_js_files_array( tdb_config::$js_files_vue_modals, array( 'jquery', 'underscore' ) );
1206 } else {
1207 wp_enqueue_script( 'tdb_js_files_vue_modals', TDB_URL . '/assets/js/js_files_vue_modals.min.js', array(
1208 'jquery',
1209 'underscore'
1210 ), TD_CLOUD_LIBRARY, true );
1211 }
1212
1213 }, 1011 ); // load them last after td-composer
1214
1215 //enqueue files that must go at the end
1216 add_action( 'admin_enqueue_scripts', function () {
1217
1218 if ( TDB_DEPLOY_MODE == 'dev' ) {
1219 tdb_util::enqueue_js_files_array( tdb_config::$js_files_vue_modals_last, array( 'jquery', 'underscore' ) );
1220 } else {
1221 wp_enqueue_script( 'js_files_vue_modals_last', TDB_URL . '/assets/js/js_files_vue_modals_last.min.js', array(
1222 'jquery',
1223 'underscore'
1224 ), TD_CLOUD_LIBRARY, true );
1225 }
1226
1227 }, 1012 );
1228
1229}
1230
1231
1232//enqueue files that must go at the end
1233add_action( 'admin_enqueue_scripts', function () {
1234
1235 if ( TDB_DEPLOY_MODE == 'dev' ) {
1236 tdb_util::enqueue_js_files_array( tdb_config::$js_files_wp_admin, array( 'jquery', 'underscore' ) );
1237 } else {
1238 wp_enqueue_script( 'tdb_js_files_for_wp_admin', TDB_URL . '/assets/js/js_files_wp_admin.min.js', array(
1239 'jquery',
1240 'underscore'
1241 ), TD_CLOUD_LIBRARY, true );
1242 }
1243
1244 // Vue files theme panel
1245 if (isset($_GET['page']) && $_GET['page'] === 'td_theme_panel') {
1246 if ( TDB_DEPLOY_MODE == 'dev' ) {
1247 tdb_util::enqueue_js_files_array( tdb_config::$js_files_vue_theme_panel, array( 'jquery', 'underscore' ) );
1248 } else {
1249 wp_enqueue_script( 'tdb_js_files_vue_theme_panel', TDB_URL . '/assets/js/js_files_vue_theme_panel.min.js', array(
1250 'jquery',
1251 'underscore'
1252 ), TD_CLOUD_LIBRARY, true );
1253 }
1254 }
1255
1256}, 1012 );
1257
1258
1259// enqueue for front
1260add_action( 'wp_enqueue_scripts', function () {
1261
1262 if ( td_util::is_mobile_theme() ) {
1263 return;
1264 }
1265
1266 // load the css
1267 if ( TDB_DEPLOY_MODE == 'dev' ) {
1268 wp_enqueue_style( 'tdb_front_style', TDB_URL . '/td_less_style.css.php?part=less_front', false, TD_CLOUD_LIBRARY );
1269 } else {
1270 wp_enqueue_style( 'tdb_front_style', TDB_URL . '/assets/css/tdb_less_front.css', false, TD_CLOUD_LIBRARY );
1271 }
1272
1273
1274 // load the js
1275 if ( TDB_DEPLOY_MODE == 'dev' ) {
1276 tdb_util::enqueue_js_files_array( tdb_config::$js_files_for_front, array( 'jquery' ) );
1277 } else {
1278 wp_enqueue_script( 'tdb_js_files_for_front', TDB_URL . '/assets/js/js_files_for_front.min.js', array( 'jquery' ), TD_CLOUD_LIBRARY, true );
1279 }
1280
1281}, 1011 ); // load them last after td-composer
1282
1283
1284/**
1285 * Patch the theme panel and metaboxes with our builder templates.
1286 * Here we add the templates to the API so that we can see them in the panels
1287 */
1288function tdb_patch_panel() {
1289 if (is_admin()) {
1290
1291 /**
1292 * patch single templates
1293 */
1294 $args = array(
1295 'post_type' => array('tdb_templates'),
1296 'meta_query' => array(
1297 array(
1298 'key' => 'tdb_template_type',
1299 'value' => 'single',
1300 ),
1301 ),
1302 'posts_per_page' => '-1'
1303 );
1304
1305 /**
1306 * @var WP_Query
1307 */
1308 $wp_query_templates = new WP_Query( $args );
1309
1310 if (!empty($wp_query_templates->posts)) {
1311
1312 /**
1313 * @var $post WP_Post
1314 */
1315 foreach ($wp_query_templates->posts as $post) {
1316 // tdb_ is used as a prefix to filter it out in theme panel and show it only on post settings
1317 // why? we have to use the prefix to identify templates even when this plugin is off to load the default theme template in that case
1318 td_api_single_template::add('tdb_template_' . $post->ID,
1319 array(
1320 'file' => '',
1321 'text' => $post->post_title,
1322 'img' => TDB_URL . '/assets/images/single_template_placeholder.png',
1323 'template_id' => $post->ID, // this key is used only on custom templates
1324 'show_featured_image_on_all_pages' => false,
1325 'bg_disable_background' => false, // disable the featured image
1326 'bg_box_layout_config' => 'auto', // auto | td-boxed-layout | td-full-layout
1327 'bg_use_featured_image_as_background' => false, // uses the featured image as a background
1328 'exclude_ad_content_top' => false,
1329 )
1330 );
1331 }
1332 }
1333 }
1334}
1335tdb_patch_panel();
1336
1337
1338/**
1339 * remove comment form nonce on composer frame
1340 * fix for console error on single post comments shortcode addition
1341 */
1342add_action( 'comment_form', function() {
1343 if ( tdc_state::is_live_editor_iframe() || tdc_state::is_live_editor_ajax() ) {
1344 remove_action( 'comment_form', 'wp_comment_form_unfiltered_html_nonce' ); ;
1345 }
1346}, 9 );
1347
1348if ( is_admin() ){
1349 add_filter( 'query_vars', function( $query_vars ) {
1350
1351 $query_vars[] = 'meta_key';
1352 $query_vars[] = 'meta_value';
1353 $query_vars[] = 'template_type';
1354
1355 return $query_vars;
1356 });
1357}
1358
1359/**
1360 * this removes the wordpress 'hentry' class
1361 * we're quiting the 'hentry' microformat and rely on the json-ld(json linked data) format
1362 * @param $classes
1363 * @return array
1364 */
1365add_filter( 'post_class',function( $classes ){
1366
1367 $classes = array_diff( $classes, array( 'hentry' ) );
1368
1369 return $classes;
1370});
1371
1372
1373/**
1374 * Class tdb_method - fake callable for auto complete
1375 */
1376class tdb_method {
1377 /**
1378 * @param string $p1
1379 * @param string $p2
1380 * @param string $p3
1381 * @param string $p4
1382 * @return array | string
1383 */
1384 function __invoke($p1 = '', $p2 = '', $p3 = '', $p4 = '') {
1385 return '';
1386 // TODO: Implement __invoke() method.
1387 }
1388}