将呈现具有自己的设置页面和单个文本字段的插件。为字段输入值并提交表单时,Settings saved.
渲染。然而,对数据库的查询wp_options
表显示未存储设置值;选项名称rma_base_url
表中存在
代码:
add_action(\'admin_menu\', \'remote_member_auth_menu\');
function remote_member_auth_menu() {
add_options_page(\'Remote Member Auth Options\', \'Remote Member Auth\', \'manage_options\', \'rma\', \'remote_member_auth_options\');
}
function remote_member_auth_options() {
if (!current_user_can(\'manage_options\')) {
wp_die(__(\'You do not have sufficient permissions to access this page.\'));
}
echo \'<div class="wrap">\' .
\'<h3>Remote Member Authnetication Settings</h3>\' .
\'<form method="post" action="options.php">\';
settings_fields(\'rma_options\');
do_settings_sections(\'rma\');
submit_button(\'Set base url\');
echo \'</form>\' .
\'</div>\';
}
function register_rma_settings() {
register_setting(\'rma_options\', \'rma_base_url\');
add_settings_section(\'rma_main\', \'\', \'rma_main_settings_fn\', \'rma\');
add_settings_field(\'rma_base_url\', \'Base URL\', \'rma_base_url_string\', \'rma\', \'rma_main\');
}
add_action(\'admin_init\', \'register_rma_settings\');
function rma_base_url_string() {
$option = get_option(\'rma_base_url\');
echo "<input id=\'rma_base_url\' name=\'rma_options[rma_base_url]\' size=\'40\' type=\'text\' value=\'{$option}\' />";
}
function rma_main_settings_fn() {
echo \'\';
}