@charset "UTF-8";
/*
 Theme Name: SANGO Child
 Theme URI: https://saruwakakun.design
 Author: SARUWAKA
 Author URI: https://saruwakakun.com
 Template: sango-theme
 Version: 4.0
*/
/*こちらはSANGOの子テーマ用CSSです。以下にCSSを記入していきましょう。*/
<?php

add_filter('sng_author_info', 'override_author_info', 10, 3);

function override_author_info($html, $options) {
  global $post;
  $supervisor_id = get_post_meta($post->ID, 'post_supervisor', true);
  if (!$supervisor_id) {
    return $html;
  }
  return $html . sng_author_info_by_id($supervisor_id, '記事の監修者');
}

add_action('sng_field_side_extra', function () {
  global $post;
  $meta_value = get_post_meta($post->ID, 'post_supervisor', true);
  ob_start();
  $users = get_users();
  foreach ($users as $user) {
    $selected = $user->ID === $meta_value ? " selected" : "";
  ?>
    <option value="<?php echo $user->ID ?>"<?php echo $selected ?>><?php echo $user->display_name ?></option>
  <?php
  }
  $options = ob_get_clean();
  echo '<p class="sng-field-title"><img draggable="false" role="img" class="emoji" alt="👦" src="https://cdn.jsdelivr.net/gh/twitter/twemoji@latest/assets/svg/1f9d1-200d-1f4bb.svg"> 監修者名</p>';
  echo "<div style='margin-top: 10px;'>
    <select name='post_supervisor'>
      <option value=''>監修者を選択</option>
      $options
    </select>
  </div>";
});

add_action('sng_update_custom_fields', function ($post_id) {
  sng_update_custom_text_fields($post_id, 'post_supervisor');
}, 10, 3);