如果像这样连接到管理菜单:
function adminmenu_users_reserves(){
add_users_page(\'Reserver\', \'Reserver\', \'read\', \'reserve_list\', \'show_userlist\');
}
add_action( \'admin_menu\', \'adminmenu_users_reserves\' );
并且有一个功能
function show_userlist(show_reserves = true, $title) {
code...
}
我可以传递变量吗
$show_reserves
从…起
add_users_page()
以某种方式(有一次我需要
$show_reserves
如果是真的,那么我需要它是假的)
还是我必须用两种不同的函数来解决我的问题?(用于几乎相同的功能)
function adminmenu_users_reserves(){
add_users_page(\'Reserves\', \'Reserves\', \'read\', \'reserve_list\', \'show_reservelist\');
}
add_action( \'admin_menu\', \'adminmenu_users_reserves\' );
function adminmenu_users_registered(){
add_users_page(\'Registered\', \'Registered\', \'read\', \'registered_list\', \'show_registeredlist\');
}
add_action( \'admin_menu\', \'adminmenu_users_registered\' );
UPDATE因为托肖给了我一个很好的答案(
https://wordpress.stackexchange.com/users/73/toscho) 我想分享我的解决方案-如果其他人将来也有同样的问题:
class userList
{
public $show_reserves = false;
public $title = \'Reserver\';
//Show a list of all reserves/or registered users in the system ordered by register-date
function render() {
$reserves = $this->show_reserves;
$title = $this->title;
echo $title;
if ($reserves === true) {
....code...
}
}
}
function adminmenu_users_reserves(){
$userlist = new userList();
add_users_page(\'Reserver\', \'Reserver\', \'read\', \'reserve_list\', array( $userlist, \'render\' ));
}
add_action( \'admin_menu\', \'adminmenu_users_reserves\' );
function adminmenu_users_registered(){
$userlist = new userList();
$userlist->show_reserves = false;
$userlist->title = \'Anmälda\';
add_users_page(\'Anmälda\', \'Anmälda\', \'read\', \'registered_list\', array( $userlist, \'render\' ));
}
add_action( \'admin_menu\', \'adminmenu_users_registered\' );