Skip to:
Content

BuddyPress.org

Changeset 13036


Ignore:
Timestamp:
08/10/2021 04:55:25 PM (3 years ago)
Author:
imath
Message:

BP Nouveau: include a notification to the active Site Wide Notice

When a Site Wide notice is active the BP Nouveau template pack is prepending a notification to the logged in user notifications list.

FYI: This feature was "missing in action" since the introduction of the bp_notifications_get_grouped_notifications_for_user() and its use inside the bp_notifications_get_notifications_for_user() function in replacement of bp_notifications_get_all_notifications_for_user().

Fixes #8547

Location:
trunk/src/bp-templates/bp-nouveau/includes/messages
Files:
2 edited

Legend:

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

    r12908 r13036  
    44 *
    55 * @since 3.0.0
    6  * @version 3.1.0
     6 * @version 10.0.0
    77 */
    88
     
    191191
    192192/**
    193  * @since 3.0.0
     193 * Prepend a notification about the active Sitewide notice.
     194 *
     195 * @since 3.0.0
     196 *
     197 * @param false|array $notifications False if there are no items, an array of notification items otherwise.
     198 * @param int         $user_id       The user ID.
     199 * @return false|array               False if there are no items, an array of notification items otherwise.
    194200 */
    195201function bp_nouveau_add_notice_notification_for_user( $notifications, $user_id ) {
     
    212218    }
    213219
    214     $notice_notification                    = new stdClass;
    215     $notice_notification->id                = 0;
    216     $notice_notification->user_id           = $user_id;
    217     $notice_notification->item_id           = $notice->id;
    218     $notice_notification->secondary_item_id = '';
    219     $notice_notification->component_name    = 'messages';
    220     $notice_notification->component_action  = 'new_notice';
    221     $notice_notification->date_notified     = $notice->date_sent;
    222     $notice_notification->is_new            = '1';
    223 
    224     return array_merge( $notifications, array( $notice_notification ) );
    225 }
    226 
    227 /**
    228  * @since 3.0.0
     220    $notice_notification = (object) array(
     221        'id'                => 0,
     222        'user_id'           => $user_id,
     223        'item_id'           => $notice->id,
     224        'secondary_item_id' => 0,
     225        'component_name'    => 'messages',
     226        'component_action'  => 'new_notice',
     227        'date_notified'     => $notice->date_sent,
     228        'is_new'            => 1,
     229        'total_count'       => 1,
     230        'content'           => __( 'New sitewide notice', 'buddypress' ),
     231        'href'              => bp_loggedin_user_domain(),
     232    );
     233
     234    if ( ! is_array( $notifications ) ) {
     235        $notifications = array( $notice_notification );
     236    } else {
     237        array_unshift( $notifications, $notice_notification );
     238    }
     239
     240    return $notifications;
     241}
     242
     243/**
     244 * Format the notice notifications.
     245 *
     246 * @since 3.0.0
     247 * @deprecated 10.0.0
     248 *
     249 * @param array $array.
    229250 */
    230251function bp_nouveau_format_notice_notification_for_user( $array ) {
    231     if ( ! empty( $array['text'] ) || ! doing_action( 'admin_bar_menu' ) ) {
    232         return $array;
    233     }
    234 
    235     return array(
    236         'text' => __( 'New sitewide notice', 'buddypress' ),
    237         'link' => bp_loggedin_user_domain(),
    238     );
     252    _deprecated_function( __FUNCTION__, '10.0.0' );
    239253}
    240254
  • trunk/src/bp-templates/bp-nouveau/includes/messages/loader.php

    r12192 r13036  
    44 *
    55 * @since 3.0.0
    6  * @version 3.0.0
     6 * @version 10.0.0
    77 */
    88
     
    8989     */
    9090    protected function setup_filters() {
    91         // Enqueue specific styles
     91        // Enqueue specific styles.
    9292        add_filter( 'bp_nouveau_enqueue_styles', 'bp_nouveau_messages_enqueue_styles', 10, 1 );
    9393
    94         // Register messages scripts
     94        // Register messages scripts.
    9595        add_filter( 'bp_nouveau_register_scripts', 'bp_nouveau_messages_register_scripts', 10, 1 );
    9696
    97         // Localize Scripts
     97        // Localize Scripts.
    9898        add_filter( 'bp_core_get_js_strings', 'bp_nouveau_messages_localize_scripts', 10, 1 );
    9999
    100         // Notices
    101         add_filter( 'bp_messages_single_new_message_notification', 'bp_nouveau_format_notice_notification_for_user', 10, 1 );
    102         add_filter( 'bp_notifications_get_all_notifications_for_user', 'bp_nouveau_add_notice_notification_for_user', 10, 2 );
     100        // Notices.
     101        add_filter( 'bp_core_get_notifications_for_user', 'bp_nouveau_add_notice_notification_for_user', 10, 2 );
    103102
    104         // Messages
     103        // Messages.
    105104        add_filter( 'bp_messages_admin_nav', 'bp_nouveau_messages_adjust_admin_nav', 10, 1 );
    106105    }
Note: See TracChangeset for help on using the changeset viewer.