post))
if($wp_query->post->post_type == 'wdk-listing')
{
$wdk_listing_id = $wp_query->post->ID;
$wdk_listing_page_id = get_option('wdk_listing_page');
if(!empty($wdk_listing_page_id) && get_post_status($wdk_listing_page_id) =='publish')
{
global $Winter_MVC_WDK;
$Winter_MVC_WDK->load_helper('listing');
if(wdk_field_value('is_activated', $wdk_listing_id,false) && wdk_field_value('is_approved', $wdk_listing_id,false)) {
if(wdk_get_option('wdk_membership_is_enable_subscriptions') && wdk_get_option('wdk_membership_subscriptions_view_listing_enabled') && function_exists('run_wdk_membership')){
/* if required subscription with View details listing */
/* if not login, return alert for ask login */
if(is_user_logged_in()) {
global $Winter_MVC_wdk_membership;
$Winter_MVC_wdk_membership->model('subscription_m');
$Winter_MVC_wdk_membership->model('subscription_user_m');
$user_subscriptions_listings_view = $Winter_MVC_wdk_membership->subscription_user_m->get_pagination(NULL, FALSE, array('is_activated'=>1,'is_view_private_listings'=>1));
/* if not allow subscription, return alert for subscription on dash page */
if(empty($user_subscriptions_listings_view)){
$content = '
';
} else {
if(class_exists('Elementor\Plugin'))
{
$content = '';
$elementor_instance = Elementor\Plugin::instance();
$content = $elementor_instance->frontend->get_builder_content_for_display($wdk_listing_page_id);
}
}
} else {
$content = '';
}
}
/* if login required */
elseif(get_option('wdk_membership_login_required_listing_preview') && !is_user_logged_in()){
if(get_option('wdk_membership_login_page')){
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'))));
// exit();
} else {
wp_redirect(wp_login_url(wdk_current_url()));
}
}
else {
if(class_exists('Elementor\Plugin'))
{
$content = '';
$elementor_instance = Elementor\Plugin::instance();
$content = $elementor_instance->frontend->get_builder_content_for_display($wdk_listing_page_id);
$custom_css = '';
$wdk_listing_id;
$Winter_MVC_WDK->model('field_m');
$Winter_MVC_WDK->db->where(array('field_type !='=> 'SECTION'));
$fields = $Winter_MVC_WDK->field_m->get();
foreach($fields as $field) {
if(wdk_field_value ($field->idfield, $wdk_listing_id)) continue;
if(!empty($custom_css)) $custom_css .= ',';
$custom_css .= '.wdk_'.$field->idfield.'_hide_empty';
}
if(!wdk_field_value ('lat', $wdk_listing_id, false) || !wdk_field_value ('lng', $wdk_listing_id)) {
if(!empty($custom_css)) $custom_css .= ',';
$custom_css .= '.wdk_map_hide_empty';
}
if(!wdk_field_value ('is_featured', $wdk_listing_id, false)) {
if(!empty($custom_css)) $custom_css .= ',';
$custom_css .= '.wdk_is_featured_hide_empty';
}
$custom_css .= '{display: none !important}';
wp_enqueue_style('wdk-custom-inline', WPDIRECTORYKIT_URL.'public/css/custom-inline.css');
wp_add_inline_style( 'wdk-custom-inline', $custom_css);
}
}
} else {
$content = '';
}
} else {
$content = '';
}
}
return $content;
}
function wdk_do_header() {
// get all elementor pro builder conditions
$pro_theme_builder_conditions = get_option('elementor_pro_theme_builder_conditions');
$listing_page_id = get_option('wdk_listing_page');
if(!empty($pro_theme_builder_conditions))
{
foreach($pro_theme_builder_conditions['header'] as $header_post_id => $header_on_pages)
{
foreach($header_on_pages as $pages)
{
$accepted_page_id = substr($pages, strrpos($pages, '/')+1);
if($accepted_page_id == $listing_page_id)
{
// render header content
$elementor_instance = \Elementor\Plugin::instance();
$content = $elementor_instance->frontend->get_builder_content_for_display($header_post_id);
echo wp_kses_post( $content );
return;
}
}
}
}
}
function wdk_do_footer() {
// get all elementor pro builder conditions
$pro_theme_builder_conditions = get_option('elementor_pro_theme_builder_conditions');
$listing_page_id = get_option('wdk_listing_page');
if(!empty($pro_theme_builder_conditions))
{
foreach($pro_theme_builder_conditions['footer'] as $footer_post_id => $footer_on_pages)
{
foreach($footer_on_pages as $pages)
{
$accepted_page_id = substr($pages, strrpos($pages, '/')+1);
if($accepted_page_id == $listing_page_id)
{
// render footer content
$elementor_instance = \Elementor\Plugin::instance();
$content = $elementor_instance->frontend->get_builder_content_for_display($footer_post_id);
echo wp_kses_post( $content );
return;
}
}
}
}
}
function wdk_do_body_class($classes)
{
if(class_exists('Elementor\Plugin'))
{
$elementor_instance = \Elementor\Plugin::instance();
$classes = $elementor_instance->frontend->body_class();
}
return $classes;
}
function wdk_page_template ($template) {
global $wp_query;
if(isset($wp_query->post))
if($wp_query->post->post_type == 'wdk-listing')
{
$listing_page_id = get_option('wdk_listing_page');
$template_elem = get_post_meta($listing_page_id, '_wp_page_template', true);
if($template_elem == 'elementor_theme')
{
// for elementor pro theme builder basic support
$template_elem = 'elementor_canvas';
add_filter( 'body_class', 'wdk_do_body_class' );
add_action( 'elementor/page_templates/canvas/before_content', 'wdk_do_header' , 0 );
add_action( 'elementor/page_templates/canvas/after_content', 'wdk_do_footer' , 0 );
}
if($template_elem == 'elementor_canvas' || $template_elem == 'elementor_header_footer' ){
/**
* @var \Elementor\Modules\PageTemplates\Module $page_templates_module
*/
if(class_exists('Elementor\Plugin'))
{
$page_templates_module = Elementor\Plugin::instance()->modules_manager->get_modules( 'page-templates' );
$template = $page_templates_module->get_template_path( $template_elem );
}
}
}
return $template;
}
add_filter ('single_template', 'wdk_page_template');
add_action('admin_bar_menu', 'wdk_add_toolbar_items', 100);
function wdk_add_toolbar_items($admin_bar){
global $wp_query;
if(isset($wp_query->post))
if ($wp_query->post->post_type == 'wdk-listing') {
$admin_bar->add_menu(array(
'id' => 'edit',
'title' => __('Edit Listing', 'wpdirectorykit'),
'href' => admin_url('admin.php?page=wdk_listing&id='.$wp_query->post->ID),
));
}
}
if(get_option('wdk_slug_listing_preview_page')){
function wdk_custom_listing_preview_page_slug( $args, $post_type ) {
if(get_option('wdk_slug_listing_preview_page_changed')){
update_option('wdk_slug_listing_preview_page_changed', 0);
flush_rewrite_rules();
}
/*item post type slug*/
if ( 'wdk-listing' === $post_type ) {
$args['rewrite']['slug'] = get_option('wdk_slug_listing_preview_page');
}
return $args;
}
add_filter( 'register_post_type_args', 'wdk_custom_listing_preview_page_slug', 10, 2 );
}
/* seo wdk feature, wp overwrite wp_head */
add_action( 'wp_head', 'wdk_seo_metatags');
function wdk_seo_metatags(){
global $wp_query;
if(isset($wp_query->post))
if($wp_query->post->post_type == 'wdk-listing')
{
$wdk_listing_id = $wp_query->post->ID;
if($wdk_listing_id) {
global $Winter_MVC_WDK;
$Winter_MVC_WDK->model('field_m');
$Winter_MVC_WDK->load_helper('listing');
echo ''.PHP_EOL;
echo ''.PHP_EOL;
echo ''.PHP_EOL;
if(get_option('wdk_seo_description')) {
echo ''.PHP_EOL;
echo ''.PHP_EOL;
}
if(get_option('wdk_seo_keywords')) {
echo ''.PHP_EOL;
}
if(!in_array('wordpress-seo/wp-seo.php', apply_filters('active_plugins', get_option('active_plugins')))){
echo ''.PHP_EOL;
}
}
}
}
/* disable some sw_seo feature if Yost seo plugin detected, for only for listing preview page and profile page */
add_action( 'template_redirect', 'wdk_disable_seo' );
function wdk_disable_seo() {
global $wp_query;
if(isset($wp_query->post))
if($wp_query->post->post_type == 'wdk-listing')
{
if(in_array('wordpress-seo/wp-seo.php', apply_filters('active_plugins', get_option('active_plugins')))){
add_filter( 'wpseo_title', '__return_false');
add_filter( 'wpseo_metadesc', '__return_false');
add_filter( 'wpseo_opengraph_url', '__return_false');
add_filter( 'wpseo_opengraph_title', '__return_false');
add_filter( 'wpseo_opengraph_image', '__return_false');
add_filter( 'wpseo_opengraph_type', '__return_false');
add_filter( 'wpseo_opengraph_desc', '__return_false');
}
}
}
function wdk_yoast_presentation($presentation) {
global $wp_query;
if(isset($wp_query->post))
if ($wp_query->post->post_type == 'wdk-listing')
{
$wdk_listing_id = $wp_query->post->ID;
if($wdk_listing_id) {
global $Winter_MVC_WDK;
$Winter_MVC_WDK->model('field_m');
$Winter_MVC_WDK->load_helper('listing');
$presentation->open_graph_images = [
[
'url' => esc_url(wdk_image_src(array('listing_images'=>wdk_field_value('listing_images', $wdk_listing_id)), 'full')),
]
];
}
}
return $presentation;
}
add_filter('wpseo_frontend_presentation', 'wdk_yoast_presentation', 30);
add_filter( 'wp_kses_allowed_html', 'wpdirectorykit_wpkses_post_iframe', 10, 2 );
function wpdirectorykit_wpkses_post_iframe( $tags, $context ) {
if ( 'post' === $context ) {
$tags['iframe'] = array(
'src' => true,
'height' => true,
'width' => true,
'frameborder' => true,
'allowfullscreen' => true,
);
}
return $tags;
}
add_action('wdk-membership/dash/homepage/widgets', function() {
global $Winter_MVC_WDK;
$Winter_MVC_WDK->model('listing_m');
$total_items = $Winter_MVC_WDK->listing_m->total(array(), TRUE, get_current_user_id());
if(function_exists('wdk_dash_url')){
?>