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

/**
 * #0 【スマート診断関数】
 */
function fanza_debug_log($msg, $num, $is_error = false) {
    if (!current_user_can('manage_options')) return "";
    $force_debug = isset($_GET['debug']);
    if (!$is_error && !$force_debug) return "";
    $color = $is_error ? "#e50012" : "#0073aa";
    $status = $is_error ? "⚠️ 要確認" : "✅ 正常動作中";
    return "<div style='font-size:10px; color:{$color}; background:#fff; padding:5px 10px; border:1px solid {$color}; border-radius:5px; margin:10px 0; line-height:1.4;'>
            <strong>機能#{$num} {$status}</strong><br>{$msg}
            " . (!$force_debug ? "<span style='color:#999;'>(成功時は自動で非表示になります)</span>" : "") . "
            </div>";
}

// ---------------------------------------------------------------------------
// #12 【タイトル書き換え：カスタムフィールドを投稿タイトルに反映】
// ---------------------------------------------------------------------------
add_filter('the_title', function($title, $id = null) {
    // 管理画面、固定ページ、メインクエリ以外では実行しない
    if (is_admin() || !$id || !is_singular('post') || !in_the_loop() || !is_main_query()) {
        return $title;
    }

    // カスタムフィールド 'fanza_title' (APIから保存された名前) を取得
    $custom_title = get_post_meta($id, 'fanza_title', true);

    // データがあれば、本来のタイトル（品番など）をAPI取得のタイトルに置き換える
    if (!empty($custom_title)) {
        return esc_html($custom_title);
    }

    return $title;
}, 10, 2);

// ---------------------------------------------------------------------------
// #3 【コア：FANZA API仕様準拠・自動スキャンロジック】
// ---------------------------------------------------------------------------
// （中略：以前提示いただいたロジックをここに維持）
// ※ get_fanza_data_logic 関数など




