Projects : mp-wp : mp-wp_genesis

mp-wp/wp-includes/author-template.php

Dir - Raw

1<?php
2/**
3 * Author Template functions for use in themes.
4 *
5 * These functions must be used within the WordPress Loop.
6 *
7 * @link http://codex.wordpress.org/Author_Templates
8 *
9 * @package WordPress
10 * @subpackage Template
11 */
12
13/**
14 * Retrieve the author of the current post.
15 *
16 * @since 1.5
17 * @uses $authordata The current author's DB object.
18 * @uses apply_filters() Calls 'the_author' hook on the author display name.
19 *
20 * @param string $deprecated Deprecated.
21 * @return string The author's display name.
22 */
23function get_the_author($deprecated = '') {
24 global $authordata;
25 return apply_filters('the_author', $authordata->display_name);
26}
27
28/**
29 * Display the name of the author of the current post.
30 *
31 * The behavior of this function is based off of old functionality predating
32 * get_the_author(). This function is not deprecated, but is designed to echo
33 * the value from get_the_author() and as an result of any old theme that might
34 * still use the old behavior will also pass the value from get_the_author().
35 *
36 * The normal, expected behavior of this function is to echo the author and not
37 * return it. However, backwards compatiability has to be maintained.
38 *
39 * @since 0.71
40 * @see get_the_author()
41 * @link http://codex.wordpress.org/Template_Tags/the_author
42 *
43 * @param string $deprecated Deprecated.
44 * @param string $deprecated_echo Echo the string or return it.
45 * @return string The author's display name, from get_the_author().
46 */
47function the_author($deprecated = '', $deprecated_echo = true) {
48 if ( $deprecated_echo )
49 echo get_the_author();
50 return get_the_author();
51}
52
53/**
54 * Retrieve the description of the author of the current post.
55 *
56 * @since 1.5
57 * @uses $authordata The current author's DB object.
58 * @return string The author's description.
59 */
60function get_the_author_description() {
61 global $authordata;
62 return $authordata->description;
63}
64
65/**
66 * Display the description of the author of the current post.
67 *
68 * @link http://codex.wordpress.org/Template_Tags/the_author_description
69 * @since 1.0.0
70 * @see get_the_author_description()
71 */
72function the_author_description() {
73 echo get_the_author_description();
74}
75
76/**
77 * Retrieve the login name of the author of the current post.
78 *
79 * @since 1.5
80 * @uses $authordata The current author's DB object.
81 * @return string The author's login name (username).
82 */
83function get_the_author_login() {
84 global $authordata;
85 return $authordata->user_login;
86}
87
88/**
89 * Display the login name of the author of the current post.
90 *
91 * @link http://codex.wordpress.org/Template_Tags/the_author_login
92 * @since 0.71
93 * @see get_the_author_login()
94 */
95function the_author_login() {
96 echo get_the_author_login();
97}
98
99/**
100 * Retrieve the first name of the author of the current post.
101 *
102 * @since 1.5
103 * @uses $authordata The current author's DB object.
104 * @return string The author's first name.
105 */
106function get_the_author_firstname() {
107 global $authordata;
108 return $authordata->first_name;
109}
110
111/**
112 * Display the first name of the author of the current post.
113 *
114 * @link http://codex.wordpress.org/Template_Tags/the_author_firstname
115 * @since 0.71
116 * @uses get_the_author_firstname()
117 */
118function the_author_firstname() {
119 echo get_the_author_firstname();
120}
121
122/**
123 * Retrieve the last name of the author of the current post.
124 *
125 * @since 1.5
126 * @uses $authordata The current author's DB object.
127 * @return string The author's last name.
128 */
129function get_the_author_lastname() {
130 global $authordata;
131 return $authordata->last_name;
132}
133
134/**
135 * Display the last name of the author of the current post.
136 *
137 * @link http://codex.wordpress.org/Template_Tags/the_author_lastname
138 * @since 0.71
139 * @uses get_the_author_lastname()
140 */
141function the_author_lastname() {
142 echo get_the_author_lastname();
143}
144
145/**
146 * Retrieve the nickname of the author of the current post.
147 *
148 * @since 1.5
149 * @uses $authordata The current author's DB object.
150 * @return string The author's nickname.
151 */
152function get_the_author_nickname() {
153 global $authordata;
154 return $authordata->nickname;
155}
156
157/**
158 * Display the nickname of the author of the current post.
159 *
160 * @link http://codex.wordpress.org/Template_Tags/the_author_nickname
161 * @since 0.71
162 * @uses get_the_author_nickname()
163 */
164function the_author_nickname() {
165 echo get_the_author_nickname();
166}
167
168/**
169 * Retrieve the ID of the author of the current post.
170 *
171 * @since 1.5
172 * @uses $authordata The current author's DB object.
173 * @return int The author's ID.
174 */
175function get_the_author_ID() {
176 global $authordata;
177 return (int) $authordata->ID;
178}
179
180/**
181 * Display the ID of the author of the current post.
182 *
183 * @link http://codex.wordpress.org/Template_Tags/the_author_ID
184 * @since 0.71
185 * @uses get_the_author_ID()
186 */
187function the_author_ID() {
188 echo get_the_author_id();
189}
190
191/**
192 * Retrieve the email of the author of the current post.
193 *
194 * @since 1.5
195 * @uses $authordata The current author's DB object.
196 * @return string The author's username.
197 */
198function get_the_author_email() {
199 global $authordata;
200 return $authordata->user_email;
201}
202
203/**
204 * Display the email of the author of the current post.
205 *
206 * @link http://codex.wordpress.org/Template_Tags/the_author_email
207 * @since 0.71
208 * @uses get_the_author_email()
209 */
210function the_author_email() {
211 echo apply_filters('the_author_email', get_the_author_email() );
212}
213
214/**
215 * Retrieve the URL to the home page of the author of the current post.
216 *
217 * @since 1.5
218 * @uses $authordata The current author's DB object.
219 * @return string The URL to the author's page.
220 */
221function get_the_author_url() {
222 global $authordata;
223
224 if ( 'http://' == $authordata->user_url )
225 return '';
226
227 return $authordata->user_url;
228}
229
230/**
231 * Display the URL to the home page of the author of the current post.
232 *
233 * @link http://codex.wordpress.org/Template_Tags/the_author_url
234 * @since 0.71
235 * @uses get_the_author_url()
236 */
237function the_author_url() {
238 echo get_the_author_url();
239}
240
241/**
242 * Display either author's link or author's name.
243 *
244 * If the author has a home page set, echo an HTML link, otherwise just echo the
245 * author's name.
246 *
247 * @link http://codex.wordpress.org/Template_Tags/the_author_link
248 * @since 2.1
249 * @uses get_the_author_url()
250 * @uses the_author()
251 */
252function the_author_link() {
253 if (get_the_author_url()) {
254 echo '<a href="' . get_the_author_url() . '" title="' . sprintf(__("Visit %s's website"), get_the_author()) . '" rel="external">' . get_the_author() . '</a>';
255 } else {
256 the_author();
257 }
258}
259
260/**
261 * Retrieve the ICQ number of the author of the current post.
262 *
263 * @since 1.5
264 * @uses $authordata The current author's DB object.
265 * @return string The author's ICQ number.
266 */
267function get_the_author_icq() {
268 global $authordata;
269 return $authordata->icq;
270}
271
272/**
273 * Display the ICQ number of the author of the current post.
274 *
275 * @link http://codex.wordpress.org/Template_Tags/the_author_icq
276 * @since 0.71
277 * @see get_the_author_icq()
278 */
279function the_author_icq() {
280 echo get_the_author_icq();
281}
282
283/**
284 * Retrieve the AIM name of the author of the current post.
285 *
286 * @since 1.5
287 * @uses $authordata The current author's DB object.
288 * @return string The author's AIM name.
289 */
290function get_the_author_aim() {
291 global $authordata;
292 return str_replace(' ', '+', $authordata->aim);
293}
294
295/**
296 * Display the AIM name of the author of the current post.
297 *
298 * @link http://codex.wordpress.org/Template_Tags/the_author_aim
299 * @since 0.71
300 * @see get_the_author_aim()
301 */
302function the_author_aim() {
303 echo get_the_author_aim();
304}
305
306/**
307 * Retrieve the Yahoo! IM name of the author of the current post.
308 *
309 * @since 1.5
310 * @uses $authordata The current author's DB object.
311 * @return string The author's Yahoo! IM name.
312 */
313function get_the_author_yim() {
314 global $authordata;
315 return $authordata->yim;
316}
317
318/**
319 * Display the Yahoo! IM name of the author of the current post.
320 *
321 * @link http://codex.wordpress.org/Template_Tags/the_author_yim
322 * @since 0.71
323 * @see get_the_author_yim()
324 */
325function the_author_yim() {
326 echo get_the_author_yim();
327}
328
329/**
330 * Retrieve the MSN address of the author of the current post.
331 *
332 * @since 1.5
333 * @uses $authordata The current author's DB object.
334 * @return string The author's MSN address.
335 */
336function get_the_author_msn() {
337 global $authordata;
338 return $authordata->msn;
339}
340
341/**
342 * Display the MSN address of the author of the current post.
343 *
344 * @link http://codex.wordpress.org/Template_Tags/the_author_msn
345 * @since 0.71
346 * @see get_the_author_msn()
347 */
348function the_author_msn() {
349 echo get_the_author_msn();
350}
351
352/**
353 * Retrieve the number of posts by the author of the current post.
354 *
355 * @since 1.5
356 * @uses $post The current post in the Loop's DB object.
357 * @uses get_usernumposts()
358 * @return int The number of posts by the author.
359 */
360function get_the_author_posts() {
361 global $post;
362 return get_usernumposts($post->post_author);
363}
364
365/**
366 * Display the number of posts by the author of the current post.
367 *
368 * @link http://codex.wordpress.org/Template_Tags/the_author_posts
369 * @since 0.71
370 * @uses get_the_author_posts() Echos returned value from function.
371 */
372function the_author_posts() {
373 echo get_the_author_posts();
374}
375
376/**
377 * Display an HTML link to the author page of the author of the current post.
378 *
379 * Does just echo get_author_posts_url() function, like the others do. The
380 * reason for this, is that another function is used to help in printing the
381 * link to the author's posts.
382 *
383 * @link http://codex.wordpress.org/Template_Tags/the_author_posts_link
384 * @since 1.2.0
385 * @uses $authordata The current author's DB object.
386 * @uses get_author_posts_url()
387 * @uses get_the_author()
388 * @param string $deprecated Deprecated.
389 */
390function the_author_posts_link($deprecated = '') {
391 global $authordata;
392 printf(
393 '<a href="%1$s" title="%2$s">%3$s</a>',
394 get_author_posts_url( $authordata->ID, $authordata->user_nicename ),
395 sprintf( __( 'Posts by %s' ), attribute_escape( get_the_author() ) ),
396 get_the_author()
397 );
398}
399
400/**
401 * Retrieve the URL to the author page of the author of the current post.
402 *
403 * @since 2.1.0
404 * @uses $wp_rewrite WP_Rewrite
405 * @return string The URL to the author's page.
406 */
407function get_author_posts_url($author_id, $author_nicename = '') {
408 global $wp_rewrite;
409 $auth_ID = (int) $author_id;
410 $link = $wp_rewrite->get_author_permastruct();
411
412 if ( empty($link) ) {
413 $file = get_option('home') . '/';
414 $link = $file . '?author=' . $auth_ID;
415 } else {
416 if ( '' == $author_nicename ) {
417 $user = get_userdata($author_id);
418 if ( !empty($user->user_nicename) )
419 $author_nicename = $user->user_nicename;
420 }
421 $link = str_replace('%author%', $author_nicename, $link);
422 $link = get_option('home') . trailingslashit($link);
423 }
424
425 $link = apply_filters('author_link', $link, $author_id, $author_nicename);
426
427 return $link;
428}
429
430/**
431 * Retrieve the specified author's preferred display name.
432 *
433 * @since 1.0.0
434 * @param int $auth_id The ID of the author.
435 * @return string The author's display name.
436 */
437function get_author_name( $auth_id ) {
438 $authordata = get_userdata( $auth_id );
439 return $authordata->display_name;
440}
441
442/**
443 * List all the authors of the blog, with several options available.
444 *
445 * optioncount (boolean) (false): Show the count in parenthesis next to the
446 * author's name.
447 * exclude_admin (boolean) (true): Exclude the 'admin' user that is installed by
448 * default.
449 * show_fullname (boolean) (false): Show their full names.
450 * hide_empty (boolean) (true): Don't show authors without any posts.
451 * feed (string) (''): If isn't empty, show links to author's feeds.
452 * feed_image (string) (''): If isn't empty, use this image to link to feeds.
453 * echo (boolean) (true): Set to false to return the output, instead of echoing.
454 *
455 * @link http://codex.wordpress.org/Template_Tags/wp_list_authors
456 * @since 1.2.0
457 * @param array $args The argument array.
458 * @return null|string The output, if echo is set to false.
459 */
460function wp_list_authors($args = '') {
461 global $wpdb;
462
463 $defaults = array(
464 'optioncount' => false, 'exclude_admin' => true,
465 'show_fullname' => false, 'hide_empty' => true,
466 'feed' => '', 'feed_image' => '', 'feed_type' => '', 'echo' => true
467 );
468
469 $r = wp_parse_args( $args, $defaults );
470 extract($r, EXTR_SKIP);
471
472 $return = '';
473
474 /** @todo Move select to get_authors(). */
475 $authors = $wpdb->get_results("SELECT ID, user_nicename from $wpdb->users " . ($exclude_admin ? "WHERE user_login <> 'admin' " : '') . "ORDER BY display_name");
476
477 $author_count = array();
478 foreach ((array) $wpdb->get_results("SELECT DISTINCT post_author, COUNT(ID) AS count FROM $wpdb->posts WHERE post_type = 'post' AND " . get_private_posts_cap_sql( 'post' ) . " GROUP BY post_author") as $row) {
479 $author_count[$row->post_author] = $row->count;
480 }
481
482 foreach ( (array) $authors as $author ) {
483 $author = get_userdata( $author->ID );
484 $posts = (isset($author_count[$author->ID])) ? $author_count[$author->ID] : 0;
485 $name = $author->display_name;
486
487 if ( $show_fullname && ($author->first_name != '' && $author->last_name != '') )
488 $name = "$author->first_name $author->last_name";
489
490 if ( !($posts == 0 && $hide_empty) )
491 $return .= '<li>';
492 if ( $posts == 0 ) {
493 if ( !$hide_empty )
494 $link = $name;
495 } else {
496 $link = '<a href="' . get_author_posts_url($author->ID, $author->user_nicename) . '" title="' . sprintf(__("Posts by %s"), attribute_escape($author->display_name)) . '">' . $name . '</a>';
497
498 if ( (! empty($feed_image)) || (! empty($feed)) ) {
499 $link .= ' ';
500 if (empty($feed_image))
501 $link .= '(';
502 $link .= '<a href="' . get_author_feed_link($author->ID) . '"';
503
504 if ( !empty($feed) ) {
505 $title = ' title="' . $feed . '"';
506 $alt = ' alt="' . $feed . '"';
507 $name = $feed;
508 $link .= $title;
509 }
510
511 $link .= '>';
512
513 if ( !empty($feed_image) )
514 $link .= "<img src=\"$feed_image\" style=\"border: none;\"$alt$title" . ' />';
515 else
516 $link .= $name;
517
518 $link .= '</a>';
519
520 if ( empty($feed_image) )
521 $link .= ')';
522 }
523
524 if ( $optioncount )
525 $link .= ' ('. $posts . ')';
526
527 }
528
529 if ( !($posts == 0 && $hide_empty) )
530 $return .= $link . '</li>';
531 }
532 if ( !$echo )
533 return $return;
534 echo $return;
535}
536
537?>