- Timestamp:
- 04/12/2023 10:12:37 PM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bp-messages/classes/class-bp-messages-component.php
r13442 r13450 190 190 191 191 /** 192 * Set up navigation for user pages. 193 * 194 * @param array $main_nav See {BP_Component::setup_nav()} for details. 195 * @param array $sub_nav See {BP_Component::setup_nav()} for details. 192 * Register component navigation. 193 * 194 * @since 12.0.0 195 * 196 * @param array $main_nav See `BP_Component::register_nav()` for details. 197 * @param array $sub_nav See `BP_Component::register_nav()` for details. 198 */ 199 public function register_nav( $main_nav = array(), $sub_nav = array() ) { 200 $slug = bp_get_messages_slug(); 201 202 // Add 'Messages' to the main navigation. 203 $main_nav = array( 204 'name' => __( 'Messages', 'buddypress' ), 205 'slug' => $slug, 206 'position' => 50, 207 'show_for_displayed_user' => false, 208 'screen_function' => 'messages_screen_inbox', 209 'default_subnav_slug' => 'inbox', 210 'item_css_id' => $this->id, 211 'user_has_access_callback' => 'bp_core_can_edit_settings', 212 ); 213 214 // Add the subnav items to the profile. 215 $sub_nav[] = array( 216 'name' => __( 'Inbox', 'buddypress' ), 217 'slug' => 'inbox', 218 'parent_slug' => $slug, 219 'screen_function' => 'messages_screen_inbox', 220 'position' => 10, 221 'user_has_access' => false, 222 'user_has_access_callback' => 'bp_core_can_edit_settings', 223 ); 224 225 if ( bp_is_active( $this->id, 'star' ) ) { 226 $sub_nav[] = array( 227 'name' => __( 'Starred', 'buddypress' ), 228 'slug' => bp_get_messages_starred_slug(), 229 'parent_slug' => $slug, 230 'screen_function' => 'bp_messages_star_screen', 231 'position' => 11, 232 'user_has_access' => false, 233 'user_has_access_callback' => 'bp_core_can_edit_settings', 234 ); 235 } 236 237 $sub_nav[] = array( 238 'name' => __( 'Sent', 'buddypress' ), 239 'slug' => 'sentbox', 240 'parent_slug' => $slug, 241 'screen_function' => 'messages_screen_sentbox', 242 'position' => 20, 243 'user_has_access' => false, 244 'user_has_access_callback' => 'bp_core_can_edit_settings', 245 ); 246 247 // Show "Compose" on the logged-in user's profile only. 248 $sub_nav[] = array( 249 'name' => __( 'Compose', 'buddypress' ), 250 'slug' => 'compose', 251 'parent_slug' => $slug, 252 'screen_function' => 'messages_screen_compose', 253 'position' => 30, 254 'user_has_access' => false, 255 'user_has_access_callback' => 'bp_is_my_profile', 256 ); 257 258 // Show "Notices" to community admins only. 259 $sub_nav[] = array( 260 'name' => __( 'Notices', 'buddypress' ), 261 'slug' => 'notices', 262 'parent_slug' => $slug, 263 'screen_function' => 'messages_screen_notices', 264 'position' => 90, 265 'user_has_access' => false, 266 'user_has_access_callback' => 'bp_current_user_can_moderate', 267 ); 268 269 parent::register_nav( $main_nav, $sub_nav ); 270 } 271 272 /** 273 * Set up component navigation. 274 * 275 * @since 1.5.0 276 * @since 12.0.0 Used to customize the main navigation name. 277 * 278 * @see `BP_Component::setup_nav()` for a description of arguments. 279 * 280 * @param array $main_nav Optional. See `BP_Component::setup_nav()` for 281 * description. 282 * @param array $sub_nav Optional. See `BP_Component::setup_nav()` for 283 * description. 196 284 */ 197 285 public function setup_nav( $main_nav = array(), $sub_nav = array() ) { 198 199 // Stop if there is no user displayed or logged in.200 if ( ! is_user_logged_in() && ! bp_displayed_user_id() ) {201 return;202 }203 204 $access = bp_core_can_edit_settings();205 $slug = bp_get_messages_slug();206 207 286 // Only grab count if we're on a user page and current user has access. 208 if ( bp_is_user() && bp_user_has_access() ) {209 $count = bp_get_total_unread_messages_count( bp_displayed_user_id() );210 $class = ( 0 === $count ) ? 'no-count' : 'count';211 $ nav_name= sprintf(287 if ( isset( $this->main_nav['name'] ) && bp_is_user() && bp_user_has_access() ) { 288 $count = bp_get_total_unread_messages_count( bp_displayed_user_id() ); 289 $class = ( 0 === $count ) ? 'no-count' : 'count'; 290 $this->main_nav['name'] = sprintf( 212 291 /* translators: %s: Unread message count for the current user */ 213 292 __( 'Messages %s', 'buddypress' ), … … 218 297 ) 219 298 ); 220 } else { 221 $nav_name = __( 'Messages', 'buddypress' ); 222 } 223 224 // Add 'Messages' to the main navigation. 225 $main_nav = array( 226 'name' => $nav_name, 227 'slug' => $slug, 228 'position' => 50, 229 'show_for_displayed_user' => $access, 230 'screen_function' => 'messages_screen_inbox', 231 'default_subnav_slug' => 'inbox', 232 'item_css_id' => $this->id 233 ); 234 235 // Add the subnav items to the profile. 236 $sub_nav[] = array( 237 'name' => __( 'Inbox', 'buddypress' ), 238 'slug' => 'inbox', 239 'parent_slug' => $slug, 240 'screen_function' => 'messages_screen_inbox', 241 'position' => 10, 242 'user_has_access' => $access 243 ); 244 245 if ( bp_is_active( $this->id, 'star' ) ) { 246 $sub_nav[] = array( 247 'name' => __( 'Starred', 'buddypress' ), 248 'slug' => bp_get_messages_starred_slug(), 249 'parent_slug' => $slug, 250 'screen_function' => 'bp_messages_star_screen', 251 'position' => 11, 252 'user_has_access' => $access 253 ); 254 } 255 256 $sub_nav[] = array( 257 'name' => __( 'Sent', 'buddypress' ), 258 'slug' => 'sentbox', 259 'parent_slug' => $slug, 260 'screen_function' => 'messages_screen_sentbox', 261 'position' => 20, 262 'user_has_access' => $access 263 ); 264 265 // Show "Compose" on the logged-in user's profile only. 266 $sub_nav[] = array( 267 'name' => __( 'Compose', 'buddypress' ), 268 'slug' => 'compose', 269 'parent_slug' => $slug, 270 'screen_function' => 'messages_screen_compose', 271 'position' => 30, 272 'user_has_access' => bp_is_my_profile(), 273 ); 274 275 // Show "Notices" to community admins only. 276 $sub_nav[] = array( 277 'name' => __( 'Notices', 'buddypress' ), 278 'slug' => 'notices', 279 'parent_slug' => $slug, 280 'screen_function' => 'messages_screen_notices', 281 'position' => 90, 282 'user_has_access' => bp_current_user_can( 'bp_moderate' ) 283 ); 299 } 284 300 285 301 parent::setup_nav( $main_nav, $sub_nav );
Note: See TracChangeset
for help on using the changeset viewer.