@charset "UTF-8";
/*
    Template: swell
    Theme Name: SWELL CHILD
    Theme URI: https://swell-theme.com/
    Description: SWELLの子テーマ
    Version: 1.0.0
    Author: LOOS WEB STUDIO
    Author URI: https://loos-web-studio.com/

    License: GNU General Public License
    License URI: http://www.gnu.org/licenses/gpl.html
*/
// カスタム REST エンドポイント：任意の post_meta を更新
add_action( 'rest_api_init', function () {
    register_rest_route( 'visa-helper/v1', '/update-meta', [
        'methods'             => 'POST',
        'callback'            => function ( $request ) {
            $post_id  = intval( $request->get_param( 'post_id' ) );
            $meta_key = sanitize_text_field( $request->get_param( 'meta_key' ) );
            $meta_val = wp_kses_post( $request->get_param( 'meta_value' ) );
            if ( ! $post_id || ! $meta_key ) {
                return new WP_Error( 'missing_params', 'post_id and meta_key required', [ 'status' => 400 ] );
            }
            $result = update_post_meta( $post_id, $meta_key, $meta_val );
            return [ 'success' => true, 'post_id' => $post_id, 'meta_key' => $meta_key ];
        },
        'permission_callback' => function () {
            return current_user_can( 'edit_posts' );
        },
    ] );
} );
