@charset "UTF-8";

/*!
Theme Name: Cocoon Child
Description: Cocoon専用の子テーマ
Theme URI: https://wp-cocoon.com/
Author: わいひら
Author URI: https://nelog.jp/
Template:   cocoon-master
Version:    1.1.3
*/

/************************************
** 子テーマ用のスタイルを書く
************************************/
/*必要ならばここにコードを書く*/

/************************************
** レスポンシブデザイン用のメディアクエリ
************************************/
/*1023px以下*/
@media screen and (max-width: 1023px){
  /*必要ならばここにコードを書く*/
}

/*834px以下*/
@media screen and (max-width: 834px){
  /*必要ならばここにコードを書く*/
}

/*480px以下*/
@media screen and (max-width: 480px){
  /*必要ならばここにコードを書く*/
}

<?php //子テーマ用関数
if ( !defined( 'ABSPATH' ) ) exit;
add_editor_style();

// REST API経由の投稿保存時にCocoonのSEOフィールドに書き込む
add_action('save_post', function ($post_id) {
    if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) return;
    if (!current_user_can('edit_post', $post_id)) return;

    $input = file_get_contents('php://input');
    if (!$input) return;
    $data = json_decode($input, true);
    if (!$data || !isset($data['meta'])) return;

    $fields = [
        'seo_title'       => 'seo_title',
        'seo_description' => 'seo_description',
        'seo_keywords'    => 'seo_keywords',
    ];

    foreach ($fields as $input_key => $meta_key) {
        if (isset($data['meta'][$input_key])) {
            update_post_meta($post_id, $meta_key, sanitize_text_field($data['meta'][$input_key]));
        }
    }
});