BP_Activity_oEmbed_Extension::validate_url_to_item_id( string $url )
Validates the URL to determine if the activity item is valid.
Description
Parameters
- $url
-
(Required) The URL to check.
Return
(int|bool) Activity ID on success; boolean false on failure.
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;
}
Changelog
| Version | Description |
|---|---|
| BuddyPress 2.6.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.