/**
 * Theme Name: Foodie Pro 5
 * Description: This is the Foodie Pro 5 child theme.
 * Author: Feast Design Co.
 * Author URI: https://feastdesignco.com/
 * Version: 5.0.0
 *
 * Tags: black, orange, white, one-column, two-columns, three-columns, fixed-width, custom-menu, full-width-template, sticky-post, theme-options, threaded-comments, translation-ready
 *
 * Template: genesis
 * Template Version: 2.0.1
 *
 * License: GPL-2.0+
 * License URI: http://www.opensource.org/licenses/gpl-license.php
 */


// Yoast meta fields registration
add_action('rest_api_init', function () {
    register_rest_field('post', 'meta', array(
        'get_callback' => function($post_arr) {
            return get_post_meta($post_arr['id']);
        },
        'update_callback' => function($meta, $post) {
            foreach ($meta as $key => $value) {
                update_post_meta($post->ID, $key, $value);
            }
            return true;
        },
        'schema' => null,
    ));
});

// Yoast meta fields registration
add_action('init', function() {
    register_meta('post', '_yoast_wpseo_metadesc', [
        'show_in_rest' => true,
        'single' => true,
        'type' => 'string',
        'auth_callback' => function() {
            return current_user_can('edit_posts');
        }
    ]);
    
    register_meta('post', '_yoast_wpseo_focuskw', [
        'show_in_rest' => true,
        'single' => true,
        'type' => 'string',
        'auth_callback' => function() {
            return current_user_can('edit_posts');
        }
    ]);
});

//  protected meta filter
add_filter('is_protected_meta', function($protected, $meta_key) {
    if (in_array($meta_key, ['_yoast_wpseo_metadesc', '_yoast_wpseo_focuskw'])) {
        return false;
    }
    return $protected;
}, 10, 2);