bp_blogs_setup_activity_loop_globals( object $activity )

Utility function to set up some variables for use in the activity loop.

Description

Grabs the blog’s comment depth and the post’s open comment status options for later use in the activity and activity comment loops.

This is to prevent having to requery these items later on.

See also

Parameters

$activity

(object) (Required) The BP_Activity_Activity object.

Source

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

function bp_blogs_setup_activity_loop_globals( $activity ) {
	if ( ! is_object( $activity ) ) {
		return;
	}

	// The activity type does not support comments or replies ? stop now!
	if ( ! bp_activity_type_supports( $activity->type, 'post-type-comment-reply' ) ) {
		return;
	}

	if ( empty( $activity->id ) ) {
		return;
	}

	// If we've already done this before, stop now!
	if ( isset( buddypress()->blogs->allow_comments[ $activity->id ] ) ) {
		return;
	}

	$allow_comments = bp_blogs_comments_open( $activity );
	$thread_depth   = bp_blogs_get_blogmeta( $activity->item_id, 'thread_comments_depth' );
	$moderation     = bp_blogs_get_blogmeta( $activity->item_id, 'comment_moderation' );

	// Initialize a local object so we won't have to query this again in the
	// comment loop.
	if ( empty( buddypress()->blogs->allow_comments ) ) {
		buddypress()->blogs->allow_comments = array();
	}
	if ( empty( buddypress()->blogs->thread_depth ) ) {
		buddypress()->blogs->thread_depth   = array();
	}
	if ( empty( buddypress()->blogs->comment_moderation ) ) {
		buddypress()->blogs->comment_moderation = array();
	}

	/*
	 * Cache comment settings in the buddypress() singleton for later reference.
	 *
	 * See bp_blogs_disable_activity_commenting() / bp_blogs_can_comment_reply().
	 *
	 * thread_depth is keyed by activity ID instead of blog ID because when we're
	 * in an actvity comment loop, we don't have access to the blog ID...
	 *
	 * Should probably object cache these values instead...
	 */
	buddypress()->blogs->allow_comments[ $activity->id ]     = $allow_comments;
	buddypress()->blogs->thread_depth[ $activity->id ]       = $thread_depth;
	buddypress()->blogs->comment_moderation[ $activity->id ] = $moderation;
}

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.