Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
10/19/2023 11:34:45 PM (20 months 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

Props dcavins

Closes https://github.com/buddypress/buddypress/pull/176
See #9007 (trunk)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-core/classes/class-bp-admin.php

    r13595 r13614  
    304304        $this->submenu_pages['settings']['bp-settings'] = $bp_settings_page;
    305305        $hooks[]                                        = $bp_settings_page;
     306
     307        // Admin notifications.
     308        $bp_admin_notifications = add_submenu_page(
     309            $this->settings_page,
     310            __( 'BuddyPress Admin Notifications', 'buddypress' ),
     311            __( 'BuddyPress Admin Notifications', 'buddypress' ),
     312            $this->capability,
     313            'bp-admin-notifications',
     314            array( $this, 'admin_notifications' )
     315        );
     316
     317        $this->submenu_pages['settings']['bp-admin-notifications'] = $bp_admin_notifications;
     318        $hooks[]                                                   = $bp_admin_notifications;
    306319
    307320        // Credits.
     
    642655
    643656        // Settings pages.
    644         remove_submenu_page( $this->settings_page, 'bp-rewrites' );
    645         remove_submenu_page( $this->settings_page, 'bp-settings' );
    646         remove_submenu_page( $this->settings_page, 'bp-credits'  );
     657        remove_submenu_page( $this->settings_page, 'bp-rewrites'            );
     658        remove_submenu_page( $this->settings_page, 'bp-settings'            );
     659        remove_submenu_page( $this->settings_page, 'bp-credits'             );
     660        remove_submenu_page( $this->settings_page, 'bp-admin-notifications' );
    647661
    648662        // Network Admin Tools.
     
    15561570     */
    15571571    public function display_addons_table() {
    1558         $notice_id = 'bp100-welcome-addons';
    1559         $dismissed = bp_get_option( "bp-dismissed-notice-{$notice_id}", false );
    1560 
    1561         if ( ! $dismissed ) {
    1562             // Enqueue the Script to Ajax Dismiss an Admin notice.
    1563             wp_enqueue_script( 'bp-dismissible-admin-notices' );
    1564 
    1565             ?>
    1566             <div class="bp-welcome-panel bp-notice-container">
    1567                 <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>
    1568                 <div class="bp-welcome-panel-content">
    1569                     <h2><span class="bp-badge"></span> <?php esc_html_e( 'Hello BuddyPress Add-ons!', 'buddypress' ); ?></h2>
    1570                     <p class="about-description">
    1571                         <?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' ); ?>
    1572                         <?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' ); ?>
    1573                     </p>
    1574                 </div>
    1575             </div>
    1576             <?php
    1577         }
    1578 
    15791572        if ( isset( $_GET['show'] ) && 'bp-classic' === $_GET['show'] ) {
    15801573            wp_add_inline_script(
     
    15921585        }
    15931586
     1587        if ( isset( $_GET['n'] ) && $_GET['n'] ) {
     1588            $notification_id = sanitize_text_field( wp_unslash( $_GET['n'] ) );
     1589            bp_core_dismiss_admin_notification( $notification_id );
     1590        }
     1591
    15941592        // Display the "buddypress" favorites.
    15951593        display_plugins_table();
    15961594    }
     1595
     1596    /**
     1597     * Display the Admin Notifications screen.
     1598     *
     1599     * @since 11.4.0
     1600     */
     1601    public function admin_notifications() {
     1602        bp_core_admin_tabbed_screen_header( __( 'BuddyPress Settings', 'buddypress' ), __( 'Notifications', 'buddypress' ) );
     1603        $notifications = bp_core_get_admin_notifications();
     1604        $class         = '';
     1605
     1606        if ( $notifications ) {
     1607            wp_enqueue_script( 'bp-dismissible-admin-notices' );
     1608            $notifications = array_reverse( bp_sort_by_key( $notifications, 'version', 'num' ) );
     1609            $class         = 'hide';
     1610        }
     1611        ?>
     1612        <div class="buddypress-body admin-notifications">
     1613            <table id="no-admin-notifications" class="form-table <?php echo sanitize_html_class( $class ); ?>" role="presentation">
     1614                <tbody>
     1615                    <tr><td><?php esc_html_e( 'No new Admin Notfications', 'buddypress' ); ?></td><tr>
     1616                </tbody>
     1617            </table>
     1618
     1619            <?php if ( $notifications ) : foreach ( $notifications as $notification ) : ?>
     1620                <?php bp_core_admin_format_notifications( $notification ); ?>
     1621            <?php endforeach; endif; ?>
     1622        </div>
     1623        <?php
     1624    }
    15971625}
    15981626endif; // End class_exists check.
Note: See TracChangeset for help on using the changeset viewer.