Skip to:
Content

BuddyPress.org

Changeset 13615


Ignore:
Timestamp:
10/19/2023 11:52:53 PM (2 years ago)
Author:
imath
Message:

Introduce Admin Notifications to warn Admin about important BP changes

  • Add a new Administration screen to list Admin notifications.
  • Put the logic in place to dismiss an Admin notification.
  • Add a 11.4 update task to add unread Admin notifications.
  • Create a 11.4 Admin Notification to inform Admin users about whether they need to install BP Classic to be ready for BuddyPress 12.0.0
  • Bump Raw DB version to 13408

Props dcavins

Fixes #9007 (Branch 11.0)

Location:
branches/11.0/src
Files:
15 edited

Legend:

Unmodified
Added
Removed
  • branches/11.0/src/bp-core/admin/bp-core-admin-functions.php

    r13550 r13615  
    512512            'name' => __( 'Pages', 'buddypress' ),
    513513        ),
    514         '3' => array(
     514        '4' => array(
    515515            'id'   => 'bp-credits',
    516516            'href' => bp_get_admin_url( add_query_arg( array( 'page' => 'bp-credits' ), 'admin.php' ) ),
     
    518518        ),
    519519    );
     520
     521    if ( bp_core_get_unread_admin_notifications() || ( isset( $_GET['page'] ) && 'bp-admin-notifications' === $_GET['page'] ) ) {
     522        $settings_tabs['3'] = array(
     523            'id'   => 'bp-admin-notifications',
     524            'href' => bp_get_admin_url( add_query_arg( array( 'page' => 'bp-admin-notifications' ), 'admin.php' ) ),
     525            'name' => __( 'Notifications', 'buddypress' ),
     526        );
     527    }
    520528
    521529    if ( ! $apply_filters ) {
     
    14131421 */
    14141422function bp_core_admin_notice_dismiss_callback() {
    1415     if ( ! current_user_can( 'install_plugins' ) ) {
     1423    if ( ! current_user_can( 'manage_options' ) ) {
    14161424        wp_send_json_error();
    14171425    }
     
    14401448    }
    14411449
    1442     bp_update_option( "bp-dismissed-notice-{$notice_id}", true );
     1450    bp_core_dismiss_admin_notification( $notice_id );
    14431451
    14441452    wp_send_json_success();
     
    15121520}
    15131521add_action( 'bp_init', 'bp_block_init_category_filter' );
     1522
     1523/**
     1524 * Outputs an Admin Notification.
     1525 *
     1526 * @since 11.4.0
     1527 *
     1528 * @param object $notification An Admin Notification object.
     1529 */
     1530function bp_core_admin_format_notifications( $notification = null ) {
     1531    if ( ! isset( $notification->id ) ) {
     1532        return '';
     1533    }
     1534    ?>
     1535    <div class="bp-welcome-panel bp-notice-container">
     1536        <a class="bp-welcome-panel-close bp-is-dismissible" href="#" data-notice_id="<?php echo esc_attr( $notification->id ); ?>" aria-label="<?php esc_attr_e( 'Dismiss the notification', 'buddypress' ); ?>"><?php esc_html_e( 'Dismiss', 'buddypress' ); ?></a>
     1537        <div class="bp-welcome-panel-content">
     1538            <h2><span class="bp-version"><?php echo number_format_i18n( $notification->version, 1 ); ?></span> <?php echo esc_html( $notification->title ); ?></h2>
     1539            <p class="about-description">
     1540                <?php echo wp_kses( $notification->content, array( 'a' => array( 'href' => true ), 'br' => array(), 'strong' => array() ) ); ?>
     1541            </p>
     1542            <div class="bp-admin-notification-action"><a href="<?php echo esc_url( $notification->href ); ?>" class="button button-primary"><?php echo esc_html( $notification->text ); ?></a></div>
     1543        </div>
     1544    </div>
     1545    <?php
     1546}
  • branches/11.0/src/bp-core/admin/css/common-rtl.css

    r13368 r13615  
    4141.bp-badge:before {
    4242    content: "\f448";
     43}
     44
     45.bp-version {
     46    color: #fff;
     47    background: #d84800;
     48    padding: 2px 5px;
    4349}
    4450
     
    614620
    615621.buddypress .bp-welcome-panel-content p {
    616     padding-bottom: 23px;
    617622    font-size: 14px;
     623}
     624
     625.buddypress .bp-welcome-panel-content .bp-admin-notification-action {
     626    margin: 23px 0;
    618627}
    619628
     
    698707}
    699708
     709.buddypress-body .form-table.hide {
     710    display: none;
     711}
     712
    700713/* Media queries */
    701714@media screen and (max-width: 782px) {
  • branches/11.0/src/bp-core/admin/css/common.css

    r13368 r13615  
    4141.bp-badge:before {
    4242    content: "\f448";
     43}
     44
     45.bp-version {
     46    color: #fff;
     47    background: #d84800;
     48    padding: 2px 5px;
    4349}
    4450
     
    614620
    615621.buddypress .bp-welcome-panel-content p {
    616     padding-bottom: 23px;
    617622    font-size: 14px;
     623}
     624
     625.buddypress .bp-welcome-panel-content .bp-admin-notification-action {
     626    margin: 23px 0;
    618627}
    619628
     
    698707}
    699708
     709.buddypress-body .form-table.hide {
     710    display: none;
     711}
     712
    700713/* Media queries */
    701714@media screen and (max-width: 782px) {
  • branches/11.0/src/bp-core/admin/js/dismissible-admin-notices.js

    r13164 r13615  
    121121// Use the bp global.
    122122window.bp = window.bp || {};
     123
    123124/**
    124125 * Use an XHR request to dismiss admin notices.
     
    126127 * @since 10.0.0
    127128 */
    128 
    129129bp.DismissibleAdminNotices = class {
    130130  constructor(settings) {
    131131    this.settings = settings || {};
    132132  }
    133 
    134133  start() {
    135134    const {
     
    137136      nonce
    138137    } = this.settings;
    139 
    140138    if (!url || !nonce) {
    141139      return;
    142140    }
    143 
    144141    document.querySelectorAll('.bp-is-dismissible').forEach(notice => {
    145142      notice.addEventListener('click', event => {
    146143        event.preventDefault();
    147144        const noticeLink = event.target;
    148 
    149145        if (noticeLink.classList.contains('loading')) {
    150146          return;
    151         } // Prevent multiple clicks.
     147        }
    152148
     149        // Prevent multiple clicks.
     150        noticeLink.classList.add('loading');
    153151
    154         noticeLink.classList.add('loading'); // Set the notice ID & notice container.
    155 
     152        // Set the notice ID & notice container.
    156153        const {
    157154          notice_id
    158155        } = noticeLink.dataset;
    159         const noticeContainer = noticeLink.closest('.bp-notice-container'); // Set notice headers.
     156        const noticeContainer = noticeLink.closest('.bp-notice-container');
    160157
     158        // Set notice headers.
    161159        const noticeHeaders = new Headers({
    162160          'X-BP-Nonce': nonce
    163         }); // Set notice data.
     161        });
    164162
     163        // Set notice data.
    165164        const noticeData = new FormData();
    166165        noticeData.append('action', 'bp_dismiss_notice');
     
    176175            success
    177176          } = data;
    178 
    179177          if (success) {
    180178            noticeContainer.remove();
     179            if (0 === document.querySelectorAll('.bp-notice-container').length) {
     180              document.querySelector('#no-admin-notifications').classList.remove('hide');
     181            }
    181182          } else {
    182183            noticeLink.classList.remove('loading');
     
    186187    });
    187188  }
    188 
    189189};
    190190const settings = window.bpDismissibleAdminNoticesSettings || {};
    191191const bpDismissibleAdminNotices = new bp.DismissibleAdminNotices(settings);
    192 
    193192if ('loading' === document.readyState) {
    194193  document.addEventListener('DOMContentLoaded', bpDismissibleAdminNotices.start());
  • branches/11.0/src/bp-core/bp-core-functions.php

    r13377 r13615  
    48924892    return $latest_deprecated_functions_versions;
    48934893}
     4894
     4895/**
     4896 * Returns the list of unread Admin Notification IDs.
     4897 *
     4898 * @since 11.4.0
     4899 *
     4900 * @return array The list of unread Admin Notification IDs.
     4901 */
     4902function bp_core_get_unread_admin_notifications() {
     4903    return (array) bp_get_option( 'bp_unread_admin_notifications', array() );
     4904}
     4905
     4906/**
     4907 * Dismisses an Admin Notification.
     4908 *
     4909 * @since 11.4.0
     4910 *
     4911 * @param string $notification_id The Admin Notification to dismiss.
     4912 */
     4913function bp_core_dismiss_admin_notification( $notification_id = '' ) {
     4914    $unread    = bp_core_get_unread_admin_notifications();
     4915    $remaining = array_diff( $unread, array( $notification_id ) );
     4916    bp_update_option( 'bp_unread_admin_notifications', $remaining );
     4917}
     4918
     4919/**
     4920 * @since 11.4.0
     4921 *
     4922 * @return array The list of Admin notifications.
     4923 */
     4924function bp_core_get_admin_notifications() {
     4925    $unreads = bp_core_get_unread_admin_notifications();
     4926    if ( ! $unreads ) {
     4927        return array();
     4928    }
     4929
     4930    $admin_notifications = array(
     4931        'bp100-welcome-addons' => (object) array(
     4932            'id'      => 'bp100-welcome-addons',
     4933            'href'    => add_query_arg(
     4934                array(
     4935                    'tab' => 'bp-add-ons',
     4936                    'n'   => 'bp100-welcome-addons',
     4937                ),
     4938                bp_get_admin_url( 'plugin-install.php' )
     4939            ),
     4940            'text'    => __( 'Discover BuddyPress Add-ons', 'buddypress' ),
     4941            'title'   => __( 'Hello BuddyPress Add-ons!', 'buddypress' ),
     4942            'content' => __( 'Add-ons are features as Plugins or Blocks maintained by the BuddyPress development team & hosted on the WordPress.org plugins directory.', 'buddypress' ) .
     4943                         __( 'Thanks to this new tab inside your Dashboard screen to add plugins, you’ll be able to find them faster and eventually contribute to beta features early to give the BuddyPress development team your feedbacks.', 'buddypress' ),
     4944            'version' => 10.0,
     4945        ),
     4946        'bp114-prepare-for-rewrites' => (object) array(
     4947            'id'      => 'bp114-prepare-for-rewrites',
     4948            'href'    => add_query_arg(
     4949                array(
     4950                    'tab'  => 'bp-add-ons',
     4951                    'show' => 'bp-classic',
     4952                    'n'    => 'bp114-prepare-for-rewrites'
     4953                ),
     4954                bp_get_admin_url( 'plugin-install.php' )
     4955            ),
     4956            'text'    => __( 'Get The BP Classic Add-on', 'buddypress' ),
     4957            'title'   => __( 'Get ready for the brand-new BP Rewrites API!', 'buddypress' ),
     4958            'content' => __( 'Our next major version (12.0.0) will introduce several large changes that could be incompatible with your site\'s configuration. To prevent problems, we\'ve built the BP Classic Add-on, which you may want to proactively install if any of the following cases:', 'buddypress' ) . '<br><br>' .
     4959                '<strong>' . __( 'Some of your BuddyPress plugins have not been updated lately.', 'buddypress' ) . '</strong><br>' .
     4960                __( 'BuddyPress 12.0.0 introduces the BP Rewrites API, which completely changes the way BuddyPress URLs are built and routed. This fundamental change requires most BuddyPress plugins to update how they deal with BuddyPress URLs. If your BuddyPress plugins have not been updated in the last few months, they are probably not ready for BuddyPress 12.0.0.', 'buddypress' ) . '<br><br>' .
     4961                '<strong>' . __( 'You are still using the BP Default theme.', 'buddypress' ) . '</strong><br><br>' .
     4962                '<strong>' . __( 'You still use a BP Legacy Widget.', 'buddypress' ) . '</strong><br><br>' .
     4963                __( 'If any of the above items are true, we strongly advise you to install and activate the Classic Add-on before updating to BuddyPress 12.0.0.', 'buddypress' ),
     4964                'version' => 11.4,
     4965        )
     4966    );
     4967
     4968    // Only keep unread notifications.
     4969    foreach ( array_keys( $admin_notifications ) as $notification_id ) {
     4970        if ( ! in_array( $notification_id, $unreads, true ) ) {
     4971            unset( $admin_notifications[ $notification_id ] );
     4972        }
     4973    }
     4974
     4975    return $admin_notifications;
     4976}
  • branches/11.0/src/bp-core/bp-core-options.php

    r12893 r13615  
    106106        'widget_bp_groups_widget'                    => false,
    107107        'widget_bp_messages_sitewide_notices_widget' => false,
     108
     109        /* Admin Notifications **************************************/
     110        'bp_unread_admin_notifications' => array( 'bp114-prepare-for-rewrites' ),
    108111    );
    109112
  • branches/11.0/src/bp-core/bp-core-update.php

    r13304 r13615  
    288288
    289289        // Version 11.0.0.
    290         if ( $raw_db_version < 13271 ){
     290        if ( $raw_db_version < 13271 ) {
    291291            bp_update_to_11_0();
    292292        }
    293293
     294        // Version 11.4.0.
     295        if ( $raw_db_version < 13408 ) {
     296            bp_update_to_11_4();
     297        }
    294298    }
    295299
     
    792796
    793797    return $new_emails;
     798}
     799
     800/**
     801 * 11.4.0 update routine.
     802 *
     803 * @since 11.4.0
     804 */
     805function bp_update_to_11_4() {
     806    $unread = array( 'bp114-prepare-for-rewrites' );
     807
     808    // Check if 10.0 notice was dismissed.
     809    $old_dismissed = (bool) bp_get_option( 'bp-dismissed-notice-bp100-welcome-addons', false );
     810    if ( ! $old_dismissed ) {
     811        $unread[] = 'bp100-welcome-addons';
     812    }
     813
     814    // Remove the dismissible option.
     815    bp_delete_option( 'bp-dismissed-notice-bp100-welcome-addons' );
     816
     817    // Create unread Admin notifications.
     818    bp_update_option( 'bp_unread_admin_notifications', $unread );
    794819}
    795820
  • branches/11.0/src/bp-core/classes/class-bp-admin.php

    r13613 r13615  
    298298        $this->submenu_pages['settings']['bp-settings'] = $bp_settings_page;
    299299        $hooks[]                                        = $bp_settings_page;
     300
     301        // Admin notifications.
     302        $bp_admin_notifications = add_submenu_page(
     303            $this->settings_page,
     304            __( 'BuddyPress Admin Notifications', 'buddypress' ),
     305            __( 'BuddyPress Admin Notifications', 'buddypress' ),
     306            $this->capability,
     307            'bp-admin-notifications',
     308            array( $this, 'admin_notifications' )
     309        );
     310
     311        $this->submenu_pages['settings']['bp-admin-notifications'] = $bp_admin_notifications;
     312        $hooks[]                                                   = $bp_admin_notifications;
    300313
    301314        // Credits.
     
    626639
    627640        // Settings pages.
    628         remove_submenu_page( $this->settings_page, 'bp-page-settings' );
    629         remove_submenu_page( $this->settings_page, 'bp-settings'      );
    630         remove_submenu_page( $this->settings_page, 'bp-credits'       );
     641        remove_submenu_page( $this->settings_page, 'bp-page-settings'       );
     642        remove_submenu_page( $this->settings_page, 'bp-settings'            );
     643        remove_submenu_page( $this->settings_page, 'bp-credits'             );
     644        remove_submenu_page( $this->settings_page, 'bp-admin-notifications' );
    631645
    632646        // Network Admin Tools.
     
    15411555     */
    15421556    public function display_addons_table() {
    1543         $notice_id = 'bp100-welcome-addons';
    1544         $dismissed = bp_get_option( "bp-dismissed-notice-{$notice_id}", false );
    1545 
    1546         if ( ! $dismissed ) {
    1547             // Enqueue the Script to Ajax Dismiss an Admin notice.
    1548             wp_enqueue_script( 'bp-dismissible-admin-notices' );
    1549 
    1550             ?>
    1551             <div class="bp-welcome-panel bp-notice-container">
    1552                 <a class="bp-welcome-panel-close bp-is-dismissible" href="#" data-notice_id="<?php echo esc_attr( $notice_id ); ?>" aria-label="<?php esc_attr_e( 'Dismiss the welcome panel', 'buddypress' ); ?>"><?php esc_html_e( 'Dismiss', 'buddypress' ); ?></a>
    1553                 <div class="bp-welcome-panel-content">
    1554                     <h2><span class="bp-badge"></span> <?php esc_html_e( 'Hello BuddyPress Add-ons!', 'buddypress' ); ?></h2>
    1555                     <p class="about-description">
    1556                         <?php esc_html_e( 'Add-ons are features as Plugins or Blocks maintained by the BuddyPress development team & hosted on the WordPress.org plugins directory.', 'buddypress' ); ?>
    1557                         <?php esc_html_e( 'Thanks to this new tab inside your Dashboard screen to add plugins, you’ll be able to find them faster and eventually contribute to beta features early to give the BuddyPress development team your feedbacks.', 'buddypress' ); ?>
    1558                     </p>
    1559                 </div>
    1560             </div>
    1561             <?php
    1562         }
    1563 
    15641557        if ( isset( $_GET['show'] ) && 'bp-classic' === $_GET['show'] ) {
    15651558            wp_add_inline_script(
     
    15771570        }
    15781571
     1572        if ( isset( $_GET['n'] ) && $_GET['n'] ) {
     1573            $notification_id = sanitize_text_field( wp_unslash( $_GET['n'] ) );
     1574            bp_core_dismiss_admin_notification( $notification_id );
     1575        }
     1576
    15791577        // Display the "buddypress" favorites.
    15801578        display_plugins_table();
    15811579    }
     1580
     1581    /**
     1582     * Display the Admin Notifications screen.
     1583     *
     1584     * @since 11.4.0
     1585     */
     1586    public function admin_notifications() {
     1587        bp_core_admin_tabbed_screen_header( __( 'BuddyPress Settings', 'buddypress' ), __( 'Notifications', 'buddypress' ) );
     1588        $notifications = bp_core_get_admin_notifications();
     1589        $class         = '';
     1590
     1591        if ( $notifications ) {
     1592            wp_enqueue_script( 'bp-dismissible-admin-notices' );
     1593            $notifications = array_reverse( bp_sort_by_key( $notifications, 'version', 'num' ) );
     1594            $class         = 'hide';
     1595        }
     1596        ?>
     1597        <div class="buddypress-body admin-notifications">
     1598            <table id="no-admin-notifications" class="form-table <?php echo sanitize_html_class( $class ); ?>" role="presentation">
     1599                <tbody>
     1600                    <tr><td><?php esc_html_e( 'No new Admin Notfications', 'buddypress' ); ?></td><tr>
     1601                </tbody>
     1602            </table>
     1603
     1604            <?php if ( $notifications ) : foreach ( $notifications as $notification ) : ?>
     1605                <?php bp_core_admin_format_notifications( $notification ); ?>
     1606            <?php endforeach; endif; ?>
     1607        </div>
     1608        <?php
     1609    }
    15821610}
    15831611endif; // End class_exists check.
  • branches/11.0/src/bp-core/css/admin-bar-rtl.css

    r12877 r13615  
    4747}
    4848
     49#wpadminbar .quicklinks li#wp-admin-bar-bp-notifications #ab-pending-notifications.alert.admin-type {
     50    background-color: #d84800;
     51}
     52
    4953#wpadminbar .quicklinks li#wp-admin-bar-bp-notifications > a {
    5054    padding: 0 0.5em;
  • branches/11.0/src/bp-core/css/admin-bar.css

    r12877 r13615  
    4747}
    4848
     49#wpadminbar .quicklinks li#wp-admin-bar-bp-notifications #ab-pending-notifications.alert.admin-type {
     50    background-color: #d84800;
     51}
     52
    4953#wpadminbar .quicklinks li#wp-admin-bar-bp-notifications > a {
    5054    padding: 0 0.5em;
  • branches/11.0/src/bp-members/admin/js/admin.js

    r13164 r13615  
    121121// Use the bp global.
    122122window.bp = window.bp || {};
     123
    123124/**
    124125 * Clears the checked/selected options of a radio button or a multiple select.
     
    128129 * @returns {void}
    129130 */
    130 
    131131bp.clear = container => {
    132132  const optionsContainer = document.getElementById(container);
    133 
    134133  if (!optionsContainer) {
    135134    return;
    136135  }
    137 
    138136  const checkedRadio = optionsContainer.querySelector('input:checked');
    139137  const allOptions = optionsContainer.querySelectorAll('option');
    140 
    141138  if (checkedRadio) {
    142139    checkedRadio.checked = '';
    143140  }
    144 
    145141  if (allOptions) {
    146142    allOptions.forEach(option => {
     
    149145  }
    150146};
    151 
    152147document.querySelectorAll('.visibility-toggle-link').forEach(button => {
    153148  button.addEventListener('click', event => {
     
    155150    const changeButton = event.target;
    156151    const changeButtonContainer = changeButton.closest('.field-visibility-settings-toggle');
    157     const settingsContainer = changeButtonContainer.nextElementSibling; // Hides the "Change" button.
     152    const settingsContainer = changeButtonContainer.nextElementSibling;
    158153
     154    // Hides the "Change" button.
    159155    changeButton.setAttribute('aria-expanded', true);
    160     changeButtonContainer.style.display = 'none'; // Displays the settings visibility container.
     156    changeButtonContainer.style.display = 'none';
    161157
     158    // Displays the settings visibility container.
    162159    settingsContainer.style.display = 'block';
    163160  });
     
    169166    const settingsContainer = closeButton.closest('.field-visibility-settings');
    170167    const changeButtonContainer = settingsContainer.previousElementSibling;
    171     const currentVisibility = settingsContainer.querySelector('input:checked').nextElementSibling.innerHTML; // Closes the visibility settings options.
     168    const currentVisibility = settingsContainer.querySelector('input:checked').nextElementSibling.innerHTML;
    172169
    173     settingsContainer.style.display = 'none'; // Displays the current visibility.
     170    // Closes the visibility settings options.
     171    settingsContainer.style.display = 'none';
    174172
     173    // Displays the current visibility.
    175174    changeButtonContainer.querySelector('.visibility-toggle-link').setAttribute('aria-expanded', false);
    176175    changeButtonContainer.querySelector('.current-visibility-level').innerHTML = currentVisibility;
  • branches/11.0/src/bp-members/bp-members-adminbar.php

    r12945 r13615  
    154154 * Build the "Notifications" dropdown.
    155155 *
     156 * @since 11.4.0
     157 */
     158function bp_members_admin_bar_notifications_dropdown( $notifications = array(), $menu_link = '', $type = 'members' ) {
     159    if ( ! $menu_link || ( 'admin' === $type && empty( $notifications ) ) ) {
     160        return false;
     161    }
     162
     163    global $wp_admin_bar;
     164
     165    $count       = 0;
     166    $alert_class = array( 'count', 'no-alert' );
     167
     168    if ( ! empty( $notifications ) ) {
     169        $count       = number_format_i18n( count( $notifications ) );
     170        $alert_class = array( 'pending-count', 'alert' );
     171
     172        if ( 'admin' === $type ) {
     173            $count = '!';
     174        }
     175    };
     176
     177    $alert_class[] = $type . '-type';
     178    $menu_title    = sprintf(
     179        '<span id="ab-pending-notifications" class="%1$s">%2$s</span>',
     180        implode( ' ', array_map( 'sanitize_html_class', $alert_class ) ),
     181        $count
     182    );
     183
     184    // Add the top-level Notifications button.
     185    $wp_admin_bar->add_node( array(
     186        'parent' => 'top-secondary',
     187        'id'     => 'bp-notifications',
     188        'title'  => $menu_title,
     189        'href'   => $menu_link,
     190    ) );
     191
     192    if ( ! empty( $notifications ) ) {
     193        foreach ( (array) $notifications as $notification ) {
     194            $wp_admin_bar->add_node( array(
     195                'parent' => 'bp-notifications',
     196                'id'     => 'notification-' . $notification->id,
     197                'title'  => $notification->content,
     198                'href'   => $notification->href,
     199            ) );
     200        }
     201    } else {
     202        $wp_admin_bar->add_node( array(
     203            'parent' => 'bp-notifications',
     204            'id'     => 'no-notifications',
     205            'title'  => __( 'No new notifications', 'buddypress' ),
     206            'href'   => $menu_link,
     207        ) );
     208    }
     209
     210    return true;
     211}
     212
     213/**
     214 * Build the Admin or Members "Notifications" dropdown.
     215 *
    156216 * @since 1.5.0
    157217 *
     
    159219 */
    160220function bp_members_admin_bar_notifications_menu() {
    161 
    162     // Bail if notifications is not active.
    163     if ( ! bp_is_active( 'notifications' ) ) {
    164         return false;
    165     }
    166 
    167     bp_notifications_toolbar_menu();
     221    $admins_notifications = array();
     222    $capability           = 'manage_options';
     223
     224    if ( bp_core_do_network_admin() ) {
     225        $capability = 'manage_network_options';
     226    }
     227
     228    if ( bp_current_user_can( $capability ) ) {
     229        $notifications = bp_core_get_admin_notifications();
     230
     231        if ( $notifications ) {
     232            $menu_link = esc_url( bp_get_admin_url( add_query_arg( 'page', 'bp-admin-notifications', 'admin.php' ) ) );
     233            $count     = count( $notifications );
     234
     235            $notifications = array(
     236                (object) array(
     237                    'id'      => 'bp-admin-notifications',
     238                    'href'    => $menu_link,
     239                    'content' => sprintf(
     240                        /* translators: %s: the number of admin notifications */
     241                        _n( 'You have %s new important admin notification.', 'You have %s new important admin notifications.', $count, 'buddypress' ),
     242                        number_format_i18n( $count )
     243                    ),
     244                ),
     245            );
     246
     247            return bp_members_admin_bar_notifications_dropdown( $notifications, $menu_link, 'admin' );
     248        }
     249    }
     250
     251    // Use Members notifications if the component is active.
     252    if ( bp_is_active( 'notifications' ) ) {
     253        return bp_notifications_toolbar_menu();
     254    }
    168255}
    169256add_action( 'admin_bar_menu', 'bp_members_admin_bar_notifications_menu', 90 );
  • branches/11.0/src/bp-notifications/bp-notifications-adminbar.php

    r13091 r13615  
    1818 * @since 1.9.0
    1919 *
     20 * @global WP_Admin_Bar $wp_admin_bar The WordPress object implementing a Toolbar API.
     21 *
    2022 * @return bool
    2123 */
    2224function bp_notifications_toolbar_menu() {
    23     global $wp_admin_bar;
    24 
    2525    if ( ! is_user_logged_in() ) {
    2626        return false;
     
    2828
    2929    $notifications = bp_notifications_get_notifications_for_user( bp_loggedin_user_id(), 'object' );
    30     $count         = ! empty( $notifications ) ? count( $notifications ) : 0;
    31     $alert_class   = (int) $count > 0 ? 'pending-count alert' : 'count no-alert';
    32     $menu_title    = '<span id="ab-pending-notifications" class="' . $alert_class . '">' . number_format_i18n( $count ) . '</span>';
    3330    $menu_link     = trailingslashit( bp_loggedin_user_domain() . bp_get_notifications_slug() );
    3431
    35     // Add the top-level Notifications button.
    36     $wp_admin_bar->add_node( array(
    37         'parent' => 'top-secondary',
    38         'id'     => 'bp-notifications',
    39         'title'  => $menu_title,
    40         'href'   => $menu_link,
    41     ) );
    42 
    43     if ( ! empty( $notifications ) ) {
    44         foreach ( (array) $notifications as $notification ) {
    45             $wp_admin_bar->add_node( array(
    46                 'parent' => 'bp-notifications',
    47                 'id'     => 'notification-' . $notification->id,
    48                 'title'  => $notification->content,
    49                 'href'   => $notification->href,
    50             ) );
    51         }
    52     } else {
    53         $wp_admin_bar->add_node( array(
    54             'parent' => 'bp-notifications',
    55             'id'     => 'no-notifications',
    56             'title'  => __( 'No new notifications', 'buddypress' ),
    57             'href'   => $menu_link,
    58         ) );
    59     }
    60 
    61     return true;
     32    return bp_members_admin_bar_notifications_dropdown( $notifications, $menu_link );
    6233}
    63 add_action( 'admin_bar_menu', 'bp_members_admin_bar_notifications_menu', 90 );
  • branches/11.0/src/class-buddypress.php

    r13610 r13615  
    351351
    352352        $this->version    = '11.3.2';
    353         $this->db_version = 13271;
     353        $this->db_version = 13408;
    354354
    355355        /** Loading */
  • branches/11.0/src/js/bp-core/admin/js/dismissible-admin-notices.js

    r13164 r13615  
    5656                    if ( success ) {
    5757                        noticeContainer.remove();
     58
     59                        if ( 0 === document.querySelectorAll( '.bp-notice-container' ).length ) {
     60                            document.querySelector( '#no-admin-notifications' ).classList.remove( 'hide' );
     61                        }
    5862                    } else {
    5963                        noticeLink.classList.remove( 'loading' );
Note: See TracChangeset for help on using the changeset viewer.