ap_user_link( boolean|integer $user_id = false, string|array $sub = false )

Description #

Return Link to user pages.

Parameters #

  • $user_id
    boolean | integer (Optional) user id. Default value: false
  • $sub
    string | array (Optional) page slug. Default value: false

Changelog #

VersionDescription
unknownunknown
4.1.2User user nicename in url as author_name query var gets user by nicename.
4.1.1Introduced.

Source #

File: includes/functions.php

function ap_user_link( $user_id = false, $sub = false ) {
	$link = '';

	if ( false === $user_id ) {
		$user_id = get_the_author_meta( 'ID' );
	}

	if ( empty( $user_id ) && is_author() ) {
		$user_id = get_queried_object_id();
	}

	if ( $user_id < 1 && empty( $user_id ) ) {
		$link = '#/user/anonymous';
	} else {
		$user = get_user_by( 'id', $user_id );

		if ( ! $user ) {
			$link = '#/user/anonymous';
		} elseif ( ap_is_addon_active( 'buddypress.php' ) && function_exists( 'bp_core_get_userlink' ) ) {
			$link = bp_core_get_userlink( $user_id, false, true ) . 'qa/';
		} elseif ( ap_is_addon_active( 'profile.php' ) ) {
			$slug = get_option( 'ap_user_path' );
			$link = home_url( $slug ) . '/' . $user->user_nicename . '/';
		} else {
			$link = get_author_posts_url( $user_id );
		}
	}

	// Append sub.
	if ( ! empty( $sub ) ) {
		if ( is_array( $sub ) ) {
			$link = rtrim( $link, '/' ) . implode( '/', $sub ) . '/';
		} else {
			$link = $link . rtrim( $sub, '/' ) . '/';
		}
	}

	$link = user_trailingslashit( $link );

	return apply_filters( 'ap_user_link', $link, $user_id, $sub );
}

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