web-dev-qa-db-fra.com

Comment interdire aux participants de publier des sujets (bbpress)?

OK, je suis vraiment coincé sur ça. J'ai essayé beaucoup de choses et pourtant rien ne fonctionne.

J'ai installé et exécuté BBpress et je souhaite interdire aux utilisateurs (rôle de participant) de publier TOPICS. Chaque fois que l'utilisateur ajoute le sujet, il doit obligatoirement s'afficher sous le statut En attente, mais il peut publier les réponses sans aucune modération.

J'ai essayé le plugin BBpress Moderation mais l'ajout de réponses dans l'état en attente. Même après avoir décoché la case qui dit Always moderate replies.

J'ai essayé de changer le rôle des utilisateurs participants en tuteur:

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

Mais il affiche un rôle vide après avoir sélectionné Forum Role TUTOR dans la page de profil de l'utilisateur.

Existe-t-il un moyen d'ajouter ces sujets par défaut dans Statut en attente et Réponses dans Publier? Aidez-moi, s'il vous plaît!

Je vous remercie

1
Ramesh Pardhi

OK j'ai une solution rapide.

J'active le plugin BBpress Moderation et change le code suivant dans /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;
}

À:

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

Cela permet maintenant aux utilisateurs de publier une réponse sans la modérer, mais les sujets doivent être modérés avant de devenir publiés.

J'espère que cela aidera quelqu'un.

0
Ramesh Pardhi