<?php if ( !defined( 'ABSPATH' ) ) exit;//PHPの宣言と直接アクセスの拒否

/* セクションID haumenu_define_section_id_02_security() */
/* タブのスラグ haumenu_define_tab_slug_02_security() */
/* $option_name 設定名 haumenu_define_option_name_02_security() */
/* get_option GetOP02_security() */

/***** 親設定の有効／無効に合わせて子設定の表示方法を変更する *****/
/* 関数名・設定名は画面ごとに変えること（関数重複を防ぐ） */
/* add_action('admin_notices', 'current_pagehook');を追加してページ名を取得し、$page_fooksuffixの値を変える */
/* 連動マップ（ID => セレクター）の項目を編集する */

function haup_child_setting_view_control_02_security( $hook_suffix ) {
	//ページフックにより出力を判断
	$page_fooksuffix = 'ha-utilitiy_page_haumenu_page_security'; //セキュリティとスパム対策設定

	if ( $page_fooksuffix !== $hook_suffix ) {
		return;
	}

	//メインスクリプトのハンドル
	$handle = 'haup-child-setting-control-js';

	// メインスクリプトが登録されていなければ終了(スクリプトの読み込みはmain-menu.phpで記述)
	if ( ! wp_script_is( $handle, 'registered' ) ) {
		return;
	}

	//設定名
	$set_name = haumenu_define_option_name_02_security();

	// 連動マップ（ID => セレクター）
	$dependency_map = array(
		// ファイル変更のメール通知
		$set_name . 'theme-plugin-file-change-notice' => '.theme-plugin-file-change-notice-testmode-wrapper',
	);
	
	// 連動マップ（ID => セレクター）
	// 1つのIDに対して複数のCSSクラスを指定する（1つなら1行）
	$dependency_map = array(
		$set_name . 'theme-plugin-file-change-notice' => array(
			'.theme-plugin-file-change-notice-testmode-wrapper', //ファイルの変更を通知する
		),
	);


	$inner_js = "";
	foreach ( $dependency_map as $id => $selectors ) {
		foreach ( (array) $selectors as $selector ) {
			// translators: %s stands for the CSS Class & ID.
			$inner_js .= sprintf(
				"haup_apply_dependency('%s', '%s');\n",
				esc_js( $id ),
				esc_js( $selector )
			);
		}
	}

	if ( $inner_js ) {
		$js_code = "if (window.haup_apply_dependency) {\n" . $inner_js . "}";
		// 第3引数を 'after' にすることで、本体JSの直後に出力
		wp_add_inline_script( $handle, $js_code, 'after' );
	}
}
add_action( 'admin_enqueue_scripts', 'haup_child_setting_view_control_02_security', 20 );

/*** テーマフォルダ内のファイル変更ログ ***/
/* 項目の追加とデータの更新 */
function haumenu_init_field_theme_file_change_log(){
//項目の追加
	add_settings_field(
		'theme-file-change-log', // 設定名
		__('Theme File Change Log','hima-art-utility'), // 設定タイトル
		'haumenu_theme_file_change_log', // 設定項目のHTMLを出力する関数名
		haumenu_define_tab_slug_02_security(), //表示させるタブのスラグ
		haumenu_define_section_id_02_security(), //セクションID
		array( 'class' => 'ha-settings-separate' )
	);

}
add_action( 'admin_init', 'haumenu_init_field_theme_file_change_log' );

/* 入力フォーム */
function haumenu_theme_file_change_log() {
	$set_name = haumenu_define_option_name_02_security(); //  $option_name 設定名
	$options = get_option($set_name);
	$option_name = 'theme-file-change-log'; //個別配列名

	//テーブルに値がなかった場合の措置（PHP8.x以降への対応）
	if(isset($options[$option_name])){
		$checked = $options[$option_name];
	}else{
		$checked = '';
	}
?>
<label>
	<input type="checkbox" id="<?php echo esc_html($set_name . $option_name ); ?>" name="<?php echo esc_html($set_name . '[' .$option_name. ']'); ?>" class="wppd-ui-toggle" <?php checked( $checked , 1 ); ?> value="1">
	<p><?php esc_html_e('Records change logs for files in the active theme and parent/child themes when using a child theme, allowing you to check the history.','hima-art-utility'); ?></p>
</label>
<details class="accordion"  style="margin: 5px 0px 0px 0px;overflow: hidden;">
<summary class="accordion__title" style="cursor: pointer;"><?php esc_html_e('View detailed description','hima-art-utility'); ?></summary>
<div class="accordion__content">
	<p><?php esc_html_e('This function checks and records the following changes every hour:','hima-art-utility'); ?></p>
	<ol>
		<li><?php esc_html_e('New files and directories added to the theme folder','hima-art-utility'); ?></li>
		<li><?php esc_html_e('There was a change in the code of a file in the theme folder','hima-art-utility'); ?></li>
		<li><?php esc_html_e('Files and directories in the theme folder were deleted','hima-art-utility'); ?></li>
	</ol>
	<p><?php esc_html_e('The recorded data can be viewed on the following screen:','hima-art-utility'); ?></p>
	<ol>
		<li><?php esc_html_e('The screen to transition from "HA Utility" → "Theme Change Log"','hima-art-utility'); ?></li>
		<li><?php esc_html_e('Dashboard Widgets','hima-art-utility'); ?></li>
	</ol>
	<p><?php esc_html_e('Please note the following points regarding use:','hima-art-utility'); ?></p>
	<ol class="haup-admin-font-red">
		<li><?php esc_html_e('It can only detect whether a file has changed within the last hour, but it cannot detect what has changed within that file.','hima-art-utility'); ?></li>
		<li><?php esc_html_e('This function detects changes in files other than those listed in "Exclusions from Detection" below in order to prevent false positives for files that are frequently updated.','hima-art-utility'); ?></li>
		<li><?php esc_html_e('When you update a theme (parent theme), many files and folders may be detected and displayed as history.','hima-art-utility'); ?></li>
		<li><?php esc_html_e('This function creates a dedicated table in the database (if the table does not exist, a message will appear prompting you to create it), but this table is designed to be deleted when the plugin is stopped so that unnecessary tables do not remain.','hima-art-utility'); ?></li>
	</ol>
	<details class="accordion"  style="margin: 5px 0px 0px 0px;overflow: hidden;">
	<summary class="accordion__title" style="cursor: pointer;"><?php esc_html_e('What to exclude from detection','hima-art-utility'); ?></summary>
	<div class="accordion__content">
		<ol>
			<li><?php esc_html_e('Files with the following extensions:','hima-art-utility'); ?>log txt md pot png jpg jpeg gif svg webp ico woff woff2 ttf eot otf</li>
			<li><?php esc_html_e('Files in the following directories:','hima-art-utility'); ?>assets languages styles templates parts patterns overwrite-theme-json node_modules</li>
			<li><?php esc_html_e('The following files:','hima-art-utility'); ?>theme.json screenshot.png readme.txt</li>
		</ol>
	</div>
	</details>
</div>
</details>
<div style="text-align:right;margin-top:1rem;"><a href="<?php echo esc_url(HAUP_MANUAL_DIR); ?>/howtouse-theme-file-mod-log" target="_blank"><?php echo esc_html(haup_manual_text()); ?></a></div>
<?php
}

/*** テーマやプラグインのファイル変更を通知する ***/
/* 項目の追加とデータの更新 */
function haumenu_init_field_theme_plugin_file_change_notice(){
//項目の追加
	add_settings_field(
		'theme-plugin-file-change-notice', // 設定名
		__('Notify of file changes','hima-art-utility'), // 設定タイトル
		'haumenu_theme_plugin_file_change_notice', // 設定項目のHTMLを出力する関数名
		haumenu_define_tab_slug_02_security(), //表示させるタブのスラグ
		haumenu_define_section_id_02_security(), //セクションID
		array( 'class' => 'ha-settings-separate' )
	);

}
add_action( 'admin_init', 'haumenu_init_field_theme_plugin_file_change_notice' );

/* 入力フォーム */
function haumenu_theme_plugin_file_change_notice() {
	$set_name = haumenu_define_option_name_02_security(); //  $option_name 設定名
	$options = get_option($set_name);
	$option_name = 'theme-plugin-file-change-notice'; //個別配列名

	//テーブルに値がなかった場合の措置（PHP8.x以降への対応）
	if(isset($options[$option_name])){
		$checked = $options[$option_name];
	}else{
		$checked = '';
	}
?>
<label>
	<input type="checkbox" id="<?php echo esc_html($set_name . $option_name ); ?>" name="<?php echo esc_html($set_name . '[' .$option_name. ']'); ?>" class="wppd-ui-toggle" <?php checked( $checked , 1 ); ?> value="1">
	<p><?php esc_html_e('When code changes are made to theme or plugin files, a notification will be sent to your sites email address.','hima-art-utility'); ?></p>
	<p class="haup-admin-font-red" style="font-size:0.8rem;"><?php esc_html_e('*This feature sends email notifications when "Update File" is clicked in the "Theme File Editor" or "Plugin File Editor." Please note that it does not send notifications for overwriting files using FTP or for regular theme/plugin updates.','hima-art-utility'); ?></p>
</label>
<p class="haup-admin-bk">
	<span>
		<?php esc_html_e('To reduce the annoyance of receiving an email every time a file is updated, we have configured the system under "Security Settings" > "Users and Login" panel to "Restrict access to the admin and login screens." This prevents notifications from being sent when a user logs in from an IP address that is permitted to access the admin screen and makes changes to a file.','hima-art-utility'); ?>
	</span>
	<br>
	<span class="haup-admin-font-red" style="font-size:0.8rem;">
		<?php esc_html_e('*By using this in conjunction with "restricting access to the administration screen and login screen," you can reduce the risk of unauthorized access to the administration screen and, in the event that access restrictions are bypassed and files are illegally modified, you can find out which files have been changed, providing a double layer of protection against site tampering.','hima-art-utility'); ?>
	</span>
</p>

<?php
}

/*** 【全通知モード】テーマやプラグインのファイル変更を通知する ***/
/* 項目の追加とデータの更新 */
function haumenu_init_field_theme_plugin_file_change_notice_testmode(){
//項目の追加
	add_settings_field(
		'theme-plugin-file-change-notice-testmode', // 設定名
		'', // 設定タイトル
		'haumenu_theme_plugin_file_change_notice_testmode', // 設定項目のHTMLを出力する関数名
		haumenu_define_tab_slug_02_security(), //表示させるタブのスラグ
		haumenu_define_section_id_02_security(), //セクションID
		array( 'class' => 'ha-settings-convine' )
	);

}
add_action( 'admin_init', 'haumenu_init_field_theme_plugin_file_change_notice_testmode' );

/* 入力フォーム */
function haumenu_theme_plugin_file_change_notice_testmode() {
	$set_name = haumenu_define_option_name_02_security(); //  $option_name 設定名
	$options = get_option($set_name);
	$option_name = 'theme-plugin-file-change-notice-testmode'; //個別配列名

	//テーブルに値がなかった場合の措置（PHP8.x以降への対応）
	if(isset($options[$option_name])){
		$checked = $options[$option_name];
	}else{
		$checked = '';
	}
?>
<div class="theme-plugin-file-change-notice-testmode-wrapper">
<label>
	<input type="checkbox" id="<?php echo esc_html($set_name . $option_name ); ?>" name="<?php echo esc_html($set_name . '[' .$option_name. ']'); ?>" class="wppd-ui-toggle" <?php checked( $checked , 1 ); ?> value="1"><?php esc_html_e('Remove notification destination restrictions','hima-art-utility'); ?>
	<p><?php esc_html_e('Enable this setting if you want to receive notifications when files are modified by a user logged in from an IP address specified in "Restrict access to the administration and login screens" under "Users and login" panel in "Security settings."','hima-art-utility'); ?></p>
</label>
</div>
<div style="text-align:right;margin-top:1rem;"><a href="<?php echo esc_url(HAUP_MANUAL_DIR); ?>/howtouse-file-change-notice" target="_blank"><?php echo esc_html(haup_manual_text()); ?></a></div>
<?php
}

/*** /?author=IDでのアクセスを404ページへ遷移させる ***/
/* 項目の追加とデータの更新 */
function haumenu_init_field_disable_author_page_id_access(){
//項目の追加
	add_settings_field(
		'disable-author-page-id-access', // 設定名
		__('Prevent access to author page by ID','hima-art-utility'), // 設定タイトル
		'haumenu_disable_author_page_id_access', // 設定項目のHTMLを出力する関数名
		haumenu_define_tab_slug_02_security(), //表示させるタブのスラグ
		haumenu_define_section_id_02_security(), //セクションID
		array( 'class' => 'ha-settings-separate' )
	);

}
add_action( 'admin_init', 'haumenu_init_field_disable_author_page_id_access' );

/* 入力フォーム */
function haumenu_disable_author_page_id_access() {
	$set_name = haumenu_define_option_name_02_security(); //  $option_name 設定名
	$options = get_option($set_name);
	$option_name = 'disable-author-page-id-access'; //個別配列名

	//テーブルに値がなかった場合の措置（PHP8.x以降への対応）
	if(isset($options[$option_name])){
		$checked = $options[$option_name];
	}else{
		$checked = '';
	}
?>
<label>
	<input type="checkbox" id="<?php echo esc_html($set_name . $option_name ); ?>" name="<?php echo esc_html($set_name . '[' .$option_name. ']'); ?>" class="wppd-ui-toggle" <?php checked( $checked , 1 ); ?> value="1">
	<p><?php esc_html_e('/?author=ID parameter will redirect to 404 page when accessing the author page','hima-art-utility'); ?></p>
</label>
<div style="text-align:right;margin-top:1rem;"><a href="<?php echo esc_url(HAUP_MANUAL_DIR); ?>/howtouse-author-id-access-to-404" target="_blank"><?php echo esc_html(haup_manual_text()); ?></a></div>
<?php
}

/*** xml-rpc接続を無効にする ***/
/* 項目の追加とデータの更新 */
function haumenu_init_field_disable_xml_rpc(){
//項目の追加
	add_settings_field(
		'disable-xml-rpc', // 設定名
		__('Disable XML-RPC API','hima-art-utility'), // 設定タイトル
		'haumenu_disable_xml_rpc', // 設定項目のHTMLを出力する関数名
		haumenu_define_tab_slug_02_security(), //表示させるタブのスラグ
		haumenu_define_section_id_02_security(), //セクションID
		array( 'class' => 'ha-settings-separate' )
	);

}
add_action( 'admin_init', 'haumenu_init_field_disable_xml_rpc' );

/* 入力フォーム */
function haumenu_disable_xml_rpc() {
	$set_name = haumenu_define_option_name_02_security(); //  $option_name 設定名
	$options = get_option($set_name);
	$option_name = 'disable-xml-rpc'; //個別配列名

	//テーブルに値がなかった場合の措置（PHP8.x以降への対応）
	if(isset($options[$option_name])){
		$checked = $options[$option_name];
	}else{
		$checked = '';
	}

	//機能が使えるかどうかの判定
	$htaccess_file = ABSPATH . '.htaccess';
	$is_writable = ( file_exists( $htaccess_file ) && is_writable( $htaccess_file ) );
	if ( $is_writable ) {
		$enabled_message_text = __('This feature is available on this site.','hima-art-utility');
		$enabled_message = '<p style="color:green;font-weight:700;">'.$enabled_message_text.'</p>';
	} else {
		$enabled_message_text = __('You are either using a server where the .htaccess file does not exist, or you do not have write permissions to the .htaccess file, so you cannot use this feature.','hima-art-utility');
		$enabled_message = '<p style="color:red;font-weight:700;">'.$enabled_message_text.'</p>';
	}

	//機能が使えない場合には選択できないようにする
	$disabled_attr = ! $is_writable ? 'disabled' : '';
?>
<label>
	<input type="checkbox" id="<?php echo esc_html($set_name . $option_name ); ?>" name="<?php echo esc_html($set_name . '[' .$option_name. ']'); ?>" class="wppd-ui-toggle" <?php checked( $checked , 1 ); ?> value="1" <?php echo esc_html( $disabled_attr ); ?>>
	<?php echo wp_kses_post( $enabled_message ); ?>
	<p><?php esc_html_e('Disables remote connection and remote posting capabilities using XML-RPC','hima-art-utility'); ?></p>
</label>
<?php
}

/*** 必要外のREST APIを無効にする ***/
/* 項目の追加とデータの更新 */
function haumenu_init_field_restrict_rest_api(){
//項目の追加
	add_settings_field(
		'restrict-rest-api', // 設定名
		__('Disable REST API','hima-art-utility'), // 設定タイトル
		'haumenu_restrict_rest_api', // 設定項目のHTMLを出力する関数名
		haumenu_define_tab_slug_02_security(), //表示させるタブのスラグ
		haumenu_define_section_id_02_security(), //セクションID
		array( 'class' => 'ha-settings-separate' )
	);

}
add_action( 'admin_init', 'haumenu_init_field_restrict_rest_api' );

/* 入力フォーム */
function haumenu_restrict_rest_api() {
	$set_name = haumenu_define_option_name_02_security(); //  $option_name 設定名
	$options = get_option($set_name);
	$option_name = 'restrict-rest-api'; //個別配列名

	//テーブルに値がなかった場合の措置（PHP8.x以降への対応）
	if(isset($options[$option_name])){
		$checked = $options[$option_name];
	}else{
		$checked = '';
	}
?>
<label>
	<input type="checkbox" id="<?php echo esc_html($set_name . $option_name ); ?>" name="<?php echo esc_html($set_name . '[' .$option_name. ']'); ?>" class="wppd-ui-toggle" <?php checked( $checked , 1 ); ?> value="1">
	<p><?php esc_html_e('Disable unnecessary REST API connections to prevent information leakage','hima-art-utility'); ?></p>
</label>
<div class="haup-admin-bk">
	<p><?php esc_html_e('Specifically, use of the REST API is permitted only in the following cases','hima-art-utility'); ?></p>
	<ul style="list-style: disc;padding-left:1rem;">
	<li><?php esc_html_e('Using the posting function','hima-art-utility'); ?></li>
	<li><?php esc_html_e('Embedding with oembed','hima-art-utility'); ?></li>
	<li><?php esc_html_e('Access from a server with the same global IP','hima-art-utility'); ?></li>
	<li><?php esc_html_e('Jetpack plugin','hima-art-utility'); ?></li>
	<li><?php esc_html_e('Contact Form7 plugin','hima-art-utility'); ?></li>
	<li><?php esc_html_e('Redirection plugin','hima-art-utility'); ?></li>
	<li><?php esc_html_e('Download Manager plugin (some endpoints in the report)','hima-art-utility'); ?></li>
	<li><?php esc_html_e('Passster plugin','hima-art-utility'); ?></li>
	</ul>
</div>
<?php
}

/*** ソースのCSS/JS読み込みタグからバージョンを削除する ***/
/* 項目の追加とデータの更新 */
function haumenu_init_field_delete_html_wp_version(){
//項目の追加
	add_settings_field(
		'delete-html-wp-version', // 設定名
		__('Remove WP version information from HTML','hima-art-utility'), // 設定タイトル
		'haumenu_delete_html_wp_version', // 設定項目のHTMLを出力する関数名
		haumenu_define_tab_slug_02_security(), //表示させるタブのスラグ
		haumenu_define_section_id_02_security(), //セクションID
		array( 'class' => 'ha-settings-separate' )
	);

}
add_action( 'admin_init', 'haumenu_init_field_delete_html_wp_version' );

/* 入力フォーム */
function haumenu_delete_html_wp_version() {
	$set_name = haumenu_define_option_name_02_security(); //  $option_name 設定名
	$options = get_option($set_name);
	$option_name = 'delete-html-wp-version'; //個別配列名

	//テーブルに値がなかった場合の措置（PHP8.x以降への対応）
	if(isset($options[$option_name])){
		$checked = $options[$option_name];
	}else{
		$checked = '';
	}
?>
<label>
	<input type="checkbox" id="<?php echo esc_html($set_name . $option_name ); ?>" name="<?php echo esc_html($set_name . '[' .$option_name. ']'); ?>" class="wppd-ui-toggle" <?php checked( $checked , 1 ); ?> value="1">
	<p><?php esc_html_e('Removes WordPress version information included in CSS and JS loading tags output to HTML','hima-art-utility'); ?></p>
</label>
<p class="haup-admin-bk">
	<span class="haup-admin-font-red">
		<?php esc_html_e('Since it is a measure to hide the version of WordPress on HTML, it does not directly lead to security improvement.','hima-art-utility'); ?>
	</span>
</p>
<?php
}

/*** Generatorタグを削除する ***/
/* 項目の追加とデータの更新 */
function haumenu_init_field_delete_generator_tag(){
//項目の追加
	add_settings_field(
		'delete-generator-tag', // 設定名
		__('Remove Generator tag','hima-art-utility'), // 設定タイトル
		'haumenu_delete_generator_tag', // 設定項目のHTMLを出力する関数名
		haumenu_define_tab_slug_02_security(), //表示させるタブのスラグ
		haumenu_define_section_id_02_security(), //セクションID
		array( 'class' => 'ha-settings-separate' )
	);

}
add_action( 'admin_init', 'haumenu_init_field_delete_generator_tag' );

/* 入力フォーム */
function haumenu_delete_generator_tag() {
	$set_name = haumenu_define_option_name_02_security(); //  $option_name 設定名
	$options = get_option($set_name);
	$option_name = 'delete-generator-tag'; //個別配列名

	//テーブルに値がなかった場合の措置（PHP8.x以降への対応）
	if(isset($options[$option_name])){
		$checked = $options[$option_name];
	}else{
		$checked = '';
	}
?>
<label>
	<input type="checkbox" id="<?php echo esc_html($set_name . $option_name ); ?>" name="<?php echo esc_html($set_name . '[' .$option_name. ']'); ?>" class="wppd-ui-toggle" <?php checked( $checked , 1 ); ?> value="1">
	<p><?php esc_html_e('Removes Generator tags output to HTML','hima-art-utility'); ?></p>
</label>
<p class="haup-admin-bk haup-admin-font-red">
	<?php esc_html_e('Since it is a measure to hide the version of WordPress on HTML, it does not directly lead to security improvement.','hima-art-utility'); ?>
</p>
<?php
}

/*** 公式配布されていないプラグイン、2年以上更新のないプラグインへの警告 ***/
/* 項目の追加とデータの更新 */
function haumenu_init_field_plugin_secuity_info(){
//項目の追加
	add_settings_field(
		'plugin-secuity-info', // 設定名
		__('Checking the validity of plugins','hima-art-utility'), // 設定タイトル
		'haumenu_plugin_secuity_info', // 設定項目のHTMLを出力する関数名
		haumenu_define_tab_slug_02_security(), //表示させるタブのスラグ
		haumenu_define_section_id_02_security(), //セクションID
		array( 'class' => 'ha-settings-separate' )
	);

}
add_action( 'admin_init', 'haumenu_init_field_plugin_secuity_info' );

/* 入力フォーム */
function haumenu_plugin_secuity_info() {
	$set_name = haumenu_define_option_name_02_security(); //  $option_name 設定名
	$options = get_option($set_name);
	$option_name = 'plugin-secuity-info'; //個別配列名

	//テーブルに値がなかった場合の措置（PHP8.x以降への対応）
	if(isset($options[$option_name])){
		$checked = $options[$option_name];
	}else{
		$checked = '';
	}
?>
<label>
	<input type="checkbox" id="<?php echo esc_html($set_name . $option_name ); ?>" name="<?php echo esc_html($set_name . '[' .$option_name. ']'); ?>" class="wppd-ui-toggle" <?php checked( $checked , 1 ); ?> value="1">
	<p><?php esc_html_e('In the plugin list, a warning message will be displayed for plugins that are not officially distributed or that have been updated more than two years ago.','hima-art-utility'); ?></p>
</label>
<?php
}



/*****  .htaccessへ追加するセキュリティ用コードの有効化 *****/
/*** 設定画面をまとめるためのもの（表示するだけでoptionへの保存等はなし） ***/
/* 項目の追加とデータの更新 */
function haumenu_init_field_enable_htaccess_secure_block(){
//項目の追加
	add_settings_field(
		'enable-htaccess-secure-block', // 設定名
		__('Security measures to add to .htaccess','hima-art-utility'), // 設定タイトル
		'haumenu_enable_htaccess_secure_block', // 設定項目のHTMLを出力する関数名
		haumenu_define_tab_slug_02_security(), //表示させるタブのスラグ
		haumenu_define_section_id_02_security(), //セクションID
		array( 'class' => 'ha-settings-separate' )
	);

}
add_action( 'admin_init', 'haumenu_init_field_enable_htaccess_secure_block' );

/* 入力フォーム */
function haumenu_enable_htaccess_secure_block() {
	$set_name = haumenu_define_option_name_02_security(); //  $option_name 設定名
	$options = get_option($set_name);
	$option_name = 'enable-htaccess-secure-block'; //個別配列名

	//テーブルに値がなかった場合の措置（PHP8.x以降への対応）
	if(isset($options[$option_name])){
		$checked = $options[$option_name];
	}else{
		$checked = '';
	}

	//機能が使えるかどうかの判定
	$htaccess_file = ABSPATH . '.htaccess';
	$is_writable = ( file_exists( $htaccess_file ) && is_writable( $htaccess_file ) );
	if ( $is_writable ) {
		$enabled_message_text = __('This feature is available on this site.','hima-art-utility');
		$enabled_message = '<p style="color:green;font-weight:700;">'.$enabled_message_text.'</p>';
	} else {
		$enabled_message_text = __('You are either using a server where the .htaccess file does not exist, or you do not have write permissions to the .htaccess file, so you cannot use this feature.','hima-art-utility');
		$enabled_message = '<p style="color:red;font-weight:700;">'.$enabled_message_text.'</p>';
	}

	//機能が使えない場合には選択できないようにする
	$disabled_attr = ! $is_writable ? 'disabled' : '';
?>
<?php echo wp_kses_post( $enabled_message ); ?>
<p class="haup-admin-bk"><?php esc_html_e('While using these features can improve security, it may cause problems with WordPress operation. Therefore, if you do not fully understand the purpose of these measures, we recommend not using them.','hima-art-utility'); ?></p>
<p><?php esc_html_e('When enabled, it adds code to the .htaccess file to improve the security status of each item.','hima-art-utility'); ?></p>
<p><?php esc_html_e('Disabling it will remove the code added to .htaccess and disable the function.','hima-art-utility'); ?></p>
<?php
}

/*** wp-config.phpへの直接アクセスを拒否 ***/
/* 項目の追加とデータの更新 */
function haumenu_init_field_disable_wp_config_direct_access(){
//項目の追加
	add_settings_field(
		'disable-wp-config-access', // 設定名
		'', // 設定タイトル
		'haumenu_disable_wp_config_direct_access', // 設定項目のHTMLを出力する関数名
		haumenu_define_tab_slug_02_security(), //表示させるタブのスラグ
		haumenu_define_section_id_02_security(), //セクションID
		array( 'class' => 'ha-settings-convine' )
	);

}
add_action( 'admin_init', 'haumenu_init_field_disable_wp_config_direct_access' );

/* 入力フォーム */
function haumenu_disable_wp_config_direct_access() {
	$set_name = haumenu_define_option_name_02_security(); //  $option_name 設定名
	$options = get_option($set_name);
	$option_name = 'disable-wp-config-access'; //個別配列名

	//テーブルに値がなかった場合の措置（PHP8.x以降への対応）
	if(isset($options[$option_name])){
		$checked = $options[$option_name];
	}else{
		$checked = '';
	}

	//機能が使えるかどうかの判定
	$htaccess_file = ABSPATH . '.htaccess';
	$is_writable = ( file_exists( $htaccess_file ) && is_writable( $htaccess_file ) );
	if ( $is_writable ) {
		$enabled_message_text = __('This feature is available on this site.','hima-art-utility');
		$enabled_message = '<p style="color:green;font-weight:700;">'.$enabled_message_text.'</p>';
	} else {
		$enabled_message_text = __('You are either using a server where the .htaccess file does not exist, or you do not have write permissions to the .htaccess file, so you cannot use this feature.','hima-art-utility');
		$enabled_message = '<p style="color:red;font-weight:700;">'.$enabled_message_text.'</p>';
	}

	//機能が使えない場合には選択できないようにする
	$disabled_attr = ! $is_writable ? 'disabled' : '';

//追加されるコード
$code = '# BEGIN WPConfigProtection
&lt;Files wp-config.php&gt;
    Require all denied
&lt;/Files&gt;
# END WPConfigProtection';
?>
<label>
	<input type="checkbox" id="<?php echo esc_html($set_name . $option_name ); ?>" name="<?php echo esc_html($set_name . '[' .$option_name. ']'); ?>" class="wppd-ui-toggle" <?php checked( $checked , 1 ); ?> value="1" <?php echo esc_html( $disabled_attr ); ?>>
	<span><?php esc_html_e('Deny external access to wp-config.php','hima-art-utility'); ?></span>
</label>
<div style="text-align:right;margin-top:1rem;"><a href="<?php echo esc_url(HAUP_MANUAL_DIR); ?>/howtouse-prevent-access-wp-config-php" target="_blank"><?php echo esc_html(haup_manual_text()); ?></a></div>
<details class="accordion"  style="margin: 5px 0px 0px 0px;overflow: hidden;">
<summary class="accordion__title" style="cursor: pointer;"><?php esc_html_e('Code added to or removed from .htaccess','hima-art-utility'); ?></summary>
<div class="accordion__content">
<pre style="white-space: break-spaces;"><code><?php echo esc_html($code); ?></code></pre>
</div>
</details>
<?php
}

/*** 悪意のあるボット・スクリプトをブロックする ***/
/* 項目の追加とデータの更新 */
function haumenu_init_field_enable_block_bad_bot(){
//項目の追加
	add_settings_field(
		'enable-block-bad-bot', // 設定名
		'', // 設定タイトル
		'haumenu_enable_block_bad_bot', // 設定項目のHTMLを出力する関数名
		haumenu_define_tab_slug_02_security(), //表示させるタブのスラグ
		haumenu_define_section_id_02_security(), //セクションID
		array( 'class' => 'ha-settings-convine' )
	);

}
add_action( 'admin_init', 'haumenu_init_field_enable_block_bad_bot' );

/* 入力フォーム */
function haumenu_enable_block_bad_bot() {
	$set_name = haumenu_define_option_name_02_security(); //  $option_name 設定名
	$options = get_option($set_name);
	$option_name = 'enable-block-bad-bot'; //個別配列名

	//テーブルに値がなかった場合の措置（PHP8.x以降への対応）
	if(isset($options[$option_name])){
		$checked = $options[$option_name];
	}else{
		$checked = '';
	}

	//機能が使えるかどうかの判定
	$htaccess_file = ABSPATH . '.htaccess';
	$is_writable = ( file_exists( $htaccess_file ) && is_writable( $htaccess_file ) );
	if ( $is_writable ) {
		$enabled_message_text = __('This feature is available on this site.','hima-art-utility');
		$enabled_message = '<p style="color:green;font-weight:700;">'.$enabled_message_text.'</p>';
	} else {
		$enabled_message_text = __('You are either using a server where the .htaccess file does not exist, or you do not have write permissions to the .htaccess file, so you cannot use this feature.','hima-art-utility');
		$enabled_message = '<p style="color:red;font-weight:700;">'.$enabled_message_text.'</p>';
	}

	//機能が使えない場合には選択できないようにする
	$disabled_attr = ! $is_writable ? 'disabled' : '';

//追加されるコード
$code = '# BEGIN HaupBlockBadBots
# 悪意のあるボット・スクリプトをブロック
&lt;IfModule mod_rewrite.c&gt;
    RewriteEngine On
    RewriteCond %{HTTP_USER_AGENT} (nikto|sqlmap|masscan|nmap|zgrab|wget|curl|httpie|python-requests|go-http-client|libwww-perl|scrapy|java/) [NC]
    RewriteRule .* - [F,L]
&lt;/IfModule&gt;
# END HaupBlockBadBots';
?>
<label>
	<input type="checkbox" id="<?php echo esc_html($set_name . $option_name ); ?>" name="<?php echo esc_html($set_name . '[' .$option_name. ']'); ?>" class="wppd-ui-toggle" <?php checked( $checked , 1 ); ?> value="1" <?php echo esc_html($disabled_attr ); ?>>
	<span><?php esc_html_e('Block malicious bot scripts.','hima-art-utility'); ?></span>
</label>
<details class="accordion"  style="margin: 5px 0px 0px 0px;overflow: hidden;">
<summary class="accordion__title" style="cursor: pointer;"><?php esc_html_e('Code added to or removed from .htaccess','hima-art-utility'); ?></summary>
<div class="accordion__content">
<pre style="white-space: break-spaces;"><code><?php echo esc_html($code); ?></code></pre>
</div>
</details>
<?php
}

/*** wp-admin/includes/ への直接アクセスをブロック ***/
/* 項目の追加とデータの更新 */
function haumenu_init_field_enable_block_admin_includes(){
//項目の追加
	add_settings_field(
		'enable-block-admin-includes', // 設定名
		'', // 設定タイトル
		'haumenu_enable_block_admin_includes', // 設定項目のHTMLを出力する関数名
		haumenu_define_tab_slug_02_security(), //表示させるタブのスラグ
		haumenu_define_section_id_02_security(), //セクションID
		array( 'class' => 'ha-settings-convine' )
	);

}
add_action( 'admin_init', 'haumenu_init_field_enable_block_admin_includes' );

/* 入力フォーム */
function haumenu_enable_block_admin_includes() {
	$set_name = haumenu_define_option_name_02_security(); //  $option_name 設定名
	$options = get_option($set_name);
	$option_name = 'enable-block-admin-includes'; //個別配列名

	//テーブルに値がなかった場合の措置（PHP8.x以降への対応）
	if(isset($options[$option_name])){
		$checked = $options[$option_name];
	}else{
		$checked = '';
	}

	//機能が使えるかどうかの判定
	$htaccess_file = ABSPATH . '.htaccess';
	$is_writable = ( file_exists( $htaccess_file ) && is_writable( $htaccess_file ) );
	if ( $is_writable ) {
		$enabled_message_text = __('This feature is available on this site.','hima-art-utility');
		$enabled_message = '<p style="color:green;font-weight:700;">'.$enabled_message_text.'</p>';
	} else {
		$enabled_message_text = __('You are either using a server where the .htaccess file does not exist, or you do not have write permissions to the .htaccess file, so you cannot use this feature.','hima-art-utility');
		$enabled_message = '<p style="color:red;font-weight:700;">'.$enabled_message_text.'</p>';
	}

	//機能が使えない場合には選択できないようにする
	$disabled_attr = ! $is_writable ? 'disabled' : '';

//追加されるコード
$code = '# BEGIN HaupBlockAdminIncludes
# wp-admin/includes/ への直接アクセスをブロック
&lt;IfModule mod_rewrite.c&gt;
    RewriteEngine On
    RewriteCond %{REQUEST_URI} ^/wp-admin/includes(?:/|$) [NC]
    RewriteRule .* - [F,L]
&lt;/IfModule&gt;
# END HaupBlockAdminIncludes';
?>
<label>
	<input type="checkbox" id="<?php echo esc_html($set_name . $option_name ); ?>" name="<?php echo esc_html($set_name . '[' .$option_name. ']'); ?>" class="wppd-ui-toggle" <?php checked( $checked , 1 ); ?> value="1" <?php echo esc_html($disabled_attr ); ?>>
	<span><?php esc_html_e('Block direct access to wp-admin/includes/','hima-art-utility'); ?></span>
</label>
<details class="accordion"  style="margin: 5px 0px 0px 0px;overflow: hidden;">
<summary class="accordion__title" style="cursor: pointer;"><?php esc_html_e('Code added to or removed from .htaccess','hima-art-utility'); ?></summary>
<div class="accordion__content">
<pre style="white-space: break-spaces;"><code><?php echo esc_html($code); ?></code></pre>
</div>
</details>
<?php
}

/*** wp-includes/内のphpファイルへの直接アクセスをブロック ***/
/* 項目の追加とデータの更新 */
function haumenu_init_field_enable_block_wp_includes(){
//項目の追加
	add_settings_field(
		'enable-block-wp-includes', // 設定名
		'', // 設定タイトル
		'haumenu_enable_block_wp_includes', // 設定項目のHTMLを出力する関数名
		haumenu_define_tab_slug_02_security(), //表示させるタブのスラグ
		haumenu_define_section_id_02_security(), //セクションID
		array( 'class' => 'ha-settings-convine' )
	);

}
add_action( 'admin_init', 'haumenu_init_field_enable_block_wp_includes' );

/* 入力フォーム */
function haumenu_enable_block_wp_includes() {
	$set_name = haumenu_define_option_name_02_security(); //  $option_name 設定名
	$options = get_option($set_name);
	$option_name = 'enable-block-wp-includes'; //個別配列名

	//テーブルに値がなかった場合の措置（PHP8.x以降への対応）
	if(isset($options[$option_name])){
		$checked = $options[$option_name];
	}else{
		$checked = '';
	}

	//機能が使えるかどうかの判定
	$htaccess_file = ABSPATH . '.htaccess';
	$is_writable = ( file_exists( $htaccess_file ) && is_writable( $htaccess_file ) );
	if ( $is_writable ) {
		$enabled_message_text = __('This feature is available on this site.','hima-art-utility');
		$enabled_message = '<p style="color:green;font-weight:700;">'.$enabled_message_text.'</p>';
	} else {
		$enabled_message_text = __('You are either using a server where the .htaccess file does not exist, or you do not have write permissions to the .htaccess file, so you cannot use this feature.','hima-art-utility');
		$enabled_message = '<p style="color:red;font-weight:700;">'.$enabled_message_text.'</p>';
	}

	//機能が使えない場合には選択できないようにする
	$disabled_attr = ! $is_writable ? 'disabled' : '';

//追加されるコード
$code = '# BEGIN HaupBlockIncludesFiles
# wp-includes/--.php への直接アクセスをブロック
&lt;IfModule mod_rewrite.c&gt;
    RewriteEngine On
    RewriteCond %{REQUEST_URI} ^/wp-includes/[^/]+\.php$ [NC]
    RewriteRule .* - [F,L]
&lt;/IfModule&gt;
# END HaupBlockIncludesFiles';
?>
<label>
	<input type="checkbox" id="<?php echo esc_html($set_name . $option_name ); ?>" name="<?php echo esc_html($set_name . '[' .$option_name. ']'); ?>" class="wppd-ui-toggle" <?php checked( $checked , 1 ); ?> value="1" <?php echo esc_html($disabled_attr ); ?>>
	<span><?php esc_html_e('Block direct access to wp-includes/*.php','hima-art-utility'); ?></span>
</label>
<details class="accordion"  style="margin: 5px 0px 0px 0px;overflow: hidden;">
<summary class="accordion__title" style="cursor: pointer;"><?php esc_html_e('Code added to or removed from .htaccess','hima-art-utility'); ?></summary>
<div class="accordion__content">
<pre style="white-space: break-spaces;"><code><?php echo esc_html($code); ?></code></pre>
</div>
</details>
<?php
}

/*** 不正なクエリ文字列をブロック ***/
/* 項目の追加とデータの更新 */
function haumenu_init_field_enable_block_bad_query(){
//項目の追加
	add_settings_field(
		'enable-block-bad-query', // 設定名
		'', // 設定タイトル
		'haumenu_enable_block_bad_query', // 設定項目のHTMLを出力する関数名
		haumenu_define_tab_slug_02_security(), //表示させるタブのスラグ
		haumenu_define_section_id_02_security(), //セクションID
		array( 'class' => 'ha-settings-convine' )
	);

}
add_action( 'admin_init', 'haumenu_init_field_enable_block_bad_query' );

/* 入力フォーム */
function haumenu_enable_block_bad_query() {
	$set_name = haumenu_define_option_name_02_security(); //  $option_name 設定名
	$options = get_option($set_name);
	$option_name = 'enable-block-bad-query'; //個別配列名

	//テーブルに値がなかった場合の措置（PHP8.x以降への対応）
	if(isset($options[$option_name])){
		$checked = $options[$option_name];
	}else{
		$checked = '';
	}

	//機能が使えるかどうかの判定
	$htaccess_file = ABSPATH . '.htaccess';
	$is_writable = ( file_exists( $htaccess_file ) && is_writable( $htaccess_file ) );
	if ( $is_writable ) {
		$enabled_message_text = __('This feature is available on this site.','hima-art-utility');
		$enabled_message = '<p style="color:green;font-weight:700;">'.$enabled_message_text.'</p>';
	} else {
		$enabled_message_text = __('You are either using a server where the .htaccess file does not exist, or you do not have write permissions to the .htaccess file, so you cannot use this feature.','hima-art-utility');
		$enabled_message = '<p style="color:red;font-weight:700;">'.$enabled_message_text.'</p>';
	}

	//機能が使えない場合には選択できないようにする
	$disabled_attr = ! $is_writable ? 'disabled' : '';

//追加されるコード
$code = '# BEGIN HaupBlockBadQuery
# 不正なクエリ文字列をブロック
&lt;IfModule mod_rewrite.c&gt;
    RewriteEngine On
    RewriteCond %{QUERY_STRING} (^|&amp;)w=[^&amp;]+(&amp;|$) [NC]
    RewriteRule ^ - [R=410,L]
&lt;/IfModule&gt;
# END HaupBlockBadQuery';
?>
<label>
	<input type="checkbox" id="<?php echo esc_html($set_name . $option_name ); ?>" name="<?php echo esc_html($set_name . '[' .$option_name. ']'); ?>" class="wppd-ui-toggle" <?php checked( $checked , 1 ); ?> value="1" <?php echo esc_html($disabled_attr ); ?>>
	<span><?php esc_html_e('Block invalid query strings.','hima-art-utility'); ?></span>
</label>
<details class="accordion"  style="margin: 5px 0px 0px 0px;overflow: hidden;">
<summary class="accordion__title" style="cursor: pointer;"><?php esc_html_e('Code added to or removed from .htaccess','hima-art-utility'); ?></summary>
<div class="accordion__content">
<pre style="white-space: break-spaces;"><code><?php echo esc_html($code); ?></code></pre>
</div>
</details>
<?php
}

/*** WordPressで直接改ざんされる可能性のあるファイルの監視 ***/
/* 項目の追加とデータの更新 */
function haumenu_init_field_wp_core_file_change_notice_widget(){
//項目の追加
	add_settings_field(
		'core-file-change-notice', // 設定名
		__('Checking for core file changes','hima-art-utility'), // 設定タイトル
		'haumenu_wp_core_file_change_notice_widget', // 設定項目のHTMLを出力する関数名
		haumenu_define_tab_slug_02_security(), //表示させるタブのスラグ
		haumenu_define_section_id_02_security(), //セクションID
		array( 'class' => 'ha-settings-separate' )
	);

}
add_action( 'admin_init', 'haumenu_init_field_wp_core_file_change_notice_widget' );

/* 入力フォーム */
function haumenu_wp_core_file_change_notice_widget() {
	$set_name = haumenu_define_option_name_02_security(); //  $option_name 設定名
	$options = get_option($set_name);
	$option_name = 'core-file-change-notice'; //個別配列名

	//テーブルに値がなかった場合の措置（PHP8.x以降への対応）
	if(isset($options[$option_name])){
		$checked = $options[$option_name];
	}else{
		$checked = '';
	}
?>
<label>
	<input type="checkbox" id="<?php echo esc_html($set_name . $option_name ); ?>" name="<?php echo esc_html($set_name . '[' .$option_name. ']'); ?>" class="wppd-ui-toggle" <?php checked( $checked , 1 ); ?> value="1">
	<p><?php esc_html_e('The dashboard widget displays the results of a check for changes to the following files, which are necessary for WordPress to function and may be directly or indirectly altered.','hima-art-utility'); ?></p>
	<ul>
		<li><?php echo esc_html('wp-config.php'); ?></li>
		<li><?php echo esc_html('.htaccess'); ?></li>
		<li><?php echo esc_html('index.php'); ?></li>
		<li><?php echo esc_html('wp-settings.php'); ?></li>
	</ul>
</label>
<?php
}