我正在创建一个小的WordPress插件。我创建了设置页面,设置页面中有两个用户输入。
我创建了两种选项类型。那些是rmpm_post_newcount 和rmpm_post_newname. 激活此插件后,中没有rmpm\\u post\\u newcount和rmpm\\u post\\u newnameoption.php page.
原因是什么?
// Specify Hooks/Filters
register_activation_hook(__FILE__, \'rmpm_add_defaults_options\');
add_action(\'admin_init\', \'rmpm_init_fn\' );
add_action(\'admin_menu\', \'rmpm_add_page\');
// Define default option settings
function rmpm_add_defaults_options() {
$tmp = get_option(\'plugin_options\');
$arr = array("rmpm_post_newcount" => "10", "rmpm_post_newname" => "My Blog Posts");
update_option(\'plugin_options\', $arr);
}
// Register our settings. Add the settings section, and settings fields
function rmpm_init_fn(){
register_setting(\'plugin_options\', \'plugin_options\', \'plugin_options_validate\' );
add_settings_section(\'main_section\', \'Main Settings\', \'rmpm_section_text_fn\', __FILE__);
add_settings_field(\'rmpm_plugin_count\', \'Display Posts Count\', \'rmpm_setting_count_fn\', __FILE__, \'main_section\');
add_settings_field(\'rmpm_plugin_name\', \'Display Name\', \'rmpm_setting_name_fn\', __FILE__, \'main_section\');
}
// Add sub page to the Settings Menu
function rmpm_add_page() {
add_options_page(\'Recent Posts BP Profile\', \'Recent Posts BP Profile\', \'administrator\', __FILE__, \'rmpm_options_page_fn\');
}
// ************************************************************************************************************
// Callback functions
// Section HTML, displayed before the first option
function rmpm_section_text_fn() {
echo \'<p>Theese are some setting.</p>\';
}
// TEXTBOX - Name: plugin_options[text_string]
function rmpm_setting_count_fn() {
$options = get_option(\'plugin_options\');
echo "<input id=\'rmpm_plugin_count\' name=\'plugin_options[rmpm_post_newcount]\' size=\'40\' type=\'text\' value=\'{$options[\'rmpm_post_newcount\']}\' />";
}
// PASSWORD-TEXTBOX - Name: plugin_options[text_string2]
function rmpm_setting_name_fn() {
$options = get_option(\'plugin_options\');
echo "<input id=\'rmpm_plugin_name\' name=\'plugin_options[rmpm_post_newname]\' size=\'40\' type=\'text\' value=\'{$options[\'rmpm_post_newname\']}\' />";
}
function rmpm_options_page_fn() {
?>
<div class="wrap">
<div class="icon32" id="icon-options-general"><br></div>
<h2>Setting Page</h2>
Some optional text here explaining the overall purpose of the options and what they relate to etc.
<form action="options.php" method="post">
<?php settings_fields(\'plugin_options\'); ?>
<?php do_settings_sections(__FILE__); ?>
<p class="submit">
<input name="Submit" type="submit" class="button-primary" value="<?php esc_attr_e(\'Save Changes\'); ?>" />
</p>
</form>
</div>
<?php
}