PluginProbe
WP Directory Kit / 1.2.4
WP Directory Kit v1.2.4
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.2.4, at filters.php

453 lines 19.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((wdk_field_value('is_activated', $wdk_listing_id,false) && wdk_field_value('is_approved', $wdk_listing_id,false)) || ( get_current_user_id() != 0 && get_current_user_id() == wdk_field_value('user_id_editor', $wdk_listing_id,false))) {
49
50 $Winter_MVC_WDK->model('listing_m');
51 $Winter_MVC_WDK->listing_m->update_counter($wdk_listing_id);
52
53 if(wdk_get_option('wdk_membership_is_enable_subscriptions') && wdk_get_option('wdk_membership_subscriptions_view_listing_enabled') && function_exists('run_wdk_membership')){
54 /* if required subscription with View details listing */
55
56 /* if not login, return alert for ask login */
57 if(is_user_logged_in()) {
58
59 global $Winter_MVC_wdk_membership;
60 $Winter_MVC_wdk_membership->model('subscription_m');
61 $Winter_MVC_wdk_membership->model('subscription_user_m');
62 $user_subscriptions_listings_view = $Winter_MVC_wdk_membership->subscription_user_m->get_pagination(NULL, FALSE, array('is_activated'=>1,'is_view_private_listings'=>1));
63
64 /* if not allow subscription, return alert for subscription on dash page */
65 if(empty($user_subscriptions_listings_view)){
66 $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>';
67 } else {
68 if(class_exists('Elementor\Plugin'))
69 {
70 $content = '';
71 $elementor_instance = Elementor\Plugin::instance();
72 $content = $elementor_instance->frontend->get_builder_content_for_display($wdk_listing_page_id);
73 }
74 }
75 } else {
76 $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>';
77 }
78
79 }
80 /* if login required */
81 elseif(get_option('wdk_membership_login_required_listing_preview') && !is_user_logged_in()){
82 if(get_option('wdk_membership_login_page')){
83 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'))));
84 // exit();
85 } else {
86 wp_redirect(wp_login_url(wdk_current_url()));
87 }
88 }
89 else {
90 if(class_exists('Elementor\Plugin'))
91 {
92 $content = '';
93
94 if(!wdk_field_value('is_approved', $wdk_listing_id, false)) {
95 $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>';
96 }
97
98 $elementor_instance = Elementor\Plugin::instance();
99 $content .= $elementor_instance->frontend->get_builder_content_for_display($wdk_listing_page_id);
100
101 $custom_css = '';
102
103 $wdk_listing_id;
104 $Winter_MVC_WDK->model('field_m');
105
106 $Winter_MVC_WDK->db->where(array('field_type !='=> 'SECTION'));
107 $fields = $Winter_MVC_WDK->field_m->get();
108
109 foreach($fields as $field) {
110 if(wdk_field_value ($field->idfield, $wdk_listing_id)) continue;
111
112 if(!empty($custom_css)) $custom_css .= ',';
113
114 $custom_css .= '.wdk_'.$field->idfield.'_hide_empty';
115 }
116
117 if(!wdk_field_value ('lat', $wdk_listing_id, false) || !wdk_field_value ('lng', $wdk_listing_id)) {
118 if(!empty($custom_css)) $custom_css .= ',';
119 $custom_css .= '.wdk_map_hide_empty';
120 }
121
122 if(!wdk_field_value ('is_featured', $wdk_listing_id, false)) {
123 if(!empty($custom_css)) $custom_css .= ',';
124 $custom_css .= '.wdk_is_featured_hide_empty';
125 }
126
127 $custom_css .= '{display: none !important}';
128
129 wp_enqueue_style('wdk-custom-inline', WPDIRECTORYKIT_URL.'public/css/custom-inline.css');
130 wp_add_inline_style( 'wdk-custom-inline', $custom_css);
131
132 }
133 }
134
135 } else {
136 $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>';
137 }
138 } else {
139 $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="'.get_admin_url().'admin.php?page=wdk_settings&function=import_demo">'.esc_html__('Import demo Page', 'wpdirectorykit').'</a></p></div>';
140 }
141
142 }
143 return $content;
144 }
145
146 function wdk_do_header() {
147 // get all elementor pro builder conditions
148 $pro_theme_builder_conditions = get_option('elementor_pro_theme_builder_conditions');
149 $listing_page_id = get_option('wdk_listing_page');
150
151 if(!empty($pro_theme_builder_conditions))
152 {
153 foreach($pro_theme_builder_conditions['header'] as $header_post_id => $header_on_pages)
154 {
155 foreach($header_on_pages as $pages)
156 {
157 $accepted_page_id = substr($pages, strrpos($pages, '/')+1);
158
159 if($accepted_page_id == $listing_page_id)
160 {
161 // render header content
162
163 $elementor_instance = \Elementor\Plugin::instance();
164 $content = $elementor_instance->frontend->get_builder_content_for_display($header_post_id);
165
166 echo wp_kses_post( $content );
167 return;
168 }
169 }
170 }
171 }
172 }
173
174 function wdk_do_footer() {
175 // get all elementor pro builder conditions
176 $pro_theme_builder_conditions = get_option('elementor_pro_theme_builder_conditions');
177 $listing_page_id = get_option('wdk_listing_page');
178
179 if(!empty($pro_theme_builder_conditions))
180 {
181 foreach($pro_theme_builder_conditions['footer'] as $footer_post_id => $footer_on_pages)
182 {
183 foreach($footer_on_pages as $pages)
184 {
185 $accepted_page_id = substr($pages, strrpos($pages, '/')+1);
186
187 if($accepted_page_id == $listing_page_id)
188 {
189 // render footer content
190
191 $elementor_instance = \Elementor\Plugin::instance();
192 $content = $elementor_instance->frontend->get_builder_content_for_display($footer_post_id);
193
194 echo wp_kses_post( $content );
195 return;
196 }
197 }
198 }
199 }
200 }
201
202 function wdk_do_body_class($classes)
203 {
204 if(class_exists('Elementor\Plugin'))
205 {
206 $elementor_instance = \Elementor\Plugin::instance();
207 $classes = $elementor_instance->frontend->body_class();
208 }
209
210 return $classes;
211 }
212
213 function wdk_page_template ($template) {
214 global $wp_query;
215 if(isset($wp_query->post))
216 if($wp_query->post->post_type == 'wdk-listing')
217 {
218 $listing_page_id = get_option('wdk_listing_page');
219 $template_elem = get_post_meta($listing_page_id, '_wp_page_template', true);
220
221 if($template_elem == 'elementor_theme')
222 {
223 // for elementor pro theme builder basic support
224 $template_elem = 'elementor_canvas';
225
226 add_filter( 'body_class', 'wdk_do_body_class' );
227 add_action( 'elementor/page_templates/canvas/before_content', 'wdk_do_header' , 0 );
228 add_action( 'elementor/page_templates/canvas/after_content', 'wdk_do_footer' , 0 );
229 }
230
231 if($template_elem == 'elementor_canvas' || $template_elem == 'elementor_header_footer' ){
232 /**
233 * @var \Elementor\Modules\PageTemplates\Module $page_templates_module
234 */
235 if(class_exists('Elementor\Plugin'))
236 {
237 $page_templates_module = Elementor\Plugin::instance()->modules_manager->get_modules( 'page-templates' );
238 $template = $page_templates_module->get_template_path( $template_elem );
239 }
240 }
241 }
242 return $template;
243 }
244 add_filter ('single_template', 'wdk_page_template');
245
246 add_action('admin_bar_menu', 'wdk_add_toolbar_items', 100);
247 function wdk_add_toolbar_items($admin_bar){
248 global $wp_query;
249 if(isset($wp_query->post))
250 if ($wp_query->post->post_type == 'wdk-listing') {
251 $admin_bar->add_menu(array(
252 'id' => 'edit',
253 'title' => __('Edit Listing', 'wpdirectorykit'),
254 'href' => admin_url('admin.php?page=wdk_listing&id='.$wp_query->post->ID),
255 ));
256 }
257 }
258
259 if(get_option('wdk_slug_listing_preview_page')){
260 function wdk_custom_listing_preview_page_slug( $args, $post_type ) {
261
262 if(get_option('wdk_slug_listing_preview_page_changed')){
263 update_option('wdk_slug_listing_preview_page_changed', 0);
264 flush_rewrite_rules();
265 }
266
267 /*item post type slug*/
268 if ( 'wdk-listing' === $post_type ) {
269 $args['rewrite']['slug'] = get_option('wdk_slug_listing_preview_page');
270 }
271
272 return $args;
273 }
274 add_filter( 'register_post_type_args', 'wdk_custom_listing_preview_page_slug', 10, 2 );
275 }
276
277 /* seo wdk feature, wp overwrite wp_head */
278 add_action( 'wp_head', 'wdk_seo_metatags');
279 function wdk_seo_metatags(){
280 global $wp_query;
281 if(isset($wp_query->post))
282 if($wp_query->post->post_type == 'wdk-listing')
283 {
284 $wdk_listing_id = $wp_query->post->ID;
285 if($wdk_listing_id) {
286 global $Winter_MVC_WDK;
287 $Winter_MVC_WDK->model('field_m');
288 $Winter_MVC_WDK->load_helper('listing');
289
290 echo '<meta name="title" content="'.esc_attr(wp_get_document_title()).'">'.PHP_EOL;
291 echo '<meta property="og:type" content="'.esc_attr(get_post_type()).'" />'.PHP_EOL;
292 echo '<meta property="og:title" content="'.esc_attr(wp_get_document_title()).'" />'.PHP_EOL;
293
294 if(get_option('wdk_seo_description')) {
295 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;
296 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;
297 }
298
299 if(get_option('wdk_seo_keywords')) {
300 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;
301 }
302
303 if(!in_array('wordpress-seo/wp-seo.php', apply_filters('active_plugins', get_option('active_plugins')))){
304 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;
305 }
306 }
307 }
308 }
309
310 /* disable some sw_seo feature if Yost seo plugin detected, for only for listing preview page and profile page */
311 add_action( 'template_redirect', 'wdk_disable_seo' );
312 function wdk_disable_seo() {
313 global $wp_query;
314 if(isset($wp_query->post))
315 if($wp_query->post->post_type == 'wdk-listing')
316 {
317 if(in_array('wordpress-seo/wp-seo.php', apply_filters('active_plugins', get_option('active_plugins')))){
318 add_filter( 'wpseo_title', '__return_false');
319 add_filter( 'wpseo_metadesc', '__return_false');
320 add_filter( 'wpseo_opengraph_url', '__return_false');
321 add_filter( 'wpseo_opengraph_title', '__return_false');
322 add_filter( 'wpseo_opengraph_image', '__return_false');
323 add_filter( 'wpseo_opengraph_type', '__return_false');
324 add_filter( 'wpseo_opengraph_desc', '__return_false');
325 }
326 }
327 }
328
329 function wdk_yoast_presentation($presentation) {
330 global $wp_query;
331 if(isset($wp_query->post))
332 if ($wp_query->post->post_type == 'wdk-listing')
333 {
334 $wdk_listing_id = $wp_query->post->ID;
335 if($wdk_listing_id) {
336 global $Winter_MVC_WDK;
337 $Winter_MVC_WDK->model('field_m');
338 $Winter_MVC_WDK->load_helper('listing');
339
340 $presentation->open_graph_images = [
341 [
342 'url' => esc_url(wdk_image_src(array('listing_images'=>wdk_field_value('listing_images', $wdk_listing_id)), 'full')),
343 ]
344 ];
345
346 }
347 }
348 return $presentation;
349 }
350 add_filter('wpseo_frontend_presentation', 'wdk_yoast_presentation', 30);
351
352 add_filter( 'wp_kses_allowed_html', 'wpdirectorykit_wpkses_post_iframe', 10, 2 );
353 function wpdirectorykit_wpkses_post_iframe( $tags, $context ) {
354 if ( 'post' === $context ) {
355 $tags['iframe'] = array(
356 'src' => true,
357 'height' => true,
358 'width' => true,
359 'frameborder' => true,
360 'allowfullscreen' => true,
361 );
362 }
363 return $tags;
364 }
365
366 add_action('wdk-membership/dash/homepage/widgets', function() {
367 if(!current_user_can('edit_own_listings') && !wmvc_user_in_role('administrator')) return false;
368
369 global $Winter_MVC_WDK;
370 $Winter_MVC_WDK->model('listing_m');
371 $total_items = $Winter_MVC_WDK->listing_m->total(array(), TRUE, get_current_user_id());
372 if(function_exists('wdk_dash_url')){
373 ?>
374 <div class="wdk-col-12 wdk-col-md-3 wdk-membership-dash-widget_listings">
375 <a href="<?php echo esc_url(wdk_dash_url('dash_page=listings'));?>" class="wdk-membership-dash-widget">
376 <span class="wdk-content">
377 <span class="icon"><span class="dashicons dashicons-location"></span></span>
378 </span>
379 <span class="wdk-side">
380 <span class="title"><?php echo esc_html__('Listings','wpdirectorykit');?></span>
381 <span class="wdk-count"><?php echo esc_html($total_items);?></span>
382 </span>
383 </a>
384 </div>
385 <?php
386 }
387 },1);
388
389 add_action('wdk-membership/dash/homepage/widgets', function() {
390 global $Winter_MVC_WDK;
391 $Winter_MVC_WDK->model('messages_m');
392 $total_items = $Winter_MVC_WDK->messages_m->total_merge(array(), TRUE, get_current_user_id());
393 if(function_exists('wdk_dash_url')){
394 ?>
395 <div class="wdk-col-12 wdk-col-md-3 wdk-membership-dash-widget_messsages">
396 <a href="<?php echo esc_url(wdk_dash_url('dash_page=messages'));?>" class="wdk-membership-dash-widget">
397 <span class="wdk-content">
398 <span class="icon"><span class="dashicons dashicons-email"></span></span>
399 </span>
400 <span class="wdk-side">
401 <span class="title"><?php echo esc_html__('Messages','wpdirectorykit');?></span>
402 <span class="wdk-count"><?php echo esc_html($total_items);?></span>
403 </span>
404 </a>
405 </div>
406 <?php
407 }
408 });
409
410 add_filter( 'woocommerce_enable_setup_wizard', '__return_false' );
411
412
413 /* detected in smart search location and replace to location id */
414 add_action( 'template_redirect', 'wdk_search_parameters' );
415 function wdk_search_parameters() {
416 global $wp_query;
417 if(!empty($_GET['field_search'])) {
418 global $Winter_MVC_WDK;
419 $Winter_MVC_WDK->model('location_m');
420 $location = $Winter_MVC_WDK->location_m->get_by(array('location_title'=>sanitize_text_field($_GET['field_search'])), TRUE);
421 if($location) {
422 $url = $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"];
423
424 $query_link = substr($url, strpos($url, '?')+1);
425 $clear_link = substr($url, 0, strpos($url, '?'));
426
427 $string_par = array();
428 parse_str( $query_link, $string_par);
429 unset($string_par['field_search']);
430 $string_par['search_location'] = $location->idlocation;
431
432 $new_url = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http").'://'.$clear_link.'?'.http_build_query($string_par);
433 wp_redirect($new_url);
434 exit;
435 }
436
437 }
438
439 }
440
441 add_filter( 'plugin_action_links_wpdirectorykit/wpdirectorykit.php', 'wdk_buy_link' );
442 function wdk_buy_link( $links ) {
443 // Build and escape the URL.
444 $url = esc_url( get_admin_url().'admin.php?page=wdk_addons' );
445 // Create the link.
446 $settings_link = "<a style=\"color:rgb(0, 163, 42);font-weight:bold;\" href='$url'>" . __( 'Check Premium Features', 'wpdirectorykit') . '</a>';
447 // Adds the link to the end of the array.
448 $links[] = $settings_link;
449 return $links;
450 }
451
452
453 ?>