get_the_author_meta

函式
get_the_author_meta ( $field = '', $user_id = false )
引數
  • (string) $field Optional. The user field to retrieve. Default empty.
    Required:
    Default: (empty)
  • (int|false) $user_id Optional. User ID.
    Required:
    Default: false
返回值
  • (string) The author's field from the current author's DB object, otherwise an empty string.
定義位置
相關方法
the_author_metaget_the_author_emailget_the_author_yimget_the_author_msnget_the_author_aim
引入
2.8.0
棄用
-

get_the_author_meta: 該函式檢索文章作者的特定後設資料欄位的值。它需要兩個引數:後設資料欄位名稱和文章作者的ID。它以字串形式返回後設資料欄位的值。

檢索當前文章的作者的請求資料。

`$field`引數的有效值包括:

– admin_color
– aim
– comment_shortcuts
– description
– display_name
– first_name
– ID
– jabber
– last_name
– nickname
– plugins_last_view
– plugins_per_page
– rich_editing
– syntax_highlighting
– user_activation_key
– user_description
– user_email
– user_firstname
– user_lastname
– user_level
– user_login
– user_nicename
– user_pass
– user_registered
– user_status
– user_url
– yim

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
function get_the_author_meta( $field = '', $user_id = false ) {
$original_user_id = $user_id;
if ( ! $user_id ) {
global $authordata;
$user_id = isset( $authordata->ID ) ? $authordata->ID : 0;
} else {
$authordata = get_userdata( $user_id );
}
if ( in_array( $field, array( 'login', 'pass', 'nicename', 'email', 'url', 'registered', 'activation_key', 'status' ), true ) ) {
$field = 'user_' . $field;
}
$value = isset( $authordata->$field ) ? $authordata->$field : '';
/**
* Filters the value of the requested user metadata.
*
* The filter name is dynamic and depends on the $field parameter of the function.
*
* @since 2.8.0
* @since 4.3.0 The `$original_user_id` parameter was added.
*
* @param string $value The value of the metadata.
* @param int $user_id The user ID for the value.
* @param int|false $original_user_id The original user ID, as passed to the function.
*/
return apply_filters( "get_the_author_{$field}", $value, $user_id, $original_user_id );
}
function get_the_author_meta( $field = '', $user_id = false ) { $original_user_id = $user_id; if ( ! $user_id ) { global $authordata; $user_id = isset( $authordata->ID ) ? $authordata->ID : 0; } else { $authordata = get_userdata( $user_id ); } if ( in_array( $field, array( 'login', 'pass', 'nicename', 'email', 'url', 'registered', 'activation_key', 'status' ), true ) ) { $field = 'user_' . $field; } $value = isset( $authordata->$field ) ? $authordata->$field : ''; /** * Filters the value of the requested user metadata. * * The filter name is dynamic and depends on the $field parameter of the function. * * @since 2.8.0 * @since 4.3.0 The `$original_user_id` parameter was added. * * @param string $value The value of the metadata. * @param int $user_id The user ID for the value. * @param int|false $original_user_id The original user ID, as passed to the function. */ return apply_filters( "get_the_author_{$field}", $value, $user_id, $original_user_id ); }
function get_the_author_meta( $field = '', $user_id = false ) {
	$original_user_id = $user_id;

	if ( ! $user_id ) {
		global $authordata;
		$user_id = isset( $authordata->ID ) ? $authordata->ID : 0;
	} else {
		$authordata = get_userdata( $user_id );
	}

	if ( in_array( $field, array( 'login', 'pass', 'nicename', 'email', 'url', 'registered', 'activation_key', 'status' ), true ) ) {
		$field = 'user_' . $field;
	}

	$value = isset( $authordata->$field ) ? $authordata->$field : '';

	/**
	 * Filters the value of the requested user metadata.
	 *
	 * The filter name is dynamic and depends on the $field parameter of the function.
	 *
	 * @since 2.8.0
	 * @since 4.3.0 The `$original_user_id` parameter was added.
	 *
	 * @param string    $value            The value of the metadata.
	 * @param int       $user_id          The user ID for the value.
	 * @param int|false $original_user_id The original user ID, as passed to the function.
	 */
	return apply_filters( "get_the_author_{$field}", $value, $user_id, $original_user_id );
}

常見問題

FAQs
檢視更多 >