Profile::user_menu( int|false $user_id = false, string $class_name = '' )

Description #

Output user profile menu.

Parameters #

  • $user_id
    int | false (Optional) Id of user, default is current user. Default value: false
  • $class_name
    string (Optional) CSS class. Default value: ''

Source #

File: addons/profile/profile.php

	public function user_menu( $user_id = false, $class_name = '' ) {
		$user_id     = false !== $user_id ? $user_id : ap_current_user_id();
		$user        = get_user_by( 'id', $user_id );
		$current_tab = get_query_var( 'user_page', ap_opt( 'user_page_slug_questions' ) );
		$ap_menu     = apply_filters( 'ap_user_menu_items', anspress()->user_pages, $user_id );

		// If BuddyPress addon is active, set the profile menu active links as required
		// with the help of the 'pagename' query var.
		if ( ap_is_addon_active( 'buddypress.php' ) ) {
			$current_tab = 'qa' === get_query_var( 'pagename' ) ? 'questions' : get_query_var( 'pagename' );
		}

		echo '<ul class="ap-tab-nav clearfix ' . esc_attr( $class_name ) . '">';

		foreach ( (array) $ap_menu as $args ) {
			if ( empty( $args['private'] ) || ( true === $args['private'] && get_current_user_id() === $user_id ) ) {
				echo '<li class="ap-menu-' . esc_attr( $args['slug'] ) . ( $args['rewrite'] === $current_tab ? ' active' : '' ) . '">';

				$url = isset( $args['url'] ) ? $args['url'] : ap_user_link( $user_id, $args['rewrite'] );
				if (
					( ap_is_addon_active( 'buddypress.php' ) && function_exists( 'bp_core_get_userlink' ) )
					&& ( in_array( 'about', $args, true ) || in_array( 'edit-profile', $args, true ) )
				) {
					$slug = get_option( 'ap_user_path' );
					$link = home_url( $slug ) . '/' . $user->user_nicename . '/';
					$url  = isset( $args['url'] ) ? $args['url'] : $link . $args['rewrite'];
				}
				echo '<a href="' . esc_url( $url ) . '">';

				// Show icon.
				if ( ! empty( $args['icon'] ) ) {
					echo '<i class="' . esc_attr( $args['icon'] ) . '"></i>';
				}

				echo esc_attr( $args['label'] );

				// Show count.
				if ( ! empty( $args['count'] ) ) {
					echo '<span>' . esc_attr( number_format_i18n( $args['count'] ) ) . '</span>';
				}

				echo '</a>';
				echo '</li>';
			}
		}

		echo '</ul>';
	}

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Add your comment