好吧,我真的被困在这个问题上了。我尝试了很多事情,但都没有成功。
我已安装并运行BBpress,希望禁止用户(参与者角色)发布主题。每次用户添加主题时,它必须显示在挂起状态下,但他们可以发布回复而无需任何调节。
我试过了BBpress Moderation
插件,但其添加回复处于挂起状态。即使在取消选中框后Always moderate replies
.
我尝试将参与者用户的角色更改为导师:
//code to add tutor role
function add_new_roles( $bbp_roles )
{
/* Add a role called tutor */
$bbp_roles[\'bbp_tutor\'] = array(
\'name\' => \'Tutor\',
\'capabilities\' => custom_capabilities( \'bbp_tutor\' )
);
return $bbp_roles;
}
add_filter( \'bbp_get_dynamic_roles\', \'add_new_roles\', 1 );
function add_role_caps_filter( $caps, $role )
{
/* Only filter for roles we are interested in! */
if( $role == \'bbp_tutor\' )
$caps = custom_capabilities( $role );
return $caps;
}
add_filter( \'bbp_get_caps_for_role\', \'add_role_caps_filter\', 10, 2 );
function custom_capabilities( $role )
{
switch ( $role )
{
/* Capabilities for \'tutor\' role */
case \'bbp_tutor\':
return array(
// Primary caps
\'spectate\' => true,
\'participate\' => true,
\'moderate\' => false,
\'throttle\' => false,
\'view_trash\' => false,
// Forum caps
\'publish_forums\' => false,
\'edit_forums\' => false,
\'edit_others_forums\' => false,
\'delete_forums\' => false,
\'delete_others_forums\' => false,
\'read_private_forums\' => true,
\'read_hidden_forums\' => false,
// Topic caps
\'publish_topics\' => true,
\'edit_topics\' => true,
\'edit_others_topics\' => false,
\'delete_topics\' => false,
\'delete_others_topics\' => false,
\'read_private_topics\' => true,
// Reply caps
\'publish_replies\' => true,
\'edit_replies\' => true,
\'edit_others_replies\' => false,
\'delete_replies\' => false,
\'delete_others_replies\' => false,
\'read_private_replies\' => true,
// Topic tag caps
\'manage_topic_tags\' => false,
\'edit_topic_tags\' => false,
\'delete_topic_tags\' => false,
\'assign_topic_tags\' => true,
);
break;
default :
return $role;
}
}
但在用户配置文件页面中选择论坛角色导师后,显示空白角色。
是否有任何方法可以在默认情况下将这些主题添加到挂起状态并在发布中添加答复?请帮帮我!
非常感谢。
最合适的回答,由SO网友:Ramesh Pardhi 整理而成
好的,我有一个快速的解决方案。
我启用插件BBpress Moderation 并在中更改以下代码/wp-content/plugins/bbpressmoderation/bbpressmoderation.php
FROM:
/**
* Before inserting a new topic/reply mark
* this as \'pending\' depending on settings
*
* @param array $data - new topic/reply data
*/
function pre_insert($data) {
global $wpdb;
if (@$data[\'post_status\']==\'spam\') return $data; // fix for 1.8.2 hide spam
// Pointless moderating a post that the current user can approve
if (current_user_can(\'moderate\')) return $data;
if ($data[\'post_author\'] == 0) {
// Anon user - check if need to moderate
if ( ( \'topic\' == $data[\'post_type\'] && get_option(self::TD . \'always_approve_topics\') ) || ( \'reply\' == $data[\'post_type\'] && get_option(self::TD . \'always_approve_replies\') ) ) {
// fix for v.1.8.3 separate settings for anonymous posting
$data[\'post_status\'] = \'pending\';
}
} else {
// Registered user
if (get_option(self::TD . \'previously_approved\')) {
// Check if user already published
$sql = $wpdb->prepare("SELECT COUNT(*) FROM {$wpdb->posts} WHERE post_author = %d AND post_type IN (\'topic\',\'reply\') AND post_status = \'publish\'", $data[\'post_author\']);
$count = $wpdb->get_var($sql);
if (!$count) {
// Anon or User never published topic/reply so mark as pending.
$data[\'post_status\'] = \'pending\';
}
} else {
$data[\'post_status\'] = \'pending\';
}
}
return $data;
}
TO:
/**
* Before inserting a new topic/reply mark
* this as \'pending\' depending on settings
*
* @param array $data - new topic/reply data
*/
function pre_insert($data) {
global $wpdb;
if (@$data[\'post_status\']==\'spam\') return $data; // fix for 1.8.2 hide spam
if(\'reply\' !== $data[\'post_type\']){
// Pointless moderating a post that the current user can approve
if (current_user_can(\'moderate\')) return $data;
if ($data[\'post_author\'] == 0) {
// Anon user - check if need to moderate
if ( ( \'topic\' == $data[\'post_type\'] && get_option(self::TD . \'always_approve_topics\') ) || ( \'reply\' == $data[\'post_type\'] && get_option(self::TD . \'always_approve_replies\') ) ) {
// fix for v.1.8.3 separate settings for anonymous posting
$data[\'post_status\'] = \'pending\';
}
} else {
// Registered user
if (get_option(self::TD . \'previously_approved\')) {
// Check if user already published
$sql = $wpdb->prepare("SELECT COUNT(*) FROM {$wpdb->posts} WHERE post_author = %d AND post_type IN (\'topic\',\'reply\') AND post_status = \'publish\'", $data[\'post_author\']);
$count = $wpdb->get_var($sql);
if (!$count) {
// Anon or User never published topic/reply so mark as pending.
$data[\'post_status\'] = \'pending\';
}
} else {
$data[\'post_status\'] = \'pending\';
}
}
}
return $data;
}
现在,这允许用户发布回复,而无需对其进行调整,但主题在发布之前必须进行调整。
我希望这能帮助别人。