Skip to:
Content

BuddyPress.org

Changeset 10833


Ignore:
Timestamp:
05/31/2016 06:53:00 AM (4 years ago)
Author:
r-a-y
Message:

Activity: Cache full oEmbed response for activity entries.

Currently, we cache the oEmbed HTML response markup. However, oEmbed also
returns other useful information like thumbnail, title, author and provider
name.

This commit caches the full oEmbed response so we can use this data for
other things such as rich activity embeds.

See #6772.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-activity/bp-activity-functions.php

    r10831 r10833  
    33903390function bp_activity_embed() {
    33913391    add_filter( 'embed_post_id',         'bp_get_activity_id'                  );
     3392    add_filter( 'oembed_dataparse',      'bp_activity_oembed_dataparse', 10, 2 );
    33923393    add_filter( 'bp_embed_get_cache',    'bp_embed_activity_cache',      10, 3 );
    33933394    add_action( 'bp_embed_update_cache', 'bp_embed_activity_save_cache', 10, 3 );
    33943395}
    33953396add_action( 'activity_loop_start', 'bp_activity_embed' );
     3397
     3398/**
     3399 * Cache full oEmbed response from oEmbed.
     3400 *
     3401 * @since 2.6.0
     3402 *
     3403 * @param string $retval Current oEmbed result.
     3404 * @param object $data   Full oEmbed response.
     3405 * @param string $url    URL used for the oEmbed request.
     3406 * @return string
     3407 */
     3408function bp_activity_oembed_dataparse( $retval, $data ) {
     3409    buddypress()->activity->oembed_response = $data;
     3410
     3411    return $retval;
     3412}
    33963413
    33973414/**
     
    34863503function bp_embed_activity_save_cache( $cache, $cachekey, $id ) {
    34873504    bp_activity_update_meta( $id, $cachekey, $cache );
     3505
     3506    // Cache full oEmbed response.
     3507    if ( true === isset( buddypress()->activity->oembed_response ) ) {
     3508        $cachekey = str_replace( '_oembed', '_oembed_response', $cachekey );
     3509        bp_activity_update_meta( $id, $cachekey, buddypress()->activity->oembed_response );
     3510    }
    34883511}
    34893512
Note: See TracChangeset for help on using the changeset viewer.