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

85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
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

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.