- Timestamp:
- 04/12/2023 10:12:37 PM (21 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bp-notifications/classes/class-bp-notifications-component.php
r13442 r13450 134 134 135 135 /** 136 * Register component navigation. 137 * 138 * @since 12.0.0 139 * 140 * @see `BP_Component::register_nav()` for a description of arguments. 141 * 142 * @param array $main_nav Optional. See `BP_Component::register_nav()` for 143 * description. 144 * @param array $sub_nav Optional. See `BP_Component::register_nav()` for 145 * description. 146 */ 147 public function register_nav( $main_nav = array(), $sub_nav = array() ) { 148 $slug = bp_get_notifications_slug(); 149 150 // Add 'Notifications' to the main navigation. 151 $main_nav = array( 152 'name' => _x( 'Notifications', 'Profile screen nav', 'buddypress' ), 153 'slug' => $slug, 154 'position' => 30, 155 'show_for_displayed_user' => false, 156 'screen_function' => 'bp_notifications_screen_unread', 157 'default_subnav_slug' => 'unread', 158 'item_css_id' => $this->id, 159 'user_has_access_callback' => 'bp_core_can_edit_settings', 160 ); 161 162 // Add the subnav items to the notifications nav item. 163 $sub_nav[] = array( 164 'name' => _x( 'Unread', 'Notification screen nav', 'buddypress' ), 165 'slug' => 'unread', 166 'parent_slug' => $slug, 167 'screen_function' => 'bp_notifications_screen_unread', 168 'position' => 10, 169 'item_css_id' => 'notifications-my-notifications', 170 'user_has_access' => false, 171 'user_has_access_callback' => 'bp_core_can_edit_settings', 172 ); 173 174 $sub_nav[] = array( 175 'name' => _x( 'Read', 'Notification screen nav', 'buddypress' ), 176 'slug' => 'read', 177 'parent_slug' => $slug, 178 'screen_function' => 'bp_notifications_screen_read', 179 'position' => 20, 180 'user_has_access' => false, 181 'user_has_access_callback' => 'bp_core_can_edit_settings', 182 ); 183 184 parent::register_nav( $main_nav, $sub_nav ); 185 } 186 187 /** 136 188 * Set up component navigation. 137 189 * 138 190 * @since 1.9.0 139 * 140 * @see BP_Component::setup_nav() for a description of arguments. 141 * 142 * @param array $main_nav Optional. See BP_Component::setup_nav() for 191 * @since 12.0.0 Used to customize the main navigation name. 192 * 193 * @see `BP_Component::setup_nav()` for a description of arguments. 194 * 195 * @param array $main_nav Optional. See `BP_Component::setup_nav()` for 143 196 * description. 144 * @param array $sub_nav Optional. See BP_Component::setup_nav()for197 * @param array $sub_nav Optional. See `BP_Component::setup_nav()` for 145 198 * description. 146 199 */ 147 200 public function setup_nav( $main_nav = array(), $sub_nav = array() ) { 148 149 // Stop if there is no user displayed or logged in.150 if ( ! is_user_logged_in() && ! bp_displayed_user_id() ) {151 return;152 }153 154 $access = bp_core_can_edit_settings();155 $slug = bp_get_notifications_slug();156 157 201 // Only grab count if we're on a user page and current user has access. 158 if ( bp_is_user() && bp_user_has_access() ) {159 $count = bp_notifications_get_unread_notification_count( bp_displayed_user_id() );160 $class = ( 0 === $count ) ? 'no-count' : 'count';161 $ nav_name= sprintf(202 if ( isset( $this->main_nav['name'] ) && bp_is_user() && bp_user_has_access() ) { 203 $count = bp_notifications_get_unread_notification_count( bp_displayed_user_id() ); 204 $class = ( 0 === $count ) ? 'no-count' : 'count'; 205 $this->main_nav['name'] = sprintf( 162 206 /* translators: %s: Unread notification count for the current user */ 163 207 _x( 'Notifications %s', 'Profile screen nav', 'buddypress' ), … … 168 212 ) 169 213 ); 170 } else { 171 $nav_name = _x( 'Notifications', 'Profile screen nav', 'buddypress' ); 172 } 173 174 // Add 'Notifications' to the main navigation. 175 $main_nav = array( 176 'name' => $nav_name, 177 'slug' => $slug, 178 'position' => 30, 179 'show_for_displayed_user' => $access, 180 'screen_function' => 'bp_notifications_screen_unread', 181 'default_subnav_slug' => 'unread', 182 'item_css_id' => $this->id, 183 ); 184 185 // Add the subnav items to the notifications nav item. 186 $sub_nav[] = array( 187 'name' => _x( 'Unread', 'Notification screen nav', 'buddypress' ), 188 'slug' => 'unread', 189 'parent_slug' => $slug, 190 'screen_function' => 'bp_notifications_screen_unread', 191 'position' => 10, 192 'item_css_id' => 'notifications-my-notifications', 193 'user_has_access' => $access, 194 ); 195 196 $sub_nav[] = array( 197 'name' => _x( 'Read', 'Notification screen nav', 'buddypress' ), 198 'slug' => 'read', 199 'parent_slug' => $slug, 200 'screen_function' => 'bp_notifications_screen_read', 201 'position' => 20, 202 'user_has_access' => $access, 203 ); 214 } 204 215 205 216 parent::setup_nav( $main_nav, $sub_nav );
Note: See TracChangeset
for help on using the changeset viewer.