Activity Embeds
Intro
WordPress added oEmbed provider support in v4.4.0, allowing users to easily embed posts by copying a WordPress post URL and pasting it into the WordPress editor.
WordPress 4.5.0 made further enhancements to the embed template for easier customization for theme developers.
In BuddyPress 2.6.0, we are piggybacking off this functionality and enabling oEmbed provider support for single activity item.
This means you will be able to embed single activity items by copying the activity permalink and pasting it into the WordPress editors.
For example:
Your WordPress version is 4.5 or higher, you can enjoy the Activity Embeds feature we’re introducing in BuddyPress 2.6!https://videopress.com/v/VwVrGm7a?hd=1– Paul Gibbs (@djpaul) June 15, 2016
This feature will require WordPress 4.5+.
Disabling Activity Embeds
If you do not want your BuddyPress site to have activity embeds enabled, you can disable the feature with this small code snippet:
add_filter( 'bp_is_activity_embeds_active', '__return_false' );
Media in Activity Embeds
If an activity item includes a URL from a registered WordPress oEmbed provider on its own line:
https://codex.wordpress.org/Embeds#Okay.2C_So_What_Sites_Can_I_Embed_From.3F
We will attempt to display an image and caption of that oEmbed item in the activity embed template.
If a URL from a registered WordPress oEmbed provider isn’t found, we will attempt to embed an inline audio or video URL using your browser’s native HTML5 player.
Information for Theme Developers
As a theme developer, if you do not like the default look of activity embeds, you can override any of the template parts located at /wp-content/plugins/buddypress/bp-templates/bp-legacy/buddypress/assets/embeds/
by copying them to your theme’s directory.
Let’s say I want to make some tweaks to the activity header embed template part, copy /wp-content/plugins/buddypress/bp-templates/bp-legacy/buddypress/assets/embeds/header-activity.php
to /wp-content/themes/YOUR-THEME/buddypress/assets/embeds/header-activity.php
and make your changes.
If you want to override the CSS, copy /wp-content/plugins/buddypress/bp-templates/bp-legacy/css/embeds-activity.min.css
to /wp-content/themes/YOUR-THEME/buddypress/css/embeds-activity.min.css
or /wp-content/themes/YOUR-THEME/css/embeds-activity.min.css
and make your changes.
If you have WP_DEBUG
turned on, then omit the '.min'
suffix.
Note: CSS is rendered inline in the <head>
tag. This is similar to what WordPress is doing in their embed template.
Information for Template Pack developers
If you do not know what a template pack is, you do not need to read this section!
As of BuddyPress 2.6, if you are developing a custom template pack that is not bp-legacy, for activity embeds to display properly, you will need to copy the following to your template pack’s directory:
/wp-content/plugins/buddypress/bp-templates/bp-legacy/buddypress/assets/embeds/
/wp-content/plugins/buddypress/bp-templates/bp-legacy/css/embeds-activity.css
/wp-content/plugins/buddypress/bp-templates/bp-legacy/css/embeds-activity-rtl.css
/wp-content/plugins/buddypress/bp-templates/bp-legacy/css/embeds-activity.min.css
/wp-content/plugins/buddypress/bp-templates/bp-legacy/css/embeds-activity-rtl.min.css
There is a proposal to eliminate this copying process in future versions. Keep an eye on the following ticket for more info:
https://buddypress.trac.wordpress.org/ticket/7116
Information for Plugin Developers
In order for oEmbed to work with BuddyPress activity items, we register a custom endpoint with the WordPress oEmbed REST API:
example.com/wp-json/oembed/1.0/embed/activity?url=URL_TO_ACTIVITY_ITEM
As well as supporting the regular oEmbed parameters like url
, format
and maxwidth
:
http://oembed.com/#section2.2
The BP Activity oEmbed endpoint also supports the hide_media
parameter.
If this is set during the oEmbed request, no media items will be displayed in the embed.