WordPress 3.0 beta 1 documentation kindly provided to you by Hay Kranen
| [ Index ] |
PHP Cross Reference of WordPress 3.0 beta 1 |
|
| [ Index ] [ Variables ] [ Functions ] [ Classes ] [ Constants ] [ Statistics ] | ||
[Summary view] [Print] [Text view]
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 */ 23 function get_the_author($deprecated = '') { 24 global $authordata; 25 26 if ( !empty( $deprecated ) ) 27 _deprecated_argument( __FUNCTION__, '2.1' ); 28 29 return apply_filters('the_author', is_object($authordata) ? $authordata->display_name : null); 30 } 31 32 /** 33 * Display the name of the author of the current post. 34 * 35 * The behavior of this function is based off of old functionality predating 36 * get_the_author(). This function is not deprecated, but is designed to echo 37 * the value from get_the_author() and as an result of any old theme that might 38 * still use the old behavior will also pass the value from get_the_author(). 39 * 40 * The normal, expected behavior of this function is to echo the author and not 41 * return it. However, backwards compatiability has to be maintained. 42 * 43 * @since 0.71 44 * @see get_the_author() 45 * @link http://codex.wordpress.org/Template_Tags/the_author 46 * 47 * @param string $deprecated Deprecated. 48 * @param string $deprecated_echo Deprecated. Use get_the_author(). Echo the string or return it. 49 * @return string The author's display name, from get_the_author(). 50 */ 51 function the_author( $deprecated = '', $deprecated_echo = true ) { 52 if ( !empty( $deprecated ) ) 53 _deprecated_argument( __FUNCTION__, '2.1' ); 54 if ( $deprecated_echo !== true ) 55 _deprecated_argument( __FUNCTION__, '1.5', __('Use get_the_author() instead if you do not want the value echoed.') ); 56 if ( $deprecated_echo ) 57 echo get_the_author(); 58 return get_the_author(); 59 } 60 61 /** 62 * Retrieve the author who last edited the current post. 63 * 64 * @since 2.8 65 * @uses $post The current post's DB object. 66 * @uses get_post_meta() Retrieves the ID of the author who last edited the current post. 67 * @uses get_userdata() Retrieves the author's DB object. 68 * @uses apply_filters() Calls 'the_modified_author' hook on the author display name. 69 * @return string The author's display name. 70 */ 71 function get_the_modified_author() { 72 global $post; 73 if ( $last_id = get_post_meta($post->ID, '_edit_last', true) ) { 74 $last_user = get_userdata($last_id); 75 return apply_filters('the_modified_author', $last_user->display_name); 76 } 77 } 78 79 /** 80 * Display the name of the author who last edited the current post. 81 * 82 * @since 2.8 83 * @see get_the_author() 84 * @return string The author's display name, from get_the_modified_author(). 85 */ 86 function the_modified_author() { 87 echo get_the_modified_author(); 88 } 89 90 /** 91 * Retrieve the requested data of the author of the current post. 92 * @link http://codex.wordpress.org/Template_Tags/the_author_meta 93 * @since 2.8.0 94 * @uses $authordata The current author's DB object (if $user_id not specified). 95 * @param string $field selects the field of the users record. 96 * @param int $user_id Optional. User ID. 97 * @return string The author's field from the current author's DB object. 98 */ 99 function get_the_author_meta($field = '', $user_id = false) { 100 if ( ! $user_id ) 101 global $authordata; 102 else 103 $authordata = get_userdata( $user_id ); 104 105 $field = strtolower($field); 106 $user_field = "user_$field"; 107 108 if ( 'id' == $field ) 109 $value = isset($authordata->ID) ? (int)$authordata->ID : 0; 110 elseif ( isset($authordata->$user_field) ) 111 $value = $authordata->$user_field; 112 else 113 $value = isset($authordata->$field) ? $authordata->$field : ''; 114 115 return apply_filters('get_the_author_' . $field, $value, $user_id); 116 } 117 118 /** 119 * Retrieve the requested data of the author of the current post. 120 * @link http://codex.wordpress.org/Template_Tags/the_author_meta 121 * @since 2.8.0 122 * @param string $field selects the field of the users record. 123 * @param int $user_id Optional. User ID. 124 * @echo string The author's field from the current author's DB object. 125 */ 126 function the_author_meta($field = '', $user_id = false) { 127 echo apply_filters('the_author_' . $field, get_the_author_meta($field, $user_id), $user_id); 128 } 129 130 /** 131 * Display either author's link or author's name. 132 * 133 * If the author has a home page set, echo an HTML link, otherwise just echo the 134 * author's name. 135 * 136 * @link http://codex.wordpress.org/Template_Tags/the_author_link 137 * @since 2.1 138 * @uses get_the_author_meta() 139 * @uses the_author() 140 */ 141 function the_author_link() { 142 if ( get_the_author_meta('url') ) { 143 echo '<a href="' . get_the_author_meta('url') . '" title="' . esc_attr( sprintf(__("Visit %s’s website"), get_the_author()) ) . '" rel="external">' . get_the_author() . '</a>'; 144 } else { 145 the_author(); 146 } 147 } 148 149 /** 150 * Retrieve the number of posts by the author of the current post. 151 * 152 * @since 1.5 153 * @uses $post The current post in the Loop's DB object. 154 * @uses count_user_posts() 155 * @return int The number of posts by the author. 156 */ 157 function get_the_author_posts() { 158 global $post; 159 return count_user_posts($post->post_author); 160 } 161 162 /** 163 * Display the number of posts by the author of the current post. 164 * 165 * @link http://codex.wordpress.org/Template_Tags/the_author_posts 166 * @since 0.71 167 * @uses get_the_author_posts() Echos returned value from function. 168 */ 169 function the_author_posts() { 170 echo get_the_author_posts(); 171 } 172 173 /** 174 * Display an HTML link to the author page of the author of the current post. 175 * 176 * Does just echo get_author_posts_url() function, like the others do. The 177 * reason for this, is that another function is used to help in printing the 178 * link to the author's posts. 179 * 180 * @link http://codex.wordpress.org/Template_Tags/the_author_posts_link 181 * @since 1.2.0 182 * @uses $authordata The current author's DB object. 183 * @uses get_author_posts_url() 184 * @uses get_the_author() 185 * @param string $deprecated Deprecated. 186 */ 187 function the_author_posts_link($deprecated = '') { 188 if ( !empty( $deprecated ) ) 189 _deprecated_argument( __FUNCTION__, '2.1' ); 190 191 global $authordata; 192 $link = sprintf( 193 '<a href="%1$s" title="%2$s">%3$s</a>', 194 get_author_posts_url( $authordata->ID, $authordata->user_nicename ), 195 esc_attr( sprintf( __( 'Posts by %s' ), get_the_author() ) ), 196 get_the_author() 197 ); 198 echo apply_filters( 'the_author_posts_link', $link ); 199 } 200 201 /** 202 * Retrieve the URL to the author page of the author of the current post. 203 * 204 * @since 2.1.0 205 * @uses $wp_rewrite WP_Rewrite 206 * @return string The URL to the author's page. 207 */ 208 function get_author_posts_url($author_id, $author_nicename = '') { 209 global $wp_rewrite; 210 $auth_ID = (int) $author_id; 211 $link = $wp_rewrite->get_author_permastruct(); 212 213 if ( empty($link) ) { 214 $file = home_url() . '/'; 215 $link = $file . '?author=' . $auth_ID; 216 } else { 217 if ( '' == $author_nicename ) { 218 $user = get_userdata($author_id); 219 if ( !empty($user->user_nicename) ) 220 $author_nicename = $user->user_nicename; 221 } 222 $link = str_replace('%author%', $author_nicename, $link); 223 $link = home_url() . trailingslashit($link); 224 } 225 226 $link = apply_filters('author_link', $link, $author_id, $author_nicename); 227 228 return $link; 229 } 230 231 /** 232 * List all the authors of the blog, with several options available. 233 * 234 * <ul> 235 * <li>optioncount (boolean) (false): Show the count in parenthesis next to the 236 * author's name.</li> 237 * <li>exclude_admin (boolean) (true): Exclude the 'admin' user that is 238 * installed bydefault.</li> 239 * <li>show_fullname (boolean) (false): Show their full names.</li> 240 * <li>hide_empty (boolean) (true): Don't show authors without any posts.</li> 241 * <li>feed (string) (''): If isn't empty, show links to author's feeds.</li> 242 * <li>feed_image (string) (''): If isn't empty, use this image to link to 243 * feeds.</li> 244 * <li>echo (boolean) (true): Set to false to return the output, instead of 245 * echoing.</li> 246 * <li>style (string) ('list'): Whether to display list of authors in list form 247 * or as a string.</li> 248 * <li>html (bool) (true): Whether to list the items in html for or plaintext. 249 * </li> 250 * </ul> 251 * 252 * @link http://codex.wordpress.org/Template_Tags/wp_list_authors 253 * @since 1.2.0 254 * @param array $args The argument array. 255 * @return null|string The output, if echo is set to false. 256 */ 257 function wp_list_authors($args = '') { 258 global $wpdb; 259 260 $defaults = array( 261 'optioncount' => false, 'exclude_admin' => true, 262 'show_fullname' => false, 'hide_empty' => true, 263 'feed' => '', 'feed_image' => '', 'feed_type' => '', 'echo' => true, 264 'style' => 'list', 'html' => true 265 ); 266 267 $r = wp_parse_args( $args, $defaults ); 268 extract($r, EXTR_SKIP); 269 $return = ''; 270 271 /** @todo Move select to get_authors(). */ 272 $users = get_users_of_blog(); 273 $author_ids = array(); 274 foreach ( (array) $users as $user ) 275 $author_ids[] = $user->user_id; 276 if ( count($author_ids) > 0 ) { 277 $author_ids = implode(',', $author_ids ); 278 $authors = $wpdb->get_results( "SELECT ID, user_nicename from $wpdb->users WHERE ID IN($author_ids) " . ($exclude_admin ? "AND user_login <> 'admin' " : '') . "ORDER BY display_name" ); 279 } else { 280 $authors = array(); 281 } 282 283 $author_count = array(); 284 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 ) 285 $author_count[$row->post_author] = $row->count; 286 287 foreach ( (array) $authors as $author ) { 288 289 $link = ''; 290 291 $author = get_userdata( $author->ID ); 292 $posts = (isset($author_count[$author->ID])) ? $author_count[$author->ID] : 0; 293 $name = $author->display_name; 294 295 if ( $show_fullname && ($author->first_name != '' && $author->last_name != '') ) 296 $name = "$author->first_name $author->last_name"; 297 298 if( !$html ) { 299 if ( $posts == 0 ) { 300 if ( ! $hide_empty ) 301 $return .= $name . ', '; 302 } else 303 $return .= $name . ', '; 304 305 // No need to go further to process HTML. 306 continue; 307 } 308 309 if ( !($posts == 0 && $hide_empty) && 'list' == $style ) 310 $return .= '<li>'; 311 if ( $posts == 0 ) { 312 if ( ! $hide_empty ) 313 $link = $name; 314 } else { 315 $link = '<a href="' . get_author_posts_url($author->ID, $author->user_nicename) . '" title="' . esc_attr( sprintf(__("Posts by %s"), $author->display_name) ) . '">' . $name . '</a>'; 316 317 if ( (! empty($feed_image)) || (! empty($feed)) ) { 318 $link .= ' '; 319 if (empty($feed_image)) 320 $link .= '('; 321 $link .= '<a href="' . get_author_feed_link($author->ID) . '"'; 322 323 if ( !empty($feed) ) { 324 $title = ' title="' . esc_attr($feed) . '"'; 325 $alt = ' alt="' . esc_attr($feed) . '"'; 326 $name = $feed; 327 $link .= $title; 328 } 329 330 $link .= '>'; 331 332 if ( !empty($feed_image) ) 333 $link .= "<img src=\"" . esc_url($feed_image) . "\" style=\"border: none;\"$alt$title" . ' />'; 334 else 335 $link .= $name; 336 337 $link .= '</a>'; 338 339 if ( empty($feed_image) ) 340 $link .= ')'; 341 } 342 343 if ( $optioncount ) 344 $link .= ' ('. $posts . ')'; 345 346 } 347 348 if ( !($posts == 0 && $hide_empty) && 'list' == $style ) 349 $return .= $link . '</li>'; 350 else if ( ! $hide_empty ) 351 $return .= $link . ', '; 352 } 353 354 $return = trim($return, ', '); 355 356 if ( ! $echo ) 357 return $return; 358 echo $return; 359 } 360 361 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Mon Apr 5 14:26:09 2010 | Cross-referenced by PHPXref 0.7 |