bp_activity_save_link_data( $activity )

Save link preview data into activity meta key “_link_preview_data”

Description

Parameters

$activity

(Required)

Source

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

function bp_activity_save_link_data( $activity ) {

	if ( empty( $_POST['link_url'] ) ) {
		return;
	}

	// Ignore YouTube and Vimeo Preview link.
	if ( strpos( $_POST['link_url'], 'youtube' ) > 0 || strpos( $_POST['link_url'], 'youtu' ) > 0 || strpos( $_POST['link_url'], 'vimeo' ) > 0 ) {
		return;
	}

	$preview_data['url'] = $_POST['link_url'];

	if ( ! empty( $_POST['link_image'] ) ) {
		$attachment_id = bp_activity_media_sideload_attachment( $_POST['link_image'] );
		if ( $attachment_id ) {
			$preview_data['attachment_id'] = $attachment_id;
		}
	}

	if ( ! empty( $_POST['link_title'] ) ) {
		$preview_data['title'] = $_POST['link_title'];
	}

	if ( ! empty( $_POST['link_description'] ) ) {
		$preview_data['description'] = $_POST['link_description'];
	}

	bp_activity_update_meta( $activity->id, '_link_preview_data', $preview_data );
}

Changelog

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