wp/wp-includes/author-template.php
author ymh <ymh.work@gmail.com>
Tue, 09 Jun 2015 03:35:32 +0200
changeset 5 5e2f62d02dcd
parent 0 d970ebf37754
child 7 cf61fcea0001
permissions -rw-r--r--
upgrade wordpress + plugins
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     1
<?php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     2
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     3
 * Author Template functions for use in themes.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     4
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     5
 * These functions must be used within the WordPress Loop.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     6
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
     7
 * @link https://codex.wordpress.org/Author_Templates
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     8
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     9
 * @package WordPress
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    10
 * @subpackage Template
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    11
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    12
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    13
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    14
 * Retrieve the author of the current post.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    15
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    16
 * @since 1.5.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    17
 *
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    18
 * @uses $authordata The current author's DB object.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    19
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    20
 * @param string $deprecated Deprecated.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    21
 * @return string The author's display name.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    22
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    23
function get_the_author($deprecated = '') {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    24
	global $authordata;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    25
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    26
	if ( !empty( $deprecated ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    27
		_deprecated_argument( __FUNCTION__, '2.1' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    28
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    29
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    30
	 * Filter the display name of the current post's author.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    31
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    32
	 * @since 2.9.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    33
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    34
	 * @param string $authordata->display_name The author's display name.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    35
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    36
	return apply_filters('the_author', is_object($authordata) ? $authordata->display_name : null);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    37
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    38
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    39
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    40
 * Display the name of the author of the current post.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    41
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    42
 * The behavior of this function is based off of old functionality predating
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    43
 * get_the_author(). This function is not deprecated, but is designed to echo
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    44
 * the value from get_the_author() and as an result of any old theme that might
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    45
 * still use the old behavior will also pass the value from get_the_author().
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    46
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    47
 * The normal, expected behavior of this function is to echo the author and not
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    48
 * return it. However, backwards compatibility has to be maintained.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    49
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    50
 * @since 0.71
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    51
 * @see get_the_author()
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    52
 * @link https://codex.wordpress.org/Template_Tags/the_author
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    53
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    54
 * @param string $deprecated Deprecated.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    55
 * @param string $deprecated_echo Deprecated. Use get_the_author(). Echo the string or return it.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    56
 * @return string The author's display name, from get_the_author().
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    57
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    58
function the_author( $deprecated = '', $deprecated_echo = true ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    59
	if ( !empty( $deprecated ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    60
		_deprecated_argument( __FUNCTION__, '2.1' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    61
	if ( $deprecated_echo !== true )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    62
		_deprecated_argument( __FUNCTION__, '1.5', __('Use <code>get_the_author()</code> instead if you do not want the value echoed.') );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    63
	if ( $deprecated_echo )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    64
		echo get_the_author();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    65
	return get_the_author();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    66
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    67
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    68
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    69
 * Retrieve the author who last edited the current post.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    70
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    71
 * @since 2.8.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    72
 *
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    73
 * @return string The author's display name.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    74
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    75
function get_the_modified_author() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    76
	if ( $last_id = get_post_meta( get_post()->ID, '_edit_last', true) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    77
		$last_user = get_userdata($last_id);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    78
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    79
		/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    80
		 * Filter the display name of the author who last edited the current post.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    81
		 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    82
		 * @since 2.8.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    83
		 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    84
		 * @param string $last_user->display_name The author's display name.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    85
		 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    86
		return apply_filters('the_modified_author', $last_user->display_name);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    87
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    88
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    89
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    90
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    91
 * Display the name of the author who last edited the current post.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    92
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    93
 * @since 2.8.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    94
 *
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    95
 * @see get_the_author()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    96
 * @return string The author's display name, from get_the_modified_author().
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    97
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    98
function the_modified_author() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    99
	echo get_the_modified_author();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   100
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   101
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   102
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   103
 * Retrieve the requested data of the author of the current post.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   104
 * @link https://codex.wordpress.org/Template_Tags/the_author_meta
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   105
 * @since 2.8.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   106
 * @param string $field selects the field of the users record.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   107
 * @param int $user_id Optional. User ID.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   108
 * @return string The author's field from the current author's DB object.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   109
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   110
function get_the_author_meta( $field = '', $user_id = false ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   111
	if ( ! $user_id ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   112
		global $authordata;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   113
		$user_id = isset( $authordata->ID ) ? $authordata->ID : 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   114
	} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   115
		$authordata = get_userdata( $user_id );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   116
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   117
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   118
	if ( in_array( $field, array( 'login', 'pass', 'nicename', 'email', 'url', 'registered', 'activation_key', 'status' ) ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   119
		$field = 'user_' . $field;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   120
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   121
	$value = isset( $authordata->$field ) ? $authordata->$field : '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   122
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   123
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   124
	 * Filter the value of the requested user metadata.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   125
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   126
	 * The filter name is dynamic and depends on the $field parameter of the function.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   127
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   128
	 * @since 2.8.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   129
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   130
	 * @param string $value   The value of the metadata.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   131
	 * @param int    $user_id The user ID.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   132
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   133
	return apply_filters( 'get_the_author_' . $field, $value, $user_id );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   134
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   135
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   136
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   137
 * Retrieve the requested data of the author of the current post.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   138
 * @link https://codex.wordpress.org/Template_Tags/the_author_meta
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   139
 * @since 2.8.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   140
 * @param string $field selects the field of the users record.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   141
 * @param int $user_id Optional. User ID.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   142
 * @echo string The author's field from the current author's DB object.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   143
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   144
function the_author_meta( $field = '', $user_id = false ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   145
	$author_meta = get_the_author_meta( $field, $user_id );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   146
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   147
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   148
	 * The value of the requested user metadata.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   149
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   150
	 * The filter name is dynamic and depends on the $field parameter of the function.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   151
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   152
	 * @since 2.8.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   153
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   154
	 * @param string $author_meta The value of the metadata.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   155
	 * @param int    $user_id     The user ID.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   156
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   157
	echo apply_filters( 'the_author_' . $field, $author_meta, $user_id );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   158
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   159
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   160
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   161
 * Retrieve either author's link or author's name.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   162
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   163
 * If the author has a home page set, return an HTML link, otherwise just return the
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   164
 * author's name.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   165
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   166
function get_the_author_link() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   167
	if ( get_the_author_meta('url') ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   168
		return '<a href="' . esc_url( get_the_author_meta('url') ) . '" title="' . esc_attr( sprintf(__("Visit %s&#8217;s website"), get_the_author()) ) . '" rel="author external">' . get_the_author() . '</a>';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   169
	} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   170
		return get_the_author();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   171
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   172
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   173
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   174
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   175
 * Display either author's link or author's name.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   176
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   177
 * If the author has a home page set, echo an HTML link, otherwise just echo the
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   178
 * author's name.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   179
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   180
 * @link https://codex.wordpress.org/Template_Tags/the_author_link
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   181
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   182
 * @since 2.1.0
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   183
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   184
function the_author_link() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   185
	echo get_the_author_link();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   186
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   187
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   188
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   189
 * Retrieve the number of posts by the author of the current post.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   190
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   191
 * @since 1.5.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   192
 *
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   193
 * @return int The number of posts by the author.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   194
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   195
function get_the_author_posts() {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   196
	$post = get_post();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   197
	if ( ! $post ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   198
		return 0;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   199
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   200
	return count_user_posts( $post->post_author, $post->post_type );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   201
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   202
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   203
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   204
 * Display the number of posts by the author of the current post.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   205
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   206
 * @link https://codex.wordpress.org/Template_Tags/the_author_posts
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   207
 * @since 0.71
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   208
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   209
function the_author_posts() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   210
	echo get_the_author_posts();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   211
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   212
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   213
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   214
 * Display an HTML link to the author page of the author of the current post.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   215
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   216
 * Does just echo get_author_posts_url() function, like the others do. The
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   217
 * reason for this, is that another function is used to help in printing the
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   218
 * link to the author's posts.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   219
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   220
 * @link https://codex.wordpress.org/Template_Tags/the_author_posts_link
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   221
 * @since 1.2.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   222
 * @param string $deprecated Deprecated.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   223
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   224
function the_author_posts_link($deprecated = '') {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   225
	if ( !empty( $deprecated ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   226
		_deprecated_argument( __FUNCTION__, '2.1' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   227
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   228
	global $authordata;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   229
	if ( !is_object( $authordata ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   230
		return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   231
	$link = sprintf(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   232
		'<a href="%1$s" title="%2$s" rel="author">%3$s</a>',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   233
		esc_url( get_author_posts_url( $authordata->ID, $authordata->user_nicename ) ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   234
		esc_attr( sprintf( __( 'Posts by %s' ), get_the_author() ) ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   235
		get_the_author()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   236
	);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   237
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   238
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   239
	 * Filter the link to the author page of the author of the current post.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   240
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   241
	 * @since 2.9.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   242
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   243
	 * @param string $link HTML link.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   244
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   245
	echo apply_filters( 'the_author_posts_link', $link );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   246
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   247
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   248
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   249
 * Retrieve the URL to the author page for the user with the ID provided.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   250
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   251
 * @since 2.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   252
 * @uses $wp_rewrite WP_Rewrite
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   253
 * @return string The URL to the author's page.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   254
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   255
function get_author_posts_url($author_id, $author_nicename = '') {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   256
	global $wp_rewrite;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   257
	$auth_ID = (int) $author_id;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   258
	$link = $wp_rewrite->get_author_permastruct();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   259
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   260
	if ( empty($link) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   261
		$file = home_url( '/' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   262
		$link = $file . '?author=' . $auth_ID;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   263
	} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   264
		if ( '' == $author_nicename ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   265
			$user = get_userdata($author_id);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   266
			if ( !empty($user->user_nicename) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   267
				$author_nicename = $user->user_nicename;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   268
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   269
		$link = str_replace('%author%', $author_nicename, $link);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   270
		$link = home_url( user_trailingslashit( $link ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   271
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   272
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   273
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   274
	 * Filter the URL to the author's page.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   275
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   276
	 * @since 2.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   277
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   278
	 * @param string $link            The URL to the author's page.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   279
	 * @param int    $author_id       The author's id.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   280
	 * @param string $author_nicename The author's nice name.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   281
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   282
	$link = apply_filters( 'author_link', $link, $author_id, $author_nicename );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   283
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   284
	return $link;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   285
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   286
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   287
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   288
 * List all the authors of the blog, with several options available.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   289
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   290
 * @link https://codex.wordpress.org/Template_Tags/wp_list_authors
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   291
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   292
 * @since 1.2.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   293
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   294
 * @param string|array $args {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   295
 *     Optional. Array or string of default arguments.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   296
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   297
 *     @type string $orderby       How to sort the authors. Accepts 'nicename', 'email', 'url', 'registered',
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   298
 *                                 'user_nicename', 'user_email', 'user_url', 'user_registered', 'name',
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   299
 *                                 'display_name', 'post_count', 'ID', 'meta_value', 'user_login'. Default 'name'.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   300
 *     @type string $order         Sorting direction for $orderby. Accepts 'ASC', 'DESC'. Default 'ASC'.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   301
 *     @type int    $number        Maximum authors to return or display. Default empty (all authors).
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   302
 *     @type bool   $optioncount   Show the count in parenthesis next to the author's name. Default false.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   303
 *     @type bool   $exclude_admin Whether to exclude the 'admin' account, if it exists. Default false.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   304
 *     @type bool   $show_fullname Whether to show the author's full name. Default false.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   305
 *     @type bool   $hide_empty    Whether to hide any authors with no posts. Default true.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   306
 *     @type string $feed          If not empty, show a link to the author's feed and use this text as the alt
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   307
 *                                 parameter of the link. Default empty.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   308
 *     @type string $feed_image    If not empty, show a link to the author's feed and use this image URL as
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   309
 *                                 clickable anchor. Default empty.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   310
 *     @type string $feed_type     The feed type to link to, such as 'rss2'. Defaults to default feed type.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   311
 *     @type bool   $echo          Whether to output the result or instead return it. Default true.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   312
 *     @type string $style         If 'list', each author is wrapped in an `<li>` element, otherwise the authors
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   313
 *                                 will be separated by commas.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   314
 *     @type bool   $html          Whether to list the items in HTML form or plaintext. Default true.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   315
 *     @type string $exclude       An array, comma-, or space-separated list of author IDs to exclude. Default empty.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   316
 *     @type string $exclude       An array, comma-, or space-separated list of author IDs to include. Default empty.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   317
 * }
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   318
 * @return null|string The output, if echo is set to false. Otherwise null.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   319
 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   320
function wp_list_authors( $args = '' ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   321
	global $wpdb;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   322
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   323
	$defaults = array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   324
		'orderby' => 'name', 'order' => 'ASC', 'number' => '',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   325
		'optioncount' => false, 'exclude_admin' => true,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   326
		'show_fullname' => false, 'hide_empty' => true,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   327
		'feed' => '', 'feed_image' => '', 'feed_type' => '', 'echo' => true,
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   328
		'style' => 'list', 'html' => true, 'exclude' => '', 'include' => ''
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   329
	);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   330
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   331
	$args = wp_parse_args( $args, $defaults );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   332
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   333
	$return = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   334
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   335
	$query_args = wp_array_slice_assoc( $args, array( 'orderby', 'order', 'number', 'exclude', 'include' ) );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   336
	$query_args['fields'] = 'ids';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   337
	$authors = get_users( $query_args );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   338
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   339
	$author_count = array();
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   340
	foreach ( (array) $wpdb->get_results( "SELECT DISTINCT post_author, COUNT(ID) AS count FROM $wpdb->posts WHERE " . get_private_posts_cap_sql( 'post' ) . " GROUP BY post_author" ) as $row ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   341
		$author_count[$row->post_author] = $row->count;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   342
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   343
	foreach ( $authors as $author_id ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   344
		$author = get_userdata( $author_id );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   345
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   346
		if ( $args['exclude_admin'] && 'admin' == $author->display_name ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   347
			continue;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   348
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   349
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   350
		$posts = isset( $author_count[$author->ID] ) ? $author_count[$author->ID] : 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   351
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   352
		if ( ! $posts && $args['hide_empty'] ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   353
			continue;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   354
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   355
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   356
		if ( $args['show_fullname'] && $author->first_name && $author->last_name ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   357
			$name = "$author->first_name $author->last_name";
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   358
		} else {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   359
			$name = $author->display_name;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   360
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   361
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   362
		if ( ! $args['html'] ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   363
			$return .= $name . ', ';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   364
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   365
			continue; // No need to go further to process HTML.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   366
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   367
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   368
		if ( 'list' == $args['style'] ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   369
			$return .= '<li>';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   370
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   371
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   372
		$link = '<a href="' . get_author_posts_url( $author->ID, $author->user_nicename ) . '" title="' . esc_attr( sprintf(__("Posts by %s"), $author->display_name) ) . '">' . $name . '</a>';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   373
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   374
		if ( ! empty( $args['feed_image'] ) || ! empty( $args['feed'] ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   375
			$link .= ' ';
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   376
			if ( empty( $args['feed_image'] ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   377
				$link .= '(';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   378
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   379
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   380
			$link .= '<a href="' . get_author_feed_link( $author->ID, $args['feed_type'] ) . '"';
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   381
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   382
			$alt = '';
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   383
			if ( ! empty( $args['feed'] ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   384
				$alt = ' alt="' . esc_attr( $args['feed'] ) . '"';
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   385
				$name = $args['feed'];
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   386
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   387
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   388
			$link .= '>';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   389
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   390
			if ( ! empty( $args['feed_image'] ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   391
				$link .= '<img src="' . esc_url( $args['feed_image'] ) . '" style="border: none;"' . $alt . ' />';
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   392
			} else {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   393
				$link .= $name;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   394
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   395
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   396
			$link .= '</a>';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   397
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   398
			if ( empty( $args['feed_image'] ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   399
				$link .= ')';
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   400
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   401
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   402
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   403
		if ( $args['optioncount'] ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   404
			$link .= ' ('. $posts . ')';
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   405
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   406
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   407
		$return .= $link;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   408
		$return .= ( 'list' == $args['style'] ) ? '</li>' : ', ';
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   409
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   410
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   411
	$return = rtrim( $return, ', ' );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   412
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   413
	if ( ! $args['echo'] ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   414
		return $return;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   415
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   416
	echo $return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   417
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   418
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   419
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   420
 * Does this site have more than one author
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   421
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   422
 * Checks to see if more than one author has published posts.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   423
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   424
 * @since 3.2.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   425
 * @return bool Whether or not we have more than one author
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   426
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   427
function is_multi_author() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   428
	global $wpdb;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   429
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   430
	if ( false === ( $is_multi_author = get_transient( 'is_multi_author' ) ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   431
		$rows = (array) $wpdb->get_col("SELECT DISTINCT post_author FROM $wpdb->posts WHERE post_type = 'post' AND post_status = 'publish' LIMIT 2");
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   432
		$is_multi_author = 1 < count( $rows ) ? 1 : 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   433
		set_transient( 'is_multi_author', $is_multi_author );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   434
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   435
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   436
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   437
	 * Filter whether the site has more than one author with published posts.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   438
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   439
	 * @since 3.2.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   440
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   441
	 * @param bool $is_multi_author Whether $is_multi_author should evaluate as true.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   442
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   443
	return apply_filters( 'is_multi_author', (bool) $is_multi_author );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   444
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   445
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   446
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   447
 * Helper function to clear the cache for number of authors.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   448
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   449
 * @private
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   450
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   451
function __clear_multi_author_cache() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   452
	delete_transient( 'is_multi_author' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   453
}