BP_Activity_oEmbed_Extension::validate_url_to_item_id( string $url )

Validates the URL to determine if the activity item is valid.


Parameters Parameters

$url

(string) (Required) The URL to check.


Top ↑

Return Return

(int|bool) Activity ID on success; boolean false on failure.


Source Source

File: bp-activity/classes/class-bp-activity-oembed-extension.php

	protected function validate_url_to_item_id( $url ) {
		if ( bp_core_enable_root_profiles() ) {
			$domain = bp_get_root_domain();
		} else {
			$domain = bp_get_members_directory_permalink();
		}

		// Check the URL to see if this is a single activity URL.
		if ( 0 !== strpos( $url, $domain ) ) {
			return false;
		}

		// Check for activity slug.
		if ( false === strpos( $url, '/' . bp_get_activity_slug() . '/' ) ) {
			return false;
		}

		// Do more checks.
		$url = trim( untrailingslashit( $url ) );

		// Grab the activity ID.
		$activity_id = (int) substr(
			$url,
			strrpos( $url, '/' ) + 1
		);

		if ( ! empty( $activity_id ) ) {
			// Check if activity item still exists.
			$activity = new BP_Activity_Activity( $activity_id );

			// Okay, we're good to go!
			if ( ! empty( $activity->component ) && 0 === (int) $activity->is_spam ) {
				return $activity_id;
			}
		}

		return false;
	}


Top ↑

Changelog Changelog

Changelog
Version Description
2.6.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.