bp_blogs_disable_activity_commenting( bool $retval )

Disable activity commenting for blog posts based on certain criteria.

Description

If activity commenting is enabled for blog posts, we still need to disable commenting if:

  • comments are disabled for the WP blog post from the admin dashboard
  • the WP blog post is supposed to be automatically closed from comments based on a certain age
  • the activity entry is a ‘new_blog_comment’ type

Parameters

$retval

(Required) Is activity commenting enabled for this activity entry.

Return

(bool)

Source

File: bp-blogs/bp-blogs-activity.php

1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
function bp_blogs_disable_activity_commenting( $retval ) {
    global $activities_template;
 
    // If activity commenting is disabled, return current value.
    if ( bp_disable_blogforum_comments() || ! isset( $activities_template->in_the_loop ) ) {
        return $retval;
    }
 
    $type = bp_get_activity_type();
 
    // It's a post type supporting comment tracking.
    if ( bp_activity_type_supports( $type, 'post-type-comment-tracking' ) ) {
        // The activity type is supporting comments or replies
        if ( bp_activity_type_supports( $type, 'post-type-comment-reply' ) ) {
            // Setup some globals we'll need to reference later.
            bp_blogs_setup_activity_loop_globals( $activities_template->activity );
 
            // If comments are closed for the WP blog post, we should disable
            // activity comments for this activity entry.
            if ( empty( buddypress()->blogs->allow_comments[ bp_get_activity_id() ] ) ) {
                $retval = false;
            }
 
            // If comments need moderation, disable activity commenting.
            if ( ! empty( buddypress()->blogs->comment_moderation[ bp_get_activity_id() ] ) ) {
                $retval = false;
            }
        // The activity type does not support comments or replies
        } else {
            $retval = false;
        }
    }
 
    return $retval;
}

Changelog

Changelog
Version Description
BuddyPress 2.0.0 Introduced.

Questions?

We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.