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

//子テーマ用のビジュアルエディタースタイルを適用
add_editor_style();

//以下に子テーマ用の関数を書く

/**
 * トップページのブログサムネイル対策（2026年8月12日）
 */
add_filter( 'wp_omit_loading_attr_threshold', function ( $threshold ) {
	return is_front_page() ? 0 : $threshold;
} );

add_filter( 'wp_get_loading_optimization_attributes', function ( $attrs ) {
	if ( is_front_page() ) {
		unset( $attrs['fetchpriority'] );
	}
	return $attrs;
} );

/**
 * 管理者のユーザー名を外部から見えなくする（2026年9月15日）
 */
add_filter( 'rest_endpoints', function ( $endpoints ) {
	if ( is_user_logged_in() ) {
		return $endpoints;
	}
	unset( $endpoints['/wp/v2/users'] );
	unset( $endpoints['/wp/v2/users/(?P<id>[\d]+)'] );
	return $endpoints;
} );

/**
 * 著者アーカイブをトップへ逃がす。
 */
add_action( 'template_redirect', function () {
	if ( is_admin() ) {
		return;
	}
	if ( is_author() || isset( $_GET['author'] ) ) {
		wp_safe_redirect( home_url( '/' ), 301 );
		exit;
	}
}, 0 );

/**
 * 著者URLを消す（2026年9月15日）
 *
 * 表示名を変えても、構造化データ(JSON-LD)・oEmbed・RSS が出力する
 * 著者URL  https://.../author/<ログイン名>/  にはログイン名が残る。
 * get_author_posts_url() は author_link フィルタを通るので、
 * ここでトップページのURLに差し替えて文字列ごと消す。
 */
add_filter( 'author_link', function () {
	return home_url( '/' );
} );
/**
 * 著者URLを消す（2026年9月15日）
 *
 * 表示名を「アニキ」に変えても、構造化データ・oEmbed・著者リンクが出力する
 * https://.../author/<ログイン名>/ にはログイン名が残る。
 * get_author_posts_url() は author_link フィルタを通るので、
 * トップページのURLに差し替えて文字列ごと消す。
 */
add_filter( 'author_link', function () {
	return home_url( '/' );
} );

