Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
05/26/2018 12:49:25 PM (7 years ago)
Author:
imath
Message:

Messages UI: Create a new Backbone view to wrap hooks caught output

This new view can be used when hooks caught output cannot be inserted into regular views. bp_before_member_messages_loop and bp_before_member_messages_loop are two good examples.

Fixes #7850 (Branch 3.0)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/3.0/src/bp-templates/bp-nouveau/includes/messages/ajax.php

    r12122 r12134  
    224224    }
    225225
    226     if ( isset( $_POST['box'] ) && 'starred' === $_POST['box'] ) {
    227         $star_filter = true;
    228 
    229         // Add the message thread filter.
     226    $bp           = buddypress();
     227    $reset_action = $bp->current_action;
     228
     229    // Override bp_current_action().
     230    if ( isset( $_POST['box'] ) ) {
     231        $bp->current_action = $_POST['box'];
     232    }
     233
     234    // Add the message thread filter.
     235    if ( 'starred' === $bp->current_action ) {
    230236        add_filter( 'bp_after_has_message_threads_parse_args', 'bp_messages_filter_starred_message_threads' );
    231237    }
     
    233239    // Simulate the loop.
    234240    if ( ! bp_has_message_threads( bp_ajax_querystring( 'messages' ) ) ) {
     241        // Remove the bp_current_action() override.
     242        $bp->current_action = $reset_action;
     243
    235244        wp_send_json_error( array(
    236245            'feedback' => __( 'Sorry, no messages were found.', 'buddypress' ),
     
    239248    }
    240249
    241     if ( ! empty( $star_filter ) ) {
    242         // remove the message thread filter.
     250    // remove the message thread filter.
     251    if ( 'starred' === $bp->current_action ) {
    243252        remove_filter( 'bp_after_has_message_threads_parse_args', 'bp_messages_filter_starred_message_threads' );
    244253    }
     
    320329    $threads->threads = array_filter( $threads->threads );
    321330
     331    $extra_content = bp_nouveau_messages_catch_hook_content( array(
     332        'beforeLoop' => 'bp_before_member_messages_loop',
     333        'afterLoop'  => 'bp_after_member_messages_loop',
     334    ) );
     335
     336    if ( array_filter( $extra_content ) ) {
     337        $threads->extraContent = $extra_content;
     338    }
     339
     340    // Remove the bp_current_action() override.
     341    $bp->current_action = $reset_action;
     342
     343    // Return the successfull reply.
    322344    wp_send_json_success( $threads );
    323345}
Note: See TracChangeset for help on using the changeset viewer.