author | ymh <ymh.work@gmail.com> |
Tue, 27 Sep 2022 16:37:53 +0200 | |
changeset 19 | 3d72ae0968f4 |
parent 18 | be944660c56a |
child 21 | 48c4eec2b7e6 |
permissions | -rw-r--r-- |
0 | 1 |
<?php |
2 |
/** |
|
3 |
* WordPress Link Template Functions |
|
4 |
* |
|
5 |
* @package WordPress |
|
6 |
* @subpackage Template |
|
7 |
*/ |
|
8 |
||
9 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
10 |
* Displays the permalink for the current post. |
0 | 11 |
* |
12 |
* @since 1.2.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
13 |
* @since 4.4.0 Added the `$post` parameter. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
14 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
15 |
* @param int|WP_Post $post Optional. Post ID or post object. Default is the global `$post`. |
0 | 16 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
17 |
function the_permalink( $post = 0 ) { |
5 | 18 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
19 |
* Filters the display of the permalink for the current post. |
5 | 20 |
* |
21 |
* @since 1.5.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
22 |
* @since 4.4.0 Added the `$post` parameter. |
5 | 23 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
24 |
* @param string $permalink The permalink for the current post. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
25 |
* @param int|WP_Post $post Post ID, WP_Post object, or 0. Default 0. |
5 | 26 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
27 |
echo esc_url( apply_filters( 'the_permalink', get_permalink( $post ), $post ) ); |
0 | 28 |
} |
29 |
||
30 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
31 |
* Retrieves a trailing-slashed string if the site is set for adding trailing slashes. |
0 | 32 |
* |
33 |
* Conditionally adds a trailing slash if the permalink structure has a trailing |
|
34 |
* slash, strips the trailing slash if not. The string is passed through the |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
35 |
* {@see 'user_trailingslashit'} filter. Will remove trailing slash from string, if |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
36 |
* site is not set to have them. |
0 | 37 |
* |
38 |
* @since 2.2.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
39 |
* |
16 | 40 |
* @global WP_Rewrite $wp_rewrite WordPress rewrite component. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
41 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
42 |
* @param string $string URL with or without a trailing slash. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
43 |
* @param string $type_of_url Optional. The type of URL being considered (e.g. single, category, etc) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
44 |
* for use in the filter. Default empty string. |
5 | 45 |
* @return string The URL with the trailing slash appended or stripped. |
0 | 46 |
*/ |
9 | 47 |
function user_trailingslashit( $string, $type_of_url = '' ) { |
0 | 48 |
global $wp_rewrite; |
9 | 49 |
if ( $wp_rewrite->use_trailing_slashes ) { |
50 |
$string = trailingslashit( $string ); |
|
51 |
} else { |
|
52 |
$string = untrailingslashit( $string ); |
|
53 |
} |
|
0 | 54 |
|
5 | 55 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
56 |
* Filters the trailing-slashed string, depending on whether the site is set to use trailing slashes. |
5 | 57 |
* |
58 |
* @since 2.2.0 |
|
59 |
* |
|
60 |
* @param string $string URL with or without a trailing slash. |
|
61 |
* @param string $type_of_url The type of URL being considered. Accepts 'single', 'single_trackback', |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
62 |
* 'single_feed', 'single_paged', 'commentpaged', 'paged', 'home', 'feed', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
63 |
* 'category', 'page', 'year', 'month', 'day', 'post_type_archive'. |
5 | 64 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
65 |
return apply_filters( 'user_trailingslashit', $string, $type_of_url ); |
0 | 66 |
} |
67 |
||
68 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
69 |
* Displays the permalink anchor for the current post. |
0 | 70 |
* |
71 |
* The permalink mode title will use the post title for the 'a' element 'id' |
|
72 |
* attribute. The id mode uses 'post-' with the post ID for the 'id' attribute. |
|
73 |
* |
|
74 |
* @since 0.71 |
|
75 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
76 |
* @param string $mode Optional. Permalink mode. Accepts 'title' or 'id'. Default 'id'. |
0 | 77 |
*/ |
78 |
function permalink_anchor( $mode = 'id' ) { |
|
79 |
$post = get_post(); |
|
80 |
switch ( strtolower( $mode ) ) { |
|
81 |
case 'title': |
|
82 |
$title = sanitize_title( $post->post_title ) . '-' . $post->ID; |
|
9 | 83 |
echo '<a id="' . $title . '"></a>'; |
0 | 84 |
break; |
85 |
case 'id': |
|
86 |
default: |
|
87 |
echo '<a id="post-' . $post->ID . '"></a>'; |
|
88 |
break; |
|
89 |
} |
|
90 |
} |
|
91 |
||
92 |
/** |
|
18 | 93 |
* Determine whether post should always use a plain permalink structure. |
94 |
* |
|
95 |
* @since 5.7.0 |
|
96 |
* |
|
97 |
* @param WP_Post|int|null $post Optional. Post ID or post object. Defaults to global $post. |
|
98 |
* @param bool|null $sample Optional. Whether to force consideration based on sample links. |
|
99 |
* If omitted, a sample link is generated if a post object is passed |
|
100 |
* with the filter property set to 'sample'. |
|
101 |
* @return bool Whether to use a plain permalink structure. |
|
102 |
*/ |
|
103 |
function wp_force_plain_post_permalink( $post = null, $sample = null ) { |
|
104 |
if ( |
|
105 |
null === $sample && |
|
106 |
is_object( $post ) && |
|
107 |
isset( $post->filter ) && |
|
108 |
'sample' === $post->filter |
|
109 |
) { |
|
110 |
$sample = true; |
|
111 |
} else { |
|
112 |
$post = get_post( $post ); |
|
113 |
$sample = null !== $sample ? $sample : false; |
|
114 |
} |
|
115 |
||
116 |
if ( ! $post ) { |
|
117 |
return true; |
|
118 |
} |
|
119 |
||
120 |
$post_status_obj = get_post_status_object( get_post_status( $post ) ); |
|
121 |
$post_type_obj = get_post_type_object( get_post_type( $post ) ); |
|
122 |
||
123 |
if ( ! $post_status_obj || ! $post_type_obj ) { |
|
124 |
return true; |
|
125 |
} |
|
126 |
||
127 |
if ( |
|
128 |
// Publicly viewable links never have plain permalinks. |
|
129 |
is_post_status_viewable( $post_status_obj ) || |
|
130 |
( |
|
131 |
// Private posts don't have plain permalinks if the user can read them. |
|
132 |
$post_status_obj->private && |
|
133 |
current_user_can( 'read_post', $post->ID ) |
|
134 |
) || |
|
135 |
// Protected posts don't have plain links if getting a sample URL. |
|
136 |
( $post_status_obj->protected && $sample ) |
|
137 |
) { |
|
138 |
return false; |
|
139 |
} |
|
140 |
||
141 |
return true; |
|
142 |
} |
|
143 |
||
144 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
145 |
* Retrieves the full permalink for the current post or post ID. |
0 | 146 |
* |
5 | 147 |
* This function is an alias for get_permalink(). |
148 |
* |
|
149 |
* @since 3.9.0 |
|
150 |
* |
|
151 |
* @see get_permalink() |
|
152 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
153 |
* @param int|WP_Post $post Optional. Post ID or post object. Default is the global `$post`. |
5 | 154 |
* @param bool $leavename Optional. Whether to keep post name or page name. Default false. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
155 |
* @return string|false The permalink URL or false if post does not exist. |
5 | 156 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
157 |
function get_the_permalink( $post = 0, $leavename = false ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
158 |
return get_permalink( $post, $leavename ); |
5 | 159 |
} |
160 |
||
161 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
162 |
* Retrieves the full permalink for the current post or post ID. |
5 | 163 |
* |
0 | 164 |
* @since 1.0.0 |
165 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
166 |
* @param int|WP_Post $post Optional. Post ID or post object. Default is the global `$post`. |
5 | 167 |
* @param bool $leavename Optional. Whether to keep post name or page name. Default false. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
168 |
* @return string|false The permalink URL or false if post does not exist. |
0 | 169 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
170 |
function get_permalink( $post = 0, $leavename = false ) { |
0 | 171 |
$rewritecode = array( |
172 |
'%year%', |
|
173 |
'%monthnum%', |
|
174 |
'%day%', |
|
175 |
'%hour%', |
|
176 |
'%minute%', |
|
177 |
'%second%', |
|
9 | 178 |
$leavename ? '' : '%postname%', |
0 | 179 |
'%post_id%', |
180 |
'%category%', |
|
181 |
'%author%', |
|
9 | 182 |
$leavename ? '' : '%pagename%', |
0 | 183 |
); |
184 |
||
16 | 185 |
if ( is_object( $post ) && isset( $post->filter ) && 'sample' === $post->filter ) { |
0 | 186 |
$sample = true; |
187 |
} else { |
|
9 | 188 |
$post = get_post( $post ); |
0 | 189 |
$sample = false; |
190 |
} |
|
191 |
||
9 | 192 |
if ( empty( $post->ID ) ) { |
0 | 193 |
return false; |
9 | 194 |
} |
195 |
||
16 | 196 |
if ( 'page' === $post->post_type ) { |
9 | 197 |
return get_page_link( $post, $leavename, $sample ); |
16 | 198 |
} elseif ( 'attachment' === $post->post_type ) { |
5 | 199 |
return get_attachment_link( $post, $leavename ); |
16 | 200 |
} elseif ( in_array( $post->post_type, get_post_types( array( '_builtin' => false ) ), true ) ) { |
9 | 201 |
return get_post_permalink( $post, $leavename, $sample ); |
202 |
} |
|
203 |
||
204 |
$permalink = get_option( 'permalink_structure' ); |
|
0 | 205 |
|
5 | 206 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
207 |
* Filters the permalink structure for a post before token replacement occurs. |
5 | 208 |
* |
209 |
* Only applies to posts with post_type of 'post'. |
|
210 |
* |
|
211 |
* @since 3.0.0 |
|
212 |
* |
|
213 |
* @param string $permalink The site's permalink structure. |
|
214 |
* @param WP_Post $post The post in question. |
|
215 |
* @param bool $leavename Whether to keep the post name. |
|
216 |
*/ |
|
217 |
$permalink = apply_filters( 'pre_post_link', $permalink, $post, $leavename ); |
|
218 |
||
18 | 219 |
if ( |
220 |
$permalink && |
|
221 |
! wp_force_plain_post_permalink( $post ) |
|
222 |
) { |
|
0 | 223 |
|
224 |
$category = ''; |
|
9 | 225 |
if ( strpos( $permalink, '%category%' ) !== false ) { |
226 |
$cats = get_the_category( $post->ID ); |
|
0 | 227 |
if ( $cats ) { |
9 | 228 |
$cats = wp_list_sort( |
229 |
$cats, |
|
230 |
array( |
|
231 |
'term_id' => 'ASC', |
|
232 |
) |
|
233 |
); |
|
5 | 234 |
|
235 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
236 |
* Filters the category that gets used in the %category% permalink token. |
5 | 237 |
* |
238 |
* @since 3.5.0 |
|
239 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
240 |
* @param WP_Term $cat The category to use in the permalink. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
241 |
* @param array $cats Array of all categories (WP_Term objects) associated with the post. |
5 | 242 |
* @param WP_Post $post The post in question. |
243 |
*/ |
|
0 | 244 |
$category_object = apply_filters( 'post_link_category', $cats[0], $cats, $post ); |
5 | 245 |
|
0 | 246 |
$category_object = get_term( $category_object, 'category' ); |
9 | 247 |
$category = $category_object->slug; |
248 |
if ( $category_object->parent ) { |
|
249 |
$category = get_category_parents( $category_object->parent, false, '/', true ) . $category; |
|
250 |
} |
|
0 | 251 |
} |
16 | 252 |
// Show default category in permalinks, |
253 |
// without having to assign it explicitly. |
|
9 | 254 |
if ( empty( $category ) ) { |
0 | 255 |
$default_category = get_term( get_option( 'default_category' ), 'category' ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
256 |
if ( $default_category && ! is_wp_error( $default_category ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
257 |
$category = $default_category->slug; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
258 |
} |
0 | 259 |
} |
260 |
} |
|
261 |
||
262 |
$author = ''; |
|
9 | 263 |
if ( strpos( $permalink, '%author%' ) !== false ) { |
264 |
$authordata = get_userdata( $post->post_author ); |
|
265 |
$author = $authordata->user_nicename; |
|
0 | 266 |
} |
267 |
||
16 | 268 |
// This is not an API call because the permalink is based on the stored post_date value, |
269 |
// which should be parsed as local time regardless of the default PHP timezone. |
|
270 |
$date = explode( ' ', str_replace( array( '-', ':' ), ' ', $post->post_date ) ); |
|
271 |
||
272 |
$rewritereplace = array( |
|
0 | 273 |
$date[0], |
274 |
$date[1], |
|
275 |
$date[2], |
|
276 |
$date[3], |
|
277 |
$date[4], |
|
278 |
$date[5], |
|
279 |
$post->post_name, |
|
280 |
$post->ID, |
|
281 |
$category, |
|
282 |
$author, |
|
283 |
$post->post_name, |
|
284 |
); |
|
16 | 285 |
|
286 |
$permalink = home_url( str_replace( $rewritecode, $rewritereplace, $permalink ) ); |
|
287 |
$permalink = user_trailingslashit( $permalink, 'single' ); |
|
288 |
||
289 |
} else { // If they're not using the fancy permalink option. |
|
9 | 290 |
$permalink = home_url( '?p=' . $post->ID ); |
0 | 291 |
} |
5 | 292 |
|
293 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
294 |
* Filters the permalink for a post. |
5 | 295 |
* |
296 |
* Only applies to posts with post_type of 'post'. |
|
297 |
* |
|
298 |
* @since 1.5.0 |
|
299 |
* |
|
300 |
* @param string $permalink The post's permalink. |
|
301 |
* @param WP_Post $post The post in question. |
|
302 |
* @param bool $leavename Whether to keep the post name. |
|
303 |
*/ |
|
304 |
return apply_filters( 'post_link', $permalink, $post, $leavename ); |
|
0 | 305 |
} |
306 |
||
307 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
308 |
* Retrieves the permalink for a post of a custom post type. |
0 | 309 |
* |
310 |
* @since 3.0.0 |
|
311 |
* |
|
16 | 312 |
* @global WP_Rewrite $wp_rewrite WordPress rewrite component. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
313 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
314 |
* @param int|WP_Post $id Optional. Post ID or post object. Default is the global `$post`. |
16 | 315 |
* @param bool $leavename Optional. Whether to keep post name. Default false. |
316 |
* @param bool $sample Optional. Is it a sample permalink. Default false. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
317 |
* @return string|WP_Error The post permalink. |
0 | 318 |
*/ |
319 |
function get_post_permalink( $id = 0, $leavename = false, $sample = false ) { |
|
320 |
global $wp_rewrite; |
|
321 |
||
9 | 322 |
$post = get_post( $id ); |
323 |
||
324 |
if ( is_wp_error( $post ) ) { |
|
0 | 325 |
return $post; |
9 | 326 |
} |
327 |
||
328 |
$post_link = $wp_rewrite->get_extra_permastruct( $post->post_type ); |
|
0 | 329 |
|
330 |
$slug = $post->post_name; |
|
331 |
||
18 | 332 |
$force_plain_link = wp_force_plain_post_permalink( $post ); |
0 | 333 |
|
9 | 334 |
$post_type = get_post_type_object( $post->post_type ); |
0 | 335 |
|
5 | 336 |
if ( $post_type->hierarchical ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
337 |
$slug = get_page_uri( $post ); |
5 | 338 |
} |
339 |
||
18 | 340 |
if ( ! empty( $post_link ) && ( ! $force_plain_link || $sample ) ) { |
0 | 341 |
if ( ! $leavename ) { |
9 | 342 |
$post_link = str_replace( "%$post->post_type%", $slug, $post_link ); |
0 | 343 |
} |
9 | 344 |
$post_link = home_url( user_trailingslashit( $post_link ) ); |
0 | 345 |
} else { |
18 | 346 |
if ( $post_type->query_var && ( isset( $post->post_status ) && ! $force_plain_link ) ) { |
9 | 347 |
$post_link = add_query_arg( $post_type->query_var, $slug, '' ); |
348 |
} else { |
|
349 |
$post_link = add_query_arg( |
|
350 |
array( |
|
351 |
'post_type' => $post->post_type, |
|
352 |
'p' => $post->ID, |
|
353 |
), |
|
354 |
'' |
|
355 |
); |
|
356 |
} |
|
357 |
$post_link = home_url( $post_link ); |
|
0 | 358 |
} |
359 |
||
5 | 360 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
361 |
* Filters the permalink for a post of a custom post type. |
5 | 362 |
* |
363 |
* @since 3.0.0 |
|
364 |
* |
|
365 |
* @param string $post_link The post's permalink. |
|
366 |
* @param WP_Post $post The post in question. |
|
367 |
* @param bool $leavename Whether to keep the post name. |
|
368 |
* @param bool $sample Is it a sample permalink. |
|
369 |
*/ |
|
370 |
return apply_filters( 'post_type_link', $post_link, $post, $leavename, $sample ); |
|
0 | 371 |
} |
372 |
||
373 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
374 |
* Retrieves the permalink for the current page or page ID. |
0 | 375 |
* |
376 |
* Respects page_on_front. Use this one. |
|
377 |
* |
|
378 |
* @since 1.5.0 |
|
379 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
380 |
* @param int|WP_Post $post Optional. Post ID or object. Default uses the global `$post`. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
381 |
* @param bool $leavename Optional. Whether to keep the page name. Default false. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
382 |
* @param bool $sample Optional. Whether it should be treated as a sample permalink. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
383 |
* Default false. |
5 | 384 |
* @return string The page permalink. |
0 | 385 |
*/ |
386 |
function get_page_link( $post = false, $leavename = false, $sample = false ) { |
|
387 |
$post = get_post( $post ); |
|
388 |
||
16 | 389 |
if ( 'page' === get_option( 'show_on_front' ) && get_option( 'page_on_front' ) == $post->ID ) { |
9 | 390 |
$link = home_url( '/' ); |
391 |
} else { |
|
0 | 392 |
$link = _get_page_link( $post, $leavename, $sample ); |
9 | 393 |
} |
0 | 394 |
|
5 | 395 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
396 |
* Filters the permalink for a page. |
5 | 397 |
* |
398 |
* @since 1.5.0 |
|
399 |
* |
|
400 |
* @param string $link The page's permalink. |
|
401 |
* @param int $post_id The ID of the page. |
|
402 |
* @param bool $sample Is it a sample permalink. |
|
403 |
*/ |
|
0 | 404 |
return apply_filters( 'page_link', $link, $post->ID, $sample ); |
405 |
} |
|
406 |
||
407 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
408 |
* Retrieves the page permalink. |
0 | 409 |
* |
410 |
* Ignores page_on_front. Internal use only. |
|
411 |
* |
|
412 |
* @since 2.1.0 |
|
413 |
* @access private |
|
414 |
* |
|
16 | 415 |
* @global WP_Rewrite $wp_rewrite WordPress rewrite component. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
416 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
417 |
* @param int|WP_Post $post Optional. Post ID or object. Default uses the global `$post`. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
418 |
* @param bool $leavename Optional. Whether to keep the page name. Default false. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
419 |
* @param bool $sample Optional. Whether it should be treated as a sample permalink. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
420 |
* Default false. |
5 | 421 |
* @return string The page permalink. |
0 | 422 |
*/ |
423 |
function _get_page_link( $post = false, $leavename = false, $sample = false ) { |
|
424 |
global $wp_rewrite; |
|
425 |
||
426 |
$post = get_post( $post ); |
|
427 |
||
18 | 428 |
$force_plain_link = wp_force_plain_post_permalink( $post ); |
0 | 429 |
|
430 |
$link = $wp_rewrite->get_page_permastruct(); |
|
431 |
||
18 | 432 |
if ( ! empty( $link ) && ( ( isset( $post->post_status ) && ! $force_plain_link ) || $sample ) ) { |
0 | 433 |
if ( ! $leavename ) { |
9 | 434 |
$link = str_replace( '%pagename%', get_page_uri( $post ), $link ); |
0 | 435 |
} |
436 |
||
9 | 437 |
$link = home_url( $link ); |
438 |
$link = user_trailingslashit( $link, 'page' ); |
|
0 | 439 |
} else { |
440 |
$link = home_url( '?page_id=' . $post->ID ); |
|
441 |
} |
|
442 |
||
5 | 443 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
444 |
* Filters the permalink for a non-page_on_front page. |
5 | 445 |
* |
446 |
* @since 2.1.0 |
|
447 |
* |
|
448 |
* @param string $link The page's permalink. |
|
449 |
* @param int $post_id The ID of the page. |
|
450 |
*/ |
|
0 | 451 |
return apply_filters( '_get_page_link', $link, $post->ID ); |
452 |
} |
|
453 |
||
454 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
455 |
* Retrieves the permalink for an attachment. |
0 | 456 |
* |
457 |
* This can be used in the WordPress Loop or outside of it. |
|
458 |
* |
|
459 |
* @since 2.0.0 |
|
460 |
* |
|
16 | 461 |
* @global WP_Rewrite $wp_rewrite WordPress rewrite component. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
462 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
463 |
* @param int|object $post Optional. Post ID or object. Default uses the global `$post`. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
464 |
* @param bool $leavename Optional. Whether to keep the page name. Default false. |
5 | 465 |
* @return string The attachment permalink. |
0 | 466 |
*/ |
467 |
function get_attachment_link( $post = null, $leavename = false ) { |
|
468 |
global $wp_rewrite; |
|
469 |
||
470 |
$link = false; |
|
471 |
||
18 | 472 |
$post = get_post( $post ); |
473 |
$force_plain_link = wp_force_plain_post_permalink( $post ); |
|
474 |
$parent_id = $post->post_parent; |
|
475 |
$parent = $parent_id ? get_post( $parent_id ) : false; |
|
476 |
$parent_valid = true; // Default for no parent. |
|
477 |
if ( |
|
478 |
$parent_id && |
|
479 |
( |
|
480 |
$post->post_parent === $post->ID || |
|
481 |
! $parent || |
|
482 |
! is_post_type_viewable( get_post_type( $parent ) ) |
|
483 |
) |
|
484 |
) { |
|
485 |
// Post is either its own parent or parent post unavailable. |
|
486 |
$parent_valid = false; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
487 |
} |
0 | 488 |
|
18 | 489 |
if ( $force_plain_link || ! $parent_valid ) { |
490 |
$link = false; |
|
491 |
} elseif ( $wp_rewrite->using_permalinks() && $parent ) { |
|
16 | 492 |
if ( 'page' === $parent->post_type ) { |
493 |
$parentlink = _get_page_link( $post->post_parent ); // Ignores page_on_front. |
|
9 | 494 |
} else { |
0 | 495 |
$parentlink = get_permalink( $post->post_parent ); |
9 | 496 |
} |
497 |
||
498 |
if ( is_numeric( $post->post_name ) || false !== strpos( get_option( 'permalink_structure' ), '%category%' ) ) { |
|
16 | 499 |
$name = 'attachment/' . $post->post_name; // <permalink>/<int>/ is paged so we use the explicit attachment marker. |
9 | 500 |
} else { |
0 | 501 |
$name = $post->post_name; |
9 | 502 |
} |
503 |
||
504 |
if ( strpos( $parentlink, '?' ) === false ) { |
|
505 |
$link = user_trailingslashit( trailingslashit( $parentlink ) . '%postname%' ); |
|
506 |
} |
|
507 |
||
508 |
if ( ! $leavename ) { |
|
0 | 509 |
$link = str_replace( '%postname%', $name, $link ); |
9 | 510 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
511 |
} elseif ( $wp_rewrite->using_permalinks() && ! $leavename ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
512 |
$link = home_url( user_trailingslashit( $post->post_name ) ); |
0 | 513 |
} |
514 |
||
9 | 515 |
if ( ! $link ) { |
0 | 516 |
$link = home_url( '/?attachment_id=' . $post->ID ); |
9 | 517 |
} |
0 | 518 |
|
5 | 519 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
520 |
* Filters the permalink for an attachment. |
5 | 521 |
* |
522 |
* @since 2.0.0 |
|
18 | 523 |
* @since 5.6.0 Providing an empty string will now disable |
524 |
* the view attachment page link on the media modal. |
|
5 | 525 |
* |
526 |
* @param string $link The attachment's permalink. |
|
527 |
* @param int $post_id Attachment ID. |
|
528 |
*/ |
|
0 | 529 |
return apply_filters( 'attachment_link', $link, $post->ID ); |
530 |
} |
|
531 |
||
532 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
533 |
* Retrieves the permalink for the year archives. |
0 | 534 |
* |
535 |
* @since 1.5.0 |
|
536 |
* |
|
16 | 537 |
* @global WP_Rewrite $wp_rewrite WordPress rewrite component. |
538 |
* |
|
539 |
* @param int|false $year Integer of year. False for current year. |
|
5 | 540 |
* @return string The permalink for the specified year archive. |
0 | 541 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
542 |
function get_year_link( $year ) { |
0 | 543 |
global $wp_rewrite; |
9 | 544 |
if ( ! $year ) { |
545 |
$year = current_time( 'Y' ); |
|
546 |
} |
|
0 | 547 |
$yearlink = $wp_rewrite->get_year_permastruct(); |
9 | 548 |
if ( ! empty( $yearlink ) ) { |
549 |
$yearlink = str_replace( '%year%', $year, $yearlink ); |
|
5 | 550 |
$yearlink = home_url( user_trailingslashit( $yearlink, 'year' ) ); |
0 | 551 |
} else { |
5 | 552 |
$yearlink = home_url( '?m=' . $year ); |
0 | 553 |
} |
5 | 554 |
|
555 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
556 |
* Filters the year archive permalink. |
5 | 557 |
* |
558 |
* @since 1.5.0 |
|
559 |
* |
|
560 |
* @param string $yearlink Permalink for the year archive. |
|
561 |
* @param int $year Year for the archive. |
|
562 |
*/ |
|
563 |
return apply_filters( 'year_link', $yearlink, $year ); |
|
0 | 564 |
} |
565 |
||
566 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
567 |
* Retrieves the permalink for the month archives with year. |
0 | 568 |
* |
569 |
* @since 1.0.0 |
|
570 |
* |
|
16 | 571 |
* @global WP_Rewrite $wp_rewrite WordPress rewrite component. |
572 |
* |
|
573 |
* @param int|false $year Integer of year. False for current year. |
|
574 |
* @param int|false $month Integer of month. False for current month. |
|
5 | 575 |
* @return string The permalink for the specified month and year archive. |
0 | 576 |
*/ |
9 | 577 |
function get_month_link( $year, $month ) { |
0 | 578 |
global $wp_rewrite; |
9 | 579 |
if ( ! $year ) { |
580 |
$year = current_time( 'Y' ); |
|
581 |
} |
|
582 |
if ( ! $month ) { |
|
583 |
$month = current_time( 'm' ); |
|
584 |
} |
|
0 | 585 |
$monthlink = $wp_rewrite->get_month_permastruct(); |
9 | 586 |
if ( ! empty( $monthlink ) ) { |
587 |
$monthlink = str_replace( '%year%', $year, $monthlink ); |
|
18 | 588 |
$monthlink = str_replace( '%monthnum%', zeroise( (int) $month, 2 ), $monthlink ); |
5 | 589 |
$monthlink = home_url( user_trailingslashit( $monthlink, 'month' ) ); |
0 | 590 |
} else { |
5 | 591 |
$monthlink = home_url( '?m=' . $year . zeroise( $month, 2 ) ); |
0 | 592 |
} |
5 | 593 |
|
594 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
595 |
* Filters the month archive permalink. |
5 | 596 |
* |
597 |
* @since 1.5.0 |
|
598 |
* |
|
599 |
* @param string $monthlink Permalink for the month archive. |
|
600 |
* @param int $year Year for the archive. |
|
601 |
* @param int $month The month for the archive. |
|
602 |
*/ |
|
603 |
return apply_filters( 'month_link', $monthlink, $year, $month ); |
|
0 | 604 |
} |
605 |
||
606 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
607 |
* Retrieves the permalink for the day archives with year and month. |
0 | 608 |
* |
609 |
* @since 1.0.0 |
|
610 |
* |
|
16 | 611 |
* @global WP_Rewrite $wp_rewrite WordPress rewrite component. |
612 |
* |
|
613 |
* @param int|false $year Integer of year. False for current year. |
|
614 |
* @param int|false $month Integer of month. False for current month. |
|
615 |
* @param int|false $day Integer of day. False for current day. |
|
5 | 616 |
* @return string The permalink for the specified day, month, and year archive. |
0 | 617 |
*/ |
9 | 618 |
function get_day_link( $year, $month, $day ) { |
0 | 619 |
global $wp_rewrite; |
9 | 620 |
if ( ! $year ) { |
621 |
$year = current_time( 'Y' ); |
|
622 |
} |
|
623 |
if ( ! $month ) { |
|
624 |
$month = current_time( 'm' ); |
|
625 |
} |
|
626 |
if ( ! $day ) { |
|
627 |
$day = current_time( 'j' ); |
|
628 |
} |
|
0 | 629 |
|
630 |
$daylink = $wp_rewrite->get_day_permastruct(); |
|
9 | 631 |
if ( ! empty( $daylink ) ) { |
632 |
$daylink = str_replace( '%year%', $year, $daylink ); |
|
18 | 633 |
$daylink = str_replace( '%monthnum%', zeroise( (int) $month, 2 ), $daylink ); |
634 |
$daylink = str_replace( '%day%', zeroise( (int) $day, 2 ), $daylink ); |
|
5 | 635 |
$daylink = home_url( user_trailingslashit( $daylink, 'day' ) ); |
0 | 636 |
} else { |
5 | 637 |
$daylink = home_url( '?m=' . $year . zeroise( $month, 2 ) . zeroise( $day, 2 ) ); |
0 | 638 |
} |
5 | 639 |
|
640 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
641 |
* Filters the day archive permalink. |
5 | 642 |
* |
643 |
* @since 1.5.0 |
|
644 |
* |
|
645 |
* @param string $daylink Permalink for the day archive. |
|
646 |
* @param int $year Year for the archive. |
|
647 |
* @param int $month Month for the archive. |
|
648 |
* @param int $day The day for the archive. |
|
649 |
*/ |
|
650 |
return apply_filters( 'day_link', $daylink, $year, $month, $day ); |
|
0 | 651 |
} |
652 |
||
653 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
654 |
* Displays the permalink for the feed type. |
0 | 655 |
* |
656 |
* @since 3.0.0 |
|
657 |
* |
|
658 |
* @param string $anchor The link's anchor text. |
|
16 | 659 |
* @param string $feed Optional. Feed type. Possible values include 'rss2', 'atom'. |
660 |
* Default is the value of get_default_feed(). |
|
0 | 661 |
*/ |
662 |
function the_feed_link( $anchor, $feed = '' ) { |
|
663 |
$link = '<a href="' . esc_url( get_feed_link( $feed ) ) . '">' . $anchor . '</a>'; |
|
5 | 664 |
|
665 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
666 |
* Filters the feed link anchor tag. |
5 | 667 |
* |
668 |
* @since 3.0.0 |
|
669 |
* |
|
670 |
* @param string $link The complete anchor tag for a feed link. |
|
16 | 671 |
* @param string $feed The feed type. Possible values include 'rss2', 'atom', |
672 |
* or an empty string for the default feed type. |
|
5 | 673 |
*/ |
0 | 674 |
echo apply_filters( 'the_feed_link', $link, $feed ); |
675 |
} |
|
676 |
||
677 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
678 |
* Retrieves the permalink for the feed type. |
0 | 679 |
* |
680 |
* @since 1.5.0 |
|
681 |
* |
|
16 | 682 |
* @global WP_Rewrite $wp_rewrite WordPress rewrite component. |
683 |
* |
|
684 |
* @param string $feed Optional. Feed type. Possible values include 'rss2', 'atom'. |
|
685 |
* Default is the value of get_default_feed(). |
|
5 | 686 |
* @return string The feed permalink. |
0 | 687 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
688 |
function get_feed_link( $feed = '' ) { |
0 | 689 |
global $wp_rewrite; |
690 |
||
691 |
$permalink = $wp_rewrite->get_feed_permastruct(); |
|
16 | 692 |
|
18 | 693 |
if ( $permalink ) { |
9 | 694 |
if ( false !== strpos( $feed, 'comments_' ) ) { |
695 |
$feed = str_replace( 'comments_', '', $feed ); |
|
0 | 696 |
$permalink = $wp_rewrite->get_comment_feed_permastruct(); |
697 |
} |
|
698 |
||
9 | 699 |
if ( get_default_feed() == $feed ) { |
0 | 700 |
$feed = ''; |
9 | 701 |
} |
702 |
||
703 |
$permalink = str_replace( '%feed%', $feed, $permalink ); |
|
704 |
$permalink = preg_replace( '#/+#', '/', "/$permalink" ); |
|
705 |
$output = home_url( user_trailingslashit( $permalink, 'feed' ) ); |
|
0 | 706 |
} else { |
9 | 707 |
if ( empty( $feed ) ) { |
0 | 708 |
$feed = get_default_feed(); |
9 | 709 |
} |
710 |
||
711 |
if ( false !== strpos( $feed, 'comments_' ) ) { |
|
712 |
$feed = str_replace( 'comments_', 'comments-', $feed ); |
|
713 |
} |
|
714 |
||
715 |
$output = home_url( "?feed={$feed}" ); |
|
0 | 716 |
} |
717 |
||
5 | 718 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
719 |
* Filters the feed type permalink. |
5 | 720 |
* |
721 |
* @since 1.5.0 |
|
722 |
* |
|
723 |
* @param string $output The feed permalink. |
|
16 | 724 |
* @param string $feed The feed type. Possible values include 'rss2', 'atom', |
725 |
* or an empty string for the default feed type. |
|
5 | 726 |
*/ |
727 |
return apply_filters( 'feed_link', $output, $feed ); |
|
0 | 728 |
} |
729 |
||
730 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
731 |
* Retrieves the permalink for the post comments feed. |
0 | 732 |
* |
733 |
* @since 2.2.0 |
|
734 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
735 |
* @param int $post_id Optional. Post ID. Default is the ID of the global `$post`. |
16 | 736 |
* @param string $feed Optional. Feed type. Possible values include 'rss2', 'atom'. |
737 |
* Default is the value of get_default_feed(). |
|
18 | 738 |
* @return string The permalink for the comments feed for the given post on success, empty string on failure. |
0 | 739 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
740 |
function get_post_comments_feed_link( $post_id = 0, $feed = '' ) { |
0 | 741 |
$post_id = absint( $post_id ); |
742 |
||
9 | 743 |
if ( ! $post_id ) { |
0 | 744 |
$post_id = get_the_ID(); |
9 | 745 |
} |
746 |
||
747 |
if ( empty( $feed ) ) { |
|
0 | 748 |
$feed = get_default_feed(); |
9 | 749 |
} |
750 |
||
18 | 751 |
$post = get_post( $post_id ); |
752 |
||
753 |
// Bail out if the post does not exist. |
|
754 |
if ( ! $post instanceof WP_Post ) { |
|
755 |
return ''; |
|
756 |
} |
|
757 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
758 |
$unattached = 'attachment' === $post->post_type && 0 === (int) $post->post_parent; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
759 |
|
16 | 760 |
if ( get_option( 'permalink_structure' ) ) { |
761 |
if ( 'page' === get_option( 'show_on_front' ) && get_option( 'page_on_front' ) == $post_id ) { |
|
0 | 762 |
$url = _get_page_link( $post_id ); |
9 | 763 |
} else { |
764 |
$url = get_permalink( $post_id ); |
|
765 |
} |
|
0 | 766 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
767 |
if ( $unattached ) { |
9 | 768 |
$url = home_url( '/feed/' ); |
16 | 769 |
if ( get_default_feed() !== $feed ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
770 |
$url .= "$feed/"; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
771 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
772 |
$url = add_query_arg( 'attachment_id', $post_id, $url ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
773 |
} else { |
9 | 774 |
$url = trailingslashit( $url ) . 'feed'; |
16 | 775 |
if ( get_default_feed() != $feed ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
776 |
$url .= "/$feed"; |
9 | 777 |
} |
778 |
$url = user_trailingslashit( $url, 'single_feed' ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
779 |
} |
0 | 780 |
} else { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
781 |
if ( $unattached ) { |
9 | 782 |
$url = add_query_arg( |
783 |
array( |
|
784 |
'feed' => $feed, |
|
785 |
'attachment_id' => $post_id, |
|
786 |
), |
|
787 |
home_url( '/' ) |
|
788 |
); |
|
16 | 789 |
} elseif ( 'page' === $post->post_type ) { |
9 | 790 |
$url = add_query_arg( |
791 |
array( |
|
792 |
'feed' => $feed, |
|
793 |
'page_id' => $post_id, |
|
794 |
), |
|
795 |
home_url( '/' ) |
|
796 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
797 |
} else { |
9 | 798 |
$url = add_query_arg( |
799 |
array( |
|
800 |
'feed' => $feed, |
|
801 |
'p' => $post_id, |
|
802 |
), |
|
803 |
home_url( '/' ) |
|
804 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
805 |
} |
0 | 806 |
} |
807 |
||
5 | 808 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
809 |
* Filters the post comments feed permalink. |
5 | 810 |
* |
811 |
* @since 1.5.1 |
|
812 |
* |
|
813 |
* @param string $url Post comments feed permalink. |
|
814 |
*/ |
|
815 |
return apply_filters( 'post_comments_feed_link', $url ); |
|
0 | 816 |
} |
817 |
||
818 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
819 |
* Displays the comment feed link for a post. |
0 | 820 |
* |
821 |
* Prints out the comment feed link for a post. Link text is placed in the |
|
822 |
* anchor. If no link text is specified, default text is used. If no post ID is |
|
823 |
* specified, the current post is used. |
|
824 |
* |
|
825 |
* @since 2.5.0 |
|
826 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
827 |
* @param string $link_text Optional. Descriptive link text. Default 'Comments Feed'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
828 |
* @param int $post_id Optional. Post ID. Default is the ID of the global `$post`. |
16 | 829 |
* @param string $feed Optional. Feed type. Possible values include 'rss2', 'atom'. |
830 |
* Default is the value of get_default_feed(). |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
831 |
*/ |
0 | 832 |
function post_comments_feed_link( $link_text = '', $post_id = '', $feed = '' ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
833 |
$url = get_post_comments_feed_link( $post_id, $feed ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
834 |
if ( empty( $link_text ) ) { |
9 | 835 |
$link_text = __( 'Comments Feed' ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
836 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
837 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
838 |
$link = '<a href="' . esc_url( $url ) . '">' . $link_text . '</a>'; |
5 | 839 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
840 |
* Filters the post comment feed link anchor tag. |
5 | 841 |
* |
842 |
* @since 2.8.0 |
|
843 |
* |
|
844 |
* @param string $link The complete anchor tag for the comment feed link. |
|
845 |
* @param int $post_id Post ID. |
|
16 | 846 |
* @param string $feed The feed type. Possible values include 'rss2', 'atom', |
847 |
* or an empty string for the default feed type. |
|
5 | 848 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
849 |
echo apply_filters( 'post_comments_feed_link_html', $link, $post_id, $feed ); |
0 | 850 |
} |
851 |
||
852 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
853 |
* Retrieves the feed link for a given author. |
0 | 854 |
* |
855 |
* Returns a link to the feed for all posts by a given author. A specific feed |
|
856 |
* can be requested or left blank to get the default feed. |
|
857 |
* |
|
858 |
* @since 2.5.0 |
|
859 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
860 |
* @param int $author_id Author ID. |
16 | 861 |
* @param string $feed Optional. Feed type. Possible values include 'rss2', 'atom'. |
862 |
* Default is the value of get_default_feed(). |
|
0 | 863 |
* @return string Link to the feed for the author specified by $author_id. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
864 |
*/ |
0 | 865 |
function get_author_feed_link( $author_id, $feed = '' ) { |
9 | 866 |
$author_id = (int) $author_id; |
867 |
$permalink_structure = get_option( 'permalink_structure' ); |
|
868 |
||
869 |
if ( empty( $feed ) ) { |
|
0 | 870 |
$feed = get_default_feed(); |
9 | 871 |
} |
0 | 872 |
|
16 | 873 |
if ( ! $permalink_structure ) { |
9 | 874 |
$link = home_url( "?feed=$feed&author=" . $author_id ); |
0 | 875 |
} else { |
9 | 876 |
$link = get_author_posts_url( $author_id ); |
16 | 877 |
if ( get_default_feed() == $feed ) { |
0 | 878 |
$feed_link = 'feed'; |
9 | 879 |
} else { |
0 | 880 |
$feed_link = "feed/$feed"; |
9 | 881 |
} |
882 |
||
883 |
$link = trailingslashit( $link ) . user_trailingslashit( $feed_link, 'feed' ); |
|
0 | 884 |
} |
885 |
||
5 | 886 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
887 |
* Filters the feed link for a given author. |
5 | 888 |
* |
889 |
* @since 1.5.1 |
|
890 |
* |
|
891 |
* @param string $link The author feed link. |
|
16 | 892 |
* @param string $feed Feed type. Possible values include 'rss2', 'atom'. |
5 | 893 |
*/ |
894 |
$link = apply_filters( 'author_feed_link', $link, $feed ); |
|
0 | 895 |
|
896 |
return $link; |
|
897 |
} |
|
898 |
||
899 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
900 |
* Retrieves the feed link for a category. |
0 | 901 |
* |
902 |
* Returns a link to the feed for all posts in a given category. A specific feed |
|
903 |
* can be requested or left blank to get the default feed. |
|
904 |
* |
|
905 |
* @since 2.5.0 |
|
906 |
* |
|
19 | 907 |
* @param int|WP_Term|object $cat The ID or category object whose feed link will be retrieved. |
908 |
* @param string $feed Optional. Feed type. Possible values include 'rss2', 'atom'. |
|
909 |
* Default is the value of get_default_feed(). |
|
910 |
* @return string Link to the feed for the category specified by `$cat`. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
911 |
*/ |
19 | 912 |
function get_category_feed_link( $cat, $feed = '' ) { |
913 |
return get_term_feed_link( $cat, 'category', $feed ); |
|
0 | 914 |
} |
915 |
||
916 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
917 |
* Retrieves the feed link for a term. |
0 | 918 |
* |
919 |
* Returns a link to the feed for all posts in a given term. A specific feed |
|
920 |
* can be requested or left blank to get the default feed. |
|
921 |
* |
|
5 | 922 |
* @since 3.0.0 |
0 | 923 |
* |
19 | 924 |
* @param int|WP_Term|object $term The ID or term object whose feed link will be retrieved. |
925 |
* @param string $taxonomy Optional. Taxonomy of `$term_id`. |
|
926 |
* @param string $feed Optional. Feed type. Possible values include 'rss2', 'atom'. |
|
927 |
* Default is the value of get_default_feed(). |
|
928 |
* @return string|false Link to the feed for the term specified by `$term` and `$taxonomy`. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
929 |
*/ |
19 | 930 |
function get_term_feed_link( $term, $taxonomy = '', $feed = '' ) { |
931 |
if ( ! is_object( $term ) ) { |
|
932 |
$term = (int) $term; |
|
933 |
} |
|
934 |
||
935 |
$term = get_term( $term, $taxonomy ); |
|
9 | 936 |
|
937 |
if ( empty( $term ) || is_wp_error( $term ) ) { |
|
0 | 938 |
return false; |
9 | 939 |
} |
940 |
||
19 | 941 |
$taxonomy = $term->taxonomy; |
942 |
||
9 | 943 |
if ( empty( $feed ) ) { |
0 | 944 |
$feed = get_default_feed(); |
9 | 945 |
} |
0 | 946 |
|
947 |
$permalink_structure = get_option( 'permalink_structure' ); |
|
948 |
||
16 | 949 |
if ( ! $permalink_structure ) { |
950 |
if ( 'category' === $taxonomy ) { |
|
19 | 951 |
$link = home_url( "?feed=$feed&cat=$term->term_id" ); |
16 | 952 |
} elseif ( 'post_tag' === $taxonomy ) { |
9 | 953 |
$link = home_url( "?feed=$feed&tag=$term->slug" ); |
0 | 954 |
} else { |
9 | 955 |
$t = get_taxonomy( $taxonomy ); |
956 |
$link = home_url( "?feed=$feed&$t->query_var=$term->slug" ); |
|
0 | 957 |
} |
958 |
} else { |
|
19 | 959 |
$link = get_term_link( $term, $term->taxonomy ); |
16 | 960 |
if ( get_default_feed() == $feed ) { |
0 | 961 |
$feed_link = 'feed'; |
9 | 962 |
} else { |
0 | 963 |
$feed_link = "feed/$feed"; |
9 | 964 |
} |
0 | 965 |
|
966 |
$link = trailingslashit( $link ) . user_trailingslashit( $feed_link, 'feed' ); |
|
967 |
} |
|
968 |
||
16 | 969 |
if ( 'category' === $taxonomy ) { |
5 | 970 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
971 |
* Filters the category feed link. |
5 | 972 |
* |
973 |
* @since 1.5.1 |
|
974 |
* |
|
975 |
* @param string $link The category feed link. |
|
16 | 976 |
* @param string $feed Feed type. Possible values include 'rss2', 'atom'. |
5 | 977 |
*/ |
0 | 978 |
$link = apply_filters( 'category_feed_link', $link, $feed ); |
16 | 979 |
} elseif ( 'post_tag' === $taxonomy ) { |
5 | 980 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
981 |
* Filters the post tag feed link. |
5 | 982 |
* |
983 |
* @since 2.3.0 |
|
984 |
* |
|
985 |
* @param string $link The tag feed link. |
|
16 | 986 |
* @param string $feed Feed type. Possible values include 'rss2', 'atom'. |
5 | 987 |
*/ |
0 | 988 |
$link = apply_filters( 'tag_feed_link', $link, $feed ); |
5 | 989 |
} else { |
990 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
991 |
* Filters the feed link for a taxonomy other than 'category' or 'post_tag'. |
5 | 992 |
* |
993 |
* @since 3.0.0 |
|
994 |
* |
|
16 | 995 |
* @param string $link The taxonomy feed link. |
996 |
* @param string $feed Feed type. Possible values include 'rss2', 'atom'. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
997 |
* @param string $taxonomy The taxonomy name. |
5 | 998 |
*/ |
0 | 999 |
$link = apply_filters( 'taxonomy_feed_link', $link, $feed, $taxonomy ); |
5 | 1000 |
} |
0 | 1001 |
|
1002 |
return $link; |
|
1003 |
} |
|
1004 |
||
1005 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1006 |
* Retrieves the permalink for a tag feed. |
0 | 1007 |
* |
1008 |
* @since 2.3.0 |
|
1009 |
* |
|
19 | 1010 |
* @param int|WP_Term|object $tag The ID or term object whose feed link will be retrieved. |
1011 |
* @param string $feed Optional. Feed type. Possible values include 'rss2', 'atom'. |
|
1012 |
* Default is the value of get_default_feed(). |
|
1013 |
* @return string The feed permalink for the given tag. |
|
0 | 1014 |
*/ |
19 | 1015 |
function get_tag_feed_link( $tag, $feed = '' ) { |
1016 |
return get_term_feed_link( $tag, 'post_tag', $feed ); |
|
0 | 1017 |
} |
1018 |
||
1019 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1020 |
* Retrieves the edit link for a tag. |
0 | 1021 |
* |
1022 |
* @since 2.7.0 |
|
1023 |
* |
|
19 | 1024 |
* @param int|WP_Term|object $tag The ID or term object whose edit link will be retrieved. |
1025 |
* @param string $taxonomy Optional. Taxonomy slug. Default 'post_tag'. |
|
5 | 1026 |
* @return string The edit tag link URL for the given tag. |
0 | 1027 |
*/ |
19 | 1028 |
function get_edit_tag_link( $tag, $taxonomy = 'post_tag' ) { |
5 | 1029 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1030 |
* Filters the edit link for a tag (or term in another taxonomy). |
5 | 1031 |
* |
1032 |
* @since 2.7.0 |
|
1033 |
* |
|
1034 |
* @param string $link The term edit link. |
|
1035 |
*/ |
|
19 | 1036 |
return apply_filters( 'get_edit_tag_link', get_edit_term_link( $tag, $taxonomy ) ); |
0 | 1037 |
} |
1038 |
||
1039 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1040 |
* Displays or retrieves the edit link for a tag with formatting. |
0 | 1041 |
* |
1042 |
* @since 2.7.0 |
|
1043 |
* |
|
16 | 1044 |
* @param string $link Optional. Anchor text. If empty, default is 'Edit This'. Default empty. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1045 |
* @param string $before Optional. Display before edit link. Default empty. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1046 |
* @param string $after Optional. Display after edit link. Default empty. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1047 |
* @param WP_Term $tag Optional. Term object. If null, the queried object will be inspected. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1048 |
* Default null. |
0 | 1049 |
*/ |
1050 |
function edit_tag_link( $link = '', $before = '', $after = '', $tag = null ) { |
|
1051 |
$link = edit_term_link( $link, '', '', $tag, false ); |
|
5 | 1052 |
|
1053 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1054 |
* Filters the anchor tag for the edit link for a tag (or term in another taxonomy). |
5 | 1055 |
* |
1056 |
* @since 2.7.0 |
|
1057 |
* |
|
1058 |
* @param string $link The anchor tag for the edit link. |
|
1059 |
*/ |
|
0 | 1060 |
echo $before . apply_filters( 'edit_tag_link', $link ) . $after; |
1061 |
} |
|
1062 |
||
1063 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1064 |
* Retrieves the URL for editing a given term. |
0 | 1065 |
* |
1066 |
* @since 3.1.0 |
|
16 | 1067 |
* @since 4.5.0 The `$taxonomy` parameter was made optional. |
0 | 1068 |
* |
19 | 1069 |
* @param int|WP_Term|object $term The ID or term object whose edit link will be retrieved. |
1070 |
* @param string $taxonomy Optional. Taxonomy. Defaults to the taxonomy of the term identified |
|
1071 |
* by `$term`. |
|
1072 |
* @param string $object_type Optional. The object type. Used to highlight the proper post type |
|
1073 |
* menu on the linked page. Defaults to the first object_type associated |
|
1074 |
* with the taxonomy. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1075 |
* @return string|null The edit term link URL for the given term, or null on failure. |
0 | 1076 |
*/ |
19 | 1077 |
function get_edit_term_link( $term, $taxonomy = '', $object_type = '' ) { |
1078 |
$term = get_term( $term, $taxonomy ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1079 |
if ( ! $term || is_wp_error( $term ) ) { |
0 | 1080 |
return; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1081 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1082 |
|
19 | 1083 |
$tax = get_taxonomy( $term->taxonomy ); |
1084 |
$term_id = $term->term_id; |
|
1085 |
if ( ! $tax || ! current_user_can( 'edit_term', $term_id ) ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1086 |
return; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1087 |
} |
0 | 1088 |
|
1089 |
$args = array( |
|
1090 |
'taxonomy' => $taxonomy, |
|
19 | 1091 |
'tag_ID' => $term_id, |
0 | 1092 |
); |
1093 |
||
5 | 1094 |
if ( $object_type ) { |
0 | 1095 |
$args['post_type'] = $object_type; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1096 |
} elseif ( ! empty( $tax->object_type ) ) { |
5 | 1097 |
$args['post_type'] = reset( $tax->object_type ); |
1098 |
} |
|
0 | 1099 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1100 |
if ( $tax->show_ui ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1101 |
$location = add_query_arg( $args, admin_url( 'term.php' ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1102 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1103 |
$location = ''; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1104 |
} |
0 | 1105 |
|
5 | 1106 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1107 |
* Filters the edit link for a term. |
5 | 1108 |
* |
1109 |
* @since 3.1.0 |
|
1110 |
* |
|
1111 |
* @param string $location The edit link. |
|
1112 |
* @param int $term_id Term ID. |
|
1113 |
* @param string $taxonomy Taxonomy name. |
|
19 | 1114 |
* @param string $object_type The object type. |
5 | 1115 |
*/ |
0 | 1116 |
return apply_filters( 'get_edit_term_link', $location, $term_id, $taxonomy, $object_type ); |
1117 |
} |
|
1118 |
||
1119 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1120 |
* Displays or retrieves the edit term link with formatting. |
0 | 1121 |
* |
1122 |
* @since 3.1.0 |
|
1123 |
* |
|
19 | 1124 |
* @param string $link Optional. Anchor text. If empty, default is 'Edit This'. Default empty. |
1125 |
* @param string $before Optional. Display before edit link. Default empty. |
|
1126 |
* @param string $after Optional. Display after edit link. Default empty. |
|
1127 |
* @param int|WP_Term|null $term Optional. Term ID or object. If null, the queried object will be inspected. Default null. |
|
1128 |
* @param bool $echo Optional. Whether or not to echo the return. Default true. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1129 |
* @return string|void HTML content. |
0 | 1130 |
*/ |
1131 |
function edit_term_link( $link = '', $before = '', $after = '', $term = null, $echo = true ) { |
|
9 | 1132 |
if ( is_null( $term ) ) { |
0 | 1133 |
$term = get_queried_object(); |
19 | 1134 |
} else { |
1135 |
$term = get_term( $term ); |
|
9 | 1136 |
} |
1137 |
||
1138 |
if ( ! $term ) { |
|
0 | 1139 |
return; |
9 | 1140 |
} |
0 | 1141 |
|
1142 |
$tax = get_taxonomy( $term->taxonomy ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1143 |
if ( ! current_user_can( 'edit_term', $term->term_id ) ) { |
0 | 1144 |
return; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1145 |
} |
0 | 1146 |
|
9 | 1147 |
if ( empty( $link ) ) { |
1148 |
$link = __( 'Edit This' ); |
|
1149 |
} |
|
0 | 1150 |
|
1151 |
$link = '<a href="' . get_edit_term_link( $term->term_id, $term->taxonomy ) . '">' . $link . '</a>'; |
|
5 | 1152 |
|
1153 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1154 |
* Filters the anchor tag for the edit link of a term. |
5 | 1155 |
* |
1156 |
* @since 3.1.0 |
|
1157 |
* |
|
1158 |
* @param string $link The anchor tag for the edit link. |
|
1159 |
* @param int $term_id Term ID. |
|
1160 |
*/ |
|
0 | 1161 |
$link = $before . apply_filters( 'edit_term_link', $link, $term->term_id ) . $after; |
1162 |
||
9 | 1163 |
if ( $echo ) { |
0 | 1164 |
echo $link; |
9 | 1165 |
} else { |
0 | 1166 |
return $link; |
9 | 1167 |
} |
0 | 1168 |
} |
1169 |
||
1170 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1171 |
* Retrieves the permalink for a search. |
5 | 1172 |
* |
16 | 1173 |
* @since 3.0.0 |
1174 |
* |
|
1175 |
* @global WP_Rewrite $wp_rewrite WordPress rewrite component. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1176 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1177 |
* @param string $query Optional. The query string to use. If empty the current query is used. Default empty. |
5 | 1178 |
* @return string The search permalink. |
1179 |
*/ |
|
0 | 1180 |
function get_search_link( $query = '' ) { |
1181 |
global $wp_rewrite; |
|
1182 |
||
9 | 1183 |
if ( empty( $query ) ) { |
0 | 1184 |
$search = get_search_query( false ); |
9 | 1185 |
} else { |
1186 |
$search = stripslashes( $query ); |
|
1187 |
} |
|
0 | 1188 |
|
1189 |
$permastruct = $wp_rewrite->get_search_permastruct(); |
|
1190 |
||
1191 |
if ( empty( $permastruct ) ) { |
|
9 | 1192 |
$link = home_url( '?s=' . urlencode( $search ) ); |
0 | 1193 |
} else { |
9 | 1194 |
$search = urlencode( $search ); |
1195 |
$search = str_replace( '%2F', '/', $search ); // %2F(/) is not valid within a URL, send it un-encoded. |
|
1196 |
$link = str_replace( '%search%', $search, $permastruct ); |
|
1197 |
$link = home_url( user_trailingslashit( $link, 'search' ) ); |
|
0 | 1198 |
} |
1199 |
||
5 | 1200 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1201 |
* Filters the search permalink. |
5 | 1202 |
* |
1203 |
* @since 3.0.0 |
|
1204 |
* |
|
1205 |
* @param string $link Search permalink. |
|
1206 |
* @param string $search The URL-encoded search term. |
|
1207 |
*/ |
|
0 | 1208 |
return apply_filters( 'search_link', $link, $search ); |
1209 |
} |
|
1210 |
||
1211 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1212 |
* Retrieves the permalink for the search results feed. |
0 | 1213 |
* |
1214 |
* @since 2.5.0 |
|
1215 |
* |
|
16 | 1216 |
* @global WP_Rewrite $wp_rewrite WordPress rewrite component. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1217 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1218 |
* @param string $search_query Optional. Search query. Default empty. |
16 | 1219 |
* @param string $feed Optional. Feed type. Possible values include 'rss2', 'atom'. |
1220 |
* Default is the value of get_default_feed(). |
|
5 | 1221 |
* @return string The search results feed permalink. |
0 | 1222 |
*/ |
9 | 1223 |
function get_search_feed_link( $search_query = '', $feed = '' ) { |
0 | 1224 |
global $wp_rewrite; |
9 | 1225 |
$link = get_search_link( $search_query ); |
1226 |
||
1227 |
if ( empty( $feed ) ) { |
|
0 | 1228 |
$feed = get_default_feed(); |
9 | 1229 |
} |
0 | 1230 |
|
1231 |
$permastruct = $wp_rewrite->get_search_permastruct(); |
|
1232 |
||
9 | 1233 |
if ( empty( $permastruct ) ) { |
1234 |
$link = add_query_arg( 'feed', $feed, $link ); |
|
0 | 1235 |
} else { |
9 | 1236 |
$link = trailingslashit( $link ); |
0 | 1237 |
$link .= "feed/$feed/"; |
1238 |
} |
|
1239 |
||
5 | 1240 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1241 |
* Filters the search feed link. |
5 | 1242 |
* |
1243 |
* @since 2.5.0 |
|
1244 |
* |
|
1245 |
* @param string $link Search feed link. |
|
16 | 1246 |
* @param string $feed Feed type. Possible values include 'rss2', 'atom'. |
5 | 1247 |
* @param string $type The search type. One of 'posts' or 'comments'. |
1248 |
*/ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1249 |
return apply_filters( 'search_feed_link', $link, $feed, 'posts' ); |
0 | 1250 |
} |
1251 |
||
1252 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1253 |
* Retrieves the permalink for the search results comments feed. |
0 | 1254 |
* |
1255 |
* @since 2.5.0 |
|
1256 |
* |
|
16 | 1257 |
* @global WP_Rewrite $wp_rewrite WordPress rewrite component. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1258 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1259 |
* @param string $search_query Optional. Search query. Default empty. |
16 | 1260 |
* @param string $feed Optional. Feed type. Possible values include 'rss2', 'atom'. |
1261 |
* Default is the value of get_default_feed(). |
|
5 | 1262 |
* @return string The comments feed search results permalink. |
0 | 1263 |
*/ |
9 | 1264 |
function get_search_comments_feed_link( $search_query = '', $feed = '' ) { |
0 | 1265 |
global $wp_rewrite; |
1266 |
||
9 | 1267 |
if ( empty( $feed ) ) { |
0 | 1268 |
$feed = get_default_feed(); |
9 | 1269 |
} |
1270 |
||
1271 |
$link = get_search_feed_link( $search_query, $feed ); |
|
0 | 1272 |
|
1273 |
$permastruct = $wp_rewrite->get_search_permastruct(); |
|
1274 |
||
9 | 1275 |
if ( empty( $permastruct ) ) { |
1276 |
$link = add_query_arg( 'feed', 'comments-' . $feed, $link ); |
|
1277 |
} else { |
|
1278 |
$link = add_query_arg( 'withcomments', 1, $link ); |
|
1279 |
} |
|
0 | 1280 |
|
5 | 1281 |
/** This filter is documented in wp-includes/link-template.php */ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1282 |
return apply_filters( 'search_feed_link', $link, $feed, 'comments' ); |
0 | 1283 |
} |
1284 |
||
1285 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1286 |
* Retrieves the permalink for a post type archive. |
0 | 1287 |
* |
1288 |
* @since 3.1.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1289 |
* @since 4.5.0 Support for posts was added. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1290 |
* |
16 | 1291 |
* @global WP_Rewrite $wp_rewrite WordPress rewrite component. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1292 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1293 |
* @param string $post_type Post type. |
18 | 1294 |
* @return string|false The post type archive permalink. False if the post type |
1295 |
* does not exist or does not have an archive. |
|
0 | 1296 |
*/ |
1297 |
function get_post_type_archive_link( $post_type ) { |
|
1298 |
global $wp_rewrite; |
|
16 | 1299 |
|
1300 |
$post_type_obj = get_post_type_object( $post_type ); |
|
1301 |
if ( ! $post_type_obj ) { |
|
0 | 1302 |
return false; |
9 | 1303 |
} |
0 | 1304 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1305 |
if ( 'post' === $post_type ) { |
9 | 1306 |
$show_on_front = get_option( 'show_on_front' ); |
1307 |
$page_for_posts = get_option( 'page_for_posts' ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1308 |
|
16 | 1309 |
if ( 'page' === $show_on_front && $page_for_posts ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1310 |
$link = get_permalink( $page_for_posts ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1311 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1312 |
$link = get_home_url(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1313 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1314 |
/** This filter is documented in wp-includes/link-template.php */ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1315 |
return apply_filters( 'post_type_archive_link', $link, $post_type ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1316 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1317 |
|
9 | 1318 |
if ( ! $post_type_obj->has_archive ) { |
0 | 1319 |
return false; |
9 | 1320 |
} |
0 | 1321 |
|
1322 |
if ( get_option( 'permalink_structure' ) && is_array( $post_type_obj->rewrite ) ) { |
|
1323 |
$struct = ( true === $post_type_obj->has_archive ) ? $post_type_obj->rewrite['slug'] : $post_type_obj->has_archive; |
|
9 | 1324 |
if ( $post_type_obj->rewrite['with_front'] ) { |
0 | 1325 |
$struct = $wp_rewrite->front . $struct; |
9 | 1326 |
} else { |
0 | 1327 |
$struct = $wp_rewrite->root . $struct; |
9 | 1328 |
} |
0 | 1329 |
$link = home_url( user_trailingslashit( $struct, 'post_type_archive' ) ); |
1330 |
} else { |
|
1331 |
$link = home_url( '?post_type=' . $post_type ); |
|
1332 |
} |
|
1333 |
||
5 | 1334 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1335 |
* Filters the post type archive permalink. |
5 | 1336 |
* |
1337 |
* @since 3.1.0 |
|
1338 |
* |
|
1339 |
* @param string $link The post type archive permalink. |
|
1340 |
* @param string $post_type Post type name. |
|
1341 |
*/ |
|
0 | 1342 |
return apply_filters( 'post_type_archive_link', $link, $post_type ); |
1343 |
} |
|
1344 |
||
1345 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1346 |
* Retrieves the permalink for a post type archive feed. |
0 | 1347 |
* |
1348 |
* @since 3.1.0 |
|
1349 |
* |
|
18 | 1350 |
* @param string $post_type Post type. |
16 | 1351 |
* @param string $feed Optional. Feed type. Possible values include 'rss2', 'atom'. |
1352 |
* Default is the value of get_default_feed(). |
|
18 | 1353 |
* @return string|false The post type feed permalink. False if the post type |
1354 |
* does not exist or does not have an archive. |
|
0 | 1355 |
*/ |
1356 |
function get_post_type_archive_feed_link( $post_type, $feed = '' ) { |
|
1357 |
$default_feed = get_default_feed(); |
|
9 | 1358 |
if ( empty( $feed ) ) { |
0 | 1359 |
$feed = $default_feed; |
9 | 1360 |
} |
1361 |
||
16 | 1362 |
$link = get_post_type_archive_link( $post_type ); |
1363 |
if ( ! $link ) { |
|
0 | 1364 |
return false; |
9 | 1365 |
} |
0 | 1366 |
|
1367 |
$post_type_obj = get_post_type_object( $post_type ); |
|
1368 |
if ( get_option( 'permalink_structure' ) && is_array( $post_type_obj->rewrite ) && $post_type_obj->rewrite['feeds'] ) { |
|
9 | 1369 |
$link = trailingslashit( $link ); |
0 | 1370 |
$link .= 'feed/'; |
9 | 1371 |
if ( $feed != $default_feed ) { |
0 | 1372 |
$link .= "$feed/"; |
9 | 1373 |
} |
0 | 1374 |
} else { |
1375 |
$link = add_query_arg( 'feed', $feed, $link ); |
|
1376 |
} |
|
1377 |
||
5 | 1378 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1379 |
* Filters the post type archive feed link. |
5 | 1380 |
* |
1381 |
* @since 3.1.0 |
|
1382 |
* |
|
1383 |
* @param string $link The post type archive feed link. |
|
16 | 1384 |
* @param string $feed Feed type. Possible values include 'rss2', 'atom'. |
5 | 1385 |
*/ |
0 | 1386 |
return apply_filters( 'post_type_archive_feed_link', $link, $feed ); |
1387 |
} |
|
1388 |
||
1389 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1390 |
* Retrieves the URL used for the post preview. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1391 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1392 |
* Allows additional query args to be appended. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1393 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1394 |
* @since 4.4.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1395 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1396 |
* @param int|WP_Post $post Optional. Post ID or `WP_Post` object. Defaults to global `$post`. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1397 |
* @param array $query_args Optional. Array of additional query args to be appended to the link. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1398 |
* Default empty array. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1399 |
* @param string $preview_link Optional. Base preview link to be used if it should differ from the |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1400 |
* post permalink. Default empty. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1401 |
* @return string|null URL used for the post preview, or null if the post does not exist. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1402 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1403 |
function get_preview_post_link( $post = null, $query_args = array(), $preview_link = '' ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1404 |
$post = get_post( $post ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1405 |
if ( ! $post ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1406 |
return; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1407 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1408 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1409 |
$post_type_object = get_post_type_object( $post->post_type ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1410 |
if ( is_post_type_viewable( $post_type_object ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1411 |
if ( ! $preview_link ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1412 |
$preview_link = set_url_scheme( get_permalink( $post ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1413 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1414 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1415 |
$query_args['preview'] = 'true'; |
9 | 1416 |
$preview_link = add_query_arg( $query_args, $preview_link ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1417 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1418 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1419 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1420 |
* Filters the URL used for a post preview. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1421 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1422 |
* @since 2.0.5 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1423 |
* @since 4.0.0 Added the `$post` parameter. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1424 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1425 |
* @param string $preview_link URL used for the post preview. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1426 |
* @param WP_Post $post Post object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1427 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1428 |
return apply_filters( 'preview_post_link', $preview_link, $post ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1429 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1430 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1431 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1432 |
* Retrieves the edit post link for post. |
0 | 1433 |
* |
1434 |
* Can be used within the WordPress loop or outside of it. Can be used with |
|
1435 |
* pages, posts, attachments, and revisions. |
|
1436 |
* |
|
1437 |
* @since 2.3.0 |
|
1438 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1439 |
* @param int|WP_Post $id Optional. Post ID or post object. Default is the global `$post`. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1440 |
* @param string $context Optional. How to output the '&' character. Default '&'. |
18 | 1441 |
* @return string|null The edit post link for the given post. Null if the post type does not exist |
1442 |
* or does not allow an editing UI. |
|
0 | 1443 |
*/ |
1444 |
function get_edit_post_link( $id = 0, $context = 'display' ) { |
|
16 | 1445 |
$post = get_post( $id ); |
1446 |
if ( ! $post ) { |
|
0 | 1447 |
return; |
9 | 1448 |
} |
1449 |
||
1450 |
if ( 'revision' === $post->post_type ) { |
|
0 | 1451 |
$action = ''; |
16 | 1452 |
} elseif ( 'display' === $context ) { |
0 | 1453 |
$action = '&action=edit'; |
9 | 1454 |
} else { |
0 | 1455 |
$action = '&action=edit'; |
9 | 1456 |
} |
0 | 1457 |
|
1458 |
$post_type_object = get_post_type_object( $post->post_type ); |
|
9 | 1459 |
if ( ! $post_type_object ) { |
0 | 1460 |
return; |
9 | 1461 |
} |
1462 |
||
1463 |
if ( ! current_user_can( 'edit_post', $post->ID ) ) { |
|
0 | 1464 |
return; |
9 | 1465 |
} |
0 | 1466 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1467 |
if ( $post_type_object->_edit_link ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1468 |
$link = admin_url( sprintf( $post_type_object->_edit_link . $action, $post->ID ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1469 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1470 |
$link = ''; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1471 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1472 |
|
5 | 1473 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1474 |
* Filters the post edit link. |
5 | 1475 |
* |
1476 |
* @since 2.3.0 |
|
1477 |
* |
|
1478 |
* @param string $link The edit link. |
|
1479 |
* @param int $post_id Post ID. |
|
1480 |
* @param string $context The link context. If set to 'display' then ampersands |
|
1481 |
* are encoded. |
|
1482 |
*/ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1483 |
return apply_filters( 'get_edit_post_link', $link, $post->ID, $context ); |
0 | 1484 |
} |
1485 |
||
1486 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1487 |
* Displays the edit post link for post. |
0 | 1488 |
* |
1489 |
* @since 1.0.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1490 |
* @since 4.4.0 The `$class` argument was added. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1491 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1492 |
* @param string $text Optional. Anchor text. If null, default is 'Edit This'. Default null. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1493 |
* @param string $before Optional. Display before edit link. Default empty. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1494 |
* @param string $after Optional. Display after edit link. Default empty. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1495 |
* @param int|WP_Post $id Optional. Post ID or post object. Default is the global `$post`. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1496 |
* @param string $class Optional. Add custom class to link. Default 'post-edit-link'. |
0 | 1497 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1498 |
function edit_post_link( $text = null, $before = '', $after = '', $id = 0, $class = 'post-edit-link' ) { |
16 | 1499 |
$post = get_post( $id ); |
1500 |
if ( ! $post ) { |
|
0 | 1501 |
return; |
5 | 1502 |
} |
1503 |
||
16 | 1504 |
$url = get_edit_post_link( $post->ID ); |
1505 |
if ( ! $url ) { |
|
0 | 1506 |
return; |
5 | 1507 |
} |
1508 |
||
1509 |
if ( null === $text ) { |
|
1510 |
$text = __( 'Edit This' ); |
|
1511 |
} |
|
1512 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1513 |
$link = '<a class="' . esc_attr( $class ) . '" href="' . esc_url( $url ) . '">' . $text . '</a>'; |
5 | 1514 |
|
1515 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1516 |
* Filters the post edit link anchor tag. |
5 | 1517 |
* |
1518 |
* @since 2.3.0 |
|
1519 |
* |
|
1520 |
* @param string $link Anchor tag for the edit link. |
|
1521 |
* @param int $post_id Post ID. |
|
1522 |
* @param string $text Anchor text. |
|
1523 |
*/ |
|
1524 |
echo $before . apply_filters( 'edit_post_link', $link, $post->ID, $text ) . $after; |
|
0 | 1525 |
} |
1526 |
||
1527 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1528 |
* Retrieves the delete posts link for post. |
0 | 1529 |
* |
1530 |
* Can be used within the WordPress loop or outside of it, with any post type. |
|
1531 |
* |
|
1532 |
* @since 2.9.0 |
|
1533 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1534 |
* @param int|WP_Post $id Optional. Post ID or post object. Default is the global `$post`. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1535 |
* @param string $deprecated Not used. |
16 | 1536 |
* @param bool $force_delete Optional. Whether to bypass Trash and force deletion. Default false. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1537 |
* @return string|void The delete post link URL for the given post. |
0 | 1538 |
*/ |
1539 |
function get_delete_post_link( $id = 0, $deprecated = '', $force_delete = false ) { |
|
9 | 1540 |
if ( ! empty( $deprecated ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1541 |
_deprecated_argument( __FUNCTION__, '3.0.0' ); |
9 | 1542 |
} |
1543 |
||
16 | 1544 |
$post = get_post( $id ); |
1545 |
if ( ! $post ) { |
|
0 | 1546 |
return; |
9 | 1547 |
} |
0 | 1548 |
|
1549 |
$post_type_object = get_post_type_object( $post->post_type ); |
|
9 | 1550 |
if ( ! $post_type_object ) { |
0 | 1551 |
return; |
9 | 1552 |
} |
1553 |
||
1554 |
if ( ! current_user_can( 'delete_post', $post->ID ) ) { |
|
0 | 1555 |
return; |
9 | 1556 |
} |
1557 |
||
1558 |
$action = ( $force_delete || ! EMPTY_TRASH_DAYS ) ? 'delete' : 'trash'; |
|
0 | 1559 |
|
1560 |
$delete_link = add_query_arg( 'action', $action, admin_url( sprintf( $post_type_object->_edit_link, $post->ID ) ) ); |
|
1561 |
||
5 | 1562 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1563 |
* Filters the post delete link. |
5 | 1564 |
* |
1565 |
* @since 2.9.0 |
|
1566 |
* |
|
1567 |
* @param string $link The delete link. |
|
1568 |
* @param int $post_id Post ID. |
|
16 | 1569 |
* @param bool $force_delete Whether to bypass the Trash and force deletion. Default false. |
5 | 1570 |
*/ |
0 | 1571 |
return apply_filters( 'get_delete_post_link', wp_nonce_url( $delete_link, "$action-post_{$post->ID}" ), $post->ID, $force_delete ); |
1572 |
} |
|
1573 |
||
1574 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1575 |
* Retrieves the edit comment link. |
0 | 1576 |
* |
1577 |
* @since 2.3.0 |
|
1578 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1579 |
* @param int|WP_Comment $comment_id Optional. Comment ID or WP_Comment object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1580 |
* @return string|void The edit comment link URL for the given comment. |
0 | 1581 |
*/ |
1582 |
function get_edit_comment_link( $comment_id = 0 ) { |
|
1583 |
$comment = get_comment( $comment_id ); |
|
1584 |
||
9 | 1585 |
if ( ! current_user_can( 'edit_comment', $comment->comment_ID ) ) { |
0 | 1586 |
return; |
9 | 1587 |
} |
1588 |
||
1589 |
$location = admin_url( 'comment.php?action=editcomment&c=' ) . $comment->comment_ID; |
|
5 | 1590 |
|
1591 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1592 |
* Filters the comment edit link. |
5 | 1593 |
* |
1594 |
* @since 2.3.0 |
|
1595 |
* |
|
1596 |
* @param string $location The edit link. |
|
1597 |
*/ |
|
0 | 1598 |
return apply_filters( 'get_edit_comment_link', $location ); |
1599 |
} |
|
1600 |
||
1601 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1602 |
* Displays the edit comment link with formatting. |
0 | 1603 |
* |
1604 |
* @since 1.0.0 |
|
1605 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1606 |
* @param string $text Optional. Anchor text. If null, default is 'Edit This'. Default null. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1607 |
* @param string $before Optional. Display before edit link. Default empty. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1608 |
* @param string $after Optional. Display after edit link. Default empty. |
0 | 1609 |
*/ |
5 | 1610 |
function edit_comment_link( $text = null, $before = '', $after = '' ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1611 |
$comment = get_comment(); |
0 | 1612 |
|
5 | 1613 |
if ( ! current_user_can( 'edit_comment', $comment->comment_ID ) ) { |
0 | 1614 |
return; |
5 | 1615 |
} |
1616 |
||
1617 |
if ( null === $text ) { |
|
1618 |
$text = __( 'Edit This' ); |
|
1619 |
} |
|
1620 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1621 |
$link = '<a class="comment-edit-link" href="' . esc_url( get_edit_comment_link( $comment ) ) . '">' . $text . '</a>'; |
5 | 1622 |
|
1623 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1624 |
* Filters the comment edit link anchor tag. |
5 | 1625 |
* |
1626 |
* @since 2.3.0 |
|
1627 |
* |
|
1628 |
* @param string $link Anchor tag for the edit link. |
|
19 | 1629 |
* @param string $comment_id Comment ID as a numeric string. |
5 | 1630 |
* @param string $text Anchor text. |
1631 |
*/ |
|
1632 |
echo $before . apply_filters( 'edit_comment_link', $link, $comment->comment_ID, $text ) . $after; |
|
0 | 1633 |
} |
1634 |
||
1635 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1636 |
* Displays the edit bookmark link. |
0 | 1637 |
* |
1638 |
* @since 2.7.0 |
|
1639 |
* |
|
16 | 1640 |
* @param int|stdClass $link Optional. Bookmark ID. Default is the ID of the current bookmark. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1641 |
* @return string|void The edit bookmark link URL. |
0 | 1642 |
*/ |
1643 |
function get_edit_bookmark_link( $link = 0 ) { |
|
1644 |
$link = get_bookmark( $link ); |
|
1645 |
||
9 | 1646 |
if ( ! current_user_can( 'manage_links' ) ) { |
0 | 1647 |
return; |
9 | 1648 |
} |
1649 |
||
1650 |
$location = admin_url( 'link.php?action=edit&link_id=' ) . $link->link_id; |
|
5 | 1651 |
|
1652 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1653 |
* Filters the bookmark edit link. |
5 | 1654 |
* |
1655 |
* @since 2.7.0 |
|
1656 |
* |
|
1657 |
* @param string $location The edit link. |
|
1658 |
* @param int $link_id Bookmark ID. |
|
1659 |
*/ |
|
0 | 1660 |
return apply_filters( 'get_edit_bookmark_link', $location, $link->link_id ); |
1661 |
} |
|
1662 |
||
1663 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1664 |
* Displays the edit bookmark link anchor content. |
0 | 1665 |
* |
1666 |
* @since 2.7.0 |
|
1667 |
* |
|
16 | 1668 |
* @param string $link Optional. Anchor text. If empty, default is 'Edit This'. Default empty. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1669 |
* @param string $before Optional. Display before edit link. Default empty. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1670 |
* @param string $after Optional. Display after edit link. Default empty. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1671 |
* @param int $bookmark Optional. Bookmark ID. Default is the current bookmark. |
0 | 1672 |
*/ |
1673 |
function edit_bookmark_link( $link = '', $before = '', $after = '', $bookmark = null ) { |
|
9 | 1674 |
$bookmark = get_bookmark( $bookmark ); |
1675 |
||
1676 |
if ( ! current_user_can( 'manage_links' ) ) { |
|
0 | 1677 |
return; |
9 | 1678 |
} |
1679 |
||
1680 |
if ( empty( $link ) ) { |
|
1681 |
$link = __( 'Edit This' ); |
|
1682 |
} |
|
0 | 1683 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1684 |
$link = '<a href="' . esc_url( get_edit_bookmark_link( $bookmark ) ) . '">' . $link . '</a>'; |
5 | 1685 |
|
1686 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1687 |
* Filters the bookmark edit link anchor tag. |
5 | 1688 |
* |
1689 |
* @since 2.7.0 |
|
1690 |
* |
|
1691 |
* @param string $link Anchor tag for the edit link. |
|
1692 |
* @param int $link_id Bookmark ID. |
|
1693 |
*/ |
|
0 | 1694 |
echo $before . apply_filters( 'edit_bookmark_link', $link, $bookmark->link_id ) . $after; |
1695 |
} |
|
1696 |
||
1697 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1698 |
* Retrieves the edit user link. |
0 | 1699 |
* |
1700 |
* @since 3.5.0 |
|
1701 |
* |
|
1702 |
* @param int $user_id Optional. User ID. Defaults to the current user. |
|
1703 |
* @return string URL to edit user page or empty string. |
|
1704 |
*/ |
|
1705 |
function get_edit_user_link( $user_id = null ) { |
|
9 | 1706 |
if ( ! $user_id ) { |
0 | 1707 |
$user_id = get_current_user_id(); |
9 | 1708 |
} |
1709 |
||
1710 |
if ( empty( $user_id ) || ! current_user_can( 'edit_user', $user_id ) ) { |
|
0 | 1711 |
return ''; |
9 | 1712 |
} |
0 | 1713 |
|
1714 |
$user = get_userdata( $user_id ); |
|
1715 |
||
9 | 1716 |
if ( ! $user ) { |
0 | 1717 |
return ''; |
9 | 1718 |
} |
1719 |
||
1720 |
if ( get_current_user_id() == $user->ID ) { |
|
0 | 1721 |
$link = get_edit_profile_url( $user->ID ); |
9 | 1722 |
} else { |
0 | 1723 |
$link = add_query_arg( 'user_id', $user->ID, self_admin_url( 'user-edit.php' ) ); |
9 | 1724 |
} |
0 | 1725 |
|
5 | 1726 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1727 |
* Filters the user edit link. |
5 | 1728 |
* |
1729 |
* @since 3.5.0 |
|
1730 |
* |
|
1731 |
* @param string $link The edit link. |
|
1732 |
* @param int $user_id User ID. |
|
1733 |
*/ |
|
0 | 1734 |
return apply_filters( 'get_edit_user_link', $link, $user->ID ); |
1735 |
} |
|
1736 |
||
16 | 1737 |
// |
1738 |
// Navigation links. |
|
1739 |
// |
|
0 | 1740 |
|
1741 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1742 |
* Retrieves the previous post that is adjacent to the current post. |
0 | 1743 |
* |
1744 |
* @since 1.5.0 |
|
1745 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1746 |
* @param bool $in_same_term Optional. Whether post should be in a same taxonomy term. Default false. |
18 | 1747 |
* @param int[]|string $excluded_terms Optional. Array or comma-separated list of excluded term IDs. Default empty. |
5 | 1748 |
* @param string $taxonomy Optional. Taxonomy, if $in_same_term is true. Default 'category'. |
19 | 1749 |
* @return WP_Post|null|string Post object if successful. Null if global $post is not set. Empty string if no |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1750 |
* corresponding post exists. |
0 | 1751 |
*/ |
5 | 1752 |
function get_previous_post( $in_same_term = false, $excluded_terms = '', $taxonomy = 'category' ) { |
1753 |
return get_adjacent_post( $in_same_term, $excluded_terms, true, $taxonomy ); |
|
0 | 1754 |
} |
1755 |
||
1756 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1757 |
* Retrieves the next post that is adjacent to the current post. |
0 | 1758 |
* |
1759 |
* @since 1.5.0 |
|
1760 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1761 |
* @param bool $in_same_term Optional. Whether post should be in a same taxonomy term. Default false. |
18 | 1762 |
* @param int[]|string $excluded_terms Optional. Array or comma-separated list of excluded term IDs. Default empty. |
5 | 1763 |
* @param string $taxonomy Optional. Taxonomy, if $in_same_term is true. Default 'category'. |
19 | 1764 |
* @return WP_Post|null|string Post object if successful. Null if global $post is not set. Empty string if no |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1765 |
* corresponding post exists. |
0 | 1766 |
*/ |
5 | 1767 |
function get_next_post( $in_same_term = false, $excluded_terms = '', $taxonomy = 'category' ) { |
1768 |
return get_adjacent_post( $in_same_term, $excluded_terms, false, $taxonomy ); |
|
0 | 1769 |
} |
1770 |
||
1771 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1772 |
* Retrieves the adjacent post. |
0 | 1773 |
* |
1774 |
* Can either be next or previous post. |
|
1775 |
* |
|
1776 |
* @since 2.5.0 |
|
1777 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1778 |
* @global wpdb $wpdb WordPress database abstraction object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1779 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1780 |
* @param bool $in_same_term Optional. Whether post should be in a same taxonomy term. Default false. |
18 | 1781 |
* @param int[]|string $excluded_terms Optional. Array or comma-separated list of excluded term IDs. Default empty string. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1782 |
* @param bool $previous Optional. Whether to retrieve previous post. Default true |
5 | 1783 |
* @param string $taxonomy Optional. Taxonomy, if $in_same_term is true. Default 'category'. |
19 | 1784 |
* @return WP_Post|null|string Post object if successful. Null if global $post is not set. Empty string if no |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1785 |
* corresponding post exists. |
0 | 1786 |
*/ |
5 | 1787 |
function get_adjacent_post( $in_same_term = false, $excluded_terms = '', $previous = true, $taxonomy = 'category' ) { |
0 | 1788 |
global $wpdb; |
1789 |
||
16 | 1790 |
$post = get_post(); |
1791 |
if ( ! $post || ! taxonomy_exists( $taxonomy ) ) { |
|
0 | 1792 |
return null; |
9 | 1793 |
} |
0 | 1794 |
|
1795 |
$current_post_date = $post->post_date; |
|
1796 |
||
9 | 1797 |
$join = ''; |
1798 |
$where = ''; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1799 |
$adjacent = $previous ? 'previous' : 'next'; |
5 | 1800 |
|
9 | 1801 |
if ( ! empty( $excluded_terms ) && ! is_array( $excluded_terms ) ) { |
1802 |
// Back-compat, $excluded_terms used to be $excluded_categories with IDs separated by " and ". |
|
1803 |
if ( false !== strpos( $excluded_terms, ' and ' ) ) { |
|
16 | 1804 |
_deprecated_argument( |
1805 |
__FUNCTION__, |
|
1806 |
'3.3.0', |
|
1807 |
sprintf( |
|
1808 |
/* translators: %s: The word 'and'. */ |
|
1809 |
__( 'Use commas instead of %s to separate excluded terms.' ), |
|
1810 |
"'and'" |
|
1811 |
) |
|
1812 |
); |
|
9 | 1813 |
$excluded_terms = explode( ' and ', $excluded_terms ); |
1814 |
} else { |
|
1815 |
$excluded_terms = explode( ',', $excluded_terms ); |
|
1816 |
} |
|
1817 |
||
1818 |
$excluded_terms = array_map( 'intval', $excluded_terms ); |
|
1819 |
} |
|
1820 |
||
1821 |
/** |
|
1822 |
* Filters the IDs of terms excluded from adjacent post queries. |
|
1823 |
* |
|
1824 |
* The dynamic portion of the hook name, `$adjacent`, refers to the type |
|
1825 |
* of adjacency, 'next' or 'previous'. |
|
1826 |
* |
|
18 | 1827 |
* Possible hook names include: |
1828 |
* |
|
1829 |
* - `get_next_post_excluded_terms` |
|
1830 |
* - `get_previous_post_excluded_terms` |
|
1831 |
* |
|
9 | 1832 |
* @since 4.4.0 |
1833 |
* |
|
18 | 1834 |
* @param array|string $excluded_terms Array of excluded term IDs. Empty string if none were provided. |
9 | 1835 |
*/ |
1836 |
$excluded_terms = apply_filters( "get_{$adjacent}_post_excluded_terms", $excluded_terms ); |
|
1837 |
||
5 | 1838 |
if ( $in_same_term || ! empty( $excluded_terms ) ) { |
9 | 1839 |
if ( $in_same_term ) { |
19 | 1840 |
$join .= " INNER JOIN $wpdb->term_relationships AS tr ON p.ID = tr.object_id INNER JOIN $wpdb->term_taxonomy AS tt ON tr.term_taxonomy_id = tt.term_taxonomy_id"; |
9 | 1841 |
$where .= $wpdb->prepare( 'AND tt.taxonomy = %s', $taxonomy ); |
1842 |
||
1843 |
if ( ! is_object_in_taxonomy( $post->post_type, $taxonomy ) ) { |
|
1844 |
return ''; |
|
5 | 1845 |
} |
1846 |
$term_array = wp_get_object_terms( $post->ID, $taxonomy, array( 'fields' => 'ids' ) ); |
|
1847 |
||
1848 |
// Remove any exclusions from the term array to include. |
|
1849 |
$term_array = array_diff( $term_array, (array) $excluded_terms ); |
|
1850 |
$term_array = array_map( 'intval', $term_array ); |
|
1851 |
||
9 | 1852 |
if ( ! $term_array || is_wp_error( $term_array ) ) { |
5 | 1853 |
return ''; |
9 | 1854 |
} |
1855 |
||
1856 |
$where .= ' AND tt.term_id IN (' . implode( ',', $term_array ) . ')'; |
|
5 | 1857 |
} |
1858 |
||
1859 |
if ( ! empty( $excluded_terms ) ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1860 |
$where .= " AND p.ID NOT IN ( SELECT tr.object_id FROM $wpdb->term_relationships tr LEFT JOIN $wpdb->term_taxonomy tt ON (tr.term_taxonomy_id = tt.term_taxonomy_id) WHERE tt.term_id IN (" . implode( ',', array_map( 'intval', $excluded_terms ) ) . ') )'; |
5 | 1861 |
} |
1862 |
} |
|
1863 |
||
1864 |
// 'post_status' clause depends on the current user. |
|
1865 |
if ( is_user_logged_in() ) { |
|
1866 |
$user_id = get_current_user_id(); |
|
1867 |
||
1868 |
$post_type_object = get_post_type_object( $post->post_type ); |
|
1869 |
if ( empty( $post_type_object ) ) { |
|
1870 |
$post_type_cap = $post->post_type; |
|
1871 |
$read_private_cap = 'read_private_' . $post_type_cap . 's'; |
|
1872 |
} else { |
|
1873 |
$read_private_cap = $post_type_object->cap->read_private_posts; |
|
1874 |
} |
|
1875 |
||
1876 |
/* |
|
1877 |
* Results should include private posts belonging to the current user, or private posts where the |
|
1878 |
* current user has the 'read_private_posts' cap. |
|
1879 |
*/ |
|
1880 |
$private_states = get_post_stati( array( 'private' => true ) ); |
|
9 | 1881 |
$where .= " AND ( p.post_status = 'publish'"; |
19 | 1882 |
foreach ( $private_states as $state ) { |
5 | 1883 |
if ( current_user_can( $read_private_cap ) ) { |
9 | 1884 |
$where .= $wpdb->prepare( ' OR p.post_status = %s', $state ); |
5 | 1885 |
} else { |
9 | 1886 |
$where .= $wpdb->prepare( ' OR (p.post_author = %d AND p.post_status = %s)', $user_id, $state ); |
0 | 1887 |
} |
1888 |
} |
|
9 | 1889 |
$where .= ' )'; |
5 | 1890 |
} else { |
1891 |
$where .= " AND p.post_status = 'publish'"; |
|
0 | 1892 |
} |
1893 |
||
9 | 1894 |
$op = $previous ? '<' : '>'; |
0 | 1895 |
$order = $previous ? 'DESC' : 'ASC'; |
1896 |
||
5 | 1897 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1898 |
* Filters the JOIN clause in the SQL for an adjacent post query. |
5 | 1899 |
* |
1900 |
* The dynamic portion of the hook name, `$adjacent`, refers to the type |
|
1901 |
* of adjacency, 'next' or 'previous'. |
|
1902 |
* |
|
18 | 1903 |
* Possible hook names include: |
1904 |
* |
|
1905 |
* - `get_next_post_join` |
|
1906 |
* - `get_previous_post_join` |
|
1907 |
* |
|
5 | 1908 |
* @since 2.5.0 |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1909 |
* @since 4.4.0 Added the `$taxonomy` and `$post` parameters. |
5 | 1910 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1911 |
* @param string $join The JOIN clause in the SQL. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1912 |
* @param bool $in_same_term Whether post should be in a same taxonomy term. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1913 |
* @param array $excluded_terms Array of excluded term IDs. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1914 |
* @param string $taxonomy Taxonomy. Used to identify the term used when `$in_same_term` is true. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1915 |
* @param WP_Post $post WP_Post object. |
5 | 1916 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1917 |
$join = apply_filters( "get_{$adjacent}_post_join", $join, $in_same_term, $excluded_terms, $taxonomy, $post ); |
5 | 1918 |
|
1919 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1920 |
* Filters the WHERE clause in the SQL for an adjacent post query. |
5 | 1921 |
* |
1922 |
* The dynamic portion of the hook name, `$adjacent`, refers to the type |
|
1923 |
* of adjacency, 'next' or 'previous'. |
|
1924 |
* |
|
18 | 1925 |
* Possible hook names include: |
1926 |
* |
|
1927 |
* - `get_next_post_where` |
|
1928 |
* - `get_previous_post_where` |
|
1929 |
* |
|
5 | 1930 |
* @since 2.5.0 |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1931 |
* @since 4.4.0 Added the `$taxonomy` and `$post` parameters. |
5 | 1932 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1933 |
* @param string $where The `WHERE` clause in the SQL. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1934 |
* @param bool $in_same_term Whether post should be in a same taxonomy term. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1935 |
* @param array $excluded_terms Array of excluded term IDs. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1936 |
* @param string $taxonomy Taxonomy. Used to identify the term used when `$in_same_term` is true. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1937 |
* @param WP_Post $post WP_Post object. |
5 | 1938 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1939 |
$where = apply_filters( "get_{$adjacent}_post_where", $wpdb->prepare( "WHERE p.post_date $op %s AND p.post_type = %s $where", $current_post_date, $post->post_type ), $in_same_term, $excluded_terms, $taxonomy, $post ); |
5 | 1940 |
|
1941 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1942 |
* Filters the ORDER BY clause in the SQL for an adjacent post query. |
5 | 1943 |
* |
1944 |
* The dynamic portion of the hook name, `$adjacent`, refers to the type |
|
1945 |
* of adjacency, 'next' or 'previous'. |
|
1946 |
* |
|
18 | 1947 |
* Possible hook names include: |
1948 |
* |
|
1949 |
* - `get_next_post_sort` |
|
1950 |
* - `get_previous_post_sort` |
|
1951 |
* |
|
5 | 1952 |
* @since 2.5.0 |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1953 |
* @since 4.4.0 Added the `$post` parameter. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1954 |
* @since 4.9.0 Added the `$order` parameter. |
5 | 1955 |
* |
1956 |
* @param string $order_by The `ORDER BY` clause in the SQL. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1957 |
* @param WP_Post $post WP_Post object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1958 |
* @param string $order Sort order. 'DESC' for previous post, 'ASC' for next. |
5 | 1959 |
*/ |
9 | 1960 |
$sort = apply_filters( "get_{$adjacent}_post_sort", "ORDER BY p.post_date $order LIMIT 1", $post, $order ); |
1961 |
||
1962 |
$query = "SELECT p.ID FROM $wpdb->posts AS p $join $where $sort"; |
|
5 | 1963 |
$query_key = 'adjacent_post_' . md5( $query ); |
9 | 1964 |
$result = wp_cache_get( $query_key, 'counts' ); |
0 | 1965 |
if ( false !== $result ) { |
9 | 1966 |
if ( $result ) { |
0 | 1967 |
$result = get_post( $result ); |
9 | 1968 |
} |
0 | 1969 |
return $result; |
1970 |
} |
|
1971 |
||
1972 |
$result = $wpdb->get_var( $query ); |
|
9 | 1973 |
if ( null === $result ) { |
0 | 1974 |
$result = ''; |
9 | 1975 |
} |
0 | 1976 |
|
5 | 1977 |
wp_cache_set( $query_key, $result, 'counts' ); |
0 | 1978 |
|
9 | 1979 |
if ( $result ) { |
0 | 1980 |
$result = get_post( $result ); |
9 | 1981 |
} |
0 | 1982 |
|
1983 |
return $result; |
|
1984 |
} |
|
1985 |
||
1986 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1987 |
* Retrieves the adjacent post relational link. |
0 | 1988 |
* |
1989 |
* Can either be next or previous post relational link. |
|
1990 |
* |
|
1991 |
* @since 2.8.0 |
|
1992 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1993 |
* @param string $title Optional. Link title format. Default '%title'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1994 |
* @param bool $in_same_term Optional. Whether link should be in a same taxonomy term. Default false. |
18 | 1995 |
* @param int[]|string $excluded_terms Optional. Array or comma-separated list of excluded term IDs. Default empty. |
5 | 1996 |
* @param bool $previous Optional. Whether to display link to previous or next post. Default true. |
1997 |
* @param string $taxonomy Optional. Taxonomy, if $in_same_term is true. Default 'category'. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1998 |
* @return string|void The adjacent post relational link URL. |
0 | 1999 |
*/ |
5 | 2000 |
function get_adjacent_post_rel_link( $title = '%title', $in_same_term = false, $excluded_terms = '', $previous = true, $taxonomy = 'category' ) { |
16 | 2001 |
$post = get_post(); |
2002 |
if ( $previous && is_attachment() && $post ) { |
|
0 | 2003 |
$post = get_post( $post->post_parent ); |
9 | 2004 |
} else { |
5 | 2005 |
$post = get_adjacent_post( $in_same_term, $excluded_terms, $previous, $taxonomy ); |
9 | 2006 |
} |
2007 |
||
2008 |
if ( empty( $post ) ) { |
|
0 | 2009 |
return; |
9 | 2010 |
} |
2011 |
||
2012 |
$post_title = the_title_attribute( |
|
2013 |
array( |
|
2014 |
'echo' => false, |
|
2015 |
'post' => $post, |
|
2016 |
) |
|
2017 |
); |
|
2018 |
||
2019 |
if ( empty( $post_title ) ) { |
|
5 | 2020 |
$post_title = $previous ? __( 'Previous Post' ) : __( 'Next Post' ); |
9 | 2021 |
} |
5 | 2022 |
|
2023 |
$date = mysql2date( get_option( 'date_format' ), $post->post_date ); |
|
2024 |
||
2025 |
$title = str_replace( '%title', $post_title, $title ); |
|
2026 |
$title = str_replace( '%date', $date, $title ); |
|
0 | 2027 |
|
9 | 2028 |
$link = $previous ? "<link rel='prev' title='" : "<link rel='next' title='"; |
0 | 2029 |
$link .= esc_attr( $title ); |
5 | 2030 |
$link .= "' href='" . get_permalink( $post ) . "' />\n"; |
0 | 2031 |
|
2032 |
$adjacent = $previous ? 'previous' : 'next'; |
|
5 | 2033 |
|
2034 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2035 |
* Filters the adjacent post relational link. |
5 | 2036 |
* |
2037 |
* The dynamic portion of the hook name, `$adjacent`, refers to the type |
|
2038 |
* of adjacency, 'next' or 'previous'. |
|
2039 |
* |
|
18 | 2040 |
* Possible hook names include: |
2041 |
* |
|
2042 |
* - `next_post_rel_link` |
|
2043 |
* - `previous_post_rel_link` |
|
2044 |
* |
|
5 | 2045 |
* @since 2.8.0 |
2046 |
* |
|
2047 |
* @param string $link The relational link. |
|
2048 |
*/ |
|
0 | 2049 |
return apply_filters( "{$adjacent}_post_rel_link", $link ); |
2050 |
} |
|
2051 |
||
2052 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2053 |
* Displays the relational links for the posts adjacent to the current post. |
0 | 2054 |
* |
2055 |
* @since 2.8.0 |
|
2056 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2057 |
* @param string $title Optional. Link title format. Default '%title'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2058 |
* @param bool $in_same_term Optional. Whether link should be in a same taxonomy term. Default false. |
18 | 2059 |
* @param int[]|string $excluded_terms Optional. Array or comma-separated list of excluded term IDs. Default empty. |
5 | 2060 |
* @param string $taxonomy Optional. Taxonomy, if $in_same_term is true. Default 'category'. |
0 | 2061 |
*/ |
5 | 2062 |
function adjacent_posts_rel_link( $title = '%title', $in_same_term = false, $excluded_terms = '', $taxonomy = 'category' ) { |
2063 |
echo get_adjacent_post_rel_link( $title, $in_same_term, $excluded_terms, true, $taxonomy ); |
|
2064 |
echo get_adjacent_post_rel_link( $title, $in_same_term, $excluded_terms, false, $taxonomy ); |
|
0 | 2065 |
} |
2066 |
||
2067 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2068 |
* Displays relational links for the posts adjacent to the current post for single post pages. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2069 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2070 |
* This is meant to be attached to actions like 'wp_head'. Do not call this directly in plugins |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2071 |
* or theme templates. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2072 |
* |
0 | 2073 |
* @since 3.0.0 |
18 | 2074 |
* @since 5.6.0 No longer used in core. |
0 | 2075 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2076 |
* @see adjacent_posts_rel_link() |
0 | 2077 |
*/ |
2078 |
function adjacent_posts_rel_link_wp_head() { |
|
5 | 2079 |
if ( ! is_single() || is_attachment() ) { |
0 | 2080 |
return; |
5 | 2081 |
} |
0 | 2082 |
adjacent_posts_rel_link(); |
2083 |
} |
|
2084 |
||
2085 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2086 |
* Displays the relational link for the next post adjacent to the current post. |
0 | 2087 |
* |
2088 |
* @since 2.8.0 |
|
2089 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2090 |
* @see get_adjacent_post_rel_link() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2091 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2092 |
* @param string $title Optional. Link title format. Default '%title'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2093 |
* @param bool $in_same_term Optional. Whether link should be in a same taxonomy term. Default false. |
18 | 2094 |
* @param int[]|string $excluded_terms Optional. Array or comma-separated list of excluded term IDs. Default empty. |
5 | 2095 |
* @param string $taxonomy Optional. Taxonomy, if $in_same_term is true. Default 'category'. |
0 | 2096 |
*/ |
5 | 2097 |
function next_post_rel_link( $title = '%title', $in_same_term = false, $excluded_terms = '', $taxonomy = 'category' ) { |
2098 |
echo get_adjacent_post_rel_link( $title, $in_same_term, $excluded_terms, false, $taxonomy ); |
|
0 | 2099 |
} |
2100 |
||
2101 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2102 |
* Displays the relational link for the previous post adjacent to the current post. |
0 | 2103 |
* |
2104 |
* @since 2.8.0 |
|
2105 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2106 |
* @see get_adjacent_post_rel_link() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2107 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2108 |
* @param string $title Optional. Link title format. Default '%title'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2109 |
* @param bool $in_same_term Optional. Whether link should be in a same taxonomy term. Default false. |
18 | 2110 |
* @param int[]|string $excluded_terms Optional. Array or comma-separated list of excluded term IDs. Default true. |
5 | 2111 |
* @param string $taxonomy Optional. Taxonomy, if $in_same_term is true. Default 'category'. |
0 | 2112 |
*/ |
5 | 2113 |
function prev_post_rel_link( $title = '%title', $in_same_term = false, $excluded_terms = '', $taxonomy = 'category' ) { |
2114 |
echo get_adjacent_post_rel_link( $title, $in_same_term, $excluded_terms, true, $taxonomy ); |
|
0 | 2115 |
} |
2116 |
||
2117 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2118 |
* Retrieves the boundary post. |
0 | 2119 |
* |
2120 |
* Boundary being either the first or last post by publish date within the constraints specified |
|
5 | 2121 |
* by $in_same_term or $excluded_terms. |
0 | 2122 |
* |
2123 |
* @since 2.8.0 |
|
2124 |
* |
|
5 | 2125 |
* @param bool $in_same_term Optional. Whether returned post should be in a same taxonomy term. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2126 |
* Default false. |
18 | 2127 |
* @param int[]|string $excluded_terms Optional. Array or comma-separated list of excluded term IDs. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2128 |
* Default empty. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2129 |
* @param bool $start Optional. Whether to retrieve first or last post. Default true |
5 | 2130 |
* @param string $taxonomy Optional. Taxonomy, if $in_same_term is true. Default 'category'. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2131 |
* @return null|array Array containing the boundary post object if successful, null otherwise. |
0 | 2132 |
*/ |
5 | 2133 |
function get_boundary_post( $in_same_term = false, $excluded_terms = '', $start = true, $taxonomy = 'category' ) { |
0 | 2134 |
$post = get_post(); |
9 | 2135 |
if ( ! $post || ! is_single() || is_attachment() || ! taxonomy_exists( $taxonomy ) ) { |
0 | 2136 |
return null; |
9 | 2137 |
} |
0 | 2138 |
|
5 | 2139 |
$query_args = array( |
9 | 2140 |
'posts_per_page' => 1, |
2141 |
'order' => $start ? 'ASC' : 'DESC', |
|
5 | 2142 |
'update_post_term_cache' => false, |
9 | 2143 |
'update_post_meta_cache' => false, |
5 | 2144 |
); |
2145 |
||
2146 |
$term_array = array(); |
|
2147 |
||
2148 |
if ( ! is_array( $excluded_terms ) ) { |
|
9 | 2149 |
if ( ! empty( $excluded_terms ) ) { |
5 | 2150 |
$excluded_terms = explode( ',', $excluded_terms ); |
9 | 2151 |
} else { |
5 | 2152 |
$excluded_terms = array(); |
9 | 2153 |
} |
5 | 2154 |
} |
2155 |
||
2156 |
if ( $in_same_term || ! empty( $excluded_terms ) ) { |
|
9 | 2157 |
if ( $in_same_term ) { |
5 | 2158 |
$term_array = wp_get_object_terms( $post->ID, $taxonomy, array( 'fields' => 'ids' ) ); |
9 | 2159 |
} |
5 | 2160 |
|
2161 |
if ( ! empty( $excluded_terms ) ) { |
|
2162 |
$excluded_terms = array_map( 'intval', $excluded_terms ); |
|
2163 |
$excluded_terms = array_diff( $excluded_terms, $term_array ); |
|
2164 |
||
2165 |
$inverse_terms = array(); |
|
9 | 2166 |
foreach ( $excluded_terms as $excluded_term ) { |
5 | 2167 |
$inverse_terms[] = $excluded_term * -1; |
9 | 2168 |
} |
5 | 2169 |
$excluded_terms = $inverse_terms; |
0 | 2170 |
} |
5 | 2171 |
|
9 | 2172 |
$query_args['tax_query'] = array( |
2173 |
array( |
|
2174 |
'taxonomy' => $taxonomy, |
|
2175 |
'terms' => array_merge( $term_array, $excluded_terms ), |
|
2176 |
), |
|
2177 |
); |
|
0 | 2178 |
} |
2179 |
||
5 | 2180 |
return get_posts( $query_args ); |
0 | 2181 |
} |
2182 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2183 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2184 |
* Retrieves the previous post link that is adjacent to the current post. |
0 | 2185 |
* |
2186 |
* @since 3.7.0 |
|
2187 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2188 |
* @param string $format Optional. Link anchor format. Default '« %link'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2189 |
* @param string $link Optional. Link permalink format. Default '%title'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2190 |
* @param bool $in_same_term Optional. Whether link should be in a same taxonomy term. Default false. |
18 | 2191 |
* @param int[]|string $excluded_terms Optional. Array or comma-separated list of excluded term IDs. Default empty. |
5 | 2192 |
* @param string $taxonomy Optional. Taxonomy, if $in_same_term is true. Default 'category'. |
2193 |
* @return string The link URL of the previous post in relation to the current post. |
|
0 | 2194 |
*/ |
5 | 2195 |
function get_previous_post_link( $format = '« %link', $link = '%title', $in_same_term = false, $excluded_terms = '', $taxonomy = 'category' ) { |
2196 |
return get_adjacent_post_link( $format, $link, $in_same_term, $excluded_terms, true, $taxonomy ); |
|
0 | 2197 |
} |
2198 |
||
2199 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2200 |
* Displays the previous post link that is adjacent to the current post. |
0 | 2201 |
* |
2202 |
* @since 1.5.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2203 |
* |
5 | 2204 |
* @see get_previous_post_link() |
0 | 2205 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2206 |
* @param string $format Optional. Link anchor format. Default '« %link'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2207 |
* @param string $link Optional. Link permalink format. Default '%title'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2208 |
* @param bool $in_same_term Optional. Whether link should be in a same taxonomy term. Default false. |
18 | 2209 |
* @param int[]|string $excluded_terms Optional. Array or comma-separated list of excluded term IDs. Default empty. |
5 | 2210 |
* @param string $taxonomy Optional. Taxonomy, if $in_same_term is true. Default 'category'. |
0 | 2211 |
*/ |
5 | 2212 |
function previous_post_link( $format = '« %link', $link = '%title', $in_same_term = false, $excluded_terms = '', $taxonomy = 'category' ) { |
2213 |
echo get_previous_post_link( $format, $link, $in_same_term, $excluded_terms, $taxonomy ); |
|
0 | 2214 |
} |
2215 |
||
2216 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2217 |
* Retrieves the next post link that is adjacent to the current post. |
0 | 2218 |
* |
2219 |
* @since 3.7.0 |
|
2220 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2221 |
* @param string $format Optional. Link anchor format. Default '« %link'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2222 |
* @param string $link Optional. Link permalink format. Default '%title'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2223 |
* @param bool $in_same_term Optional. Whether link should be in a same taxonomy term. Default false. |
18 | 2224 |
* @param int[]|string $excluded_terms Optional. Array or comma-separated list of excluded term IDs. Default empty. |
5 | 2225 |
* @param string $taxonomy Optional. Taxonomy, if $in_same_term is true. Default 'category'. |
2226 |
* @return string The link URL of the next post in relation to the current post. |
|
0 | 2227 |
*/ |
5 | 2228 |
function get_next_post_link( $format = '%link »', $link = '%title', $in_same_term = false, $excluded_terms = '', $taxonomy = 'category' ) { |
2229 |
return get_adjacent_post_link( $format, $link, $in_same_term, $excluded_terms, false, $taxonomy ); |
|
0 | 2230 |
} |
2231 |
||
2232 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2233 |
* Displays the next post link that is adjacent to the current post. |
0 | 2234 |
* |
2235 |
* @since 1.5.0 |
|
16 | 2236 |
* |
5 | 2237 |
* @see get_next_post_link() |
0 | 2238 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2239 |
* @param string $format Optional. Link anchor format. Default '« %link'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2240 |
* @param string $link Optional. Link permalink format. Default '%title' |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2241 |
* @param bool $in_same_term Optional. Whether link should be in a same taxonomy term. Default false. |
18 | 2242 |
* @param int[]|string $excluded_terms Optional. Array or comma-separated list of excluded term IDs. Default empty. |
5 | 2243 |
* @param string $taxonomy Optional. Taxonomy, if $in_same_term is true. Default 'category'. |
0 | 2244 |
*/ |
5 | 2245 |
function next_post_link( $format = '%link »', $link = '%title', $in_same_term = false, $excluded_terms = '', $taxonomy = 'category' ) { |
9 | 2246 |
echo get_next_post_link( $format, $link, $in_same_term, $excluded_terms, $taxonomy ); |
0 | 2247 |
} |
2248 |
||
2249 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2250 |
* Retrieves the adjacent post link. |
0 | 2251 |
* |
2252 |
* Can be either next post link or previous. |
|
2253 |
* |
|
2254 |
* @since 3.7.0 |
|
2255 |
* |
|
5 | 2256 |
* @param string $format Link anchor format. |
2257 |
* @param string $link Link permalink format. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2258 |
* @param bool $in_same_term Optional. Whether link should be in a same taxonomy term. Default false. |
18 | 2259 |
* @param int[]|string $excluded_terms Optional. Array or comma-separated list of excluded terms IDs. Default empty. |
5 | 2260 |
* @param bool $previous Optional. Whether to display link to previous or next post. Default true. |
2261 |
* @param string $taxonomy Optional. Taxonomy, if $in_same_term is true. Default 'category'. |
|
2262 |
* @return string The link URL of the previous or next post in relation to the current post. |
|
0 | 2263 |
*/ |
5 | 2264 |
function get_adjacent_post_link( $format, $link, $in_same_term = false, $excluded_terms = '', $previous = true, $taxonomy = 'category' ) { |
9 | 2265 |
if ( $previous && is_attachment() ) { |
0 | 2266 |
$post = get_post( get_post()->post_parent ); |
9 | 2267 |
} else { |
5 | 2268 |
$post = get_adjacent_post( $in_same_term, $excluded_terms, $previous, $taxonomy ); |
9 | 2269 |
} |
0 | 2270 |
|
2271 |
if ( ! $post ) { |
|
2272 |
$output = ''; |
|
2273 |
} else { |
|
2274 |
$title = $post->post_title; |
|
2275 |
||
9 | 2276 |
if ( empty( $post->post_title ) ) { |
0 | 2277 |
$title = $previous ? __( 'Previous Post' ) : __( 'Next Post' ); |
9 | 2278 |
} |
0 | 2279 |
|
2280 |
/** This filter is documented in wp-includes/post-template.php */ |
|
2281 |
$title = apply_filters( 'the_title', $title, $post->ID ); |
|
5 | 2282 |
|
0 | 2283 |
$date = mysql2date( get_option( 'date_format' ), $post->post_date ); |
9 | 2284 |
$rel = $previous ? 'prev' : 'next'; |
2285 |
||
2286 |
$string = '<a href="' . get_permalink( $post ) . '" rel="' . $rel . '">'; |
|
0 | 2287 |
$inlink = str_replace( '%title', $title, $link ); |
2288 |
$inlink = str_replace( '%date', $date, $inlink ); |
|
2289 |
$inlink = $string . $inlink . '</a>'; |
|
2290 |
||
2291 |
$output = str_replace( '%link', $inlink, $format ); |
|
2292 |
} |
|
2293 |
||
2294 |
$adjacent = $previous ? 'previous' : 'next'; |
|
2295 |
||
5 | 2296 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2297 |
* Filters the adjacent post link. |
5 | 2298 |
* |
2299 |
* The dynamic portion of the hook name, `$adjacent`, refers to the type |
|
2300 |
* of adjacency, 'next' or 'previous'. |
|
2301 |
* |
|
18 | 2302 |
* Possible hook names include: |
2303 |
* |
|
2304 |
* - `next_post_link` |
|
2305 |
* - `previous_post_link` |
|
2306 |
* |
|
5 | 2307 |
* @since 2.6.0 |
2308 |
* @since 4.2.0 Added the `$adjacent` parameter. |
|
2309 |
* |
|
2310 |
* @param string $output The adjacent post link. |
|
2311 |
* @param string $format Link anchor format. |
|
2312 |
* @param string $link Link permalink format. |
|
2313 |
* @param WP_Post $post The adjacent post. |
|
2314 |
* @param string $adjacent Whether the post is previous or next. |
|
2315 |
*/ |
|
2316 |
return apply_filters( "{$adjacent}_post_link", $output, $format, $link, $post, $adjacent ); |
|
0 | 2317 |
} |
2318 |
||
2319 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2320 |
* Displays the adjacent post link. |
0 | 2321 |
* |
2322 |
* Can be either next post link or previous. |
|
2323 |
* |
|
2324 |
* @since 2.5.0 |
|
2325 |
* |
|
5 | 2326 |
* @param string $format Link anchor format. |
2327 |
* @param string $link Link permalink format. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2328 |
* @param bool $in_same_term Optional. Whether link should be in a same taxonomy term. Default false. |
18 | 2329 |
* @param int[]|string $excluded_terms Optional. Array or comma-separated list of excluded category IDs. Default empty. |
5 | 2330 |
* @param bool $previous Optional. Whether to display link to previous or next post. Default true. |
2331 |
* @param string $taxonomy Optional. Taxonomy, if $in_same_term is true. Default 'category'. |
|
0 | 2332 |
*/ |
5 | 2333 |
function adjacent_post_link( $format, $link, $in_same_term = false, $excluded_terms = '', $previous = true, $taxonomy = 'category' ) { |
2334 |
echo get_adjacent_post_link( $format, $link, $in_same_term, $excluded_terms, $previous, $taxonomy ); |
|
0 | 2335 |
} |
2336 |
||
2337 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2338 |
* Retrieves the link for a page number. |
0 | 2339 |
* |
2340 |
* @since 1.5.0 |
|
2341 |
* |
|
16 | 2342 |
* @global WP_Rewrite $wp_rewrite WordPress rewrite component. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2343 |
* |
9 | 2344 |
* @param int $pagenum Optional. Page number. Default 1. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2345 |
* @param bool $escape Optional. Whether to escape the URL for display, with esc_url(). Defaults to true. |
9 | 2346 |
* Otherwise, prepares the URL with esc_url_raw(). |
5 | 2347 |
* @return string The link URL for the given page number. |
0 | 2348 |
*/ |
9 | 2349 |
function get_pagenum_link( $pagenum = 1, $escape = true ) { |
0 | 2350 |
global $wp_rewrite; |
2351 |
||
2352 |
$pagenum = (int) $pagenum; |
|
2353 |
||
2354 |
$request = remove_query_arg( 'paged' ); |
|
2355 |
||
9 | 2356 |
$home_root = parse_url( home_url() ); |
2357 |
$home_root = ( isset( $home_root['path'] ) ) ? $home_root['path'] : ''; |
|
0 | 2358 |
$home_root = preg_quote( $home_root, '|' ); |
2359 |
||
9 | 2360 |
$request = preg_replace( '|^' . $home_root . '|i', '', $request ); |
2361 |
$request = preg_replace( '|^/+|', '', $request ); |
|
2362 |
||
2363 |
if ( ! $wp_rewrite->using_permalinks() || is_admin() ) { |
|
0 | 2364 |
$base = trailingslashit( get_bloginfo( 'url' ) ); |
2365 |
||
2366 |
if ( $pagenum > 1 ) { |
|
2367 |
$result = add_query_arg( 'paged', $pagenum, $base . $request ); |
|
2368 |
} else { |
|
2369 |
$result = $base . $request; |
|
2370 |
} |
|
2371 |
} else { |
|
2372 |
$qs_regex = '|\?.*?$|'; |
|
2373 |
preg_match( $qs_regex, $request, $qs_match ); |
|
2374 |
||
9 | 2375 |
if ( ! empty( $qs_match[0] ) ) { |
0 | 2376 |
$query_string = $qs_match[0]; |
9 | 2377 |
$request = preg_replace( $qs_regex, '', $request ); |
0 | 2378 |
} else { |
2379 |
$query_string = ''; |
|
2380 |
} |
|
2381 |
||
9 | 2382 |
$request = preg_replace( "|$wp_rewrite->pagination_base/\d+/?$|", '', $request ); |
2383 |
$request = preg_replace( '|^' . preg_quote( $wp_rewrite->index, '|' ) . '|i', '', $request ); |
|
2384 |
$request = ltrim( $request, '/' ); |
|
0 | 2385 |
|
2386 |
$base = trailingslashit( get_bloginfo( 'url' ) ); |
|
2387 |
||
16 | 2388 |
if ( $wp_rewrite->using_index_permalinks() && ( $pagenum > 1 || '' !== $request ) ) { |
0 | 2389 |
$base .= $wp_rewrite->index . '/'; |
9 | 2390 |
} |
0 | 2391 |
|
2392 |
if ( $pagenum > 1 ) { |
|
9 | 2393 |
$request = ( ( ! empty( $request ) ) ? trailingslashit( $request ) : $request ) . user_trailingslashit( $wp_rewrite->pagination_base . '/' . $pagenum, 'paged' ); |
0 | 2394 |
} |
2395 |
||
2396 |
$result = $base . $request . $query_string; |
|
2397 |
} |
|
2398 |
||
5 | 2399 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2400 |
* Filters the page number link for the current request. |
5 | 2401 |
* |
2402 |
* @since 2.5.0 |
|
9 | 2403 |
* @since 5.2.0 Added the `$pagenum` argument. |
5 | 2404 |
* |
9 | 2405 |
* @param string $result The page number link. |
2406 |
* @param int $pagenum The page number. |
|
5 | 2407 |
*/ |
9 | 2408 |
$result = apply_filters( 'get_pagenum_link', $result, $pagenum ); |
2409 |
||
2410 |
if ( $escape ) { |
|
0 | 2411 |
return esc_url( $result ); |
9 | 2412 |
} else { |
0 | 2413 |
return esc_url_raw( $result ); |
9 | 2414 |
} |
0 | 2415 |
} |
2416 |
||
2417 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2418 |
* Retrieves the next posts page link. |
0 | 2419 |
* |
2420 |
* Backported from 2.1.3 to 2.0.10. |
|
2421 |
* |
|
2422 |
* @since 2.0.10 |
|
2423 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2424 |
* @global int $paged |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2425 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2426 |
* @param int $max_page Optional. Max pages. Default 0. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2427 |
* @return string|void The link URL for next posts page. |
0 | 2428 |
*/ |
9 | 2429 |
function get_next_posts_page_link( $max_page = 0 ) { |
0 | 2430 |
global $paged; |
2431 |
||
9 | 2432 |
if ( ! is_single() ) { |
2433 |
if ( ! $paged ) { |
|
0 | 2434 |
$paged = 1; |
9 | 2435 |
} |
18 | 2436 |
$nextpage = (int) $paged + 1; |
9 | 2437 |
if ( ! $max_page || $max_page >= $nextpage ) { |
2438 |
return get_pagenum_link( $nextpage ); |
|
2439 |
} |
|
0 | 2440 |
} |
2441 |
} |
|
2442 |
||
2443 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2444 |
* Displays or retrieves the next posts page link. |
0 | 2445 |
* |
2446 |
* @since 0.71 |
|
2447 |
* |
|
16 | 2448 |
* @param int $max_page Optional. Max pages. Default 0. |
2449 |
* @param bool $echo Optional. Whether to echo the link. Default true. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2450 |
* @return string|void The link URL for next posts page if `$echo = false`. |
0 | 2451 |
*/ |
2452 |
function next_posts( $max_page = 0, $echo = true ) { |
|
2453 |
$output = esc_url( get_next_posts_page_link( $max_page ) ); |
|
2454 |
||
9 | 2455 |
if ( $echo ) { |
0 | 2456 |
echo $output; |
9 | 2457 |
} else { |
0 | 2458 |
return $output; |
9 | 2459 |
} |
0 | 2460 |
} |
2461 |
||
2462 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2463 |
* Retrieves the next posts page link. |
0 | 2464 |
* |
2465 |
* @since 2.7.0 |
|
2466 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2467 |
* @global int $paged |
16 | 2468 |
* @global WP_Query $wp_query WordPress Query object. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2469 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2470 |
* @param string $label Content for link text. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2471 |
* @param int $max_page Optional. Max pages. Default 0. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2472 |
* @return string|void HTML-formatted next posts page link. |
0 | 2473 |
*/ |
2474 |
function get_next_posts_link( $label = null, $max_page = 0 ) { |
|
2475 |
global $paged, $wp_query; |
|
2476 |
||
9 | 2477 |
if ( ! $max_page ) { |
0 | 2478 |
$max_page = $wp_query->max_num_pages; |
9 | 2479 |
} |
2480 |
||
2481 |
if ( ! $paged ) { |
|
0 | 2482 |
$paged = 1; |
9 | 2483 |
} |
2484 |
||
18 | 2485 |
$nextpage = (int) $paged + 1; |
9 | 2486 |
|
2487 |
if ( null === $label ) { |
|
0 | 2488 |
$label = __( 'Next Page »' ); |
9 | 2489 |
} |
2490 |
||
2491 |
if ( ! is_single() && ( $nextpage <= $max_page ) ) { |
|
5 | 2492 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2493 |
* Filters the anchor tag attributes for the next posts page link. |
5 | 2494 |
* |
2495 |
* @since 2.7.0 |
|
2496 |
* |
|
2497 |
* @param string $attributes Attributes for the anchor tag. |
|
2498 |
*/ |
|
0 | 2499 |
$attr = apply_filters( 'next_posts_link_attributes', '' ); |
5 | 2500 |
|
9 | 2501 |
return '<a href="' . next_posts( $max_page, false ) . "\" $attr>" . preg_replace( '/&([^#])(?![a-z]{1,8};)/i', '&$1', $label ) . '</a>'; |
0 | 2502 |
} |
2503 |
} |
|
2504 |
||
2505 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2506 |
* Displays the next posts page link. |
0 | 2507 |
* |
2508 |
* @since 0.71 |
|
2509 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2510 |
* @param string $label Content for link text. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2511 |
* @param int $max_page Optional. Max pages. Default 0. |
0 | 2512 |
*/ |
2513 |
function next_posts_link( $label = null, $max_page = 0 ) { |
|
2514 |
echo get_next_posts_link( $label, $max_page ); |
|
2515 |
} |
|
2516 |
||
2517 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2518 |
* Retrieves the previous posts page link. |
0 | 2519 |
* |
2520 |
* Will only return string, if not on a single page or post. |
|
2521 |
* |
|
2522 |
* Backported to 2.0.10 from 2.1.3. |
|
2523 |
* |
|
2524 |
* @since 2.0.10 |
|
2525 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2526 |
* @global int $paged |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2527 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2528 |
* @return string|void The link for the previous posts page. |
0 | 2529 |
*/ |
2530 |
function get_previous_posts_page_link() { |
|
2531 |
global $paged; |
|
2532 |
||
9 | 2533 |
if ( ! is_single() ) { |
18 | 2534 |
$nextpage = (int) $paged - 1; |
9 | 2535 |
if ( $nextpage < 1 ) { |
0 | 2536 |
$nextpage = 1; |
9 | 2537 |
} |
2538 |
return get_pagenum_link( $nextpage ); |
|
0 | 2539 |
} |
2540 |
} |
|
2541 |
||
2542 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2543 |
* Displays or retrieves the previous posts page link. |
0 | 2544 |
* |
2545 |
* @since 0.71 |
|
2546 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2547 |
* @param bool $echo Optional. Whether to echo the link. Default true. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2548 |
* @return string|void The previous posts page link if `$echo = false`. |
0 | 2549 |
*/ |
2550 |
function previous_posts( $echo = true ) { |
|
2551 |
$output = esc_url( get_previous_posts_page_link() ); |
|
2552 |
||
9 | 2553 |
if ( $echo ) { |
0 | 2554 |
echo $output; |
9 | 2555 |
} else { |
0 | 2556 |
return $output; |
9 | 2557 |
} |
0 | 2558 |
} |
2559 |
||
2560 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2561 |
* Retrieves the previous posts page link. |
0 | 2562 |
* |
2563 |
* @since 2.7.0 |
|
2564 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2565 |
* @global int $paged |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2566 |
* |
0 | 2567 |
* @param string $label Optional. Previous page link text. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2568 |
* @return string|void HTML-formatted previous page link. |
0 | 2569 |
*/ |
2570 |
function get_previous_posts_link( $label = null ) { |
|
2571 |
global $paged; |
|
2572 |
||
9 | 2573 |
if ( null === $label ) { |
0 | 2574 |
$label = __( '« Previous Page' ); |
9 | 2575 |
} |
2576 |
||
2577 |
if ( ! is_single() && $paged > 1 ) { |
|
5 | 2578 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2579 |
* Filters the anchor tag attributes for the previous posts page link. |
5 | 2580 |
* |
2581 |
* @since 2.7.0 |
|
2582 |
* |
|
2583 |
* @param string $attributes Attributes for the anchor tag. |
|
2584 |
*/ |
|
0 | 2585 |
$attr = apply_filters( 'previous_posts_link_attributes', '' ); |
9 | 2586 |
return '<a href="' . previous_posts( false ) . "\" $attr>" . preg_replace( '/&([^#])(?![a-z]{1,8};)/i', '&$1', $label ) . '</a>'; |
0 | 2587 |
} |
2588 |
} |
|
2589 |
||
2590 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2591 |
* Displays the previous posts page link. |
0 | 2592 |
* |
2593 |
* @since 0.71 |
|
2594 |
* |
|
2595 |
* @param string $label Optional. Previous page link text. |
|
2596 |
*/ |
|
2597 |
function previous_posts_link( $label = null ) { |
|
2598 |
echo get_previous_posts_link( $label ); |
|
2599 |
} |
|
2600 |
||
2601 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2602 |
* Retrieves the post pages link navigation for previous and next pages. |
0 | 2603 |
* |
5 | 2604 |
* @since 2.8.0 |
0 | 2605 |
* |
16 | 2606 |
* @global WP_Query $wp_query WordPress Query object. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2607 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2608 |
* @param string|array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2609 |
* Optional. Arguments to build the post pages link navigation. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2610 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2611 |
* @type string $sep Separator character. Default '—'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2612 |
* @type string $prelabel Link text to display for the previous page link. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2613 |
* Default '« Previous Page'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2614 |
* @type string $nxtlabel Link text to display for the next page link. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2615 |
* Default 'Next Page »'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2616 |
* } |
0 | 2617 |
* @return string The posts link navigation. |
2618 |
*/ |
|
2619 |
function get_posts_nav_link( $args = array() ) { |
|
2620 |
global $wp_query; |
|
2621 |
||
2622 |
$return = ''; |
|
2623 |
||
9 | 2624 |
if ( ! is_singular() ) { |
0 | 2625 |
$defaults = array( |
9 | 2626 |
'sep' => ' — ', |
2627 |
'prelabel' => __( '« Previous Page' ), |
|
2628 |
'nxtlabel' => __( 'Next Page »' ), |
|
0 | 2629 |
); |
9 | 2630 |
$args = wp_parse_args( $args, $defaults ); |
0 | 2631 |
|
2632 |
$max_num_pages = $wp_query->max_num_pages; |
|
9 | 2633 |
$paged = get_query_var( 'paged' ); |
0 | 2634 |
|
16 | 2635 |
// Only have sep if there's both prev and next results. |
9 | 2636 |
if ( $paged < 2 || $paged >= $max_num_pages ) { |
0 | 2637 |
$args['sep'] = ''; |
2638 |
} |
|
2639 |
||
2640 |
if ( $max_num_pages > 1 ) { |
|
9 | 2641 |
$return = get_previous_posts_link( $args['prelabel'] ); |
2642 |
$return .= preg_replace( '/&([^#])(?![a-z]{1,8};)/i', '&$1', $args['sep'] ); |
|
2643 |
$return .= get_next_posts_link( $args['nxtlabel'] ); |
|
0 | 2644 |
} |
2645 |
} |
|
2646 |
return $return; |
|
2647 |
||
2648 |
} |
|
2649 |
||
2650 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2651 |
* Displays the post pages link navigation for previous and next pages. |
0 | 2652 |
* |
2653 |
* @since 0.71 |
|
2654 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2655 |
* @param string $sep Optional. Separator for posts navigation links. Default empty. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2656 |
* @param string $prelabel Optional. Label for previous pages. Default empty. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2657 |
* @param string $nxtlabel Optional Label for next pages. Default empty. |
0 | 2658 |
*/ |
2659 |
function posts_nav_link( $sep = '', $prelabel = '', $nxtlabel = '' ) { |
|
9 | 2660 |
$args = array_filter( compact( 'sep', 'prelabel', 'nxtlabel' ) ); |
2661 |
echo get_posts_nav_link( $args ); |
|
0 | 2662 |
} |
2663 |
||
2664 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2665 |
* Retrieves the navigation to next/previous post, when applicable. |
5 | 2666 |
* |
2667 |
* @since 4.1.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2668 |
* @since 4.4.0 Introduced the `in_same_term`, `excluded_terms`, and `taxonomy` arguments. |
16 | 2669 |
* @since 5.3.0 Added the `aria_label` parameter. |
2670 |
* @since 5.5.0 Added the `class` parameter. |
|
5 | 2671 |
* |
2672 |
* @param array $args { |
|
2673 |
* Optional. Default post navigation arguments. Default empty array. |
|
2674 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2675 |
* @type string $prev_text Anchor text to display in the previous post link. Default '%title'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2676 |
* @type string $next_text Anchor text to display in the next post link. Default '%title'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2677 |
* @type bool $in_same_term Whether link should be in a same taxonomy term. Default false. |
18 | 2678 |
* @type int[]|string $excluded_terms Array or comma-separated list of excluded term IDs. Default empty. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2679 |
* @type string $taxonomy Taxonomy, if `$in_same_term` is true. Default 'category'. |
16 | 2680 |
* @type string $screen_reader_text Screen reader text for the nav element. Default 'Post navigation'. |
2681 |
* @type string $aria_label ARIA label text for the nav element. Default 'Posts'. |
|
2682 |
* @type string $class Custom class for the nav element. Default 'post-navigation'. |
|
5 | 2683 |
* } |
2684 |
* @return string Markup for post links. |
|
2685 |
*/ |
|
2686 |
function get_the_post_navigation( $args = array() ) { |
|
16 | 2687 |
// Make sure the nav element has an aria-label attribute: fallback to the screen reader text. |
2688 |
if ( ! empty( $args['screen_reader_text'] ) && empty( $args['aria_label'] ) ) { |
|
2689 |
$args['aria_label'] = $args['screen_reader_text']; |
|
2690 |
} |
|
2691 |
||
9 | 2692 |
$args = wp_parse_args( |
2693 |
$args, |
|
2694 |
array( |
|
2695 |
'prev_text' => '%title', |
|
2696 |
'next_text' => '%title', |
|
2697 |
'in_same_term' => false, |
|
2698 |
'excluded_terms' => '', |
|
2699 |
'taxonomy' => 'category', |
|
2700 |
'screen_reader_text' => __( 'Post navigation' ), |
|
16 | 2701 |
'aria_label' => __( 'Posts' ), |
2702 |
'class' => 'post-navigation', |
|
9 | 2703 |
) |
2704 |
); |
|
5 | 2705 |
|
2706 |
$navigation = ''; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2707 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2708 |
$previous = get_previous_post_link( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2709 |
'<div class="nav-previous">%link</div>', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2710 |
$args['prev_text'], |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2711 |
$args['in_same_term'], |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2712 |
$args['excluded_terms'], |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2713 |
$args['taxonomy'] |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2714 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2715 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2716 |
$next = get_next_post_link( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2717 |
'<div class="nav-next">%link</div>', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2718 |
$args['next_text'], |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2719 |
$args['in_same_term'], |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2720 |
$args['excluded_terms'], |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2721 |
$args['taxonomy'] |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2722 |
); |
5 | 2723 |
|
2724 |
// Only add markup if there's somewhere to navigate to. |
|
2725 |
if ( $previous || $next ) { |
|
16 | 2726 |
$navigation = _navigation_markup( $previous . $next, $args['class'], $args['screen_reader_text'], $args['aria_label'] ); |
5 | 2727 |
} |
2728 |
||
2729 |
return $navigation; |
|
2730 |
} |
|
2731 |
||
2732 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2733 |
* Displays the navigation to next/previous post, when applicable. |
5 | 2734 |
* |
2735 |
* @since 4.1.0 |
|
2736 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2737 |
* @param array $args Optional. See get_the_post_navigation() for available arguments. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2738 |
* Default empty array. |
5 | 2739 |
*/ |
2740 |
function the_post_navigation( $args = array() ) { |
|
2741 |
echo get_the_post_navigation( $args ); |
|
2742 |
} |
|
2743 |
||
2744 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2745 |
* Returns the navigation to next/previous set of posts, when applicable. |
5 | 2746 |
* |
2747 |
* @since 4.1.0 |
|
16 | 2748 |
* @since 5.3.0 Added the `aria_label` parameter. |
2749 |
* @since 5.5.0 Added the `class` parameter. |
|
5 | 2750 |
* |
2751 |
* @global WP_Query $wp_query WordPress Query object. |
|
2752 |
* |
|
2753 |
* @param array $args { |
|
2754 |
* Optional. Default posts navigation arguments. Default empty array. |
|
2755 |
* |
|
2756 |
* @type string $prev_text Anchor text to display in the previous posts link. |
|
2757 |
* Default 'Older posts'. |
|
2758 |
* @type string $next_text Anchor text to display in the next posts link. |
|
2759 |
* Default 'Newer posts'. |
|
16 | 2760 |
* @type string $screen_reader_text Screen reader text for the nav element. |
5 | 2761 |
* Default 'Posts navigation'. |
16 | 2762 |
* @type string $aria_label ARIA label text for the nav element. Default 'Posts'. |
2763 |
* @type string $class Custom class for the nav element. Default 'posts-navigation'. |
|
5 | 2764 |
* } |
2765 |
* @return string Markup for posts links. |
|
2766 |
*/ |
|
2767 |
function get_the_posts_navigation( $args = array() ) { |
|
2768 |
$navigation = ''; |
|
2769 |
||
2770 |
// Don't print empty markup if there's only one page. |
|
2771 |
if ( $GLOBALS['wp_query']->max_num_pages > 1 ) { |
|
16 | 2772 |
// Make sure the nav element has an aria-label attribute: fallback to the screen reader text. |
2773 |
if ( ! empty( $args['screen_reader_text'] ) && empty( $args['aria_label'] ) ) { |
|
2774 |
$args['aria_label'] = $args['screen_reader_text']; |
|
2775 |
} |
|
2776 |
||
9 | 2777 |
$args = wp_parse_args( |
2778 |
$args, |
|
2779 |
array( |
|
2780 |
'prev_text' => __( 'Older posts' ), |
|
2781 |
'next_text' => __( 'Newer posts' ), |
|
2782 |
'screen_reader_text' => __( 'Posts navigation' ), |
|
16 | 2783 |
'aria_label' => __( 'Posts' ), |
2784 |
'class' => 'posts-navigation', |
|
9 | 2785 |
) |
2786 |
); |
|
5 | 2787 |
|
2788 |
$next_link = get_previous_posts_link( $args['next_text'] ); |
|
2789 |
$prev_link = get_next_posts_link( $args['prev_text'] ); |
|
2790 |
||
2791 |
if ( $prev_link ) { |
|
2792 |
$navigation .= '<div class="nav-previous">' . $prev_link . '</div>'; |
|
2793 |
} |
|
2794 |
||
2795 |
if ( $next_link ) { |
|
2796 |
$navigation .= '<div class="nav-next">' . $next_link . '</div>'; |
|
2797 |
} |
|
2798 |
||
16 | 2799 |
$navigation = _navigation_markup( $navigation, $args['class'], $args['screen_reader_text'], $args['aria_label'] ); |
5 | 2800 |
} |
2801 |
||
2802 |
return $navigation; |
|
2803 |
} |
|
2804 |
||
2805 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2806 |
* Displays the navigation to next/previous set of posts, when applicable. |
5 | 2807 |
* |
2808 |
* @since 4.1.0 |
|
2809 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2810 |
* @param array $args Optional. See get_the_posts_navigation() for available arguments. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2811 |
* Default empty array. |
5 | 2812 |
*/ |
2813 |
function the_posts_navigation( $args = array() ) { |
|
2814 |
echo get_the_posts_navigation( $args ); |
|
2815 |
} |
|
2816 |
||
2817 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2818 |
* Retrieves a paginated navigation to next/previous set of posts, when applicable. |
5 | 2819 |
* |
2820 |
* @since 4.1.0 |
|
16 | 2821 |
* @since 5.3.0 Added the `aria_label` parameter. |
2822 |
* @since 5.5.0 Added the `class` parameter. |
|
5 | 2823 |
* |
2824 |
* @param array $args { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2825 |
* Optional. Default pagination arguments, see paginate_links(). |
5 | 2826 |
* |
2827 |
* @type string $screen_reader_text Screen reader text for navigation element. |
|
2828 |
* Default 'Posts navigation'. |
|
16 | 2829 |
* @type string $aria_label ARIA label text for the nav element. Default 'Posts'. |
2830 |
* @type string $class Custom class for the nav element. Default 'pagination'. |
|
5 | 2831 |
* } |
2832 |
* @return string Markup for pagination links. |
|
2833 |
*/ |
|
2834 |
function get_the_posts_pagination( $args = array() ) { |
|
2835 |
$navigation = ''; |
|
2836 |
||
2837 |
// Don't print empty markup if there's only one page. |
|
2838 |
if ( $GLOBALS['wp_query']->max_num_pages > 1 ) { |
|
16 | 2839 |
// Make sure the nav element has an aria-label attribute: fallback to the screen reader text. |
2840 |
if ( ! empty( $args['screen_reader_text'] ) && empty( $args['aria_label'] ) ) { |
|
2841 |
$args['aria_label'] = $args['screen_reader_text']; |
|
2842 |
} |
|
2843 |
||
9 | 2844 |
$args = wp_parse_args( |
2845 |
$args, |
|
2846 |
array( |
|
2847 |
'mid_size' => 1, |
|
2848 |
'prev_text' => _x( 'Previous', 'previous set of posts' ), |
|
2849 |
'next_text' => _x( 'Next', 'next set of posts' ), |
|
2850 |
'screen_reader_text' => __( 'Posts navigation' ), |
|
16 | 2851 |
'aria_label' => __( 'Posts' ), |
2852 |
'class' => 'pagination', |
|
9 | 2853 |
) |
2854 |
); |
|
5 | 2855 |
|
2856 |
// Make sure we get a string back. Plain is the next best thing. |
|
16 | 2857 |
if ( isset( $args['type'] ) && 'array' === $args['type'] ) { |
5 | 2858 |
$args['type'] = 'plain'; |
2859 |
} |
|
2860 |
||
2861 |
// Set up paginated links. |
|
2862 |
$links = paginate_links( $args ); |
|
2863 |
||
2864 |
if ( $links ) { |
|
16 | 2865 |
$navigation = _navigation_markup( $links, $args['class'], $args['screen_reader_text'], $args['aria_label'] ); |
5 | 2866 |
} |
2867 |
} |
|
2868 |
||
2869 |
return $navigation; |
|
2870 |
} |
|
2871 |
||
2872 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2873 |
* Displays a paginated navigation to next/previous set of posts, when applicable. |
5 | 2874 |
* |
2875 |
* @since 4.1.0 |
|
2876 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2877 |
* @param array $args Optional. See get_the_posts_pagination() for available arguments. |
5 | 2878 |
* Default empty array. |
2879 |
*/ |
|
2880 |
function the_posts_pagination( $args = array() ) { |
|
2881 |
echo get_the_posts_pagination( $args ); |
|
2882 |
} |
|
2883 |
||
2884 |
/** |
|
2885 |
* Wraps passed links in navigational markup. |
|
2886 |
* |
|
2887 |
* @since 4.1.0 |
|
16 | 2888 |
* @since 5.3.0 Added the `aria_label` parameter. |
5 | 2889 |
* @access private |
2890 |
* |
|
2891 |
* @param string $links Navigational links. |
|
16 | 2892 |
* @param string $class Optional. Custom class for the nav element. |
2893 |
* Default 'posts-navigation'. |
|
2894 |
* @param string $screen_reader_text Optional. Screen reader text for the nav element. |
|
2895 |
* Default 'Posts navigation'. |
|
2896 |
* @param string $aria_label Optional. ARIA label for the nav element. |
|
2897 |
* Defaults to the value of `$screen_reader_text`. |
|
5 | 2898 |
* @return string Navigation template tag. |
2899 |
*/ |
|
16 | 2900 |
function _navigation_markup( $links, $class = 'posts-navigation', $screen_reader_text = '', $aria_label = '' ) { |
5 | 2901 |
if ( empty( $screen_reader_text ) ) { |
2902 |
$screen_reader_text = __( 'Posts navigation' ); |
|
2903 |
} |
|
16 | 2904 |
if ( empty( $aria_label ) ) { |
2905 |
$aria_label = $screen_reader_text; |
|
2906 |
} |
|
5 | 2907 |
|
2908 |
$template = ' |
|
19 | 2909 |
<nav class="navigation %1$s" aria-label="%4$s"> |
5 | 2910 |
<h2 class="screen-reader-text">%2$s</h2> |
2911 |
<div class="nav-links">%3$s</div> |
|
2912 |
</nav>'; |
|
2913 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2914 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2915 |
* Filters the navigation markup template. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2916 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2917 |
* Note: The filtered template HTML must contain specifiers for the navigation |
16 | 2918 |
* class (%1$s), the screen-reader-text value (%2$s), placement of the navigation |
2919 |
* links (%3$s), and ARIA label text if screen-reader-text does not fit that (%4$s): |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2920 |
* |
19 | 2921 |
* <nav class="navigation %1$s" aria-label="%4$s"> |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2922 |
* <h2 class="screen-reader-text">%2$s</h2> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2923 |
* <div class="nav-links">%3$s</div> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2924 |
* </nav> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2925 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2926 |
* @since 4.4.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2927 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2928 |
* @param string $template The default template. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2929 |
* @param string $class The class passed by the calling function. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2930 |
* @return string Navigation template. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2931 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2932 |
$template = apply_filters( 'navigation_markup_template', $template, $class ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2933 |
|
16 | 2934 |
return sprintf( $template, sanitize_html_class( $class ), esc_html( $screen_reader_text ), $links, esc_html( $aria_label ) ); |
5 | 2935 |
} |
2936 |
||
2937 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2938 |
* Retrieves the comments page number link. |
0 | 2939 |
* |
2940 |
* @since 2.7.0 |
|
2941 |
* |
|
16 | 2942 |
* @global WP_Rewrite $wp_rewrite WordPress rewrite component. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2943 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2944 |
* @param int $pagenum Optional. Page number. Default 1. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2945 |
* @param int $max_page Optional. The maximum number of comment pages. Default 0. |
5 | 2946 |
* @return string The comments page number link URL. |
0 | 2947 |
*/ |
2948 |
function get_comments_pagenum_link( $pagenum = 1, $max_page = 0 ) { |
|
2949 |
global $wp_rewrite; |
|
2950 |
||
2951 |
$pagenum = (int) $pagenum; |
|
2952 |
||
2953 |
$result = get_permalink(); |
|
2954 |
||
16 | 2955 |
if ( 'newest' === get_option( 'default_comments_page' ) ) { |
0 | 2956 |
if ( $pagenum != $max_page ) { |
9 | 2957 |
if ( $wp_rewrite->using_permalinks() ) { |
2958 |
$result = user_trailingslashit( trailingslashit( $result ) . $wp_rewrite->comments_pagination_base . '-' . $pagenum, 'commentpaged' ); |
|
2959 |
} else { |
|
0 | 2960 |
$result = add_query_arg( 'cpage', $pagenum, $result ); |
9 | 2961 |
} |
0 | 2962 |
} |
2963 |
} elseif ( $pagenum > 1 ) { |
|
9 | 2964 |
if ( $wp_rewrite->using_permalinks() ) { |
2965 |
$result = user_trailingslashit( trailingslashit( $result ) . $wp_rewrite->comments_pagination_base . '-' . $pagenum, 'commentpaged' ); |
|
2966 |
} else { |
|
0 | 2967 |
$result = add_query_arg( 'cpage', $pagenum, $result ); |
9 | 2968 |
} |
0 | 2969 |
} |
2970 |
||
2971 |
$result .= '#comments'; |
|
2972 |
||
5 | 2973 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2974 |
* Filters the comments page number link for the current request. |
5 | 2975 |
* |
2976 |
* @since 2.7.0 |
|
2977 |
* |
|
2978 |
* @param string $result The comments page number link. |
|
2979 |
*/ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2980 |
return apply_filters( 'get_comments_pagenum_link', $result ); |
0 | 2981 |
} |
2982 |
||
2983 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2984 |
* Retrieves the link to the next comments page. |
0 | 2985 |
* |
2986 |
* @since 2.7.1 |
|
2987 |
* |
|
16 | 2988 |
* @global WP_Query $wp_query WordPress Query object. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2989 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2990 |
* @param string $label Optional. Label for link text. Default empty. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2991 |
* @param int $max_page Optional. Max page. Default 0. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2992 |
* @return string|void HTML-formatted link for the next page of comments. |
0 | 2993 |
*/ |
2994 |
function get_next_comments_link( $label = '', $max_page = 0 ) { |
|
2995 |
global $wp_query; |
|
2996 |
||
9 | 2997 |
if ( ! is_singular() ) { |
0 | 2998 |
return; |
9 | 2999 |
} |
3000 |
||
3001 |
$page = get_query_var( 'cpage' ); |
|
0 | 3002 |
|
5 | 3003 |
if ( ! $page ) { |
3004 |
$page = 1; |
|
3005 |
} |
|
3006 |
||
18 | 3007 |
$nextpage = (int) $page + 1; |
9 | 3008 |
|
3009 |
if ( empty( $max_page ) ) { |
|
0 | 3010 |
$max_page = $wp_query->max_num_comment_pages; |
9 | 3011 |
} |
3012 |
||
3013 |
if ( empty( $max_page ) ) { |
|
0 | 3014 |
$max_page = get_comment_pages_count(); |
9 | 3015 |
} |
3016 |
||
3017 |
if ( $nextpage > $max_page ) { |
|
0 | 3018 |
return; |
9 | 3019 |
} |
3020 |
||
3021 |
if ( empty( $label ) ) { |
|
3022 |
$label = __( 'Newer Comments »' ); |
|
3023 |
} |
|
0 | 3024 |
|
5 | 3025 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3026 |
* Filters the anchor tag attributes for the next comments page link. |
5 | 3027 |
* |
3028 |
* @since 2.7.0 |
|
3029 |
* |
|
3030 |
* @param string $attributes Attributes for the anchor tag. |
|
3031 |
*/ |
|
9 | 3032 |
return '<a href="' . esc_url( get_comments_pagenum_link( $nextpage, $max_page ) ) . '" ' . apply_filters( 'next_comments_link_attributes', '' ) . '>' . preg_replace( '/&([^#])(?![a-z]{1,8};)/i', '&$1', $label ) . '</a>'; |
0 | 3033 |
} |
3034 |
||
3035 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3036 |
* Displays the link to the next comments page. |
0 | 3037 |
* |
3038 |
* @since 2.7.0 |
|
3039 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3040 |
* @param string $label Optional. Label for link text. Default empty. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3041 |
* @param int $max_page Optional. Max page. Default 0. |
0 | 3042 |
*/ |
3043 |
function next_comments_link( $label = '', $max_page = 0 ) { |
|
3044 |
echo get_next_comments_link( $label, $max_page ); |
|
3045 |
} |
|
3046 |
||
3047 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3048 |
* Retrieves the link to the previous comments page. |
0 | 3049 |
* |
3050 |
* @since 2.7.1 |
|
3051 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3052 |
* @param string $label Optional. Label for comments link text. Default empty. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3053 |
* @return string|void HTML-formatted link for the previous page of comments. |
0 | 3054 |
*/ |
3055 |
function get_previous_comments_link( $label = '' ) { |
|
9 | 3056 |
if ( ! is_singular() ) { |
3057 |
return; |
|
3058 |
} |
|
3059 |
||
3060 |
$page = get_query_var( 'cpage' ); |
|
3061 |
||
18 | 3062 |
if ( (int) $page <= 1 ) { |
0 | 3063 |
return; |
9 | 3064 |
} |
3065 |
||
18 | 3066 |
$prevpage = (int) $page - 1; |
9 | 3067 |
|
3068 |
if ( empty( $label ) ) { |
|
3069 |
$label = __( '« Older Comments' ); |
|
3070 |
} |
|
0 | 3071 |
|
5 | 3072 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3073 |
* Filters the anchor tag attributes for the previous comments page link. |
5 | 3074 |
* |
3075 |
* @since 2.7.0 |
|
3076 |
* |
|
3077 |
* @param string $attributes Attributes for the anchor tag. |
|
3078 |
*/ |
|
9 | 3079 |
return '<a href="' . esc_url( get_comments_pagenum_link( $prevpage ) ) . '" ' . apply_filters( 'previous_comments_link_attributes', '' ) . '>' . preg_replace( '/&([^#])(?![a-z]{1,8};)/i', '&$1', $label ) . '</a>'; |
0 | 3080 |
} |
3081 |
||
3082 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3083 |
* Displays the link to the previous comments page. |
0 | 3084 |
* |
3085 |
* @since 2.7.0 |
|
3086 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3087 |
* @param string $label Optional. Label for comments link text. Default empty. |
0 | 3088 |
*/ |
3089 |
function previous_comments_link( $label = '' ) { |
|
3090 |
echo get_previous_comments_link( $label ); |
|
3091 |
} |
|
3092 |
||
3093 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3094 |
* Displays or retrieves pagination links for the comments on the current post. |
0 | 3095 |
* |
3096 |
* @see paginate_links() |
|
3097 |
* @since 2.7.0 |
|
3098 |
* |
|
16 | 3099 |
* @global WP_Rewrite $wp_rewrite WordPress rewrite component. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3100 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3101 |
* @param string|array $args Optional args. See paginate_links(). Default empty array. |
16 | 3102 |
* @return void|string|array Void if 'echo' argument is true and 'type' is not an array, |
3103 |
* or if the query is not for an existing single post of any post type. |
|
3104 |
* Otherwise, markup for comment page links or array of comment page links, |
|
3105 |
* depending on 'type' argument. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3106 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3107 |
function paginate_comments_links( $args = array() ) { |
0 | 3108 |
global $wp_rewrite; |
3109 |
||
9 | 3110 |
if ( ! is_singular() ) { |
0 | 3111 |
return; |
9 | 3112 |
} |
3113 |
||
3114 |
$page = get_query_var( 'cpage' ); |
|
3115 |
if ( ! $page ) { |
|
0 | 3116 |
$page = 1; |
9 | 3117 |
} |
0 | 3118 |
$max_page = get_comment_pages_count(); |
3119 |
$defaults = array( |
|
9 | 3120 |
'base' => add_query_arg( 'cpage', '%#%' ), |
3121 |
'format' => '', |
|
3122 |
'total' => $max_page, |
|
3123 |
'current' => $page, |
|
3124 |
'echo' => true, |
|
3125 |
'type' => 'plain', |
|
3126 |
'add_fragment' => '#comments', |
|
0 | 3127 |
); |
9 | 3128 |
if ( $wp_rewrite->using_permalinks() ) { |
3129 |
$defaults['base'] = user_trailingslashit( trailingslashit( get_permalink() ) . $wp_rewrite->comments_pagination_base . '-%#%', 'commentpaged' ); |
|
3130 |
} |
|
3131 |
||
3132 |
$args = wp_parse_args( $args, $defaults ); |
|
0 | 3133 |
$page_links = paginate_links( $args ); |
3134 |
||
9 | 3135 |
if ( $args['echo'] && 'array' !== $args['type'] ) { |
0 | 3136 |
echo $page_links; |
9 | 3137 |
} else { |
0 | 3138 |
return $page_links; |
9 | 3139 |
} |
0 | 3140 |
} |
3141 |
||
3142 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3143 |
* Retrieves navigation to next/previous set of comments, when applicable. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3144 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3145 |
* @since 4.4.0 |
16 | 3146 |
* @since 5.3.0 Added the `aria_label` parameter. |
3147 |
* @since 5.5.0 Added the `class` parameter. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3148 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3149 |
* @param array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3150 |
* Optional. Default comments navigation arguments. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3151 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3152 |
* @type string $prev_text Anchor text to display in the previous comments link. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3153 |
* Default 'Older comments'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3154 |
* @type string $next_text Anchor text to display in the next comments link. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3155 |
* Default 'Newer comments'. |
16 | 3156 |
* @type string $screen_reader_text Screen reader text for the nav element. Default 'Comments navigation'. |
3157 |
* @type string $aria_label ARIA label text for the nav element. Default 'Comments'. |
|
3158 |
* @type string $class Custom class for the nav element. Default 'comment-navigation'. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3159 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3160 |
* @return string Markup for comments links. |
0 | 3161 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3162 |
function get_the_comments_navigation( $args = array() ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3163 |
$navigation = ''; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3164 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3165 |
// Are there comments to navigate through? |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3166 |
if ( get_comment_pages_count() > 1 ) { |
16 | 3167 |
// Make sure the nav element has an aria-label attribute: fallback to the screen reader text. |
3168 |
if ( ! empty( $args['screen_reader_text'] ) && empty( $args['aria_label'] ) ) { |
|
3169 |
$args['aria_label'] = $args['screen_reader_text']; |
|
3170 |
} |
|
3171 |
||
9 | 3172 |
$args = wp_parse_args( |
3173 |
$args, |
|
3174 |
array( |
|
3175 |
'prev_text' => __( 'Older comments' ), |
|
3176 |
'next_text' => __( 'Newer comments' ), |
|
3177 |
'screen_reader_text' => __( 'Comments navigation' ), |
|
16 | 3178 |
'aria_label' => __( 'Comments' ), |
3179 |
'class' => 'comment-navigation', |
|
9 | 3180 |
) |
3181 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3182 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3183 |
$prev_link = get_previous_comments_link( $args['prev_text'] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3184 |
$next_link = get_next_comments_link( $args['next_text'] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3185 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3186 |
if ( $prev_link ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3187 |
$navigation .= '<div class="nav-previous">' . $prev_link . '</div>'; |
5 | 3188 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3189 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3190 |
if ( $next_link ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3191 |
$navigation .= '<div class="nav-next">' . $next_link . '</div>'; |
5 | 3192 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3193 |
|
16 | 3194 |
$navigation = _navigation_markup( $navigation, $args['class'], $args['screen_reader_text'], $args['aria_label'] ); |
5 | 3195 |
} |
3196 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3197 |
return $navigation; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3198 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3199 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3200 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3201 |
* Displays navigation to next/previous set of comments, when applicable. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3202 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3203 |
* @since 4.4.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3204 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3205 |
* @param array $args See get_the_comments_navigation() for available arguments. Default empty array. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3206 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3207 |
function the_comments_navigation( $args = array() ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3208 |
echo get_the_comments_navigation( $args ); |
0 | 3209 |
} |
3210 |
||
3211 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3212 |
* Retrieves a paginated navigation to next/previous set of comments, when applicable. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3213 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3214 |
* @since 4.4.0 |
16 | 3215 |
* @since 5.3.0 Added the `aria_label` parameter. |
3216 |
* @since 5.5.0 Added the `class` parameter. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3217 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3218 |
* @see paginate_comments_links() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3219 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3220 |
* @param array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3221 |
* Optional. Default pagination arguments. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3222 |
* |
16 | 3223 |
* @type string $screen_reader_text Screen reader text for the nav element. Default 'Comments navigation'. |
3224 |
* @type string $aria_label ARIA label text for the nav element. Default 'Comments'. |
|
3225 |
* @type string $class Custom class for the nav element. Default 'comments-pagination'. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3226 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3227 |
* @return string Markup for pagination links. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3228 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3229 |
function get_the_comments_pagination( $args = array() ) { |
16 | 3230 |
$navigation = ''; |
3231 |
||
3232 |
// Make sure the nav element has an aria-label attribute: fallback to the screen reader text. |
|
3233 |
if ( ! empty( $args['screen_reader_text'] ) && empty( $args['aria_label'] ) ) { |
|
3234 |
$args['aria_label'] = $args['screen_reader_text']; |
|
3235 |
} |
|
3236 |
||
9 | 3237 |
$args = wp_parse_args( |
3238 |
$args, |
|
3239 |
array( |
|
3240 |
'screen_reader_text' => __( 'Comments navigation' ), |
|
16 | 3241 |
'aria_label' => __( 'Comments' ), |
3242 |
'class' => 'comments-pagination', |
|
9 | 3243 |
) |
3244 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3245 |
$args['echo'] = false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3246 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3247 |
// Make sure we get a string back. Plain is the next best thing. |
16 | 3248 |
if ( isset( $args['type'] ) && 'array' === $args['type'] ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3249 |
$args['type'] = 'plain'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3250 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3251 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3252 |
$links = paginate_comments_links( $args ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3253 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3254 |
if ( $links ) { |
16 | 3255 |
$navigation = _navigation_markup( $links, $args['class'], $args['screen_reader_text'], $args['aria_label'] ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3256 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3257 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3258 |
return $navigation; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3259 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3260 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3261 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3262 |
* Displays a paginated navigation to next/previous set of comments, when applicable. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3263 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3264 |
* @since 4.4.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3265 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3266 |
* @param array $args See get_the_comments_pagination() for available arguments. Default empty array. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3267 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3268 |
function the_comments_pagination( $args = array() ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3269 |
echo get_the_comments_pagination( $args ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3270 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3271 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3272 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3273 |
* Retrieves the URL for the current site where the front end is accessible. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3274 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3275 |
* Returns the 'home' option with the appropriate protocol. The protocol will be 'https' |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3276 |
* if is_ssl() evaluates to true; otherwise, it will be the same as the 'home' option. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3277 |
* If `$scheme` is 'http' or 'https', is_ssl() is overridden. |
0 | 3278 |
* |
3279 |
* @since 3.0.0 |
|
3280 |
* |
|
16 | 3281 |
* @param string $path Optional. Path relative to the home URL. Default empty. |
3282 |
* @param string|null $scheme Optional. Scheme to give the home URL context. Accepts |
|
3283 |
* 'http', 'https', 'relative', 'rest', or null. Default null. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3284 |
* @return string Home URL link with optional path appended. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3285 |
*/ |
0 | 3286 |
function home_url( $path = '', $scheme = null ) { |
3287 |
return get_home_url( null, $path, $scheme ); |
|
3288 |
} |
|
3289 |
||
3290 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3291 |
* Retrieves the URL for a given site where the front end is accessible. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3292 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3293 |
* Returns the 'home' option with the appropriate protocol. The protocol will be 'https' |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3294 |
* if is_ssl() evaluates to true; otherwise, it will be the same as the 'home' option. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3295 |
* If `$scheme` is 'http' or 'https', is_ssl() is overridden. |
0 | 3296 |
* |
3297 |
* @since 3.0.0 |
|
3298 |
* |
|
18 | 3299 |
* @param int|null $blog_id Optional. Site ID. Default null (current site). |
16 | 3300 |
* @param string $path Optional. Path relative to the home URL. Default empty. |
3301 |
* @param string|null $scheme Optional. Scheme to give the home URL context. Accepts |
|
3302 |
* 'http', 'https', 'relative', 'rest', or null. Default null. |
|
5 | 3303 |
* @return string Home URL link with optional path appended. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3304 |
*/ |
0 | 3305 |
function get_home_url( $blog_id = null, $path = '', $scheme = null ) { |
3306 |
$orig_scheme = $scheme; |
|
3307 |
||
9 | 3308 |
if ( empty( $blog_id ) || ! is_multisite() ) { |
0 | 3309 |
$url = get_option( 'home' ); |
3310 |
} else { |
|
3311 |
switch_to_blog( $blog_id ); |
|
3312 |
$url = get_option( 'home' ); |
|
3313 |
restore_current_blog(); |
|
3314 |
} |
|
3315 |
||
16 | 3316 |
if ( ! in_array( $scheme, array( 'http', 'https', 'relative' ), true ) ) { |
18 | 3317 |
if ( is_ssl() ) { |
0 | 3318 |
$scheme = 'https'; |
9 | 3319 |
} else { |
0 | 3320 |
$scheme = parse_url( $url, PHP_URL_SCHEME ); |
9 | 3321 |
} |
0 | 3322 |
} |
3323 |
||
3324 |
$url = set_url_scheme( $url, $scheme ); |
|
3325 |
||
9 | 3326 |
if ( $path && is_string( $path ) ) { |
0 | 3327 |
$url .= '/' . ltrim( $path, '/' ); |
9 | 3328 |
} |
0 | 3329 |
|
5 | 3330 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3331 |
* Filters the home URL. |
5 | 3332 |
* |
3333 |
* @since 3.0.0 |
|
3334 |
* |
|
3335 |
* @param string $url The complete home URL including scheme and path. |
|
3336 |
* @param string $path Path relative to the home URL. Blank string if no path is specified. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3337 |
* @param string|null $orig_scheme Scheme to give the home URL context. Accepts 'http', 'https', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3338 |
* 'relative', 'rest', or null. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3339 |
* @param int|null $blog_id Site ID, or null for the current site. |
5 | 3340 |
*/ |
0 | 3341 |
return apply_filters( 'home_url', $url, $path, $orig_scheme, $blog_id ); |
3342 |
} |
|
3343 |
||
3344 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3345 |
* Retrieves the URL for the current site where WordPress application files |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3346 |
* (e.g. wp-blog-header.php or the wp-admin/ folder) are accessible. |
0 | 3347 |
* |
3348 |
* Returns the 'site_url' option with the appropriate protocol, 'https' if |
|
3349 |
* is_ssl() and 'http' otherwise. If $scheme is 'http' or 'https', is_ssl() is |
|
3350 |
* overridden. |
|
3351 |
* |
|
5 | 3352 |
* @since 3.0.0 |
0 | 3353 |
* |
18 | 3354 |
* @param string $path Optional. Path relative to the site URL. Default empty. |
3355 |
* @param string|null $scheme Optional. Scheme to give the site URL context. See set_url_scheme(). |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3356 |
* @return string Site URL link with optional path appended. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3357 |
*/ |
0 | 3358 |
function site_url( $path = '', $scheme = null ) { |
3359 |
return get_site_url( null, $path, $scheme ); |
|
3360 |
} |
|
3361 |
||
3362 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3363 |
* Retrieves the URL for a given site where WordPress application files |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3364 |
* (e.g. wp-blog-header.php or the wp-admin/ folder) are accessible. |
0 | 3365 |
* |
3366 |
* Returns the 'site_url' option with the appropriate protocol, 'https' if |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3367 |
* is_ssl() and 'http' otherwise. If `$scheme` is 'http' or 'https', |
5 | 3368 |
* `is_ssl()` is overridden. |
0 | 3369 |
* |
3370 |
* @since 3.0.0 |
|
3371 |
* |
|
18 | 3372 |
* @param int|null $blog_id Optional. Site ID. Default null (current site). |
3373 |
* @param string $path Optional. Path relative to the site URL. Default empty. |
|
3374 |
* @param string|null $scheme Optional. Scheme to give the site URL context. Accepts |
|
3375 |
* 'http', 'https', 'login', 'login_post', 'admin', or |
|
3376 |
* 'relative'. Default null. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3377 |
* @return string Site URL link with optional path appended. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3378 |
*/ |
0 | 3379 |
function get_site_url( $blog_id = null, $path = '', $scheme = null ) { |
9 | 3380 |
if ( empty( $blog_id ) || ! is_multisite() ) { |
0 | 3381 |
$url = get_option( 'siteurl' ); |
3382 |
} else { |
|
3383 |
switch_to_blog( $blog_id ); |
|
3384 |
$url = get_option( 'siteurl' ); |
|
3385 |
restore_current_blog(); |
|
3386 |
} |
|
3387 |
||
3388 |
$url = set_url_scheme( $url, $scheme ); |
|
3389 |
||
9 | 3390 |
if ( $path && is_string( $path ) ) { |
0 | 3391 |
$url .= '/' . ltrim( $path, '/' ); |
9 | 3392 |
} |
0 | 3393 |
|
5 | 3394 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3395 |
* Filters the site URL. |
5 | 3396 |
* |
3397 |
* @since 2.7.0 |
|
3398 |
* |
|
3399 |
* @param string $url The complete site URL including scheme and path. |
|
3400 |
* @param string $path Path relative to the site URL. Blank string if no path is specified. |
|
3401 |
* @param string|null $scheme Scheme to give the site URL context. Accepts 'http', 'https', 'login', |
|
3402 |
* 'login_post', 'admin', 'relative' or null. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3403 |
* @param int|null $blog_id Site ID, or null for the current site. |
5 | 3404 |
*/ |
0 | 3405 |
return apply_filters( 'site_url', $url, $path, $scheme, $blog_id ); |
3406 |
} |
|
3407 |
||
3408 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3409 |
* Retrieves the URL to the admin area for the current site. |
0 | 3410 |
* |
3411 |
* @since 2.6.0 |
|
3412 |
* |
|
18 | 3413 |
* @param string $path Optional. Path relative to the admin URL. Default 'admin'. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3414 |
* @param string $scheme The scheme to use. Default is 'admin', which obeys force_ssl_admin() and is_ssl(). |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3415 |
* 'http' or 'https' can be passed to force those schemes. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3416 |
* @return string Admin URL link with optional path appended. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3417 |
*/ |
0 | 3418 |
function admin_url( $path = '', $scheme = 'admin' ) { |
3419 |
return get_admin_url( null, $path, $scheme ); |
|
3420 |
} |
|
3421 |
||
3422 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3423 |
* Retrieves the URL to the admin area for a given site. |
0 | 3424 |
* |
3425 |
* @since 3.0.0 |
|
3426 |
* |
|
18 | 3427 |
* @param int|null $blog_id Optional. Site ID. Default null (current site). |
3428 |
* @param string $path Optional. Path relative to the admin URL. Default empty. |
|
3429 |
* @param string $scheme Optional. The scheme to use. Accepts 'http' or 'https', |
|
3430 |
* to force those schemes. Default 'admin', which obeys |
|
3431 |
* force_ssl_admin() and is_ssl(). |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3432 |
* @return string Admin URL link with optional path appended. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3433 |
*/ |
0 | 3434 |
function get_admin_url( $blog_id = null, $path = '', $scheme = 'admin' ) { |
9 | 3435 |
$url = get_site_url( $blog_id, 'wp-admin/', $scheme ); |
3436 |
||
3437 |
if ( $path && is_string( $path ) ) { |
|
0 | 3438 |
$url .= ltrim( $path, '/' ); |
9 | 3439 |
} |
0 | 3440 |
|
5 | 3441 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3442 |
* Filters the admin area URL. |
5 | 3443 |
* |
3444 |
* @since 2.8.0 |
|
18 | 3445 |
* @since 5.8.0 The `$scheme` parameter was added. |
5 | 3446 |
* |
18 | 3447 |
* @param string $url The complete admin area URL including scheme and path. |
3448 |
* @param string $path Path relative to the admin area URL. Blank string if no path is specified. |
|
3449 |
* @param int|null $blog_id Site ID, or null for the current site. |
|
3450 |
* @param string|null $scheme The scheme to use. Accepts 'http', 'https', |
|
3451 |
* 'admin', or null. Default 'admin', which obeys force_ssl_admin() and is_ssl(). |
|
5 | 3452 |
*/ |
18 | 3453 |
return apply_filters( 'admin_url', $url, $path, $blog_id, $scheme ); |
0 | 3454 |
} |
3455 |
||
3456 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3457 |
* Retrieves the URL to the includes directory. |
0 | 3458 |
* |
3459 |
* @since 2.6.0 |
|
3460 |
* |
|
18 | 3461 |
* @param string $path Optional. Path relative to the includes URL. Default empty. |
3462 |
* @param string|null $scheme Optional. Scheme to give the includes URL context. Accepts |
|
3463 |
* 'http', 'https', or 'relative'. Default null. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3464 |
* @return string Includes URL link with optional path appended. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3465 |
*/ |
0 | 3466 |
function includes_url( $path = '', $scheme = null ) { |
3467 |
$url = site_url( '/' . WPINC . '/', $scheme ); |
|
3468 |
||
9 | 3469 |
if ( $path && is_string( $path ) ) { |
3470 |
$url .= ltrim( $path, '/' ); |
|
3471 |
} |
|
0 | 3472 |
|
5 | 3473 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3474 |
* Filters the URL to the includes directory. |
5 | 3475 |
* |
3476 |
* @since 2.8.0 |
|
18 | 3477 |
* @since 5.8.0 The `$scheme` parameter was added. |
5 | 3478 |
* |
18 | 3479 |
* @param string $url The complete URL to the includes directory including scheme and path. |
3480 |
* @param string $path Path relative to the URL to the wp-includes directory. Blank string |
|
3481 |
* if no path is specified. |
|
3482 |
* @param string|null $scheme Scheme to give the includes URL context. Accepts |
|
3483 |
* 'http', 'https', 'relative', or null. Default null. |
|
5 | 3484 |
*/ |
18 | 3485 |
return apply_filters( 'includes_url', $url, $path, $scheme ); |
0 | 3486 |
} |
3487 |
||
3488 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3489 |
* Retrieves the URL to the content directory. |
0 | 3490 |
* |
3491 |
* @since 2.6.0 |
|
3492 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3493 |
* @param string $path Optional. Path relative to the content URL. Default empty. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3494 |
* @return string Content URL link with optional path appended. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3495 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3496 |
function content_url( $path = '' ) { |
0 | 3497 |
$url = set_url_scheme( WP_CONTENT_URL ); |
3498 |
||
9 | 3499 |
if ( $path && is_string( $path ) ) { |
3500 |
$url .= '/' . ltrim( $path, '/' ); |
|
3501 |
} |
|
0 | 3502 |
|
5 | 3503 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3504 |
* Filters the URL to the content directory. |
5 | 3505 |
* |
3506 |
* @since 2.8.0 |
|
3507 |
* |
|
3508 |
* @param string $url The complete URL to the content directory including scheme and path. |
|
3509 |
* @param string $path Path relative to the URL to the content directory. Blank string |
|
3510 |
* if no path is specified. |
|
3511 |
*/ |
|
9 | 3512 |
return apply_filters( 'content_url', $url, $path ); |
0 | 3513 |
} |
3514 |
||
3515 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3516 |
* Retrieves a URL within the plugins or mu-plugins directory. |
0 | 3517 |
* |
5 | 3518 |
* Defaults to the plugins directory URL if no arguments are supplied. |
3519 |
* |
|
0 | 3520 |
* @since 2.6.0 |
3521 |
* |
|
16 | 3522 |
* @param string $path Optional. Extra path appended to the end of the URL, including |
3523 |
* the relative directory if $plugin is supplied. Default empty. |
|
3524 |
* @param string $plugin Optional. A full path to a file inside a plugin or mu-plugin. |
|
3525 |
* The URL will be relative to its directory. Default empty. |
|
3526 |
* Typically this is done by passing `__FILE__` as the argument. |
|
5 | 3527 |
* @return string Plugins URL link with optional paths appended. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3528 |
*/ |
5 | 3529 |
function plugins_url( $path = '', $plugin = '' ) { |
3530 |
||
9 | 3531 |
$path = wp_normalize_path( $path ); |
3532 |
$plugin = wp_normalize_path( $plugin ); |
|
5 | 3533 |
$mu_plugin_dir = wp_normalize_path( WPMU_PLUGIN_DIR ); |
0 | 3534 |
|
9 | 3535 |
if ( ! empty( $plugin ) && 0 === strpos( $plugin, $mu_plugin_dir ) ) { |
0 | 3536 |
$url = WPMU_PLUGIN_URL; |
9 | 3537 |
} else { |
0 | 3538 |
$url = WP_PLUGIN_URL; |
9 | 3539 |
} |
0 | 3540 |
|
3541 |
$url = set_url_scheme( $url ); |
|
3542 |
||
9 | 3543 |
if ( ! empty( $plugin ) && is_string( $plugin ) ) { |
3544 |
$folder = dirname( plugin_basename( $plugin ) ); |
|
16 | 3545 |
if ( '.' !== $folder ) { |
9 | 3546 |
$url .= '/' . ltrim( $folder, '/' ); |
3547 |
} |
|
0 | 3548 |
} |
3549 |
||
9 | 3550 |
if ( $path && is_string( $path ) ) { |
3551 |
$url .= '/' . ltrim( $path, '/' ); |
|
3552 |
} |
|
0 | 3553 |
|
5 | 3554 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3555 |
* Filters the URL to the plugins directory. |
5 | 3556 |
* |
3557 |
* @since 2.8.0 |
|
3558 |
* |
|
3559 |
* @param string $url The complete URL to the plugins directory including scheme and path. |
|
3560 |
* @param string $path Path relative to the URL to the plugins directory. Blank string |
|
3561 |
* if no path is specified. |
|
3562 |
* @param string $plugin The plugin file path to be relative to. Blank string if no plugin |
|
3563 |
* is specified. |
|
3564 |
*/ |
|
3565 |
return apply_filters( 'plugins_url', $url, $path, $plugin ); |
|
0 | 3566 |
} |
3567 |
||
3568 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3569 |
* Retrieves the site URL for the current network. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3570 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3571 |
* Returns the site URL with the appropriate protocol, 'https' if |
0 | 3572 |
* is_ssl() and 'http' otherwise. If $scheme is 'http' or 'https', is_ssl() is |
3573 |
* overridden. |
|
3574 |
* |
|
3575 |
* @since 3.0.0 |
|
3576 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3577 |
* @see set_url_scheme() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3578 |
* |
18 | 3579 |
* @param string $path Optional. Path relative to the site URL. Default empty. |
3580 |
* @param string|null $scheme Optional. Scheme to give the site URL context. Accepts |
|
3581 |
* 'http', 'https', or 'relative'. Default null. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3582 |
* @return string Site URL link with optional path appended. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3583 |
*/ |
0 | 3584 |
function network_site_url( $path = '', $scheme = null ) { |
9 | 3585 |
if ( ! is_multisite() ) { |
3586 |
return site_url( $path, $scheme ); |
|
3587 |
} |
|
0 | 3588 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3589 |
$current_network = get_network(); |
5 | 3590 |
|
16 | 3591 |
if ( 'relative' === $scheme ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3592 |
$url = $current_network->path; |
9 | 3593 |
} else { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3594 |
$url = set_url_scheme( 'http://' . $current_network->domain . $current_network->path, $scheme ); |
9 | 3595 |
} |
3596 |
||
3597 |
if ( $path && is_string( $path ) ) { |
|
0 | 3598 |
$url .= ltrim( $path, '/' ); |
9 | 3599 |
} |
0 | 3600 |
|
5 | 3601 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3602 |
* Filters the network site URL. |
5 | 3603 |
* |
3604 |
* @since 3.0.0 |
|
3605 |
* |
|
3606 |
* @param string $url The complete network site URL including scheme and path. |
|
3607 |
* @param string $path Path relative to the network site URL. Blank string if |
|
3608 |
* no path is specified. |
|
3609 |
* @param string|null $scheme Scheme to give the URL context. Accepts 'http', 'https', |
|
3610 |
* 'relative' or null. |
|
3611 |
*/ |
|
0 | 3612 |
return apply_filters( 'network_site_url', $url, $path, $scheme ); |
3613 |
} |
|
3614 |
||
3615 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3616 |
* Retrieves the home URL for the current network. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3617 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3618 |
* Returns the home URL with the appropriate protocol, 'https' is_ssl() |
5 | 3619 |
* and 'http' otherwise. If `$scheme` is 'http' or 'https', `is_ssl()` is |
0 | 3620 |
* overridden. |
3621 |
* |
|
3622 |
* @since 3.0.0 |
|
3623 |
* |
|
18 | 3624 |
* @param string $path Optional. Path relative to the home URL. Default empty. |
3625 |
* @param string|null $scheme Optional. Scheme to give the home URL context. Accepts |
|
3626 |
* 'http', 'https', or 'relative'. Default null. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3627 |
* @return string Home URL link with optional path appended. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3628 |
*/ |
0 | 3629 |
function network_home_url( $path = '', $scheme = null ) { |
9 | 3630 |
if ( ! is_multisite() ) { |
3631 |
return home_url( $path, $scheme ); |
|
3632 |
} |
|
0 | 3633 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3634 |
$current_network = get_network(); |
9 | 3635 |
$orig_scheme = $scheme; |
3636 |
||
16 | 3637 |
if ( ! in_array( $scheme, array( 'http', 'https', 'relative' ), true ) ) { |
18 | 3638 |
$scheme = is_ssl() ? 'https' : 'http'; |
9 | 3639 |
} |
3640 |
||
16 | 3641 |
if ( 'relative' === $scheme ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3642 |
$url = $current_network->path; |
9 | 3643 |
} else { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3644 |
$url = set_url_scheme( 'http://' . $current_network->domain . $current_network->path, $scheme ); |
9 | 3645 |
} |
3646 |
||
3647 |
if ( $path && is_string( $path ) ) { |
|
0 | 3648 |
$url .= ltrim( $path, '/' ); |
9 | 3649 |
} |
0 | 3650 |
|
5 | 3651 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3652 |
* Filters the network home URL. |
5 | 3653 |
* |
3654 |
* @since 3.0.0 |
|
3655 |
* |
|
3656 |
* @param string $url The complete network home URL including scheme and path. |
|
3657 |
* @param string $path Path relative to the network home URL. Blank string |
|
3658 |
* if no path is specified. |
|
3659 |
* @param string|null $orig_scheme Scheme to give the URL context. Accepts 'http', 'https', |
|
3660 |
* 'relative' or null. |
|
3661 |
*/ |
|
9 | 3662 |
return apply_filters( 'network_home_url', $url, $path, $orig_scheme ); |
0 | 3663 |
} |
3664 |
||
3665 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3666 |
* Retrieves the URL to the admin area for the network. |
0 | 3667 |
* |
3668 |
* @since 3.0.0 |
|
3669 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3670 |
* @param string $path Optional path relative to the admin URL. Default empty. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3671 |
* @param string $scheme Optional. The scheme to use. Default is 'admin', which obeys force_ssl_admin() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3672 |
* and is_ssl(). 'http' or 'https' can be passed to force those schemes. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3673 |
* @return string Admin URL link with optional path appended. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3674 |
*/ |
0 | 3675 |
function network_admin_url( $path = '', $scheme = 'admin' ) { |
9 | 3676 |
if ( ! is_multisite() ) { |
0 | 3677 |
return admin_url( $path, $scheme ); |
9 | 3678 |
} |
3679 |
||
3680 |
$url = network_site_url( 'wp-admin/network/', $scheme ); |
|
3681 |
||
3682 |
if ( $path && is_string( $path ) ) { |
|
3683 |
$url .= ltrim( $path, '/' ); |
|
3684 |
} |
|
0 | 3685 |
|
5 | 3686 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3687 |
* Filters the network admin URL. |
5 | 3688 |
* |
3689 |
* @since 3.0.0 |
|
18 | 3690 |
* @since 5.8.0 The `$scheme` parameter was added. |
5 | 3691 |
* |
18 | 3692 |
* @param string $url The complete network admin URL including scheme and path. |
3693 |
* @param string $path Path relative to the network admin URL. Blank string if |
|
3694 |
* no path is specified. |
|
3695 |
* @param string|null $scheme The scheme to use. Accepts 'http', 'https', |
|
3696 |
* 'admin', or null. Default is 'admin', which obeys force_ssl_admin() and is_ssl(). |
|
5 | 3697 |
*/ |
18 | 3698 |
return apply_filters( 'network_admin_url', $url, $path, $scheme ); |
0 | 3699 |
} |
3700 |
||
3701 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3702 |
* Retrieves the URL to the admin area for the current user. |
0 | 3703 |
* |
3704 |
* @since 3.0.0 |
|
3705 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3706 |
* @param string $path Optional. Path relative to the admin URL. Default empty. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3707 |
* @param string $scheme Optional. The scheme to use. Default is 'admin', which obeys force_ssl_admin() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3708 |
* and is_ssl(). 'http' or 'https' can be passed to force those schemes. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3709 |
* @return string Admin URL link with optional path appended. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3710 |
*/ |
0 | 3711 |
function user_admin_url( $path = '', $scheme = 'admin' ) { |
9 | 3712 |
$url = network_site_url( 'wp-admin/user/', $scheme ); |
3713 |
||
3714 |
if ( $path && is_string( $path ) ) { |
|
3715 |
$url .= ltrim( $path, '/' ); |
|
3716 |
} |
|
0 | 3717 |
|
5 | 3718 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3719 |
* Filters the user admin URL for the current user. |
5 | 3720 |
* |
3721 |
* @since 3.1.0 |
|
18 | 3722 |
* @since 5.8.0 The `$scheme` parameter was added. |
5 | 3723 |
* |
18 | 3724 |
* @param string $url The complete URL including scheme and path. |
3725 |
* @param string $path Path relative to the URL. Blank string if |
|
3726 |
* no path is specified. |
|
3727 |
* @param string|null $scheme The scheme to use. Accepts 'http', 'https', |
|
3728 |
* 'admin', or null. Default is 'admin', which obeys force_ssl_admin() and is_ssl(). |
|
5 | 3729 |
*/ |
18 | 3730 |
return apply_filters( 'user_admin_url', $url, $path, $scheme ); |
0 | 3731 |
} |
3732 |
||
3733 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3734 |
* Retrieves the URL to the admin area for either the current site or the network depending on context. |
0 | 3735 |
* |
3736 |
* @since 3.1.0 |
|
3737 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3738 |
* @param string $path Optional. Path relative to the admin URL. Default empty. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3739 |
* @param string $scheme Optional. The scheme to use. Default is 'admin', which obeys force_ssl_admin() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3740 |
* and is_ssl(). 'http' or 'https' can be passed to force those schemes. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3741 |
* @return string Admin URL link with optional path appended. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3742 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3743 |
function self_admin_url( $path = '', $scheme = 'admin' ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3744 |
if ( is_network_admin() ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3745 |
$url = network_admin_url( $path, $scheme ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3746 |
} elseif ( is_user_admin() ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3747 |
$url = user_admin_url( $path, $scheme ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3748 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3749 |
$url = admin_url( $path, $scheme ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3750 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3751 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3752 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3753 |
* Filters the admin URL for the current site or network depending on context. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3754 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3755 |
* @since 4.9.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3756 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3757 |
* @param string $url The complete URL including scheme and path. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3758 |
* @param string $path Path relative to the URL. Blank string if no path is specified. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3759 |
* @param string $scheme The scheme to use. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3760 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3761 |
return apply_filters( 'self_admin_url', $url, $path, $scheme ); |
0 | 3762 |
} |
3763 |
||
3764 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3765 |
* Sets the scheme for a URL. |
0 | 3766 |
* |
3767 |
* @since 3.4.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3768 |
* @since 4.4.0 The 'rest' scheme was added. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3769 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3770 |
* @param string $url Absolute URL that includes a scheme |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3771 |
* @param string|null $scheme Optional. Scheme to give $url. Currently 'http', 'https', 'login', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3772 |
* 'login_post', 'admin', 'relative', 'rest', 'rpc', or null. Default null. |
16 | 3773 |
* @return string URL with chosen scheme. |
0 | 3774 |
*/ |
3775 |
function set_url_scheme( $url, $scheme = null ) { |
|
3776 |
$orig_scheme = $scheme; |
|
5 | 3777 |
|
3778 |
if ( ! $scheme ) { |
|
3779 |
$scheme = is_ssl() ? 'https' : 'http'; |
|
16 | 3780 |
} elseif ( 'admin' === $scheme || 'login' === $scheme || 'login_post' === $scheme || 'rpc' === $scheme ) { |
5 | 3781 |
$scheme = is_ssl() || force_ssl_admin() ? 'https' : 'http'; |
16 | 3782 |
} elseif ( 'http' !== $scheme && 'https' !== $scheme && 'relative' !== $scheme ) { |
5 | 3783 |
$scheme = is_ssl() ? 'https' : 'http'; |
0 | 3784 |
} |
3785 |
||
3786 |
$url = trim( $url ); |
|
9 | 3787 |
if ( substr( $url, 0, 2 ) === '//' ) { |
0 | 3788 |
$url = 'http:' . $url; |
9 | 3789 |
} |
0 | 3790 |
|
16 | 3791 |
if ( 'relative' === $scheme ) { |
0 | 3792 |
$url = ltrim( preg_replace( '#^\w+://[^/]*#', '', $url ) ); |
16 | 3793 |
if ( '' !== $url && '/' === $url[0] ) { |
9 | 3794 |
$url = '/' . ltrim( $url, "/ \t\n\r\0\x0B" ); |
3795 |
} |
|
0 | 3796 |
} else { |
3797 |
$url = preg_replace( '#^\w+://#', $scheme . '://', $url ); |
|
3798 |
} |
|
3799 |
||
5 | 3800 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3801 |
* Filters the resulting URL after setting the scheme. |
5 | 3802 |
* |
3803 |
* @since 3.4.0 |
|
3804 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3805 |
* @param string $url The complete URL including scheme and path. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3806 |
* @param string $scheme Scheme applied to the URL. One of 'http', 'https', or 'relative'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3807 |
* @param string|null $orig_scheme Scheme requested for the URL. One of 'http', 'https', 'login', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3808 |
* 'login_post', 'admin', 'relative', 'rest', 'rpc', or null. |
5 | 3809 |
*/ |
0 | 3810 |
return apply_filters( 'set_url_scheme', $url, $scheme, $orig_scheme ); |
3811 |
} |
|
3812 |
||
3813 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3814 |
* Retrieves the URL to the user's dashboard. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3815 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3816 |
* If a user does not belong to any site, the global user dashboard is used. If the user |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3817 |
* belongs to the current site, the dashboard for the current site is returned. If the user |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3818 |
* cannot edit the current site, the dashboard to the user's primary site is returned. |
0 | 3819 |
* |
3820 |
* @since 3.1.0 |
|
3821 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3822 |
* @param int $user_id Optional. User ID. Defaults to current user. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3823 |
* @param string $path Optional path relative to the dashboard. Use only paths known to |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3824 |
* both site and user admins. Default empty. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3825 |
* @param string $scheme The scheme to use. Default is 'admin', which obeys force_ssl_admin() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3826 |
* and is_ssl(). 'http' or 'https' can be passed to force those schemes. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3827 |
* @return string Dashboard URL link with optional path appended. |
0 | 3828 |
*/ |
5 | 3829 |
function get_dashboard_url( $user_id = 0, $path = '', $scheme = 'admin' ) { |
3830 |
$user_id = $user_id ? (int) $user_id : get_current_user_id(); |
|
0 | 3831 |
|
3832 |
$blogs = get_blogs_of_user( $user_id ); |
|
16 | 3833 |
|
9 | 3834 |
if ( is_multisite() && ! user_can( $user_id, 'manage_network' ) && empty( $blogs ) ) { |
0 | 3835 |
$url = user_admin_url( $path, $scheme ); |
3836 |
} elseif ( ! is_multisite() ) { |
|
3837 |
$url = admin_url( $path, $scheme ); |
|
3838 |
} else { |
|
3839 |
$current_blog = get_current_blog_id(); |
|
16 | 3840 |
|
3841 |
if ( $current_blog && ( user_can( $user_id, 'manage_network' ) || in_array( $current_blog, array_keys( $blogs ), true ) ) ) { |
|
0 | 3842 |
$url = admin_url( $path, $scheme ); |
3843 |
} else { |
|
3844 |
$active = get_active_blog_for_user( $user_id ); |
|
9 | 3845 |
if ( $active ) { |
0 | 3846 |
$url = get_admin_url( $active->blog_id, $path, $scheme ); |
9 | 3847 |
} else { |
0 | 3848 |
$url = user_admin_url( $path, $scheme ); |
9 | 3849 |
} |
0 | 3850 |
} |
3851 |
} |
|
3852 |
||
5 | 3853 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3854 |
* Filters the dashboard URL for a user. |
5 | 3855 |
* |
3856 |
* @since 3.1.0 |
|
3857 |
* |
|
3858 |
* @param string $url The complete URL including scheme and path. |
|
3859 |
* @param int $user_id The user ID. |
|
3860 |
* @param string $path Path relative to the URL. Blank string if no path is specified. |
|
3861 |
* @param string $scheme Scheme to give the URL context. Accepts 'http', 'https', 'login', |
|
3862 |
* 'login_post', 'admin', 'relative' or null. |
|
3863 |
*/ |
|
9 | 3864 |
return apply_filters( 'user_dashboard_url', $url, $user_id, $path, $scheme ); |
0 | 3865 |
} |
3866 |
||
3867 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3868 |
* Retrieves the URL to the user's profile editor. |
0 | 3869 |
* |
3870 |
* @since 3.1.0 |
|
3871 |
* |
|
5 | 3872 |
* @param int $user_id Optional. User ID. Defaults to current user. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3873 |
* @param string $scheme Optional. The scheme to use. Default is 'admin', which obeys force_ssl_admin() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3874 |
* and is_ssl(). 'http' or 'https' can be passed to force those schemes. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3875 |
* @return string Dashboard URL link with optional path appended. |
0 | 3876 |
*/ |
5 | 3877 |
function get_edit_profile_url( $user_id = 0, $scheme = 'admin' ) { |
3878 |
$user_id = $user_id ? (int) $user_id : get_current_user_id(); |
|
0 | 3879 |
|
9 | 3880 |
if ( is_user_admin() ) { |
0 | 3881 |
$url = user_admin_url( 'profile.php', $scheme ); |
9 | 3882 |
} elseif ( is_network_admin() ) { |
0 | 3883 |
$url = network_admin_url( 'profile.php', $scheme ); |
9 | 3884 |
} else { |
5 | 3885 |
$url = get_dashboard_url( $user_id, 'profile.php', $scheme ); |
9 | 3886 |
} |
5 | 3887 |
|
3888 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3889 |
* Filters the URL for a user's profile editor. |
5 | 3890 |
* |
3891 |
* @since 3.1.0 |
|
3892 |
* |
|
3893 |
* @param string $url The complete URL including scheme and path. |
|
3894 |
* @param int $user_id The user ID. |
|
3895 |
* @param string $scheme Scheme to give the URL context. Accepts 'http', 'https', 'login', |
|
3896 |
* 'login_post', 'admin', 'relative' or null. |
|
3897 |
*/ |
|
9 | 3898 |
return apply_filters( 'edit_profile_url', $url, $user_id, $scheme ); |
0 | 3899 |
} |
3900 |
||
3901 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3902 |
* Returns the canonical URL for a post. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3903 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3904 |
* When the post is the same as the current requested page the function will handle the |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3905 |
* pagination arguments too. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3906 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3907 |
* @since 4.6.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3908 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3909 |
* @param int|WP_Post $post Optional. Post ID or object. Default is global `$post`. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3910 |
* @return string|false The canonical URL, or false if the post does not exist or has not |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3911 |
* been published yet. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3912 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3913 |
function wp_get_canonical_url( $post = null ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3914 |
$post = get_post( $post ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3915 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3916 |
if ( ! $post ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3917 |
return false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3918 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3919 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3920 |
if ( 'publish' !== $post->post_status ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3921 |
return false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3922 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3923 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3924 |
$canonical_url = get_permalink( $post ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3925 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3926 |
// If a canonical is being generated for the current page, make sure it has pagination if needed. |
16 | 3927 |
if ( get_queried_object_id() === $post->ID ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3928 |
$page = get_query_var( 'page', 0 ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3929 |
if ( $page >= 2 ) { |
16 | 3930 |
if ( ! get_option( 'permalink_structure' ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3931 |
$canonical_url = add_query_arg( 'page', $page, $canonical_url ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3932 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3933 |
$canonical_url = trailingslashit( $canonical_url ) . user_trailingslashit( $page, 'single_paged' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3934 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3935 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3936 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3937 |
$cpage = get_query_var( 'cpage', 0 ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3938 |
if ( $cpage ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3939 |
$canonical_url = get_comments_pagenum_link( $cpage ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3940 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3941 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3942 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3943 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3944 |
* Filters the canonical URL for a post. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3945 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3946 |
* @since 4.6.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3947 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3948 |
* @param string $canonical_url The post's canonical URL. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3949 |
* @param WP_Post $post Post object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3950 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3951 |
return apply_filters( 'get_canonical_url', $canonical_url, $post ); |
0 | 3952 |
} |
3953 |
||
3954 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3955 |
* Outputs rel=canonical for singular queries. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3956 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3957 |
* @since 2.9.0 |
9 | 3958 |
* @since 4.6.0 Adjusted to use `wp_get_canonical_url()`. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3959 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3960 |
function rel_canonical() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3961 |
if ( ! is_singular() ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3962 |
return; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3963 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3964 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3965 |
$id = get_queried_object_id(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3966 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3967 |
if ( 0 === $id ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3968 |
return; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3969 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3970 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3971 |
$url = wp_get_canonical_url( $id ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3972 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3973 |
if ( ! empty( $url ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3974 |
echo '<link rel="canonical" href="' . esc_url( $url ) . '" />' . "\n"; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3975 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3976 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3977 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3978 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3979 |
* Returns a shortlink for a post, page, attachment, or site. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3980 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3981 |
* This function exists to provide a shortlink tag that all themes and plugins can target. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3982 |
* A plugin must hook in to provide the actual shortlinks. Default shortlink support is |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3983 |
* limited to providing ?p= style links for posts. Plugins can short-circuit this function |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3984 |
* via the {@see 'pre_get_shortlink'} filter or filter the output via the {@see 'get_shortlink'} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3985 |
* filter. |
0 | 3986 |
* |
9 | 3987 |
* @since 3.0.0 |
0 | 3988 |
* |
16 | 3989 |
* @param int $id Optional. A post or site ID. Default is 0, which means the current post or site. |
19 | 3990 |
* @param string $context Optional. Whether the ID is a 'site' ID, 'post' ID, or 'media' ID. If 'post', |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3991 |
* the post_type of the post is consulted. If 'query', the current query is consulted |
16 | 3992 |
* to determine the ID and context. Default 'post'. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3993 |
* @param bool $allow_slugs Optional. Whether to allow post slugs in the shortlink. It is up to the plugin how |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3994 |
* and whether to honor this. Default true. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3995 |
* @return string A shortlink or an empty string if no shortlink exists for the requested resource or if shortlinks |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3996 |
* are not enabled. |
0 | 3997 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3998 |
function wp_get_shortlink( $id = 0, $context = 'post', $allow_slugs = true ) { |
5 | 3999 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4000 |
* Filters whether to preempt generating a shortlink for the given post. |
5 | 4001 |
* |
16 | 4002 |
* Returning a truthy value from the filter will effectively short-circuit |
4003 |
* the shortlink generation process, returning that value instead. |
|
5 | 4004 |
* |
4005 |
* @since 3.0.0 |
|
4006 |
* |
|
16 | 4007 |
* @param false|string $return Short-circuit return value. Either false or a URL string. |
4008 |
* @param int $id Post ID, or 0 for the current post. |
|
4009 |
* @param string $context The context for the link. One of 'post' or 'query', |
|
4010 |
* @param bool $allow_slugs Whether to allow post slugs in the shortlink. |
|
5 | 4011 |
*/ |
4012 |
$shortlink = apply_filters( 'pre_get_shortlink', false, $id, $context, $allow_slugs ); |
|
4013 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4014 |
if ( false !== $shortlink ) { |
0 | 4015 |
return $shortlink; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4016 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4017 |
|
0 | 4018 |
$post_id = 0; |
16 | 4019 |
if ( 'query' === $context && is_singular() ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4020 |
$post_id = get_queried_object_id(); |
9 | 4021 |
$post = get_post( $post_id ); |
16 | 4022 |
} elseif ( 'post' === $context ) { |
0 | 4023 |
$post = get_post( $id ); |
9 | 4024 |
if ( ! empty( $post->ID ) ) { |
0 | 4025 |
$post_id = $post->ID; |
9 | 4026 |
} |
0 | 4027 |
} |
4028 |
||
4029 |
$shortlink = ''; |
|
4030 |
||
16 | 4031 |
// Return `?p=` link for all public post types. |
0 | 4032 |
if ( ! empty( $post_id ) ) { |
4033 |
$post_type = get_post_type_object( $post->post_type ); |
|
5 | 4034 |
|
16 | 4035 |
if ( 'page' === $post->post_type && get_option( 'page_on_front' ) == $post->ID && 'page' === get_option( 'show_on_front' ) ) { |
5 | 4036 |
$shortlink = home_url( '/' ); |
18 | 4037 |
} elseif ( $post_type && $post_type->public ) { |
5 | 4038 |
$shortlink = home_url( '?p=' . $post_id ); |
4039 |
} |
|
0 | 4040 |
} |
4041 |
||
5 | 4042 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4043 |
* Filters the shortlink for a post. |
5 | 4044 |
* |
4045 |
* @since 3.0.0 |
|
4046 |
* |
|
4047 |
* @param string $shortlink Shortlink URL. |
|
4048 |
* @param int $id Post ID, or 0 for the current post. |
|
4049 |
* @param string $context The context for the link. One of 'post' or 'query', |
|
4050 |
* @param bool $allow_slugs Whether to allow post slugs in the shortlink. Not used by default. |
|
4051 |
*/ |
|
4052 |
return apply_filters( 'get_shortlink', $shortlink, $id, $context, $allow_slugs ); |
|
0 | 4053 |
} |
4054 |
||
4055 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4056 |
* Injects rel=shortlink into the head if a shortlink is defined for the current page. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4057 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4058 |
* Attached to the {@see 'wp_head'} action. |
0 | 4059 |
* |
4060 |
* @since 3.0.0 |
|
4061 |
*/ |
|
4062 |
function wp_shortlink_wp_head() { |
|
4063 |
$shortlink = wp_get_shortlink( 0, 'query' ); |
|
4064 |
||
9 | 4065 |
if ( empty( $shortlink ) ) { |
0 | 4066 |
return; |
9 | 4067 |
} |
0 | 4068 |
|
4069 |
echo "<link rel='shortlink' href='" . esc_url( $shortlink ) . "' />\n"; |
|
4070 |
} |
|
4071 |
||
4072 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4073 |
* Sends a Link: rel=shortlink header if a shortlink is defined for the current page. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4074 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4075 |
* Attached to the {@see 'wp'} action. |
0 | 4076 |
* |
4077 |
* @since 3.0.0 |
|
4078 |
*/ |
|
4079 |
function wp_shortlink_header() { |
|
9 | 4080 |
if ( headers_sent() ) { |
0 | 4081 |
return; |
9 | 4082 |
} |
4083 |
||
4084 |
$shortlink = wp_get_shortlink( 0, 'query' ); |
|
4085 |
||
4086 |
if ( empty( $shortlink ) ) { |
|
0 | 4087 |
return; |
9 | 4088 |
} |
4089 |
||
4090 |
header( 'Link: <' . $shortlink . '>; rel=shortlink', false ); |
|
0 | 4091 |
} |
4092 |
||
4093 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4094 |
* Displays the shortlink for a post. |
0 | 4095 |
* |
4096 |
* Must be called from inside "The Loop" |
|
4097 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4098 |
* Call like the_shortlink( __( 'Shortlinkage FTW' ) ) |
0 | 4099 |
* |
4100 |
* @since 3.0.0 |
|
4101 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4102 |
* @param string $text Optional The link text or HTML to be displayed. Defaults to 'This is the short link.' |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4103 |
* @param string $title Optional The tooltip for the link. Must be sanitized. Defaults to the sanitized post title. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4104 |
* @param string $before Optional HTML to display before the link. Default empty. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4105 |
* @param string $after Optional HTML to display after the link. Default empty. |
0 | 4106 |
*/ |
4107 |
function the_shortlink( $text = '', $title = '', $before = '', $after = '' ) { |
|
4108 |
$post = get_post(); |
|
4109 |
||
9 | 4110 |
if ( empty( $text ) ) { |
4111 |
$text = __( 'This is the short link.' ); |
|
4112 |
} |
|
4113 |
||
4114 |
if ( empty( $title ) ) { |
|
0 | 4115 |
$title = the_title_attribute( array( 'echo' => false ) ); |
9 | 4116 |
} |
0 | 4117 |
|
4118 |
$shortlink = wp_get_shortlink( $post->ID ); |
|
4119 |
||
9 | 4120 |
if ( ! empty( $shortlink ) ) { |
0 | 4121 |
$link = '<a rel="shortlink" href="' . esc_url( $shortlink ) . '" title="' . $title . '">' . $text . '</a>'; |
5 | 4122 |
|
4123 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4124 |
* Filters the short link anchor tag for a post. |
5 | 4125 |
* |
4126 |
* @since 3.0.0 |
|
4127 |
* |
|
4128 |
* @param string $link Shortlink anchor tag. |
|
4129 |
* @param string $shortlink Shortlink URL. |
|
4130 |
* @param string $text Shortlink's text. |
|
4131 |
* @param string $title Shortlink's title attribute. |
|
4132 |
*/ |
|
0 | 4133 |
$link = apply_filters( 'the_shortlink', $link, $shortlink, $text, $title ); |
4134 |
echo $before, $link, $after; |
|
4135 |
} |
|
4136 |
} |
|
5 | 4137 |
|
4138 |
||
4139 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4140 |
* Retrieves the avatar URL. |
5 | 4141 |
* |
4142 |
* @since 4.2.0 |
|
4143 |
* |
|
4144 |
* @param mixed $id_or_email The Gravatar to retrieve a URL for. Accepts a user_id, gravatar md5 hash, |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4145 |
* user email, WP_User object, WP_Post object, or WP_Comment object. |
5 | 4146 |
* @param array $args { |
4147 |
* Optional. Arguments to return instead of the default arguments. |
|
4148 |
* |
|
4149 |
* @type int $size Height and width of the avatar in pixels. Default 96. |
|
4150 |
* @type string $default URL for the default image or a default type. Accepts '404' (return |
|
4151 |
* a 404 instead of a default image), 'retro' (8bit), 'monsterid' (monster), |
|
4152 |
* 'wavatar' (cartoon face), 'indenticon' (the "quilt"), 'mystery', 'mm', |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4153 |
* or 'mysteryman' (The Oyster Man), 'blank' (transparent GIF), or |
5 | 4154 |
* 'gravatar_default' (the Gravatar logo). Default is the value of the |
4155 |
* 'avatar_default' option, with a fallback of 'mystery'. |
|
4156 |
* @type bool $force_default Whether to always show the default image, never the Gravatar. Default false. |
|
4157 |
* @type string $rating What rating to display avatars up to. Accepts 'G', 'PG', 'R', 'X', and are |
|
4158 |
* judged in that order. Default is the value of the 'avatar_rating' option. |
|
4159 |
* @type string $scheme URL scheme to use. See set_url_scheme() for accepted values. |
|
4160 |
* Default null. |
|
4161 |
* @type array $processed_args When the function returns, the value will be the processed/sanitized $args |
|
4162 |
* plus a "found_avatar" guess. Pass as a reference. Default null. |
|
4163 |
* } |
|
16 | 4164 |
* @return string|false The URL of the avatar on success, false on failure. |
5 | 4165 |
*/ |
4166 |
function get_avatar_url( $id_or_email, $args = null ) { |
|
4167 |
$args = get_avatar_data( $id_or_email, $args ); |
|
4168 |
return $args['url']; |
|
4169 |
} |
|
4170 |
||
9 | 4171 |
|
4172 |
/** |
|
4173 |
* Check if this comment type allows avatars to be retrieved. |
|
4174 |
* |
|
4175 |
* @since 5.1.0 |
|
4176 |
* |
|
4177 |
* @param string $comment_type Comment type to check. |
|
4178 |
* @return bool Whether the comment type is allowed for retrieving avatars. |
|
4179 |
*/ |
|
4180 |
function is_avatar_comment_type( $comment_type ) { |
|
4181 |
/** |
|
4182 |
* Filters the list of allowed comment types for retrieving avatars. |
|
4183 |
* |
|
4184 |
* @since 3.0.0 |
|
4185 |
* |
|
4186 |
* @param array $types An array of content types. Default only contains 'comment'. |
|
4187 |
*/ |
|
4188 |
$allowed_comment_types = apply_filters( 'get_avatar_comment_types', array( 'comment' ) ); |
|
4189 |
||
4190 |
return in_array( $comment_type, (array) $allowed_comment_types, true ); |
|
4191 |
} |
|
4192 |
||
4193 |
||
5 | 4194 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4195 |
* Retrieves default data about the avatar. |
5 | 4196 |
* |
4197 |
* @since 4.2.0 |
|
4198 |
* |
|
16 | 4199 |
* @param mixed $id_or_email The Gravatar to retrieve. Accepts a user ID, Gravatar MD5 hash, |
4200 |
* user email, WP_User object, WP_Post object, or WP_Comment object. |
|
5 | 4201 |
* @param array $args { |
4202 |
* Optional. Arguments to return instead of the default arguments. |
|
4203 |
* |
|
4204 |
* @type int $size Height and width of the avatar image file in pixels. Default 96. |
|
4205 |
* @type int $height Display height of the avatar in pixels. Defaults to $size. |
|
4206 |
* @type int $width Display width of the avatar in pixels. Defaults to $size. |
|
4207 |
* @type string $default URL for the default image or a default type. Accepts '404' (return |
|
4208 |
* a 404 instead of a default image), 'retro' (8bit), 'monsterid' (monster), |
|
4209 |
* 'wavatar' (cartoon face), 'indenticon' (the "quilt"), 'mystery', 'mm', |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4210 |
* or 'mysteryman' (The Oyster Man), 'blank' (transparent GIF), or |
5 | 4211 |
* 'gravatar_default' (the Gravatar logo). Default is the value of the |
4212 |
* 'avatar_default' option, with a fallback of 'mystery'. |
|
4213 |
* @type bool $force_default Whether to always show the default image, never the Gravatar. Default false. |
|
4214 |
* @type string $rating What rating to display avatars up to. Accepts 'G', 'PG', 'R', 'X', and are |
|
4215 |
* judged in that order. Default is the value of the 'avatar_rating' option. |
|
4216 |
* @type string $scheme URL scheme to use. See set_url_scheme() for accepted values. |
|
4217 |
* Default null. |
|
4218 |
* @type array $processed_args When the function returns, the value will be the processed/sanitized $args |
|
4219 |
* plus a "found_avatar" guess. Pass as a reference. Default null. |
|
4220 |
* @type string $extra_attr HTML attributes to insert in the IMG element. Is not sanitized. Default empty. |
|
4221 |
* } |
|
16 | 4222 |
* @return array { |
5 | 4223 |
* Along with the arguments passed in `$args`, this will contain a couple of extra arguments. |
4224 |
* |
|
4225 |
* @type bool $found_avatar True if we were able to find an avatar for this user, |
|
4226 |
* false or not set if we couldn't. |
|
4227 |
* @type string $url The URL of the avatar we found. |
|
4228 |
* } |
|
4229 |
*/ |
|
4230 |
function get_avatar_data( $id_or_email, $args = null ) { |
|
9 | 4231 |
$args = wp_parse_args( |
4232 |
$args, |
|
4233 |
array( |
|
4234 |
'size' => 96, |
|
4235 |
'height' => null, |
|
4236 |
'width' => null, |
|
4237 |
'default' => get_option( 'avatar_default', 'mystery' ), |
|
4238 |
'force_default' => false, |
|
4239 |
'rating' => get_option( 'avatar_rating' ), |
|
4240 |
'scheme' => null, |
|
16 | 4241 |
'processed_args' => null, // If used, should be a reference. |
9 | 4242 |
'extra_attr' => '', |
4243 |
) |
|
4244 |
); |
|
5 | 4245 |
|
4246 |
if ( is_numeric( $args['size'] ) ) { |
|
4247 |
$args['size'] = absint( $args['size'] ); |
|
4248 |
if ( ! $args['size'] ) { |
|
4249 |
$args['size'] = 96; |
|
4250 |
} |
|
4251 |
} else { |
|
4252 |
$args['size'] = 96; |
|
4253 |
} |
|
4254 |
||
4255 |
if ( is_numeric( $args['height'] ) ) { |
|
4256 |
$args['height'] = absint( $args['height'] ); |
|
4257 |
if ( ! $args['height'] ) { |
|
4258 |
$args['height'] = $args['size']; |
|
4259 |
} |
|
4260 |
} else { |
|
4261 |
$args['height'] = $args['size']; |
|
4262 |
} |
|
4263 |
||
4264 |
if ( is_numeric( $args['width'] ) ) { |
|
4265 |
$args['width'] = absint( $args['width'] ); |
|
4266 |
if ( ! $args['width'] ) { |
|
4267 |
$args['width'] = $args['size']; |
|
4268 |
} |
|
4269 |
} else { |
|
4270 |
$args['width'] = $args['size']; |
|
4271 |
} |
|
4272 |
||
4273 |
if ( empty( $args['default'] ) ) { |
|
4274 |
$args['default'] = get_option( 'avatar_default', 'mystery' ); |
|
4275 |
} |
|
4276 |
||
4277 |
switch ( $args['default'] ) { |
|
9 | 4278 |
case 'mm': |
4279 |
case 'mystery': |
|
4280 |
case 'mysteryman': |
|
5 | 4281 |
$args['default'] = 'mm'; |
4282 |
break; |
|
9 | 4283 |
case 'gravatar_default': |
5 | 4284 |
$args['default'] = false; |
4285 |
break; |
|
4286 |
} |
|
4287 |
||
4288 |
$args['force_default'] = (bool) $args['force_default']; |
|
4289 |
||
4290 |
$args['rating'] = strtolower( $args['rating'] ); |
|
4291 |
||
4292 |
$args['found_avatar'] = false; |
|
4293 |
||
4294 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4295 |
* Filters whether to retrieve the avatar URL early. |
5 | 4296 |
* |
4297 |
* Passing a non-null value in the 'url' member of the return array will |
|
4298 |
* effectively short circuit get_avatar_data(), passing the value through |
|
4299 |
* the {@see 'get_avatar_data'} filter and returning early. |
|
4300 |
* |
|
4301 |
* @since 4.2.0 |
|
4302 |
* |
|
16 | 4303 |
* @param array $args Arguments passed to get_avatar_data(), after processing. |
4304 |
* @param mixed $id_or_email The Gravatar to retrieve. Accepts a user ID, Gravatar MD5 hash, |
|
4305 |
* user email, WP_User object, WP_Post object, or WP_Comment object. |
|
5 | 4306 |
*/ |
4307 |
$args = apply_filters( 'pre_get_avatar_data', $args, $id_or_email ); |
|
4308 |
||
9 | 4309 |
if ( isset( $args['url'] ) ) { |
5 | 4310 |
/** This filter is documented in wp-includes/link-template.php */ |
4311 |
return apply_filters( 'get_avatar_data', $args, $id_or_email ); |
|
4312 |
} |
|
4313 |
||
4314 |
$email_hash = ''; |
|
16 | 4315 |
$user = false; |
4316 |
$email = false; |
|
5 | 4317 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4318 |
if ( is_object( $id_or_email ) && isset( $id_or_email->comment_ID ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4319 |
$id_or_email = get_comment( $id_or_email ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4320 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4321 |
|
5 | 4322 |
// Process the user identifier. |
4323 |
if ( is_numeric( $id_or_email ) ) { |
|
4324 |
$user = get_user_by( 'id', absint( $id_or_email ) ); |
|
4325 |
} elseif ( is_string( $id_or_email ) ) { |
|
4326 |
if ( strpos( $id_or_email, '@md5.gravatar.com' ) ) { |
|
16 | 4327 |
// MD5 hash. |
5 | 4328 |
list( $email_hash ) = explode( '@', $id_or_email ); |
4329 |
} else { |
|
16 | 4330 |
// Email address. |
5 | 4331 |
$email = $id_or_email; |
4332 |
} |
|
4333 |
} elseif ( $id_or_email instanceof WP_User ) { |
|
16 | 4334 |
// User object. |
5 | 4335 |
$user = $id_or_email; |
4336 |
} elseif ( $id_or_email instanceof WP_Post ) { |
|
16 | 4337 |
// Post object. |
5 | 4338 |
$user = get_user_by( 'id', (int) $id_or_email->post_author ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4339 |
} elseif ( $id_or_email instanceof WP_Comment ) { |
9 | 4340 |
if ( ! is_avatar_comment_type( get_comment_type( $id_or_email ) ) ) { |
5 | 4341 |
$args['url'] = false; |
4342 |
/** This filter is documented in wp-includes/link-template.php */ |
|
4343 |
return apply_filters( 'get_avatar_data', $args, $id_or_email ); |
|
4344 |
} |
|
4345 |
||
4346 |
if ( ! empty( $id_or_email->user_id ) ) { |
|
4347 |
$user = get_user_by( 'id', (int) $id_or_email->user_id ); |
|
4348 |
} |
|
4349 |
if ( ( ! $user || is_wp_error( $user ) ) && ! empty( $id_or_email->comment_author_email ) ) { |
|
4350 |
$email = $id_or_email->comment_author_email; |
|
4351 |
} |
|
4352 |
} |
|
4353 |
||
4354 |
if ( ! $email_hash ) { |
|
4355 |
if ( $user ) { |
|
4356 |
$email = $user->user_email; |
|
4357 |
} |
|
4358 |
||
4359 |
if ( $email ) { |
|
4360 |
$email_hash = md5( strtolower( trim( $email ) ) ); |
|
4361 |
} |
|
4362 |
} |
|
4363 |
||
4364 |
if ( $email_hash ) { |
|
4365 |
$args['found_avatar'] = true; |
|
9 | 4366 |
$gravatar_server = hexdec( $email_hash[0] ) % 3; |
5 | 4367 |
} else { |
4368 |
$gravatar_server = rand( 0, 2 ); |
|
4369 |
} |
|
4370 |
||
4371 |
$url_args = array( |
|
4372 |
's' => $args['size'], |
|
4373 |
'd' => $args['default'], |
|
4374 |
'f' => $args['force_default'] ? 'y' : false, |
|
4375 |
'r' => $args['rating'], |
|
4376 |
); |
|
4377 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4378 |
if ( is_ssl() ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4379 |
$url = 'https://secure.gravatar.com/avatar/' . $email_hash; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4380 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4381 |
$url = sprintf( 'http://%d.gravatar.com/avatar/%s', $gravatar_server, $email_hash ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4382 |
} |
5 | 4383 |
|
4384 |
$url = add_query_arg( |
|
4385 |
rawurlencode_deep( array_filter( $url_args ) ), |
|
4386 |
set_url_scheme( $url, $args['scheme'] ) |
|
4387 |
); |
|
4388 |
||
4389 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4390 |
* Filters the avatar URL. |
5 | 4391 |
* |
4392 |
* @since 4.2.0 |
|
4393 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4394 |
* @param string $url The URL of the avatar. |
16 | 4395 |
* @param mixed $id_or_email The Gravatar to retrieve. Accepts a user ID, Gravatar MD5 hash, |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4396 |
* user email, WP_User object, WP_Post object, or WP_Comment object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4397 |
* @param array $args Arguments passed to get_avatar_data(), after processing. |
5 | 4398 |
*/ |
4399 |
$args['url'] = apply_filters( 'get_avatar_url', $url, $id_or_email, $args ); |
|
4400 |
||
4401 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4402 |
* Filters the avatar data. |
5 | 4403 |
* |
4404 |
* @since 4.2.0 |
|
4405 |
* |
|
16 | 4406 |
* @param array $args Arguments passed to get_avatar_data(), after processing. |
4407 |
* @param mixed $id_or_email The Gravatar to retrieve. Accepts a user ID, Gravatar MD5 hash, |
|
4408 |
* user email, WP_User object, WP_Post object, or WP_Comment object. |
|
5 | 4409 |
*/ |
4410 |
return apply_filters( 'get_avatar_data', $args, $id_or_email ); |
|
4411 |
} |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4412 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4413 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4414 |
* Retrieves the URL of a file in the theme. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4415 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4416 |
* Searches in the stylesheet directory before the template directory so themes |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4417 |
* which inherit from a parent theme can just override one file. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4418 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4419 |
* @since 4.7.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4420 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4421 |
* @param string $file Optional. File to search for in the stylesheet directory. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4422 |
* @return string The URL of the file. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4423 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4424 |
function get_theme_file_uri( $file = '' ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4425 |
$file = ltrim( $file, '/' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4426 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4427 |
if ( empty( $file ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4428 |
$url = get_stylesheet_directory_uri(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4429 |
} elseif ( file_exists( get_stylesheet_directory() . '/' . $file ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4430 |
$url = get_stylesheet_directory_uri() . '/' . $file; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4431 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4432 |
$url = get_template_directory_uri() . '/' . $file; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4433 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4434 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4435 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4436 |
* Filters the URL to a file in the theme. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4437 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4438 |
* @since 4.7.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4439 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4440 |
* @param string $url The file URL. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4441 |
* @param string $file The requested file to search for. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4442 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4443 |
return apply_filters( 'theme_file_uri', $url, $file ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4444 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4445 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4446 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4447 |
* Retrieves the URL of a file in the parent theme. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4448 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4449 |
* @since 4.7.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4450 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4451 |
* @param string $file Optional. File to return the URL for in the template directory. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4452 |
* @return string The URL of the file. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4453 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4454 |
function get_parent_theme_file_uri( $file = '' ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4455 |
$file = ltrim( $file, '/' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4456 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4457 |
if ( empty( $file ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4458 |
$url = get_template_directory_uri(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4459 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4460 |
$url = get_template_directory_uri() . '/' . $file; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4461 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4462 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4463 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4464 |
* Filters the URL to a file in the parent theme. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4465 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4466 |
* @since 4.7.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4467 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4468 |
* @param string $url The file URL. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4469 |
* @param string $file The requested file to search for. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4470 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4471 |
return apply_filters( 'parent_theme_file_uri', $url, $file ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4472 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4473 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4474 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4475 |
* Retrieves the path of a file in the theme. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4476 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4477 |
* Searches in the stylesheet directory before the template directory so themes |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4478 |
* which inherit from a parent theme can just override one file. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4479 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4480 |
* @since 4.7.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4481 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4482 |
* @param string $file Optional. File to search for in the stylesheet directory. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4483 |
* @return string The path of the file. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4484 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4485 |
function get_theme_file_path( $file = '' ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4486 |
$file = ltrim( $file, '/' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4487 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4488 |
if ( empty( $file ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4489 |
$path = get_stylesheet_directory(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4490 |
} elseif ( file_exists( get_stylesheet_directory() . '/' . $file ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4491 |
$path = get_stylesheet_directory() . '/' . $file; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4492 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4493 |
$path = get_template_directory() . '/' . $file; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4494 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4495 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4496 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4497 |
* Filters the path to a file in the theme. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4498 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4499 |
* @since 4.7.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4500 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4501 |
* @param string $path The file path. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4502 |
* @param string $file The requested file to search for. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4503 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4504 |
return apply_filters( 'theme_file_path', $path, $file ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4505 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4506 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4507 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4508 |
* Retrieves the path of a file in the parent theme. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4509 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4510 |
* @since 4.7.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4511 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4512 |
* @param string $file Optional. File to return the path for in the template directory. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4513 |
* @return string The path of the file. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4514 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4515 |
function get_parent_theme_file_path( $file = '' ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4516 |
$file = ltrim( $file, '/' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4517 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4518 |
if ( empty( $file ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4519 |
$path = get_template_directory(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4520 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4521 |
$path = get_template_directory() . '/' . $file; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4522 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4523 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4524 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4525 |
* Filters the path to a file in the parent theme. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4526 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4527 |
* @since 4.7.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4528 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4529 |
* @param string $path The file path. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4530 |
* @param string $file The requested file to search for. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4531 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4532 |
return apply_filters( 'parent_theme_file_path', $path, $file ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4533 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4534 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4535 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4536 |
* Retrieves the URL to the privacy policy page. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4537 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4538 |
* @since 4.9.6 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4539 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4540 |
* @return string The URL to the privacy policy page. Empty string if it doesn't exist. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4541 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4542 |
function get_privacy_policy_url() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4543 |
$url = ''; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4544 |
$policy_page_id = (int) get_option( 'wp_page_for_privacy_policy' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4545 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4546 |
if ( ! empty( $policy_page_id ) && get_post_status( $policy_page_id ) === 'publish' ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4547 |
$url = (string) get_permalink( $policy_page_id ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4548 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4549 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4550 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4551 |
* Filters the URL of the privacy policy page. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4552 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4553 |
* @since 4.9.6 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4554 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4555 |
* @param string $url The URL to the privacy policy page. Empty string |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4556 |
* if it doesn't exist. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4557 |
* @param int $policy_page_id The ID of privacy policy page. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4558 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4559 |
return apply_filters( 'privacy_policy_url', $url, $policy_page_id ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4560 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4561 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4562 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4563 |
* Displays the privacy policy link with formatting, when applicable. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4564 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4565 |
* @since 4.9.6 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4566 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4567 |
* @param string $before Optional. Display before privacy policy link. Default empty. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4568 |
* @param string $after Optional. Display after privacy policy link. Default empty. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4569 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4570 |
function the_privacy_policy_link( $before = '', $after = '' ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4571 |
echo get_the_privacy_policy_link( $before, $after ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4572 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4573 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4574 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4575 |
* Returns the privacy policy link with formatting, when applicable. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4576 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4577 |
* @since 4.9.6 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4578 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4579 |
* @param string $before Optional. Display before privacy policy link. Default empty. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4580 |
* @param string $after Optional. Display after privacy policy link. Default empty. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4581 |
* @return string Markup for the link and surrounding elements. Empty string if it |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4582 |
* doesn't exist. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4583 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4584 |
function get_the_privacy_policy_link( $before = '', $after = '' ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4585 |
$link = ''; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4586 |
$privacy_policy_url = get_privacy_policy_url(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4587 |
$policy_page_id = (int) get_option( 'wp_page_for_privacy_policy' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4588 |
$page_title = ( $policy_page_id ) ? get_the_title( $policy_page_id ) : ''; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4589 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4590 |
if ( $privacy_policy_url && $page_title ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4591 |
$link = sprintf( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4592 |
'<a class="privacy-policy-link" href="%s">%s</a>', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4593 |
esc_url( $privacy_policy_url ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4594 |
esc_html( $page_title ) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4595 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4596 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4597 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4598 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4599 |
* Filters the privacy policy link. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4600 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4601 |
* @since 4.9.6 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4602 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4603 |
* @param string $link The privacy policy link. Empty string if it |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4604 |
* doesn't exist. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4605 |
* @param string $privacy_policy_url The URL of the privacy policy. Empty string |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4606 |
* if it doesn't exist. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4607 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4608 |
$link = apply_filters( 'the_privacy_policy_link', $link, $privacy_policy_url ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4609 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4610 |
if ( $link ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4611 |
return $before . $link . $after; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4612 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4613 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4614 |
return ''; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4615 |
} |