bp_activity_get_post_type_tracking_args( string $post_type )
Get tracking arguments for a specific post type.
Description
Parameters
- $post_type
-
(Required) Name of the post type.
Return
(object) The tracking arguments of the post type.
Source
File: bp-activity/bp-activity-functions.php
function bp_activity_get_post_type_tracking_args( $post_type ) {
if ( ! post_type_supports( $post_type, 'buddypress-activity' ) ) {
return false;
}
$post_type_object = get_post_type_object( $post_type );
$post_type_support_comments = post_type_supports( $post_type, 'comments' );
$post_type_activity = array(
'component_id' => buddypress()->activity->id,
'action_id' => 'new_' . $post_type,
'format_callback' => 'bp_activity_format_activity_action_custom_post_type_post',
'front_filter' => $post_type_object->labels->name,
'contexts' => array( 'activity' ),
'position' => 0,
'singular' => strtolower( $post_type_object->labels->singular_name ),
'activity_comment' => ! $post_type_support_comments,
'comment_action_id' => false,
'comment_format_callback' => 'bp_activity_format_activity_action_custom_post_type_comment',
);
if ( ! empty( $post_type_object->bp_activity ) ) {
$post_type_activity = bp_parse_args( (array) $post_type_object->bp_activity, $post_type_activity, $post_type . '_tracking_args' );
}
$post_type_activity = (object) $post_type_activity;
// Try to get the admin filter from the post type labels.
if ( ! empty( $post_type_object->labels->bp_activity_admin_filter ) ) {
$post_type_activity->admin_filter = $post_type_object->labels->bp_activity_admin_filter;
// Fall back to a generic name.
} else {
$post_type_activity->admin_filter = __( 'New item published', 'buddyboss' );
}
// Check for the front filter in the post type labels.
if ( ! empty( $post_type_object->labels->bp_activity_front_filter ) ) {
$post_type_activity->front_filter = $post_type_object->labels->bp_activity_front_filter;
}
// Try to get the action for new post type action on non-multisite installations.
if ( ! empty( $post_type_object->labels->bp_activity_new_post ) ) {
$post_type_activity->new_post_type_action = $post_type_object->labels->bp_activity_new_post;
}
// Try to get the action for new post type action on multisite installations.
if ( ! empty( $post_type_object->labels->bp_activity_new_post_ms ) ) {
$post_type_activity->new_post_type_action_ms = $post_type_object->labels->bp_activity_new_post_ms;
}
// If the post type supports comments and has a comment action id, build the comments tracking args
if ( $post_type_support_comments && ! empty( $post_type_activity->comment_action_id ) ) {
// Init a new container for the activity type for comments
$post_type_activity->comments_tracking = new stdClass();
// Build the activity type for comments
$post_type_activity->comments_tracking->component_id = $post_type_activity->component_id;
$post_type_activity->comments_tracking->action_id = $post_type_activity->comment_action_id;
// Try to get the comments admin filter from the post type labels.
if ( ! empty( $post_type_object->labels->bp_activity_comments_admin_filter ) ) {
$post_type_activity->comments_tracking->admin_filter = $post_type_object->labels->bp_activity_comments_admin_filter;
// Fall back to a generic name.
} else {
$post_type_activity->comments_tracking->admin_filter = __( 'New item comment posted', 'buddyboss' );
}
$post_type_activity->comments_tracking->format_callback = $post_type_activity->comment_format_callback;
// Check for the comments front filter in the post type labels.
if ( ! empty( $post_type_object->labels->bp_activity_comments_front_filter ) ) {
$post_type_activity->comments_tracking->front_filter = $post_type_object->labels->bp_activity_comments_front_filter;
// Fall back to a generic name.
} else {
$post_type_activity->comments_tracking->front_filter = __( 'Item comments', 'buddyboss' );
}
$post_type_activity->comments_tracking->contexts = $post_type_activity->contexts;
$post_type_activity->comments_tracking->position = (int) $post_type_activity->position + 1;
// Try to get the action for new post type comment action on non-multisite installations.
if ( ! empty( $post_type_object->labels->bp_activity_new_comment ) ) {
$post_type_activity->comments_tracking->new_post_type_comment_action = $post_type_object->labels->bp_activity_new_comment;
}
// Try to get the action for new post type comment action on multisite installations.
if ( ! empty( $post_type_object->labels->bp_activity_new_comment_ms ) ) {
$post_type_activity->comments_tracking->new_post_type_comment_action_ms = $post_type_object->labels->bp_activity_new_comment_ms;
}
}
// Finally make sure we'll be able to find the post type this activity type is associated to.
$post_type_activity->post_type = $post_type;
/**
* Filters tracking arguments for a specific post type.
*
* @since BuddyPress 2.2.0
*
* @param object $post_type_activity The tracking arguments of the post type.
* @param string $post_type Name of the post type.
*/
return apply_filters( 'bp_activity_get_post_type_tracking_args', $post_type_activity, $post_type );
}
Changelog
| Version | Description |
|---|---|
| BuddyPress 2.5.0 Add post type comments tracking args | BuddyPress 2.5.0 Add post type comments tracking args |
| BuddyPress 2.2.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.