Skip to:
Content
Pages
Categories
Search
Top
Bottom

Notify user when a reply goes into moderation


  • Chuckie
    Participant

    @ajtruckle

    I had a look at the code in 2.6.1.

    Lines 618 – 622 in functions.php in replies folder:

    /** Reply Bad Words *******************************************************/
    
    if ( ! bbp_check_for_moderation( $anonymous_data, $reply_author, $reply_title, $reply_content, true ) ) {
    	bbp_add_error( 'bbp_reply_moderation', __( '<strong>ERROR</strong>: Your reply cannot be edited at this time.', 'bbpress' ) );
    }

    Notice that it makes use of the bbp_add_error call to notify the user? Well, look at lines 624 – 636:

    /** Reply Status **********************************************************/

    // Maybe put into moderation
    if ( ! bbp_check_for_moderation( $anonymous_data, $reply_author, $reply_title, $reply_content ) ) {
    
    	// Set post status to pending if public
    	if ( bbp_get_public_status_id() === $reply->post_status ) {
    		$reply_status = bbp_get_pending_status_id();
    	}
    
    // Use existing post_status
    } else {
    	$reply_status = $reply->post_status;
    }

    There does not appear to be any code to flag the user. Either way, if a “reply” is flagged as pending (for example, I insert 3 images) it just vanishes with no feedback to the user. This also happens here in this forum.

    I confess I don’t know the code enough and could be barking up the wrong tree.

Viewing 15 replies - 26 through 40 (of 40 total)

  • Robin W
    Moderator

    @robin-w

    @clivesmith just tried an anonymous post using

    //add message if reply help in moderation
    add_filter ('bbp_new_reply_redirect_to' , 'rew_pending_check', 10 , 3) ;
    
    function rew_pending_check  ($reply_url, $redirect_to, $reply_id) {
    	$status = get_post_status ($reply_id) ;
    	if ($status == 'pending' ) {
    		$reply_url = '/moderation/' ;
    	}
    return $reply_url ;
    }

    and it does redirect to the moderation page – can you recheck yours please ?


    Clivesmith
    Participant

    @clivesmith

    I have tried it on my live site but I still just get the same as before, I will leave it there if you would like to try


    Robin W
    Moderator

    @robin-w

    thanks


    Robin W
    Moderator

    @robin-w

    ah, I think you have a moderation plugin as you moderate all repiles – yes?


    Clivesmith
    Participant

    @clivesmith

    yes I have bbress moderation tools by digital arm


    Robin W
    Moderator

    @robin-w

    ok, let’s try upping the priority as that plugin updates the url, so change

    add_filter ('bbp_new_reply_redirect_to' , 'rew_pending_check', 10 , 3) ;

    to

    add_filter ('bbp_new_reply_redirect_to' , 'rew_pending_check', 30 , 3) ;


    Clivesmith
    Participant

    @clivesmith

    That’s it, great thank you.


    Robin W
    Moderator

    @robin-w

    good, I may improve it later!


    Chuckie
    Participant

    @ajtruckle

    Is it possible for someone to show a short video of this in action? Thanks.


    Robin W
    Moderator

    @robin-w

    @clivesmith try this and you can add [mod-return] shortcode to your moderation page that gives a return to topic link

    //add message if reply help in moderation
    add_filter ('bbp_new_reply_redirect_to' , 'rew_pending_check', 30 , 3) ;
    
    function rew_pending_check  ($reply_url, $redirect_to, $reply_id) {
    	$status = get_post_status ($reply_id) ;
    	$topic_id = bbp_get_reply_topic_id( $reply_id );
    	if ($status == 'pending' ) {
    		$reply_url = '/moderation/?moderation_pending='.$topic_id ;
    	}
    return $reply_url ;
    }
    
    add_shortcode ('mod-return' , 'mod_return' ) ;
    
    function mod_return () {
    	if (!empty($_REQUEST['moderation_pending'] )) {
    	$topic_url         = get_permalink( $_REQUEST['moderation_pending'] );
    	echo '<div class="mod-return"><a href= "'.$topic_url,'">Return to topic</a></div>';
    	}	
    }

    Robin W
    Moderator

    @robin-w

    @ajtruckle Most of the code I did is probably redundant as I think digital arms moderation tools does it

    But the code for Clive immediately above notifies the user that their reply is in moderation.

    so

    1. create a WordPress page with a permalink of ‘/moderation/’
    2. put whatever message you want in there eg ‘your reply is being held in moderation’
    3. if you want you can also put the shortcode [mod-return] in the page as well which will post a return link to the topic
    4. add the code above to functions file or code snippets
    5. when a user (logged in or anonymous if you allow that) posts a reply that goes into moderation, they are directed to your moderation page, so get certainty that their post is being held in moderation, with a link back to their topic if you’ve added the shortcode


    Clivesmith
    Participant

    @clivesmith

    Brilliant !! thank you, works perfectly 🙂 🙂


    Robin W
    Moderator

    @robin-w

    🙂

    Hi All, I posted this on the trac ticket too, in case others are interested:

    I’ve taken a slightly different approach to Robin, for me I only have logged in users on my forums, and I want to show the pending reply with a warning so the user knows it’s pending but exists. The below will show pending replies to the author who wrote them and a warning to the author that the reply is pending, as well as adding a warning specific to moderators so they clearly know to moderate it.

    Hope it helps someone!

    /**
     * Modifies the SQL query for reply loops so that reply authors can view their own replies that are still pending
     * @param $where string
     * @param $wp_query WP_Query
     * @return string
     */
    function bbp_allow_members_pending_view( $where, $wp_query ){
    	global $wpdb;
    	$type = $wp_query->query_vars['post_type'];
    	if( $type == bbp_get_reply_post_type() && !current_user_can('moderate') && is_user_logged_in() ){
    		// check reply here
    		$user_id = get_current_user_id();
    		$find = "{$wpdb->prefix}posts.post_author = $user_id AND {$wpdb->prefix}posts.post_status = 'private'";
    		$replace = $find . $wpdb->prepare(" OR {$wpdb->prefix}posts.post_author = %d AND {$wpdb->prefix}posts.post_status = %s", $user_id, bbp_get_pending_status_id());
    		$where = str_replace( $find, $replace, $where );
    	}
    	return $where;
    }
    add_action('posts_where', 'bbp_allow_members_pending_view', 10, 2);
    
    /**
     * Shows a warning above pending replies, different warning for mods and the author.
     */
    function my_bbp_allow_members_pending_view_warning(){
    	if( bbp_get_reply_status() == bbp_get_pending_status_id() ){
    		if( current_user_can('moderate') ){
    			$warning = 'This reply is pending moderation, approve so others can see it or trash it!';
    		}elseif( bbp_get_reply_author_id() == get_current_user_id() ){
    			$warning = 'This reply is pending moderation, others will see it once a moderator approves it.';
    		}
    		if( !empty($warning) ){
    			echo '<div class="bbp-template-notice notice"><ul><li>'.$warning.'</li></ul></div>';
    		}
    	}
    }
    add_action( 'bbp_theme_before_reply_content', 'my_bbp_allow_members_pending_view_warning');

    Chuckie
    Participant

    @ajtruckle

    Thanks for your code. It has been so long now when I asked this that i am reluctant to start fiddling with my setup.

    I prefer to continue to wait until such a time and bbPress is updated rather than add bits of code to my functions file.

    At the moment what I have works for me due to the bsp settings that were added some time back.

    Thank you for the code though.

Viewing 15 replies - 26 through 40 (of 40 total)
  • You must be logged in to reply to this topic.
Skip to toolbar