1

OK, I am really stuck on this. I tried many things and yet nothing works.

I have BBpress install and running and want to disallow users(Participant Role) from publishing TOPICS. Every time when user add the topic, it must have to display under pending status but they can publish replies without any moderation.

I tried BBpress Moderation plugin but its adding replies in pending status. Even after unchecking the box which says Always moderate replies.

I Tried to change the role of Participant users to Tutor:

//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;
    }
}

But It shows blank role after selecting Forum Role TUTOR in user profile page.

Is there any way to add these topics by default in Pending status and Replies in Publish? Please help me!

Thank You

0

OK I got a quick Solution.

I enable the plugin BBpress Moderation and change the following code in /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;
}

Now this allows users to publish reply without getting it moderate, but Topics must have to moderate before they becomes publish.

I hope this will help someone.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.