bp_blogs_register_post_tracking_args( object|null $params = null, string|int $post_type )

Set up the tracking arguments for the ‘post’ post type.

Description

See also

Parameters

$params

(object|null) (Optional) Tracking arguments.

Default value: null

$post_type

(string|int) (Required) Post type to track.

Return

(object|null)

Source

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

function bp_blogs_register_post_tracking_args( $params = null, $post_type = 0 ) {

	/**
	 * Filters the post types to track for the Blogs component.
	 *
	 * @since BuddyPress 1.5.0
	 * @deprecated 2.3.0
	 *
	 * Make sure plugins still using 'bp_blogs_record_post_post_types'
	 * to track their post types will generate new_blog_post activities
	 * See https://buddypress.trac.wordpress.org/ticket/6306
	 *
	 * @param array $value Array of post types to track.
	 */
	$post_types = apply_filters( 'bp_blogs_record_post_post_types', bp_core_get_active_custom_post_type_feed() );

	$post_types_array = array_flip( $post_types );

	if ( ! isset( $post_types_array[ $post_type ] ) ) {
		return $params;
	}

	if ( 'post' === $post_type ) {
		// Set specific params for the 'post' post type.
		$params->component_id    = buddypress()->blogs->id;
		$params->action_id       = 'new_blog_post';
		$params->admin_filter    = __( 'New post published', 'buddyboss' );
		$params->format_callback = 'bp_blogs_format_activity_action_new_blog_post';
		$params->front_filter    = __( 'Posts', 'buddyboss' );
		$params->contexts        = array( 'activity', 'member' );
		$params->position        = 5;
	} else {

		$enabled = bp_is_post_type_feed_enable( $post_type );
		if ( $enabled  ) {

			$args = array(
				'name' => $post_type
			);

			$output = 'objects'; // names or objects

			$cu_post_types = get_post_types( $args, $output );


			foreach ( $cu_post_types  as $cu ) {

				$plural_label_name = $cu->labels->name;
				$singular_label_name = $cu->labels->singular_name;

				// Set specific params for the 'post' post type.
				$params->component_id    = buddypress()->blogs->id;
				$params->action_id       = 'new_blog_' . $post_type;
				$params->admin_filter    = sprintf( __( 'New %s published', 'buddyboss' ), strtolower( $singular_label_name ) );
				$params->format_callback = 'bp_blogs_format_activity_action_new_custom_post_type_feed';
				$params->front_filter    = sprintf( __( '%s', 'buddyboss' ), $plural_label_name );
				$params->contexts        = array( 'activity', 'member' );
				$params->position        = 5;

			}
		}
	}


	if ( post_type_supports( $post_type, 'comments' ) ) {
		$params->comment_action_id = 'new_blog_comment';

		/**
		 * Filters the post types to track for the Blogs component.
		 *
		 * @since BuddyPress 1.5.0
		 * @deprecated 2.5.0
		 *
		 * Make sure plugins still using 'bp_blogs_record_comment_post_types'
		 * to track comment about their post types will generate new_blog_comment activities
		 * See https://buddypress.trac.wordpress.org/ticket/6306
		 *
		 * @param array $value Array of post types to track.
		 */
		$comment_post_types = apply_filters( 'bp_blogs_record_comment_post_types', array( 'post' ) );
		$comment_post_types_array = array_flip( $comment_post_types );

		if ( isset( $comment_post_types_array[ $post_type ] ) ) {
			$params->comments_tracking = new stdClass();
			$params->comments_tracking->component_id    = buddypress()->blogs->id;
			$params->comments_tracking->action_id       = 'new_blog_comment';
			$params->comments_tracking->admin_filter    = __( 'New post comment posted', 'buddyboss' );
			$params->comments_tracking->format_callback = 'bp_blogs_format_activity_action_new_blog_comment';
			$params->comments_tracking->front_filter    = __( 'Comments', 'buddyboss' );
			$params->comments_tracking->contexts        = array( 'activity', 'member' );
			$params->comments_tracking->position        = 10;
		}
	}

	return $params;
}

Changelog

Changelog
Version Description
BuddyPress 2.5.0 This was moved out of the BP_Blogs_Component class. 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.