author | Anthony Ly <anthonyly.com@gmail.com> |
Wed, 19 Dec 2012 17:50:20 -0800 | |
changeset 205 | a4f7897e21a9 |
parent 204 | 09a1c134465b |
permissions | -rw-r--r-- |
136 | 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; |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
25 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
26 |
if ( !empty( $deprecated ) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
27 |
_deprecated_argument( __FUNCTION__, '2.1' ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
28 |
|
136 | 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 |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
41 |
* return it. However, backwards compatibility has to be maintained. |
136 | 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. |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
48 |
* @param string $deprecated_echo Deprecated. Use get_the_author(). Echo the string or return it. |
136 | 49 |
* @return string The author's display name, from get_the_author(). |
50 |
*/ |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
51 |
function the_author( $deprecated = '', $deprecated_echo = true ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
52 |
if ( !empty( $deprecated ) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
53 |
_deprecated_argument( __FUNCTION__, '2.1' ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
54 |
if ( $deprecated_echo !== true ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
55 |
_deprecated_argument( __FUNCTION__, '1.5', __('Use <code>get_the_author()</code> instead if you do not want the value echoed.') ); |
136 | 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() { |
|
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
72 |
if ( $last_id = get_post_meta( get_post()->ID, '_edit_last', true) ) { |
136 | 73 |
$last_user = get_userdata($last_id); |
74 |
return apply_filters('the_modified_author', $last_user->display_name); |
|
75 |
} |
|
76 |
} |
|
77 |
||
78 |
/** |
|
79 |
* Display the name of the author who last edited the current post. |
|
80 |
* |
|
81 |
* @since 2.8 |
|
82 |
* @see get_the_author() |
|
83 |
* @return string The author's display name, from get_the_modified_author(). |
|
84 |
*/ |
|
85 |
function the_modified_author() { |
|
86 |
echo get_the_modified_author(); |
|
87 |
} |
|
88 |
||
89 |
/** |
|
90 |
* Retrieve the requested data of the author of the current post. |
|
91 |
* @link http://codex.wordpress.org/Template_Tags/the_author_meta |
|
92 |
* @since 2.8.0 |
|
93 |
* @uses $authordata The current author's DB object (if $user_id not specified). |
|
94 |
* @param string $field selects the field of the users record. |
|
95 |
* @param int $user_id Optional. User ID. |
|
96 |
* @return string The author's field from the current author's DB object. |
|
97 |
*/ |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
98 |
function get_the_author_meta( $field = '', $user_id = false ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
99 |
if ( ! $user_id ) { |
136 | 100 |
global $authordata; |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
101 |
$user_id = isset( $authordata->ID ) ? $authordata->ID : 0; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
102 |
} else { |
136 | 103 |
$authordata = get_userdata( $user_id ); |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
104 |
} |
136 | 105 |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
106 |
if ( in_array( $field, array( 'login', 'pass', 'nicename', 'email', 'url', 'registered', 'activation_key', 'status' ) ) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
107 |
$field = 'user_' . $field; |
136 | 108 |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
109 |
$value = isset( $authordata->$field ) ? $authordata->$field : ''; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
110 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
111 |
return apply_filters( 'get_the_author_' . $field, $value, $user_id ); |
136 | 112 |
} |
113 |
||
114 |
/** |
|
115 |
* Retrieve the requested data of the author of the current post. |
|
116 |
* @link http://codex.wordpress.org/Template_Tags/the_author_meta |
|
117 |
* @since 2.8.0 |
|
118 |
* @param string $field selects the field of the users record. |
|
119 |
* @param int $user_id Optional. User ID. |
|
120 |
* @echo string The author's field from the current author's DB object. |
|
121 |
*/ |
|
122 |
function the_author_meta($field = '', $user_id = false) { |
|
123 |
echo apply_filters('the_author_' . $field, get_the_author_meta($field, $user_id), $user_id); |
|
124 |
} |
|
125 |
||
126 |
/** |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
127 |
* Retrieve either author's link or author's name. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
128 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
129 |
* If the author has a home page set, return an HTML link, otherwise just return the |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
130 |
* author's name. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
131 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
132 |
* @uses get_the_author_meta() |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
133 |
* @uses get_the_author() |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
134 |
*/ |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
135 |
function get_the_author_link() { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
136 |
if ( get_the_author_meta('url') ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
137 |
return '<a href="' . get_the_author_meta('url') . '" title="' . esc_attr( sprintf(__("Visit %s’s website"), get_the_author()) ) . '" rel="author external">' . get_the_author() . '</a>'; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
138 |
} else { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
139 |
return get_the_author(); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
140 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
141 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
142 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
143 |
/** |
136 | 144 |
* Display either author's link or author's name. |
145 |
* |
|
146 |
* If the author has a home page set, echo an HTML link, otherwise just echo the |
|
147 |
* author's name. |
|
148 |
* |
|
149 |
* @link http://codex.wordpress.org/Template_Tags/the_author_link |
|
150 |
* @since 2.1 |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
151 |
* @uses get_the_author_link() |
136 | 152 |
*/ |
153 |
function the_author_link() { |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
154 |
echo get_the_author_link(); |
136 | 155 |
} |
156 |
||
157 |
/** |
|
158 |
* Retrieve the number of posts by the author of the current post. |
|
159 |
* |
|
160 |
* @since 1.5 |
|
161 |
* @uses $post The current post in the Loop's DB object. |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
162 |
* @uses count_user_posts() |
136 | 163 |
* @return int The number of posts by the author. |
164 |
*/ |
|
165 |
function get_the_author_posts() { |
|
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
166 |
return count_user_posts( get_post()->post_author ); |
136 | 167 |
} |
168 |
||
169 |
/** |
|
170 |
* Display the number of posts by the author of the current post. |
|
171 |
* |
|
172 |
* @link http://codex.wordpress.org/Template_Tags/the_author_posts |
|
173 |
* @since 0.71 |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
174 |
* @uses get_the_author_posts() Echoes returned value from function. |
136 | 175 |
*/ |
176 |
function the_author_posts() { |
|
177 |
echo get_the_author_posts(); |
|
178 |
} |
|
179 |
||
180 |
/** |
|
181 |
* Display an HTML link to the author page of the author of the current post. |
|
182 |
* |
|
183 |
* Does just echo get_author_posts_url() function, like the others do. The |
|
184 |
* reason for this, is that another function is used to help in printing the |
|
185 |
* link to the author's posts. |
|
186 |
* |
|
187 |
* @link http://codex.wordpress.org/Template_Tags/the_author_posts_link |
|
188 |
* @since 1.2.0 |
|
189 |
* @uses $authordata The current author's DB object. |
|
190 |
* @uses get_author_posts_url() |
|
191 |
* @uses get_the_author() |
|
192 |
* @param string $deprecated Deprecated. |
|
193 |
*/ |
|
194 |
function the_author_posts_link($deprecated = '') { |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
195 |
if ( !empty( $deprecated ) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
196 |
_deprecated_argument( __FUNCTION__, '2.1' ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
197 |
|
136 | 198 |
global $authordata; |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
199 |
if ( !is_object( $authordata ) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
200 |
return false; |
136 | 201 |
$link = sprintf( |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
202 |
'<a href="%1$s" title="%2$s" rel="author">%3$s</a>', |
136 | 203 |
get_author_posts_url( $authordata->ID, $authordata->user_nicename ), |
204 |
esc_attr( sprintf( __( 'Posts by %s' ), get_the_author() ) ), |
|
205 |
get_the_author() |
|
206 |
); |
|
207 |
echo apply_filters( 'the_author_posts_link', $link ); |
|
208 |
} |
|
209 |
||
210 |
/** |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
211 |
* Retrieve the URL to the author page for the user with the ID provided. |
136 | 212 |
* |
213 |
* @since 2.1.0 |
|
214 |
* @uses $wp_rewrite WP_Rewrite |
|
215 |
* @return string The URL to the author's page. |
|
216 |
*/ |
|
217 |
function get_author_posts_url($author_id, $author_nicename = '') { |
|
218 |
global $wp_rewrite; |
|
219 |
$auth_ID = (int) $author_id; |
|
220 |
$link = $wp_rewrite->get_author_permastruct(); |
|
221 |
||
222 |
if ( empty($link) ) { |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
223 |
$file = home_url( '/' ); |
136 | 224 |
$link = $file . '?author=' . $auth_ID; |
225 |
} else { |
|
226 |
if ( '' == $author_nicename ) { |
|
227 |
$user = get_userdata($author_id); |
|
228 |
if ( !empty($user->user_nicename) ) |
|
229 |
$author_nicename = $user->user_nicename; |
|
230 |
} |
|
231 |
$link = str_replace('%author%', $author_nicename, $link); |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
232 |
$link = home_url( user_trailingslashit( $link ) ); |
136 | 233 |
} |
234 |
||
235 |
$link = apply_filters('author_link', $link, $author_id, $author_nicename); |
|
236 |
||
237 |
return $link; |
|
238 |
} |
|
239 |
||
240 |
/** |
|
241 |
* List all the authors of the blog, with several options available. |
|
242 |
* |
|
243 |
* <ul> |
|
244 |
* <li>optioncount (boolean) (false): Show the count in parenthesis next to the |
|
245 |
* author's name.</li> |
|
246 |
* <li>exclude_admin (boolean) (true): Exclude the 'admin' user that is |
|
247 |
* installed bydefault.</li> |
|
248 |
* <li>show_fullname (boolean) (false): Show their full names.</li> |
|
249 |
* <li>hide_empty (boolean) (true): Don't show authors without any posts.</li> |
|
250 |
* <li>feed (string) (''): If isn't empty, show links to author's feeds.</li> |
|
251 |
* <li>feed_image (string) (''): If isn't empty, use this image to link to |
|
252 |
* feeds.</li> |
|
253 |
* <li>echo (boolean) (true): Set to false to return the output, instead of |
|
254 |
* echoing.</li> |
|
255 |
* <li>style (string) ('list'): Whether to display list of authors in list form |
|
256 |
* or as a string.</li> |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
257 |
* <li>html (bool) (true): Whether to list the items in html form or plaintext. |
136 | 258 |
* </li> |
259 |
* </ul> |
|
260 |
* |
|
261 |
* @link http://codex.wordpress.org/Template_Tags/wp_list_authors |
|
262 |
* @since 1.2.0 |
|
263 |
* @param array $args The argument array. |
|
264 |
* @return null|string The output, if echo is set to false. |
|
265 |
*/ |
|
266 |
function wp_list_authors($args = '') { |
|
267 |
global $wpdb; |
|
268 |
||
269 |
$defaults = array( |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
270 |
'orderby' => 'name', 'order' => 'ASC', 'number' => '', |
136 | 271 |
'optioncount' => false, 'exclude_admin' => true, |
272 |
'show_fullname' => false, 'hide_empty' => true, |
|
273 |
'feed' => '', 'feed_image' => '', 'feed_type' => '', 'echo' => true, |
|
274 |
'style' => 'list', 'html' => true |
|
275 |
); |
|
276 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
277 |
$args = wp_parse_args( $args, $defaults ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
278 |
extract( $args, EXTR_SKIP ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
279 |
|
136 | 280 |
$return = ''; |
281 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
282 |
$query_args = wp_array_slice_assoc( $args, array( 'orderby', 'order', 'number' ) ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
283 |
$query_args['fields'] = 'ids'; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
284 |
$authors = get_users( $query_args ); |
136 | 285 |
|
286 |
$author_count = array(); |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
287 |
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 ) |
136 | 288 |
$author_count[$row->post_author] = $row->count; |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
289 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
290 |
foreach ( $authors as $author_id ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
291 |
$author = get_userdata( $author_id ); |
136 | 292 |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
293 |
if ( $exclude_admin && 'admin' == $author->display_name ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
294 |
continue; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
295 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
296 |
$posts = isset( $author_count[$author->ID] ) ? $author_count[$author->ID] : 0; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
297 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
298 |
if ( !$posts && $hide_empty ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
299 |
continue; |
136 | 300 |
|
301 |
$link = ''; |
|
302 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
303 |
if ( $show_fullname && $author->first_name && $author->last_name ) |
136 | 304 |
$name = "$author->first_name $author->last_name"; |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
305 |
else |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
306 |
$name = $author->display_name; |
136 | 307 |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
308 |
if ( !$html ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
309 |
$return .= $name . ', '; |
136 | 310 |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
311 |
continue; // No need to go further to process HTML. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
312 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
313 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
314 |
if ( 'list' == $style ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
315 |
$return .= '<li>'; |
136 | 316 |
} |
317 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
318 |
$link = '<a href="' . get_author_posts_url( $author->ID, $author->user_nicename ) . '" title="' . esc_attr( sprintf(__("Posts by %s"), $author->display_name) ) . '">' . $name . '</a>'; |
136 | 319 |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
320 |
if ( !empty( $feed_image ) || !empty( $feed ) ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
321 |
$link .= ' '; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
322 |
if ( empty( $feed_image ) ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
323 |
$link .= '('; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
324 |
} |
136 | 325 |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
326 |
$link .= '<a href="' . get_author_feed_link( $author->ID ) . '"'; |
136 | 327 |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
328 |
$alt = $title = ''; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
329 |
if ( !empty( $feed ) ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
330 |
$title = ' title="' . esc_attr( $feed ) . '"'; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
331 |
$alt = ' alt="' . esc_attr( $feed ) . '"'; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
332 |
$name = $feed; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
333 |
$link .= $title; |
136 | 334 |
} |
335 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
336 |
$link .= '>'; |
136 | 337 |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
338 |
if ( !empty( $feed_image ) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
339 |
$link .= '<img src="' . esc_url( $feed_image ) . '" style="border: none;"' . $alt . $title . ' />'; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
340 |
else |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
341 |
$link .= $name; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
342 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
343 |
$link .= '</a>'; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
344 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
345 |
if ( empty( $feed_image ) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
346 |
$link .= ')'; |
136 | 347 |
} |
348 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
349 |
if ( $optioncount ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
350 |
$link .= ' ('. $posts . ')'; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
351 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
352 |
$return .= $link; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
353 |
$return .= ( 'list' == $style ) ? '</li>' : ', '; |
136 | 354 |
} |
355 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
356 |
$return = rtrim($return, ', '); |
136 | 357 |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
358 |
if ( !$echo ) |
136 | 359 |
return $return; |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
360 |
|
136 | 361 |
echo $return; |
362 |
} |
|
363 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
364 |
/** |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
365 |
* Does this site have more than one author |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
366 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
367 |
* Checks to see if more than one author has published posts. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
368 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
369 |
* @since 3.2.0 |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
370 |
* @return bool Whether or not we have more than one author |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
371 |
*/ |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
372 |
function is_multi_author() { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
373 |
global $wpdb; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
374 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
375 |
if ( false === ( $is_multi_author = wp_cache_get('is_multi_author', 'posts') ) ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
376 |
$rows = (array) $wpdb->get_col("SELECT DISTINCT post_author FROM $wpdb->posts WHERE post_type = 'post' AND post_status = 'publish' LIMIT 2"); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
377 |
$is_multi_author = 1 < count( $rows ) ? 1 : 0; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
378 |
wp_cache_set('is_multi_author', $is_multi_author, 'posts'); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
379 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
380 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
381 |
return apply_filters( 'is_multi_author', (bool) $is_multi_author ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
382 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
383 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
384 |
/** |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
385 |
* Helper function to clear the cache for number of authors. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
386 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
387 |
* @private |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
388 |
*/ |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
389 |
function __clear_multi_author_cache() { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
390 |
wp_cache_delete('is_multi_author', 'posts'); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
391 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
392 |
add_action('transition_post_status', '__clear_multi_author_cache'); |