<?php

/**
 * Plugin Name:       ConferenceManager
 * Plugin URI:        https://cs24.biz/conference/
 * Description:       Academic conference management — registration, payment, and document automation for scholarly events.
 * Version:           1.1.8
 * Requires at least: 6.9
 * Requires PHP:      8.4
 * Author:            CS24 Co.,Ltd.
 * Author URI:        https://cs24.biz/
 * License:           GPL v2 or later
 * License URI:       https://www.gnu.org/licenses/gpl-2.0.html
 * Text Domain:       conferencemanager
 * Domain Path:       /languages
 *
 * @package ConfManager
 *
 * == External services ==
 *
 * 1. Stripe (optional, only when the site administrator configures Stripe API keys
 *    and a participant selects Stripe at checkout)
 *    This plugin loads Stripe.js from https://js.stripe.com and sends payment
 *    details to Stripe's servers for processing.
 *    Data sent: payment amount, currency, participant email, billing details,
 *    registration ID.
 *    Terms of Service: https://stripe.com/legal/ssa
 *    Privacy Policy:   https://stripe.com/privacy
 *
 * 2. IPA font download (PDF generation)
 *    This plugin downloads IPA Gothic/Mincho fonts from https://moji.or.jp/
 *    for Japanese PDF rendering. This occurs once when fonts are first needed.
 *    No user data is sent.
 *    IPA Font License: https://moji.or.jp/ipafont/license/
 */

declare(strict_types=1);

// 直接アクセス禁止
if (! defined('ABSPATH')) {
	exit;
}

/*
 * 二重ロードガード
 *
 * 旧フォルダ（conf-manager/）と新フォルダ（conferencemanager/）の両方に
 * 本プラグインが存在し両方とも有効化されると、Composer オートローダや
 * ConfManager\* クラスが二重定義され fatal error（白画面）になる。
 * 最初に読み込まれた 1 つだけを生かし、2 つ目以降はここで安全に離脱して
 * 管理者に重複削除を促す通知を出す（Free→Pro 移行時の事故防止）。
 */
if (defined('CONF_MANAGER_VERSION')) {
	add_action('admin_notices', static function () {
		echo '<div class="notice notice-error"><p>';
		echo esc_html__('Conference Manager is installed in more than one plugin folder. To resolve the conflict, please keep only one copy and delete the other plugin folder.', 'conferencemanager');
		echo '</p></div>';
	});
	return;
}

// プラグイン定数
define('CONF_MANAGER_VERSION', '1.1.8');
define('CONF_MANAGER_DB_VERSION', '3.1.0');
define('CONF_MANAGER_PLUGIN_FILE', __FILE__);
define('CONF_MANAGER_PLUGIN_DIR', plugin_dir_path(__FILE__));
define('CONF_MANAGER_PLUGIN_URL', plugin_dir_url(__FILE__));
define('CONF_MANAGER_PLUGIN_BASENAME', plugin_basename(__FILE__));

// Composer オートローダー
if (file_exists(CONF_MANAGER_PLUGIN_DIR . 'vendor/autoload.php')) {
	require_once CONF_MANAGER_PLUGIN_DIR . 'vendor/autoload.php';
}

// 有効化・無効化フック
register_activation_hook(__FILE__, ['ConfManager\Activator', 'activate']);
register_deactivation_hook(__FILE__, ['ConfManager\Deactivator', 'deactivate']);

/**
 * プラグインのメインインスタンスを起動
 *
 * @since 1.0.0
 * @return ConfManager\ConfManager
 */
function conf_manager(): ConfManager\ConfManager
{
	return ConfManager\ConfManager::instance();
}

// WordPress の plugins_loaded で初期化
add_action('plugins_loaded', 'conf_manager');
