Marcus (aka @msykes) (@netweblogic)

Forum Replies Created

Viewing 2 replies - 1 through 2 (of 2 total)
  • 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');

    Thanks! Just what I was looking for :)

Viewing 2 replies - 1 through 2 (of 2 total)