Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
07/08/2021 05:23:19 PM (5 years ago)
Author:
dcavins
Message:

Introduce bp_messages_dismiss_sitewide_notice().

Introduce bp_messages_dismiss_sitewide_notice()
as core function to dismiss a notice for a user.
This function allows us to replace code to update the
user's closed_notices meta that is repeated in
several places in BuddyPress.

See #8505.

File:
1 edited

Legend:

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

    r12937 r12989  
    767767
    768768        // Mark the active notice as closed.
    769         $notice = BP_Messages_Notice::get_active();
    770 
    771         if ( ! empty( $notice->id ) ) {
    772                 $user_id = bp_loggedin_user_id();
    773 
    774                 $closed_notices = bp_get_user_meta( $user_id, 'closed_notices', true );
    775 
    776                 if ( empty( $closed_notices ) ) {
    777                         $closed_notices = array();
    778                 }
    779 
    780                 // Add the notice to the array of the user's closed notices.
    781                 $closed_notices[] = (int) $notice->id;
    782                 bp_update_user_meta( $user_id, 'closed_notices', array_map( 'absint', array_unique( $closed_notices ) ) );
    783 
     769        $success = bp_messages_dismiss_sitewide_notice();
     770
     771        if ( $success ) {
    784772                wp_send_json_success( array(
    785773                        'feedback' => '<div class="bp-feedback info"><span class="bp-icon" aria-hidden="true"></span><p>' . __( 'Sitewide notice dismissed', 'buddypress' ) . '</p></div>',
    786774                        'type'     => 'success',
    787775                ) );
    788         }
    789 }
     776        } else {
     777                wp_send_json_error( array(
     778                        'feedback' => '<div class="bp-feedback info"><span class="bp-icon" aria-hidden="true"></span><p>' . __( 'There was a problem dismissing that sitewide notice', 'buddypress' ) . '</p></div>',
     779                        'type'     => 'error',
     780                ) );
     781        }
     782}
Note: See TracChangeset for help on using the changeset viewer.