--- a/wp/wp-includes/author-template.php Mon Oct 14 18:06:33 2019 +0200
+++ b/wp/wp-includes/author-template.php Mon Oct 14 18:28:13 2019 +0200
@@ -20,11 +20,12 @@
* @param string $deprecated Deprecated.
* @return string|null The author's display name.
*/
-function get_the_author($deprecated = '') {
+function get_the_author( $deprecated = '' ) {
global $authordata;
- if ( !empty( $deprecated ) )
+ if ( ! empty( $deprecated ) ) {
_deprecated_argument( __FUNCTION__, '2.1.0' );
+ }
/**
* Filters the display name of the current post's author.
@@ -33,7 +34,7 @@
*
* @param string $authordata->display_name The author's display name.
*/
- return apply_filters('the_author', is_object($authordata) ? $authordata->display_name : null);
+ return apply_filters( 'the_author', is_object( $authordata ) ? $authordata->display_name : null );
}
/**
@@ -51,8 +52,8 @@
* @see get_the_author()
* @link https://codex.wordpress.org/Template_Tags/the_author
*
- * @param string $deprecated Deprecated.
- * @param string $deprecated_echo Deprecated. Use get_the_author(). Echo the string or return it.
+ * @param string $deprecated Deprecated.
+ * @param bool $deprecated_echo Deprecated. Use get_the_author(). Echo the string or return it.
* @return string|null The author's display name, from get_the_author().
*/
function the_author( $deprecated = '', $deprecated_echo = true ) {
@@ -61,9 +62,12 @@
}
if ( true !== $deprecated_echo ) {
- _deprecated_argument( __FUNCTION__, '1.5.0',
+ _deprecated_argument(
+ __FUNCTION__,
+ '1.5.0',
/* translators: %s: get_the_author() */
- sprintf( __( 'Use %s instead if you do not want the value echoed.' ),
+ sprintf(
+ __( 'Use %s instead if you do not want the value echoed.' ),
'<code>get_the_author()</code>'
)
);
@@ -84,8 +88,10 @@
* @return string|void The author's display name.
*/
function get_the_modified_author() {
- if ( $last_id = get_post_meta( get_post()->ID, '_edit_last', true) ) {
- $last_user = get_userdata($last_id);
+ $last_id = get_post_meta( get_post()->ID, '_edit_last', true );
+
+ if ( $last_id ) {
+ $last_user = get_userdata( $last_id );
/**
* Filters the display name of the author who last edited the current post.
@@ -94,7 +100,7 @@
*
* @param string $last_user->display_name The author's display name.
*/
- return apply_filters('the_modified_author', $last_user->display_name);
+ return apply_filters( 'the_modified_author', $last_user->display_name );
}
}
@@ -147,8 +153,8 @@
*
* @global object $authordata The current author's DB object.
*
- * @param string $field Optional. The user field to retrieve. Default empty.
- * @param int $user_id Optional. User ID.
+ * @param string $field Optional. The user field to retrieve. Default empty.
+ * @param int|false $user_id Optional. User ID.
* @return string The author's field from the current author's DB object, otherwise an empty string.
*/
function get_the_author_meta( $field = '', $user_id = false ) {
@@ -161,8 +167,9 @@
$authordata = get_userdata( $user_id );
}
- if ( in_array( $field, array( 'login', 'pass', 'nicename', 'email', 'url', 'registered', 'activation_key', 'status' ) ) )
+ if ( in_array( $field, array( 'login', 'pass', 'nicename', 'email', 'url', 'registered', 'activation_key', 'status' ) ) ) {
$field = 'user_' . $field;
+ }
$value = isset( $authordata->$field ) ? $authordata->$field : '';
@@ -174,9 +181,9 @@
* @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|bool $original_user_id The original user ID, as passed to the function.
+ * @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 );
}
@@ -186,9 +193,9 @@
*
* @since 2.8.0
*
- * @param string $field Selects the field of the users record. See get_the_author_meta()
- * for the list of possible fields.
- * @param int $user_id Optional. User ID.
+ * @param string $field Selects the field of the users record. See get_the_author_meta()
+ * for the list of possible fields.
+ * @param int|false $user_id Optional. User ID.
*
* @see get_the_author_meta()
*/
@@ -202,8 +209,8 @@
*
* @since 2.8.0
*
- * @param string $author_meta The value of the metadata.
- * @param int $user_id The user ID.
+ * @param string $author_meta The value of the metadata.
+ * @param int|false $user_id The user ID.
*/
echo apply_filters( "the_author_{$field}", $author_meta, $user_id );
}
@@ -220,9 +227,10 @@
* else the result of get_the_author().
*/
function get_the_author_link() {
- if ( get_the_author_meta('url') ) {
- return sprintf( '<a href="%1$s" title="%2$s" rel="author external">%3$s</a>',
- esc_url( get_the_author_meta('url') ),
+ if ( get_the_author_meta( 'url' ) ) {
+ return sprintf(
+ '<a href="%1$s" title="%2$s" rel="author external">%3$s</a>',
+ esc_url( get_the_author_meta( 'url' ) ),
/* translators: %s: author's display name */
esc_attr( sprintf( __( 'Visit %s’s website' ), get_the_author() ) ),
get_the_author()
@@ -280,15 +288,16 @@
*
* @global object $authordata The current author's DB object.
*
- * @return string An HTML link to the author page.
+ * @return string An HTML link to the author page, or an empty string if $authordata isn't defined.
*/
function get_the_author_posts_link() {
global $authordata;
if ( ! is_object( $authordata ) ) {
- return;
+ return '';
}
- $link = sprintf( '<a href="%1$s" title="%2$s" rel="author">%3$s</a>',
+ $link = sprintf(
+ '<a href="%1$s" title="%2$s" rel="author">%3$s</a>',
esc_url( get_author_posts_url( $authordata->ID, $authordata->user_nicename ) ),
/* translators: %s: author's display name */
esc_attr( sprintf( __( 'Posts by %s' ), get_the_author() ) ),
@@ -334,18 +343,19 @@
function get_author_posts_url( $author_id, $author_nicename = '' ) {
global $wp_rewrite;
$auth_ID = (int) $author_id;
- $link = $wp_rewrite->get_author_permastruct();
+ $link = $wp_rewrite->get_author_permastruct();
- if ( empty($link) ) {
+ if ( empty( $link ) ) {
$file = home_url( '/' );
$link = $file . '?author=' . $auth_ID;
} else {
if ( '' == $author_nicename ) {
- $user = get_userdata($author_id);
- if ( !empty($user->user_nicename) )
+ $user = get_userdata( $author_id );
+ if ( ! empty( $user->user_nicename ) ) {
$author_nicename = $user->user_nicename;
+ }
}
- $link = str_replace('%author%', $author_nicename, $link);
+ $link = str_replace( '%author%', $author_nicename, $link );
$link = home_url( user_trailingslashit( $link ) );
}
@@ -381,7 +391,7 @@
* @type string $order Sorting direction for $orderby. Accepts 'ASC', 'DESC'. Default 'ASC'.
* @type int $number Maximum authors to return or display. Default empty (all authors).
* @type bool $optioncount Show the count in parenthesis next to the author's name. Default false.
- * @type bool $exclude_admin Whether to exclude the 'admin' account, if it exists. Default false.
+ * @type bool $exclude_admin Whether to exclude the 'admin' account, if it exists. Default true.
* @type bool $show_fullname Whether to show the author's full name. Default false.
* @type bool $hide_empty Whether to hide any authors with no posts. Default true.
* @type string $feed If not empty, show a link to the author's feed and use this text as the alt
@@ -402,35 +412,45 @@
global $wpdb;
$defaults = array(
- 'orderby' => 'name', 'order' => 'ASC', 'number' => '',
- 'optioncount' => false, 'exclude_admin' => true,
- 'show_fullname' => false, 'hide_empty' => true,
- 'feed' => '', 'feed_image' => '', 'feed_type' => '', 'echo' => true,
- 'style' => 'list', 'html' => true, 'exclude' => '', 'include' => ''
+ 'orderby' => 'name',
+ 'order' => 'ASC',
+ 'number' => '',
+ 'optioncount' => false,
+ 'exclude_admin' => true,
+ 'show_fullname' => false,
+ 'hide_empty' => true,
+ 'feed' => '',
+ 'feed_image' => '',
+ 'feed_type' => '',
+ 'echo' => true,
+ 'style' => 'list',
+ 'html' => true,
+ 'exclude' => '',
+ 'include' => '',
);
$args = wp_parse_args( $args, $defaults );
$return = '';
- $query_args = wp_array_slice_assoc( $args, array( 'orderby', 'order', 'number', 'exclude', 'include' ) );
+ $query_args = wp_array_slice_assoc( $args, array( 'orderby', 'order', 'number', 'exclude', 'include' ) );
$query_args['fields'] = 'ids';
- $authors = get_users( $query_args );
+ $authors = get_users( $query_args );
$author_count = array();
- 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 ) {
- $author_count[$row->post_author] = $row->count;
+ 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 ) {
+ $author_count[ $row->post_author ] = $row->count;
}
foreach ( $authors as $author_id ) {
- $author = get_userdata( $author_id );
+ $posts = isset( $author_count[ $author_id ] ) ? $author_count[ $author_id ] : 0;
- if ( $args['exclude_admin'] && 'admin' == $author->display_name ) {
+ if ( ! $posts && $args['hide_empty'] ) {
continue;
}
- $posts = isset( $author_count[$author->ID] ) ? $author_count[$author->ID] : 0;
+ $author = get_userdata( $author_id );
- if ( ! $posts && $args['hide_empty'] ) {
+ if ( $args['exclude_admin'] && 'admin' === $author->display_name ) {
continue;
}
@@ -450,7 +470,8 @@
$return .= '<li>';
}
- $link = sprintf( '<a href="%1$s" title="%2$s">%3$s</a>',
+ $link = sprintf(
+ '<a href="%1$s" title="%2$s">%3$s</a>',
get_author_posts_url( $author->ID, $author->user_nicename ),
/* translators: %s: author's display name */
esc_attr( sprintf( __( 'Posts by %s' ), $author->display_name ) ),
@@ -467,7 +488,7 @@
$alt = '';
if ( ! empty( $args['feed'] ) ) {
- $alt = ' alt="' . esc_attr( $args['feed'] ) . '"';
+ $alt = ' alt="' . esc_attr( $args['feed'] ) . '"';
$name = $args['feed'];
}
@@ -487,7 +508,7 @@
}
if ( $args['optioncount'] ) {
- $link .= ' ('. $posts . ')';
+ $link .= ' (' . $posts . ')';
}
$return .= $link;
@@ -503,10 +524,14 @@
}
/**
- * Does this site have more than one author
+ * Determines whether this site has more than one author.
*
* Checks to see if more than one author has published posts.
*
+ * For more information on this and similar theme functions, check out
+ * the {@link https://developer.wordpress.org/themes/basics/conditional-tags/
+ * Conditional Tags} article in the Theme Developer Handbook.
+ *
* @since 3.2.0
*
* @global wpdb $wpdb WordPress database abstraction object.
@@ -517,7 +542,7 @@
global $wpdb;
if ( false === ( $is_multi_author = get_transient( 'is_multi_author' ) ) ) {
- $rows = (array) $wpdb->get_col("SELECT DISTINCT post_author FROM $wpdb->posts WHERE post_type = 'post' AND post_status = 'publish' LIMIT 2");
+ $rows = (array) $wpdb->get_col( "SELECT DISTINCT post_author FROM $wpdb->posts WHERE post_type = 'post' AND post_status = 'publish' LIMIT 2" );
$is_multi_author = 1 < count( $rows ) ? 1 : 0;
set_transient( 'is_multi_author', $is_multi_author );
}