Skip to:
Content

BuddyPress.org

Changeset 7552


Ignore:
Timestamp:
11/09/2013 08:53:27 PM (13 years ago)
Author:
johnjamesjacoby
Message:

Clean up admin-notice code. Add $notices variable to BP_Admin class to help avoid debug notices.

Location:
trunk/bp-core
Files:
2 edited

Legend:

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

    r7427 r7552  
    121121 */
    122122function bp_core_print_admin_notices() {
    123         $bp = buddypress();
    124123
    125124        // Only the super admin should see messages
    126         if ( !bp_current_user_can( 'bp_moderate' ) )
    127                 return;
    128 
    129         // On multisite installs, don't show on the Site Admin of a non-root blog, unless
    130         // do_network_admin is overridden
    131         if ( is_multisite() && bp_core_do_network_admin() && !bp_is_root_blog() )
    132                 return;
     125        if ( ! bp_current_user_can( 'bp_moderate' ) ) {
     126                return;
     127        }
     128
     129        // On multisite installs, don't show on a non-root blog, unless
     130        // 'do_network_admin' is overridden.
     131        if ( is_multisite() && bp_core_do_network_admin() && ! bp_is_root_blog() ) {
     132                return;
     133        }
     134
     135        // Get the admin notices
     136        $admin_notices = buddypress()->admin->notices;
    133137
    134138        // Show the messages
    135         if ( !empty( $bp->admin->notices ) ) {
    136                 ?>
     139        if ( !empty( $admin_notices ) ) : ?>
     140
    137141                <div id="message" class="updated fade">
    138                 <?php foreach ( $bp->admin->notices as $notice ) : ?>
    139                                 <p><?php echo $notice ?></p>
    140                 <?php endforeach ?>
     142
     143                        <?php foreach ( $admin_notices as $notice ) : ?>
     144
     145                                <p><?php echo $notice; ?></p>
     146
     147                        <?php endforeach; ?>
     148
    141149                </div>
    142                 <?php
    143         }
     150
     151        <?php endif;
    144152}
    145153add_action( 'admin_notices',         'bp_core_print_admin_notices' );
     
    158166 * @param string $notice The notice you are adding to the queue
    159167 */
    160 function bp_core_add_admin_notice( $notice ) {
    161         $bp = buddypress();
    162 
    163         if ( empty( $bp->admin->notices ) ) {
    164                 $bp->admin->notices = array();
    165         }
    166 
    167         $bp->admin->notices[] = $notice;
     168function bp_core_add_admin_notice( $notice = '' ) {
     169
     170        // Do not add if the notice is empty
     171        if ( empty( $notice ) ) {
     172                return;
     173        }
     174
     175        // Double check the object before referencing it
     176        if ( ! isset( buddypress()->admin->notices ) ) {
     177                buddypress()->admin->notices = array();
     178        }
     179
     180        // Add the notice
     181        buddypress()->admin->notices[] = $notice;
    168182}
    169183
     
    187201
    188202        // Only the super admin gets warnings
    189         if ( !bp_current_user_can( 'bp_moderate' ) )
    190                 return;
     203        if ( ! bp_current_user_can( 'bp_moderate' ) ) {
     204                return;
     205        }
    191206
    192207        // On multisite installs, don't load on a non-root blog, unless do_network_admin is overridden
    193         if ( is_multisite() && bp_core_do_network_admin() && !bp_is_root_blog() )
    194                 return;
     208        if ( is_multisite() && bp_core_do_network_admin() && !bp_is_root_blog() ) {
     209                return;
     210        }
    195211
    196212        /**
     
    210226         * Are pretty permalinks enabled?
    211227         */
    212         if ( isset( $_POST['permalink_structure'] ) )
    213                 return;
     228        if ( isset( $_POST['permalink_structure'] ) ) {
     229                return;
     230        }
    214231
    215232        if ( empty( $wp_rewrite->permalink_structure ) ) {
     
    248265
    249266        // On the first admin screen after a new installation, this isn't set, so grab it to supress a misleading error message.
    250         if ( empty( $bp->pages->members ) )
     267        if ( empty( $bp->pages->members ) ) {
    251268                $bp->pages = bp_core_get_directory_pages();
     269        }
    252270
    253271        foreach( $wp_page_components as $component ) {
  • trunk/bp-core/bp-core-admin.php

    r7455 r7552  
    6060         */
    6161        public $js_url = '';
     62
     63        /** Other *****************************************************************/
     64
     65        /**
     66         * Notices used for user feedback, like saving settings.
     67         *
     68         * @var array()
     69         */
     70        public $notices = array();
    6271
    6372        /** Methods ***************************************************************/
Note: See TracChangeset for help on using the changeset viewer.