/*
Theme Name:           Flatsome
Theme URI:            http://flatsome.uxthemes.com
Author:               UX-Themes
Author URI:           https://uxthemes.com
Description:          Multi-Purpose Responsive WooCommerce Theme
Version:              3.20.9
Requires at least:    6.4
Requires PHP:         7.4
WC requires at least: 8.3
Text Domain:          flatsome
License:              https://themeforest.net/licenses
License URI:          https://themeforest.net/licenses
*/


/***************
All custom CSS should be added to Flatsome > Advanced > Custom CSS,
or in the style.css of a Child Theme.
***************/
/**
 * Hiển thị các trường ACF trong Author Box
 */
function s8links_author_acf_info($description) {

    // Lấy ID tác giả của bài viết hiện tại
    $author_id = get_the_author_meta('ID');

    if (!$author_id) {
        return $description;
    }

    // Lấy dữ liệu ACF của User
    $vi_tri_chuyen_mon = get_field('vi_tri_chuyen_mon', 'user_' . $author_id);
    $hoc_van           = get_field('hoc_van', 'user_' . $author_id);
    $kinh_nghiem       = get_field('kinh_nghiem', 'user_' . $author_id);
    $noi_cong_tac      = get_field('noi_cong_tac', 'user_' . $author_id);

    // Tạo phần thông tin ACF
    $acf_info = '<div class="s8-author-acf-info">';

    if ($vi_tri_chuyen_mon) {
        $acf_info .= '<div class="s8-author-field">
            <strong>Chuyên môn:</strong> ' . esc_html($vi_tri_chuyen_mon) . '
        </div>';
    }

    if ($hoc_van) {
        $acf_info .= '<div class="s8-author-field">
            <strong>Học vấn:</strong> ' . esc_html($hoc_van) . '
        </div>';
    }

    if ($kinh_nghiem) {
        $acf_info .= '<div class="s8-author-field">
            <strong>Kinh nghiệm:</strong> ' . esc_html($kinh_nghiem) . ' năm
        </div>';
    }

    if ($noi_cong_tac) {
        $acf_info .= '<div class="s8-author-field">
            <strong>Nơi công tác:</strong> ' . esc_html($noi_cong_tac) . '
        </div>';
    }

    $acf_info .= '</div>';

    // Nếu không có dữ liệu ACF thì giữ nguyên mô tả
    if (!$vi_tri_chuyen_mon && !$hoc_van && !$kinh_nghiem && !$noi_cong_tac) {
        return $description;
    }

    // Đưa thông tin ACF xuống dưới mô tả tác giả
    return $description . $acf_info;
}

add_filter('get_the_author_description', 's8links_author_acf_info');
