Files
Convert_Protection_Text/class/class.conv_protection_txt.php
nobu d8afed24d5 ・WordPress6.9動作確認
・PHP8.3対応修正
2025-12-16 20:13:03 +09:00

80 lines
2.3 KiB
PHP

<?php
if ( ! defined( 'ABSPATH' ) ) {
exit;
} // Exit if accessed directly
if ( ! class_exists( 'conv_protection_txt' ) ) {
class conv_protection_txt {
public function __construct() {
add_action( 'admin_menu', array( $this, 'add_pages' ) );
add_filter( 'protected_title_format', array( $this, 'edit_protected_word' ) );
add_filter( 'the_password_form', array( $this, 'protect_password_form' ) );
}
public function add_pages() {
add_menu_page(
'Convert Protection Text',
'Convert Protection Text',
'level_8',
__FILE__,
array(
$this,
'show_text_option_page'
)
);
}
public function show_text_option_page() {
$update_option = filter_input( INPUT_POST, 'conv_protection_options', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY );
if ( ! empty( $update_option ) ) {
check_admin_referer( 'conv_options' );
update_option( 'conv_protection_options', $update_option );
include_once conv_protection_txt_settings::TEMPLATE_DIR . 'success.php';
}
include_once conv_protection_txt_settings::TEMPLATE_DIR . 'conv_protection_txt_form.php';
}
public function edit_protected_word( $text ) {
$opt = get_option( 'conv_protection_options' );
if ( isset( $opt['flag'] ) && $opt['flag'] == 2 ) {
return '%s';
}
return $text;
}
//パスワード保護時のメッセージ
public function protect_password_form( $form_text ): string {
$opt = get_option( 'conv_protection_options' );
if (! empty( $opt['text'] )) {
$alert_text = $opt['text'];
} else {
$alert_text = conv_protection_txt_settings::ALERT_TEXT;
}
if (! empty( $opt['label'] )) {
$btn_label = $opt['label'] . ' : ';
} else {
$btn_label = conv_protection_txt_settings::BTN_LABEL . ' : ';
}
if (! empty( $opt['btn'] )) {
$btn_text = $opt['btn'];
} else {
$btn_text = conv_protection_txt_settings::BTN_TEXT;
}
return '
<form action="' . wp_login_url() . '?action=postpass" class="post-password-form" method="post">
<p>' . nl2br( esc_html( $alert_text ) ) . '</p>
<p>
<label for="pwbox">' . esc_html( $btn_label ) .
'<input name="post_password" id="pwbox" type="password" size="20">
</label>
<input type="submit" name="Submit" value="' . esc_attr( $btn_text ) . '">
</p>
</form>';
}
}
}