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

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

/*全てをまとめて非表示*/
.home.page .entry-title,
.home.page .date-tags,
.home.page .author-info{
  display: none;
}



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

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

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

// 選手成績を表示するショートコード
function player_stats_shortcode($atts) {
    $atts = shortcode_atts(
        array(
            'url' => ''  // JSONファイルのURLを指定
        ),
        $atts,
        'player_stats'
    );

    if (empty($atts['url'])) {
        return "URLが指定されていません";
    }

    // JSONを取得
    $response = wp_remote_get($atts['url'], array(
        'redirection' => 5,
        'timeout' => 15,
        'sslverify' => false
    ));

    if (is_wp_error($response)) {
        return "データ取得エラー: " . $response->get_error_message();
    }

    $body = wp_remote_retrieve_body($response);
    if (empty($body)) {
        return "JSONが空です。URLや公開設定を確認してください。";
    }

    $data = json_decode($body, true);
    if (!$data) {
        return "JSONの読み込みに失敗しました";
    }

    // HTML出力を組み立て
    $output  = "<div class='player-stats'>";
    $output .= "<h3>" . esc_html($data['name']) . " (" . esc_html($data['team']) . ")</h3>";
    $output .= "<ul>";
    $output .= "<li>試合数: " . esc_html($data['season']['games']) . "</li>";
    $output .= "<li>打率: " . esc_html($data['season']['avg']) . "</li>";
    $output .= "<li>本塁打: " . esc_html($data['season']['hr']) . "</li>";
    $output .= "<li>打点: " . esc_html($data['season']['rbi']) . "</li>";
    $output .= "</ul>";
    $output .= "</div>";

    return $output;
}
add_shortcode('player_stats', 'player_stats_shortcode');

function test_shortcode() {
    return "ショートコード動作OK";
}
add_shortcode('test', 'test_shortcode');

// テスト用ショートコード
function test_shortcode() {
    return "ショートコード動作OK";
}
add_shortcode('test', 'test_shortcode');

<?php
if ( !defined( 'ABSPATH' ) ) exit;

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

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

// テスト用ショートコード
function test_shortcode() {
    return "ショートコード動作OK";
}
add_shortcode('test', 'test_shortcode');

// 選手成績を表示するショートコード
function player_stats_shortcode($atts) {
    $atts = shortcode_atts(
        array(
            'url' => ''  // JSONファイルのURLを指定
        ),
        $atts,
        'player_stats'
    );

    if (empty($atts['url'])) {
        return "URLが指定されていません";
    }

    $response = wp_remote_get($atts['url'], array(
        'redirection' => 5,
        'timeout' => 15,
        'sslverify' => false
    ));

    if (is_wp_error($response)) {
        return "データ取得エラー: " . $response->get_error_message();
    }

    $body = wp_remote_retrieve_body($response);
    if (empty($body)) {
        return "JSONが空です。URLを確認してください。";
    }

    $data = json_decode($body, true);
    if (!$data) {
        return "JSONの読み込みに失敗しました";
    }

    $output  = "<div class='player-stats'>";
    $output .= "<h3>" . esc_html($data['name']) . " (" . esc_html($data['team']) . ")</h3>";
    $output .= "<ul>";
    $output .= "<li>試合数: " . esc_html($data['season']['games']) . "</li>";
    $output .= "<li>打率: " . esc_html($data['season']['avg']) . "</li>";
    $output .= "<li>本塁打: " . esc_html($data['season']['hr']) . "</li>";
    $output .= "<li>打点: " . esc_html($data['season']['rbi']) . "</li>";
    $output .= "</ul>";
    $output .= "</div>";

    return $output;
}
add_shortcode('player_stats', 'player_stats_shortcode');