PluginProbe
WP Directory Kit / 1.4.8
WP Directory Kit v1.4.8
1.5.6 1.5.5 1.5.4 1.5.3 trunk 1.1.0 1.1.6 1.1.8 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.8 1.4.0 1.4.1 All 35 releases
wpdirectorykit / filters.php

filters.php in WP Directory Kit 1.4.8, at filters.php

540 lines 22.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 if ( ! defined( 'ABSPATH' ) ) {
3 exit; // Exit if accessed directly.
4 }
5
6 /* fix for redirect */
7 add_action('init', 'wdk_do_output_buffer');
8 function wdk_do_output_buffer() {
9 ob_start();
10 }
11
12 /* add elementor body class */
13 add_filter( 'body_class', function( $classes ) {
14 global $wp_query;
15 global $wdk_listing_id;
16 global $wdk_listing_page_id;
17 if(isset($wp_query->post))
18 if($wp_query->post->post_type == 'wdk-listing')
19 {
20 $wdk_listing_id = $wp_query->post->ID;
21 $wdk_listing_page_id = get_option('wdk_listing_page');
22 if(!empty($wdk_listing_page_id) && get_post_status($wdk_listing_page_id) =='publish')
23 {
24 return array_merge( $classes, array( 'elementor-page-'.$wdk_listing_page_id ) );
25 }
26 }
27
28 return array_merge( $classes, array( 'class-name' ) );
29 } );
30
31 add_filter('the_content', 'wdk_content');
32
33 function wdk_content( $content )
34 {
35 global $wp_query;
36 global $wdk_listing_id;
37 global $wdk_listing_page_id;
38 if(isset($wp_query->post))
39 if($wp_query->post->post_type == 'wdk-listing')
40 {
41 $wdk_listing_id = $wp_query->post->ID;
42 $wdk_listing_page_id = get_option('wdk_listing_page');
43 if(!empty($wdk_listing_page_id) && get_post_status($wdk_listing_page_id) =='publish')
44 {
45 global $Winter_MVC_WDK;
46 $Winter_MVC_WDK->load_helper('listing');
47
48 if(
49 (
50 wdk_field_value('is_activated', $wdk_listing_id,false) && wdk_field_value('is_approved', $wdk_listing_id,false)) ||
51 (get_current_user_id() != 0 && get_current_user_id() == wdk_field_value('user_id_editor', $wdk_listing_id,false)) ||
52 (get_current_user_id() != 0 && wmvc_user_in_role('administrator'))
53 ) {
54
55 $Winter_MVC_WDK->model('listing_m');
56 $Winter_MVC_WDK->listing_m->update_counter($wdk_listing_id);
57
58 if(wdk_get_option('wdk_membership_is_enable_subscriptions') && wdk_get_option('wdk_membership_subscriptions_view_listing_enabled') && function_exists('run_wdk_membership')){
59 /* if required subscription with View details listing */
60
61 /* if not login, return alert for ask login */
62 if(is_user_logged_in()) {
63
64 global $Winter_MVC_wdk_membership;
65 $Winter_MVC_wdk_membership->model('subscription_m');
66 $Winter_MVC_wdk_membership->model('subscription_user_m');
67 $user_subscriptions_listings_view = $Winter_MVC_wdk_membership->subscription_user_m->get_pagination(NULL, FALSE, array('is_activated'=>1,'is_view_private_listings'=>1));
68
69 /* if not allow subscription, return alert for subscription on dash page */
70 if(empty($user_subscriptions_listings_view)){
71 $content = '<div style="margin: 35px auto;max-width:768px"><p class="wdk_alert wdk_alert-danger">'.esc_html__('Required subscription for "View Listings Details", please', 'wpdirectorykit').' <a href="'.esc_url(wdk_dash_url('dash_page=membership')).'">'.esc_html__('purchase subscription here', 'wpdirectorykit').'</a></p></div>';
72 } else {
73 if(class_exists('Elementor\Plugin'))
74 {
75 $content = '';
76 $elementor_instance = Elementor\Plugin::instance();
77 $content = $elementor_instance->frontend->get_builder_content_for_display($wdk_listing_page_id);
78 }
79 }
80 } else {
81 $content = '<div style="margin: 35px auto;max-width:768px"><p class="wdk_alert wdk_alert-danger">'.esc_html__('Required subscription for "View Listings Details", please', 'wpdirectorykit').' <a href="'.wdk_login_url(wdk_server_current_url(), esc_html__('Login for open Listing', 'wpdirectorykit')).'">'.esc_html__('register or login here', 'wpdirectorykit').'</a></p></div>';
82 }
83
84 }
85 /* if login required */
86 elseif(get_option('wdk_membership_login_required_listing_preview') && !is_user_logged_in()){
87 if(get_option('wdk_membership_login_page')){
88 wp_redirect(wdk_url_suffix(get_permalink(get_option('wdk_membership_login_page')),'redirect_to='.urlencode(wdk_current_url()).'&custom_message='.urlencode(esc_html__('Please login for open Listing', 'wpdirectorykit'))));
89 // exit();
90 } else {
91 wp_redirect(wp_login_url(wdk_current_url()));
92 }
93 }
94 else {
95 if(class_exists('Elementor\Plugin'))
96 {
97 $content = '';
98
99 if(!wdk_field_value('is_approved', $wdk_listing_id, false) || !wdk_field_value('is_activated', $wdk_listing_id, false)) {
100 $content = '<div style="margin: 35px auto;max-width:768px;margin-bottom: 35px"><p class="wdk_alert wdk_alert-danger">'.esc_html__('Listing is not activated/approved and not visible for public', 'wpdirectorykit').'</p></div>';
101 }
102
103 $elementor_instance = Elementor\Plugin::instance();
104 $content .= $elementor_instance->frontend->get_builder_content_for_display($wdk_listing_page_id);
105
106 $custom_css = '';
107
108 $wdk_listing_id;
109 $Winter_MVC_WDK->model('field_m');
110
111 $Winter_MVC_WDK->db->where(array('field_type !='=> 'SECTION'));
112 $fields = $Winter_MVC_WDK->field_m->get();
113
114 foreach($fields as $field) {
115 if(wdk_field_value ($field->idfield, $wdk_listing_id)) continue;
116
117 if(!empty($custom_css)) $custom_css .= ',';
118
119 $custom_css .= '.wdk_'.$field->idfield.'_hide_empty';
120 }
121
122 if(!wdk_field_value ('lat', $wdk_listing_id, false) || !wdk_field_value ('lng', $wdk_listing_id)) {
123 if(!empty($custom_css)) $custom_css .= ',';
124 $custom_css .= '.wdk_map_hide_empty';
125 }
126
127 if(!wdk_field_value ('is_featured', $wdk_listing_id, false)) {
128 if(!empty($custom_css)) $custom_css .= ',';
129 $custom_css .= '.wdk_is_featured_hide_empty';
130 }
131
132 $custom_css .= '{display: none !important}';
133
134 wp_enqueue_style('wdk-custom-inline', WPDIRECTORYKIT_URL.'public/css/custom-inline.css');
135 wp_add_inline_style( 'wdk-custom-inline', $custom_css);
136
137 }
138 }
139
140 } else {
141 $content = '<div style="margin: 35px auto;max-width:768px"><p class="wdk_alert wdk_alert-danger">'.esc_html__('Listing missing or not activated', 'wpdirectorykit').', <a href="'.get_home_url().'">'.esc_html__('return to Homepage', 'wpdirectorykit').'</a></p></div>';
142 }
143 } else {
144 $content = '<div style="margin: 35px auto;max-width:768px"><p class="wdk_alert wdk_alert-danger">'.esc_html__('Missing listing Preview Page', 'wpdirectorykit').', <a href="'.esc_url(get_admin_url()).'admin.php?page=wdk_settings&function=import_demo">'.esc_html__('Import demo Page', 'wpdirectorykit').'</a></p></div>';
145 }
146
147 }
148 return $content;
149 }
150
151 function wdk_do_header() {
152 // get all elementor pro builder conditions
153 $pro_theme_builder_conditions = get_option('elementor_pro_theme_builder_conditions');
154 $listing_page_id = get_option('wdk_listing_page');
155
156 if(!empty($pro_theme_builder_conditions))
157 {
158 foreach($pro_theme_builder_conditions['header'] as $header_post_id => $header_on_pages)
159 {
160 foreach($header_on_pages as $pages)
161 {
162 $accepted_page_id = substr($pages, strrpos($pages, '/')+1);
163
164 if($accepted_page_id == $listing_page_id)
165 {
166 // render header content
167
168 $elementor_instance = \Elementor\Plugin::instance();
169 $content = $elementor_instance->frontend->get_builder_content_for_display($header_post_id);
170
171 echo wp_kses_post( $content );
172 return;
173 }
174 }
175 }
176 }
177 }
178
179 function wdk_do_footer() {
180 // get all elementor pro builder conditions
181 $pro_theme_builder_conditions = get_option('elementor_pro_theme_builder_conditions');
182 $listing_page_id = get_option('wdk_listing_page');
183
184 if(!empty($pro_theme_builder_conditions))
185 {
186 foreach($pro_theme_builder_conditions['footer'] as $footer_post_id => $footer_on_pages)
187 {
188 foreach($footer_on_pages as $pages)
189 {
190 $accepted_page_id = substr($pages, strrpos($pages, '/')+1);
191
192 if($accepted_page_id == $listing_page_id)
193 {
194 // render footer content
195
196 $elementor_instance = \Elementor\Plugin::instance();
197 $content = $elementor_instance->frontend->get_builder_content_for_display($footer_post_id);
198
199 echo wp_kses_post( $content );
200 return;
201 }
202 }
203 }
204 }
205 }
206
207 function wdk_do_body_class($classes)
208 {
209 if(class_exists('Elementor\Plugin'))
210 {
211 $elementor_instance = \Elementor\Plugin::instance();
212 $classes = $elementor_instance->frontend->body_class();
213 }
214
215 return $classes;
216 }
217
218 function wdk_page_template ($template) {
219 global $wp_query;
220 if(isset($wp_query->post))
221 if($wp_query->post->post_type == 'wdk-listing')
222 {
223 $listing_page_id = get_option('wdk_listing_page');
224 $template_elem = get_post_meta($listing_page_id, '_wp_page_template', true);
225
226 if($template_elem == 'elementor_theme')
227 {
228 // for elementor pro theme builder basic support
229 $template_elem = 'elementor_canvas';
230
231 add_filter( 'body_class', 'wdk_do_body_class' );
232 add_action( 'elementor/page_templates/canvas/before_content', 'wdk_do_header' , 0 );
233 add_action( 'elementor/page_templates/canvas/after_content', 'wdk_do_footer' , 0 );
234 }
235
236 if($template_elem == 'elementor_canvas' || $template_elem == 'elementor_header_footer' ){
237 /**
238 * @var \Elementor\Modules\PageTemplates\Module $page_templates_module
239 */
240 if(class_exists('Elementor\Plugin'))
241 {
242 $page_templates_module = Elementor\Plugin::instance()->modules_manager->get_modules( 'page-templates' );
243 $template = $page_templates_module->get_template_path( $template_elem );
244 }
245 }
246 }
247 return $template;
248 }
249 add_filter ('single_template', 'wdk_page_template');
250
251 add_action('admin_bar_menu', 'wdk_add_toolbar_items', 100);
252 function wdk_add_toolbar_items($admin_bar){
253 global $wp_query;
254 if(isset($wp_query->post))
255 if ($wp_query->post->post_type == 'wdk-listing') {
256 $admin_bar->add_menu(array(
257 'id' => 'edit',
258 'title' => __('Edit Listing', 'wpdirectorykit'),
259 'href' => admin_url('admin.php?page=wdk_listing&id='.$wp_query->post->ID),
260 ));
261 }
262 }
263
264 if(get_option('wdk_slug_listing_preview_page')){
265 function wdk_custom_listing_preview_page_slug( $args, $post_type ) {
266
267 if(get_option('wdk_slug_listing_preview_page_changed')){
268 update_option('wdk_slug_listing_preview_page_changed', 0);
269 flush_rewrite_rules();
270 }
271
272 /*item post type slug*/
273 if ( 'wdk-listing' === $post_type ) {
274 $args['rewrite']['slug'] = get_option('wdk_slug_listing_preview_page');
275 }
276
277 return $args;
278 }
279 add_filter( 'register_post_type_args', 'wdk_custom_listing_preview_page_slug', 10, 2 );
280 }
281
282 /* seo wdk feature, wp overwrite wp_head */
283 add_action( 'wp_head', 'wdk_seo_metatags');
284 function wdk_seo_metatags(){
285 global $wp_query;
286 if(isset($wp_query->post))
287 if($wp_query->post->post_type == 'wdk-listing')
288 {
289 $wdk_listing_id = $wp_query->post->ID;
290 if($wdk_listing_id) {
291 global $Winter_MVC_WDK;
292 $Winter_MVC_WDK->model('field_m');
293 $Winter_MVC_WDK->load_helper('listing');
294
295 echo '<meta name="title" content="'.esc_attr(wp_get_document_title()).'">'.PHP_EOL;
296 echo '<meta property="og:type" content="'.esc_attr(get_post_type()).'" />'.PHP_EOL;
297 echo '<meta property="og:title" content="'.esc_attr(wp_get_document_title()).'" />'.PHP_EOL;
298
299 if(get_option('wdk_seo_description')) {
300 echo '<meta name="description" content="'.esc_attr(wp_trim_words(wp_strip_all_tags(wpautop(wdk_field_value(get_option('wdk_seo_description'), $wdk_listing_id))), 20)).'">'.PHP_EOL;
301 echo '<meta property="og:description" content="'.esc_attr(wp_trim_words(wp_strip_all_tags(wpautop(wdk_field_value(get_option('wdk_seo_description'), $wdk_listing_id))), 20)).'">'.PHP_EOL;
302 }
303
304 if(get_option('wdk_seo_keywords')) {
305 echo '<meta name="keywords" content="'.esc_attr(wp_trim_words(wp_strip_all_tags(wpautop(wdk_field_value(get_option('wdk_seo_keywords'), $wdk_listing_id))), 20)).'">'.PHP_EOL;
306 }
307
308 if(!in_array('wordpress-seo/wp-seo.php', apply_filters('active_plugins', get_option('active_plugins')))){
309 echo '<meta property="og:image" content="'.esc_url(wdk_image_src(array('listing_images'=>wdk_field_value('listing_images', $wdk_listing_id)), 'full')).'" />'.PHP_EOL;
310 }
311 }
312 }
313 }
314
315 /* disable some sw_seo feature if Yost seo plugin detected, for only for listing preview page and profile page */
316 add_action( 'template_redirect', 'wdk_disable_seo' );
317 function wdk_disable_seo() {
318 global $wp_query;
319 if(isset($wp_query->post))
320 if($wp_query->post->post_type == 'wdk-listing')
321 {
322 if(in_array('wordpress-seo/wp-seo.php', apply_filters('active_plugins', get_option('active_plugins')))){
323 add_filter( 'wpseo_title', '__return_false');
324 add_filter( 'wpseo_metadesc', '__return_false');
325 add_filter( 'wpseo_opengraph_url', '__return_false');
326 add_filter( 'wpseo_opengraph_title', '__return_false');
327 add_filter( 'wpseo_opengraph_image', '__return_false');
328 add_filter( 'wpseo_opengraph_type', '__return_false');
329 add_filter( 'wpseo_opengraph_desc', '__return_false');
330 }
331 }
332 }
333
334 function wdk_yoast_presentation($presentation) {
335 global $wp_query;
336 if(isset($wp_query->post))
337 if ($wp_query->post->post_type == 'wdk-listing')
338 {
339 $wdk_listing_id = $wp_query->post->ID;
340 if($wdk_listing_id) {
341 global $Winter_MVC_WDK;
342 $Winter_MVC_WDK->model('field_m');
343 $Winter_MVC_WDK->load_helper('listing');
344
345 $presentation->open_graph_images = [
346 [
347 'url' => esc_url(wdk_image_src(array('listing_images'=>wdk_field_value('listing_images', $wdk_listing_id)), 'full')),
348 ]
349 ];
350
351 }
352 }
353 return $presentation;
354 }
355 add_filter('wpseo_frontend_presentation', 'wdk_yoast_presentation', 30);
356
357 add_filter( 'wp_kses_allowed_html', 'wpdirectorykit_wpkses_post_iframe', 10, 2 );
358 function wpdirectorykit_wpkses_post_iframe( $tags, $context ) {
359 if ( 'post' === $context ) {
360 $tags['iframe'] = array(
361 'src' => true,
362 'height' => true,
363 'width' => true,
364 'frameborder' => true,
365 'allowfullscreen' => true,
366 );
367 }
368 return $tags;
369 }
370
371 add_action('wdk-membership/dash/homepage/widgets', function() {
372 if(!current_user_can('edit_own_listings') && !wmvc_user_in_role('administrator')) return false;
373
374 global $Winter_MVC_WDK;
375 $Winter_MVC_WDK->model('listing_m');
376 $total_items = $Winter_MVC_WDK->listing_m->total(array(), TRUE, get_current_user_id());
377 if(function_exists('wdk_dash_url')){
378 ?>
379 <div class="wdk-col-12 wdk-col-md-3 wdk-membership-dash-widget_listings">
380 <a href="<?php echo esc_url(wdk_dash_url('dash_page=listings'));?>" class="wdk-membership-dash-widget">
381 <span class="wdk-content">
382 <span class="icon"><span class="dashicons dashicons-location"></span></span>
383 </span>
384 <span class="wdk-side">
385 <span class="title"><?php echo esc_html__('Listings','wpdirectorykit');?></span>
386 <span class="wdk-count"><?php echo esc_html($total_items);?></span>
387 </span>
388 </a>
389 </div>
390 <?php
391 }
392 },1);
393
394 add_action('wdk-membership/dash/homepage/widgets', function() {
395 global $Winter_MVC_WDK;
396 $Winter_MVC_WDK->model('messages_m');
397 $total_items = $Winter_MVC_WDK->messages_m->total_merge(array(), TRUE, get_current_user_id());
398 if(function_exists('wdk_dash_url')){
399 ?>
400 <div class="wdk-col-12 wdk-col-md-3 wdk-membership-dash-widget_messsages">
401 <a href="<?php echo esc_url(wdk_dash_url('dash_page=messages'));?>" class="wdk-membership-dash-widget">
402 <span class="wdk-content">
403 <span class="icon"><span class="dashicons dashicons-email"></span></span>
404 </span>
405 <span class="wdk-side">
406 <span class="title"><?php echo esc_html__('Messages','wpdirectorykit');?></span>
407 <span class="wdk-count"><?php echo esc_html($total_items);?></span>
408 </span>
409 </a>
410 </div>
411 <?php
412 }
413 });
414
415 add_filter( 'woocommerce_enable_setup_wizard', '__return_false' );
416
417
418 /* detected in smart search location and replace to location id */
419 add_action( 'template_redirect', 'wdk_search_parameters' );
420 function wdk_search_parameters() {
421 global $wp_query;
422 if(!empty($_GET['field_search'])) {
423 global $Winter_MVC_WDK;
424 $Winter_MVC_WDK->model('location_m');
425 $location = $Winter_MVC_WDK->location_m->get_by(array('location_title'=>sanitize_text_field($_GET['field_search'])), TRUE);
426 if($location) {
427 $url = $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"];
428
429 $query_link = substr($url, strpos($url, '?')+1);
430 $clear_link = substr($url, 0, strpos($url, '?'));
431
432 $string_par = array();
433 parse_str( $query_link, $string_par);
434 unset($string_par['field_search']);
435 $string_par['search_location'] = $location->idlocation;
436
437 $new_url = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http").'://'.$clear_link.'?'.http_build_query($string_par);
438 wp_redirect($new_url);
439 exit;
440 }
441
442 }
443
444 }
445
446 add_filter( 'plugin_action_links_wpdirectorykit/wpdirectorykit.php', 'wdk_buy_link' );
447 function wdk_buy_link( $links ) {
448 // Build and escape the URL.
449 $url = esc_url( get_admin_url().'admin.php?page=wdk_addons' );
450 // Create the link.
451 $settings_link = "<a style=\"color:rgb(0, 163, 42);font-weight:bold;\" href='$url'>" . __( 'Check Premium Features', 'wpdirectorykit') . '</a>';
452 // Adds the link to the end of the array.
453 $links[] = $settings_link;
454 return $links;
455 }
456
457
458 add_filter( 'wpdirectorykit/listing/field/value', 'wdk_filter_field_format_date', 2, 10);
459 if(!function_exists('wdk_filter_field_format_date')) {
460 function wdk_filter_field_format_date ($field_value = '', $field_id = NULL, $number_format = TRUE) {
461 if(in_array($field_id, array('date', 'date-modified'))) {
462 $field_value = wdk_get_date($field_value, TRUE);
463 }
464
465 return $field_value;
466 }
467 }
468
469
470 // fix sitemap issue
471 function wdk_modify_sitemap_index($content) {
472 // Modify the $content as needed
473 // For example, replace & with &amp;
474 $content = str_replace('&', '&amp;', $content);
475 return $content;
476 }
477
478 // Hook the filter to the wpseo_sitemap_index filter hook
479 add_filter('wpseo_sitemap_index', 'wdk_modify_sitemap_index');
480
481 if(false) {
482 // Hook example, custom page title for
483 add_filter( 'document_title_parts', function( $title_parts_array ) {
484 global $wp_query;
485 if(isset($wp_query->post))
486 if($wp_query->post->post_type == 'wdk-listing')
487 {
488 $wdk_listing_id = $wp_query->post->ID;
489 if($wdk_listing_id) {
490 global $Winter_MVC_WDK;
491 $Winter_MVC_WDK->model('field_m');
492 $Winter_MVC_WDK->load_helper('listing');
493
494 $title_parts_array['title'] = wp_strip_all_tags(wpautop(wdk_field_value('post_title', $wdk_listing_id).' - '.wdk_field_value('address', $wdk_listing_id)));
495 }
496 }
497 return $title_parts_array;
498 } );
499 }
500
501 add_filter('tiny_mce_before_init', function($init){
502 if(get_option('wdk_disable_toolbar_on_content_editor')) {
503 $init['wpautop'] = false;
504 $init['toolbar'] = false;
505 }
506
507 return $init;
508 });
509
510 /*
511 * configuration number_format_i18n
512 */
513 add_filter('init', function($init){
514 if(get_option('wdk_number_format_decimal_point') || get_option('wdk_number_format_thousands_sep')) {
515 global $wp_locale;
516 if(get_option('wdk_number_format_decimal_point'))
517 $wp_locale->number_format['decimal_point'] = get_option('wdk_number_format_decimal_point');
518
519 if(get_option('wdk_number_format_thousands_sep'))
520 $wp_locale->number_format['thousands_sep'] = get_option('wdk_number_format_thousands_sep');
521 }
522 });
523
524 add_filter( 'wdk/listings/results', function($listings) {
525 global $Winter_MVC_WDK;
526 $Winter_MVC_WDK->model('field_m');
527 $Winter_MVC_WDK->load_helper('listing');
528
529 $listings_ids = array();
530 foreach($listings as $listing) {
531 $listings_ids[] = $listing->post_id;
532 }
533
534 if(!empty($listings_ids)) {
535 $Winter_MVC_WDK->listing_m->update_listings_views($listings_ids);
536 }
537
538 return $listings;
539 } )
540 ?>