check_admin_referer(), wp_nonce_field()
function my_plugin_menu() { add_options_page( ('My Plugin Options','my_plugin'), ('My Plugin','my_plugin'), 'manage_options', FILE, 'my_plugin_options'); } add_action('admin_menu', 'my_plugin_menu'); 3. function my_plugin_options() {?><div class="wrap"> <?php /* */?> </div><?php }
$My_Plugin_Options = new My_Plugin_Options; class My_Plugin_Options { public function construct() { add_action('admin_menu', array($this,'add_menu')); } public function add_menu() { add_options_page( ('My Plugin Options','my_plugin'), ('My Plugin','my_plugin'), 'manage_options', FILE, array($this, 'options_page')); } public function options_page () { /* */ } /* End of class */ }
add_options_page( $page_title, /* */ $menu_title, /* */ $access_level, /* 8 */ $file, /* FILE */ $function /* */ )
public function options_page () { if (isset($_post['update_option'])) { check_admin_referer('my_plugin-options'); $this->upate_options();?> <div class="updated fade"><p><strong><?php _e('options saved.');?></strong></p></div> <?php } $font_color = get_option('my_plugin_font_color');?> <div class="wrap"> <h2><?php _e('my Plugin Options', 'my_plugin');?></h2> <form name="form" method="post" action=""> <input type="hidden" name="action" value="update" /> <?php wp_nonce_field('my_plugin-options');?> <!-- -->
wp_nonce_field check_admin_referer wp_nonce_field('field_name'); check_admin_referer('field_name');
<table class="form-table"><tbody><tr> <th><label for="my_plugin_font_color"><?php _e('font Color', 'my_plugin');?></label></th> <td><input type="text" name="my_plugin_font_color" id="my_plugin_font_color" value="<?php echo attribute_escape($font_color);?>" /></td> </tr></tbody></table> <p class="submit"> <input type="submit" name="update_option" class="buttonprimary" value="<?php _e('save Changes');?>" /> </p> </form></div>
private function update_option() { } if (isset($_post['my_plugin_font_color'])) { } $font_color = stripslashes( $_POST['my_plugin_font_color'] ); if (preg_match('/^#[0-9a-fa-f]+$/', $font_color)) { } update_option('my_plugin_font_color', $font_color); $_POST addslashes() stripslashes()
<tr> <th><?php _e('bold Style', 'my_plugin');?></th> <td><label> <input type="checkbox" name="my_plugin_use_bold" id="my_plugin_use_bold"<?php checked($use_bold);?> /> <?php _e('use bold style for link', 'my_plugin');?> </label></td> </tr>
checked($checked, $current) $checked $current checked('post', $post_or_page) checked($checked) $checked == true
<tr><th><?php _e('emphasis Style', 'my_plugin');?></th> <td> <label><input type="radio" name="my_plugin_emphasis" id="my_plugin_emphasis-strong" value="strong" <?php checked('strong', $emphasis_sytle);?>/> <?php _e('strong', 'my_plugin');?></label> <br /> <label><input type="radio" name="my_plugin_emphasis" id="my_plugin_emphasis-em" value="em" <?php checked('em', $emphasis_sytle);?>/> <?php _e('em', 'my_plugin');?></label> </td> </tr>
$intervals = array(0, 2, 5, 10, 15, 30, 60);?> <tr> <th><label for="my_plugin_interval"><?php _e('retieval Interval', 'my_plugin');?></label></th> <td> <select name="my_plugin_interval" id="my_plugin_interval"> <?php foreach ($intervals as $i) {?> <option value="<?php echo intval($i);?>" <?php selected($i, $interval);?> /> <?php _e($i. ' min', 'my_plugin');?></option> <?php }?> </select> </td> </tr>
selected($selected, $current) $selcted $current selected(15, $interval) selected($selected) $selected == true
wp_specialchars($string) attribute_escape($attribute) <input type="input" value="<?php echo attribute_escape($opt_value);?>".. etc_html(), esc_attr() clean_url($url) esc_url()
<form method="post" action=""> action="<?php echo str_replace('%7e','~', $_SERVER['REQUEST_URI']);?>"