- Timestamp:
- 04/12/2023 10:12:37 PM (20 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bp-friends/classes/class-bp-friends-component.php
r13441 r13450 149 149 150 150 /** 151 * Set upcomponent navigation.152 * 153 * @since 1 .5.0154 * 155 * @see BP_Component::setup_nav()for a description of arguments.156 * 157 * @param array $main_nav Optional. See BP_Component::setup_nav()for151 * Register component navigation. 152 * 153 * @since 12.0.0 154 * 155 * @see `BP_Component::register_nav()` for a description of arguments. 156 * 157 * @param array $main_nav Optional. See `BP_Component::register_nav()` for 158 158 * description. 159 * @param array $sub_nav Optional. See BP_Component::setup_nav()for159 * @param array $sub_nav Optional. See `BP_Component::register_nav()` for 160 160 * description. 161 161 */ 162 public function setup_nav( $main_nav = array(), $sub_nav = array() ) { 163 164 // Stop if there is no user displayed or logged in. 165 if ( ! is_user_logged_in() && ! bp_displayed_user_id() ) { 166 return; 167 } 168 169 $access = bp_core_can_edit_settings(); 162 public function register_nav( $main_nav = array(), $sub_nav = array() ) { 170 163 $slug = bp_get_friends_slug(); 171 164 172 // Add 'Friends' to the main navigation.173 $count = friends_get_total_friend_count();174 $class = ( 0 === $count ) ? 'no-count' : 'count';175 176 $main_nav_name = sprintf(177 /* translators: %s: Friend count for the current user */178 __( 'Friends %s', 'buddypress' ),179 sprintf(180 '<span class="%s">%s</span>',181 esc_attr( $class ),182 esc_html( $count )183 )184 );185 186 165 $main_nav = array( 187 'name' => $main_nav_name,166 'name' => __( 'Friends', 'buddypress' ), 188 167 'slug' => $slug, 189 168 'position' => 60, … … 204 183 205 184 $sub_nav[] = array( 206 'name' => _x( 'Requests', 'Friends screen sub nav', 'buddypress' ), 207 'slug' => 'requests', 208 'parent_slug' => $slug, 209 'screen_function' => 'friends_screen_requests', 210 'position' => 20, 211 'user_has_access' => $access, 212 ); 185 'name' => _x( 'Requests', 'Friends screen sub nav', 'buddypress' ), 186 'slug' => 'requests', 187 'parent_slug' => $slug, 188 'screen_function' => 'friends_screen_requests', 189 'position' => 20, 190 'user_has_access' => false, 191 'user_has_access_callback' => 'bp_core_can_edit_settings', 192 ); 193 194 parent::register_nav( $main_nav, $sub_nav ); 195 } 196 197 /** 198 * Set up component navigation. 199 * 200 * @since 1.5.0 201 * 202 * @see `BP_Component::setup_nav()` for a description of arguments. 203 * 204 * @param array $main_nav Optional. See `BP_Component::setup_nav()` for 205 * description. 206 * @param array $sub_nav Optional. See `BP_Component::setup_nav()` for 207 * description. 208 */ 209 public function setup_nav( $main_nav = array(), $sub_nav = array() ) { 210 // Only grab count if we're on a user page. 211 if ( bp_is_user() && isset( $this->main_nav['name'] ) ) { 212 // Add 'Friends' to the main navigation. 213 $count = friends_get_total_friend_count(); 214 $class = ( 0 === $count ) ? 'no-count' : 'count'; 215 $this->main_nav['name'] = sprintf( 216 /* translators: %s: Friend count for the current user */ 217 __( 'Friends %s', 'buddypress' ), 218 sprintf( 219 '<span class="%s">%s</span>', 220 esc_attr( $class ), 221 esc_html( $count ) 222 ) 223 ); 224 } 213 225 214 226 parent::setup_nav( $main_nav, $sub_nav );
Note: See TracChangeset
for help on using the changeset viewer.