Skip to:
Content

BuddyPress.org

Ticket #7592: 7592.01.patch

File 7592.01.patch, 4.4 KB (added by r-a-y, 2 years ago)

Disables activity commenting for sub-sites requiring manual approval for blog comments.

  • src/bp-blogs/bp-blogs-activity.php

     
    11481148
    11491149        $allow_comments = bp_blogs_comments_open( $activity );
    11501150        $thread_depth   = bp_blogs_get_blogmeta( $activity->item_id, 'thread_comments_depth' );
     1151        $moderation     = bp_blogs_get_blogmeta( $activity->item_id, 'comment_moderation' );
    11511152
    11521153        // Initialize a local object so we won't have to query this again in the
    11531154        // comment loop.
     
    11571158        if ( empty( buddypress()->blogs->thread_depth ) ) {
    11581159                buddypress()->blogs->thread_depth   = array();
    11591160        }
     1161        if ( empty( buddypress()->blogs->comment_moderation ) ) {
     1162                buddypress()->blogs->comment_moderation = array();
     1163        }
    11601164
    1161         // Cache comment settings in the buddypress() singleton to reference later in
    1162         // the activity comment loop
    1163         // @see bp_blogs_disable_activity_replies()
    1164         //
    1165         // thread_depth is keyed by activity ID instead of blog ID because when we're
    1166         // in a comment loop, we don't have access to the blog ID...
    1167         // should probably object cache these values instead...
    1168         buddypress()->blogs->allow_comments[ $activity->id ] = $allow_comments;
    1169         buddypress()->blogs->thread_depth[ $activity->id ]   = $thread_depth;
     1165        /*
     1166         * Cache comment settings in the buddypress() singleton for later reference.
     1167         *
     1168         * See bp_blogs_disable_activity_commenting() / bp_blogs_can_comment_reply().
     1169         *
     1170         * thread_depth is keyed by activity ID instead of blog ID because when we're
     1171         * in an actvity comment loop, we don't have access to the blog ID...
     1172         *
     1173         * Should probably object cache these values instead...
     1174         */
     1175        buddypress()->blogs->allow_comments[ $activity->id ]     = $allow_comments;
     1176        buddypress()->blogs->thread_depth[ $activity->id ]       = $thread_depth;
     1177        buddypress()->blogs->comment_moderation[ $activity->id ] = $moderation;
    11701178}
    11711179
    11721180/**
     
    12311239                        if ( empty( buddypress()->blogs->allow_comments[ bp_get_activity_id() ] ) ) {
    12321240                                $retval = false;
    12331241                        }
     1242
     1243                        // If comments need moderation, disable activity commenting.
     1244                        if ( ! empty( buddypress()->blogs->comment_moderation[ bp_get_activity_id() ] ) ) {
     1245                                $retval = false;
     1246                        }
    12341247                // The activity type does not support comments or replies
    12351248                } else {
    12361249                        $retval = false;
     
    13141327                }
    13151328        }
    13161329
     1330        // If comments need moderation, disable activity commenting.
     1331        if ( ! empty( buddypress()->blogs->comment_moderation[$comment->item_id] ) ) {
     1332                $retval = false;
     1333        }
     1334
    13171335        return $retval;
    13181336}
    13191337add_filter( 'bp_activity_can_comment_reply', 'bp_blogs_can_comment_reply', 10, 2 );
  • src/bp-blogs/bp-blogs-functions.php

     
    362362        $description     = get_blog_option( $blog_id, 'blogdescription' );
    363363        $close_old_posts = get_blog_option( $blog_id, 'close_comments_for_old_posts' );
    364364        $close_days_old  = get_blog_option( $blog_id, 'close_comments_days_old' );
     365        $moderation      = get_blog_option( $blog_id, 'comment_moderation' );
    365366
    366367        $thread_depth = get_blog_option( $blog_id, 'thread_comments' );
    367368        if ( ! empty( $thread_depth ) ) {
     
    384385        bp_blogs_update_blogmeta( $recorded_blog->blog_id, 'close_comments_for_old_posts', $close_old_posts );
    385386        bp_blogs_update_blogmeta( $recorded_blog->blog_id, 'close_comments_days_old', $close_days_old );
    386387        bp_blogs_update_blogmeta( $recorded_blog->blog_id, 'thread_comments_depth', $thread_depth );
     388        bp_blogs_update_blogmeta( $recorded_blog->blog_id, 'comment_moderation', $moderation );
    387389
    388390        $is_private = !empty( $_POST['blog_public'] ) && (int) $_POST['blog_public'] ? false : true;
    389391
     
    525527}
    526528add_action( 'update_option_thread_comments_depth', 'bp_blogs_update_option_thread_comments_depth', 10, 2 );
    527529
     530/**
     531 * When updating comment moderation, mirror value in blogmeta table.
     532 *
     533 * @since 3.0.0
     534 *
     535 * @param string $oldvalue Value before save. Passed by do_action() but unused here.
     536 * @param string $newvalue Value to change meta to.
     537 */
     538function bp_blogs_update_option_comment_moderation( $oldvalue, $newvalue ) {
     539        bp_blogs_update_blogmeta( $GLOBALS['wpdb']->blogid, 'comment_moderation', $newvalue );
     540}
     541add_action( 'update_option_comment_moderation', 'bp_blogs_update_option_comment_moderation', 10, 2 );
     542
    528543/**
    529544 * Syncs site icon URLs to blogmeta.
    530545 *