Changeset 13614 for trunk/src/bp-members/bp-members-adminbar.php
- Timestamp:
- 10/19/2023 11:34:45 PM (3 years ago)
- File:
-
- 1 edited
-
trunk/src/bp-members/bp-members-adminbar.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bp-members/bp-members-adminbar.php
r13503 r13614 168 168 * Build the "Notifications" dropdown. 169 169 * 170 * @since 11.4.0 171 */ 172 function bp_members_admin_bar_notifications_dropdown( $notifications = array(), $menu_link = '', $type = 'members' ) { 173 if ( ! $menu_link || ( 'admin' === $type && empty( $notifications ) ) ) { 174 return false; 175 } 176 177 global $wp_admin_bar; 178 179 $count = 0; 180 $alert_class = array( 'count', 'no-alert' ); 181 182 if ( ! empty( $notifications ) ) { 183 $count = number_format_i18n( count( $notifications ) ); 184 $alert_class = array( 'pending-count', 'alert' ); 185 186 if ( 'admin' === $type ) { 187 $count = '!'; 188 } 189 }; 190 191 $alert_class[] = $type . '-type'; 192 $menu_title = sprintf( 193 '<span id="ab-pending-notifications" class="%1$s">%2$s</span>', 194 implode( ' ', array_map( 'sanitize_html_class', $alert_class ) ), 195 $count 196 ); 197 198 // Add the top-level Notifications button. 199 $wp_admin_bar->add_node( array( 200 'parent' => 'top-secondary', 201 'id' => 'bp-notifications', 202 'title' => $menu_title, 203 'href' => $menu_link, 204 ) ); 205 206 if ( ! empty( $notifications ) ) { 207 foreach ( (array) $notifications as $notification ) { 208 $wp_admin_bar->add_node( array( 209 'parent' => 'bp-notifications', 210 'id' => 'notification-' . $notification->id, 211 'title' => $notification->content, 212 'href' => $notification->href, 213 ) ); 214 } 215 } else { 216 $wp_admin_bar->add_node( array( 217 'parent' => 'bp-notifications', 218 'id' => 'no-notifications', 219 'title' => __( 'No new notifications', 'buddypress' ), 220 'href' => $menu_link, 221 ) ); 222 } 223 224 return true; 225 } 226 227 /** 228 * Build the Admin or Members "Notifications" dropdown. 229 * 170 230 * @since 1.5.0 171 231 * … … 173 233 */ 174 234 function bp_members_admin_bar_notifications_menu() { 175 176 // Bail if notifications is not active. 177 if ( ! bp_is_active( 'notifications' ) ) { 178 return false; 179 } 180 181 bp_notifications_toolbar_menu(); 235 $admins_notifications = array(); 236 $capability = 'manage_options'; 237 238 if ( bp_core_do_network_admin() ) { 239 $capability = 'manage_network_options'; 240 } 241 242 if ( bp_current_user_can( $capability ) ) { 243 $notifications = bp_core_get_admin_notifications(); 244 245 if ( $notifications ) { 246 $menu_link = esc_url( bp_get_admin_url( add_query_arg( 'page', 'bp-admin-notifications', 'admin.php' ) ) ); 247 $count = count( $notifications ); 248 249 $notifications = array( 250 (object) array( 251 'id' => 'bp-admin-notifications', 252 'href' => $menu_link, 253 'content' => sprintf( 254 /* translators: %s: the number of admin notifications */ 255 _n( 'You have %s new important admin notification.', 'You have %s new important admin notifications.', $count, 'buddypress' ), 256 number_format_i18n( $count ) 257 ), 258 ), 259 ); 260 261 return bp_members_admin_bar_notifications_dropdown( $notifications, $menu_link, 'admin' ); 262 } 263 } 264 265 // Use Members notifications if the component is active. 266 if ( bp_is_active( 'notifications' ) ) { 267 return bp_notifications_toolbar_menu(); 268 } 182 269 } 183 270 add_action( 'admin_bar_menu', 'bp_members_admin_bar_notifications_menu', 90 );
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)