43 * get_the_author(). This function is not deprecated, but is designed to echo |
43 * get_the_author(). This function is not deprecated, but is designed to echo |
44 * the value from get_the_author() and as an result of any old theme that might |
44 * the value from get_the_author() and as an result of any old theme that might |
45 * still use the old behavior will also pass the value from get_the_author(). |
45 * still use the old behavior will also pass the value from get_the_author(). |
46 * |
46 * |
47 * The normal, expected behavior of this function is to echo the author and not |
47 * The normal, expected behavior of this function is to echo the author and not |
48 * return it. However, backwards compatibility has to be maintained. |
48 * return it. However, backward compatibility has to be maintained. |
49 * |
49 * |
50 * @since 0.71 |
50 * @since 0.71 |
51 * @see get_the_author() |
51 * @see get_the_author() |
52 * @link https://codex.wordpress.org/Template_Tags/the_author |
52 * @link https://codex.wordpress.org/Template_Tags/the_author |
53 * |
53 * |
54 * @param string $deprecated Deprecated. |
54 * @param string $deprecated Deprecated. |
55 * @param string $deprecated_echo Deprecated. Use get_the_author(). Echo the string or return it. |
55 * @param string $deprecated_echo Deprecated. Use get_the_author(). Echo the string or return it. |
56 * @return string The author's display name, from get_the_author(). |
56 * @return string|null The author's display name, from get_the_author(). |
57 */ |
57 */ |
58 function the_author( $deprecated = '', $deprecated_echo = true ) { |
58 function the_author( $deprecated = '', $deprecated_echo = true ) { |
59 if ( !empty( $deprecated ) ) |
59 if ( ! empty( $deprecated ) ) { |
60 _deprecated_argument( __FUNCTION__, '2.1' ); |
60 _deprecated_argument( __FUNCTION__, '2.1.0' ); |
61 if ( $deprecated_echo !== true ) |
61 } |
62 _deprecated_argument( __FUNCTION__, '1.5', __('Use <code>get_the_author()</code> instead if you do not want the value echoed.') ); |
62 |
63 if ( $deprecated_echo ) |
63 if ( true !== $deprecated_echo ) { |
|
64 _deprecated_argument( __FUNCTION__, '1.5.0', |
|
65 /* translators: %s: get_the_author() */ |
|
66 sprintf( __( 'Use %s instead if you do not want the value echoed.' ), |
|
67 '<code>get_the_author()</code>' |
|
68 ) |
|
69 ); |
|
70 } |
|
71 |
|
72 if ( $deprecated_echo ) { |
64 echo get_the_author(); |
73 echo get_the_author(); |
|
74 } |
|
75 |
65 return get_the_author(); |
76 return get_the_author(); |
66 } |
77 } |
67 |
78 |
68 /** |
79 /** |
69 * Retrieve the author who last edited the current post. |
80 * Retrieve the author who last edited the current post. |
70 * |
81 * |
71 * @since 2.8.0 |
82 * @since 2.8.0 |
72 * |
83 * |
73 * @return string The author's display name. |
84 * @return string|void The author's display name. |
74 */ |
85 */ |
75 function get_the_modified_author() { |
86 function get_the_modified_author() { |
76 if ( $last_id = get_post_meta( get_post()->ID, '_edit_last', true) ) { |
87 if ( $last_id = get_post_meta( get_post()->ID, '_edit_last', true) ) { |
77 $last_user = get_userdata($last_id); |
88 $last_user = get_userdata($last_id); |
78 |
89 |
79 /** |
90 /** |
80 * Filter the display name of the author who last edited the current post. |
91 * Filters the display name of the author who last edited the current post. |
81 * |
92 * |
82 * @since 2.8.0 |
93 * @since 2.8.0 |
83 * |
94 * |
84 * @param string $last_user->display_name The author's display name. |
95 * @param string $last_user->display_name The author's display name. |
85 */ |
96 */ |
86 return apply_filters('the_modified_author', $last_user->display_name); |
97 return apply_filters('the_modified_author', $last_user->display_name); |
87 } |
98 } |
88 } |
99 } |
89 |
100 |
90 /** |
101 /** |
91 * Display the name of the author who last edited the current post. |
102 * Display the name of the author who last edited the current post, |
|
103 * if the author's ID is available. |
92 * |
104 * |
93 * @since 2.8.0 |
105 * @since 2.8.0 |
94 * |
106 * |
95 * @see get_the_author() |
107 * @see get_the_author() |
96 * @return string The author's display name, from get_the_modified_author(). |
|
97 */ |
108 */ |
98 function the_modified_author() { |
109 function the_modified_author() { |
99 echo get_the_modified_author(); |
110 echo get_the_modified_author(); |
100 } |
111 } |
101 |
112 |
102 /** |
113 /** |
103 * Retrieve the requested data of the author of the current post. |
114 * Retrieves the requested data of the author of the current post. |
104 * @link https://codex.wordpress.org/Template_Tags/the_author_meta |
115 * |
|
116 * Valid values for the `$field` parameter include: |
|
117 * |
|
118 * - admin_color |
|
119 * - aim |
|
120 * - comment_shortcuts |
|
121 * - description |
|
122 * - display_name |
|
123 * - first_name |
|
124 * - ID |
|
125 * - jabber |
|
126 * - last_name |
|
127 * - nickname |
|
128 * - plugins_last_view |
|
129 * - plugins_per_page |
|
130 * - rich_editing |
|
131 * - syntax_highlighting |
|
132 * - user_activation_key |
|
133 * - user_description |
|
134 * - user_email |
|
135 * - user_firstname |
|
136 * - user_lastname |
|
137 * - user_level |
|
138 * - user_login |
|
139 * - user_nicename |
|
140 * - user_pass |
|
141 * - user_registered |
|
142 * - user_status |
|
143 * - user_url |
|
144 * - yim |
|
145 * |
105 * @since 2.8.0 |
146 * @since 2.8.0 |
106 * @param string $field selects the field of the users record. |
147 * |
107 * @param int $user_id Optional. User ID. |
148 * @global object $authordata The current author's DB object. |
108 * @return string The author's field from the current author's DB object. |
149 * |
|
150 * @param string $field Optional. The user field to retrieve. Default empty. |
|
151 * @param int $user_id Optional. User ID. |
|
152 * @return string The author's field from the current author's DB object, otherwise an empty string. |
109 */ |
153 */ |
110 function get_the_author_meta( $field = '', $user_id = false ) { |
154 function get_the_author_meta( $field = '', $user_id = false ) { |
|
155 $original_user_id = $user_id; |
|
156 |
111 if ( ! $user_id ) { |
157 if ( ! $user_id ) { |
112 global $authordata; |
158 global $authordata; |
113 $user_id = isset( $authordata->ID ) ? $authordata->ID : 0; |
159 $user_id = isset( $authordata->ID ) ? $authordata->ID : 0; |
114 } else { |
160 } else { |
115 $authordata = get_userdata( $user_id ); |
161 $authordata = get_userdata( $user_id ); |
119 $field = 'user_' . $field; |
165 $field = 'user_' . $field; |
120 |
166 |
121 $value = isset( $authordata->$field ) ? $authordata->$field : ''; |
167 $value = isset( $authordata->$field ) ? $authordata->$field : ''; |
122 |
168 |
123 /** |
169 /** |
124 * Filter the value of the requested user metadata. |
170 * Filters the value of the requested user metadata. |
125 * |
171 * |
126 * The filter name is dynamic and depends on the $field parameter of the function. |
172 * The filter name is dynamic and depends on the $field parameter of the function. |
127 * |
173 * |
128 * @since 2.8.0 |
174 * @since 2.8.0 |
129 * |
175 * @since 4.3.0 The `$original_user_id` parameter was added. |
130 * @param string $value The value of the metadata. |
176 * |
131 * @param int $user_id The user ID. |
177 * @param string $value The value of the metadata. |
|
178 * @param int $user_id The user ID for the value. |
|
179 * @param int|bool $original_user_id The original user ID, as passed to the function. |
132 */ |
180 */ |
133 return apply_filters( 'get_the_author_' . $field, $value, $user_id ); |
181 return apply_filters( "get_the_author_{$field}", $value, $user_id, $original_user_id ); |
134 } |
182 } |
135 |
183 |
136 /** |
184 /** |
137 * Retrieve the requested data of the author of the current post. |
185 * Outputs the field from the user's DB object. Defaults to current post's author. |
138 * @link https://codex.wordpress.org/Template_Tags/the_author_meta |
186 * |
139 * @since 2.8.0 |
187 * @since 2.8.0 |
140 * @param string $field selects the field of the users record. |
188 * |
141 * @param int $user_id Optional. User ID. |
189 * @param string $field Selects the field of the users record. See get_the_author_meta() |
142 * @echo string The author's field from the current author's DB object. |
190 * for the list of possible fields. |
|
191 * @param int $user_id Optional. User ID. |
|
192 * |
|
193 * @see get_the_author_meta() |
143 */ |
194 */ |
144 function the_author_meta( $field = '', $user_id = false ) { |
195 function the_author_meta( $field = '', $user_id = false ) { |
145 $author_meta = get_the_author_meta( $field, $user_id ); |
196 $author_meta = get_the_author_meta( $field, $user_id ); |
146 |
197 |
147 /** |
198 /** |
152 * @since 2.8.0 |
203 * @since 2.8.0 |
153 * |
204 * |
154 * @param string $author_meta The value of the metadata. |
205 * @param string $author_meta The value of the metadata. |
155 * @param int $user_id The user ID. |
206 * @param int $user_id The user ID. |
156 */ |
207 */ |
157 echo apply_filters( 'the_author_' . $field, $author_meta, $user_id ); |
208 echo apply_filters( "the_author_{$field}", $author_meta, $user_id ); |
158 } |
209 } |
159 |
210 |
160 /** |
211 /** |
161 * Retrieve either author's link or author's name. |
212 * Retrieve either author's link or author's name. |
162 * |
213 * |
163 * If the author has a home page set, return an HTML link, otherwise just return the |
214 * If the author has a home page set, return an HTML link, otherwise just return the |
164 * author's name. |
215 * author's name. |
|
216 * |
|
217 * @since 3.0.0 |
|
218 * |
|
219 * @return string|null An HTML link if the author's url exist in user meta, |
|
220 * else the result of get_the_author(). |
165 */ |
221 */ |
166 function get_the_author_link() { |
222 function get_the_author_link() { |
167 if ( get_the_author_meta('url') ) { |
223 if ( get_the_author_meta('url') ) { |
168 return '<a href="' . esc_url( get_the_author_meta('url') ) . '" title="' . esc_attr( sprintf(__("Visit %s’s website"), get_the_author()) ) . '" rel="author external">' . get_the_author() . '</a>'; |
224 return sprintf( '<a href="%1$s" title="%2$s" rel="author external">%3$s</a>', |
|
225 esc_url( get_the_author_meta('url') ), |
|
226 /* translators: %s: author's display name */ |
|
227 esc_attr( sprintf( __( 'Visit %s’s website' ), get_the_author() ) ), |
|
228 get_the_author() |
|
229 ); |
169 } else { |
230 } else { |
170 return get_the_author(); |
231 return get_the_author(); |
171 } |
232 } |
172 } |
233 } |
173 |
234 |
209 function the_author_posts() { |
270 function the_author_posts() { |
210 echo get_the_author_posts(); |
271 echo get_the_author_posts(); |
211 } |
272 } |
212 |
273 |
213 /** |
274 /** |
214 * Display an HTML link to the author page of the author of the current post. |
275 * Retrieves an HTML link to the author page of the current post's author. |
215 * |
276 * |
216 * Does just echo get_author_posts_url() function, like the others do. The |
277 * Returns an HTML-formatted link using get_author_posts_url(). |
217 * reason for this, is that another function is used to help in printing the |
278 * |
218 * link to the author's posts. |
279 * @since 4.4.0 |
219 * |
280 * |
220 * @link https://codex.wordpress.org/Template_Tags/the_author_posts_link |
281 * @global object $authordata The current author's DB object. |
221 * @since 1.2.0 |
282 * |
222 * @param string $deprecated Deprecated. |
283 * @return string An HTML link to the author page. |
223 */ |
284 */ |
224 function the_author_posts_link($deprecated = '') { |
285 function get_the_author_posts_link() { |
225 if ( !empty( $deprecated ) ) |
|
226 _deprecated_argument( __FUNCTION__, '2.1' ); |
|
227 |
|
228 global $authordata; |
286 global $authordata; |
229 if ( !is_object( $authordata ) ) |
287 if ( ! is_object( $authordata ) ) { |
230 return false; |
288 return; |
231 $link = sprintf( |
289 } |
232 '<a href="%1$s" title="%2$s" rel="author">%3$s</a>', |
290 |
|
291 $link = sprintf( '<a href="%1$s" title="%2$s" rel="author">%3$s</a>', |
233 esc_url( get_author_posts_url( $authordata->ID, $authordata->user_nicename ) ), |
292 esc_url( get_author_posts_url( $authordata->ID, $authordata->user_nicename ) ), |
|
293 /* translators: %s: author's display name */ |
234 esc_attr( sprintf( __( 'Posts by %s' ), get_the_author() ) ), |
294 esc_attr( sprintf( __( 'Posts by %s' ), get_the_author() ) ), |
235 get_the_author() |
295 get_the_author() |
236 ); |
296 ); |
237 |
297 |
238 /** |
298 /** |
239 * Filter the link to the author page of the author of the current post. |
299 * Filters the link to the author page of the author of the current post. |
240 * |
300 * |
241 * @since 2.9.0 |
301 * @since 2.9.0 |
242 * |
302 * |
243 * @param string $link HTML link. |
303 * @param string $link HTML link. |
244 */ |
304 */ |
245 echo apply_filters( 'the_author_posts_link', $link ); |
305 return apply_filters( 'the_author_posts_link', $link ); |
|
306 } |
|
307 |
|
308 /** |
|
309 * Displays an HTML link to the author page of the current post's author. |
|
310 * |
|
311 * @since 1.2.0 |
|
312 * @since 4.4.0 Converted into a wrapper for get_the_author_posts_link() |
|
313 * |
|
314 * @param string $deprecated Unused. |
|
315 */ |
|
316 function the_author_posts_link( $deprecated = '' ) { |
|
317 if ( ! empty( $deprecated ) ) { |
|
318 _deprecated_argument( __FUNCTION__, '2.1.0' ); |
|
319 } |
|
320 echo get_the_author_posts_link(); |
246 } |
321 } |
247 |
322 |
248 /** |
323 /** |
249 * Retrieve the URL to the author page for the user with the ID provided. |
324 * Retrieve the URL to the author page for the user with the ID provided. |
250 * |
325 * |
251 * @since 2.1.0 |
326 * @since 2.1.0 |
252 * @uses $wp_rewrite WP_Rewrite |
327 * |
|
328 * @global WP_Rewrite $wp_rewrite |
|
329 * |
|
330 * @param int $author_id Author ID. |
|
331 * @param string $author_nicename Optional. The author's nicename (slug). Default empty. |
253 * @return string The URL to the author's page. |
332 * @return string The URL to the author's page. |
254 */ |
333 */ |
255 function get_author_posts_url($author_id, $author_nicename = '') { |
334 function get_author_posts_url( $author_id, $author_nicename = '' ) { |
256 global $wp_rewrite; |
335 global $wp_rewrite; |
257 $auth_ID = (int) $author_id; |
336 $auth_ID = (int) $author_id; |
258 $link = $wp_rewrite->get_author_permastruct(); |
337 $link = $wp_rewrite->get_author_permastruct(); |
259 |
338 |
260 if ( empty($link) ) { |
339 if ( empty($link) ) { |
283 |
362 |
284 return $link; |
363 return $link; |
285 } |
364 } |
286 |
365 |
287 /** |
366 /** |
288 * List all the authors of the blog, with several options available. |
367 * List all the authors of the site, with several options available. |
289 * |
368 * |
290 * @link https://codex.wordpress.org/Template_Tags/wp_list_authors |
369 * @link https://codex.wordpress.org/Template_Tags/wp_list_authors |
291 * |
370 * |
292 * @since 1.2.0 |
371 * @since 1.2.0 |
|
372 * |
|
373 * @global wpdb $wpdb WordPress database abstraction object. |
293 * |
374 * |
294 * @param string|array $args { |
375 * @param string|array $args { |
295 * Optional. Array or string of default arguments. |
376 * Optional. Array or string of default arguments. |
296 * |
377 * |
297 * @type string $orderby How to sort the authors. Accepts 'nicename', 'email', 'url', 'registered', |
378 * @type string $orderby How to sort the authors. Accepts 'nicename', 'email', 'url', 'registered', |
298 * 'user_nicename', 'user_email', 'user_url', 'user_registered', 'name', |
379 * 'user_nicename', 'user_email', 'user_url', 'user_registered', 'name', |
299 * 'display_name', 'post_count', 'ID', 'meta_value', 'user_login'. Default 'name'. |
380 * 'display_name', 'post_count', 'ID', 'meta_value', 'user_login'. Default 'name'. |
300 * @type string $order Sorting direction for $orderby. Accepts 'ASC', 'DESC'. Default 'ASC'. |
381 * @type string $order Sorting direction for $orderby. Accepts 'ASC', 'DESC'. Default 'ASC'. |
301 * @type int $number Maximum authors to return or display. Default empty (all authors). |
382 * @type int $number Maximum authors to return or display. Default empty (all authors). |
302 * @type bool $optioncount Show the count in parenthesis next to the author's name. Default false. |
383 * @type bool $optioncount Show the count in parenthesis next to the author's name. Default false. |
303 * @type bool $exclude_admin Whether to exclude the 'admin' account, if it exists. Default false. |
384 * @type bool $exclude_admin Whether to exclude the 'admin' account, if it exists. Default false. |
304 * @type bool $show_fullname Whether to show the author's full name. Default false. |
385 * @type bool $show_fullname Whether to show the author's full name. Default false. |
305 * @type bool $hide_empty Whether to hide any authors with no posts. Default true. |
386 * @type bool $hide_empty Whether to hide any authors with no posts. Default true. |
306 * @type string $feed If not empty, show a link to the author's feed and use this text as the alt |
387 * @type string $feed If not empty, show a link to the author's feed and use this text as the alt |
307 * parameter of the link. Default empty. |
388 * parameter of the link. Default empty. |
308 * @type string $feed_image If not empty, show a link to the author's feed and use this image URL as |
389 * @type string $feed_image If not empty, show a link to the author's feed and use this image URL as |
309 * clickable anchor. Default empty. |
390 * clickable anchor. Default empty. |
310 * @type string $feed_type The feed type to link to, such as 'rss2'. Defaults to default feed type. |
391 * @type string $feed_type The feed type to link to, such as 'rss2'. Defaults to default feed type. |
311 * @type bool $echo Whether to output the result or instead return it. Default true. |
392 * @type bool $echo Whether to output the result or instead return it. Default true. |
312 * @type string $style If 'list', each author is wrapped in an `<li>` element, otherwise the authors |
393 * @type string $style If 'list', each author is wrapped in an `<li>` element, otherwise the authors |
313 * will be separated by commas. |
394 * will be separated by commas. |
314 * @type bool $html Whether to list the items in HTML form or plaintext. Default true. |
395 * @type bool $html Whether to list the items in HTML form or plaintext. Default true. |
315 * @type string $exclude An array, comma-, or space-separated list of author IDs to exclude. Default empty. |
396 * @type array|string $exclude Array or comma/space-separated list of author IDs to exclude. Default empty. |
316 * @type string $exclude An array, comma-, or space-separated list of author IDs to include. Default empty. |
397 * @type array|string $include Array or comma/space-separated list of author IDs to include. Default empty. |
317 * } |
398 * } |
318 * @return null|string The output, if echo is set to false. Otherwise null. |
399 * @return string|void The output, if echo is set to false. |
319 */ |
400 */ |
320 function wp_list_authors( $args = '' ) { |
401 function wp_list_authors( $args = '' ) { |
321 global $wpdb; |
402 global $wpdb; |
322 |
403 |
323 $defaults = array( |
404 $defaults = array( |