@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
*/

/**
 * ログイン直後は必ずトップへ
 */
add_action('wp_login', function ($user_login, $user) {
  // 管理画面ログインは邪魔しない（必要なら）
  if (is_admin()) return;

  wp_safe_redirect(home_url('/'));
  exit;
}, 10, 2);

/**
 * すでにログインしている人が /login /register を開いたらトップへ
 */
add_action('template_redirect', function () {
  if (is_admin()) return;
  if (!is_user_logged_in()) return;
  if (!is_page()) return;

  $post = get_queried_object();
  $slug = ($post && !empty($post->post_name)) ? $post->post_name : '';

  if (in_array($slug, ['login', 'register', 'account'], true)) {
    wp_safe_redirect(home_url('/'));
    exit;
  }
}, 20);