Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
07/03/2014 08:02:18 PM (10 years ago)
Author:
djpaul
Message:

at-mentions: overhaul the mentions implementation for Private Messages and Groups (admin) components.

Previously, these components had seperate implementations of username auto-suggestions, which weren't
reusable outside of where they'd been built, nor easily extended by developers, or other plugins.
This change creates a central API for auto-suggestions, currently only for usernames, but easily
extensible for other kinds of auto-suggestions in the future (i.e. group names, or #hashtags).

See #3278

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-core/bp-core-functions.php

    r8541 r8557  
    19221922    return $nav_item_url;
    19231923}
     1924
     1925/** Suggestions***************************************************************/
     1926
     1927/**
     1928 * BuddyPress Suggestions API for types of at-mentions.
     1929 *
     1930 * This is used to power BuddyPress' at-mentions suggestions, but it is flexible enough to be used
     1931 * for similar kinds of future requirements, or those implemented by third-party developers.
     1932 *
     1933 * @param array $args
     1934 * @return array|WP_Error Array of results. If there were any problems, returns a WP_Error object.
     1935 * @since BuddyPress (2.1.0)
     1936 */
     1937function bp_core_get_suggestions( $args ) {
     1938    $args = wp_parse_args( $args );
     1939
     1940    if ( ! $args['type'] ) {
     1941        return new WP_Error( 'missing_parameter' );
     1942    }
     1943
     1944    // Members @name suggestions.
     1945    if ( $args['type'] === 'members' ) {
     1946        $class = 'BP_Members_Suggestions';
     1947
     1948        // Members @name suggestions for users in a specific Group.
     1949        if ( isset( $args['group_id'] ) ) {
     1950            $class = 'BP_Groups_Member_Suggestions';
     1951        }
     1952
     1953    } else {
     1954        // If you've built a custom suggestions service, use this to tell BP the name of your class.
     1955        $class = apply_filters( 'bp_suggestions_services', '', $args );
     1956    }
     1957
     1958    if ( ! $class || ! class_exists( $class ) ) {
     1959        return new WP_Error( 'missing_parameter' );
     1960    }
     1961
     1962
     1963    $suggestions = new $class( $args );
     1964    $validation  = $suggestions->validate();
     1965
     1966    if ( is_wp_error( $validation ) ) {
     1967        $retval = $validation;
     1968    } else {
     1969        $retval = $suggestions->get_suggestions();
     1970    }
     1971
     1972    return apply_filters( 'bp_core_get_suggestions', $retval, $args );
     1973}
Note: See TracChangeset for help on using the changeset viewer.