<?php
/**
 * Flatsome functions and definitions
 *
 * @package flatsome
 */

require get_template_directory() . '/inc/init.php';

flatsome()->init();

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');

/**
 * It's not recommended to add any custom code here. Please use a child theme
 * so that your customizations aren't lost during updates.
 *
 * Learn more here: https://developer.wordpress.org/themes/advanced-topics/child-themes/
 */


