我正在使用WordPress插件, 但是我一直在获取错误:未找到选项页面。尝试保存更改时出错。这是我的设置的页面代码:https://pastebin.com/AsfcqHhe
我已经尝试了很多修复程序, 但都无济于事。
#1【WordPress错误(找不到选项页面)】你订购字段和部分的方式有误, 请参见下面经过测试的代码并作为独立插件工作。在你这边进行测试, 然后如果可行, 请在你的主插件逻辑中实施。
<
?php/**
* Plugin Name: Example Settings
* Description: Example Settings
* Version: 1.0
**/class Member_Only {
/* Create blank array */
public function __construct() {
//$this = [];
// Hook into the admin menu
add_action( 'admin_menu', array( $this, 'settings_page' ) );
add_action( 'admin_init', array( $this, 'setup_init' ) );
}
public function settings_page() {
//Create the menu item and page
$parent_slug = "member_only_fields";
$page_title = "Member Only Content Settings Page";
$menu_title = "Member Only Content";
$capability = "manage_options";
$slug = "member_only_fields";
$callback = array( $this, 'settings_page_content' );
add_submenu_page( "options-general.php", $page_title, $menu_title, $capability, $slug, $callback );
}
/* Create the page*/
public function settings_page_content() { ?>
<
div class="wrap">
<
h2>
Member Only Content <
/h2>
<
form method="post" action="options.php">
<
?php
settings_fields("member_only_fields");
do_settings_sections("member_only_fields");
submit_button();
?>
<
/form>
<
?php }
/* Setup section_callback */
public function section_callback( $arguments ) {
/* Set up input*/
switch( $arguments['id'] ){
case "categories" :
echo "Categories that will trigger the member only message.";
break;
case "loginURL":
echo "The login URL of your site. ";
break;
}
}
public function setup_init() {
register_setting("member_only_fields", "categories");
add_settings_section("categories", "Member Only Categories: ", array($this, 'section_callback'), "member_only_fields");
add_settings_field( 'categories', 'Categories: ', array( $this, 'field_callback' ), 'member_only_fields', 'categories' );
add_settings_section("loginURL", "Login URL: ", array($this, 'section_callback'), "member_only_fields");
}
/* Create input fields*/
public function field_callback ( $arguments ) {
echo "<
input name=\"categories\" id=\"categories\" type=\"text\" value=http://www.srcmini.com/"" .get_option("categories"). "\"\>
";
}
}new Member_Only();
推荐阅读
- WordPress失败-我的主题登录(注销)
- WordPress ENV/WP_HOME/WP_SITE_URL
- 插件和主题的WordPress目录权限
- WordPress在一页上显示所有页面
- #导入Word文档图片# Linux下文件目录权限操作
- SpringBoot整合SpringSecurity
- 持续集成CI/CD之CD的完整版最佳实践
- php手册String函数(解析)
- shell脚本系列---如何创建shell脚本,并执行常用的命令