添加角色和功能时,只需运行一次代码,因为使用时角色和功能会保存到数据库中add_role
或->add_cap
就像Andy说的那样after_setup_theme
对于此类操作,请添加某种检查,使其只运行一次,如register_activation_hook 或使用选项:
add_action(\'after_setup_theme\',\'my_add_role_function\');
function my_add_role_function(){
$roles_set = get_option(\'my_roles_are_set\');
if(!$roles_set){
add_role(\'my_role\', \'my_roleUser\', array(
\'read\' => true, // True allows that capability, False specifically removes it.
\'edit_posts\' => true,
\'delete_posts\' => true,
\'upload_files\' => true
));
update_option(\'my_roles_are_set\',true);
}
}