Written by Anonymous
<?php //オリジナル設定ページ
/**
* Cocoon WordPress Theme
* @author: yhira
* @link: https://wp-cocoon.com/
* @license: http://www.gnu.org/licenses/gpl-2.0.html GPL v2 or later
*/
if ( !defined( 'ABSPATH' ) ) exit;
// POST処理判定
$is_post_ok = isset($_POST[HIDDEN_FIELD_NAME]) &&
wp_verify_nonce($_POST[HIDDEN_FIELD_NAME], 'settings');
///////////////////////////////////////
// タブ構成の定義(配列化)
///////////////////////////////////////
$default_tabs = array(
'skin' => array('label' => __( 'スキン', THEME_NAME ), 'file' => 'skin'),
'all' => array('label' => __( '全体', THEME_NAME ), 'file' => 'all'),
'theme-header' => array('label' => __( 'ヘッダー', THEME_NAME ), 'file' => 'header'),
'ads' => array('label' => __( '広告', THEME_NAME ), 'file' => 'ads'),
'title' => array('label' => __( 'タイトル', THEME_NAME ), 'file' => 'title'),
'seo' => array('label' => __( 'SEO', THEME_NAME ), 'file' => 'seo'),
'ogp' => array('label' => __( 'OGP', THEME_NAME ), 'file' => 'ogp'),
'analytics' => array('label' => __( 'アクセス解析・認証', THEME_NAME ), 'file' => 'analytics'),
'column' => array('label' => __( 'カラム', THEME_NAME ), 'file' => 'column'),
'index-page' => array('label' => __( 'インデックス', THEME_NAME ), 'file' => 'index'),
'single-page' => array('label' => __( '投稿', THEME_NAME ), 'file' => 'single'),
'page-page' => array('label' => __( '固定ページ', THEME_NAME ), 'file' => 'page'),
'content-page' => array('label' => __( '本文', THEME_NAME ), 'file' => 'content'),
'toc-page' => array('label' => __( '目次', THEME_NAME ), 'file' => 'toc'),
'sns-share' => array('label' => __( 'SNSシェア', THEME_NAME ), 'file' => 'sns-share'),
'sns-follow' => array('label' => __( 'SNSフォロー', THEME_NAME ), 'file' => 'sns-follow'),
'image' => array('label' => __( '画像', THEME_NAME ), 'file' => 'image'),
'blog-card' => array(
'label' => __( 'ブログカード', THEME_NAME ),
'forms' => array('blogcard-in-forms.php', 'blogcard-out-forms.php'),
'posts' => array('blogcard-in-posts.php', 'blogcard-out-posts.php'),
),
'code-highlight' => array('label' => __( 'コード', THEME_NAME ), 'file' => 'code'),
'comment' => array('label' => __( 'コメント', THEME_NAME ), 'file' => 'comment'),
'notice-area' => array('label' => __( '通知', THEME_NAME ), 'file' => 'notice'),
'appeal-area' => array('label' => __( 'アピールエリア', THEME_NAME ), 'file' => 'appeal'),
'recommended' => array('label' => __( 'おすすめカード', THEME_NAME ), 'file' => 'recommended'),
'carousel' => array('label' => __( 'カルーセル', THEME_NAME ), 'file' => 'carousel'),
'footer' => array('label' => __( 'フッター', THEME_NAME ), 'file' => 'footer'),
'buttons' => array('label' => __( 'ボタン', THEME_NAME ), 'file' => 'buttons'),
'mobile-buttons' => array('label' => __( 'モバイル', THEME_NAME ), 'file' => 'mobile-buttons'),
'page-404' => array('label' => __( '404ページ', THEME_NAME ), 'file' => '404'),
// 条件判定をインラインに組み込み
'amp' => is_amp_enable() ? array('label' => __( 'AMP', THEME_NAME ), 'file' => 'amp') : null,
'pwa' => is_pwa_enable() ? array('label' => __( 'PWA', THEME_NAME ), 'file' => 'pwa') : null,
'admin' => array('label' => __( '管理者画面', THEME_NAME ), 'file' => 'admin'),
'widget' => array('label' => __( 'ウィジェット', THEME_NAME ), 'file' => 'widget'),
'widget-area' => array('label' => __( 'ウィジェットエリア', THEME_NAME ), 'file' => 'widget-area'),
'editor' => array('label' => __( 'エディター', THEME_NAME ), 'file' => 'editor'),
'apis' => array('label' => __( 'API', THEME_NAME ), 'file' => 'apis'),
'others' => array('label' => __( 'その他', THEME_NAME ), 'file' => 'others'),
'reset' => array('label' => __( 'リセット', THEME_NAME ), 'file' => 'reset'),
'about' => array('label' => __( 'テーマ情報', THEME_NAME ), 'file' => 'about'),
);
// 条件に合致せず null になった要素(AMP/PWA等)を除去
$default_tabs = array_filter($default_tabs);
/**
* 独自タブを追加・変更するためのフィルターフック
*/
$settings_tabs = apply_filters('cocoon_settings_tabs', $default_tabs);
///////////////////////////////////////
// 設定の保存処理
///////////////////////////////////////
if( $is_post_ok ):
do_action('cocoon_settings_before_save');
// リセット処理(先頭で実行)
if (isset($settings_tabs['reset'])) {
require_once abspath(__FILE__).'reset-posts.php';
}
// タブごとの保存スクリプトをループ処理
foreach ($settings_tabs as $id => $tab) {
if ($id === 'reset') continue;
// 1. カスタムポストファイル指定(配列)時
if (isset($tab['posts']) && is_array($tab['posts'])) {
foreach ($tab['posts'] as $post_file) {
$path = abspath(__FILE__) . $post_file;
if (file_exists($path)) require_once $path;
}
}
// 2. 単一ファイル判定(例: skin-posts.php)
elseif (isset($tab['file'])) {
$file_name = $tab['file'] . '-posts.php';
$path = abspath(__FILE__) . $file_name;
if (file_exists($path)) {
require_once $path;
}
}
// 3. 独自保存用アクションフック
do_action("cocoon_settings_save_{$id}");
}
// テーマ設定ページではスキン設定の読み込みを保存後にするために遅らせる
if (get_skin_url() && is_admin_php_page()) {
cocoon_skin_settings();
}
// エディター用のカスタマイズCSS・ads.txt 出力
put_theme_css_cache_file();
put_ads_txt_file();
do_action('cocoon_settings_after_save');
endif;
///////////////////////////////////////
// 入力フォーム描画
///////////////////////////////////////
?>
<div class="wrap admin-settings">
<h1><?php _e( 'Cocoon 設定', THEME_NAME ) ?></h1>
<?php
// 画面に「設定は保存されました」メッセージを表示
$is_reset_ok = isset($_GET['reset']) && $_GET['reset'];
if ($is_post_ok || $is_reset_ok):
?>
<div class="notice notice-success is-dismissible">
<p>
<strong>
<?php
$reset_msg = __( '設定はリセットされました。', THEME_NAME );
if ($is_post_ok) {
if (isset($_POST[OP_RESET_ALL_SETTINGS]) && isset($_POST[OP_CONFIRM_RESET_ALL_SETTINGS])) {
echo $reset_msg;
} else {
_e('設定は保存されました。', THEME_NAME );
}
}
if ($is_reset_ok) {
echo $reset_msg;
}
?>
</strong>
</p>
</div>
<?php endif; ?>
<p>
<?php _e( 'Cocoonの設定全般についてはマニュアルを参照してください。', THEME_NAME ) ?>
<a href="https://wp-cocoon.com/manual/" target="_blank" rel="noopener">
<?php echo change_fa('<span class="fa fa-book" aria-hidden="true">'); ?></span>
<?php _e( 'テーマ利用マニュアル', THEME_NAME ) ?>
</a>
</p>
<form name="form1" method="post" action="<?php echo add_query_arg(array('reset' => null)); ?>" class="admin-settings">
<?php submit_button(__( '変更をまとめて保存', THEME_NAME )); ?>
<!-- タブ機能の実装 -->
<div id="tabs" class="tabs">
<?php
$first_key = array_key_first($settings_tabs);
foreach ($settings_tabs as $id => $tab):
$input_id = "tab-{$id}-input";
$label_id = "tab-{$id}-label";
$checked = ($id === $first_key) ? 'checked="checked"' : '';
?>
<input id="<?php echo esc_attr($input_id); ?>" value="<?php echo esc_attr($input_id); ?>" class="tab-input" type="radio" name="tab-input" <?php echo $checked; ?>>
<label for="<?php echo esc_attr($input_id); ?>" id="<?php echo esc_attr($label_id); ?>" class="<?php echo esc_attr($label_id); ?> tab-label"><?php echo esc_html($tab['label']); ?></label>
<?php endforeach; ?>
<?php if ($_POST && isset($_POST['tab-input'])): ?>
<script>
// 前回選択していたタブを選択
var cocoonSelectedTab = document.getElementById('<?php echo esc_js($_POST['tab-input']); ?>');
if (cocoonSelectedTab) {
cocoonSelectedTab.checked = true;
}
</script>
<?php endif; ?>
<?php // スキン制御変数のクリアとバックアップ
clear_global_skin_theme_options(); ?>
<!-- 各タブのコンテンツ描画 -->
<?php foreach ($settings_tabs as $id => $tab): ?>
<div id="tab-<?php echo esc_attr($id); ?>-content" class="<?php echo esc_attr($id); ?> metabox-holder">
<?php
// 1. カスタムフォーム配列指定時
if (isset($tab['forms']) && is_array($tab['forms'])) {
foreach ($tab['forms'] as $form_file) {
$path = abspath(__FILE__) . $form_file;
if (file_exists($path)) require_once $path;
}
}
// 2. 単一ファイル判定(例: skin-forms.php)
elseif (isset($tab['file'])) {
$file_name = $tab['file'] . '-forms.php';
$path = abspath(__FILE__) . $file_name;
if (file_exists($path)) {
require_once $path;
}
}
// 3. 独自コンテンツ挿入用アクションフック
do_action("cocoon_settings_tab_content_{$id}");
?>
</div><!-- /.metabox-holder -->
<?php endforeach; ?>
<?php // スキン制御変数の復元
restore_global_skin_theme_options(); ?>
</div><!-- /#tabs -->
<input type="hidden" name="<?php echo HIDDEN_FIELD_NAME; ?>" value="<?php echo wp_create_nonce('settings');?>">
<input type="hidden" id="<?php echo SELECT_INDEX_NAME; ?>" name="<?php echo SELECT_INDEX_NAME; ?>" value="<?php echo ($_POST[SELECT_INDEX_NAME] ?? 0); ?>">
<?php submit_button(__( '変更をまとめて保存', THEME_NAME ), 'primary', "submit-2"); ?>
</form>
</div>
<style>
<?php cocoon_template_part('tmp/css-custom'); ?>
</style>