BP_REST_Members_Details_Endpoint::bp_rest_default_menu()

Get default dropdown navigation.

Description

Return

(object)

Source

File: bp-members/classes/class-bp-rest-members-details-endpoint.php

	protected function bp_rest_default_menu() {
		$items = array();

		if ( bp_is_active( 'xprofile' ) ) {
			$profile_link  = trailingslashit( bp_loggedin_user_domain() . bp_get_profile_slug() );
			$item_xprofile = array(
				'ID'       => 'profile',
				'title'    => __( 'Profile', 'buddyboss' ),
				'url'      => esc_url( $profile_link ),
				'count'    => '',
				'children' => array(
					array(
						'ID'    => 'view',
						'title' => __( 'View', 'buddyboss' ),
						'url'   => esc_url( $profile_link ),
						'count' => '',
					),
					array(
						'ID'    => 'edit',
						'title' => __( 'Edit', 'buddyboss' ),
						'url'   => esc_url( $profile_link ),
						'count' => '',
					),
				),
			);

			if ( buddypress()->avatar->show_avatars ) {
				$item_xprofile['children'][] = array(
					'ID'    => 'profile-photo',
					'title' => __( 'Profile Photo', 'buddyboss' ),
					'url'   => esc_url( trailingslashit( $profile_link . 'change-avatar' ) ),
					'count' => '',
				);
			}

			if ( function_exists( 'bp_displayed_user_use_cover_image_header' ) && bp_displayed_user_use_cover_image_header() ) {
				$item_xprofile['children'][] = array(
					'ID'    => 'cover-photo',
					'title' => __( 'Cover Photo', 'buddyboss' ),
					'url'   => esc_url( trailingslashit( $profile_link . 'change-cover-image' ) ),
					'count' => '',
				);
			}

			$items[] = $item_xprofile;
		}

		if ( bp_is_active( 'settings' ) ) {
			$settings_link = trailingslashit( bp_loggedin_user_domain() . bp_get_settings_slug() );
			$item_settings = array(
				'ID'       => bp_get_settings_slug(),
				'title'    => __( 'Account', 'buddyboss' ),
				'url'      => esc_url( $settings_link ),
				'count'    => '',
				'children' => array(),
			);

			$item_settings['children'][] = array(
				'ID'    => 'general',
				'title' => __( 'Login Information', 'buddyboss' ),
				'url'   => esc_url( $settings_link ),
				'count' => '',
			);

			if ( has_action( 'bp_notification_settings' ) ) {
				$item_settings['children'][] = array(
					'ID'    => 'notifications',
					'title' => __( 'Email Preferences', 'buddyboss' ),
					'url'   => esc_url( trailingslashit( $settings_link . 'notifications' ) ),
					'count' => '',
				);
			}

			$item_settings['children'][] = array(
				'ID'    => 'profile',
				'title' => __( 'Privacy', 'buddyboss' ),
				'url'   => esc_url( trailingslashit( $settings_link . 'profile' ) ),
				'count' => '',
			);

			if ( bp_core_can_edit_settings() ) {
				$item_settings['children'][] = array(
					'ID'    => 'invites',
					'title' => __( 'Group Invites', 'buddyboss' ),
					'url'   => esc_url( trailingslashit( $settings_link . 'invites' ) ),
					'count' => '',
				);
			}

			$item_settings['children'][] = array(
				'ID'    => 'export',
				'title' => __( 'Export Data', 'buddyboss' ),
				'url'   => esc_url( trailingslashit( $settings_link . 'export' ) ),
				'count' => '',
			);

			if ( ! bp_current_user_can( 'bp_moderate' ) && ! bp_core_get_root_option( 'bp-disable-account-deletion' ) ) {
				$item_settings['children'][] = array(
					'ID'    => 'delete-account',
					'title' => __( 'Delete Account', 'buddyboss' ),
					'url'   => esc_url( trailingslashit( $settings_link . 'delete-account' ) ),
					'count' => '',
				);
			}

			$items[] = $item_settings;
		}

		if ( bp_is_active( 'activity' ) ) {
			$activity_link = trailingslashit( bp_loggedin_user_domain() . bp_get_activity_slug() );
			$item_activity = array(
				'ID'       => 'activities',
				'title'    => __( 'Timeline', 'buddyboss' ),
				'url'      => esc_url( $activity_link ),
				'count'    => '',
				'children' => array(),
			);

			$item_activity['children'][] = array(
				'ID'    => 'activities',
				'title' => function_exists( 'bp_is_activity_tabs_active' ) && bp_is_activity_tabs_active() ? __( 'Personal', 'buddyboss' ) : __( 'Posts', 'buddyboss' ),
				'url'   => esc_url( $activity_link ),
				'count' => '',
			);

			if (
				function_exists( 'bp_is_activity_tabs_active' )
				&& bp_is_activity_tabs_active()
			) {

				if ( bp_is_activity_like_active() ) {
					$item_activity['children'][] = array(
						'ID'    => 'favorites',
						'title' => __( 'Likes', 'buddyboss' ),
						'url'   => esc_url( trailingslashit( $activity_link . 'favorites' ) ),
						'count' => '',
					);
				}

				if ( bp_is_active( 'friends' ) ) {
					$item_activity['children'][] = array(
						'ID'    => 'friends',
						'title' => __( 'Connections', 'buddyboss' ),
						'url'   => esc_url( trailingslashit( $activity_link . 'friends' ) ),
						'count' => '',
					);
				}

				if ( bp_is_active( 'groups' ) ) {
					$item_activity['children'][] = array(
						'ID'    => 'groups',
						'title' => __( 'Groups', 'buddyboss' ),
						'url'   => esc_url( trailingslashit( $activity_link . 'groups' ) ),
						'count' => '',
					);
				}

				if ( bp_activity_do_mentions() ) {
					$item_activity['children'][] = array(
						'ID'    => 'mentions',
						'title' => __( 'Mentions', 'buddyboss' ),
						'url'   => esc_url( trailingslashit( $activity_link . 'mentions' ) ),
						'count' => '',
					);
				}

				if ( bp_is_activity_follow_active() ) {
					$item_activity['children'][] = array(
						'ID'    => 'following',
						'title' => __( 'Following', 'buddyboss' ),
						'url'   => esc_url( trailingslashit( $activity_link . 'following' ) ),
						'count' => '',
					);
				}
			}
			$items[] = $item_activity;
		}

		if ( bp_is_active( 'notifications' ) ) {
			// Setup the logged in user variables.
			$notifications_link = trailingslashit( bp_loggedin_user_domain() . bp_get_notifications_slug() );

			// Pending notification requests.
			$count             = bp_notifications_get_unread_notification_count( bp_loggedin_user_id() );
			$item_notification = array(
				'ID'       => 'notifications',
				'title'    => __( 'Notifications', 'buddyboss' ),
				'url'      => esc_url( $notifications_link ),
				'count'    => bp_core_number_format( $count ),
				'children' => array(
					array(
						'ID'    => 'unread',
						'title' => __( 'Unread', 'buddyboss' ),
						'url'   => esc_url( $notifications_link ),
						'count' => bp_core_number_format( $count ),
					),
					array(
						'ID'    => 'read',
						'title' => __( 'Read', 'buddyboss' ),
						'url'   => esc_url( trailingslashit( $notifications_link . 'read' ) ),
						'count' => '',
					),
				),
			);

			$items[] = $item_notification;
		}

		if ( bp_is_active( 'messages' ) ) {
			// Setup the logged in user variables.
			$messages_link = trailingslashit( bp_loggedin_user_domain() . bp_get_messages_slug() );

			// Unread message count.
			$count = messages_get_unread_count( bp_loggedin_user_id() );

			$item_messages = array(
				'ID'       => 'messages',
				'title'    => __( 'Messages', 'buddyboss' ),
				'url'      => esc_url( $messages_link ),
				'count'    => bp_core_number_format( $count ),
				'children' => array(
					array(
						'ID'    => 'inbox',
						'title' => __( 'Messages', 'buddyboss' ),
						'url'   => esc_url( $messages_link ),
						'count' => bp_core_number_format( $count ),
					),
					array(
						'ID'    => 'compose',
						'title' => __( 'New Message', 'buddyboss' ),
						'url'   => esc_url( trailingslashit( $messages_link . 'compose' ) ),
						'count' => '',
					),
				),
			);

			$items[] = $item_messages;
		}

		if ( bp_is_active( 'friends' ) ) {
			// Setup the logged in user variables.
			$friends_link = trailingslashit( bp_loggedin_user_domain() . bp_get_friends_slug() );

			// Pending friend requests.
			$count = count( friends_get_friendship_request_user_ids( bp_loggedin_user_id() ) );

			$item_friends = array(
				'ID'       => 'friends',
				'title'    => __( 'Connections', 'buddyboss' ),
				'url'      => esc_url( $friends_link ),
				'count'    => bp_core_number_format( $count ),
				'children' => array(
					array(
						'ID'    => 'my-friends',
						'title' => __( 'My Connections', 'buddyboss' ),
						'url'   => esc_url( $friends_link ),
						'count' => '',
					),
					array(
						'ID'    => 'requests',
						'title' => ( ! empty( $count ) ? __( 'Pending Requests', 'buddyboss' ) : __( 'No Pending Requests', 'buddyboss' ) ),
						'url'   => esc_url( trailingslashit( $friends_link . 'requests' ) ),
						'count' => bp_core_number_format( $count ),
					),
				),
			);

			$items[] = $item_friends;
		}

		if ( bp_is_active( 'groups' ) ) {
			// Setup the logged in user variables.
			$groups_link = trailingslashit( bp_loggedin_user_domain() . bp_get_groups_slug() );

			// Pending group invites.
			$count = groups_get_invite_count_for_user();

			$item_groups = array(
				'ID'       => 'groups',
				'title'    => __( 'Groups', 'buddyboss' ),
				'url'      => esc_url( $groups_link ),
				'count'    => bp_core_number_format( $count ),
				'children' => array(
					array(
						'ID'    => 'my-groups',
						'title' => __( 'My Groups', 'buddyboss' ),
						'url'   => esc_url( $groups_link ),
						'count' => '',
					),
					array(
						'ID'    => 'invites',
						'title' => ( ! empty( $count ) ? __( 'Pending Invites', 'buddyboss' ) : __( 'No Pending Invites', 'buddyboss' ) ),
						'url'   => esc_url( trailingslashit( $groups_link . 'invites' ) ),
						'count' => bp_core_number_format( $count ),
					),
				),
			);

			if ( bp_user_can_create_groups() ) {
				$item_groups['children'][] = array(
					'ID'    => 'create-group',
					'title' => __( 'Create Group', 'buddyboss' ),
					'url'   => esc_url( trailingslashit( bp_get_groups_directory_permalink() . 'create' ) ),
					'count' => '',
				);
			}

			$items[] = $item_groups;

		}

		if ( function_exists( 'bp_ld_sync' ) && bp_ld_sync()->settings->get( 'course.courses_visibility' ) ) {
			$slug        = apply_filters( 'bp_learndash_profile_courses_slug', \LearnDash_Settings_Section::get_section_setting( 'LearnDash_Settings_Section_Permalinks', 'courses' ) );
			$course_link = trailingslashit( bp_loggedin_user_domain() . $slug );
			$name        = \LearnDash_Custom_Label::get_label( 'courses' );

			$item_courses = array(
				'ID'       => $slug,
				'title'    => $name,
				'url'      => esc_url( $course_link ),
				'count'    => '',
				'children' => array(
					array(
						'ID'    => 'my-courses',
						'title' => sprintf(
							/* translators: My Courses */
							__( 'My %s', 'buddyboss' ),
							$name
						),
						'url'   => esc_url( $course_link ),
						'count' => '',
					),
				),
			);

			$items[] = $item_courses;
		}

		if ( bp_is_active( 'forums' ) ) {
			$user_domain = bp_loggedin_user_domain();
			$forums_link = trailingslashit( $user_domain . bp_get_option( '_bbp_root_slug', BP_FORUMS_SLUG ) );

			$item_forums = array(
				'ID'       => 'forums',
				'title'    => __( 'Forums', 'buddyboss' ),
				'url'      => esc_url( $forums_link ),
				'count'    => '',
				'children' => array(
					array(
						'ID'    => 'topics',
						'title' => __( 'My Discussions', 'buddyboss' ),
						'url'   => esc_url( trailingslashit( $forums_link . bbp_get_topic_archive_slug() ) ),
						'count' => '',
					),
					array(
						'ID'    => 'replies',
						'title' => __( 'My Replies', 'buddyboss' ),
						'url'   => esc_url( trailingslashit( $forums_link . bbp_get_reply_archive_slug() ) ),
						'count' => '',
					),
				),
			);

			if ( function_exists( 'bbp_is_favorites_active' ) && bbp_is_favorites_active() ) {
				$item_forums['children'][] = array(
					'ID'    => 'favorite',
					'title' => __( 'My Favorites', 'buddyboss' ),
					'url'   => esc_url( trailingslashit( $forums_link . bbp_get_user_favorites_slug() ) ),
					'count' => '',
				);
			}

			if ( function_exists( 'bbp_is_subscriptions_active' ) && bbp_is_subscriptions_active() ) {
				$item_forums['children'][] = array(
					'ID'    => 'subscribe',
					'title' => __( 'Subscriptions', 'buddyboss' ),
					'url'   => esc_url( trailingslashit( $forums_link . bbp_get_user_subscriptions_slug() ) ),
					'count' => '',
				);
			}

			$items[] = $item_forums;
		}

		if ( bp_is_active( 'media' ) && function_exists( 'bp_is_profile_media_support_enabled' ) && bp_is_profile_media_support_enabled() ) {
			// Setup the logged in user variables.
			$media_link = trailingslashit( bp_loggedin_user_domain() . bp_get_media_slug() );

			$item_media = array(
				'ID'       => 'photos',
				'title'    => __( 'Photos', 'buddyboss' ),
				'url'      => esc_url( $media_link ),
				'count'    => '',
				'children' => array(
					array(
						'ID'    => 'my-media',
						'title' => __( 'My Photos', 'buddyboss' ),
						'url'   => esc_url( $media_link ),
						'count' => '',
					),
				),
			);

			if ( function_exists( 'bp_is_profile_albums_support_enabled' ) && bp_is_profile_albums_support_enabled() ) {
				$item_media['children'][] = array(
					'ID'    => 'albums',
					'title' => __( 'My Albums', 'buddyboss' ),
					'url'   => esc_url( trailingslashit( $media_link . 'albums' ) ),
					'count' => '',
				);
			}

			$items[] = $item_media;
		}

		if ( bp_is_active( 'media' ) && function_exists( 'bp_is_profile_document_support_enabled' ) && bp_is_profile_document_support_enabled() ) {
			// Setup the logged in user variables.
			$document_link = trailingslashit( bp_loggedin_user_domain() . bp_get_document_slug() );

			$item_documents = array(
				'ID'       => 'documents',
				'title'    => __( 'Documents', 'buddyboss' ),
				'url'      => esc_url( $document_link ),
				'count'    => '',
				'children' => array(
					array(
						'ID'    => 'my-document',
						'title' => __( 'My Documents', 'buddyboss' ),
						'url'   => esc_url( $document_link ),
						'count' => '',
					),
				),
			);
			$items[]        = $item_documents;
		}

		if ( bp_is_active( 'invites' ) && function_exists( 'bp_allow_user_to_send_invites' ) && true === bp_allow_user_to_send_invites() ) {
			// Setup the logged in user variables.
			$invites_link = trailingslashit( bp_loggedin_user_domain() . bp_get_invites_slug() );
			$item_invites = array(
				'ID'       => 'invites',
				'title'    => __( 'Email Invites', 'buddyboss' ),
				'url'      => esc_url( $invites_link ),
				'count'    => '',
				'children' => array(
					array(
						'ID'    => 'send-invites',
						'title' => __( 'Send Invites', 'buddyboss' ),
						'url'   => esc_url( $invites_link ),
						'count' => '',
					),
					array(
						'ID'    => 'sent-invites',
						'title' => __( 'Sent Invites', 'buddyboss' ),
						'url'   => esc_url( trailingslashit( $invites_link . 'sent-invites' ) ),
						'count' => '',
					),
				),
			);
			$items[]      = $item_invites;
		}

		$items[] = array(
			'ID'    => 'log-out',
			'title' => __( 'Log Out', 'buddyboss' ),
			'url'   => esc_url( wp_logout_url() ),
			'count' => '',
		);

		// phpcs:ignore
		$items = json_decode( json_encode( $items ), false );

		return $items;
	}

Questions?

We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.