36 */ |
36 */ |
37 return apply_filters( 'the_author', is_object( $authordata ) ? $authordata->display_name : null ); |
37 return apply_filters( 'the_author', is_object( $authordata ) ? $authordata->display_name : null ); |
38 } |
38 } |
39 |
39 |
40 /** |
40 /** |
41 * Display the name of the author of the current post. |
41 * Displays the name of the author of the current post. |
42 * |
42 * |
43 * The behavior of this function is based off of old functionality predating |
43 * The behavior of this function is based off of old functionality predating |
44 * get_the_author(). This function is not deprecated, but is designed to echo |
44 * get_the_author(). This function is not deprecated, but is designed to echo |
45 * the value from get_the_author() and as an result of any old theme that might |
45 * the value from get_the_author() and as an result of any old theme that might |
46 * still use the old behavior will also pass the value from get_the_author(). |
46 * still use the old behavior will also pass the value from get_the_author(). |
80 |
80 |
81 return get_the_author(); |
81 return get_the_author(); |
82 } |
82 } |
83 |
83 |
84 /** |
84 /** |
85 * Retrieve the author who last edited the current post. |
85 * Retrieves the author who last edited the current post. |
86 * |
86 * |
87 * @since 2.8.0 |
87 * @since 2.8.0 |
88 * |
88 * |
89 * @return string|void The author's display name. |
89 * @return string|void The author's display name, empty string if unknown. |
90 */ |
90 */ |
91 function get_the_modified_author() { |
91 function get_the_modified_author() { |
92 $last_id = get_post_meta( get_post()->ID, '_edit_last', true ); |
92 $last_id = get_post_meta( get_post()->ID, '_edit_last', true ); |
93 |
93 |
94 if ( $last_id ) { |
94 if ( $last_id ) { |
97 /** |
97 /** |
98 * Filters the display name of the author who last edited the current post. |
98 * Filters the display name of the author who last edited the current post. |
99 * |
99 * |
100 * @since 2.8.0 |
100 * @since 2.8.0 |
101 * |
101 * |
102 * @param string $display_name The author's display name. |
102 * @param string $display_name The author's display name, empty string if unknown. |
103 */ |
103 */ |
104 return apply_filters( 'the_modified_author', $last_user->display_name ); |
104 return apply_filters( 'the_modified_author', $last_user ? $last_user->display_name : '' ); |
105 } |
105 } |
106 } |
106 } |
107 |
107 |
108 /** |
108 /** |
109 * Display the name of the author who last edited the current post, |
109 * Displays the name of the author who last edited the current post, |
110 * if the author's ID is available. |
110 * if the author's ID is available. |
111 * |
111 * |
112 * @since 2.8.0 |
112 * @since 2.8.0 |
113 * |
113 * |
114 * @see get_the_author() |
114 * @see get_the_author() |
202 */ |
202 */ |
203 function the_author_meta( $field = '', $user_id = false ) { |
203 function the_author_meta( $field = '', $user_id = false ) { |
204 $author_meta = get_the_author_meta( $field, $user_id ); |
204 $author_meta = get_the_author_meta( $field, $user_id ); |
205 |
205 |
206 /** |
206 /** |
207 * The value of the requested user metadata. |
207 * Filters the value of the requested user metadata. |
208 * |
208 * |
209 * The filter name is dynamic and depends on the $field parameter of the function. |
209 * The filter name is dynamic and depends on the $field parameter of the function. |
210 * |
210 * |
211 * @since 2.8.0 |
211 * @since 2.8.0 |
212 * |
212 * |
215 */ |
215 */ |
216 echo apply_filters( "the_author_{$field}", $author_meta, $user_id ); |
216 echo apply_filters( "the_author_{$field}", $author_meta, $user_id ); |
217 } |
217 } |
218 |
218 |
219 /** |
219 /** |
220 * Retrieve either author's link or author's name. |
220 * Retrieves either author's link or author's name. |
221 * |
221 * |
222 * If the author has a home page set, return an HTML link, otherwise just return the |
222 * If the author has a home page set, return an HTML link, otherwise just return the |
223 * author's name. |
223 * author's name. |
224 * |
224 * |
225 * @since 3.0.0 |
225 * @since 3.0.0 |
226 * |
226 * |
|
227 * @global WP_User $authordata The current author's data. |
|
228 * |
227 * @return string|null An HTML link if the author's url exist in user meta, |
229 * @return string|null An HTML link if the author's url exist in user meta, |
228 * else the result of get_the_author(). |
230 * else the result of get_the_author(). |
229 */ |
231 */ |
230 function get_the_author_link() { |
232 function get_the_author_link() { |
231 if ( get_the_author_meta( 'url' ) ) { |
233 if ( get_the_author_meta( 'url' ) ) { |
232 return sprintf( |
234 global $authordata; |
|
235 |
|
236 $author_url = get_the_author_meta( 'url' ); |
|
237 $author_display_name = get_the_author(); |
|
238 |
|
239 $link = sprintf( |
233 '<a href="%1$s" title="%2$s" rel="author external">%3$s</a>', |
240 '<a href="%1$s" title="%2$s" rel="author external">%3$s</a>', |
234 esc_url( get_the_author_meta( 'url' ) ), |
241 esc_url( $author_url ), |
235 /* translators: %s: Author's display name. */ |
242 /* translators: %s: Author's display name. */ |
236 esc_attr( sprintf( __( 'Visit %s’s website' ), get_the_author() ) ), |
243 esc_attr( sprintf( __( 'Visit %s’s website' ), $author_display_name ) ), |
237 get_the_author() |
244 $author_display_name |
238 ); |
245 ); |
|
246 |
|
247 /** |
|
248 * Filters the author URL link HTML. |
|
249 * |
|
250 * @since 6.0.0 |
|
251 * |
|
252 * @param string $link The default rendered author HTML link. |
|
253 * @param string $author_url Author's URL. |
|
254 * @param WP_User $authordata Author user data. |
|
255 */ |
|
256 return apply_filters( 'the_author_link', $link, $author_url, $authordata ); |
239 } else { |
257 } else { |
240 return get_the_author(); |
258 return get_the_author(); |
241 } |
259 } |
242 } |
260 } |
243 |
261 |
244 /** |
262 /** |
245 * Display either author's link or author's name. |
263 * Displays either author's link or author's name. |
246 * |
264 * |
247 * If the author has a home page set, echo an HTML link, otherwise just echo the |
265 * If the author has a home page set, echo an HTML link, otherwise just echo the |
248 * author's name. |
266 * author's name. |
249 * |
267 * |
250 * @link https://developer.wordpress.org/reference/functions/the_author_link/ |
268 * @link https://developer.wordpress.org/reference/functions/the_author_link/ |
341 * @param string $author_nicename Optional. The author's nicename (slug). Default empty. |
359 * @param string $author_nicename Optional. The author's nicename (slug). Default empty. |
342 * @return string The URL to the author's page. |
360 * @return string The URL to the author's page. |
343 */ |
361 */ |
344 function get_author_posts_url( $author_id, $author_nicename = '' ) { |
362 function get_author_posts_url( $author_id, $author_nicename = '' ) { |
345 global $wp_rewrite; |
363 global $wp_rewrite; |
346 $auth_ID = (int) $author_id; |
364 |
347 $link = $wp_rewrite->get_author_permastruct(); |
365 $author_id = (int) $author_id; |
|
366 $link = $wp_rewrite->get_author_permastruct(); |
348 |
367 |
349 if ( empty( $link ) ) { |
368 if ( empty( $link ) ) { |
350 $file = home_url( '/' ); |
369 $file = home_url( '/' ); |
351 $link = $file . '?author=' . $auth_ID; |
370 $link = $file . '?author=' . $author_id; |
352 } else { |
371 } else { |
353 if ( '' === $author_nicename ) { |
372 if ( '' === $author_nicename ) { |
354 $user = get_userdata( $author_id ); |
373 $user = get_userdata( $author_id ); |
355 if ( ! empty( $user->user_nicename ) ) { |
374 if ( ! empty( $user->user_nicename ) ) { |
356 $author_nicename = $user->user_nicename; |
375 $author_nicename = $user->user_nicename; |