跳到:
内容
类别
搜索
顶部
底部

自定义功能

Codex主页自定义功能

虽然bbPress提供了一套很好的论坛角色,具有独特的功能,但您可能需要修改这些角色或添加新名称。

然而,如果要执行此操作的代码位于子主题(或父主题!)的functions.php文件中,则WordPress和bbPress的最新组合不起作用。

如果你把这个代码放在一个插件中,它似乎工作得很好。

如果您习惯于更改文件并将其FTPing到您的站点,请访问bbpress角色添加器–Robin W的网站(rewweb.co.uk)对于应该工作的插件和模板

添加新名称

在最简单的级别上,您可以添加新角色名称并为其提供现有功能

这只对您自己的管理有用,但如果您像我一样讨厌“keymaster”角色名称,只需创建一个新角色并为其提供keymaster功能即可。

下面的代码创建了三个名为“name 1”、“name 2”和“name 3”的新角色,第一个角色有参与者、第二个主持人和第三个密钥管理员。

只需修改代码即可创建尽可能多的角色,并具有所需的任何功能

add_action('wp_loaded','load_new_roles');
函数load_new_roles()
{
添加过滤器('bbp_get_dynamic_roles','add_custom_role',1);
}

函数add_custom_role($bbp_roles)
{

$bbp_roles['my_custom_role1']=数组(
“name”=>“name 1”,
“功能”=>bbp_get_caps_for_role(bbp_get_participant_role)//与参与者的功能相同
);
$bbp_roles['my_custom_role2']=数组(
“name”=>“name 2”,
“功能”=>bbp_get_caps_for_role(bbp_get_participant_role)//与参与者的功能相同
);
$bbp_roles['my_custom_role3']=数组(
“name”=>“name 3”,
“功能”=>bbp_get_caps_for_role(bbp_get_keymaster_role)//与keymaster相同的功能
);
返回$bbp_roles;
}

创建新角色

如果要添加具有特定功能的新角色,则可以添加以下内容

下面的代码添加了一个名为“tutor”的角色,只需将单词tutor更改为您想要的名称,并决定您希望该角色具有哪些功能。

//添加导师角色的代码add_action('wp_loaded','load_new_roles');函数load_new_roles(){add_filter('bbp_get_dynamic_roles','添加新角色',1);添加过滤器('bbp_get_caps_for_role','add_role_caps_filter',10,2);}函数add_new_roles($bbp_roles){/*添加名为tutor的角色*/$bbp_roles['bbp_tutor']=数组(“name”=>“Totor”,“功能”=>custom_capabilities(“bbp_tutor”));返回$bbp_roles;}函数add_role_caps_filter($caps,$role){/*只筛选我们感兴趣的角色*/if($role=='bbp_tutor')$caps=自定义能力($role);返回$caps;}函数custom_capabilities($role){交换机($role){/*“导师”角色的能力*/案例“bbp_tutor”:返回数组(//主要盖子“spectate”=>正确,“参与”=>true,“中等”=>假,“油门”=>假,“view_trash”=>错误,//论坛上限“publish_forums”=>假,“edit_forums”=>假,“edit_others_forums”=>错误,“delete_forums”=>false,“delete_others_forums”=>错误,“read_private_forums”=>true,“read_hidden_forums”=>false,//主题大写“publish_topics”=>true,“edit_topics”=>true,'edit_others_topics'=>错误,“delete_topics”=>false,“delete_others_topics”=>false,“read_private_topics”=>true,//回复大写“publish_replys”=>真,“edit_replies”=>真,“edit_others_replies”=>错误,“delete_replies”=>false,“delete_others_replies”=>错误,“read_private_replys”=>真,//主题标记大写“manage_topic_tags”=>错误,“edit_topic_tags”=>假,“delete_topic_tags”=>假,“assign_topic_tags”=>true,);断裂;违约:return$role;}}

下面的代码添加了两个角色,导师和学生。使用此功能,您应该能够添加任意数量的角色

add_action('wp_loaded','load_new_roles');函数load_new_roles(){add_filter('bbp_get_dynamic_roles','添加新角色',1);添加过滤器('bbp_get_caps_for_role','add_role_caps_filter',10,2);}函数add_new_roles($bbp_roles){/*添加名为tutor的角色*/$bbp_roles['bbp_tutor']=数组(“name”=“gt;”导师',“功能”=>自定义功能(“bbp_tutor”));/*添加名为学生的角色*/$bbp_roles['bbp_pupil']=数组(“name”=“gt;”小学生',“功能”=>自定义功能('bbp_phoild'));返回$bbp_roles;}函数add_role_caps_filter($caps,$role){/*只筛选我们感兴趣的角色*/if($role=='bbp_tutor')$caps=自定义能力($role);if($role=='bbp_phoild')$caps=自定义功能($role);返回$caps;}函数custom_capabilities($role){交换机($role){/*“导师”角色的能力*/案例“bbp_tutoriar”:返回数组(//主要盖子“旁观者”=>是的,“参与”=>是的,“中等”=>错误,“油门”=>错误,“view_trash”=>错误,//论坛上限“publish_forums”=>错误,“编辑论坛”=>错误,'edit_others_forums'=>错误,'删除论坛'=>错误,“delete_others_forums”=>错误,'read_private_forums'=>是的,“read_hidden_forums”=>false,//主题大写“publish_topics”=>true,“edit_topics”=>true,“edit_others_topics”=>false,“delete_topics”=>false,“delete_others_topics”=>false,“read_private_topics”=>true,//回复大写“publish_replies”=>true,“edit_replys”=>真,“edit_others_replies”=>错误,“delete_replies”=>false,“delete_others_replies”=>错误,“read_private_replies”=>true,//主题标记大写“manage_topic_tags”=>错误,“edit_topic_tags”=>假,“delete_topic_tags”=>假,“assign_topic_tags”=>true,);/*“学生”角色的能力*/案例“bbp_phoild”:返回数组(//主要盖子“spectate”=>正确,“参与”=>true,“中等”=>假,“油门”=>假,“view_trash”=>错误,//论坛上限“publish_forums”=>假,“edit_forums”=>假,“edit_others_forums”=>错误,“delete_forums”=>false,“delete_others_forums”=>错误,“read_private_forums”=>true,“read_hidden_forums”=>false,//主题大写“publish_topics”=>true,“edit_topics”=>true,“edit_others_topics”=>false,“delete_topics”=>false,“delete_others_topics”=>false,“read_private_topics”=>true,//回复大写“publish_replies”=>true,“edit_replies”=>真,“edit_others_replies”=>错误,“delete_replys”=>错误,“delete_others_replies”=>错误,“read_private_replies”=>true,//主题标记大写“manage_topic_tags”=>错误,'edit_topic_tags'=>错误,“delete_topic_tags”=>假,“assign_topic_tags”=>true,);断裂;违约:return$role;}}
跳到工具栏