Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
11/15/2018 07:17:12 PM (5 years ago)
Author:
boonebgorges
Message:

Move bp_ajax_get_suggestions() handler to Core component.

It was previously located in the Activity component, which made it
impossible to do an AJAX suggestions query (such as in the case of
Messages) when Activity was disabled.

Props imath.

See #7951.

File:
1 edited

Legend:

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

    r12281 r12286  
    27712771
    27722772/**
     2773 * AJAX endpoint for Suggestions API lookups.
     2774 *
     2775 * @since 2.1.0
     2776 * @since 4.0.0 Moved here to make sure this function is available
     2777 *              even if the Activity component is not active.
     2778 */
     2779function bp_ajax_get_suggestions() {
     2780    if ( ! bp_is_user_active() || empty( $_GET['term'] ) || empty( $_GET['type'] ) ) {
     2781        wp_send_json_error( 'missing_parameter' );
     2782        exit;
     2783    }
     2784
     2785    $args = array(
     2786        'term' => sanitize_text_field( $_GET['term'] ),
     2787        'type' => sanitize_text_field( $_GET['type'] ),
     2788    );
     2789
     2790    // Support per-Group suggestions.
     2791    if ( ! empty( $_GET['group-id'] ) ) {
     2792        $args['group_id'] = absint( $_GET['group-id'] );
     2793    }
     2794
     2795    $results = bp_core_get_suggestions( $args );
     2796
     2797    if ( is_wp_error( $results ) ) {
     2798        wp_send_json_error( $results->get_error_message() );
     2799        exit;
     2800    }
     2801
     2802    wp_send_json_success( $results );
     2803}
     2804add_action( 'wp_ajax_bp_get_suggestions', 'bp_ajax_get_suggestions' );
     2805
     2806/**
    27732807 * Set data from the BP root blog's upload directory.
    27742808 *
Note: See TracChangeset for help on using the changeset viewer.