author | ymh <ymh.work@gmail.com> |
Mon, 14 Oct 2019 18:28:13 +0200 | |
changeset 9 | 177826044cd9 |
parent 7 | cf61fcea0001 |
child 16 | a86126ab1dd4 |
permissions | -rw-r--r-- |
0 | 1 |
<?php |
2 |
/** |
|
3 |
* Author Template functions for use in themes. |
|
4 |
* |
|
5 |
* These functions must be used within the WordPress Loop. |
|
6 |
* |
|
5 | 7 |
* @link https://codex.wordpress.org/Author_Templates |
0 | 8 |
* |
9 |
* @package WordPress |
|
10 |
* @subpackage Template |
|
11 |
*/ |
|
12 |
||
13 |
/** |
|
14 |
* Retrieve the author of the current post. |
|
15 |
* |
|
5 | 16 |
* @since 1.5.0 |
17 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
18 |
* @global object $authordata The current author's DB object. |
0 | 19 |
* |
20 |
* @param string $deprecated Deprecated. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
21 |
* @return string|null The author's display name. |
0 | 22 |
*/ |
9 | 23 |
function get_the_author( $deprecated = '' ) { |
0 | 24 |
global $authordata; |
25 |
||
9 | 26 |
if ( ! empty( $deprecated ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
27 |
_deprecated_argument( __FUNCTION__, '2.1.0' ); |
9 | 28 |
} |
0 | 29 |
|
30 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
31 |
* Filters the display name of the current post's author. |
0 | 32 |
* |
33 |
* @since 2.9.0 |
|
34 |
* |
|
35 |
* @param string $authordata->display_name The author's display name. |
|
36 |
*/ |
|
9 | 37 |
return apply_filters( 'the_author', is_object( $authordata ) ? $authordata->display_name : null ); |
0 | 38 |
} |
39 |
||
40 |
/** |
|
41 |
* Display the name of the author of the current post. |
|
42 |
* |
|
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 |
|
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(). |
|
47 |
* |
|
48 |
* The normal, expected behavior of this function is to echo the author and not |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
49 |
* return it. However, backward compatibility has to be maintained. |
0 | 50 |
* |
51 |
* @since 0.71 |
|
52 |
* @see get_the_author() |
|
5 | 53 |
* @link https://codex.wordpress.org/Template_Tags/the_author |
0 | 54 |
* |
9 | 55 |
* @param string $deprecated Deprecated. |
56 |
* @param bool $deprecated_echo Deprecated. Use get_the_author(). Echo the string or return it. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
57 |
* @return string|null The author's display name, from get_the_author(). |
0 | 58 |
*/ |
59 |
function the_author( $deprecated = '', $deprecated_echo = true ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
60 |
if ( ! empty( $deprecated ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
61 |
_deprecated_argument( __FUNCTION__, '2.1.0' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
62 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
63 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
64 |
if ( true !== $deprecated_echo ) { |
9 | 65 |
_deprecated_argument( |
66 |
__FUNCTION__, |
|
67 |
'1.5.0', |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
68 |
/* translators: %s: get_the_author() */ |
9 | 69 |
sprintf( |
70 |
__( 'Use %s instead if you do not want the value echoed.' ), |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
71 |
'<code>get_the_author()</code>' |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
72 |
) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
73 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
74 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
75 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
76 |
if ( $deprecated_echo ) { |
0 | 77 |
echo get_the_author(); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
78 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
79 |
|
0 | 80 |
return get_the_author(); |
81 |
} |
|
82 |
||
83 |
/** |
|
84 |
* Retrieve the author who last edited the current post. |
|
85 |
* |
|
5 | 86 |
* @since 2.8.0 |
87 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
88 |
* @return string|void The author's display name. |
0 | 89 |
*/ |
90 |
function get_the_modified_author() { |
|
9 | 91 |
$last_id = get_post_meta( get_post()->ID, '_edit_last', true ); |
92 |
||
93 |
if ( $last_id ) { |
|
94 |
$last_user = get_userdata( $last_id ); |
|
0 | 95 |
|
96 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
97 |
* Filters the display name of the author who last edited the current post. |
0 | 98 |
* |
99 |
* @since 2.8.0 |
|
100 |
* |
|
101 |
* @param string $last_user->display_name The author's display name. |
|
102 |
*/ |
|
9 | 103 |
return apply_filters( 'the_modified_author', $last_user->display_name ); |
0 | 104 |
} |
105 |
} |
|
106 |
||
107 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
108 |
* Display the name of the author who last edited the current post, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
109 |
* if the author's ID is available. |
0 | 110 |
* |
5 | 111 |
* @since 2.8.0 |
112 |
* |
|
0 | 113 |
* @see get_the_author() |
114 |
*/ |
|
115 |
function the_modified_author() { |
|
116 |
echo get_the_modified_author(); |
|
117 |
} |
|
118 |
||
119 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
120 |
* Retrieves the requested data of the author of the current post. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
121 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
122 |
* Valid values for the `$field` parameter include: |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
123 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
124 |
* - admin_color |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
125 |
* - aim |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
126 |
* - comment_shortcuts |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
127 |
* - description |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
128 |
* - display_name |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
129 |
* - first_name |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
130 |
* - ID |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
131 |
* - jabber |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
132 |
* - last_name |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
133 |
* - nickname |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
134 |
* - plugins_last_view |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
135 |
* - plugins_per_page |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
136 |
* - rich_editing |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
137 |
* - syntax_highlighting |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
138 |
* - user_activation_key |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
139 |
* - user_description |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
140 |
* - user_email |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
141 |
* - user_firstname |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
142 |
* - user_lastname |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
143 |
* - user_level |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
144 |
* - user_login |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
145 |
* - user_nicename |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
146 |
* - user_pass |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
147 |
* - user_registered |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
148 |
* - user_status |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
149 |
* - user_url |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
150 |
* - yim |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
151 |
* |
0 | 152 |
* @since 2.8.0 |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
153 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
154 |
* @global object $authordata The current author's DB object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
155 |
* |
9 | 156 |
* @param string $field Optional. The user field to retrieve. Default empty. |
157 |
* @param int|false $user_id Optional. User ID. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
158 |
* @return string The author's field from the current author's DB object, otherwise an empty string. |
0 | 159 |
*/ |
160 |
function get_the_author_meta( $field = '', $user_id = false ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
161 |
$original_user_id = $user_id; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
162 |
|
0 | 163 |
if ( ! $user_id ) { |
164 |
global $authordata; |
|
165 |
$user_id = isset( $authordata->ID ) ? $authordata->ID : 0; |
|
166 |
} else { |
|
167 |
$authordata = get_userdata( $user_id ); |
|
168 |
} |
|
169 |
||
9 | 170 |
if ( in_array( $field, array( 'login', 'pass', 'nicename', 'email', 'url', 'registered', 'activation_key', 'status' ) ) ) { |
0 | 171 |
$field = 'user_' . $field; |
9 | 172 |
} |
0 | 173 |
|
174 |
$value = isset( $authordata->$field ) ? $authordata->$field : ''; |
|
175 |
||
176 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
177 |
* Filters the value of the requested user metadata. |
0 | 178 |
* |
179 |
* The filter name is dynamic and depends on the $field parameter of the function. |
|
180 |
* |
|
181 |
* @since 2.8.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
182 |
* @since 4.3.0 The `$original_user_id` parameter was added. |
0 | 183 |
* |
9 | 184 |
* @param string $value The value of the metadata. |
185 |
* @param int $user_id The user ID for the value. |
|
186 |
* @param int|false $original_user_id The original user ID, as passed to the function. |
|
0 | 187 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
188 |
return apply_filters( "get_the_author_{$field}", $value, $user_id, $original_user_id ); |
0 | 189 |
} |
190 |
||
191 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
192 |
* Outputs the field from the user's DB object. Defaults to current post's author. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
193 |
* |
0 | 194 |
* @since 2.8.0 |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
195 |
* |
9 | 196 |
* @param string $field Selects the field of the users record. See get_the_author_meta() |
197 |
* for the list of possible fields. |
|
198 |
* @param int|false $user_id Optional. User ID. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
199 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
200 |
* @see get_the_author_meta() |
0 | 201 |
*/ |
202 |
function the_author_meta( $field = '', $user_id = false ) { |
|
203 |
$author_meta = get_the_author_meta( $field, $user_id ); |
|
204 |
||
205 |
/** |
|
206 |
* The value of the requested user metadata. |
|
207 |
* |
|
208 |
* The filter name is dynamic and depends on the $field parameter of the function. |
|
209 |
* |
|
210 |
* @since 2.8.0 |
|
211 |
* |
|
9 | 212 |
* @param string $author_meta The value of the metadata. |
213 |
* @param int|false $user_id The user ID. |
|
0 | 214 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
215 |
echo apply_filters( "the_author_{$field}", $author_meta, $user_id ); |
0 | 216 |
} |
217 |
||
218 |
/** |
|
219 |
* Retrieve either author's link or author's name. |
|
220 |
* |
|
221 |
* If the author has a home page set, return an HTML link, otherwise just return the |
|
222 |
* author's name. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
223 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
224 |
* @since 3.0.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
225 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
226 |
* @return string|null An HTML link if the author's url exist in user meta, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
227 |
* else the result of get_the_author(). |
0 | 228 |
*/ |
229 |
function get_the_author_link() { |
|
9 | 230 |
if ( get_the_author_meta( 'url' ) ) { |
231 |
return sprintf( |
|
232 |
'<a href="%1$s" title="%2$s" rel="author external">%3$s</a>', |
|
233 |
esc_url( get_the_author_meta( 'url' ) ), |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
234 |
/* translators: %s: author's display name */ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
235 |
esc_attr( sprintf( __( 'Visit %s’s website' ), get_the_author() ) ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
236 |
get_the_author() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
237 |
); |
0 | 238 |
} else { |
239 |
return get_the_author(); |
|
240 |
} |
|
241 |
} |
|
242 |
||
243 |
/** |
|
244 |
* Display either author's link or author's name. |
|
245 |
* |
|
246 |
* If the author has a home page set, echo an HTML link, otherwise just echo the |
|
247 |
* author's name. |
|
248 |
* |
|
5 | 249 |
* @link https://codex.wordpress.org/Template_Tags/the_author_link |
250 |
* |
|
251 |
* @since 2.1.0 |
|
0 | 252 |
*/ |
253 |
function the_author_link() { |
|
254 |
echo get_the_author_link(); |
|
255 |
} |
|
256 |
||
257 |
/** |
|
258 |
* Retrieve the number of posts by the author of the current post. |
|
259 |
* |
|
5 | 260 |
* @since 1.5.0 |
261 |
* |
|
0 | 262 |
* @return int The number of posts by the author. |
263 |
*/ |
|
264 |
function get_the_author_posts() { |
|
5 | 265 |
$post = get_post(); |
266 |
if ( ! $post ) { |
|
267 |
return 0; |
|
268 |
} |
|
269 |
return count_user_posts( $post->post_author, $post->post_type ); |
|
0 | 270 |
} |
271 |
||
272 |
/** |
|
273 |
* Display the number of posts by the author of the current post. |
|
274 |
* |
|
5 | 275 |
* @link https://codex.wordpress.org/Template_Tags/the_author_posts |
0 | 276 |
* @since 0.71 |
277 |
*/ |
|
278 |
function the_author_posts() { |
|
279 |
echo get_the_author_posts(); |
|
280 |
} |
|
281 |
||
282 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
283 |
* Retrieves an HTML link to the author page of the current post's author. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
284 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
285 |
* Returns an HTML-formatted link using get_author_posts_url(). |
0 | 286 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
287 |
* @since 4.4.0 |
0 | 288 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
289 |
* @global object $authordata The current author's DB object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
290 |
* |
9 | 291 |
* @return string An HTML link to the author page, or an empty string if $authordata isn't defined. |
0 | 292 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
293 |
function get_the_author_posts_link() { |
0 | 294 |
global $authordata; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
295 |
if ( ! is_object( $authordata ) ) { |
9 | 296 |
return ''; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
297 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
298 |
|
9 | 299 |
$link = sprintf( |
300 |
'<a href="%1$s" title="%2$s" rel="author">%3$s</a>', |
|
0 | 301 |
esc_url( get_author_posts_url( $authordata->ID, $authordata->user_nicename ) ), |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
302 |
/* translators: %s: author's display name */ |
0 | 303 |
esc_attr( sprintf( __( 'Posts by %s' ), get_the_author() ) ), |
304 |
get_the_author() |
|
305 |
); |
|
306 |
||
307 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
308 |
* Filters the link to the author page of the author of the current post. |
0 | 309 |
* |
310 |
* @since 2.9.0 |
|
311 |
* |
|
312 |
* @param string $link HTML link. |
|
313 |
*/ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
314 |
return apply_filters( 'the_author_posts_link', $link ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
315 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
316 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
317 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
318 |
* Displays an HTML link to the author page of the current post's author. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
319 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
320 |
* @since 1.2.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
321 |
* @since 4.4.0 Converted into a wrapper for get_the_author_posts_link() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
322 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
323 |
* @param string $deprecated Unused. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
324 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
325 |
function the_author_posts_link( $deprecated = '' ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
326 |
if ( ! empty( $deprecated ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
327 |
_deprecated_argument( __FUNCTION__, '2.1.0' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
328 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
329 |
echo get_the_author_posts_link(); |
0 | 330 |
} |
331 |
||
332 |
/** |
|
333 |
* Retrieve the URL to the author page for the user with the ID provided. |
|
334 |
* |
|
335 |
* @since 2.1.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
336 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
337 |
* @global WP_Rewrite $wp_rewrite |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
338 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
339 |
* @param int $author_id Author ID. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
340 |
* @param string $author_nicename Optional. The author's nicename (slug). Default empty. |
0 | 341 |
* @return string The URL to the author's page. |
342 |
*/ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
343 |
function get_author_posts_url( $author_id, $author_nicename = '' ) { |
0 | 344 |
global $wp_rewrite; |
345 |
$auth_ID = (int) $author_id; |
|
9 | 346 |
$link = $wp_rewrite->get_author_permastruct(); |
0 | 347 |
|
9 | 348 |
if ( empty( $link ) ) { |
0 | 349 |
$file = home_url( '/' ); |
350 |
$link = $file . '?author=' . $auth_ID; |
|
351 |
} else { |
|
352 |
if ( '' == $author_nicename ) { |
|
9 | 353 |
$user = get_userdata( $author_id ); |
354 |
if ( ! empty( $user->user_nicename ) ) { |
|
0 | 355 |
$author_nicename = $user->user_nicename; |
9 | 356 |
} |
0 | 357 |
} |
9 | 358 |
$link = str_replace( '%author%', $author_nicename, $link ); |
0 | 359 |
$link = home_url( user_trailingslashit( $link ) ); |
360 |
} |
|
361 |
||
362 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
363 |
* Filters the URL to the author's page. |
0 | 364 |
* |
365 |
* @since 2.1.0 |
|
366 |
* |
|
367 |
* @param string $link The URL to the author's page. |
|
368 |
* @param int $author_id The author's id. |
|
369 |
* @param string $author_nicename The author's nice name. |
|
370 |
*/ |
|
371 |
$link = apply_filters( 'author_link', $link, $author_id, $author_nicename ); |
|
372 |
||
373 |
return $link; |
|
374 |
} |
|
375 |
||
376 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
377 |
* List all the authors of the site, with several options available. |
0 | 378 |
* |
5 | 379 |
* @link https://codex.wordpress.org/Template_Tags/wp_list_authors |
380 |
* |
|
381 |
* @since 1.2.0 |
|
382 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
383 |
* @global wpdb $wpdb WordPress database abstraction object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
384 |
* |
5 | 385 |
* @param string|array $args { |
386 |
* Optional. Array or string of default arguments. |
|
0 | 387 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
388 |
* @type string $orderby How to sort the authors. Accepts 'nicename', 'email', 'url', 'registered', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
389 |
* 'user_nicename', 'user_email', 'user_url', 'user_registered', 'name', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
390 |
* 'display_name', 'post_count', 'ID', 'meta_value', 'user_login'. Default 'name'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
391 |
* @type string $order Sorting direction for $orderby. Accepts 'ASC', 'DESC'. Default 'ASC'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
392 |
* @type int $number Maximum authors to return or display. Default empty (all authors). |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
393 |
* @type bool $optioncount Show the count in parenthesis next to the author's name. Default false. |
9 | 394 |
* @type bool $exclude_admin Whether to exclude the 'admin' account, if it exists. Default true. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
395 |
* @type bool $show_fullname Whether to show the author's full name. Default false. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
396 |
* @type bool $hide_empty Whether to hide any authors with no posts. Default true. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
397 |
* @type string $feed If not empty, show a link to the author's feed and use this text as the alt |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
398 |
* parameter of the link. Default empty. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
399 |
* @type string $feed_image If not empty, show a link to the author's feed and use this image URL as |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
400 |
* clickable anchor. Default empty. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
401 |
* @type string $feed_type The feed type to link to, such as 'rss2'. Defaults to default feed type. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
402 |
* @type bool $echo Whether to output the result or instead return it. Default true. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
403 |
* @type string $style If 'list', each author is wrapped in an `<li>` element, otherwise the authors |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
404 |
* will be separated by commas. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
405 |
* @type bool $html Whether to list the items in HTML form or plaintext. Default true. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
406 |
* @type array|string $exclude Array or comma/space-separated list of author IDs to exclude. Default empty. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
407 |
* @type array|string $include Array or comma/space-separated list of author IDs to include. Default empty. |
5 | 408 |
* } |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
409 |
* @return string|void The output, if echo is set to false. |
0 | 410 |
*/ |
5 | 411 |
function wp_list_authors( $args = '' ) { |
0 | 412 |
global $wpdb; |
413 |
||
414 |
$defaults = array( |
|
9 | 415 |
'orderby' => 'name', |
416 |
'order' => 'ASC', |
|
417 |
'number' => '', |
|
418 |
'optioncount' => false, |
|
419 |
'exclude_admin' => true, |
|
420 |
'show_fullname' => false, |
|
421 |
'hide_empty' => true, |
|
422 |
'feed' => '', |
|
423 |
'feed_image' => '', |
|
424 |
'feed_type' => '', |
|
425 |
'echo' => true, |
|
426 |
'style' => 'list', |
|
427 |
'html' => true, |
|
428 |
'exclude' => '', |
|
429 |
'include' => '', |
|
0 | 430 |
); |
431 |
||
432 |
$args = wp_parse_args( $args, $defaults ); |
|
433 |
||
434 |
$return = ''; |
|
435 |
||
9 | 436 |
$query_args = wp_array_slice_assoc( $args, array( 'orderby', 'order', 'number', 'exclude', 'include' ) ); |
0 | 437 |
$query_args['fields'] = 'ids'; |
9 | 438 |
$authors = get_users( $query_args ); |
0 | 439 |
|
440 |
$author_count = array(); |
|
9 | 441 |
foreach ( (array) $wpdb->get_results( "SELECT DISTINCT post_author, COUNT(ID) AS count FROM $wpdb->posts WHERE " . get_private_posts_cap_sql( 'post' ) . ' GROUP BY post_author' ) as $row ) { |
442 |
$author_count[ $row->post_author ] = $row->count; |
|
5 | 443 |
} |
0 | 444 |
foreach ( $authors as $author_id ) { |
9 | 445 |
$posts = isset( $author_count[ $author_id ] ) ? $author_count[ $author_id ] : 0; |
0 | 446 |
|
9 | 447 |
if ( ! $posts && $args['hide_empty'] ) { |
0 | 448 |
continue; |
5 | 449 |
} |
0 | 450 |
|
9 | 451 |
$author = get_userdata( $author_id ); |
0 | 452 |
|
9 | 453 |
if ( $args['exclude_admin'] && 'admin' === $author->display_name ) { |
0 | 454 |
continue; |
5 | 455 |
} |
0 | 456 |
|
5 | 457 |
if ( $args['show_fullname'] && $author->first_name && $author->last_name ) { |
0 | 458 |
$name = "$author->first_name $author->last_name"; |
5 | 459 |
} else { |
0 | 460 |
$name = $author->display_name; |
5 | 461 |
} |
0 | 462 |
|
5 | 463 |
if ( ! $args['html'] ) { |
0 | 464 |
$return .= $name . ', '; |
465 |
||
466 |
continue; // No need to go further to process HTML. |
|
467 |
} |
|
468 |
||
5 | 469 |
if ( 'list' == $args['style'] ) { |
0 | 470 |
$return .= '<li>'; |
471 |
} |
|
472 |
||
9 | 473 |
$link = sprintf( |
474 |
'<a href="%1$s" title="%2$s">%3$s</a>', |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
475 |
get_author_posts_url( $author->ID, $author->user_nicename ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
476 |
/* translators: %s: author's display name */ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
477 |
esc_attr( sprintf( __( 'Posts by %s' ), $author->display_name ) ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
478 |
$name |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
479 |
); |
0 | 480 |
|
5 | 481 |
if ( ! empty( $args['feed_image'] ) || ! empty( $args['feed'] ) ) { |
0 | 482 |
$link .= ' '; |
5 | 483 |
if ( empty( $args['feed_image'] ) ) { |
0 | 484 |
$link .= '('; |
485 |
} |
|
486 |
||
5 | 487 |
$link .= '<a href="' . get_author_feed_link( $author->ID, $args['feed_type'] ) . '"'; |
0 | 488 |
|
5 | 489 |
$alt = ''; |
490 |
if ( ! empty( $args['feed'] ) ) { |
|
9 | 491 |
$alt = ' alt="' . esc_attr( $args['feed'] ) . '"'; |
5 | 492 |
$name = $args['feed']; |
0 | 493 |
} |
494 |
||
495 |
$link .= '>'; |
|
496 |
||
5 | 497 |
if ( ! empty( $args['feed_image'] ) ) { |
498 |
$link .= '<img src="' . esc_url( $args['feed_image'] ) . '" style="border: none;"' . $alt . ' />'; |
|
499 |
} else { |
|
0 | 500 |
$link .= $name; |
5 | 501 |
} |
0 | 502 |
|
503 |
$link .= '</a>'; |
|
504 |
||
5 | 505 |
if ( empty( $args['feed_image'] ) ) { |
0 | 506 |
$link .= ')'; |
5 | 507 |
} |
0 | 508 |
} |
509 |
||
5 | 510 |
if ( $args['optioncount'] ) { |
9 | 511 |
$link .= ' (' . $posts . ')'; |
5 | 512 |
} |
0 | 513 |
|
514 |
$return .= $link; |
|
5 | 515 |
$return .= ( 'list' == $args['style'] ) ? '</li>' : ', '; |
0 | 516 |
} |
517 |
||
5 | 518 |
$return = rtrim( $return, ', ' ); |
0 | 519 |
|
5 | 520 |
if ( ! $args['echo'] ) { |
0 | 521 |
return $return; |
5 | 522 |
} |
0 | 523 |
echo $return; |
524 |
} |
|
525 |
||
526 |
/** |
|
9 | 527 |
* Determines whether this site has more than one author. |
0 | 528 |
* |
529 |
* Checks to see if more than one author has published posts. |
|
530 |
* |
|
9 | 531 |
* For more information on this and similar theme functions, check out |
532 |
* the {@link https://developer.wordpress.org/themes/basics/conditional-tags/ |
|
533 |
* Conditional Tags} article in the Theme Developer Handbook. |
|
534 |
* |
|
0 | 535 |
* @since 3.2.0 |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
536 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
537 |
* @global wpdb $wpdb WordPress database abstraction object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
538 |
* |
0 | 539 |
* @return bool Whether or not we have more than one author |
540 |
*/ |
|
541 |
function is_multi_author() { |
|
542 |
global $wpdb; |
|
543 |
||
544 |
if ( false === ( $is_multi_author = get_transient( 'is_multi_author' ) ) ) { |
|
9 | 545 |
$rows = (array) $wpdb->get_col( "SELECT DISTINCT post_author FROM $wpdb->posts WHERE post_type = 'post' AND post_status = 'publish' LIMIT 2" ); |
0 | 546 |
$is_multi_author = 1 < count( $rows ) ? 1 : 0; |
547 |
set_transient( 'is_multi_author', $is_multi_author ); |
|
548 |
} |
|
549 |
||
550 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
551 |
* Filters whether the site has more than one author with published posts. |
0 | 552 |
* |
553 |
* @since 3.2.0 |
|
554 |
* |
|
555 |
* @param bool $is_multi_author Whether $is_multi_author should evaluate as true. |
|
556 |
*/ |
|
557 |
return apply_filters( 'is_multi_author', (bool) $is_multi_author ); |
|
558 |
} |
|
559 |
||
560 |
/** |
|
561 |
* Helper function to clear the cache for number of authors. |
|
562 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
563 |
* @since 3.2.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
564 |
* @access private |
0 | 565 |
*/ |
566 |
function __clear_multi_author_cache() { |
|
567 |
delete_transient( 'is_multi_author' ); |
|
568 |
} |