我想我的插件重定向到一个页面时,一些条件不符合插件激活后。我一直在To many redirects...
错误消息。
我的代码如下所示:
if (! defined(\'WPINC\')) die;
if (! class_exists(\'AwesomePlugin\')) {
class AwesomePlugin {
public function __construct(){
//Register admin menus
add_action(\'admin_menu\', [$this, add_menu]);
//Init plugin
add_action(\'admin_init\', [$this, \'init_plugin\']);
}
/**
*
* Init plugin
*/
public function init_plugin(){
if(!isset(get_option("some_option"))){
wp_redirect("admin.php?page=some-page"); exit; //This gives too many redirects
}
wp_redirect(\'admin.php?page=dashboard\'); exit;
}
/**
* Add menu and submenu items
*/
public function add_menu(){
add_menu_page(
\'Dashboard\', \'Dashboard\', \'manage_options\', \'dashboard\',
[__CLASS__, \'load_dashboard_view\'],
plugins_url(\'logo.png\', __FILE__)
);
add_submenu_page(
\'\', \'Signup page\', \'Signup page\', \'manage_options\',
\'sign-up\', [__CLASS__, \'load_signup_view\']
);
}
/**
* Dashboard page
*/
public function load_dashboard_view(){
include(plugin_dir_path(__FILE__) . \'dashboard.php\');
}
/**
* Signup page
*/
public function load_signup_view(){
include(plugin_dir_path(__FILE__) . \'signup.php\');
}
}
AwesomePlugin()
}
我错过了什么?
EDIT: 我知道无论我加载的页面是什么init_plugin
功能持续启动。因此,它会不断将用户重定向到sign-up
, 因此many redirect
错误消息。如何解决此问题?