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 25 replies - 1 through 25 (of 40 total)

  • Clivesmith
    Participant

    @clivesmith

    I have seen that users (all guests) do not get any indication what happened to their post (all go to moderation). If it is blocked a message is shown, if it is OK all they get is the form going blank.
    this was happening before the update to 2.6.0. I have not updated yet as on my development site I still cannot see sub forums.


    John James Jacoby
    Keymaster

    @johnjamesjacoby

    Pending content is a funny thing.

    If you tell someone why it’s pending, they’ll post again to try and skirt the filter.

    If you tell them nothing, they’ll post again thinking something is wrong.

    If we can come up with some verbiage, that’s step one.

    Step 2, is where to redirect them. If a topic is pending, you can’t really show them their own pending topic, because it’s not visible to them, at least not the way bbPress works currently.


    Chuckie
    Participant

    @ajtruckle

    If I create a topic, not a reply, and it goes to moderation, I am given a message at the top of the screen saying it has gone for moderation.

    It should do exactly the same for a reply and zoom to the top of the topic to show the same message.

    It should be the same behaviour. Except this time it is saying the reply has gone to moderation.

    They are not redirected anywhere.

    I had sent you screen shots about this and my posts in your own forum vanished. They must be in your own pending list.

    See?


    Chuckie
    Participant

    @ajtruckle

    In the template.php file it has the following code:

    	// Get the topic status
    	switch ( $topic_status ) {
    
    		// Spam notice
    		case bbp_get_spam_status_id() :
    			$notice_text = esc_html__( 'This topic is marked as spam.', 'bbpress' );
    			break;
    
    		// Trashed notice
    		case bbp_get_trash_status_id() :
    			$notice_text = esc_html__( 'This topic is in the trash.', 'bbpress' );
    			break;
    
    		// Pending notice
    		case bbp_get_pending_status_id() :
    			$notice_text = esc_html__( 'This topic is pending moderation.', 'bbpress' );
    			break;
    
    		// Standard status
    		default :
    			$notice_text = '';
    			break;
    	}

    As you can see, it has specific notices for feedback to the user.

    The above work when it is a “topic” they are creating. What we now need is exactly the same code, but for “replies”. In addition though, this warning needs to be placed just above the empty editor and just after the previous reply.

    It is this code that is lacking for replies. So IMHO your comments don’t apply here. It is not about redirection or anything. It is about consistency with informing the user just like it does for a new topic.

    I hope this helps you in resolving this issue and thank you so much for your time in looking into this.

    The above begins on line 3029:

    /**
     * Displays topic notices
     *
     * @since 2.0.0 bbPress (r2744)
     */
    function bbp_topic_notices() {

    Chuckie
    Participant

    @ajtruckle

    I created a trac ticket here in the hopes this might get progressed more easily:

    https://bbpress.trac.wordpress.org/ticket/3284#ticket


    canvasstudio
    Participant

    @canvasstudio

    So the issue with topic going into pending, is that the topic or reply most likely has invalid formatted code. Example: User type is a URL and hit submit, it is gone. Well, no, it is pending. because https://domain.com/something is not allowed. And the app does tell the user of the error.


    cedluck
    Participant

    @cedluck

    Hi there,

    cancasstudio stated :

    So the issue with topic going into pending, is that the topic or reply most likely has invalid formatted code. Example: User type is a URL and hit submit, it is gone. Well, no, it is pending. because https://domain.com/something is not allowed. And the app does tell the user of the error.

    Is there any way we can allow people to type url in there topics/replies?


    Robin W
    Moderator

    @robin-w

    as standard people can type url’s into their topics/replies.

    The number is set in

    dashboard>settings>discussion and look for comment moderation and maybe up the number of links


    Clivesmith
    Participant

    @clivesmith

    Has this thread gone off topic?
    The problem is that when a reply is sent and it goes to moderation it does not return a message to the user saying why the user cannot see their message.
    I don’t understand where url’s come into that. If the reply is just a simple “hello” where is the url ?


    Robin W
    Moderator

    @robin-w

    I’ve had a play this evening with this issue.

    This code is very rough and ready, but if it works as I think it does, then it shows pending REPLIES to the user who posted them and moderators and keymasters. NOT topics !!

    so when a user posts a reply and it goes into moderation, they see there reply in the topic with a warning.

    If you want to try it, put this in your child theme’s function file – or use

    Code Snippets

    add_filter ('bbp_has_replies' , 'rew_has_replies' ) ;
    	
    function rew_has_replies( $args = array() ) {
    
    	/** Defaults **************************************************************/
    
    	// Other defaults
    	$default_reply_search   = bbp_sanitize_search_request( 'rs' );
    	$default_post_parent    = ( bbp_is_single_topic() ) ? bbp_get_topic_id() : 'any';
    	$default_post_type      = ( bbp_is_single_topic() && bbp_show_lead_topic() ) ? bbp_get_reply_post_type() : array( bbp_get_topic_post_type(), bbp_get_reply_post_type() );
    	$default_thread_replies = (bool) ( bbp_is_single_topic() && bbp_thread_replies() );
    
    	// Default query args
    	$default = array(
    		'post_type'              => $default_post_type,         // Only replies
    		'post_parent'            => $default_post_parent,       // Of this topic
    		'posts_per_page'         => bbp_get_replies_per_page(), // This many
    		'paged'                  => bbp_get_paged(),            // On this page
    		'orderby'                => 'date',                     // Sorted by date
    		'order'                  => 'ASC',                      // Oldest to newest
    		'hierarchical'           => $default_thread_replies,    // Hierarchical replies
    		'ignore_sticky_posts'    => true,                       // Stickies not supported
    		'update_post_term_cache' => false,                      // No terms to cache
    
    		// Conditionally prime the cache for all related posts
    		'update_post_family_cache' => true
    	);
    
    	// Only add 's' arg if searching for replies
    	// See https://bbpress.trac.wordpress.org/ticket/2607
    	if ( ! empty( $default_reply_search ) ) {
    		$default['s'] = $default_reply_search;
    	}
    
    	// What are the default allowed statuses (based on user caps)
    	if ( bbp_get_view_all( 'edit_others_replies' ) ) {
    
    		// Default view=all statuses
    		$post_statuses = array_keys( bbp_get_topic_statuses() );
    
    		// Add support for private status
    		if ( current_user_can( 'read_private_replies' ) ) {
    			$post_statuses[] = bbp_get_private_status_id();
    		}
    
    		// Join post statuses together
    		$default['post_status'] = $post_statuses;
    
    	// Lean on the 'perm' query var value of 'readable' to provide statuses
    	} else {
    		//get public and pending (not sure if we need this or just to remove the perm status that was here ?
    		$post_statuses = array_keys( rew_get_topic_statuses() );
    	}
    
    	/** Setup *****************************************************************/
    
    	// Parse arguments against default values
    	$r = bbp_parse_args( $args, $default, 'has_replies' );
    
    	// Set posts_per_page value if replies are threaded
    	$replies_per_page = (int) $r['posts_per_page'];
    	if ( true === $r['hierarchical'] ) {
    		$r['posts_per_page'] = -1;
    	}
    
    	// Get bbPress
    	$bbp = bbpress();
    	
    	//now filter the query before execution
    	
    	// Add filter if participant
    	$user_id = get_current_user_id() ;
    	$role = bbp_get_user_role( $user_id );
    	if ($role == 'bbp_participant'  || $role == 'bbp_moderator' || bbp_is_user_keymaster($user_id)) { 
    		add_filter( 'posts_where', 'rew_where' );
    	}
    
    	// Call the query
    	$bbp->reply_query = new WP_Query( $r );
    	
    	
    		// Remove filter
    	if ($role == 'bbp_participant'  || $role == 'bbp_moderator' || bbp_is_user_keymaster($user_id)) { 
    		remove_filter( 'posts_where', 'rew_where' );
    	}
    	
    	// Maybe prime the post author caches
    	if ( ! empty( $r['update_post_family_cache'] ) ) {
    		bbp_update_post_family_caches( $bbp->reply_query->posts );
    	}
    
    	// Add pagination values to query object
    	$bbp->reply_query->posts_per_page = (int) $replies_per_page;
    	$bbp->reply_query->paged          = (int) $r['paged'];
    
    	// Never home, regardless of what parse_query says
    	$bbp->reply_query->is_home        = false;
    
    	// Reset is_single if single topic
    	if ( bbp_is_single_topic() ) {
    		$bbp->reply_query->is_single = true;
    	}
    
    	// Only add reply to if query returned results
    	if ( ! empty( $bbp->reply_query->found_posts ) ) {
    
    		// Get reply to for each reply
    		foreach ( $bbp->reply_query->posts as &$post ) {
    
    			// Check for reply post type
    			if ( bbp_get_reply_post_type() === $post->post_type ) {
    				$reply_to = bbp_get_reply_to( $post->ID );
    
    				// Make sure it's a reply to a reply
    				if ( empty( $reply_to ) || ( bbp_get_reply_topic_id( $post->ID ) === $reply_to ) ) {
    					$reply_to = 0;
    				}
    
    				// Add reply_to to the post object so we can walk it later
    				$post->reply_to = $reply_to;
    			}
    		}
    	}
    
    	// Only add pagination if query returned results
    	if ( ! empty( $bbp->reply_query->found_posts ) && ! empty( $bbp->reply_query->posts_per_page ) ) {
    
    		// Figure out total pages
    		if ( true === $r['hierarchical'] ) {
    			$walker      = new BBP_Walker_Reply();
    			$total_pages = ceil( $walker->get_number_of_root_elements( $bbp->reply_query->posts ) / $bbp->reply_query->posts_per_page );
    		} else {
    
    			// Total for pagination boundaries
    			$total_pages = ( $bbp->reply_query->posts_per_page === $bbp->reply_query->found_posts )
    				? 1
    				: ceil( $bbp->reply_query->found_posts / $bbp->reply_query->posts_per_page );
    
    			// Pagination settings with filter
    			$bbp_replies_pagination = apply_filters( 'bbp_replies_pagination', array(
    				'base'    => bbp_get_replies_pagination_base( bbp_get_topic_id() ),
    				'total'   => $total_pages,
    				'current' => $bbp->reply_query->paged
    			) );
    
    			// Add pagination to query object
    			$bbp->reply_query->pagination_links = bbp_paginate_links( $bbp_replies_pagination );
    		}
    	}
    
    	// Filter & return
    	return apply_filters( 'rew_has_replies', $bbp->reply_query->have_posts(), $bbp->reply_query );
    }
    
    function rew_get_topic_statuses( $topic_id = 0 ) {
    
    	// Filter & return
    	return (array) apply_filters( 'bbp_get_topic_statuses', array(
    		bbp_get_public_status_id()  => _x( 'Open',    'Open the topic',      'bbpress' ),
    		), $topic_id );
    }
    
    function rew_where( $where ) {
    	$user_id = get_current_user_id() ;
        global $wpdb;
    	$posts = $wpdb->posts ;
        return $where . " OR ( 
                 ".$posts.".post_author = ".$user_id."
            AND  ".$posts.".post_status = 'pending'
    		                 
        ) ";
    }
    
    add_action ('bbp_theme_before_reply_content' , 'rew_pending' );
    
    function rew_pending () {
    	$id = bbp_get_reply_id() ;
    	$status = get_post_status ($id) ;
    	if ($status == 'pending' ) {
    	echo '<i><b>This reply is pending review and can only be seen by you and the administrators</b></i>' ;
    	}
    	
    }

    Clivesmith
    Participant

    @clivesmith

    Hi Robin,

    Should this work for guests posters as well as members ?

    Clive


    Robin W
    Moderator

    @robin-w

    just participants in this version – much work still to do !


    Clivesmith
    Participant

    @clivesmith

    OK thanks.


    Robin W
    Moderator

    @robin-w

    @clivesmith – had a think about guest posters – we can’t show the post, as by definition they are not logged in, so unless you show all moderation replies to all users (which defeats the purpose of moderation 🙂 ) they won’t see the post.

    bbpress doesn’t have the functionality that chuckie shows for topics above.

    I’ll try and see if I can work some code as I dig further into this, but no promises 🙂


    Robin W
    Moderator

    @robin-w

    just had a thought

    create a WordPress page with a permalink of ‘/moderation’ and in that put some text say

    ‘your post is being held pending moderation’

    tehn put this in your child theme’s function file – or use

    Code Snippets

    //add message if reply held 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 ;
    }

    not perfect by any means, but better than the nothing they now get

    If you could test for me, I’ll see if I can improve how it works


    Chuckie
    Participant

    @ajtruckle

    @robin-w Thanks. I don’t have time to test myself right now.

    I wonder why the authors are not responding again to again of these issues? After all they are the developers and it seems like one big huge leap with this version and then it appears nothing? I thought there were several authors of bbpress? It seems unfair that 99% of the user support is coming from you. What a strain on you!

    Thanks though!


    Robin W
    Moderator

    @robin-w

    authors are working on stuff – they chat on slack most days – they were discussing topic counts yesterday. But they have day jobs, and writing and testing fixes when your plugin is affecting 300,000 users takes a lot of time and careful thought.

    I do this totally voluntarily, so strain is entirely self inflicted 🙂 But thanks that you are thinking of me, cheers me up !

    It would be good to get some feedback on the code, but I’m chugging on looking at it as a side project whilst I wait clients coming back on paid projects.


    Clivesmith
    Participant

    @clivesmith

    Hi Robin,
    Thank you, I would like to echo Chuckle’s comment, you are really appreciated.

    The code above returns me to the topic page with address as /topic/ministro-pistarini-ezeiza-international-airport-eze/?moderation_pending=7364

    I added a { to the function line of the code above. I assume I did not need the original code as well.


    Robin W
    Moderator

    @robin-w

    @clivesmith

    thanks, and yes I spotted the { this morning !

    I did no testing before posting it – I’m planning on looking later, so I’ll see what it does on my site


    Clivesmith
    Participant

    @clivesmith

    Thanks, I am more than happy for it to work that way there is no missing what is happening which you can get with a small banner and it will give me chance to customize the page they go to.


    Robin W
    Moderator

    @robin-w

    interesting that your one adds ‘/?moderation_pending=7364’ to the end – would give a neat way to give a link back to the topic.


    Clivesmith
    Participant

    @clivesmith

    Just realized that even without your code it comes back as /topic/adelaide-airport-adl/?moderation_pending=7608 never noticed that before


    Robin W
    Moderator

    @robin-w

    so are you saying my code does nothing for anonymous users ? It seems to work for logged in users.

    am doing further testing later, but your feedback would be useful


    Clivesmith
    Participant

    @clivesmith

    I ran your code on my development site as a guest and it does not work it returns the same as on the live site as a guest.
    As I am the only member, I only moderate guests.


    Robin W
    Moderator

    @robin-w

    great – thanks – I’ll look at anonymous posting and see if I can help

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