bp_get_members_component_link( string $component, string $action = '', array|string $query_args = '', array|bool $nonce = false )

Generate a link to a members component subpage.


Parameters Parameters

$component

(string) (Required) ID of the component (eg 'friends').

$action

(string) (Optional) 'action' slug (eg 'invites').

Default value: ''

$query_args

(array|string) (Optional) Array of URL params to add to the URL. See add_query_arg() for format.

Default value: ''

$nonce

(array|bool) (Optional) If provided, the URL will be passed through wp_nonce_url() with $nonce as the action string.

Default value: false


Top ↑

Return Return

(string)


Source Source

File: bp-members/bp-members-template.php

	function bp_get_members_component_link( $component, $action = '', $query_args = '', $nonce = false ) {
		// Must be displayed user.
		if ( ! bp_displayed_user_id() ) {
			return;
		}

		$bp = buddypress();

		if ( 'xprofile' === $component ) {
			$component = 'profile';
		}

		// Append $action to $url if there is no $type.
		if ( ! empty( $action ) ) {
			$url = bp_displayed_user_domain() . $bp->{$component}->slug . '/' . $action;
		} else {
			$url = bp_displayed_user_domain() . $bp->{$component}->slug;
		}

		// Add a slash at the end of our user url.
		$url = trailingslashit( $url );

		// Add possible query arg.
		if ( ! empty( $query_args ) && is_array( $query_args ) ) {
			$url = add_query_arg( $query_args, $url );
		}

		// To nonce, or not to nonce...
		if ( true === $nonce ) {
			$url = wp_nonce_url( $url );
		} elseif ( is_string( $nonce ) ) {
			$url = wp_nonce_url( $url, $nonce );
		}

		// Return the url, if there is one.
		if ( ! empty( $url ) ) {
			return $url;
		}
	}


Top ↑

Changelog Changelog

Changelog
Version Description
1.5.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.