<?php
/**
 * Plugin Name: Mia Yoast REST Expose
 * Description: Registra campos meta Yoast SEO no REST API pra permitir setar focus keyphrase, SEO title e meta description via API.
 * Version: 1.0.0
 * Author: Climb Digital
 */

if (!defined('ABSPATH')) exit;

add_action('init', function () {
    $post_types = ['post', 'page'];
    $meta_keys = [
        '_yoast_wpseo_focuskw',
        '_yoast_wpseo_title',
        '_yoast_wpseo_metadesc',
        '_yoast_wpseo_opengraph-title',
        '_yoast_wpseo_opengraph-description',
        '_yoast_wpseo_twitter-title',
        '_yoast_wpseo_twitter-description',
        '_yoast_wpseo_canonical',
        '_yoast_wpseo_meta-robots-noindex',
        '_yoast_wpseo_meta-robots-nofollow',
    ];
    foreach ($post_types as $pt) {
        foreach ($meta_keys as $key) {
            register_post_meta($pt, $key, [
                'show_in_rest' => true,
                'single' => true,
                'type' => 'string',
                'auth_callback' => function () {
                    return current_user_can('edit_posts');
                },
            ]);
        }
    }
}, 20);
