Skip to:
Content

BuddyPress.org

Ticket #4802: 4802.diff

File 4802.diff, 6.8 KB (added by imath, 13 years ago)
  • bp-templates/bp-legacy/buddypress-functions.php

     
    9696                add_action( 'bp_enqueue_scripts', array( $this, 'enqueue_scripts'  ) ); // Enqueue theme JS
    9797                add_filter( 'bp_enqueue_scripts', array( $this, 'localize_scripts' ) ); // Enqueue theme script localization
    9898                add_action( 'bp_head',            array( $this, 'head_scripts'     ) ); // Output some extra JS in the <head>
     99                add_action( 'dynamic_sidebar',    array( $this, 'get_notices'      ), 10, 1 ); // Output the admin notices if any
    99100
    100101                /** Buttons ***********************************************************/
    101102
     
    284285
    285286        <?php
    286287        }
     288       
     289        /**
     290         * Hooks dynamic_sidebar to reference a new hook for Admin notices
     291         *
     292         * @param array $widget_array the first widget data
     293         * @uses do_action_ref_array to reference bp_legacy_get_notices new hook
     294         */
     295        public function get_notices( $widget_array = false ) {
     296                do_action_ref_array( 'bp_legacy_get_notices', array( $widget_array ) );
     297        }
    287298
    288299        /**
    289300         * Load localizations for topic script
     
    12001211
    12011212        exit;
    12021213}
     1214
     1215/**
     1216 * formats the notices in order to respect theme's widget structure
     1217 *
     1218 * @param array $args (the widget structure)
     1219 * @uses wp_parse_args() to merge with the theme's widget structure
     1220 * @uses bp_message_get_notices() to output the notices
     1221 */
     1222function bp_legacy_format_notices( $args = array() ) {
     1223       
     1224        $defaults = array(
     1225                'before_widget' => '<li id="%1$s" class="widget %2$s">',
     1226                'after_widget' => "</li>\n"
     1227        );
     1228
     1229        $r = wp_parse_args( $args, $defaults );
     1230        extract( $r );
     1231       
     1232        $before_widget = sprintf( $before_widget, 'bp-sidebar-notice', '' );
     1233       
     1234        /*
     1235        I added this 2 vars which default to false to bp_message_get_notices
     1236        in order to add an id to the notices container so that we can style it
     1237        as in the sidebar, the identifier #buddypress is not available
     1238        */
     1239        bp_message_get_notices( $before_widget, $after_widget );
     1240
     1241}
     1242
     1243/**
     1244 * Eventually prints once (and only) the notices in the sidebar
     1245 *
     1246 * using the new hook bp_legacy_get_notices to check did_action
     1247 * this way if someone else hooks dynamic_sidebar, it won't interfere
     1248 * in our amount of actions to count.
     1249 *
     1250 * @param array $widget_array
     1251 * @global $wp_registered_sidebars to get the theme's widget structure
     1252 * @uses did_action() to check the number of time bp_legacy_get_notices is hooked
     1253 * @uses is_admin() to stop the process if we're in backend
     1254 * @uses bp_is_active() to stop the process if messages component is not active
     1255 * @uses bp_legacy_format_notices() to respect theme's widget structure to print notices
     1256 */
     1257function bp_legacy_print_notices( $widget_array = false ) {
     1258        global $wp_registered_sidebars;
     1259       
     1260        $did_action = did_action( 'bp_legacy_get_notices' );
     1261       
     1262        if( is_admin() )
     1263                return;
     1264               
     1265        if ( !bp_is_active( 'messages' ) )
     1266                return;
     1267       
     1268        // this way we print the notice before the first widget and not at every widget.
     1269        if( $did_action <= 1 ) {
     1270               
     1271                $notices_args = array();
     1272               
     1273                if( count( $wp_registered_sidebars ) >= 1 ) {
     1274                       
     1275                        $widget_structure = array_slice( $wp_registered_sidebars, 0, 1 );
     1276                        $widget_sisebar_id = key( $widget_structure );
     1277                        $notice_args = $widget_structure[$widget_sisebar_id];
     1278                }
     1279               
     1280                bp_legacy_format_notices( $notice_args );
     1281        }
     1282}
     1283
     1284add_action( 'bp_legacy_get_notices', 'bp_legacy_print_notices', 10, 1 );
     1285 No newline at end of file
  • bp-templates/bp-legacy/css/buddypress.css

     
    506506#buddypress div#message.updated {
    507507        clear: both;
    508508}
    509 #buddypress div#message p {
     509#buddypress div#message p, #bp-sidebar-notice div#message p {
    510510        font-size: 90%;
    511511        display: block;
    512512        padding: 10px 15px;
     
    10031003        font-weight: bold;
    10041004}
    10051005#buddypress span.activity,
    1006 #buddypress div#message p {
     1006#buddypress div#message p, #bp-sidebar-notice div#message p {
    10071007        border: 1px solid #e1ca82;
    10081008        -moz-border-radius: 3px;
    10091009        -webkit-border-radius: 3px;
  • bp-messages/bp-messages-template.php

     
    584584                return apply_filters( 'bp_get_messages_slug', $bp->messages->slug );
    585585        }
    586586
    587 function bp_message_get_notices() {
     587/**
     588 * Displays admin notices in the sidebar
     589 *
     590 * @param string $before_notice used by bp_legacy_format_notices to add before_widget html
     591 * @param string $after_notice used by bp_legacy_format_notices to add after_widget html
     592 */
     593function bp_message_get_notices( $before_notice = false, $after_notice = false ) {
    588594        global $userdata;
    589595
    590596        $notice = BP_Messages_Notice::get_active();
     
    599605
    600606        if ( is_array($closed_notices) ) {
    601607                if ( !in_array( $notice->id, $closed_notices ) && $notice->id ) {
     608                        echo $before_notice;
    602609                        ?>
    603610                        <div id="message" class="info notice" rel="n-<?php echo $notice->id ?>">
    604611                                <p>
     
    608615                                </p>
    609616                        </div>
    610617                        <?php
     618                        echo $after_notice;
    611619                }
    612620        }
    613621}
  • bp-messages/bp-messages-screens.php

     
    160160
    161161        if ( !$new_messages = bp_get_user_meta( bp_displayed_user_id(), 'notification_messages_new_message', true ) )
    162162                $new_messages = 'yes';
     163       
     164        ?>
    163165
    164         if ( !$new_notices = bp_get_user_meta( bp_displayed_user_id(), 'notification_messages_new_notice', true ) )
    165                 $new_notices  = 'yes'; ?>
    166 
    167166        <table class="notification-settings" id="messages-notification-settings">
    168167                <thead>
    169168                        <tr>
     
    181180                                <td class="yes"><input type="radio" name="notifications[notification_messages_new_message]" value="yes" <?php checked( $new_messages, 'yes', true ) ?>/></td>
    182181                                <td class="no"><input type="radio" name="notifications[notification_messages_new_message]" value="no" <?php checked( $new_messages, 'no', true ) ?>/></td>
    183182                        </tr>
    184                         <tr id="messages-notification-settings-new-site-notice">
    185                                 <td></td>
    186                                 <td><?php _e( 'A new site notice is posted', 'buddypress' ) ?></td>
    187                                 <td class="yes"><input type="radio" name="notifications[notification_messages_new_notice]" value="yes" <?php checked( $new_notices, 'yes', true ) ?>/></td>
    188                                 <td class="no"><input type="radio" name="notifications[notification_messages_new_notice]" value="no" <?php checked( $new_notices, 'no', true ) ?>/></td>
    189                         </tr>
    190183
    191184                        <?php do_action( 'messages_screen_notification_settings' ) ?>
    192185                </tbody>