[英]Wordpress - Error: Options Page Not Found
I know there's a few solutions out there for this problem, but none of them seem to fix my code. 我知道有一些解决此问题的方法,但是似乎没有一个可以解决我的代码。
I've been following a lynda.com tutorial on creating plugins. 我一直在关注有关创建插件的lynda.com教程。 However I believe they are using an older version of wordpress, which is why I think I'm running into trouble. 但是我相信他们使用的是旧版的wordpress,这就是为什么我认为自己遇到了麻烦。
I'm trying to add an options page, but everytime I "save" on my options page it gives me "not found" error for the options.php page. 我正在尝试添加一个选项页面,但是每次我在选项页面上“保存”时,都会为options.php页面提供“未找到”错误。
Here's my code: 这是我的代码:
function cc_init(){
register_setting('cc_options,','cc_cc_email');
}add_action('admin_init','cc_init');
function cc_option_page(){
?>
<div class="wrap">
<?php screen_icon(); ?>
<h2>CC Comments Options</h2>
<p>Welcome to the CC comments plugin. here you can edit the email(s) to CC your comments to.</p>
<form action="options.php" method="post" id="cc-comments-email-options-form">
<?php settings_fields('cc_options'); ?>
<h3><label for="cc_cc_email">Eamil to send CC to:</label>
<input type="text" id="cc_cc_email" name="cc_cc_email"
value="<?php echo esc_attr(get_option('cc_cc_email')); ?>" /></h3>
<p><input type="submit" name="submit" value="Save Email" /></p>
</form>
</div>
<?php
}
function cc_plugin_menu(){
add_options_page('CC Comments Settings','CC Comments','manage_options','cc-comments-plugin','cc_option_page');
}add_action('admin_menu','cc_plugin_menu');
I think I had my add_action('admin_menu', 'cc_plugin_menu'); 我想我有了add_action('admin_menu','cc_plugin_menu'); in the wrong spot. 在错误的位置。 I moved it into the cc_plugin_menu function and it seems to save OK now. 我将其移至cc_plugin_menu函数中,现在看来可以保存。
Here's the updated code: 这是更新的代码:
add_action('admin_menu', 'cc_plugin_menu');
function register_mysettings() {
register_setting( 'cc_options', 'cc_cc_email' );
}
function cc_option_page() {
?>
<div class="wrap">
<h2>CC Comments Options</h2>
<p>Welcome to the CC comments plugin. here you can edit the email(s) to CC your comments to.</p>
<form method="post" action="options.php" id="cc-comments-email-options-form">
<?php settings_fields( 'cc_options' ); ?>
<?php do_settings_sections( 'cc_options' ); ?>
<h3><label for="cc_cc_email">Eamil to send CC to:</label>
<input type="text" id="cc_cc_email" name="cc_cc_email"
value="<?php echo esc_attr(get_option('cc_cc_email')); ?>" /></h3>
<p><input type="submit" name="submit" value="Save Email" /></p>
</form>
</div>
<?php
}
function cc_plugin_menu(){
add_options_page('CC Comments Settings','CC Comments','manage_options','cc-comments-plugin','cc_option_page');
add_action( 'admin_init', 'register_mysettings' );
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.