'Version' ]); if ( ! defined( 'AJFAQBLOCK_VERSION' ) ) { define( 'AJFAQBLOCK_VERSION', $aj_faq_block_data['Version'] ); } // Admin CSS add_action('admin_enqueue_scripts', function () { wp_enqueue_style( 'ajfaqbl-admin-style', plugins_url('css/ajfaqbl-admin-style.css', __FILE__), [], AJFAQBLOCK_VERSION ); }); // Frontend CSS add_action('wp_enqueue_scripts', function () { wp_enqueue_style( 'ajfaqblock-style', plugins_url('css/aj-faq-block-style.css', __FILE__), [], AJFAQBLOCK_VERSION ); }); // Frontend JS add_action('wp_enqueue_scripts', function () { wp_enqueue_script( 'ajfaqblock-plugin', plugins_url('js/aj-faq-block-plugin.js', __FILE__), [], AJFAQBLOCK_VERSION, true ); }); // Function for Admin Menu function ajfaqblock_add_admin_menu() { add_menu_page( __('AJFAQ Block', 'aj-faq-block'), __('AJFAQ Block', 'aj-faq-block'), 'manage_options', 'ajfabl-main-menu', 'ajfabl_documentation_page_callback', // Correct callback here 'dashicons-editor-help', 20 ); // Documentation submenu under AJFAQ Block add_submenu_page( 'ajfabl-main-menu', __('Documentation', 'aj-faq-block'), __('Documentation', 'aj-faq-block'), 'manage_options', 'ajfabl-documentation', 'ajfabl_documentation_page_callback' ); } add_action('admin_menu', 'ajfaqblock_add_admin_menu'); // Register FAQ Group Post Type function ajfaqblock_register_faq_group_cpt() { register_post_type('ajfabl_group', array( 'labels' => array( 'name' => __('FAQ Groups', 'aj-faq-block'), 'singular_name' => __('FAQ Group', 'aj-faq-block'), 'add_new' => __('Add New Group', 'aj-faq-block'), 'add_new_item' => __('Add a Group Name', 'aj-faq-block'), // <- This is what changes the text above the input 'edit_item' => __('Edit FAQ Group', 'aj-faq-block'), 'new_item' => __('New FAQ Group', 'aj-faq-block'), 'view_item' => __('View FAQ Group', 'aj-faq-block'), 'search_items' => __('Search FAQ Groups', 'aj-faq-block'), 'not_found' => __('No FAQ Groups found', 'aj-faq-block'), 'not_found_in_trash' => __('No FAQ Groups found in Trash', 'aj-faq-block'), ), 'public' => true, 'has_archive' => true, 'supports' => array('title'), 'menu_icon' => 'dashicons-editor-help', 'show_in_menu' => 'ajfabl-main-menu', // Nests under AJFAQ Block )); } add_action('init', 'ajfaqblock_register_faq_group_cpt'); // Register FAQ Questions CPT function ajfaqblock_register_question_cpt() { register_post_type('ajfabl_question', array( 'labels' => array( 'name' => __('FAQ Questions', 'aj-faq-block'), 'singular_name' => __('FAQ Question', 'aj-faq-block'), 'add_new' => __('Add New Question', 'aj-faq-block'), 'add_new_item' => __('Add a Question', 'aj-faq-block'), 'edit_item' => __('Edit Question', 'aj-faq-block'), 'new_item' => __('New Question', 'aj-faq-block'), 'view_item' => __('View Question', 'aj-faq-block'), 'search_items' => __('Search Question', 'aj-faq-block'), 'not_found' => __('No Question', 'aj-faq-block'), 'not_found_in_trash' => __('No Question found in Trash', 'aj-faq-block'), ), 'public' => true, 'has_archive' => false, 'supports' => array('title', 'editor'), 'menu_icon' => 'dashicons-format-status', 'show_in_menu' => 'ajfabl-main-menu', // Nests under AJFAQ Block )); } add_action('init', 'ajfaqblock_register_question_cpt'); // Add Custom Meta Box for FAQ Block function ajfaqblock_add_question_meta_box() { add_meta_box( 'ajfabl_question_group', __('Assign to FAQ Group', 'aj-faq-block'), 'ajfaqblock_question_group_meta_callback', 'ajfabl_question', 'side' ); } add_action('add_meta_boxes', 'ajfaqblock_add_question_meta_box'); function ajfaqblock_question_group_meta_callback($post) { $selected = get_post_meta($post->ID, 'faq_group_id', true); $groups = get_posts(array('post_type' => 'ajfabl_group', 'numberposts' => -1)); echo ''; wp_nonce_field('ajfabl_group_meta_save', 'ajfabl_group_meta_nonce'); } // Save Meta Box Data function ajfaqblock_save_question_group_meta($post_id) { if ( ! isset($_POST['ajfabl_group_meta_nonce']) || ! wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['ajfabl_group_meta_nonce'])), 'ajfabl_group_meta_save') ) { return; } if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) return; if (!current_user_can('edit_post', $post_id)) return; if (isset($_POST['faq_group_id'])) { $faq_group_id = sanitize_text_field(wp_unslash($_POST['faq_group_id'])); update_post_meta($post_id, 'faq_group_id', $faq_group_id); } } add_action('save_post', 'ajfaqblock_save_question_group_meta'); // Shortcode to Display FAQs function ajfaqblock_display_group_faqs($atts) { $atts = shortcode_atts(array( 'id' => 0, ), $atts, 'aj-faq'); $group_id = intval($atts['id']); if (!$group_id) { return esc_html__('Invalid FAQ Group ID.', 'aj-faq-block'); } $args = array( 'post_type' => 'ajfabl_question', 'posts_per_page' => -1, 'meta_query' => array( array( 'key' => 'faq_group_id', 'value' => $group_id, 'compare' => '=' ) ), 'orderby' => 'date', 'order' => 'ASC', ); $query = new WP_Query($args); $output = '
'; if ($query->have_posts()) { while ($query->have_posts()) { $query->the_post(); $output .= '
'; $output .= '
' . esc_html(get_the_title()) . '
'; $output .= '
' . wp_kses_post(get_the_content()) . '
'; $output .= '
'; } wp_reset_postdata(); } else { $output .= '

' . esc_html__('No FAQs found in this group.', 'aj-faq-block') . '

'; } $output .= '
'; return $output; } add_shortcode('aj-faq', 'ajfaqblock_display_group_faqs'); // Add Shortcode Column to FAQ Group Admin function ajfaqblock_add_shortcode_column($columns) { $columns['shortcode'] = esc_html__('Shortcode', 'aj-faq-block'); return $columns; } add_filter('manage_ajfabl_group_posts_columns', 'ajfaqblock_add_shortcode_column'); function ajfaqblock_display_shortcode_column($column, $post_id) { if ('shortcode' === $column) { echo '' . esc_html('[aj-faq id="' . intval($post_id) . '"]') . ''; } } add_action('manage_ajfabl_group_posts_custom_column', 'ajfaqblock_display_shortcode_column', 10, 2); //Documentation Function // Documentation Callback function ajfabl_documentation_page_callback() { ?>

  1. AJFAQ Block > FAQ Groups in your WordPress Admin Dashboard.', 'aj-faq-block')); ?>
  2. Add New then enter a Group Name (e.g., Site FAQ, General FAQ).', 'aj-faq-block')); ?>
  3. [aj-faq id="123"]).', 'aj-faq-block')); ?>

Appearance > Customize > AJFAQ Block Settings.', 'aj-faq-block')); ?>


About Author

Jahid Shah

';}?>

I'm Jahid Shah, a front-end developer with specialized skills in WordPress theme development and WordPress Security Expert, who passionate about creating error-free, secure websites and achieving 100% client satisfaction. I have a drive for learning and sharing knowledge as widely as possible. Solving real-world problems is my passion.


'; } ?>
Watch Help Video

Watch On YouTube

add_section('ajfaqblock_settings', array( 'title' => esc_html__('AJFAQ Block Customization', 'aj-faq-block'), 'priority' => 30, )); // Translatable labels array $labels = [ 'block_bg_color' => esc_html__('Block Background Color', 'aj-faq-block'), 'qblock_bg_color' => esc_html__('Question Block Background Color', 'aj-faq-block'), 'qhblock_bg_color' => esc_html__('Question Block Hover Background Color', 'aj-faq-block'), 'question_text_color' => esc_html__('Question Text Color', 'aj-faq-block'), 'ablock_bg_color' => esc_html__('Answer Background Color', 'aj-faq-block'), 'answer_text_color' => esc_html__('Answer Text Color', 'aj-faq-block'), ]; // Default values $defaults = [ 'block_bg_color' => '#ffffff', 'qblock_bg_color' => '#007BFF', 'qhblock_bg_color' => '#0056b3', 'question_text_color' => '#ffffff', 'ablock_bg_color' => '#ffffff', 'answer_text_color' => '#020202', ]; foreach ($defaults as $key => $default) { $wp_customize->add_setting($key, array( 'default' => $default, 'sanitize_callback' => 'sanitize_hex_color', )); $wp_customize->add_control(new WP_Customize_Color_Control($wp_customize, $key, array( 'label' => $labels[$key], 'section' => 'ajfaqblock_settings', 'settings' => $key, ))); } } add_action('customize_register', 'ajfaqblock_customize_register'); // Output customizer styles in the frontend function ajfaqblock_customize_css() { // Ensure the main stylesheet is enqueued if (!wp_style_is('ajfaqblock-style', 'enqueued')) { wp_enqueue_style( 'ajfaqblock-style', plugins_url('css/aj-faq-block-style.css', __FILE__), array(), AJFAQBLOCK_VERSION); } $css = " .faq-body { background: " . esc_attr(get_theme_mod('block_bg_color', '#ffffff')) . "; } .faq-question { background: " . esc_attr(get_theme_mod('qblock_bg_color', '#007BFF')) . "; color: " . esc_attr(get_theme_mod('question_text_color', '#ffffff')) . "; } .faq-question:hover { background: " . esc_attr(get_theme_mod('qhblock_bg_color', '#0056b3')) . "; } .faq-answer { background: " . esc_attr(get_theme_mod('ablock_bg_color', '#ffffff')) . "; color: " . esc_attr(get_theme_mod('answer_text_color', '#020202')) . "; } "; wp_add_inline_style('ajfaqblock-style', $css); } add_action('wp_enqueue_scripts', 'ajfaqblock_customize_css');