Skip to:
Content

BuddyPress.org

Changeset 9171


Ignore:
Timestamp:
11/25/2014 08:45:16 AM (6 years ago)
Author:
djpaul
Message:

Core: admin notice functions now support a "type".

The type parameter is used to set a CSS class when the notices are
rendered in wp-admin. It defaults to “updated”, which is the same as
the previous behaviour, which is visually styled as the box with the
green border.

Fixes #6041

File:
1 edited

Legend:

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

    r9113 r9171  
    120120 * boxes.
    121121 *
    122  * @package BuddyPress Core
    123122 * @since BuddyPress (1.5)
    124123 *
     
    139138    }
    140139
    141     // Get the admin notices
    142     $admin_notices = buddypress()->admin->notices;
    143 
    144     // Show the messages
    145     if ( !empty( $admin_notices ) ) : ?>
    146 
    147         <div id="message" class="updated fade">
    148 
    149             <?php foreach ( $admin_notices as $notice ) : ?>
    150 
    151                 <p><?php echo $notice; ?></p>
    152 
    153             <?php endforeach; ?>
    154 
    155         </div>
    156 
    157     <?php endif;
     140    $notice_types = array();
     141    foreach ( buddypress()->admin->notices as $notice ) {
     142        $notice_types[] = $notice['type'];
     143    }
     144    $notice_types = array_unique( $notice_types );
     145
     146    foreach ( $notice_types as $type ) {
     147        $notices = wp_list_filter( buddypress()->admin->notices, array( 'type' => $type ) );
     148        printf( '<div id="message" class="fade %s">', sanitize_html_class( $type ) );
     149
     150        foreach ( $notices as $notice ) {
     151            printf( '<p>%s</p>', $notice['message'] );
     152        }
     153
     154        printf( '</div>' );
     155    }
    158156}
    159157add_action( 'admin_notices',         'bp_core_print_admin_notices' );
     
    167165 * loaded in time.
    168166 *
    169  * @package BuddyPress Core
    170167 * @since BuddyPress (1.5)
    171168 *
    172  * @param string $notice The notice you are adding to the queue
    173  */
    174 function bp_core_add_admin_notice( $notice = '' ) {
     169 * @param string $notice The notice you are adding to the queue.
     170 * @param string $type The notice type; optional. Usually either "updated" or "error".
     171 */
     172function bp_core_add_admin_notice( $notice = '', $type = 'updated' ) {
    175173
    176174    // Do not add if the notice is empty
     
    185183
    186184    // Add the notice
    187     buddypress()->admin->notices[] = $notice;
     185    buddypress()->admin->notices[] = array(
     186        'message' => $notice,
     187        'type'    => $type,
     188    );
    188189}
    189190
Note: See TracChangeset for help on using the changeset viewer.