BP_REST_Activity_Endpoint::render_item( BP_Activity_Activity $activity )

Renders the content of an activity.

Description

Parameters

$activity

(Required) Activity data.

Return

(string) The rendered activity content.

Source

File: bp-activity/classes/class-bp-rest-activity-endpoint.php

1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
public function render_item( $activity ) {
    $rendered = '';
 
    if ( empty( $activity->content ) ) {
        return $rendered;
    }
 
    // Do not truncate activities.
    add_filter( 'bp_activity_maybe_truncate_entry', '__return_false' );
 
    if ( 'activity_comment' === $activity->type ) {
        $rendered = apply_filters( 'bp_get_activity_content', $activity->content );
    } else {
        $activities_template = null;
 
        if ( isset( $GLOBALS['activities_template'] ) ) {
            $activities_template = $GLOBALS['activities_template'];
        }
 
        // Set the `activities_template` global for the current activity.
        $GLOBALS['activities_template']           = new stdClass();
        $GLOBALS['activities_template']->activity = $activity;
 
        // Set up activity oEmbed cache.
        bp_activity_embed();
 
        // removed combined gif data with content.
        if ( function_exists( 'bp_media_activity_embed_gif' ) ) {
            remove_filter( 'bp_get_activity_content_body', 'bp_media_activity_embed_gif', 20, 2 );
        }
 
        $rendered = apply_filters_ref_array(
            'bp_get_activity_content_body',
            array(
                $activity->content,
                &$activity,
            )
        );
 
        // removed combined gif data with content.
        if ( function_exists( 'bp_media_activity_embed_gif' ) ) {
            add_filter( 'bp_get_activity_content_body', 'bp_media_activity_embed_gif', 20, 2 );
        }
 
        // Restore the `activities_template` global.
        $GLOBALS['activities_template'] = $activities_template;
    }
 
    // Restore the filter to truncate activities.
    remove_filter( 'bp_activity_maybe_truncate_entry', '__return_false' );
 
    return $rendered;
}

Changelog

Changelog
Version Description
0.1.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.