いつもありがとうございます。
下記の行がサニタイズ≒値チェックできてないとのことですが、保存するデータはそれ以降の行でチェックを行っているつもりです。下記の行について、どういった処理が必要でしょうか?
$this->options = $_POST[$this->text_domain];
That sets your option name to be a NON sanitized value.
php
1 2function admin_setting_form() { 3 $post_types = wp_list_filter( get_post_types(array('public'=>true)),array('attachment'), 'NOT' ); 4 ?> 5 <div class="wrap"> 6 <h2><?php echo esc_attr($this->name); ?> » <?php _e('Settings'); ?></h2> 7 <form id="<?php echo esc_attr($this->text_domain); ?>" method="post" action=""> 8 <?php wp_nonce_field( 'csr-nonce-key', 'csr-key' ); ?> 9 <h3><?php _e('有効にする投稿タイプを選択してください'); ?></h3> 10 <?php 11 foreach ( $post_types as $post_type ) { 12 ?> 13 <p> 14 <strong><?php echo esc_attr($post_type); ?>ページ上で有効にします</strong> 15 <input type="checkbox" name="<?php echo esc_attr($this->text_domain); ?>[post_type][<?php echo esc_attr($post_type); ?>]" value="1" <?php if( isset( $this->options['post_type'][$post_type] ) && $this->options['post_type'][$post_type] == '1' ) echo 'checked'; ?> /> 16 </p> 17 <?php 18 } 19 ?> 20 <h3>コメントの入力から外したい要素を選択</h3> 21 <p> 22 <strong>URLを外す</strong> 23 <input type="checkbox" name="<?php echo esc_attr($this->text_domain); ?>[url]" value="1" <?php if( isset( $this->options['url'] ) && $this->options['url'] == '1' ) echo 'checked'; ?> /> 24 </p> 25 <p> 26 <strong>メールアドレスを外す</strong> 27 <input type="checkbox" name="<?php echo esc_attr($this->text_domain); ?>[email]" value="1" <?php if( isset( $this->options['email'] ) && $this->options['email'] == '1' ) echo 'checked'; ?> /> 28 </p> 29 <p class="submit"> 30 <input class="button-primary" type="submit" name='save' value='<?php _e('Save Changes') ?>' /> 31 </p> 32 </form> 33 </div> 34 <?php 35} 36// save 37function admin_save_options() { 38 $post_types = wp_list_filter( get_post_types(array('public'=>true)),array('attachment'), 'NOT' ); 39 if (isset($_POST['save'])) { 40 if( check_admin_referer( 'csr-nonce-key', 'csr-key' ) ) { 41 if (isset($_POST[$this->text_domain]) && is_array($_POST[$this->text_domain]) ) { 42 $this->options = $_POST[$this->text_domain]; 43 // post_type sanitai 44 foreach ( $post_types as $post_type ) { 45 if( isset($this->options['post_type'][$post_type]) ) { 46 $this->options['post_type'][$post_type] = '1'; 47 } 48 } 49 if( isset( $this->options['url'] ) && $this->options['url'] == '1' ) { 50 $this->options['url'] = '1'; 51 } 52 if( isset( $this->options['email'] ) && $this->options['email'] == '1' ) { 53 $this->options['email'] = '1'; 54 } 55 update_option($this->text_domain, $this->options ); 56 } 57 //wp_safe_redirect( menu_page_url( $this->text_domain, false ) ); 58 } 59 } 60 $this->options = get_option($this->text_domain); 61 $this->admin_setting_form(); 62}
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/02/17 16:55