| 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_filter('the_content', 'wdk_content'); |
| 13 |
|
| 14 |
function wdk_content( $content ) |
| 15 |
{ |
| 16 |
global $wp_query; |
| 17 |
global $wdk_listing_id; |
| 18 |
global $wdk_listing_page_id; |
| 19 |
if(isset($wp_query->post)) |
| 20 |
if($wp_query->post->post_type == 'wdk-listing') |
| 21 |
{ |
| 22 |
$wdk_listing_id = $wp_query->post->ID; |
| 23 |
$wdk_listing_page_id = get_option('wdk_listing_page'); |
| 24 |
if(!empty($wdk_listing_page_id) && get_post_status($wdk_listing_page_id) =='publish') |
| 25 |
{ |
| 26 |
global $Winter_MVC_WDK; |
| 27 |
$Winter_MVC_WDK->load_helper('listing'); |
| 28 |
if(wdk_field_value('is_activated', $wdk_listing_id,false) && wdk_field_value('is_approved', $wdk_listing_id,false)) { |
| 29 |
|
| 30 |
if(wdk_get_option('wdk_membership_is_enable_subscriptions') && wdk_get_option('wdk_membership_subscriptions_view_listing_enabled') && function_exists('run_wdk_membership')){ |
| 31 |
/* if required subscription with View details listing */ |
| 32 |
|
| 33 |
/* if not login, return alert for ask login */ |
| 34 |
if(is_user_logged_in()) { |
| 35 |
|
| 36 |
global $Winter_MVC_wdk_membership; |
| 37 |
$Winter_MVC_wdk_membership->model('subscription_m'); |
| 38 |
$Winter_MVC_wdk_membership->model('subscription_user_m'); |
| 39 |
$user_subscriptions_listings_view = $Winter_MVC_wdk_membership->subscription_user_m->get_pagination(NULL, FALSE, array('is_activated'=>1,'is_view_private_listings'=>1)); |
| 40 |
|
| 41 |
/* if not allow subscription, return alert for subscription on dash page */ |
| 42 |
if(empty($user_subscriptions_listings_view)){ |
| 43 |
$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>'; |
| 44 |
} else { |
| 45 |
if(class_exists('Elementor\Plugin')) |
| 46 |
{ |
| 47 |
$content = ''; |
| 48 |
$elementor_instance = Elementor\Plugin::instance(); |
| 49 |
$content = $elementor_instance->frontend->get_builder_content_for_display($wdk_listing_page_id); |
| 50 |
} |
| 51 |
} |
| 52 |
} else { |
| 53 |
$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>'; |
| 54 |
} |
| 55 |
|
| 56 |
} |
| 57 |
/* if login required */ |
| 58 |
elseif(get_option('wdk_membership_login_required_listing_preview') && !is_user_logged_in()){ |
| 59 |
if(get_option('wdk_membership_login_page')){ |
| 60 |
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')))); |
| 61 |
// exit(); |
| 62 |
} else { |
| 63 |
wp_redirect(wp_login_url(wdk_current_url())); |
| 64 |
} |
| 65 |
} |
| 66 |
else { |
| 67 |
if(class_exists('Elementor\Plugin')) |
| 68 |
{ |
| 69 |
$content = ''; |
| 70 |
$elementor_instance = Elementor\Plugin::instance(); |
| 71 |
$content = $elementor_instance->frontend->get_builder_content_for_display($wdk_listing_page_id); |
| 72 |
|
| 73 |
$custom_css = ''; |
| 74 |
|
| 75 |
$wdk_listing_id; |
| 76 |
$Winter_MVC_WDK->model('field_m'); |
| 77 |
|
| 78 |
$Winter_MVC_WDK->db->where(array('field_type !='=> 'SECTION')); |
| 79 |
$fields = $Winter_MVC_WDK->field_m->get(); |
| 80 |
|
| 81 |
foreach($fields as $field) { |
| 82 |
if(wdk_field_value ($field->idfield, $wdk_listing_id)) continue; |
| 83 |
|
| 84 |
if(!empty($custom_css)) $custom_css .= ','; |
| 85 |
|
| 86 |
$custom_css .= '.wdk_'.$field->idfield.'_hide_empty'; |
| 87 |
} |
| 88 |
|
| 89 |
if(!wdk_field_value ('lat', $wdk_listing_id, false) || !wdk_field_value ('lng', $wdk_listing_id)) { |
| 90 |
if(!empty($custom_css)) $custom_css .= ','; |
| 91 |
$custom_css .= '.wdk_map_hide_empty'; |
| 92 |
} |
| 93 |
|
| 94 |
if(!wdk_field_value ('is_featured', $wdk_listing_id, false)) { |
| 95 |
if(!empty($custom_css)) $custom_css .= ','; |
| 96 |
$custom_css .= '.wdk_is_featured_hide_empty'; |
| 97 |
} |
| 98 |
|
| 99 |
$custom_css .= '{display: none !important}'; |
| 100 |
|
| 101 |
wp_enqueue_style('wdk-custom-inline', WPDIRECTORYKIT_URL.'public/css/custom-inline.css'); |
| 102 |
wp_add_inline_style( 'wdk-custom-inline', $custom_css); |
| 103 |
|
| 104 |
} |
| 105 |
} |
| 106 |
|
| 107 |
} else { |
| 108 |
$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>'; |
| 109 |
} |
| 110 |
} else { |
| 111 |
$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>'; |
| 112 |
} |
| 113 |
|
| 114 |
} |
| 115 |
return $content; |
| 116 |
} |
| 117 |
|
| 118 |
function wdk_do_header() { |
| 119 |
// get all elementor pro builder conditions |
| 120 |
$pro_theme_builder_conditions = get_option('elementor_pro_theme_builder_conditions'); |
| 121 |
$listing_page_id = get_option('wdk_listing_page'); |
| 122 |
|
| 123 |
if(!empty($pro_theme_builder_conditions)) |
| 124 |
{ |
| 125 |
foreach($pro_theme_builder_conditions['header'] as $header_post_id => $header_on_pages) |
| 126 |
{ |
| 127 |
foreach($header_on_pages as $pages) |
| 128 |
{ |
| 129 |
$accepted_page_id = substr($pages, strrpos($pages, '/')+1); |
| 130 |
|
| 131 |
if($accepted_page_id == $listing_page_id) |
| 132 |
{ |
| 133 |
// render header content |
| 134 |
|
| 135 |
$elementor_instance = \Elementor\Plugin::instance(); |
| 136 |
$content = $elementor_instance->frontend->get_builder_content_for_display($header_post_id); |
| 137 |
|
| 138 |
echo wp_kses_post( $content ); |
| 139 |
return; |
| 140 |
} |
| 141 |
} |
| 142 |
} |
| 143 |
} |
| 144 |
} |
| 145 |
|
| 146 |
function wdk_do_footer() { |
| 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['footer'] as $footer_post_id => $footer_on_pages) |
| 154 |
{ |
| 155 |
foreach($footer_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 footer content |
| 162 |
|
| 163 |
$elementor_instance = \Elementor\Plugin::instance(); |
| 164 |
$content = $elementor_instance->frontend->get_builder_content_for_display($footer_post_id); |
| 165 |
|
| 166 |
echo wp_kses_post( $content ); |
| 167 |
return; |
| 168 |
} |
| 169 |
} |
| 170 |
} |
| 171 |
} |
| 172 |
} |
| 173 |
|
| 174 |
function wdk_do_body_class($classes) |
| 175 |
{ |
| 176 |
if(class_exists('Elementor\Plugin')) |
| 177 |
{ |
| 178 |
$elementor_instance = \Elementor\Plugin::instance(); |
| 179 |
$classes = $elementor_instance->frontend->body_class(); |
| 180 |
} |
| 181 |
|
| 182 |
return $classes; |
| 183 |
} |
| 184 |
|
| 185 |
function wdk_page_template ($template) { |
| 186 |
global $wp_query; |
| 187 |
if(isset($wp_query->post)) |
| 188 |
if($wp_query->post->post_type == 'wdk-listing') |
| 189 |
{ |
| 190 |
$listing_page_id = get_option('wdk_listing_page'); |
| 191 |
$template_elem = get_post_meta($listing_page_id, '_wp_page_template', true); |
| 192 |
|
| 193 |
if($template_elem == 'elementor_theme') |
| 194 |
{ |
| 195 |
// for elementor pro theme builder basic support |
| 196 |
$template_elem = 'elementor_canvas'; |
| 197 |
|
| 198 |
add_filter( 'body_class', 'wdk_do_body_class' ); |
| 199 |
add_action( 'elementor/page_templates/canvas/before_content', 'wdk_do_header' , 0 ); |
| 200 |
add_action( 'elementor/page_templates/canvas/after_content', 'wdk_do_footer' , 0 ); |
| 201 |
} |
| 202 |
|
| 203 |
if($template_elem == 'elementor_canvas' || $template_elem == 'elementor_header_footer' ){ |
| 204 |
/** |
| 205 |
* @var \Elementor\Modules\PageTemplates\Module $page_templates_module |
| 206 |
*/ |
| 207 |
if(class_exists('Elementor\Plugin')) |
| 208 |
{ |
| 209 |
$page_templates_module = Elementor\Plugin::instance()->modules_manager->get_modules( 'page-templates' ); |
| 210 |
$template = $page_templates_module->get_template_path( $template_elem ); |
| 211 |
} |
| 212 |
} |
| 213 |
} |
| 214 |
return $template; |
| 215 |
} |
| 216 |
add_filter ('single_template', 'wdk_page_template'); |
| 217 |
|
| 218 |
add_action('admin_bar_menu', 'wdk_add_toolbar_items', 100); |
| 219 |
function wdk_add_toolbar_items($admin_bar){ |
| 220 |
global $wp_query; |
| 221 |
if(isset($wp_query->post)) |
| 222 |
if ($wp_query->post->post_type == 'wdk-listing') { |
| 223 |
$admin_bar->add_menu(array( |
| 224 |
'id' => 'edit', |
| 225 |
'title' => __('Edit Listing', 'wpdirectorykit'), |
| 226 |
'href' => admin_url('admin.php?page=wdk_listing&id='.$wp_query->post->ID), |
| 227 |
)); |
| 228 |
} |
| 229 |
} |
| 230 |
|
| 231 |
if(get_option('wdk_slug_listing_preview_page')){ |
| 232 |
function wdk_custom_listing_preview_page_slug( $args, $post_type ) { |
| 233 |
|
| 234 |
if(get_option('wdk_slug_listing_preview_page_changed')){ |
| 235 |
update_option('wdk_slug_listing_preview_page_changed', 0); |
| 236 |
flush_rewrite_rules(); |
| 237 |
} |
| 238 |
|
| 239 |
/*item post type slug*/ |
| 240 |
if ( 'wdk-listing' === $post_type ) { |
| 241 |
$args['rewrite']['slug'] = get_option('wdk_slug_listing_preview_page'); |
| 242 |
} |
| 243 |
|
| 244 |
return $args; |
| 245 |
} |
| 246 |
add_filter( 'register_post_type_args', 'wdk_custom_listing_preview_page_slug', 10, 2 ); |
| 247 |
} |
| 248 |
|
| 249 |
/* seo wdk feature, wp overwrite wp_head */ |
| 250 |
add_action( 'wp_head', 'wdk_seo_metatags'); |
| 251 |
function wdk_seo_metatags(){ |
| 252 |
global $wp_query; |
| 253 |
if(isset($wp_query->post)) |
| 254 |
if($wp_query->post->post_type == 'wdk-listing') |
| 255 |
{ |
| 256 |
$wdk_listing_id = $wp_query->post->ID; |
| 257 |
if($wdk_listing_id) { |
| 258 |
global $Winter_MVC_WDK; |
| 259 |
$Winter_MVC_WDK->model('field_m'); |
| 260 |
$Winter_MVC_WDK->load_helper('listing'); |
| 261 |
|
| 262 |
echo '<meta name="title" content="'.esc_attr(wp_get_document_title()).'">'.PHP_EOL; |
| 263 |
echo '<meta property="og:type" content="'.esc_attr(get_post_type()).'" />'.PHP_EOL; |
| 264 |
echo '<meta property="og:title" content="'.esc_attr(wp_get_document_title()).'" />'.PHP_EOL; |
| 265 |
|
| 266 |
if(get_option('wdk_seo_description')) { |
| 267 |
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; |
| 268 |
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; |
| 269 |
} |
| 270 |
|
| 271 |
if(get_option('wdk_seo_keywords')) { |
| 272 |
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; |
| 273 |
} |
| 274 |
|
| 275 |
if(!in_array('wordpress-seo/wp-seo.php', apply_filters('active_plugins', get_option('active_plugins')))){ |
| 276 |
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; |
| 277 |
} |
| 278 |
} |
| 279 |
} |
| 280 |
} |
| 281 |
|
| 282 |
/* disable some sw_seo feature if Yost seo plugin detected, for only for listing preview page and profile page */ |
| 283 |
add_action( 'template_redirect', 'wdk_disable_seo' ); |
| 284 |
function wdk_disable_seo() { |
| 285 |
global $wp_query; |
| 286 |
if(isset($wp_query->post)) |
| 287 |
if($wp_query->post->post_type == 'wdk-listing') |
| 288 |
{ |
| 289 |
if(in_array('wordpress-seo/wp-seo.php', apply_filters('active_plugins', get_option('active_plugins')))){ |
| 290 |
add_filter( 'wpseo_title', '__return_false'); |
| 291 |
add_filter( 'wpseo_metadesc', '__return_false'); |
| 292 |
add_filter( 'wpseo_opengraph_url', '__return_false'); |
| 293 |
add_filter( 'wpseo_opengraph_title', '__return_false'); |
| 294 |
add_filter( 'wpseo_opengraph_image', '__return_false'); |
| 295 |
add_filter( 'wpseo_opengraph_type', '__return_false'); |
| 296 |
add_filter( 'wpseo_opengraph_desc', '__return_false'); |
| 297 |
} |
| 298 |
} |
| 299 |
} |
| 300 |
|
| 301 |
function wdk_yoast_presentation($presentation) { |
| 302 |
global $wp_query; |
| 303 |
if(isset($wp_query->post)) |
| 304 |
if ($wp_query->post->post_type == 'wdk-listing') |
| 305 |
{ |
| 306 |
$wdk_listing_id = $wp_query->post->ID; |
| 307 |
if($wdk_listing_id) { |
| 308 |
global $Winter_MVC_WDK; |
| 309 |
$Winter_MVC_WDK->model('field_m'); |
| 310 |
$Winter_MVC_WDK->load_helper('listing'); |
| 311 |
|
| 312 |
$presentation->open_graph_images = [ |
| 313 |
[ |
| 314 |
'url' => esc_url(wdk_image_src(array('listing_images'=>wdk_field_value('listing_images', $wdk_listing_id)), 'full')), |
| 315 |
] |
| 316 |
]; |
| 317 |
|
| 318 |
} |
| 319 |
} |
| 320 |
return $presentation; |
| 321 |
} |
| 322 |
add_filter('wpseo_frontend_presentation', 'wdk_yoast_presentation', 30); |
| 323 |
|
| 324 |
add_filter( 'wp_kses_allowed_html', 'wpdirectorykit_wpkses_post_iframe', 10, 2 ); |
| 325 |
function wpdirectorykit_wpkses_post_iframe( $tags, $context ) { |
| 326 |
if ( 'post' === $context ) { |
| 327 |
$tags['iframe'] = array( |
| 328 |
'src' => true, |
| 329 |
'height' => true, |
| 330 |
'width' => true, |
| 331 |
'frameborder' => true, |
| 332 |
'allowfullscreen' => true, |
| 333 |
); |
| 334 |
} |
| 335 |
return $tags; |
| 336 |
} |
| 337 |
|
| 338 |
add_action('wdk-membership/dash/homepage/widgets', function() { |
| 339 |
global $Winter_MVC_WDK; |
| 340 |
$Winter_MVC_WDK->model('listing_m'); |
| 341 |
$total_items = $Winter_MVC_WDK->listing_m->total(array(), TRUE, get_current_user_id()); |
| 342 |
if(function_exists('wdk_dash_url')){ |
| 343 |
?> |
| 344 |
<div class="wdk-col-12 wdk-col-md-3"> |
| 345 |
<a href="<?php echo esc_url(wdk_dash_url('dash_page=listings'));?>" class="wdk-membership-dash-widget"> |
| 346 |
<span class="wdk-content"> |
| 347 |
<span class="icon"><span class="dashicons dashicons-location"></span></span> |
| 348 |
</span> |
| 349 |
<span class="wdk-side"> |
| 350 |
<span class="title"><?php echo esc_html__('Listings','wpdirectorykit');?></span> |
| 351 |
<span class="wdk-count"><?php echo esc_html($total_items);?></span> |
| 352 |
</span> |
| 353 |
</a> |
| 354 |
</div> |
| 355 |
<?php |
| 356 |
} |
| 357 |
},1); |
| 358 |
|
| 359 |
?> |