WP_PLUGIN パスワード保護ページのテキスト変更

・サニタイズとエスケープ
・完了メッセージの閉じるボタン追加
This commit is contained in:
2021-06-18 19:20:02 +09:00
parent cd7f6fd0a5
commit 622d8dc3c8
+54 -51
View File
@@ -30,19 +30,20 @@ class CNV_Protection_Text {
} }
public function show_text_option_page() { public function show_text_option_page() {
//$_POST['_cnv_protect_options'])があったら保存 $update_option = filter_input( INPUT_POST, '_cnv_protect_options', FILTER_SANITIZE_STRING, FILTER_REQUIRE_ARRAY );
if ( isset( $_POST['_cnv_protect_options'] ) ) { if ( ! empty( $update_option ) ) {
check_admin_referer( 'cnv_options' ); check_admin_referer( 'cnv_options' );
$opt = $_POST['_cnv_protect_options']; update_option( '_cnv_protect_options', $update_option );
update_option( '_cnv_protect_options', $opt );
?> ?>
<div class="updated fade"><p><strong>設定を保存しました</strong></p></div><?php <div id="settings_updated" class="updated notice is-dismissible">
<p><strong>設定を保存しました</strong></p>
</div><?php
} }
?> ?>
<div class="wrap"> <div class="wrap">
<div id="icon-options-general" class="icon32"><br/></div> <div id="icon-options-general" class="icon32"><br/></div>
<h2>アクセス権限ページ設定</h2> <h2>アクセス権限ページ設定</h2>
<form action="" method="post"> <form action="" method="post">
<?php <?php
wp_nonce_field( 'cnv_options' ); wp_nonce_field( 'cnv_options' );
$opt = get_option( '_cnv_protect_options' ); $opt = get_option( '_cnv_protect_options' );
@@ -51,50 +52,52 @@ class CNV_Protection_Text {
$show_label = $opt['label'] ?? self::BTN_LABEL; $show_label = $opt['label'] ?? self::BTN_LABEL;
$show_btn = $opt['btn'] ?? self::BTN_TEXT; $show_btn = $opt['btn'] ?? self::BTN_TEXT;
?> ?>
<table class="form-table"> <table class="form-table">
<tr valign="top"> <tr valign="top">
<th scope="row"><label for="inputtext">保護中</label></th> <th scope="row"><label for="inputtext">保護中</label></th>
<td> <td>
<?php if ( $show_radio == 2 ) : ?> <?php if ( $show_radio == 2 ) : ?>
<label> <label>
<input type="radio" name="_cnv_protect_options[flag]" value="1">表示 <input type="radio" name="_cnv_protect_options[flag]" value="1">表示
</label> </label>
<label> <label>
<input type="radio" name="_cnv_protect_options[flag]" value="2" checked>非表示 <input type="radio" name="_cnv_protect_options[flag]" value="2" checked>非表示
</label> </label>
<?php elseif ( $show_radio == 1 ): ?> <?php elseif ( $show_radio == 1 ): ?>
<label> <label>
<input type="radio" name="_cnv_protect_options[flag]" value="1" checked>表示 <input type="radio" name="_cnv_protect_options[flag]" value="1" checked>表示
</label> </label>
<label> <label>
<input type="radio" name="_cnv_protect_options[flag]" value="2">非表示 <input type="radio" name="_cnv_protect_options[flag]" value="2">非表示
</label> </label>
<?php endif; ?> <?php endif; ?>
</td> </td>
</tr> </tr>
<tr valign="top"> <tr valign="top">
<th scope="row">メッセージ</th> <th scope="row">メッセージ</th>
<td> <td>
<textarea name="_cnv_protect_options[text]" rows="4" <textarea name="_cnv_protect_options[text]" rows="4"
cols="60"><?php echo $show_text; ?></textarea> cols="60"><?php echo esc_html( $show_text ); ?></textarea>
</td> </td>
</tr> </tr>
<tr valign="top"> <tr valign="top">
<th scope="row">ボタンラベル</th> <th scope="row">ボタンラベル</th>
<td> <td>
<input type="text" name="_cnv_protect_options[label]" value="<?php echo $show_label; ?>"> <input type="text" name="_cnv_protect_options[label]"
</td> value="<?php echo esc_html( $show_label ); ?>">
</tr> </td>
<tr valign="top"> </tr>
<th scope="row">ボタン名</th> <tr valign="top">
<td> <th scope="row">ボタン名</th>
<input type="text" name="_cnv_protect_options[btn]" value="<?php echo $show_btn; ?>"> <td>
</td> <input type="text" name="_cnv_protect_options[btn]"
</tr> value="<?php echo esc_html( $show_btn ); ?>">
</table> </td>
<p class="submit"><input type="submit" name="Submit" class="button-primary" value="変更を保存"/></p> </tr>
</form> </table>
<!-- /.wrap --></div> <p class="submit"><input type="submit" name="Submit" class="button-primary" value="変更を保存"/></p>
</form>
<!-- /.wrap --></div>
<?php <?php
} }
@@ -127,8 +130,8 @@ class CNV_Protection_Text {
} }
return '<form action="' . home_url() . '/wp-login.php?action=postpass" class="post-password-form" method="post"> return '<form action="' . home_url() . '/wp-login.php?action=postpass" class="post-password-form" method="post">
<p>' . nl2br( $alert_text ) . '</p> <p>' . nl2br( esc_html( $alert_text ) ) . '</p>
<p><label for="pwbox">' . $btn_label . '<input name="post_password" id="pwbox" type="password" size="20"></label> <input type="submit" name="Submit" value="' . $btn_text . '"></p></form>'; <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_html( $btn_text ) . '"></p></form>';
} }
} }