($open_multiple_faqs || $open_multiple_faqs === 'yes') ? 'yes' : 'no', 'admin_url' => admin_url(), 'ajax_url' => admin_url( 'admin-ajax.php'), ); wp_localize_script('thfaqf-public-script', 'thfaqf_public_var', $faqf_var); } public function faq_shortcode($atts){ $args = shortcode_atts( array( 'id' => '', ), $atts ); $invalid_ids = array(); $faq_post_ids = explode(',', $args['id']); ob_start(); foreach($faq_post_ids as $key => $faq_post_id){ $post_status = get_post_status($faq_post_id); $post_type = get_post_type($faq_post_id); if($post_type == 'faq' && $post_status == 'publish'){ $this->faq_list($faq_post_id,'faq'); }else{ array_push($invalid_ids, $faq_post_id); } } $invalid_ids = implode(',', $invalid_ids); echo $invalid_faq_html = !empty($invalid_ids) ? '[FAQ id="'.$invalid_ids.'"]' : ''; return ob_get_clean(); } public function faq_layout_shortcode($atts){ ob_start(); $sh_args = shortcode_atts( array( 'category' => '', 'limit' => '', ), $atts ); $faq_category = $sh_args['category']; $limit = $sh_args['limit']; $category_array = explode (",", $faq_category); $pst_args = array( 'post_type' => 'faq', 'post_status' => 'publish', 'posts_per_page' => $limit, 'tax_query' => array( array( 'taxonomy' => 'faq_category', 'field' => 'slug', 'terms' => $category_array, ), ), 'order' => 'ASC', 'orderby' => 'title', ); $loop = new WP_Query( $pst_args ); $this->prepare_faq_layout($loop); wp_reset_postdata(); return ob_get_clean(); } public function prepare_faq_layout($loop){ $theme_wrapper_class = $this->get_theme_wrapper_class(); ?>
have_posts()) : $loop->the_post(); $faq_index1++; ?>
faq_search_option($show_updated_date) : ''; $last_updated = get_the_modified_date(get_option('date_format'), get_the_ID()); echo $show_updated_date ? '

'.esc_html($last_updated).'

' : ''; ?>
have_posts()) : $loop->the_post(); $tab_index++; $tab_title = get_the_title(get_the_ID()); $tab_title = $tab_title ? $tab_title : 'Title '.$tab_index; ?>
have_posts()) : $loop->the_post(); $faq_index++; ?>
faq_list(get_the_ID(),'layout'); ?>
prepare_faq_settings($global_settings, $local_settings); $border_radius = isset($settings['faq_border_radius']) ? $settings['faq_border_radius'] : 0; $faq_title_icon = isset($settings['icon_picker']) ? $settings['icon_picker'] : 0; $enable_icon_options = isset($settings['enable_disable_title_icons']) ?$settings['enable_disable_title_icons']: false; $border_radius = is_numeric($border_radius) ? $border_radius : 0; $title_color = isset($settings['title_color']) ? $settings['title_color'] : false; $title_bg = isset($settings['title_bg_color']) ? $settings['title_bg_color'] : false; $content_color = isset($settings['content_color']) ? $settings['content_color'] : false; $content_bg = isset($settings['content_bg_color']) ? $settings['content_bg_color'] : false; $expnd_icon_color = isset($settings['expnd_icon_color']) ? $settings['expnd_icon_color'] : false; $title_active_color = isset($settings['title_active_color']) ? $settings['title_active_color'] : false; $enable_search_option = isset($individual_settings['enable_disable_search_option']) ? $individual_settings['enable_disable_search_option'] : false; $faq_count = isset($settings['thfaq_count']) ? $settings['thfaq_count'] : false; $show_updated_date = THFAQF_Utils::get_setting_value($settings, 'show_updated_date'); $accordion_display_mode = THFAQF_Utils::get_setting_value($settings, 'accordion_display_mode'); $accordion_display_mode = $accordion_display_mode ? $accordion_display_mode : 'open_first'; $fist_item_active_class = $accordion_display_mode === 'open_first' ? ' thfaqf-active' : ''; $theme_wrapper_class = $this->get_theme_wrapper_class(); $item_wrapper_style = ''; $item_title_style = 'border-width: 1px; border-style: solid; margin-bottom: -1px;'; $item_content_style = 'border-width: 1px; border-style: solid;'; $title_text_style = ''; $item_expnd_icon_style = ''; $user_id = $current_user->ID; $tottal_faq_count = is_array($faqs) ? count($faqs) : 0; $visible_faq_count =!empty((int)$faq_count) ? (int)$faq_count : $tottal_faq_count; $load_button_display_none = $visible_faq_count >= $tottal_faq_count ? 'hide-faqf-group' : ''; if($border_radius){ $item_wrapper_style .= 'border-radius: '.esc_attr($border_radius).'px;'; } if($title_bg){ $item_title_style .= ' background-color: '.esc_attr($title_bg).'; border-color: '.esc_attr($title_bg).';'; } if($title_color){ $title_text_style .= ' color: '.esc_attr($title_color).';'; } if($content_bg){ $item_content_style .= ' background-color: '.esc_attr($content_bg).'; border-color: '.esc_attr($content_bg).';'; } if($content_color){ $item_content_style .= ' color: '.esc_attr($content_color).';'; } if($expnd_icon_color){ $item_expnd_icon_style = ' color: '.esc_attr($expnd_icon_color).';'; } $this->get_additional_css_for_faqs($post_id); ?>
'.get_the_title($post_id).'' : ''; echo ($enable_search_option === 'yes' || $enable_search_option === true) && $type != 'layout' ? $this->faq_search_option($show_updated_date ) : ''; if(($show_updated_date === "yes" || $show_updated_date == 1) && $type != 'layout'){ $last_updated = get_the_modified_date(get_option('date_format'), $post_id); echo '

'. esc_html($last_updated).'

'; } $index = 0; echo '
'; foreach($faqs as $key => $faq_item){ $item_wrapper_class = $index === 0 ? $fist_item_active_class : ''; $like_user_ids = !empty($faq_item['like_user_ids']) ? $faq_item['like_user_ids'] : ''; $dislike_user_ids = !empty ($faq_item['dislike_user_ids']) ? $faq_item['dislike_user_ids'] : ''; $display_none = $key < $visible_faq_count ? '' : 'thfaqf-div-none'; $this->display_faq_item($faq_item, $item_wrapper_class, $item_wrapper_style, $item_title_style, $item_content_style, $title_text_style,$item_expnd_icon_style,$post_id,$key,$like_user_ids,$dislike_user_ids,$faq_title_icon,$enable_icon_options,$user_id,$display_none,$title_active_color); $index++; } echo '
'; $this->display_social_share($post_id, $settings); $total_count = isset($faqs) ? count($faqs) : 0; $count = intdiv($total_count, $visible_faq_count); $mod = fmod($total_count, $visible_faq_count); $page_count = (($mod < $visible_faq_count) and ($mod > 0) ) ? $count+1 : $count; $pagination_panel = fmod($page_count,4)>0 ? $count = intdiv($page_count,4)+1 : intdiv($page_count,4); ?>

<< 4? 'thfaqf-div-none' : ''; ?> ... >>


display_edit_link($post_id); ?>
rate_comment($faq_comment_id); $c_color = $count_comments>0? 'color:black;': ''; ?>

like_option($post_id,$key,$like_user_ids,$dislike_user_ids,$user_id) : ''; if($enable_comment_box == true){ ?>

display_comment_box($post_id,$key);?>

$faq_single_comment_ids){ $post_status = get_post_status($faq_single_comment_ids); $post_type = get_post_type($faq_single_comment_ids); $post_content = get_post($faq_single_comment_ids); if($post_status == 'publish' and $post_type == 'user-comment'){ $content = $post_content->post_content; $content = wpautop(make_clickable(wp_kses_post($content))); $faq_cmmted_user = get_the_title($faq_single_comment_ids); ?>

$faq_single_comment_ids){ $post_status = get_post_status($faq_single_comment_ids); $post_type = get_post_type($faq_single_comment_ids); if($post_status == 'publish' and $post_type == 'user-comment'){ array_push($comment_arr,$faq_single_comment_ids); } } return isset($comment_arr) ? count($comment_arr) : 0; } public function thfaqf_comment(){ if (! isset( $_POST['wp_thfaqc_nonce'] ) || ! wp_verify_nonce( $_POST['wp_thfaqc_nonce'],'thfaqc_nonce')){ $message =array( 'verify_nonce' => 'Sorry, your nonce did not verify.'); wp_send_json($message); }else{ $submit_faq_comment = array(); $post_type = 'user-comment'; $user_name = isset($_REQUEST['user_name']) ? trim($_REQUEST['user_name']) : false; $user_msg = isset($_REQUEST['user_msg']) ? trim($_REQUEST['user_msg']) : false; $faq_id = isset($_REQUEST['faq_id']) ? trim($_REQUEST['faq_id']) : false; $faq_index = isset($_REQUEST['faq_index']) ? trim($_REQUEST['faq_index']) : false; $post_status = get_post_status($faq_id); $user_name = sanitize_text_field(stripslashes($user_name)); $user_msg = wp_filter_post_kses(stripslashes($user_msg)); $faq_id = sanitize_text_field($faq_id); $faq_index = sanitize_text_field($faq_index); $message = array(); if(empty($user_name)){ $message['name'] = "Name is a required field."; } if(empty($user_msg)){ $message['comment'] = "Comment is a required field."; } if(!empty($message)){ wp_send_json($message); }else{ $submit_faq_comment = array( 'post_title' => $user_name, 'post_content' => $user_msg, 'post_type' => $post_type, 'post_status' => 'draft', ); $post_id = wp_insert_post( $submit_faq_comment, $wp_error = false ); $faq_data = get_post_meta($faq_id, THFAQF_Utils::OPTION_KEY_FAQ_ITEMS, true); $faq_comment_string = isset($faq_data[$faq_index]['faq_comment']) ? $faq_data[$faq_index]['faq_comment'] : ''; if($faq_comment_string){ $faq_comments_array = explode(',', $faq_comment_string); if(is_array($faq_comments_array)){ array_push($faq_comments_array,$post_id); } }else{ $faq_comments_array = array($post_id); } $faq_comments = implode(',', $faq_comments_array); $faq_data[$faq_index]['faq_comment'] = $faq_comments; if($post_status == 'publish'){ $update_data1 = update_post_meta($faq_id, THFAQF_Utils::OPTION_KEY_FAQ_ITEMS,$faq_data); } $message = 'Comment posted successfully.'; } } wp_send_json($message); } public function display_social_share($post_id, $settings){ $enabled_share_button = THFAQF_Utils::get_setting_value($settings, 'enable_share_button'); if($enabled_share_button === 'yes' || $enabled_share_button == 1){ $post_url = get_post_permalink($post_id); $social_share_icons = THFAQF_Utils::get_setting_value($settings, 'social_share_options'); $social_share_icons = $social_share_icons ? explode(',', $social_share_icons) : false; $social_share_html = ''; if(is_array($social_share_icons)){ foreach($social_share_icons as $key){ $link = ''; if($key === 'twitter'){ $url = 'https://twitter.com/home?status='.esc_url($post_url); $link = ''; }else if($key === 'facebook'){ $url = 'https://www.facebook.com/sharer/sharer.php?u='.esc_url($post_url); $link = ''; }else if($key === 'email'){ $url = 'mailto:info@example.com?&subject=&body='.esc_url($post_url); $link = ''; }else if($key === 'linkedin'){ $url = 'https://www.linkedin.com/shareArticle?mini=true&url='.esc_url($post_url); $link = ''; }else if($key === 'pinterest'){ $url = 'https://pinterest.com/pin/create/button/?url='.esc_url($post_url) ; $link = ''; }else if($key === 'whatsapp'){ $url = 'https://web.whatsapp.com/send?text='. esc_url($post_url); $link = ''; } $social_share_html .= $link; } } if($social_share_html){ $social_share_title = THFAQF_Utils::get_setting_value($settings, 'social_share_title'); ?> $value) { if($value){ $global_settings[$key] = $value; } } } } return $global_settings; } public function get_theme_wrapper_class(){ $current_theme = wp_get_theme(); $current_theme_name = isset($current_theme['Template']) ? $current_theme['Template'] : ''; $wrapper_class = ''; if($current_theme_name){ $wrapper_class = str_replace(' ', '-', strtolower($current_theme_name)); $wrapper_class = 'thfaqf-theme-wrapper-'.$wrapper_class; } return $wrapper_class; } public function prepare_colour_settings($faq_cleaned_color, $general_settings){ $settings_fields = THFAQF_Utils::get_settings_fields(); $use_post_settings = isset($faq_cleaned_color['use_post_settings']) ? $faq_cleaned_color['use_post_settings'] : ''; if(($use_post_settings == 'yes') and (!empty($faq_cleaned_color))){ $title_color = isset($faq_cleaned_color['title_color'])?$faq_cleaned_color['title_color']:''; $title_bg_color = isset($faq_cleaned_color['title_bg_color'])?$faq_cleaned_color['title_bg_color']:''; $content_color = isset($faq_cleaned_color['content_color'])?$faq_cleaned_color['content_color']:''; $content_bg_color = isset($faq_cleaned_color['content_bg_color'])?$faq_cleaned_color['content_bg_color']:''; }else{ $title_color = isset($general_settings['title_color'])?$general_settings['title_color']:$settings_fields['title_color']['value']; $title_bg_color = isset($general_settings['title_bg_color'])?$general_settings['title_bg_color']:$settings_fields['title_bg_color']['value']; $content_color = isset($general_settings['content_color'])?$general_settings['content_color']:$settings_fields['content_color']['value']; $content_bg_color = isset($general_settings['content_bg_color'])?$general_settings['content_bg_color']:$settings_fields['content_bg_color']['value']; } $data = array( 'title_color' => $title_color, 'title_bg_color' => $title_bg_color, 'content_color' => $content_color, 'content_bg_color' => $content_bg_color, ); return $data; } public function like_option($post_id,$key,$like_user_ids,$dislike_user_ids,$user_id){ $liked_user = !empty($like_user_ids) ? explode(',', $like_user_ids): array(); $dislikeliked_user = !empty($dislike_user_ids) ? explode(',', $dislike_user_ids): array(); $like_count = is_array($liked_user) ? count($liked_user) : 0; $dislike_count = is_array($dislikeliked_user) ? count($dislikeliked_user) : 0; $l_color = in_array($user_id, $liked_user) ? 'color:black' : ''; $d_color = in_array($user_id, $dislikeliked_user) ? 'color:black' : ''; $user_login = $user_id<=0 ? wp_login_url( get_permalink() ) : '#'; ?>
'Sorry, your nonce did not verify.'); wp_send_json($responce); }else{ global $current_user; $user_id = $current_user->ID; $value = isset($_REQUEST['value']) ? trim($_REQUEST['value']) : false; $faq_uid = isset($_REQUEST['uid']) ? trim($_REQUEST['uid']) : false; $post_id = isset($_REQUEST['post_id']) ? trim($_REQUEST['post_id']) : false; $faq_data = get_post_meta($post_id, THFAQF_Utils::OPTION_KEY_FAQ_ITEMS, true); $value = sanitize_text_field($value); $faq_uid = sanitize_text_field($faq_uid); $post_id = sanitize_text_field($post_id); $result = array(); if ($user_id >0){ $faq_liked_user_string = !empty($faq_data[$faq_uid]['like_user_ids']) ? trim($faq_data[$faq_uid]['like_user_ids']) : false; $faq_disliked_user_string = !empty($faq_data[$faq_uid]['dislike_user_ids']) ? trim($faq_data[$faq_uid]['dislike_user_ids']) : false; $faq_liked_user_array = explode(',', $faq_liked_user_string); $faq_disliked_user_array = explode(',', $faq_disliked_user_string); if($value =='like'){ if($faq_disliked_user_string){ foreach ($faq_disliked_user_array as $key => $id){ if($user_id == $id){ unset($faq_disliked_user_array[$key]); } } } if($faq_liked_user_string){ if(!in_array($user_id, $faq_liked_user_array)){ array_push($faq_liked_user_array,$user_id); }else{ foreach ($faq_liked_user_array as $key => $id){ if($user_id == $id){ unset($faq_liked_user_array[$key]); } } } }else{ $faq_liked_user_array = array($user_id); } }else{ if($faq_liked_user_string){ foreach ($faq_liked_user_array as $key => $id){ if($user_id == $id){ unset($faq_liked_user_array[$key]); } } } if($faq_disliked_user_string){ if(!in_array($user_id, $faq_disliked_user_array)){ array_push($faq_disliked_user_array,$user_id); }else{ foreach ($faq_disliked_user_array as $key => $id){ if($user_id == $id){ unset($faq_disliked_user_array[$key]); } } } }else{ $faq_disliked_user_array = array($user_id); } } $faq_liked_user_array = array_filter($faq_liked_user_array); $faq_disliked_user_array = array_filter($faq_disliked_user_array); $user_like = implode(',', $faq_liked_user_array); $user_dislike = implode(',', $faq_disliked_user_array); $faq_data[$faq_uid]['like_user_ids'] = $user_like; $faq_data[$faq_uid]['dislike_user_ids'] = $user_dislike; $update = update_post_meta($post_id, THFAQF_Utils::OPTION_KEY_FAQ_ITEMS,$faq_data); $result = array('like_user_ids' => $faq_liked_user_array,'dislike_user_ids' => $faq_disliked_user_array,'current_user_id' => $user_id); if($update) wp_send_json($result); } } } public function get_additional_css_for_faqs($id){ $global_settings = THFAQF_Utils::get_faq_settings(); $css = isset($global_settings['thfaq_custom_css']) ? $global_settings['thfaq_custom_css'] : ''; $enable = isset($global_settings['enable_thfaq_custom_css']) ? $global_settings['enable_thfaq_custom_css'] : ''; $local_settings = get_post_meta($id, THFAQF_Utils::OPTION_KEY_FAQ_SETTINGS_POST, true); $settings = $this->prepare_faq_settings($global_settings, $local_settings); $title_active_color = isset($settings['title_active_color']) ? $settings['title_active_color'] : '#cc2753'; $tab_active_color = isset($settings['tab_active_color']) ? $settings['tab_active_color'] : '#cc2753'; $tab_bg_color = isset($settings['tab_bg_color']) ? $settings['tab_bg_color'] : '#f5f5f5'; ?>