create_faq_post_type(); } public function init(){ // add init functions } // create faq custom post type private function create_faq_post_type(){ $faq_labels = array( 'name' => ('FAQ'), 'singular_name' => ('FAQ'), 'add_new' => __('Add New', 'advanced-faq-manager'), 'all_items' => __('All FAQ', 'advanced-faq-manager'), 'add_new_item' => __('Add New FAQ', 'advanced-faq-manager'), 'edit_item' => __('Edit FAQ', 'advanced-faq-manager'), 'new_item' => __('New FAQ', 'advanced-faq-manager'), 'view_item' => __('Vew FAQ', 'advanced-faq-manager'), 'search_items' => __('Search FAQ', 'advanced-faq-manager'), 'not_found' => __('No FAQ Found', 'advanced-faq-manager'), 'not_found_in_trash' => __('No FAQ Found in Trash ', 'advanced-faq-manager'), 'parent_item_colon' => 'parent item', 'menu_name' => __('FAQs', 'advanced-faq-manager'), 'exclude_from_search' => true ); $faq_args = array( 'labels' => $faq_labels, 'public' => true, 'publicly_queryable' => true, 'has_archive' => true, 'rewrite' => true, 'show_in_menu' => true, 'query_var' => true, 'capability_type' => 'post', 'has_archive' => false, 'hierarchical' => false, 'menu_icon' => 'dashicons-portfolio', 'supports' => array('title'), 'menu_position' => 4, 'exclude_from_search' => false, ); register_post_type('faq', $faq_args); } public function metabox_section(){ $this->add_meta_box_shortcode_display(); $this->add_meta_box_color_settings(); $this->add_meta_box_faqs(); } /******* META BOX - Color Settings *******/ /*****************************************/ public function add_meta_box_color_settings(){ add_meta_box('thfaq_color_settings', 'Display Color Settings', array($this, 'render_meta_box_color_settings'), 'faq', 'side'); } public function render_meta_box_color_settings($post){ if(!empty($post)){ $post_id = get_the_ID(); $override_fields = THFAQF_Utils::get_settings_override_fields(); $global_settings = THFAQF_Utils::get_faq_settings(); $local_settings = get_post_meta($post_id, THFAQF_Utils::OPTION_KEY_FAQ_SETTINGS_POST, true); $local_settings = $this->prepare_local_settings($local_settings, $global_settings, $override_fields); $override_settings = isset($local_settings['override_global_settings']) ? $local_settings['override_global_settings'] : false; $override_settings = ($override_settings === 'yes' || $override_settings === 1) ? 1 : 0; $override_checked = $override_settings ? 'checked' : ''; $atts = array( 'input_width' => '80px', 'tab_cell_width' => '125px', ); ?>
Override global settings
$field){ if($key != 'override_global_settings'){ ?> render_form_field_element($field, $local_settings, $atts, true, false); ?>
$field){ $value = isset($local_settings[$key]) ? $local_settings[$key] : ''; if(!$value){ $value = isset($global_settings[$key]) ? $global_settings[$key] : $value; $local_settings[$key] = $value; } } return $local_settings; } /******* META BOX - Shortcode Display *******/ /********************************************/ public function add_meta_box_shortcode_display(){ add_meta_box('thfaq_shortcode_display', 'Shortcode', array($this, 'render_meta_box_shortcode_display'), 'faq', 'side'); } public function render_meta_box_shortcode_display(){ $post_id = get_the_ID(); $shortcode = '[FAQ id="'. $post_id .'"]'; ?>

ID, THFAQF_Utils::OPTION_KEY_FAQ_ITEMS, true); if(is_array($faq_items)){ foreach($faq_items as $key => $faq_item){ if(empty($faq_item)){ unset($faq_item[$key]); } $faq_title = $faq_item['faq_title']; $faq_content = $faq_item['faq_content']; $faq_form_html .= $this->get_single_faq_form($faq_title, $faq_content, ''); } } if(!$faq_form_html){ $faq_form_html = $this->get_single_faq_form('', '', 'thfaqf-active'); } ?>

post_type; if($post_id && $post_type === 'faq' && isset($_POST['faq_title']) && $_POST['faq_title']){ $faqs = array(); $submitted_title = $_POST['faq_title']; $submitted_content = isset($_POST['faq_content']) ? $_POST['faq_content'] : ''; $cleaned_title = array_filter($submitted_title); $cleaned_content = array_filter($submitted_content); $count_title = count($cleaned_title) ; $count_content = count($cleaned_content); $update_date = get_the_modified_date(get_option('date_format'), $post_id); $update_date = isset($update_date) ? $update_date : ''; $count = $count_content >= $count_title ? $count_content : $count_title; if($count > 0){ for($i=0; $i < $count; $i++){ $faq_title = isset($_POST['faq_title'][$i]) ? htmlspecialchars($_POST['faq_title'][$i]) : ''; $faq_content = isset($_POST['faq_content'][$i]) ? htmlspecialchars($_POST['faq_content'][$i]) : ''; if($faq_title or $faq_content){ $faqs[] = array( 'faq_title' => $faq_title, 'faq_content' => $faq_content, 'updated_date' => $update_date, ); } } $faqs = array_filter($faqs); } if(!empty($faqs)){ $result1 = update_post_meta($post_id, THFAQF_Utils::OPTION_KEY_FAQ_ITEMS, $faqs); $result2 = $this->save_settings_override($post_id); } else { delete_post_meta($post_id, THFAQF_Utils::OPTION_KEY_FAQ_ITEMS); } } } public function save_settings_override($post_id){ $override_fields = THFAQF_Utils::get_settings_override_fields(); $is_override = isset($_POST['override_global_settings']) ? $_POST['override_global_settings'] : ''; $override_settings = array(); if($is_override === 'yes' || $is_override === 1){ foreach($override_fields as $key => $field) { $value = isset($_POST[$key]) ? $_POST[$key] : ''; $override_settings[$key] = $value; } }else{ $override_settings = get_post_meta($post_id, THFAQF_Utils::OPTION_KEY_FAQ_SETTINGS_POST, true); $override_settings = is_array($override_settings) ? $override_settings : array(); } $override_settings['override_global_settings'] = $is_override; $result = update_post_meta($post_id, THFAQF_Utils::OPTION_KEY_FAQ_SETTINGS_POST, $override_settings); return $result; } public function add_custom_column($columns){ $posttype = get_post_type(); $colum_title = 'Shortcode'; $next_column_name = 'date'; foreach($columns as $key => $value){ if($key == $next_column_name && $posttype == 'faq'){ $post_columns[$colum_title] = $colum_title; } $post_columns[$key] = $value; } return $post_columns; } public function add_custom_column_data($post_columns, $post_id){ $posttype = get_post_type(); if($post_columns === 'Shortcode' && $posttype == 'faq'){ $shortcode = '[FAQ id="'. $post_id .'"]' ?> $value) { foreach ($value as $pkey => $pvalue) { if($pvalue == 'Text') { $params[$key] = array_replace($params[$key], array('before_widget' => str_replace("widget ", "widget thfaqf-widget ", $params[$key]['before_widget']))); } } } return $params; } } endif;