Skip to:
Content

BuddyPress.org

Changeset 12286


Ignore:
Timestamp:
11/15/2018 07:17:12 PM (6 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.

Location:
trunk/src
Files:
2 edited

Legend:

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

    r12281 r12286  
    39183918
    39193919/**
    3920  * AJAX endpoint for Suggestions API lookups.
    3921  *
    3922  * @since 2.1.0
    3923  */
    3924 function bp_ajax_get_suggestions() {
    3925     if ( ! bp_is_user_active() || empty( $_GET['term'] ) || empty( $_GET['type'] ) ) {
    3926         wp_send_json_error( 'missing_parameter' );
    3927         exit;
    3928     }
    3929 
    3930     $args = array(
    3931         'term' => sanitize_text_field( $_GET['term'] ),
    3932         'type' => sanitize_text_field( $_GET['type'] ),
    3933     );
    3934 
    3935     // Support per-Group suggestions.
    3936     if ( ! empty( $_GET['group-id'] ) ) {
    3937         $args['group_id'] = absint( $_GET['group-id'] );
    3938     }
    3939 
    3940     $results = bp_core_get_suggestions( $args );
    3941 
    3942     if ( is_wp_error( $results ) ) {
    3943         wp_send_json_error( $results->get_error_message() );
    3944         exit;
    3945     }
    3946 
    3947     wp_send_json_success( $results );
    3948 }
    3949 add_action( 'wp_ajax_bp_get_suggestions', 'bp_ajax_get_suggestions' );
    3950 
    3951 /**
    39523920 * Detect a change in post type status, and initiate an activity update if necessary.
    39533921 *
  • 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.