函数文档

get_edit_profile_url()

💡 云策文档标注

概述

get_edit_profile_url() 函数用于获取用户个人资料编辑器的 URL。它根据用户 ID 和方案参数动态生成 URL,并支持通过过滤器进行自定义。

关键要点

  • 函数返回用户个人资料编辑器的 URL,默认针对当前用户。
  • 接受两个可选参数:$user_id(用户 ID,默认为当前用户)和 $scheme(方案,默认为 'admin')。
  • 根据当前管理界面类型(用户管理、网络管理或默认)使用不同的 URL 生成函数。
  • 提供 'edit_profile_url' 过滤器,允许开发者修改生成的 URL。

代码示例

function get_edit_profile_url( $user_id = 0, $scheme = 'admin' ) {
	$user_id = $user_id ? (int) $user_id : get_current_user_id();

	if ( is_user_admin() ) {
		$url = user_admin_url( 'profile.php', $scheme );
	} elseif ( is_network_admin() ) {
		$url = network_admin_url( 'profile.php', $scheme );
	} else {
		$url = get_dashboard_url( $user_id, 'profile.php', $scheme );
	}

	/**
	 * Filters the URL for a user's profile editor.
	 *
	 * @since 3.1.0
	 *
	 * @param string $url     The complete URL including scheme and path.
	 * @param int    $user_id The user ID.
	 * @param string $scheme  Scheme to give the URL context. Accepts 'http', 'https', 'login',
	 *                        'login_post', 'admin', 'relative' or null.
	 */
	return apply_filters( 'edit_profile_url', $url, $user_id, $scheme );
}

注意事项

  • 函数自 WordPress 3.1.0 版本引入。
  • 方案参数 $scheme 接受 'http'、'https'、'admin' 等值,默认 'admin' 会根据 force_ssl_admin() 和 is_ssl() 自动处理 SSL。
  • 相关函数包括 is_user_admin()、is_network_admin()、get_dashboard_url() 等,用于辅助 URL 生成。

📄 原文内容

Retrieves the URL to the user’s profile editor.

Parameters

$user_idintoptional
User ID. Defaults to current user.
$schemestringoptional
The scheme to use. Default is 'admin', which obeys force_ssl_admin() and is_ssl() . 'http' or 'https' can be passed to force those schemes.

Return

string Dashboard URL link with optional path appended.

Source

function get_edit_profile_url( $user_id = 0, $scheme = 'admin' ) {
	$user_id = $user_id ? (int) $user_id : get_current_user_id();

	if ( is_user_admin() ) {
		$url = user_admin_url( 'profile.php', $scheme );
	} elseif ( is_network_admin() ) {
		$url = network_admin_url( 'profile.php', $scheme );
	} else {
		$url = get_dashboard_url( $user_id, 'profile.php', $scheme );
	}

	/**
	 * Filters the URL for a user's profile editor.
	 *
	 * @since 3.1.0
	 *
	 * @param string $url     The complete URL including scheme and path.
	 * @param int    $user_id The user ID.
	 * @param string $scheme  Scheme to give the URL context. Accepts 'http', 'https', 'login',
	 *                        'login_post', 'admin', 'relative' or null.
	 */
	return apply_filters( 'edit_profile_url', $url, $user_id, $scheme );
}

Hooks

apply_filters( ‘edit_profile_url’, string $url, int $user_id, string $scheme )

Filters the URL for a user’s profile editor.

Changelog

Version Description
3.1.0 Introduced.