/*
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.19.8
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.
***************/
function register_rank_math_seo_meta() {
    // Hàm xác thực quyền truy cập
    function rank_math_seo_meta_auth_callback($allowed, $meta_key, $post_id, $user_id, $cap, $caps) {
        // Chỉ cho phép người dùng có quyền chỉnh sửa bài viết
        return current_user_can('edit_post', $post_id);
    }

    // Đăng ký rank_math_title
    register_meta('post', 'rank_math_title', array(
        'type' => 'string',
        'description' => 'Rank Math SEO Title',
        'single' => true,
        'show_in_rest' => true, // Cho phép chỉnh sửa thông qua REST API
        'auth_callback' => 'rank_math_seo_meta_auth_callback' // Thêm auth_callback
    ));
    
    // Đăng ký rank_math_description
    register_meta('post', 'rank_math_description', array(
        'type' => 'string',
        'description' => 'Rank Math SEO Description',
        'single' => true,
        'show_in_rest' => true, // Cho phép chỉnh sửa thông qua REST API
        'auth_callback' => 'rank_math_seo_meta_auth_callback' // Thêm auth_callback
    ));
    
    // Đăng ký rank_math_focus_keyword
    register_meta('post', 'rank_math_focus_keyword', array(
        'type' => 'string',
        'description' => 'Rank Math Focus Keyword',
        'single' => true,
        'show_in_rest' => true, // Cho phép chỉnh sửa thông qua REST API
        'auth_callback' => 'rank_math_seo_meta_auth_callback' // Thêm auth_callback
    ));
}

add_action('init', 'register_rank_math_seo_meta');
