这种设置框架适用于我处理自定义选项页面输入:
<?php
/*
Plugin Name: Settings Skeleton
*/
if(!class_exists(\'MySettings\')){
function call_my_settings() {
return new MySettings();
}
if (is_admin()){
add_action( \'init\', \'call_my_settings\' );
}
class MySettings{
public function __construct(){
add_action(\'admin_menu\', array(&$this, \'add_menu\'));
add_action(\'admin_init\', array(&$this,\'settings\') );
}
public function add_menu(){
add_options_page(__(\'My Plugin Settings\',\'myplugindomain\'), \'My Plugin Settings\', \'manage_options\', __FILE__, array(&$this,\'options_page\'));
}
public function settings() {
register_setting( \'my_settings\', \'my_settings\', array(&$this,\'validate\') );
}
public function validate($input) {
// do validation
$input[\'mytext\']=esc_attr($input[\'mytext\']);
return $input;
}
public function options_page(){
?>
<div class="wrap">
<div class="icon32" id="icon-options-general"><br></div>
<h2><?php _e(\'My plugin settings\',\'myplugindomain\'); ?></h2>
<form method="post" action="options.php">
<?php settings_fields(\'my_settings\'); ?>
<?php $settings = get_option(\'my_settings\'); ?>
<table class="form-table">
<tr>
<th scope="row" colspan="2">
<h3><?php _e(\'General settings\',\'myplugindomain\'); ?></h3>
</th>
</tr>
<tr>
<th scope="row"><?php _e(\'My text\',\'myplugindomain\'); ?> </th>
<td>
<input type="text" size="70" name="my_settings[mytext]" value="<?php echo $settings[mytext]; ?>" />
</td>
</tr>
</table>
<?php submit_button(); ?>
</form>
</div>
<?php
}
}
}
这将为您提供以下选项页面:
你怎么把你的settings()
作用
在上面的代码示例中settings()
函数连接到admin_init
行动,即。
add_action(\'admin_init\', array(&$this,\'settings\') );