author | ymh <ymh.work@gmail.com> |
Wed, 21 Sep 2022 18:19:35 +0200 | |
changeset 18 | be944660c56a |
parent 16 | a86126ab1dd4 |
child 19 | 3d72ae0968f4 |
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 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
907 |
* @param int $cat_id Category ID. |
16 | 908 |
* @param string $feed Optional. Feed type. Possible values include 'rss2', 'atom'. |
909 |
* Default is the value of get_default_feed(). |
|
0 | 910 |
* @return string Link to the feed for the category specified by $cat_id. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
911 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
912 |
function get_category_feed_link( $cat_id, $feed = '' ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
913 |
return get_term_feed_link( $cat_id, '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 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
924 |
* @param int $term_id Term ID. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
925 |
* @param string $taxonomy Optional. Taxonomy of `$term_id`. Default 'category'. |
16 | 926 |
* @param string $feed Optional. Feed type. Possible values include 'rss2', 'atom'. |
927 |
* Default is the value of get_default_feed(). |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
928 |
* @return string|false Link to the feed for the term specified by $term_id and $taxonomy. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
929 |
*/ |
0 | 930 |
function get_term_feed_link( $term_id, $taxonomy = 'category', $feed = '' ) { |
9 | 931 |
$term_id = (int) $term_id; |
932 |
||
933 |
$term = get_term( $term_id, $taxonomy ); |
|
934 |
||
935 |
if ( empty( $term ) || is_wp_error( $term ) ) { |
|
0 | 936 |
return false; |
9 | 937 |
} |
938 |
||
939 |
if ( empty( $feed ) ) { |
|
0 | 940 |
$feed = get_default_feed(); |
9 | 941 |
} |
0 | 942 |
|
943 |
$permalink_structure = get_option( 'permalink_structure' ); |
|
944 |
||
16 | 945 |
if ( ! $permalink_structure ) { |
946 |
if ( 'category' === $taxonomy ) { |
|
9 | 947 |
$link = home_url( "?feed=$feed&cat=$term_id" ); |
16 | 948 |
} elseif ( 'post_tag' === $taxonomy ) { |
9 | 949 |
$link = home_url( "?feed=$feed&tag=$term->slug" ); |
0 | 950 |
} else { |
9 | 951 |
$t = get_taxonomy( $taxonomy ); |
952 |
$link = home_url( "?feed=$feed&$t->query_var=$term->slug" ); |
|
0 | 953 |
} |
954 |
} else { |
|
955 |
$link = get_term_link( $term_id, $term->taxonomy ); |
|
16 | 956 |
if ( get_default_feed() == $feed ) { |
0 | 957 |
$feed_link = 'feed'; |
9 | 958 |
} else { |
0 | 959 |
$feed_link = "feed/$feed"; |
9 | 960 |
} |
0 | 961 |
|
962 |
$link = trailingslashit( $link ) . user_trailingslashit( $feed_link, 'feed' ); |
|
963 |
} |
|
964 |
||
16 | 965 |
if ( 'category' === $taxonomy ) { |
5 | 966 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
967 |
* Filters the category feed link. |
5 | 968 |
* |
969 |
* @since 1.5.1 |
|
970 |
* |
|
971 |
* @param string $link The category feed link. |
|
16 | 972 |
* @param string $feed Feed type. Possible values include 'rss2', 'atom'. |
5 | 973 |
*/ |
0 | 974 |
$link = apply_filters( 'category_feed_link', $link, $feed ); |
16 | 975 |
} elseif ( 'post_tag' === $taxonomy ) { |
5 | 976 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
977 |
* Filters the post tag feed link. |
5 | 978 |
* |
979 |
* @since 2.3.0 |
|
980 |
* |
|
981 |
* @param string $link The tag feed link. |
|
16 | 982 |
* @param string $feed Feed type. Possible values include 'rss2', 'atom'. |
5 | 983 |
*/ |
0 | 984 |
$link = apply_filters( 'tag_feed_link', $link, $feed ); |
5 | 985 |
} else { |
986 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
987 |
* Filters the feed link for a taxonomy other than 'category' or 'post_tag'. |
5 | 988 |
* |
989 |
* @since 3.0.0 |
|
990 |
* |
|
16 | 991 |
* @param string $link The taxonomy feed link. |
992 |
* @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
|
993 |
* @param string $taxonomy The taxonomy name. |
5 | 994 |
*/ |
0 | 995 |
$link = apply_filters( 'taxonomy_feed_link', $link, $feed, $taxonomy ); |
5 | 996 |
} |
0 | 997 |
|
998 |
return $link; |
|
999 |
} |
|
1000 |
||
1001 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1002 |
* Retrieves the permalink for a tag feed. |
0 | 1003 |
* |
1004 |
* @since 2.3.0 |
|
1005 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1006 |
* @param int $tag_id Tag ID. |
16 | 1007 |
* @param string $feed Optional. Feed type. Possible values include 'rss2', 'atom'. |
1008 |
* Default is the value of get_default_feed(). |
|
5 | 1009 |
* @return string The feed permalink for the given tag. |
0 | 1010 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1011 |
function get_tag_feed_link( $tag_id, $feed = '' ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1012 |
return get_term_feed_link( $tag_id, 'post_tag', $feed ); |
0 | 1013 |
} |
1014 |
||
1015 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1016 |
* Retrieves the edit link for a tag. |
0 | 1017 |
* |
1018 |
* @since 2.7.0 |
|
1019 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1020 |
* @param int $tag_id Tag ID. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1021 |
* @param string $taxonomy Optional. Taxonomy slug. Default 'post_tag'. |
5 | 1022 |
* @return string The edit tag link URL for the given tag. |
0 | 1023 |
*/ |
1024 |
function get_edit_tag_link( $tag_id, $taxonomy = 'post_tag' ) { |
|
5 | 1025 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1026 |
* Filters the edit link for a tag (or term in another taxonomy). |
5 | 1027 |
* |
1028 |
* @since 2.7.0 |
|
1029 |
* |
|
1030 |
* @param string $link The term edit link. |
|
1031 |
*/ |
|
0 | 1032 |
return apply_filters( 'get_edit_tag_link', get_edit_term_link( $tag_id, $taxonomy ) ); |
1033 |
} |
|
1034 |
||
1035 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1036 |
* Displays or retrieves the edit link for a tag with formatting. |
0 | 1037 |
* |
1038 |
* @since 2.7.0 |
|
1039 |
* |
|
16 | 1040 |
* @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
|
1041 |
* @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
|
1042 |
* @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
|
1043 |
* @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
|
1044 |
* Default null. |
0 | 1045 |
*/ |
1046 |
function edit_tag_link( $link = '', $before = '', $after = '', $tag = null ) { |
|
1047 |
$link = edit_term_link( $link, '', '', $tag, false ); |
|
5 | 1048 |
|
1049 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1050 |
* Filters the anchor tag for the edit link for a tag (or term in another taxonomy). |
5 | 1051 |
* |
1052 |
* @since 2.7.0 |
|
1053 |
* |
|
1054 |
* @param string $link The anchor tag for the edit link. |
|
1055 |
*/ |
|
0 | 1056 |
echo $before . apply_filters( 'edit_tag_link', $link ) . $after; |
1057 |
} |
|
1058 |
||
1059 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1060 |
* Retrieves the URL for editing a given term. |
0 | 1061 |
* |
1062 |
* @since 3.1.0 |
|
16 | 1063 |
* @since 4.5.0 The `$taxonomy` parameter was made optional. |
0 | 1064 |
* |
5 | 1065 |
* @param int $term_id Term ID. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1066 |
* @param string $taxonomy Optional. Taxonomy. Defaults to the taxonomy of the term identified |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1067 |
* by `$term_id`. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1068 |
* @param string $object_type Optional. The object type. Used to highlight the proper post type |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1069 |
* menu on the linked page. Defaults to the first object_type associated |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1070 |
* with the taxonomy. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1071 |
* @return string|null The edit term link URL for the given term, or null on failure. |
0 | 1072 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1073 |
function get_edit_term_link( $term_id, $taxonomy = '', $object_type = '' ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1074 |
$term = get_term( $term_id, $taxonomy ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1075 |
if ( ! $term || is_wp_error( $term ) ) { |
0 | 1076 |
return; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1077 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1078 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1079 |
$tax = get_taxonomy( $term->taxonomy ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1080 |
if ( ! $tax || ! current_user_can( 'edit_term', $term->term_id ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1081 |
return; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1082 |
} |
0 | 1083 |
|
1084 |
$args = array( |
|
1085 |
'taxonomy' => $taxonomy, |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1086 |
'tag_ID' => $term->term_id, |
0 | 1087 |
); |
1088 |
||
5 | 1089 |
if ( $object_type ) { |
0 | 1090 |
$args['post_type'] = $object_type; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1091 |
} elseif ( ! empty( $tax->object_type ) ) { |
5 | 1092 |
$args['post_type'] = reset( $tax->object_type ); |
1093 |
} |
|
0 | 1094 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1095 |
if ( $tax->show_ui ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1096 |
$location = add_query_arg( $args, admin_url( 'term.php' ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1097 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1098 |
$location = ''; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1099 |
} |
0 | 1100 |
|
5 | 1101 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1102 |
* Filters the edit link for a term. |
5 | 1103 |
* |
1104 |
* @since 3.1.0 |
|
1105 |
* |
|
1106 |
* @param string $location The edit link. |
|
1107 |
* @param int $term_id Term ID. |
|
1108 |
* @param string $taxonomy Taxonomy name. |
|
1109 |
* @param string $object_type The object type (eg. the post type). |
|
1110 |
*/ |
|
0 | 1111 |
return apply_filters( 'get_edit_term_link', $location, $term_id, $taxonomy, $object_type ); |
1112 |
} |
|
1113 |
||
1114 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1115 |
* Displays or retrieves the edit term link with formatting. |
0 | 1116 |
* |
1117 |
* @since 3.1.0 |
|
1118 |
* |
|
16 | 1119 |
* @param string $link Optional. Anchor text. If empty, default is 'Edit This'. Default empty. |
1120 |
* @param string $before Optional. Display before edit link. Default empty. |
|
1121 |
* @param string $after Optional. Display after edit link. Default empty. |
|
1122 |
* @param WP_Term $term Optional. Term object. If null, the queried object will be inspected. Default null. |
|
1123 |
* @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
|
1124 |
* @return string|void HTML content. |
0 | 1125 |
*/ |
1126 |
function edit_term_link( $link = '', $before = '', $after = '', $term = null, $echo = true ) { |
|
9 | 1127 |
if ( is_null( $term ) ) { |
0 | 1128 |
$term = get_queried_object(); |
9 | 1129 |
} |
1130 |
||
1131 |
if ( ! $term ) { |
|
0 | 1132 |
return; |
9 | 1133 |
} |
0 | 1134 |
|
1135 |
$tax = get_taxonomy( $term->taxonomy ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1136 |
if ( ! current_user_can( 'edit_term', $term->term_id ) ) { |
0 | 1137 |
return; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1138 |
} |
0 | 1139 |
|
9 | 1140 |
if ( empty( $link ) ) { |
1141 |
$link = __( 'Edit This' ); |
|
1142 |
} |
|
0 | 1143 |
|
1144 |
$link = '<a href="' . get_edit_term_link( $term->term_id, $term->taxonomy ) . '">' . $link . '</a>'; |
|
5 | 1145 |
|
1146 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1147 |
* Filters the anchor tag for the edit link of a term. |
5 | 1148 |
* |
1149 |
* @since 3.1.0 |
|
1150 |
* |
|
1151 |
* @param string $link The anchor tag for the edit link. |
|
1152 |
* @param int $term_id Term ID. |
|
1153 |
*/ |
|
0 | 1154 |
$link = $before . apply_filters( 'edit_term_link', $link, $term->term_id ) . $after; |
1155 |
||
9 | 1156 |
if ( $echo ) { |
0 | 1157 |
echo $link; |
9 | 1158 |
} else { |
0 | 1159 |
return $link; |
9 | 1160 |
} |
0 | 1161 |
} |
1162 |
||
1163 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1164 |
* Retrieves the permalink for a search. |
5 | 1165 |
* |
16 | 1166 |
* @since 3.0.0 |
1167 |
* |
|
1168 |
* @global WP_Rewrite $wp_rewrite WordPress rewrite component. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1169 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1170 |
* @param string $query Optional. The query string to use. If empty the current query is used. Default empty. |
5 | 1171 |
* @return string The search permalink. |
1172 |
*/ |
|
0 | 1173 |
function get_search_link( $query = '' ) { |
1174 |
global $wp_rewrite; |
|
1175 |
||
9 | 1176 |
if ( empty( $query ) ) { |
0 | 1177 |
$search = get_search_query( false ); |
9 | 1178 |
} else { |
1179 |
$search = stripslashes( $query ); |
|
1180 |
} |
|
0 | 1181 |
|
1182 |
$permastruct = $wp_rewrite->get_search_permastruct(); |
|
1183 |
||
1184 |
if ( empty( $permastruct ) ) { |
|
9 | 1185 |
$link = home_url( '?s=' . urlencode( $search ) ); |
0 | 1186 |
} else { |
9 | 1187 |
$search = urlencode( $search ); |
1188 |
$search = str_replace( '%2F', '/', $search ); // %2F(/) is not valid within a URL, send it un-encoded. |
|
1189 |
$link = str_replace( '%search%', $search, $permastruct ); |
|
1190 |
$link = home_url( user_trailingslashit( $link, 'search' ) ); |
|
0 | 1191 |
} |
1192 |
||
5 | 1193 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1194 |
* Filters the search permalink. |
5 | 1195 |
* |
1196 |
* @since 3.0.0 |
|
1197 |
* |
|
1198 |
* @param string $link Search permalink. |
|
1199 |
* @param string $search The URL-encoded search term. |
|
1200 |
*/ |
|
0 | 1201 |
return apply_filters( 'search_link', $link, $search ); |
1202 |
} |
|
1203 |
||
1204 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1205 |
* Retrieves the permalink for the search results feed. |
0 | 1206 |
* |
1207 |
* @since 2.5.0 |
|
1208 |
* |
|
16 | 1209 |
* @global WP_Rewrite $wp_rewrite WordPress rewrite component. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1210 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1211 |
* @param string $search_query Optional. Search query. Default empty. |
16 | 1212 |
* @param string $feed Optional. Feed type. Possible values include 'rss2', 'atom'. |
1213 |
* Default is the value of get_default_feed(). |
|
5 | 1214 |
* @return string The search results feed permalink. |
0 | 1215 |
*/ |
9 | 1216 |
function get_search_feed_link( $search_query = '', $feed = '' ) { |
0 | 1217 |
global $wp_rewrite; |
9 | 1218 |
$link = get_search_link( $search_query ); |
1219 |
||
1220 |
if ( empty( $feed ) ) { |
|
0 | 1221 |
$feed = get_default_feed(); |
9 | 1222 |
} |
0 | 1223 |
|
1224 |
$permastruct = $wp_rewrite->get_search_permastruct(); |
|
1225 |
||
9 | 1226 |
if ( empty( $permastruct ) ) { |
1227 |
$link = add_query_arg( 'feed', $feed, $link ); |
|
0 | 1228 |
} else { |
9 | 1229 |
$link = trailingslashit( $link ); |
0 | 1230 |
$link .= "feed/$feed/"; |
1231 |
} |
|
1232 |
||
5 | 1233 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1234 |
* Filters the search feed link. |
5 | 1235 |
* |
1236 |
* @since 2.5.0 |
|
1237 |
* |
|
1238 |
* @param string $link Search feed link. |
|
16 | 1239 |
* @param string $feed Feed type. Possible values include 'rss2', 'atom'. |
5 | 1240 |
* @param string $type The search type. One of 'posts' or 'comments'. |
1241 |
*/ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1242 |
return apply_filters( 'search_feed_link', $link, $feed, 'posts' ); |
0 | 1243 |
} |
1244 |
||
1245 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1246 |
* Retrieves the permalink for the search results comments feed. |
0 | 1247 |
* |
1248 |
* @since 2.5.0 |
|
1249 |
* |
|
16 | 1250 |
* @global WP_Rewrite $wp_rewrite WordPress rewrite component. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1251 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1252 |
* @param string $search_query Optional. Search query. Default empty. |
16 | 1253 |
* @param string $feed Optional. Feed type. Possible values include 'rss2', 'atom'. |
1254 |
* Default is the value of get_default_feed(). |
|
5 | 1255 |
* @return string The comments feed search results permalink. |
0 | 1256 |
*/ |
9 | 1257 |
function get_search_comments_feed_link( $search_query = '', $feed = '' ) { |
0 | 1258 |
global $wp_rewrite; |
1259 |
||
9 | 1260 |
if ( empty( $feed ) ) { |
0 | 1261 |
$feed = get_default_feed(); |
9 | 1262 |
} |
1263 |
||
1264 |
$link = get_search_feed_link( $search_query, $feed ); |
|
0 | 1265 |
|
1266 |
$permastruct = $wp_rewrite->get_search_permastruct(); |
|
1267 |
||
9 | 1268 |
if ( empty( $permastruct ) ) { |
1269 |
$link = add_query_arg( 'feed', 'comments-' . $feed, $link ); |
|
1270 |
} else { |
|
1271 |
$link = add_query_arg( 'withcomments', 1, $link ); |
|
1272 |
} |
|
0 | 1273 |
|
5 | 1274 |
/** 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
|
1275 |
return apply_filters( 'search_feed_link', $link, $feed, 'comments' ); |
0 | 1276 |
} |
1277 |
||
1278 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1279 |
* Retrieves the permalink for a post type archive. |
0 | 1280 |
* |
1281 |
* @since 3.1.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1282 |
* @since 4.5.0 Support for posts was added. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1283 |
* |
16 | 1284 |
* @global WP_Rewrite $wp_rewrite WordPress rewrite component. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1285 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1286 |
* @param string $post_type Post type. |
18 | 1287 |
* @return string|false The post type archive permalink. False if the post type |
1288 |
* does not exist or does not have an archive. |
|
0 | 1289 |
*/ |
1290 |
function get_post_type_archive_link( $post_type ) { |
|
1291 |
global $wp_rewrite; |
|
16 | 1292 |
|
1293 |
$post_type_obj = get_post_type_object( $post_type ); |
|
1294 |
if ( ! $post_type_obj ) { |
|
0 | 1295 |
return false; |
9 | 1296 |
} |
0 | 1297 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1298 |
if ( 'post' === $post_type ) { |
9 | 1299 |
$show_on_front = get_option( 'show_on_front' ); |
1300 |
$page_for_posts = get_option( 'page_for_posts' ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1301 |
|
16 | 1302 |
if ( 'page' === $show_on_front && $page_for_posts ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1303 |
$link = get_permalink( $page_for_posts ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1304 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1305 |
$link = get_home_url(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1306 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1307 |
/** 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
|
1308 |
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
|
1309 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1310 |
|
9 | 1311 |
if ( ! $post_type_obj->has_archive ) { |
0 | 1312 |
return false; |
9 | 1313 |
} |
0 | 1314 |
|
1315 |
if ( get_option( 'permalink_structure' ) && is_array( $post_type_obj->rewrite ) ) { |
|
1316 |
$struct = ( true === $post_type_obj->has_archive ) ? $post_type_obj->rewrite['slug'] : $post_type_obj->has_archive; |
|
9 | 1317 |
if ( $post_type_obj->rewrite['with_front'] ) { |
0 | 1318 |
$struct = $wp_rewrite->front . $struct; |
9 | 1319 |
} else { |
0 | 1320 |
$struct = $wp_rewrite->root . $struct; |
9 | 1321 |
} |
0 | 1322 |
$link = home_url( user_trailingslashit( $struct, 'post_type_archive' ) ); |
1323 |
} else { |
|
1324 |
$link = home_url( '?post_type=' . $post_type ); |
|
1325 |
} |
|
1326 |
||
5 | 1327 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1328 |
* Filters the post type archive permalink. |
5 | 1329 |
* |
1330 |
* @since 3.1.0 |
|
1331 |
* |
|
1332 |
* @param string $link The post type archive permalink. |
|
1333 |
* @param string $post_type Post type name. |
|
1334 |
*/ |
|
0 | 1335 |
return apply_filters( 'post_type_archive_link', $link, $post_type ); |
1336 |
} |
|
1337 |
||
1338 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1339 |
* Retrieves the permalink for a post type archive feed. |
0 | 1340 |
* |
1341 |
* @since 3.1.0 |
|
1342 |
* |
|
18 | 1343 |
* @param string $post_type Post type. |
16 | 1344 |
* @param string $feed Optional. Feed type. Possible values include 'rss2', 'atom'. |
1345 |
* Default is the value of get_default_feed(). |
|
18 | 1346 |
* @return string|false The post type feed permalink. False if the post type |
1347 |
* does not exist or does not have an archive. |
|
0 | 1348 |
*/ |
1349 |
function get_post_type_archive_feed_link( $post_type, $feed = '' ) { |
|
1350 |
$default_feed = get_default_feed(); |
|
9 | 1351 |
if ( empty( $feed ) ) { |
0 | 1352 |
$feed = $default_feed; |
9 | 1353 |
} |
1354 |
||
16 | 1355 |
$link = get_post_type_archive_link( $post_type ); |
1356 |
if ( ! $link ) { |
|
0 | 1357 |
return false; |
9 | 1358 |
} |
0 | 1359 |
|
1360 |
$post_type_obj = get_post_type_object( $post_type ); |
|
1361 |
if ( get_option( 'permalink_structure' ) && is_array( $post_type_obj->rewrite ) && $post_type_obj->rewrite['feeds'] ) { |
|
9 | 1362 |
$link = trailingslashit( $link ); |
0 | 1363 |
$link .= 'feed/'; |
9 | 1364 |
if ( $feed != $default_feed ) { |
0 | 1365 |
$link .= "$feed/"; |
9 | 1366 |
} |
0 | 1367 |
} else { |
1368 |
$link = add_query_arg( 'feed', $feed, $link ); |
|
1369 |
} |
|
1370 |
||
5 | 1371 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1372 |
* Filters the post type archive feed link. |
5 | 1373 |
* |
1374 |
* @since 3.1.0 |
|
1375 |
* |
|
1376 |
* @param string $link The post type archive feed link. |
|
16 | 1377 |
* @param string $feed Feed type. Possible values include 'rss2', 'atom'. |
5 | 1378 |
*/ |
0 | 1379 |
return apply_filters( 'post_type_archive_feed_link', $link, $feed ); |
1380 |
} |
|
1381 |
||
1382 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1383 |
* Retrieves the URL used for the post preview. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1384 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1385 |
* Allows additional query args to be appended. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1386 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1387 |
* @since 4.4.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1388 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1389 |
* @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
|
1390 |
* @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
|
1391 |
* Default empty array. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1392 |
* @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
|
1393 |
* post permalink. Default empty. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1394 |
* @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
|
1395 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1396 |
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
|
1397 |
$post = get_post( $post ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1398 |
if ( ! $post ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1399 |
return; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1400 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1401 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1402 |
$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
|
1403 |
if ( is_post_type_viewable( $post_type_object ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1404 |
if ( ! $preview_link ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1405 |
$preview_link = set_url_scheme( get_permalink( $post ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1406 |
} |
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 |
$query_args['preview'] = 'true'; |
9 | 1409 |
$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
|
1410 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1411 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1412 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1413 |
* Filters the URL used for a post preview. |
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 |
* @since 2.0.5 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1416 |
* @since 4.0.0 Added the `$post` parameter. |
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 |
* @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
|
1419 |
* @param WP_Post $post Post object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1420 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1421 |
return apply_filters( 'preview_post_link', $preview_link, $post ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1422 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1423 |
|
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 |
* Retrieves the edit post link for post. |
0 | 1426 |
* |
1427 |
* Can be used within the WordPress loop or outside of it. Can be used with |
|
1428 |
* pages, posts, attachments, and revisions. |
|
1429 |
* |
|
1430 |
* @since 2.3.0 |
|
1431 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1432 |
* @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
|
1433 |
* @param string $context Optional. How to output the '&' character. Default '&'. |
18 | 1434 |
* @return string|null The edit post link for the given post. Null if the post type does not exist |
1435 |
* or does not allow an editing UI. |
|
0 | 1436 |
*/ |
1437 |
function get_edit_post_link( $id = 0, $context = 'display' ) { |
|
16 | 1438 |
$post = get_post( $id ); |
1439 |
if ( ! $post ) { |
|
0 | 1440 |
return; |
9 | 1441 |
} |
1442 |
||
1443 |
if ( 'revision' === $post->post_type ) { |
|
0 | 1444 |
$action = ''; |
16 | 1445 |
} elseif ( 'display' === $context ) { |
0 | 1446 |
$action = '&action=edit'; |
9 | 1447 |
} else { |
0 | 1448 |
$action = '&action=edit'; |
9 | 1449 |
} |
0 | 1450 |
|
1451 |
$post_type_object = get_post_type_object( $post->post_type ); |
|
9 | 1452 |
if ( ! $post_type_object ) { |
0 | 1453 |
return; |
9 | 1454 |
} |
1455 |
||
1456 |
if ( ! current_user_can( 'edit_post', $post->ID ) ) { |
|
0 | 1457 |
return; |
9 | 1458 |
} |
0 | 1459 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1460 |
if ( $post_type_object->_edit_link ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1461 |
$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
|
1462 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1463 |
$link = ''; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1464 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1465 |
|
5 | 1466 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1467 |
* Filters the post edit link. |
5 | 1468 |
* |
1469 |
* @since 2.3.0 |
|
1470 |
* |
|
1471 |
* @param string $link The edit link. |
|
1472 |
* @param int $post_id Post ID. |
|
1473 |
* @param string $context The link context. If set to 'display' then ampersands |
|
1474 |
* are encoded. |
|
1475 |
*/ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1476 |
return apply_filters( 'get_edit_post_link', $link, $post->ID, $context ); |
0 | 1477 |
} |
1478 |
||
1479 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1480 |
* Displays the edit post link for post. |
0 | 1481 |
* |
1482 |
* @since 1.0.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1483 |
* @since 4.4.0 The `$class` argument was added. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1484 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1485 |
* @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
|
1486 |
* @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
|
1487 |
* @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
|
1488 |
* @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
|
1489 |
* @param string $class Optional. Add custom class to link. Default 'post-edit-link'. |
0 | 1490 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1491 |
function edit_post_link( $text = null, $before = '', $after = '', $id = 0, $class = 'post-edit-link' ) { |
16 | 1492 |
$post = get_post( $id ); |
1493 |
if ( ! $post ) { |
|
0 | 1494 |
return; |
5 | 1495 |
} |
1496 |
||
16 | 1497 |
$url = get_edit_post_link( $post->ID ); |
1498 |
if ( ! $url ) { |
|
0 | 1499 |
return; |
5 | 1500 |
} |
1501 |
||
1502 |
if ( null === $text ) { |
|
1503 |
$text = __( 'Edit This' ); |
|
1504 |
} |
|
1505 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1506 |
$link = '<a class="' . esc_attr( $class ) . '" href="' . esc_url( $url ) . '">' . $text . '</a>'; |
5 | 1507 |
|
1508 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1509 |
* Filters the post edit link anchor tag. |
5 | 1510 |
* |
1511 |
* @since 2.3.0 |
|
1512 |
* |
|
1513 |
* @param string $link Anchor tag for the edit link. |
|
1514 |
* @param int $post_id Post ID. |
|
1515 |
* @param string $text Anchor text. |
|
1516 |
*/ |
|
1517 |
echo $before . apply_filters( 'edit_post_link', $link, $post->ID, $text ) . $after; |
|
0 | 1518 |
} |
1519 |
||
1520 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1521 |
* Retrieves the delete posts link for post. |
0 | 1522 |
* |
1523 |
* Can be used within the WordPress loop or outside of it, with any post type. |
|
1524 |
* |
|
1525 |
* @since 2.9.0 |
|
1526 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1527 |
* @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
|
1528 |
* @param string $deprecated Not used. |
16 | 1529 |
* @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
|
1530 |
* @return string|void The delete post link URL for the given post. |
0 | 1531 |
*/ |
1532 |
function get_delete_post_link( $id = 0, $deprecated = '', $force_delete = false ) { |
|
9 | 1533 |
if ( ! empty( $deprecated ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1534 |
_deprecated_argument( __FUNCTION__, '3.0.0' ); |
9 | 1535 |
} |
1536 |
||
16 | 1537 |
$post = get_post( $id ); |
1538 |
if ( ! $post ) { |
|
0 | 1539 |
return; |
9 | 1540 |
} |
0 | 1541 |
|
1542 |
$post_type_object = get_post_type_object( $post->post_type ); |
|
9 | 1543 |
if ( ! $post_type_object ) { |
0 | 1544 |
return; |
9 | 1545 |
} |
1546 |
||
1547 |
if ( ! current_user_can( 'delete_post', $post->ID ) ) { |
|
0 | 1548 |
return; |
9 | 1549 |
} |
1550 |
||
1551 |
$action = ( $force_delete || ! EMPTY_TRASH_DAYS ) ? 'delete' : 'trash'; |
|
0 | 1552 |
|
1553 |
$delete_link = add_query_arg( 'action', $action, admin_url( sprintf( $post_type_object->_edit_link, $post->ID ) ) ); |
|
1554 |
||
5 | 1555 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1556 |
* Filters the post delete link. |
5 | 1557 |
* |
1558 |
* @since 2.9.0 |
|
1559 |
* |
|
1560 |
* @param string $link The delete link. |
|
1561 |
* @param int $post_id Post ID. |
|
16 | 1562 |
* @param bool $force_delete Whether to bypass the Trash and force deletion. Default false. |
5 | 1563 |
*/ |
0 | 1564 |
return apply_filters( 'get_delete_post_link', wp_nonce_url( $delete_link, "$action-post_{$post->ID}" ), $post->ID, $force_delete ); |
1565 |
} |
|
1566 |
||
1567 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1568 |
* Retrieves the edit comment link. |
0 | 1569 |
* |
1570 |
* @since 2.3.0 |
|
1571 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1572 |
* @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
|
1573 |
* @return string|void The edit comment link URL for the given comment. |
0 | 1574 |
*/ |
1575 |
function get_edit_comment_link( $comment_id = 0 ) { |
|
1576 |
$comment = get_comment( $comment_id ); |
|
1577 |
||
9 | 1578 |
if ( ! current_user_can( 'edit_comment', $comment->comment_ID ) ) { |
0 | 1579 |
return; |
9 | 1580 |
} |
1581 |
||
1582 |
$location = admin_url( 'comment.php?action=editcomment&c=' ) . $comment->comment_ID; |
|
5 | 1583 |
|
1584 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1585 |
* Filters the comment edit link. |
5 | 1586 |
* |
1587 |
* @since 2.3.0 |
|
1588 |
* |
|
1589 |
* @param string $location The edit link. |
|
1590 |
*/ |
|
0 | 1591 |
return apply_filters( 'get_edit_comment_link', $location ); |
1592 |
} |
|
1593 |
||
1594 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1595 |
* Displays the edit comment link with formatting. |
0 | 1596 |
* |
1597 |
* @since 1.0.0 |
|
1598 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1599 |
* @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
|
1600 |
* @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
|
1601 |
* @param string $after Optional. Display after edit link. Default empty. |
0 | 1602 |
*/ |
5 | 1603 |
function edit_comment_link( $text = null, $before = '', $after = '' ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1604 |
$comment = get_comment(); |
0 | 1605 |
|
5 | 1606 |
if ( ! current_user_can( 'edit_comment', $comment->comment_ID ) ) { |
0 | 1607 |
return; |
5 | 1608 |
} |
1609 |
||
1610 |
if ( null === $text ) { |
|
1611 |
$text = __( 'Edit This' ); |
|
1612 |
} |
|
1613 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1614 |
$link = '<a class="comment-edit-link" href="' . esc_url( get_edit_comment_link( $comment ) ) . '">' . $text . '</a>'; |
5 | 1615 |
|
1616 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1617 |
* Filters the comment edit link anchor tag. |
5 | 1618 |
* |
1619 |
* @since 2.3.0 |
|
1620 |
* |
|
1621 |
* @param string $link Anchor tag for the edit link. |
|
1622 |
* @param int $comment_id Comment ID. |
|
1623 |
* @param string $text Anchor text. |
|
1624 |
*/ |
|
1625 |
echo $before . apply_filters( 'edit_comment_link', $link, $comment->comment_ID, $text ) . $after; |
|
0 | 1626 |
} |
1627 |
||
1628 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1629 |
* Displays the edit bookmark link. |
0 | 1630 |
* |
1631 |
* @since 2.7.0 |
|
1632 |
* |
|
16 | 1633 |
* @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
|
1634 |
* @return string|void The edit bookmark link URL. |
0 | 1635 |
*/ |
1636 |
function get_edit_bookmark_link( $link = 0 ) { |
|
1637 |
$link = get_bookmark( $link ); |
|
1638 |
||
9 | 1639 |
if ( ! current_user_can( 'manage_links' ) ) { |
0 | 1640 |
return; |
9 | 1641 |
} |
1642 |
||
1643 |
$location = admin_url( 'link.php?action=edit&link_id=' ) . $link->link_id; |
|
5 | 1644 |
|
1645 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1646 |
* Filters the bookmark edit link. |
5 | 1647 |
* |
1648 |
* @since 2.7.0 |
|
1649 |
* |
|
1650 |
* @param string $location The edit link. |
|
1651 |
* @param int $link_id Bookmark ID. |
|
1652 |
*/ |
|
0 | 1653 |
return apply_filters( 'get_edit_bookmark_link', $location, $link->link_id ); |
1654 |
} |
|
1655 |
||
1656 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1657 |
* Displays the edit bookmark link anchor content. |
0 | 1658 |
* |
1659 |
* @since 2.7.0 |
|
1660 |
* |
|
16 | 1661 |
* @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
|
1662 |
* @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
|
1663 |
* @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
|
1664 |
* @param int $bookmark Optional. Bookmark ID. Default is the current bookmark. |
0 | 1665 |
*/ |
1666 |
function edit_bookmark_link( $link = '', $before = '', $after = '', $bookmark = null ) { |
|
9 | 1667 |
$bookmark = get_bookmark( $bookmark ); |
1668 |
||
1669 |
if ( ! current_user_can( 'manage_links' ) ) { |
|
0 | 1670 |
return; |
9 | 1671 |
} |
1672 |
||
1673 |
if ( empty( $link ) ) { |
|
1674 |
$link = __( 'Edit This' ); |
|
1675 |
} |
|
0 | 1676 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1677 |
$link = '<a href="' . esc_url( get_edit_bookmark_link( $bookmark ) ) . '">' . $link . '</a>'; |
5 | 1678 |
|
1679 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1680 |
* Filters the bookmark edit link anchor tag. |
5 | 1681 |
* |
1682 |
* @since 2.7.0 |
|
1683 |
* |
|
1684 |
* @param string $link Anchor tag for the edit link. |
|
1685 |
* @param int $link_id Bookmark ID. |
|
1686 |
*/ |
|
0 | 1687 |
echo $before . apply_filters( 'edit_bookmark_link', $link, $bookmark->link_id ) . $after; |
1688 |
} |
|
1689 |
||
1690 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1691 |
* Retrieves the edit user link. |
0 | 1692 |
* |
1693 |
* @since 3.5.0 |
|
1694 |
* |
|
1695 |
* @param int $user_id Optional. User ID. Defaults to the current user. |
|
1696 |
* @return string URL to edit user page or empty string. |
|
1697 |
*/ |
|
1698 |
function get_edit_user_link( $user_id = null ) { |
|
9 | 1699 |
if ( ! $user_id ) { |
0 | 1700 |
$user_id = get_current_user_id(); |
9 | 1701 |
} |
1702 |
||
1703 |
if ( empty( $user_id ) || ! current_user_can( 'edit_user', $user_id ) ) { |
|
0 | 1704 |
return ''; |
9 | 1705 |
} |
0 | 1706 |
|
1707 |
$user = get_userdata( $user_id ); |
|
1708 |
||
9 | 1709 |
if ( ! $user ) { |
0 | 1710 |
return ''; |
9 | 1711 |
} |
1712 |
||
1713 |
if ( get_current_user_id() == $user->ID ) { |
|
0 | 1714 |
$link = get_edit_profile_url( $user->ID ); |
9 | 1715 |
} else { |
0 | 1716 |
$link = add_query_arg( 'user_id', $user->ID, self_admin_url( 'user-edit.php' ) ); |
9 | 1717 |
} |
0 | 1718 |
|
5 | 1719 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1720 |
* Filters the user edit link. |
5 | 1721 |
* |
1722 |
* @since 3.5.0 |
|
1723 |
* |
|
1724 |
* @param string $link The edit link. |
|
1725 |
* @param int $user_id User ID. |
|
1726 |
*/ |
|
0 | 1727 |
return apply_filters( 'get_edit_user_link', $link, $user->ID ); |
1728 |
} |
|
1729 |
||
16 | 1730 |
// |
1731 |
// Navigation links. |
|
1732 |
// |
|
0 | 1733 |
|
1734 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1735 |
* Retrieves the previous post that is adjacent to the current post. |
0 | 1736 |
* |
1737 |
* @since 1.5.0 |
|
1738 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1739 |
* @param bool $in_same_term Optional. Whether post should be in a same taxonomy term. Default false. |
18 | 1740 |
* @param int[]|string $excluded_terms Optional. Array or comma-separated list of excluded term IDs. Default empty. |
5 | 1741 |
* @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
|
1742 |
* @return null|string|WP_Post Post object if successful. Null if global $post is not set. Empty string if no |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1743 |
* corresponding post exists. |
0 | 1744 |
*/ |
5 | 1745 |
function get_previous_post( $in_same_term = false, $excluded_terms = '', $taxonomy = 'category' ) { |
1746 |
return get_adjacent_post( $in_same_term, $excluded_terms, true, $taxonomy ); |
|
0 | 1747 |
} |
1748 |
||
1749 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1750 |
* Retrieves the next post that is adjacent to the current post. |
0 | 1751 |
* |
1752 |
* @since 1.5.0 |
|
1753 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1754 |
* @param bool $in_same_term Optional. Whether post should be in a same taxonomy term. Default false. |
18 | 1755 |
* @param int[]|string $excluded_terms Optional. Array or comma-separated list of excluded term IDs. Default empty. |
5 | 1756 |
* @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
|
1757 |
* @return null|string|WP_Post Post object if successful. Null if global $post is not set. Empty string if no |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1758 |
* corresponding post exists. |
0 | 1759 |
*/ |
5 | 1760 |
function get_next_post( $in_same_term = false, $excluded_terms = '', $taxonomy = 'category' ) { |
1761 |
return get_adjacent_post( $in_same_term, $excluded_terms, false, $taxonomy ); |
|
0 | 1762 |
} |
1763 |
||
1764 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1765 |
* Retrieves the adjacent post. |
0 | 1766 |
* |
1767 |
* Can either be next or previous post. |
|
1768 |
* |
|
1769 |
* @since 2.5.0 |
|
1770 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1771 |
* @global wpdb $wpdb WordPress database abstraction object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1772 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1773 |
* @param bool $in_same_term Optional. Whether post should be in a same taxonomy term. Default false. |
18 | 1774 |
* @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
|
1775 |
* @param bool $previous Optional. Whether to retrieve previous post. Default true |
5 | 1776 |
* @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
|
1777 |
* @return null|string|WP_Post Post object if successful. Null if global $post is not set. Empty string if no |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1778 |
* corresponding post exists. |
0 | 1779 |
*/ |
5 | 1780 |
function get_adjacent_post( $in_same_term = false, $excluded_terms = '', $previous = true, $taxonomy = 'category' ) { |
0 | 1781 |
global $wpdb; |
1782 |
||
16 | 1783 |
$post = get_post(); |
1784 |
if ( ! $post || ! taxonomy_exists( $taxonomy ) ) { |
|
0 | 1785 |
return null; |
9 | 1786 |
} |
0 | 1787 |
|
1788 |
$current_post_date = $post->post_date; |
|
1789 |
||
9 | 1790 |
$join = ''; |
1791 |
$where = ''; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1792 |
$adjacent = $previous ? 'previous' : 'next'; |
5 | 1793 |
|
9 | 1794 |
if ( ! empty( $excluded_terms ) && ! is_array( $excluded_terms ) ) { |
1795 |
// Back-compat, $excluded_terms used to be $excluded_categories with IDs separated by " and ". |
|
1796 |
if ( false !== strpos( $excluded_terms, ' and ' ) ) { |
|
16 | 1797 |
_deprecated_argument( |
1798 |
__FUNCTION__, |
|
1799 |
'3.3.0', |
|
1800 |
sprintf( |
|
1801 |
/* translators: %s: The word 'and'. */ |
|
1802 |
__( 'Use commas instead of %s to separate excluded terms.' ), |
|
1803 |
"'and'" |
|
1804 |
) |
|
1805 |
); |
|
9 | 1806 |
$excluded_terms = explode( ' and ', $excluded_terms ); |
1807 |
} else { |
|
1808 |
$excluded_terms = explode( ',', $excluded_terms ); |
|
1809 |
} |
|
1810 |
||
1811 |
$excluded_terms = array_map( 'intval', $excluded_terms ); |
|
1812 |
} |
|
1813 |
||
1814 |
/** |
|
1815 |
* Filters the IDs of terms excluded from adjacent post queries. |
|
1816 |
* |
|
1817 |
* The dynamic portion of the hook name, `$adjacent`, refers to the type |
|
1818 |
* of adjacency, 'next' or 'previous'. |
|
1819 |
* |
|
18 | 1820 |
* Possible hook names include: |
1821 |
* |
|
1822 |
* - `get_next_post_excluded_terms` |
|
1823 |
* - `get_previous_post_excluded_terms` |
|
1824 |
* |
|
9 | 1825 |
* @since 4.4.0 |
1826 |
* |
|
18 | 1827 |
* @param array|string $excluded_terms Array of excluded term IDs. Empty string if none were provided. |
9 | 1828 |
*/ |
1829 |
$excluded_terms = apply_filters( "get_{$adjacent}_post_excluded_terms", $excluded_terms ); |
|
1830 |
||
5 | 1831 |
if ( $in_same_term || ! empty( $excluded_terms ) ) { |
9 | 1832 |
if ( $in_same_term ) { |
1833 |
$join .= " INNER JOIN $wpdb->term_relationships AS tr ON p.ID = tr.object_id INNER JOIN $wpdb->term_taxonomy tt ON tr.term_taxonomy_id = tt.term_taxonomy_id"; |
|
1834 |
$where .= $wpdb->prepare( 'AND tt.taxonomy = %s', $taxonomy ); |
|
1835 |
||
1836 |
if ( ! is_object_in_taxonomy( $post->post_type, $taxonomy ) ) { |
|
1837 |
return ''; |
|
5 | 1838 |
} |
1839 |
$term_array = wp_get_object_terms( $post->ID, $taxonomy, array( 'fields' => 'ids' ) ); |
|
1840 |
||
1841 |
// Remove any exclusions from the term array to include. |
|
1842 |
$term_array = array_diff( $term_array, (array) $excluded_terms ); |
|
1843 |
$term_array = array_map( 'intval', $term_array ); |
|
1844 |
||
9 | 1845 |
if ( ! $term_array || is_wp_error( $term_array ) ) { |
5 | 1846 |
return ''; |
9 | 1847 |
} |
1848 |
||
1849 |
$where .= ' AND tt.term_id IN (' . implode( ',', $term_array ) . ')'; |
|
5 | 1850 |
} |
1851 |
||
1852 |
if ( ! empty( $excluded_terms ) ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1853 |
$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 | 1854 |
} |
1855 |
} |
|
1856 |
||
1857 |
// 'post_status' clause depends on the current user. |
|
1858 |
if ( is_user_logged_in() ) { |
|
1859 |
$user_id = get_current_user_id(); |
|
1860 |
||
1861 |
$post_type_object = get_post_type_object( $post->post_type ); |
|
1862 |
if ( empty( $post_type_object ) ) { |
|
1863 |
$post_type_cap = $post->post_type; |
|
1864 |
$read_private_cap = 'read_private_' . $post_type_cap . 's'; |
|
1865 |
} else { |
|
1866 |
$read_private_cap = $post_type_object->cap->read_private_posts; |
|
1867 |
} |
|
1868 |
||
1869 |
/* |
|
1870 |
* Results should include private posts belonging to the current user, or private posts where the |
|
1871 |
* current user has the 'read_private_posts' cap. |
|
1872 |
*/ |
|
1873 |
$private_states = get_post_stati( array( 'private' => true ) ); |
|
9 | 1874 |
$where .= " AND ( p.post_status = 'publish'"; |
5 | 1875 |
foreach ( (array) $private_states as $state ) { |
1876 |
if ( current_user_can( $read_private_cap ) ) { |
|
9 | 1877 |
$where .= $wpdb->prepare( ' OR p.post_status = %s', $state ); |
5 | 1878 |
} else { |
9 | 1879 |
$where .= $wpdb->prepare( ' OR (p.post_author = %d AND p.post_status = %s)', $user_id, $state ); |
0 | 1880 |
} |
1881 |
} |
|
9 | 1882 |
$where .= ' )'; |
5 | 1883 |
} else { |
1884 |
$where .= " AND p.post_status = 'publish'"; |
|
0 | 1885 |
} |
1886 |
||
9 | 1887 |
$op = $previous ? '<' : '>'; |
0 | 1888 |
$order = $previous ? 'DESC' : 'ASC'; |
1889 |
||
5 | 1890 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1891 |
* Filters the JOIN clause in the SQL for an adjacent post query. |
5 | 1892 |
* |
1893 |
* The dynamic portion of the hook name, `$adjacent`, refers to the type |
|
1894 |
* of adjacency, 'next' or 'previous'. |
|
1895 |
* |
|
18 | 1896 |
* Possible hook names include: |
1897 |
* |
|
1898 |
* - `get_next_post_join` |
|
1899 |
* - `get_previous_post_join` |
|
1900 |
* |
|
5 | 1901 |
* @since 2.5.0 |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1902 |
* @since 4.4.0 Added the `$taxonomy` and `$post` parameters. |
5 | 1903 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1904 |
* @param string $join The JOIN clause in the SQL. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1905 |
* @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
|
1906 |
* @param array $excluded_terms Array of excluded term IDs. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1907 |
* @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
|
1908 |
* @param WP_Post $post WP_Post object. |
5 | 1909 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1910 |
$join = apply_filters( "get_{$adjacent}_post_join", $join, $in_same_term, $excluded_terms, $taxonomy, $post ); |
5 | 1911 |
|
1912 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1913 |
* Filters the WHERE clause in the SQL for an adjacent post query. |
5 | 1914 |
* |
1915 |
* The dynamic portion of the hook name, `$adjacent`, refers to the type |
|
1916 |
* of adjacency, 'next' or 'previous'. |
|
1917 |
* |
|
18 | 1918 |
* Possible hook names include: |
1919 |
* |
|
1920 |
* - `get_next_post_where` |
|
1921 |
* - `get_previous_post_where` |
|
1922 |
* |
|
5 | 1923 |
* @since 2.5.0 |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1924 |
* @since 4.4.0 Added the `$taxonomy` and `$post` parameters. |
5 | 1925 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1926 |
* @param string $where The `WHERE` clause in the SQL. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1927 |
* @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
|
1928 |
* @param array $excluded_terms Array of excluded term IDs. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1929 |
* @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
|
1930 |
* @param WP_Post $post WP_Post object. |
5 | 1931 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1932 |
$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 | 1933 |
|
1934 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1935 |
* Filters the ORDER BY clause in the SQL for an adjacent post query. |
5 | 1936 |
* |
1937 |
* The dynamic portion of the hook name, `$adjacent`, refers to the type |
|
1938 |
* of adjacency, 'next' or 'previous'. |
|
1939 |
* |
|
18 | 1940 |
* Possible hook names include: |
1941 |
* |
|
1942 |
* - `get_next_post_sort` |
|
1943 |
* - `get_previous_post_sort` |
|
1944 |
* |
|
5 | 1945 |
* @since 2.5.0 |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1946 |
* @since 4.4.0 Added the `$post` parameter. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1947 |
* @since 4.9.0 Added the `$order` parameter. |
5 | 1948 |
* |
1949 |
* @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
|
1950 |
* @param WP_Post $post WP_Post object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1951 |
* @param string $order Sort order. 'DESC' for previous post, 'ASC' for next. |
5 | 1952 |
*/ |
9 | 1953 |
$sort = apply_filters( "get_{$adjacent}_post_sort", "ORDER BY p.post_date $order LIMIT 1", $post, $order ); |
1954 |
||
1955 |
$query = "SELECT p.ID FROM $wpdb->posts AS p $join $where $sort"; |
|
5 | 1956 |
$query_key = 'adjacent_post_' . md5( $query ); |
9 | 1957 |
$result = wp_cache_get( $query_key, 'counts' ); |
0 | 1958 |
if ( false !== $result ) { |
9 | 1959 |
if ( $result ) { |
0 | 1960 |
$result = get_post( $result ); |
9 | 1961 |
} |
0 | 1962 |
return $result; |
1963 |
} |
|
1964 |
||
1965 |
$result = $wpdb->get_var( $query ); |
|
9 | 1966 |
if ( null === $result ) { |
0 | 1967 |
$result = ''; |
9 | 1968 |
} |
0 | 1969 |
|
5 | 1970 |
wp_cache_set( $query_key, $result, 'counts' ); |
0 | 1971 |
|
9 | 1972 |
if ( $result ) { |
0 | 1973 |
$result = get_post( $result ); |
9 | 1974 |
} |
0 | 1975 |
|
1976 |
return $result; |
|
1977 |
} |
|
1978 |
||
1979 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1980 |
* Retrieves the adjacent post relational link. |
0 | 1981 |
* |
1982 |
* Can either be next or previous post relational link. |
|
1983 |
* |
|
1984 |
* @since 2.8.0 |
|
1985 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1986 |
* @param string $title Optional. Link title format. Default '%title'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1987 |
* @param bool $in_same_term Optional. Whether link should be in a same taxonomy term. Default false. |
18 | 1988 |
* @param int[]|string $excluded_terms Optional. Array or comma-separated list of excluded term IDs. Default empty. |
5 | 1989 |
* @param bool $previous Optional. Whether to display link to previous or next post. Default true. |
1990 |
* @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
|
1991 |
* @return string|void The adjacent post relational link URL. |
0 | 1992 |
*/ |
5 | 1993 |
function get_adjacent_post_rel_link( $title = '%title', $in_same_term = false, $excluded_terms = '', $previous = true, $taxonomy = 'category' ) { |
16 | 1994 |
$post = get_post(); |
1995 |
if ( $previous && is_attachment() && $post ) { |
|
0 | 1996 |
$post = get_post( $post->post_parent ); |
9 | 1997 |
} else { |
5 | 1998 |
$post = get_adjacent_post( $in_same_term, $excluded_terms, $previous, $taxonomy ); |
9 | 1999 |
} |
2000 |
||
2001 |
if ( empty( $post ) ) { |
|
0 | 2002 |
return; |
9 | 2003 |
} |
2004 |
||
2005 |
$post_title = the_title_attribute( |
|
2006 |
array( |
|
2007 |
'echo' => false, |
|
2008 |
'post' => $post, |
|
2009 |
) |
|
2010 |
); |
|
2011 |
||
2012 |
if ( empty( $post_title ) ) { |
|
5 | 2013 |
$post_title = $previous ? __( 'Previous Post' ) : __( 'Next Post' ); |
9 | 2014 |
} |
5 | 2015 |
|
2016 |
$date = mysql2date( get_option( 'date_format' ), $post->post_date ); |
|
2017 |
||
2018 |
$title = str_replace( '%title', $post_title, $title ); |
|
2019 |
$title = str_replace( '%date', $date, $title ); |
|
0 | 2020 |
|
9 | 2021 |
$link = $previous ? "<link rel='prev' title='" : "<link rel='next' title='"; |
0 | 2022 |
$link .= esc_attr( $title ); |
5 | 2023 |
$link .= "' href='" . get_permalink( $post ) . "' />\n"; |
0 | 2024 |
|
2025 |
$adjacent = $previous ? 'previous' : 'next'; |
|
5 | 2026 |
|
2027 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2028 |
* Filters the adjacent post relational link. |
5 | 2029 |
* |
2030 |
* The dynamic portion of the hook name, `$adjacent`, refers to the type |
|
2031 |
* of adjacency, 'next' or 'previous'. |
|
2032 |
* |
|
18 | 2033 |
* Possible hook names include: |
2034 |
* |
|
2035 |
* - `next_post_rel_link` |
|
2036 |
* - `previous_post_rel_link` |
|
2037 |
* |
|
5 | 2038 |
* @since 2.8.0 |
2039 |
* |
|
2040 |
* @param string $link The relational link. |
|
2041 |
*/ |
|
0 | 2042 |
return apply_filters( "{$adjacent}_post_rel_link", $link ); |
2043 |
} |
|
2044 |
||
2045 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2046 |
* Displays the relational links for the posts adjacent to the current post. |
0 | 2047 |
* |
2048 |
* @since 2.8.0 |
|
2049 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2050 |
* @param string $title Optional. Link title format. Default '%title'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2051 |
* @param bool $in_same_term Optional. Whether link should be in a same taxonomy term. Default false. |
18 | 2052 |
* @param int[]|string $excluded_terms Optional. Array or comma-separated list of excluded term IDs. Default empty. |
5 | 2053 |
* @param string $taxonomy Optional. Taxonomy, if $in_same_term is true. Default 'category'. |
0 | 2054 |
*/ |
5 | 2055 |
function adjacent_posts_rel_link( $title = '%title', $in_same_term = false, $excluded_terms = '', $taxonomy = 'category' ) { |
2056 |
echo get_adjacent_post_rel_link( $title, $in_same_term, $excluded_terms, true, $taxonomy ); |
|
2057 |
echo get_adjacent_post_rel_link( $title, $in_same_term, $excluded_terms, false, $taxonomy ); |
|
0 | 2058 |
} |
2059 |
||
2060 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2061 |
* 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
|
2062 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2063 |
* 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
|
2064 |
* or theme templates. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2065 |
* |
0 | 2066 |
* @since 3.0.0 |
18 | 2067 |
* @since 5.6.0 No longer used in core. |
0 | 2068 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2069 |
* @see adjacent_posts_rel_link() |
0 | 2070 |
*/ |
2071 |
function adjacent_posts_rel_link_wp_head() { |
|
5 | 2072 |
if ( ! is_single() || is_attachment() ) { |
0 | 2073 |
return; |
5 | 2074 |
} |
0 | 2075 |
adjacent_posts_rel_link(); |
2076 |
} |
|
2077 |
||
2078 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2079 |
* Displays the relational link for the next post adjacent to the current post. |
0 | 2080 |
* |
2081 |
* @since 2.8.0 |
|
2082 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2083 |
* @see get_adjacent_post_rel_link() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2084 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2085 |
* @param string $title Optional. Link title format. Default '%title'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2086 |
* @param bool $in_same_term Optional. Whether link should be in a same taxonomy term. Default false. |
18 | 2087 |
* @param int[]|string $excluded_terms Optional. Array or comma-separated list of excluded term IDs. Default empty. |
5 | 2088 |
* @param string $taxonomy Optional. Taxonomy, if $in_same_term is true. Default 'category'. |
0 | 2089 |
*/ |
5 | 2090 |
function next_post_rel_link( $title = '%title', $in_same_term = false, $excluded_terms = '', $taxonomy = 'category' ) { |
2091 |
echo get_adjacent_post_rel_link( $title, $in_same_term, $excluded_terms, false, $taxonomy ); |
|
0 | 2092 |
} |
2093 |
||
2094 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2095 |
* Displays the relational link for the previous post adjacent to the current post. |
0 | 2096 |
* |
2097 |
* @since 2.8.0 |
|
2098 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2099 |
* @see get_adjacent_post_rel_link() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2100 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2101 |
* @param string $title Optional. Link title format. Default '%title'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2102 |
* @param bool $in_same_term Optional. Whether link should be in a same taxonomy term. Default false. |
18 | 2103 |
* @param int[]|string $excluded_terms Optional. Array or comma-separated list of excluded term IDs. Default true. |
5 | 2104 |
* @param string $taxonomy Optional. Taxonomy, if $in_same_term is true. Default 'category'. |
0 | 2105 |
*/ |
5 | 2106 |
function prev_post_rel_link( $title = '%title', $in_same_term = false, $excluded_terms = '', $taxonomy = 'category' ) { |
2107 |
echo get_adjacent_post_rel_link( $title, $in_same_term, $excluded_terms, true, $taxonomy ); |
|
0 | 2108 |
} |
2109 |
||
2110 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2111 |
* Retrieves the boundary post. |
0 | 2112 |
* |
2113 |
* Boundary being either the first or last post by publish date within the constraints specified |
|
5 | 2114 |
* by $in_same_term or $excluded_terms. |
0 | 2115 |
* |
2116 |
* @since 2.8.0 |
|
2117 |
* |
|
5 | 2118 |
* @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
|
2119 |
* Default false. |
18 | 2120 |
* @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
|
2121 |
* Default empty. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2122 |
* @param bool $start Optional. Whether to retrieve first or last post. Default true |
5 | 2123 |
* @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
|
2124 |
* @return null|array Array containing the boundary post object if successful, null otherwise. |
0 | 2125 |
*/ |
5 | 2126 |
function get_boundary_post( $in_same_term = false, $excluded_terms = '', $start = true, $taxonomy = 'category' ) { |
0 | 2127 |
$post = get_post(); |
9 | 2128 |
if ( ! $post || ! is_single() || is_attachment() || ! taxonomy_exists( $taxonomy ) ) { |
0 | 2129 |
return null; |
9 | 2130 |
} |
0 | 2131 |
|
5 | 2132 |
$query_args = array( |
9 | 2133 |
'posts_per_page' => 1, |
2134 |
'order' => $start ? 'ASC' : 'DESC', |
|
5 | 2135 |
'update_post_term_cache' => false, |
9 | 2136 |
'update_post_meta_cache' => false, |
5 | 2137 |
); |
2138 |
||
2139 |
$term_array = array(); |
|
2140 |
||
2141 |
if ( ! is_array( $excluded_terms ) ) { |
|
9 | 2142 |
if ( ! empty( $excluded_terms ) ) { |
5 | 2143 |
$excluded_terms = explode( ',', $excluded_terms ); |
9 | 2144 |
} else { |
5 | 2145 |
$excluded_terms = array(); |
9 | 2146 |
} |
5 | 2147 |
} |
2148 |
||
2149 |
if ( $in_same_term || ! empty( $excluded_terms ) ) { |
|
9 | 2150 |
if ( $in_same_term ) { |
5 | 2151 |
$term_array = wp_get_object_terms( $post->ID, $taxonomy, array( 'fields' => 'ids' ) ); |
9 | 2152 |
} |
5 | 2153 |
|
2154 |
if ( ! empty( $excluded_terms ) ) { |
|
2155 |
$excluded_terms = array_map( 'intval', $excluded_terms ); |
|
2156 |
$excluded_terms = array_diff( $excluded_terms, $term_array ); |
|
2157 |
||
2158 |
$inverse_terms = array(); |
|
9 | 2159 |
foreach ( $excluded_terms as $excluded_term ) { |
5 | 2160 |
$inverse_terms[] = $excluded_term * -1; |
9 | 2161 |
} |
5 | 2162 |
$excluded_terms = $inverse_terms; |
0 | 2163 |
} |
5 | 2164 |
|
9 | 2165 |
$query_args['tax_query'] = array( |
2166 |
array( |
|
2167 |
'taxonomy' => $taxonomy, |
|
2168 |
'terms' => array_merge( $term_array, $excluded_terms ), |
|
2169 |
), |
|
2170 |
); |
|
0 | 2171 |
} |
2172 |
||
5 | 2173 |
return get_posts( $query_args ); |
0 | 2174 |
} |
2175 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2176 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2177 |
* Retrieves the previous post link that is adjacent to the current post. |
0 | 2178 |
* |
2179 |
* @since 3.7.0 |
|
2180 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2181 |
* @param string $format Optional. Link anchor format. Default '« %link'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2182 |
* @param string $link Optional. Link permalink format. Default '%title'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2183 |
* @param bool $in_same_term Optional. Whether link should be in a same taxonomy term. Default false. |
18 | 2184 |
* @param int[]|string $excluded_terms Optional. Array or comma-separated list of excluded term IDs. Default empty. |
5 | 2185 |
* @param string $taxonomy Optional. Taxonomy, if $in_same_term is true. Default 'category'. |
2186 |
* @return string The link URL of the previous post in relation to the current post. |
|
0 | 2187 |
*/ |
5 | 2188 |
function get_previous_post_link( $format = '« %link', $link = '%title', $in_same_term = false, $excluded_terms = '', $taxonomy = 'category' ) { |
2189 |
return get_adjacent_post_link( $format, $link, $in_same_term, $excluded_terms, true, $taxonomy ); |
|
0 | 2190 |
} |
2191 |
||
2192 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2193 |
* Displays the previous post link that is adjacent to the current post. |
0 | 2194 |
* |
2195 |
* @since 1.5.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2196 |
* |
5 | 2197 |
* @see get_previous_post_link() |
0 | 2198 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2199 |
* @param string $format Optional. Link anchor format. Default '« %link'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2200 |
* @param string $link Optional. Link permalink format. Default '%title'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2201 |
* @param bool $in_same_term Optional. Whether link should be in a same taxonomy term. Default false. |
18 | 2202 |
* @param int[]|string $excluded_terms Optional. Array or comma-separated list of excluded term IDs. Default empty. |
5 | 2203 |
* @param string $taxonomy Optional. Taxonomy, if $in_same_term is true. Default 'category'. |
0 | 2204 |
*/ |
5 | 2205 |
function previous_post_link( $format = '« %link', $link = '%title', $in_same_term = false, $excluded_terms = '', $taxonomy = 'category' ) { |
2206 |
echo get_previous_post_link( $format, $link, $in_same_term, $excluded_terms, $taxonomy ); |
|
0 | 2207 |
} |
2208 |
||
2209 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2210 |
* Retrieves the next post link that is adjacent to the current post. |
0 | 2211 |
* |
2212 |
* @since 3.7.0 |
|
2213 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2214 |
* @param string $format Optional. Link anchor format. Default '« %link'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2215 |
* @param string $link Optional. Link permalink format. Default '%title'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2216 |
* @param bool $in_same_term Optional. Whether link should be in a same taxonomy term. Default false. |
18 | 2217 |
* @param int[]|string $excluded_terms Optional. Array or comma-separated list of excluded term IDs. Default empty. |
5 | 2218 |
* @param string $taxonomy Optional. Taxonomy, if $in_same_term is true. Default 'category'. |
2219 |
* @return string The link URL of the next post in relation to the current post. |
|
0 | 2220 |
*/ |
5 | 2221 |
function get_next_post_link( $format = '%link »', $link = '%title', $in_same_term = false, $excluded_terms = '', $taxonomy = 'category' ) { |
2222 |
return get_adjacent_post_link( $format, $link, $in_same_term, $excluded_terms, false, $taxonomy ); |
|
0 | 2223 |
} |
2224 |
||
2225 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2226 |
* Displays the next post link that is adjacent to the current post. |
0 | 2227 |
* |
2228 |
* @since 1.5.0 |
|
16 | 2229 |
* |
5 | 2230 |
* @see get_next_post_link() |
0 | 2231 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2232 |
* @param string $format Optional. Link anchor format. Default '« %link'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2233 |
* @param string $link Optional. Link permalink format. Default '%title' |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2234 |
* @param bool $in_same_term Optional. Whether link should be in a same taxonomy term. Default false. |
18 | 2235 |
* @param int[]|string $excluded_terms Optional. Array or comma-separated list of excluded term IDs. Default empty. |
5 | 2236 |
* @param string $taxonomy Optional. Taxonomy, if $in_same_term is true. Default 'category'. |
0 | 2237 |
*/ |
5 | 2238 |
function next_post_link( $format = '%link »', $link = '%title', $in_same_term = false, $excluded_terms = '', $taxonomy = 'category' ) { |
9 | 2239 |
echo get_next_post_link( $format, $link, $in_same_term, $excluded_terms, $taxonomy ); |
0 | 2240 |
} |
2241 |
||
2242 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2243 |
* Retrieves the adjacent post link. |
0 | 2244 |
* |
2245 |
* Can be either next post link or previous. |
|
2246 |
* |
|
2247 |
* @since 3.7.0 |
|
2248 |
* |
|
5 | 2249 |
* @param string $format Link anchor format. |
2250 |
* @param string $link Link permalink format. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2251 |
* @param bool $in_same_term Optional. Whether link should be in a same taxonomy term. Default false. |
18 | 2252 |
* @param int[]|string $excluded_terms Optional. Array or comma-separated list of excluded terms IDs. Default empty. |
5 | 2253 |
* @param bool $previous Optional. Whether to display link to previous or next post. Default true. |
2254 |
* @param string $taxonomy Optional. Taxonomy, if $in_same_term is true. Default 'category'. |
|
2255 |
* @return string The link URL of the previous or next post in relation to the current post. |
|
0 | 2256 |
*/ |
5 | 2257 |
function get_adjacent_post_link( $format, $link, $in_same_term = false, $excluded_terms = '', $previous = true, $taxonomy = 'category' ) { |
9 | 2258 |
if ( $previous && is_attachment() ) { |
0 | 2259 |
$post = get_post( get_post()->post_parent ); |
9 | 2260 |
} else { |
5 | 2261 |
$post = get_adjacent_post( $in_same_term, $excluded_terms, $previous, $taxonomy ); |
9 | 2262 |
} |
0 | 2263 |
|
2264 |
if ( ! $post ) { |
|
2265 |
$output = ''; |
|
2266 |
} else { |
|
2267 |
$title = $post->post_title; |
|
2268 |
||
9 | 2269 |
if ( empty( $post->post_title ) ) { |
0 | 2270 |
$title = $previous ? __( 'Previous Post' ) : __( 'Next Post' ); |
9 | 2271 |
} |
0 | 2272 |
|
2273 |
/** This filter is documented in wp-includes/post-template.php */ |
|
2274 |
$title = apply_filters( 'the_title', $title, $post->ID ); |
|
5 | 2275 |
|
0 | 2276 |
$date = mysql2date( get_option( 'date_format' ), $post->post_date ); |
9 | 2277 |
$rel = $previous ? 'prev' : 'next'; |
2278 |
||
2279 |
$string = '<a href="' . get_permalink( $post ) . '" rel="' . $rel . '">'; |
|
0 | 2280 |
$inlink = str_replace( '%title', $title, $link ); |
2281 |
$inlink = str_replace( '%date', $date, $inlink ); |
|
2282 |
$inlink = $string . $inlink . '</a>'; |
|
2283 |
||
2284 |
$output = str_replace( '%link', $inlink, $format ); |
|
2285 |
} |
|
2286 |
||
2287 |
$adjacent = $previous ? 'previous' : 'next'; |
|
2288 |
||
5 | 2289 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2290 |
* Filters the adjacent post link. |
5 | 2291 |
* |
2292 |
* The dynamic portion of the hook name, `$adjacent`, refers to the type |
|
2293 |
* of adjacency, 'next' or 'previous'. |
|
2294 |
* |
|
18 | 2295 |
* Possible hook names include: |
2296 |
* |
|
2297 |
* - `next_post_link` |
|
2298 |
* - `previous_post_link` |
|
2299 |
* |
|
5 | 2300 |
* @since 2.6.0 |
2301 |
* @since 4.2.0 Added the `$adjacent` parameter. |
|
2302 |
* |
|
2303 |
* @param string $output The adjacent post link. |
|
2304 |
* @param string $format Link anchor format. |
|
2305 |
* @param string $link Link permalink format. |
|
2306 |
* @param WP_Post $post The adjacent post. |
|
2307 |
* @param string $adjacent Whether the post is previous or next. |
|
2308 |
*/ |
|
2309 |
return apply_filters( "{$adjacent}_post_link", $output, $format, $link, $post, $adjacent ); |
|
0 | 2310 |
} |
2311 |
||
2312 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2313 |
* Displays the adjacent post link. |
0 | 2314 |
* |
2315 |
* Can be either next post link or previous. |
|
2316 |
* |
|
2317 |
* @since 2.5.0 |
|
2318 |
* |
|
5 | 2319 |
* @param string $format Link anchor format. |
2320 |
* @param string $link Link permalink format. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2321 |
* @param bool $in_same_term Optional. Whether link should be in a same taxonomy term. Default false. |
18 | 2322 |
* @param int[]|string $excluded_terms Optional. Array or comma-separated list of excluded category IDs. Default empty. |
5 | 2323 |
* @param bool $previous Optional. Whether to display link to previous or next post. Default true. |
2324 |
* @param string $taxonomy Optional. Taxonomy, if $in_same_term is true. Default 'category'. |
|
0 | 2325 |
*/ |
5 | 2326 |
function adjacent_post_link( $format, $link, $in_same_term = false, $excluded_terms = '', $previous = true, $taxonomy = 'category' ) { |
2327 |
echo get_adjacent_post_link( $format, $link, $in_same_term, $excluded_terms, $previous, $taxonomy ); |
|
0 | 2328 |
} |
2329 |
||
2330 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2331 |
* Retrieves the link for a page number. |
0 | 2332 |
* |
2333 |
* @since 1.5.0 |
|
2334 |
* |
|
16 | 2335 |
* @global WP_Rewrite $wp_rewrite WordPress rewrite component. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2336 |
* |
9 | 2337 |
* @param int $pagenum Optional. Page number. Default 1. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2338 |
* @param bool $escape Optional. Whether to escape the URL for display, with esc_url(). Defaults to true. |
9 | 2339 |
* Otherwise, prepares the URL with esc_url_raw(). |
5 | 2340 |
* @return string The link URL for the given page number. |
0 | 2341 |
*/ |
9 | 2342 |
function get_pagenum_link( $pagenum = 1, $escape = true ) { |
0 | 2343 |
global $wp_rewrite; |
2344 |
||
2345 |
$pagenum = (int) $pagenum; |
|
2346 |
||
2347 |
$request = remove_query_arg( 'paged' ); |
|
2348 |
||
9 | 2349 |
$home_root = parse_url( home_url() ); |
2350 |
$home_root = ( isset( $home_root['path'] ) ) ? $home_root['path'] : ''; |
|
0 | 2351 |
$home_root = preg_quote( $home_root, '|' ); |
2352 |
||
9 | 2353 |
$request = preg_replace( '|^' . $home_root . '|i', '', $request ); |
2354 |
$request = preg_replace( '|^/+|', '', $request ); |
|
2355 |
||
2356 |
if ( ! $wp_rewrite->using_permalinks() || is_admin() ) { |
|
0 | 2357 |
$base = trailingslashit( get_bloginfo( 'url' ) ); |
2358 |
||
2359 |
if ( $pagenum > 1 ) { |
|
2360 |
$result = add_query_arg( 'paged', $pagenum, $base . $request ); |
|
2361 |
} else { |
|
2362 |
$result = $base . $request; |
|
2363 |
} |
|
2364 |
} else { |
|
2365 |
$qs_regex = '|\?.*?$|'; |
|
2366 |
preg_match( $qs_regex, $request, $qs_match ); |
|
2367 |
||
9 | 2368 |
if ( ! empty( $qs_match[0] ) ) { |
0 | 2369 |
$query_string = $qs_match[0]; |
9 | 2370 |
$request = preg_replace( $qs_regex, '', $request ); |
0 | 2371 |
} else { |
2372 |
$query_string = ''; |
|
2373 |
} |
|
2374 |
||
9 | 2375 |
$request = preg_replace( "|$wp_rewrite->pagination_base/\d+/?$|", '', $request ); |
2376 |
$request = preg_replace( '|^' . preg_quote( $wp_rewrite->index, '|' ) . '|i', '', $request ); |
|
2377 |
$request = ltrim( $request, '/' ); |
|
0 | 2378 |
|
2379 |
$base = trailingslashit( get_bloginfo( 'url' ) ); |
|
2380 |
||
16 | 2381 |
if ( $wp_rewrite->using_index_permalinks() && ( $pagenum > 1 || '' !== $request ) ) { |
0 | 2382 |
$base .= $wp_rewrite->index . '/'; |
9 | 2383 |
} |
0 | 2384 |
|
2385 |
if ( $pagenum > 1 ) { |
|
9 | 2386 |
$request = ( ( ! empty( $request ) ) ? trailingslashit( $request ) : $request ) . user_trailingslashit( $wp_rewrite->pagination_base . '/' . $pagenum, 'paged' ); |
0 | 2387 |
} |
2388 |
||
2389 |
$result = $base . $request . $query_string; |
|
2390 |
} |
|
2391 |
||
5 | 2392 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2393 |
* Filters the page number link for the current request. |
5 | 2394 |
* |
2395 |
* @since 2.5.0 |
|
9 | 2396 |
* @since 5.2.0 Added the `$pagenum` argument. |
5 | 2397 |
* |
9 | 2398 |
* @param string $result The page number link. |
2399 |
* @param int $pagenum The page number. |
|
5 | 2400 |
*/ |
9 | 2401 |
$result = apply_filters( 'get_pagenum_link', $result, $pagenum ); |
2402 |
||
2403 |
if ( $escape ) { |
|
0 | 2404 |
return esc_url( $result ); |
9 | 2405 |
} else { |
0 | 2406 |
return esc_url_raw( $result ); |
9 | 2407 |
} |
0 | 2408 |
} |
2409 |
||
2410 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2411 |
* Retrieves the next posts page link. |
0 | 2412 |
* |
2413 |
* Backported from 2.1.3 to 2.0.10. |
|
2414 |
* |
|
2415 |
* @since 2.0.10 |
|
2416 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2417 |
* @global int $paged |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2418 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2419 |
* @param int $max_page Optional. Max pages. Default 0. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2420 |
* @return string|void The link URL for next posts page. |
0 | 2421 |
*/ |
9 | 2422 |
function get_next_posts_page_link( $max_page = 0 ) { |
0 | 2423 |
global $paged; |
2424 |
||
9 | 2425 |
if ( ! is_single() ) { |
2426 |
if ( ! $paged ) { |
|
0 | 2427 |
$paged = 1; |
9 | 2428 |
} |
18 | 2429 |
$nextpage = (int) $paged + 1; |
9 | 2430 |
if ( ! $max_page || $max_page >= $nextpage ) { |
2431 |
return get_pagenum_link( $nextpage ); |
|
2432 |
} |
|
0 | 2433 |
} |
2434 |
} |
|
2435 |
||
2436 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2437 |
* Displays or retrieves the next posts page link. |
0 | 2438 |
* |
2439 |
* @since 0.71 |
|
2440 |
* |
|
16 | 2441 |
* @param int $max_page Optional. Max pages. Default 0. |
2442 |
* @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
|
2443 |
* @return string|void The link URL for next posts page if `$echo = false`. |
0 | 2444 |
*/ |
2445 |
function next_posts( $max_page = 0, $echo = true ) { |
|
2446 |
$output = esc_url( get_next_posts_page_link( $max_page ) ); |
|
2447 |
||
9 | 2448 |
if ( $echo ) { |
0 | 2449 |
echo $output; |
9 | 2450 |
} else { |
0 | 2451 |
return $output; |
9 | 2452 |
} |
0 | 2453 |
} |
2454 |
||
2455 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2456 |
* Retrieves the next posts page link. |
0 | 2457 |
* |
2458 |
* @since 2.7.0 |
|
2459 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2460 |
* @global int $paged |
16 | 2461 |
* @global WP_Query $wp_query WordPress Query object. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2462 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2463 |
* @param string $label Content for link text. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2464 |
* @param int $max_page Optional. Max pages. Default 0. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2465 |
* @return string|void HTML-formatted next posts page link. |
0 | 2466 |
*/ |
2467 |
function get_next_posts_link( $label = null, $max_page = 0 ) { |
|
2468 |
global $paged, $wp_query; |
|
2469 |
||
9 | 2470 |
if ( ! $max_page ) { |
0 | 2471 |
$max_page = $wp_query->max_num_pages; |
9 | 2472 |
} |
2473 |
||
2474 |
if ( ! $paged ) { |
|
0 | 2475 |
$paged = 1; |
9 | 2476 |
} |
2477 |
||
18 | 2478 |
$nextpage = (int) $paged + 1; |
9 | 2479 |
|
2480 |
if ( null === $label ) { |
|
0 | 2481 |
$label = __( 'Next Page »' ); |
9 | 2482 |
} |
2483 |
||
2484 |
if ( ! is_single() && ( $nextpage <= $max_page ) ) { |
|
5 | 2485 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2486 |
* Filters the anchor tag attributes for the next posts page link. |
5 | 2487 |
* |
2488 |
* @since 2.7.0 |
|
2489 |
* |
|
2490 |
* @param string $attributes Attributes for the anchor tag. |
|
2491 |
*/ |
|
0 | 2492 |
$attr = apply_filters( 'next_posts_link_attributes', '' ); |
5 | 2493 |
|
9 | 2494 |
return '<a href="' . next_posts( $max_page, false ) . "\" $attr>" . preg_replace( '/&([^#])(?![a-z]{1,8};)/i', '&$1', $label ) . '</a>'; |
0 | 2495 |
} |
2496 |
} |
|
2497 |
||
2498 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2499 |
* Displays the next posts page link. |
0 | 2500 |
* |
2501 |
* @since 0.71 |
|
2502 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2503 |
* @param string $label Content for link text. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2504 |
* @param int $max_page Optional. Max pages. Default 0. |
0 | 2505 |
*/ |
2506 |
function next_posts_link( $label = null, $max_page = 0 ) { |
|
2507 |
echo get_next_posts_link( $label, $max_page ); |
|
2508 |
} |
|
2509 |
||
2510 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2511 |
* Retrieves the previous posts page link. |
0 | 2512 |
* |
2513 |
* Will only return string, if not on a single page or post. |
|
2514 |
* |
|
2515 |
* Backported to 2.0.10 from 2.1.3. |
|
2516 |
* |
|
2517 |
* @since 2.0.10 |
|
2518 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2519 |
* @global int $paged |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2520 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2521 |
* @return string|void The link for the previous posts page. |
0 | 2522 |
*/ |
2523 |
function get_previous_posts_page_link() { |
|
2524 |
global $paged; |
|
2525 |
||
9 | 2526 |
if ( ! is_single() ) { |
18 | 2527 |
$nextpage = (int) $paged - 1; |
9 | 2528 |
if ( $nextpage < 1 ) { |
0 | 2529 |
$nextpage = 1; |
9 | 2530 |
} |
2531 |
return get_pagenum_link( $nextpage ); |
|
0 | 2532 |
} |
2533 |
} |
|
2534 |
||
2535 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2536 |
* Displays or retrieves the previous posts page link. |
0 | 2537 |
* |
2538 |
* @since 0.71 |
|
2539 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2540 |
* @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
|
2541 |
* @return string|void The previous posts page link if `$echo = false`. |
0 | 2542 |
*/ |
2543 |
function previous_posts( $echo = true ) { |
|
2544 |
$output = esc_url( get_previous_posts_page_link() ); |
|
2545 |
||
9 | 2546 |
if ( $echo ) { |
0 | 2547 |
echo $output; |
9 | 2548 |
} else { |
0 | 2549 |
return $output; |
9 | 2550 |
} |
0 | 2551 |
} |
2552 |
||
2553 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2554 |
* Retrieves the previous posts page link. |
0 | 2555 |
* |
2556 |
* @since 2.7.0 |
|
2557 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2558 |
* @global int $paged |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2559 |
* |
0 | 2560 |
* @param string $label Optional. Previous page link text. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2561 |
* @return string|void HTML-formatted previous page link. |
0 | 2562 |
*/ |
2563 |
function get_previous_posts_link( $label = null ) { |
|
2564 |
global $paged; |
|
2565 |
||
9 | 2566 |
if ( null === $label ) { |
0 | 2567 |
$label = __( '« Previous Page' ); |
9 | 2568 |
} |
2569 |
||
2570 |
if ( ! is_single() && $paged > 1 ) { |
|
5 | 2571 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2572 |
* Filters the anchor tag attributes for the previous posts page link. |
5 | 2573 |
* |
2574 |
* @since 2.7.0 |
|
2575 |
* |
|
2576 |
* @param string $attributes Attributes for the anchor tag. |
|
2577 |
*/ |
|
0 | 2578 |
$attr = apply_filters( 'previous_posts_link_attributes', '' ); |
9 | 2579 |
return '<a href="' . previous_posts( false ) . "\" $attr>" . preg_replace( '/&([^#])(?![a-z]{1,8};)/i', '&$1', $label ) . '</a>'; |
0 | 2580 |
} |
2581 |
} |
|
2582 |
||
2583 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2584 |
* Displays the previous posts page link. |
0 | 2585 |
* |
2586 |
* @since 0.71 |
|
2587 |
* |
|
2588 |
* @param string $label Optional. Previous page link text. |
|
2589 |
*/ |
|
2590 |
function previous_posts_link( $label = null ) { |
|
2591 |
echo get_previous_posts_link( $label ); |
|
2592 |
} |
|
2593 |
||
2594 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2595 |
* Retrieves the post pages link navigation for previous and next pages. |
0 | 2596 |
* |
5 | 2597 |
* @since 2.8.0 |
0 | 2598 |
* |
16 | 2599 |
* @global WP_Query $wp_query WordPress Query object. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2600 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2601 |
* @param string|array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2602 |
* Optional. Arguments to build the post pages link navigation. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2603 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2604 |
* @type string $sep Separator character. Default '—'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2605 |
* @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
|
2606 |
* Default '« Previous Page'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2607 |
* @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
|
2608 |
* Default 'Next Page »'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2609 |
* } |
0 | 2610 |
* @return string The posts link navigation. |
2611 |
*/ |
|
2612 |
function get_posts_nav_link( $args = array() ) { |
|
2613 |
global $wp_query; |
|
2614 |
||
2615 |
$return = ''; |
|
2616 |
||
9 | 2617 |
if ( ! is_singular() ) { |
0 | 2618 |
$defaults = array( |
9 | 2619 |
'sep' => ' — ', |
2620 |
'prelabel' => __( '« Previous Page' ), |
|
2621 |
'nxtlabel' => __( 'Next Page »' ), |
|
0 | 2622 |
); |
9 | 2623 |
$args = wp_parse_args( $args, $defaults ); |
0 | 2624 |
|
2625 |
$max_num_pages = $wp_query->max_num_pages; |
|
9 | 2626 |
$paged = get_query_var( 'paged' ); |
0 | 2627 |
|
16 | 2628 |
// Only have sep if there's both prev and next results. |
9 | 2629 |
if ( $paged < 2 || $paged >= $max_num_pages ) { |
0 | 2630 |
$args['sep'] = ''; |
2631 |
} |
|
2632 |
||
2633 |
if ( $max_num_pages > 1 ) { |
|
9 | 2634 |
$return = get_previous_posts_link( $args['prelabel'] ); |
2635 |
$return .= preg_replace( '/&([^#])(?![a-z]{1,8};)/i', '&$1', $args['sep'] ); |
|
2636 |
$return .= get_next_posts_link( $args['nxtlabel'] ); |
|
0 | 2637 |
} |
2638 |
} |
|
2639 |
return $return; |
|
2640 |
||
2641 |
} |
|
2642 |
||
2643 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2644 |
* Displays the post pages link navigation for previous and next pages. |
0 | 2645 |
* |
2646 |
* @since 0.71 |
|
2647 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2648 |
* @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
|
2649 |
* @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
|
2650 |
* @param string $nxtlabel Optional Label for next pages. Default empty. |
0 | 2651 |
*/ |
2652 |
function posts_nav_link( $sep = '', $prelabel = '', $nxtlabel = '' ) { |
|
9 | 2653 |
$args = array_filter( compact( 'sep', 'prelabel', 'nxtlabel' ) ); |
2654 |
echo get_posts_nav_link( $args ); |
|
0 | 2655 |
} |
2656 |
||
2657 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2658 |
* Retrieves the navigation to next/previous post, when applicable. |
5 | 2659 |
* |
2660 |
* @since 4.1.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2661 |
* @since 4.4.0 Introduced the `in_same_term`, `excluded_terms`, and `taxonomy` arguments. |
16 | 2662 |
* @since 5.3.0 Added the `aria_label` parameter. |
2663 |
* @since 5.5.0 Added the `class` parameter. |
|
5 | 2664 |
* |
2665 |
* @param array $args { |
|
2666 |
* Optional. Default post navigation arguments. Default empty array. |
|
2667 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2668 |
* @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
|
2669 |
* @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
|
2670 |
* @type bool $in_same_term Whether link should be in a same taxonomy term. Default false. |
18 | 2671 |
* @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
|
2672 |
* @type string $taxonomy Taxonomy, if `$in_same_term` is true. Default 'category'. |
16 | 2673 |
* @type string $screen_reader_text Screen reader text for the nav element. Default 'Post navigation'. |
2674 |
* @type string $aria_label ARIA label text for the nav element. Default 'Posts'. |
|
2675 |
* @type string $class Custom class for the nav element. Default 'post-navigation'. |
|
5 | 2676 |
* } |
2677 |
* @return string Markup for post links. |
|
2678 |
*/ |
|
2679 |
function get_the_post_navigation( $args = array() ) { |
|
16 | 2680 |
// Make sure the nav element has an aria-label attribute: fallback to the screen reader text. |
2681 |
if ( ! empty( $args['screen_reader_text'] ) && empty( $args['aria_label'] ) ) { |
|
2682 |
$args['aria_label'] = $args['screen_reader_text']; |
|
2683 |
} |
|
2684 |
||
9 | 2685 |
$args = wp_parse_args( |
2686 |
$args, |
|
2687 |
array( |
|
2688 |
'prev_text' => '%title', |
|
2689 |
'next_text' => '%title', |
|
2690 |
'in_same_term' => false, |
|
2691 |
'excluded_terms' => '', |
|
2692 |
'taxonomy' => 'category', |
|
2693 |
'screen_reader_text' => __( 'Post navigation' ), |
|
16 | 2694 |
'aria_label' => __( 'Posts' ), |
2695 |
'class' => 'post-navigation', |
|
9 | 2696 |
) |
2697 |
); |
|
5 | 2698 |
|
2699 |
$navigation = ''; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2700 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2701 |
$previous = get_previous_post_link( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2702 |
'<div class="nav-previous">%link</div>', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2703 |
$args['prev_text'], |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2704 |
$args['in_same_term'], |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2705 |
$args['excluded_terms'], |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2706 |
$args['taxonomy'] |
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 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2709 |
$next = get_next_post_link( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2710 |
'<div class="nav-next">%link</div>', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2711 |
$args['next_text'], |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2712 |
$args['in_same_term'], |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2713 |
$args['excluded_terms'], |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2714 |
$args['taxonomy'] |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2715 |
); |
5 | 2716 |
|
2717 |
// Only add markup if there's somewhere to navigate to. |
|
2718 |
if ( $previous || $next ) { |
|
16 | 2719 |
$navigation = _navigation_markup( $previous . $next, $args['class'], $args['screen_reader_text'], $args['aria_label'] ); |
5 | 2720 |
} |
2721 |
||
2722 |
return $navigation; |
|
2723 |
} |
|
2724 |
||
2725 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2726 |
* Displays the navigation to next/previous post, when applicable. |
5 | 2727 |
* |
2728 |
* @since 4.1.0 |
|
2729 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2730 |
* @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
|
2731 |
* Default empty array. |
5 | 2732 |
*/ |
2733 |
function the_post_navigation( $args = array() ) { |
|
2734 |
echo get_the_post_navigation( $args ); |
|
2735 |
} |
|
2736 |
||
2737 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2738 |
* Returns the navigation to next/previous set of posts, when applicable. |
5 | 2739 |
* |
2740 |
* @since 4.1.0 |
|
16 | 2741 |
* @since 5.3.0 Added the `aria_label` parameter. |
2742 |
* @since 5.5.0 Added the `class` parameter. |
|
5 | 2743 |
* |
2744 |
* @global WP_Query $wp_query WordPress Query object. |
|
2745 |
* |
|
2746 |
* @param array $args { |
|
2747 |
* Optional. Default posts navigation arguments. Default empty array. |
|
2748 |
* |
|
2749 |
* @type string $prev_text Anchor text to display in the previous posts link. |
|
2750 |
* Default 'Older posts'. |
|
2751 |
* @type string $next_text Anchor text to display in the next posts link. |
|
2752 |
* Default 'Newer posts'. |
|
16 | 2753 |
* @type string $screen_reader_text Screen reader text for the nav element. |
5 | 2754 |
* Default 'Posts navigation'. |
16 | 2755 |
* @type string $aria_label ARIA label text for the nav element. Default 'Posts'. |
2756 |
* @type string $class Custom class for the nav element. Default 'posts-navigation'. |
|
5 | 2757 |
* } |
2758 |
* @return string Markup for posts links. |
|
2759 |
*/ |
|
2760 |
function get_the_posts_navigation( $args = array() ) { |
|
2761 |
$navigation = ''; |
|
2762 |
||
2763 |
// Don't print empty markup if there's only one page. |
|
2764 |
if ( $GLOBALS['wp_query']->max_num_pages > 1 ) { |
|
16 | 2765 |
// Make sure the nav element has an aria-label attribute: fallback to the screen reader text. |
2766 |
if ( ! empty( $args['screen_reader_text'] ) && empty( $args['aria_label'] ) ) { |
|
2767 |
$args['aria_label'] = $args['screen_reader_text']; |
|
2768 |
} |
|
2769 |
||
9 | 2770 |
$args = wp_parse_args( |
2771 |
$args, |
|
2772 |
array( |
|
2773 |
'prev_text' => __( 'Older posts' ), |
|
2774 |
'next_text' => __( 'Newer posts' ), |
|
2775 |
'screen_reader_text' => __( 'Posts navigation' ), |
|
16 | 2776 |
'aria_label' => __( 'Posts' ), |
2777 |
'class' => 'posts-navigation', |
|
9 | 2778 |
) |
2779 |
); |
|
5 | 2780 |
|
2781 |
$next_link = get_previous_posts_link( $args['next_text'] ); |
|
2782 |
$prev_link = get_next_posts_link( $args['prev_text'] ); |
|
2783 |
||
2784 |
if ( $prev_link ) { |
|
2785 |
$navigation .= '<div class="nav-previous">' . $prev_link . '</div>'; |
|
2786 |
} |
|
2787 |
||
2788 |
if ( $next_link ) { |
|
2789 |
$navigation .= '<div class="nav-next">' . $next_link . '</div>'; |
|
2790 |
} |
|
2791 |
||
16 | 2792 |
$navigation = _navigation_markup( $navigation, $args['class'], $args['screen_reader_text'], $args['aria_label'] ); |
5 | 2793 |
} |
2794 |
||
2795 |
return $navigation; |
|
2796 |
} |
|
2797 |
||
2798 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2799 |
* Displays the navigation to next/previous set of posts, when applicable. |
5 | 2800 |
* |
2801 |
* @since 4.1.0 |
|
2802 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2803 |
* @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
|
2804 |
* Default empty array. |
5 | 2805 |
*/ |
2806 |
function the_posts_navigation( $args = array() ) { |
|
2807 |
echo get_the_posts_navigation( $args ); |
|
2808 |
} |
|
2809 |
||
2810 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2811 |
* Retrieves a paginated navigation to next/previous set of posts, when applicable. |
5 | 2812 |
* |
2813 |
* @since 4.1.0 |
|
16 | 2814 |
* @since 5.3.0 Added the `aria_label` parameter. |
2815 |
* @since 5.5.0 Added the `class` parameter. |
|
5 | 2816 |
* |
2817 |
* @param array $args { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2818 |
* Optional. Default pagination arguments, see paginate_links(). |
5 | 2819 |
* |
2820 |
* @type string $screen_reader_text Screen reader text for navigation element. |
|
2821 |
* Default 'Posts navigation'. |
|
16 | 2822 |
* @type string $aria_label ARIA label text for the nav element. Default 'Posts'. |
2823 |
* @type string $class Custom class for the nav element. Default 'pagination'. |
|
5 | 2824 |
* } |
2825 |
* @return string Markup for pagination links. |
|
2826 |
*/ |
|
2827 |
function get_the_posts_pagination( $args = array() ) { |
|
2828 |
$navigation = ''; |
|
2829 |
||
2830 |
// Don't print empty markup if there's only one page. |
|
2831 |
if ( $GLOBALS['wp_query']->max_num_pages > 1 ) { |
|
16 | 2832 |
// Make sure the nav element has an aria-label attribute: fallback to the screen reader text. |
2833 |
if ( ! empty( $args['screen_reader_text'] ) && empty( $args['aria_label'] ) ) { |
|
2834 |
$args['aria_label'] = $args['screen_reader_text']; |
|
2835 |
} |
|
2836 |
||
9 | 2837 |
$args = wp_parse_args( |
2838 |
$args, |
|
2839 |
array( |
|
2840 |
'mid_size' => 1, |
|
2841 |
'prev_text' => _x( 'Previous', 'previous set of posts' ), |
|
2842 |
'next_text' => _x( 'Next', 'next set of posts' ), |
|
2843 |
'screen_reader_text' => __( 'Posts navigation' ), |
|
16 | 2844 |
'aria_label' => __( 'Posts' ), |
2845 |
'class' => 'pagination', |
|
9 | 2846 |
) |
2847 |
); |
|
5 | 2848 |
|
2849 |
// Make sure we get a string back. Plain is the next best thing. |
|
16 | 2850 |
if ( isset( $args['type'] ) && 'array' === $args['type'] ) { |
5 | 2851 |
$args['type'] = 'plain'; |
2852 |
} |
|
2853 |
||
2854 |
// Set up paginated links. |
|
2855 |
$links = paginate_links( $args ); |
|
2856 |
||
2857 |
if ( $links ) { |
|
16 | 2858 |
$navigation = _navigation_markup( $links, $args['class'], $args['screen_reader_text'], $args['aria_label'] ); |
5 | 2859 |
} |
2860 |
} |
|
2861 |
||
2862 |
return $navigation; |
|
2863 |
} |
|
2864 |
||
2865 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2866 |
* Displays a paginated navigation to next/previous set of posts, when applicable. |
5 | 2867 |
* |
2868 |
* @since 4.1.0 |
|
2869 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2870 |
* @param array $args Optional. See get_the_posts_pagination() for available arguments. |
5 | 2871 |
* Default empty array. |
2872 |
*/ |
|
2873 |
function the_posts_pagination( $args = array() ) { |
|
2874 |
echo get_the_posts_pagination( $args ); |
|
2875 |
} |
|
2876 |
||
2877 |
/** |
|
2878 |
* Wraps passed links in navigational markup. |
|
2879 |
* |
|
2880 |
* @since 4.1.0 |
|
16 | 2881 |
* @since 5.3.0 Added the `aria_label` parameter. |
5 | 2882 |
* @access private |
2883 |
* |
|
2884 |
* @param string $links Navigational links. |
|
16 | 2885 |
* @param string $class Optional. Custom class for the nav element. |
2886 |
* Default 'posts-navigation'. |
|
2887 |
* @param string $screen_reader_text Optional. Screen reader text for the nav element. |
|
2888 |
* Default 'Posts navigation'. |
|
2889 |
* @param string $aria_label Optional. ARIA label for the nav element. |
|
2890 |
* Defaults to the value of `$screen_reader_text`. |
|
5 | 2891 |
* @return string Navigation template tag. |
2892 |
*/ |
|
16 | 2893 |
function _navigation_markup( $links, $class = 'posts-navigation', $screen_reader_text = '', $aria_label = '' ) { |
5 | 2894 |
if ( empty( $screen_reader_text ) ) { |
2895 |
$screen_reader_text = __( 'Posts navigation' ); |
|
2896 |
} |
|
16 | 2897 |
if ( empty( $aria_label ) ) { |
2898 |
$aria_label = $screen_reader_text; |
|
2899 |
} |
|
5 | 2900 |
|
2901 |
$template = ' |
|
16 | 2902 |
<nav class="navigation %1$s" role="navigation" aria-label="%4$s"> |
5 | 2903 |
<h2 class="screen-reader-text">%2$s</h2> |
2904 |
<div class="nav-links">%3$s</div> |
|
2905 |
</nav>'; |
|
2906 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2907 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2908 |
* Filters the navigation markup template. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2909 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2910 |
* Note: The filtered template HTML must contain specifiers for the navigation |
16 | 2911 |
* class (%1$s), the screen-reader-text value (%2$s), placement of the navigation |
2912 |
* 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
|
2913 |
* |
16 | 2914 |
* <nav class="navigation %1$s" role="navigation" aria-label="%4$s"> |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2915 |
* <h2 class="screen-reader-text">%2$s</h2> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2916 |
* <div class="nav-links">%3$s</div> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2917 |
* </nav> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2918 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2919 |
* @since 4.4.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2920 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2921 |
* @param string $template The default template. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2922 |
* @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
|
2923 |
* @return string Navigation template. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2924 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2925 |
$template = apply_filters( 'navigation_markup_template', $template, $class ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2926 |
|
16 | 2927 |
return sprintf( $template, sanitize_html_class( $class ), esc_html( $screen_reader_text ), $links, esc_html( $aria_label ) ); |
5 | 2928 |
} |
2929 |
||
2930 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2931 |
* Retrieves the comments page number link. |
0 | 2932 |
* |
2933 |
* @since 2.7.0 |
|
2934 |
* |
|
16 | 2935 |
* @global WP_Rewrite $wp_rewrite WordPress rewrite component. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2936 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2937 |
* @param int $pagenum Optional. Page number. Default 1. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2938 |
* @param int $max_page Optional. The maximum number of comment pages. Default 0. |
5 | 2939 |
* @return string The comments page number link URL. |
0 | 2940 |
*/ |
2941 |
function get_comments_pagenum_link( $pagenum = 1, $max_page = 0 ) { |
|
2942 |
global $wp_rewrite; |
|
2943 |
||
2944 |
$pagenum = (int) $pagenum; |
|
2945 |
||
2946 |
$result = get_permalink(); |
|
2947 |
||
16 | 2948 |
if ( 'newest' === get_option( 'default_comments_page' ) ) { |
0 | 2949 |
if ( $pagenum != $max_page ) { |
9 | 2950 |
if ( $wp_rewrite->using_permalinks() ) { |
2951 |
$result = user_trailingslashit( trailingslashit( $result ) . $wp_rewrite->comments_pagination_base . '-' . $pagenum, 'commentpaged' ); |
|
2952 |
} else { |
|
0 | 2953 |
$result = add_query_arg( 'cpage', $pagenum, $result ); |
9 | 2954 |
} |
0 | 2955 |
} |
2956 |
} elseif ( $pagenum > 1 ) { |
|
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 |
||
2964 |
$result .= '#comments'; |
|
2965 |
||
5 | 2966 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2967 |
* Filters the comments page number link for the current request. |
5 | 2968 |
* |
2969 |
* @since 2.7.0 |
|
2970 |
* |
|
2971 |
* @param string $result The comments page number link. |
|
2972 |
*/ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2973 |
return apply_filters( 'get_comments_pagenum_link', $result ); |
0 | 2974 |
} |
2975 |
||
2976 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2977 |
* Retrieves the link to the next comments page. |
0 | 2978 |
* |
2979 |
* @since 2.7.1 |
|
2980 |
* |
|
16 | 2981 |
* @global WP_Query $wp_query WordPress Query object. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2982 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2983 |
* @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
|
2984 |
* @param int $max_page Optional. Max page. Default 0. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2985 |
* @return string|void HTML-formatted link for the next page of comments. |
0 | 2986 |
*/ |
2987 |
function get_next_comments_link( $label = '', $max_page = 0 ) { |
|
2988 |
global $wp_query; |
|
2989 |
||
9 | 2990 |
if ( ! is_singular() ) { |
0 | 2991 |
return; |
9 | 2992 |
} |
2993 |
||
2994 |
$page = get_query_var( 'cpage' ); |
|
0 | 2995 |
|
5 | 2996 |
if ( ! $page ) { |
2997 |
$page = 1; |
|
2998 |
} |
|
2999 |
||
18 | 3000 |
$nextpage = (int) $page + 1; |
9 | 3001 |
|
3002 |
if ( empty( $max_page ) ) { |
|
0 | 3003 |
$max_page = $wp_query->max_num_comment_pages; |
9 | 3004 |
} |
3005 |
||
3006 |
if ( empty( $max_page ) ) { |
|
0 | 3007 |
$max_page = get_comment_pages_count(); |
9 | 3008 |
} |
3009 |
||
3010 |
if ( $nextpage > $max_page ) { |
|
0 | 3011 |
return; |
9 | 3012 |
} |
3013 |
||
3014 |
if ( empty( $label ) ) { |
|
3015 |
$label = __( 'Newer Comments »' ); |
|
3016 |
} |
|
0 | 3017 |
|
5 | 3018 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3019 |
* Filters the anchor tag attributes for the next comments page link. |
5 | 3020 |
* |
3021 |
* @since 2.7.0 |
|
3022 |
* |
|
3023 |
* @param string $attributes Attributes for the anchor tag. |
|
3024 |
*/ |
|
9 | 3025 |
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 | 3026 |
} |
3027 |
||
3028 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3029 |
* Displays the link to the next comments page. |
0 | 3030 |
* |
3031 |
* @since 2.7.0 |
|
3032 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3033 |
* @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
|
3034 |
* @param int $max_page Optional. Max page. Default 0. |
0 | 3035 |
*/ |
3036 |
function next_comments_link( $label = '', $max_page = 0 ) { |
|
3037 |
echo get_next_comments_link( $label, $max_page ); |
|
3038 |
} |
|
3039 |
||
3040 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3041 |
* Retrieves the link to the previous comments page. |
0 | 3042 |
* |
3043 |
* @since 2.7.1 |
|
3044 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3045 |
* @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
|
3046 |
* @return string|void HTML-formatted link for the previous page of comments. |
0 | 3047 |
*/ |
3048 |
function get_previous_comments_link( $label = '' ) { |
|
9 | 3049 |
if ( ! is_singular() ) { |
3050 |
return; |
|
3051 |
} |
|
3052 |
||
3053 |
$page = get_query_var( 'cpage' ); |
|
3054 |
||
18 | 3055 |
if ( (int) $page <= 1 ) { |
0 | 3056 |
return; |
9 | 3057 |
} |
3058 |
||
18 | 3059 |
$prevpage = (int) $page - 1; |
9 | 3060 |
|
3061 |
if ( empty( $label ) ) { |
|
3062 |
$label = __( '« Older Comments' ); |
|
3063 |
} |
|
0 | 3064 |
|
5 | 3065 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3066 |
* Filters the anchor tag attributes for the previous comments page link. |
5 | 3067 |
* |
3068 |
* @since 2.7.0 |
|
3069 |
* |
|
3070 |
* @param string $attributes Attributes for the anchor tag. |
|
3071 |
*/ |
|
9 | 3072 |
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 | 3073 |
} |
3074 |
||
3075 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3076 |
* Displays the link to the previous comments page. |
0 | 3077 |
* |
3078 |
* @since 2.7.0 |
|
3079 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3080 |
* @param string $label Optional. Label for comments link text. Default empty. |
0 | 3081 |
*/ |
3082 |
function previous_comments_link( $label = '' ) { |
|
3083 |
echo get_previous_comments_link( $label ); |
|
3084 |
} |
|
3085 |
||
3086 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3087 |
* Displays or retrieves pagination links for the comments on the current post. |
0 | 3088 |
* |
3089 |
* @see paginate_links() |
|
3090 |
* @since 2.7.0 |
|
3091 |
* |
|
16 | 3092 |
* @global WP_Rewrite $wp_rewrite WordPress rewrite component. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3093 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3094 |
* @param string|array $args Optional args. See paginate_links(). Default empty array. |
16 | 3095 |
* @return void|string|array Void if 'echo' argument is true and 'type' is not an array, |
3096 |
* or if the query is not for an existing single post of any post type. |
|
3097 |
* Otherwise, markup for comment page links or array of comment page links, |
|
3098 |
* depending on 'type' argument. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3099 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3100 |
function paginate_comments_links( $args = array() ) { |
0 | 3101 |
global $wp_rewrite; |
3102 |
||
9 | 3103 |
if ( ! is_singular() ) { |
0 | 3104 |
return; |
9 | 3105 |
} |
3106 |
||
3107 |
$page = get_query_var( 'cpage' ); |
|
3108 |
if ( ! $page ) { |
|
0 | 3109 |
$page = 1; |
9 | 3110 |
} |
0 | 3111 |
$max_page = get_comment_pages_count(); |
3112 |
$defaults = array( |
|
9 | 3113 |
'base' => add_query_arg( 'cpage', '%#%' ), |
3114 |
'format' => '', |
|
3115 |
'total' => $max_page, |
|
3116 |
'current' => $page, |
|
3117 |
'echo' => true, |
|
3118 |
'type' => 'plain', |
|
3119 |
'add_fragment' => '#comments', |
|
0 | 3120 |
); |
9 | 3121 |
if ( $wp_rewrite->using_permalinks() ) { |
3122 |
$defaults['base'] = user_trailingslashit( trailingslashit( get_permalink() ) . $wp_rewrite->comments_pagination_base . '-%#%', 'commentpaged' ); |
|
3123 |
} |
|
3124 |
||
3125 |
$args = wp_parse_args( $args, $defaults ); |
|
0 | 3126 |
$page_links = paginate_links( $args ); |
3127 |
||
9 | 3128 |
if ( $args['echo'] && 'array' !== $args['type'] ) { |
0 | 3129 |
echo $page_links; |
9 | 3130 |
} else { |
0 | 3131 |
return $page_links; |
9 | 3132 |
} |
0 | 3133 |
} |
3134 |
||
3135 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3136 |
* 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
|
3137 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3138 |
* @since 4.4.0 |
16 | 3139 |
* @since 5.3.0 Added the `aria_label` parameter. |
3140 |
* @since 5.5.0 Added the `class` parameter. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3141 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3142 |
* @param array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3143 |
* Optional. Default comments navigation arguments. |
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 |
* @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
|
3146 |
* Default 'Older comments'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3147 |
* @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
|
3148 |
* Default 'Newer comments'. |
16 | 3149 |
* @type string $screen_reader_text Screen reader text for the nav element. Default 'Comments navigation'. |
3150 |
* @type string $aria_label ARIA label text for the nav element. Default 'Comments'. |
|
3151 |
* @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
|
3152 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3153 |
* @return string Markup for comments links. |
0 | 3154 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3155 |
function get_the_comments_navigation( $args = array() ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3156 |
$navigation = ''; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3157 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3158 |
// Are there comments to navigate through? |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3159 |
if ( get_comment_pages_count() > 1 ) { |
16 | 3160 |
// Make sure the nav element has an aria-label attribute: fallback to the screen reader text. |
3161 |
if ( ! empty( $args['screen_reader_text'] ) && empty( $args['aria_label'] ) ) { |
|
3162 |
$args['aria_label'] = $args['screen_reader_text']; |
|
3163 |
} |
|
3164 |
||
9 | 3165 |
$args = wp_parse_args( |
3166 |
$args, |
|
3167 |
array( |
|
3168 |
'prev_text' => __( 'Older comments' ), |
|
3169 |
'next_text' => __( 'Newer comments' ), |
|
3170 |
'screen_reader_text' => __( 'Comments navigation' ), |
|
16 | 3171 |
'aria_label' => __( 'Comments' ), |
3172 |
'class' => 'comment-navigation', |
|
9 | 3173 |
) |
3174 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3175 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3176 |
$prev_link = get_previous_comments_link( $args['prev_text'] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3177 |
$next_link = get_next_comments_link( $args['next_text'] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3178 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3179 |
if ( $prev_link ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3180 |
$navigation .= '<div class="nav-previous">' . $prev_link . '</div>'; |
5 | 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 |
if ( $next_link ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3184 |
$navigation .= '<div class="nav-next">' . $next_link . '</div>'; |
5 | 3185 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3186 |
|
16 | 3187 |
$navigation = _navigation_markup( $navigation, $args['class'], $args['screen_reader_text'], $args['aria_label'] ); |
5 | 3188 |
} |
3189 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3190 |
return $navigation; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3191 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3192 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3193 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3194 |
* 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
|
3195 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3196 |
* @since 4.4.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3197 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3198 |
* @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
|
3199 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3200 |
function the_comments_navigation( $args = array() ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3201 |
echo get_the_comments_navigation( $args ); |
0 | 3202 |
} |
3203 |
||
3204 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3205 |
* 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
|
3206 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3207 |
* @since 4.4.0 |
16 | 3208 |
* @since 5.3.0 Added the `aria_label` parameter. |
3209 |
* @since 5.5.0 Added the `class` parameter. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3210 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3211 |
* @see paginate_comments_links() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3212 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3213 |
* @param array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3214 |
* Optional. Default pagination arguments. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3215 |
* |
16 | 3216 |
* @type string $screen_reader_text Screen reader text for the nav element. Default 'Comments navigation'. |
3217 |
* @type string $aria_label ARIA label text for the nav element. Default 'Comments'. |
|
3218 |
* @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
|
3219 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3220 |
* @return string Markup for pagination links. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3221 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3222 |
function get_the_comments_pagination( $args = array() ) { |
16 | 3223 |
$navigation = ''; |
3224 |
||
3225 |
// Make sure the nav element has an aria-label attribute: fallback to the screen reader text. |
|
3226 |
if ( ! empty( $args['screen_reader_text'] ) && empty( $args['aria_label'] ) ) { |
|
3227 |
$args['aria_label'] = $args['screen_reader_text']; |
|
3228 |
} |
|
3229 |
||
9 | 3230 |
$args = wp_parse_args( |
3231 |
$args, |
|
3232 |
array( |
|
3233 |
'screen_reader_text' => __( 'Comments navigation' ), |
|
16 | 3234 |
'aria_label' => __( 'Comments' ), |
3235 |
'class' => 'comments-pagination', |
|
9 | 3236 |
) |
3237 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3238 |
$args['echo'] = false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3239 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3240 |
// Make sure we get a string back. Plain is the next best thing. |
16 | 3241 |
if ( isset( $args['type'] ) && 'array' === $args['type'] ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3242 |
$args['type'] = 'plain'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3243 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3244 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3245 |
$links = paginate_comments_links( $args ); |
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 |
if ( $links ) { |
16 | 3248 |
$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
|
3249 |
} |
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 |
return $navigation; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3252 |
} |
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 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3255 |
* 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
|
3256 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3257 |
* @since 4.4.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3258 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3259 |
* @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
|
3260 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3261 |
function the_comments_pagination( $args = array() ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3262 |
echo get_the_comments_pagination( $args ); |
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 |
|
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 |
* 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
|
3267 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3268 |
* 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
|
3269 |
* 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
|
3270 |
* If `$scheme` is 'http' or 'https', is_ssl() is overridden. |
0 | 3271 |
* |
3272 |
* @since 3.0.0 |
|
3273 |
* |
|
16 | 3274 |
* @param string $path Optional. Path relative to the home URL. Default empty. |
3275 |
* @param string|null $scheme Optional. Scheme to give the home URL context. Accepts |
|
3276 |
* 'http', 'https', 'relative', 'rest', or null. Default null. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3277 |
* @return string Home URL link with optional path appended. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3278 |
*/ |
0 | 3279 |
function home_url( $path = '', $scheme = null ) { |
3280 |
return get_home_url( null, $path, $scheme ); |
|
3281 |
} |
|
3282 |
||
3283 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3284 |
* 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
|
3285 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3286 |
* 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
|
3287 |
* 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
|
3288 |
* If `$scheme` is 'http' or 'https', is_ssl() is overridden. |
0 | 3289 |
* |
3290 |
* @since 3.0.0 |
|
3291 |
* |
|
18 | 3292 |
* @param int|null $blog_id Optional. Site ID. Default null (current site). |
16 | 3293 |
* @param string $path Optional. Path relative to the home URL. Default empty. |
3294 |
* @param string|null $scheme Optional. Scheme to give the home URL context. Accepts |
|
3295 |
* 'http', 'https', 'relative', 'rest', or null. Default null. |
|
5 | 3296 |
* @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
|
3297 |
*/ |
0 | 3298 |
function get_home_url( $blog_id = null, $path = '', $scheme = null ) { |
3299 |
$orig_scheme = $scheme; |
|
3300 |
||
9 | 3301 |
if ( empty( $blog_id ) || ! is_multisite() ) { |
0 | 3302 |
$url = get_option( 'home' ); |
3303 |
} else { |
|
3304 |
switch_to_blog( $blog_id ); |
|
3305 |
$url = get_option( 'home' ); |
|
3306 |
restore_current_blog(); |
|
3307 |
} |
|
3308 |
||
16 | 3309 |
if ( ! in_array( $scheme, array( 'http', 'https', 'relative' ), true ) ) { |
18 | 3310 |
if ( is_ssl() ) { |
0 | 3311 |
$scheme = 'https'; |
9 | 3312 |
} else { |
0 | 3313 |
$scheme = parse_url( $url, PHP_URL_SCHEME ); |
9 | 3314 |
} |
0 | 3315 |
} |
3316 |
||
3317 |
$url = set_url_scheme( $url, $scheme ); |
|
3318 |
||
9 | 3319 |
if ( $path && is_string( $path ) ) { |
0 | 3320 |
$url .= '/' . ltrim( $path, '/' ); |
9 | 3321 |
} |
0 | 3322 |
|
5 | 3323 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3324 |
* Filters the home URL. |
5 | 3325 |
* |
3326 |
* @since 3.0.0 |
|
3327 |
* |
|
3328 |
* @param string $url The complete home URL including scheme and path. |
|
3329 |
* @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
|
3330 |
* @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
|
3331 |
* 'relative', 'rest', or null. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3332 |
* @param int|null $blog_id Site ID, or null for the current site. |
5 | 3333 |
*/ |
0 | 3334 |
return apply_filters( 'home_url', $url, $path, $orig_scheme, $blog_id ); |
3335 |
} |
|
3336 |
||
3337 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3338 |
* 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
|
3339 |
* (e.g. wp-blog-header.php or the wp-admin/ folder) are accessible. |
0 | 3340 |
* |
3341 |
* Returns the 'site_url' option with the appropriate protocol, 'https' if |
|
3342 |
* is_ssl() and 'http' otherwise. If $scheme is 'http' or 'https', is_ssl() is |
|
3343 |
* overridden. |
|
3344 |
* |
|
5 | 3345 |
* @since 3.0.0 |
0 | 3346 |
* |
18 | 3347 |
* @param string $path Optional. Path relative to the site URL. Default empty. |
3348 |
* @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
|
3349 |
* @return string Site URL link with optional path appended. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3350 |
*/ |
0 | 3351 |
function site_url( $path = '', $scheme = null ) { |
3352 |
return get_site_url( null, $path, $scheme ); |
|
3353 |
} |
|
3354 |
||
3355 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3356 |
* 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
|
3357 |
* (e.g. wp-blog-header.php or the wp-admin/ folder) are accessible. |
0 | 3358 |
* |
3359 |
* 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
|
3360 |
* is_ssl() and 'http' otherwise. If `$scheme` is 'http' or 'https', |
5 | 3361 |
* `is_ssl()` is overridden. |
0 | 3362 |
* |
3363 |
* @since 3.0.0 |
|
3364 |
* |
|
18 | 3365 |
* @param int|null $blog_id Optional. Site ID. Default null (current site). |
3366 |
* @param string $path Optional. Path relative to the site URL. Default empty. |
|
3367 |
* @param string|null $scheme Optional. Scheme to give the site URL context. Accepts |
|
3368 |
* 'http', 'https', 'login', 'login_post', 'admin', or |
|
3369 |
* 'relative'. Default null. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3370 |
* @return string Site URL link with optional path appended. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3371 |
*/ |
0 | 3372 |
function get_site_url( $blog_id = null, $path = '', $scheme = null ) { |
9 | 3373 |
if ( empty( $blog_id ) || ! is_multisite() ) { |
0 | 3374 |
$url = get_option( 'siteurl' ); |
3375 |
} else { |
|
3376 |
switch_to_blog( $blog_id ); |
|
3377 |
$url = get_option( 'siteurl' ); |
|
3378 |
restore_current_blog(); |
|
3379 |
} |
|
3380 |
||
3381 |
$url = set_url_scheme( $url, $scheme ); |
|
3382 |
||
9 | 3383 |
if ( $path && is_string( $path ) ) { |
0 | 3384 |
$url .= '/' . ltrim( $path, '/' ); |
9 | 3385 |
} |
0 | 3386 |
|
5 | 3387 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3388 |
* Filters the site URL. |
5 | 3389 |
* |
3390 |
* @since 2.7.0 |
|
3391 |
* |
|
3392 |
* @param string $url The complete site URL including scheme and path. |
|
3393 |
* @param string $path Path relative to the site URL. Blank string if no path is specified. |
|
3394 |
* @param string|null $scheme Scheme to give the site URL context. Accepts 'http', 'https', 'login', |
|
3395 |
* 'login_post', 'admin', 'relative' or null. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3396 |
* @param int|null $blog_id Site ID, or null for the current site. |
5 | 3397 |
*/ |
0 | 3398 |
return apply_filters( 'site_url', $url, $path, $scheme, $blog_id ); |
3399 |
} |
|
3400 |
||
3401 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3402 |
* Retrieves the URL to the admin area for the current site. |
0 | 3403 |
* |
3404 |
* @since 2.6.0 |
|
3405 |
* |
|
18 | 3406 |
* @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
|
3407 |
* @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
|
3408 |
* '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
|
3409 |
* @return string Admin URL link with optional path appended. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3410 |
*/ |
0 | 3411 |
function admin_url( $path = '', $scheme = 'admin' ) { |
3412 |
return get_admin_url( null, $path, $scheme ); |
|
3413 |
} |
|
3414 |
||
3415 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3416 |
* Retrieves the URL to the admin area for a given site. |
0 | 3417 |
* |
3418 |
* @since 3.0.0 |
|
3419 |
* |
|
18 | 3420 |
* @param int|null $blog_id Optional. Site ID. Default null (current site). |
3421 |
* @param string $path Optional. Path relative to the admin URL. Default empty. |
|
3422 |
* @param string $scheme Optional. The scheme to use. Accepts 'http' or 'https', |
|
3423 |
* to force those schemes. Default 'admin', which obeys |
|
3424 |
* force_ssl_admin() and is_ssl(). |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3425 |
* @return string Admin URL link with optional path appended. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3426 |
*/ |
0 | 3427 |
function get_admin_url( $blog_id = null, $path = '', $scheme = 'admin' ) { |
9 | 3428 |
$url = get_site_url( $blog_id, 'wp-admin/', $scheme ); |
3429 |
||
3430 |
if ( $path && is_string( $path ) ) { |
|
0 | 3431 |
$url .= ltrim( $path, '/' ); |
9 | 3432 |
} |
0 | 3433 |
|
5 | 3434 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3435 |
* Filters the admin area URL. |
5 | 3436 |
* |
3437 |
* @since 2.8.0 |
|
18 | 3438 |
* @since 5.8.0 The `$scheme` parameter was added. |
5 | 3439 |
* |
18 | 3440 |
* @param string $url The complete admin area URL including scheme and path. |
3441 |
* @param string $path Path relative to the admin area URL. Blank string if no path is specified. |
|
3442 |
* @param int|null $blog_id Site ID, or null for the current site. |
|
3443 |
* @param string|null $scheme The scheme to use. Accepts 'http', 'https', |
|
3444 |
* 'admin', or null. Default 'admin', which obeys force_ssl_admin() and is_ssl(). |
|
5 | 3445 |
*/ |
18 | 3446 |
return apply_filters( 'admin_url', $url, $path, $blog_id, $scheme ); |
0 | 3447 |
} |
3448 |
||
3449 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3450 |
* Retrieves the URL to the includes directory. |
0 | 3451 |
* |
3452 |
* @since 2.6.0 |
|
3453 |
* |
|
18 | 3454 |
* @param string $path Optional. Path relative to the includes URL. Default empty. |
3455 |
* @param string|null $scheme Optional. Scheme to give the includes URL context. Accepts |
|
3456 |
* 'http', 'https', or 'relative'. Default null. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3457 |
* @return string Includes URL link with optional path appended. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3458 |
*/ |
0 | 3459 |
function includes_url( $path = '', $scheme = null ) { |
3460 |
$url = site_url( '/' . WPINC . '/', $scheme ); |
|
3461 |
||
9 | 3462 |
if ( $path && is_string( $path ) ) { |
3463 |
$url .= ltrim( $path, '/' ); |
|
3464 |
} |
|
0 | 3465 |
|
5 | 3466 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3467 |
* Filters the URL to the includes directory. |
5 | 3468 |
* |
3469 |
* @since 2.8.0 |
|
18 | 3470 |
* @since 5.8.0 The `$scheme` parameter was added. |
5 | 3471 |
* |
18 | 3472 |
* @param string $url The complete URL to the includes directory including scheme and path. |
3473 |
* @param string $path Path relative to the URL to the wp-includes directory. Blank string |
|
3474 |
* if no path is specified. |
|
3475 |
* @param string|null $scheme Scheme to give the includes URL context. Accepts |
|
3476 |
* 'http', 'https', 'relative', or null. Default null. |
|
5 | 3477 |
*/ |
18 | 3478 |
return apply_filters( 'includes_url', $url, $path, $scheme ); |
0 | 3479 |
} |
3480 |
||
3481 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3482 |
* Retrieves the URL to the content directory. |
0 | 3483 |
* |
3484 |
* @since 2.6.0 |
|
3485 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3486 |
* @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
|
3487 |
* @return string Content URL link with optional path appended. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3488 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3489 |
function content_url( $path = '' ) { |
0 | 3490 |
$url = set_url_scheme( WP_CONTENT_URL ); |
3491 |
||
9 | 3492 |
if ( $path && is_string( $path ) ) { |
3493 |
$url .= '/' . ltrim( $path, '/' ); |
|
3494 |
} |
|
0 | 3495 |
|
5 | 3496 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3497 |
* Filters the URL to the content directory. |
5 | 3498 |
* |
3499 |
* @since 2.8.0 |
|
3500 |
* |
|
3501 |
* @param string $url The complete URL to the content directory including scheme and path. |
|
3502 |
* @param string $path Path relative to the URL to the content directory. Blank string |
|
3503 |
* if no path is specified. |
|
3504 |
*/ |
|
9 | 3505 |
return apply_filters( 'content_url', $url, $path ); |
0 | 3506 |
} |
3507 |
||
3508 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3509 |
* Retrieves a URL within the plugins or mu-plugins directory. |
0 | 3510 |
* |
5 | 3511 |
* Defaults to the plugins directory URL if no arguments are supplied. |
3512 |
* |
|
0 | 3513 |
* @since 2.6.0 |
3514 |
* |
|
16 | 3515 |
* @param string $path Optional. Extra path appended to the end of the URL, including |
3516 |
* the relative directory if $plugin is supplied. Default empty. |
|
3517 |
* @param string $plugin Optional. A full path to a file inside a plugin or mu-plugin. |
|
3518 |
* The URL will be relative to its directory. Default empty. |
|
3519 |
* Typically this is done by passing `__FILE__` as the argument. |
|
5 | 3520 |
* @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
|
3521 |
*/ |
5 | 3522 |
function plugins_url( $path = '', $plugin = '' ) { |
3523 |
||
9 | 3524 |
$path = wp_normalize_path( $path ); |
3525 |
$plugin = wp_normalize_path( $plugin ); |
|
5 | 3526 |
$mu_plugin_dir = wp_normalize_path( WPMU_PLUGIN_DIR ); |
0 | 3527 |
|
9 | 3528 |
if ( ! empty( $plugin ) && 0 === strpos( $plugin, $mu_plugin_dir ) ) { |
0 | 3529 |
$url = WPMU_PLUGIN_URL; |
9 | 3530 |
} else { |
0 | 3531 |
$url = WP_PLUGIN_URL; |
9 | 3532 |
} |
0 | 3533 |
|
3534 |
$url = set_url_scheme( $url ); |
|
3535 |
||
9 | 3536 |
if ( ! empty( $plugin ) && is_string( $plugin ) ) { |
3537 |
$folder = dirname( plugin_basename( $plugin ) ); |
|
16 | 3538 |
if ( '.' !== $folder ) { |
9 | 3539 |
$url .= '/' . ltrim( $folder, '/' ); |
3540 |
} |
|
0 | 3541 |
} |
3542 |
||
9 | 3543 |
if ( $path && is_string( $path ) ) { |
3544 |
$url .= '/' . ltrim( $path, '/' ); |
|
3545 |
} |
|
0 | 3546 |
|
5 | 3547 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3548 |
* Filters the URL to the plugins directory. |
5 | 3549 |
* |
3550 |
* @since 2.8.0 |
|
3551 |
* |
|
3552 |
* @param string $url The complete URL to the plugins directory including scheme and path. |
|
3553 |
* @param string $path Path relative to the URL to the plugins directory. Blank string |
|
3554 |
* if no path is specified. |
|
3555 |
* @param string $plugin The plugin file path to be relative to. Blank string if no plugin |
|
3556 |
* is specified. |
|
3557 |
*/ |
|
3558 |
return apply_filters( 'plugins_url', $url, $path, $plugin ); |
|
0 | 3559 |
} |
3560 |
||
3561 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3562 |
* Retrieves the site URL for the current network. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3563 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3564 |
* Returns the site URL with the appropriate protocol, 'https' if |
0 | 3565 |
* is_ssl() and 'http' otherwise. If $scheme is 'http' or 'https', is_ssl() is |
3566 |
* overridden. |
|
3567 |
* |
|
3568 |
* @since 3.0.0 |
|
3569 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3570 |
* @see set_url_scheme() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3571 |
* |
18 | 3572 |
* @param string $path Optional. Path relative to the site URL. Default empty. |
3573 |
* @param string|null $scheme Optional. Scheme to give the site URL context. Accepts |
|
3574 |
* 'http', 'https', or 'relative'. Default null. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3575 |
* @return string Site URL link with optional path appended. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3576 |
*/ |
0 | 3577 |
function network_site_url( $path = '', $scheme = null ) { |
9 | 3578 |
if ( ! is_multisite() ) { |
3579 |
return site_url( $path, $scheme ); |
|
3580 |
} |
|
0 | 3581 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3582 |
$current_network = get_network(); |
5 | 3583 |
|
16 | 3584 |
if ( 'relative' === $scheme ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3585 |
$url = $current_network->path; |
9 | 3586 |
} else { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3587 |
$url = set_url_scheme( 'http://' . $current_network->domain . $current_network->path, $scheme ); |
9 | 3588 |
} |
3589 |
||
3590 |
if ( $path && is_string( $path ) ) { |
|
0 | 3591 |
$url .= ltrim( $path, '/' ); |
9 | 3592 |
} |
0 | 3593 |
|
5 | 3594 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3595 |
* Filters the network site URL. |
5 | 3596 |
* |
3597 |
* @since 3.0.0 |
|
3598 |
* |
|
3599 |
* @param string $url The complete network site URL including scheme and path. |
|
3600 |
* @param string $path Path relative to the network site URL. Blank string if |
|
3601 |
* no path is specified. |
|
3602 |
* @param string|null $scheme Scheme to give the URL context. Accepts 'http', 'https', |
|
3603 |
* 'relative' or null. |
|
3604 |
*/ |
|
0 | 3605 |
return apply_filters( 'network_site_url', $url, $path, $scheme ); |
3606 |
} |
|
3607 |
||
3608 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3609 |
* Retrieves the home URL for the current network. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3610 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3611 |
* Returns the home URL with the appropriate protocol, 'https' is_ssl() |
5 | 3612 |
* and 'http' otherwise. If `$scheme` is 'http' or 'https', `is_ssl()` is |
0 | 3613 |
* overridden. |
3614 |
* |
|
3615 |
* @since 3.0.0 |
|
3616 |
* |
|
18 | 3617 |
* @param string $path Optional. Path relative to the home URL. Default empty. |
3618 |
* @param string|null $scheme Optional. Scheme to give the home URL context. Accepts |
|
3619 |
* 'http', 'https', or 'relative'. Default null. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3620 |
* @return string Home URL link with optional path appended. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3621 |
*/ |
0 | 3622 |
function network_home_url( $path = '', $scheme = null ) { |
9 | 3623 |
if ( ! is_multisite() ) { |
3624 |
return home_url( $path, $scheme ); |
|
3625 |
} |
|
0 | 3626 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3627 |
$current_network = get_network(); |
9 | 3628 |
$orig_scheme = $scheme; |
3629 |
||
16 | 3630 |
if ( ! in_array( $scheme, array( 'http', 'https', 'relative' ), true ) ) { |
18 | 3631 |
$scheme = is_ssl() ? 'https' : 'http'; |
9 | 3632 |
} |
3633 |
||
16 | 3634 |
if ( 'relative' === $scheme ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3635 |
$url = $current_network->path; |
9 | 3636 |
} else { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3637 |
$url = set_url_scheme( 'http://' . $current_network->domain . $current_network->path, $scheme ); |
9 | 3638 |
} |
3639 |
||
3640 |
if ( $path && is_string( $path ) ) { |
|
0 | 3641 |
$url .= ltrim( $path, '/' ); |
9 | 3642 |
} |
0 | 3643 |
|
5 | 3644 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3645 |
* Filters the network home URL. |
5 | 3646 |
* |
3647 |
* @since 3.0.0 |
|
3648 |
* |
|
3649 |
* @param string $url The complete network home URL including scheme and path. |
|
3650 |
* @param string $path Path relative to the network home URL. Blank string |
|
3651 |
* if no path is specified. |
|
3652 |
* @param string|null $orig_scheme Scheme to give the URL context. Accepts 'http', 'https', |
|
3653 |
* 'relative' or null. |
|
3654 |
*/ |
|
9 | 3655 |
return apply_filters( 'network_home_url', $url, $path, $orig_scheme ); |
0 | 3656 |
} |
3657 |
||
3658 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3659 |
* Retrieves the URL to the admin area for the network. |
0 | 3660 |
* |
3661 |
* @since 3.0.0 |
|
3662 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3663 |
* @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
|
3664 |
* @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
|
3665 |
* 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
|
3666 |
* @return string Admin URL link with optional path appended. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3667 |
*/ |
0 | 3668 |
function network_admin_url( $path = '', $scheme = 'admin' ) { |
9 | 3669 |
if ( ! is_multisite() ) { |
0 | 3670 |
return admin_url( $path, $scheme ); |
9 | 3671 |
} |
3672 |
||
3673 |
$url = network_site_url( 'wp-admin/network/', $scheme ); |
|
3674 |
||
3675 |
if ( $path && is_string( $path ) ) { |
|
3676 |
$url .= ltrim( $path, '/' ); |
|
3677 |
} |
|
0 | 3678 |
|
5 | 3679 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3680 |
* Filters the network admin URL. |
5 | 3681 |
* |
3682 |
* @since 3.0.0 |
|
18 | 3683 |
* @since 5.8.0 The `$scheme` parameter was added. |
5 | 3684 |
* |
18 | 3685 |
* @param string $url The complete network admin URL including scheme and path. |
3686 |
* @param string $path Path relative to the network admin URL. Blank string if |
|
3687 |
* no path is specified. |
|
3688 |
* @param string|null $scheme The scheme to use. Accepts 'http', 'https', |
|
3689 |
* 'admin', or null. Default is 'admin', which obeys force_ssl_admin() and is_ssl(). |
|
5 | 3690 |
*/ |
18 | 3691 |
return apply_filters( 'network_admin_url', $url, $path, $scheme ); |
0 | 3692 |
} |
3693 |
||
3694 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3695 |
* Retrieves the URL to the admin area for the current user. |
0 | 3696 |
* |
3697 |
* @since 3.0.0 |
|
3698 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3699 |
* @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
|
3700 |
* @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
|
3701 |
* 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
|
3702 |
* @return string Admin URL link with optional path appended. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3703 |
*/ |
0 | 3704 |
function user_admin_url( $path = '', $scheme = 'admin' ) { |
9 | 3705 |
$url = network_site_url( 'wp-admin/user/', $scheme ); |
3706 |
||
3707 |
if ( $path && is_string( $path ) ) { |
|
3708 |
$url .= ltrim( $path, '/' ); |
|
3709 |
} |
|
0 | 3710 |
|
5 | 3711 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3712 |
* Filters the user admin URL for the current user. |
5 | 3713 |
* |
3714 |
* @since 3.1.0 |
|
18 | 3715 |
* @since 5.8.0 The `$scheme` parameter was added. |
5 | 3716 |
* |
18 | 3717 |
* @param string $url The complete URL including scheme and path. |
3718 |
* @param string $path Path relative to the URL. Blank string if |
|
3719 |
* no path is specified. |
|
3720 |
* @param string|null $scheme The scheme to use. Accepts 'http', 'https', |
|
3721 |
* 'admin', or null. Default is 'admin', which obeys force_ssl_admin() and is_ssl(). |
|
5 | 3722 |
*/ |
18 | 3723 |
return apply_filters( 'user_admin_url', $url, $path, $scheme ); |
0 | 3724 |
} |
3725 |
||
3726 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3727 |
* Retrieves the URL to the admin area for either the current site or the network depending on context. |
0 | 3728 |
* |
3729 |
* @since 3.1.0 |
|
3730 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3731 |
* @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
|
3732 |
* @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
|
3733 |
* 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
|
3734 |
* @return string Admin URL link with optional path appended. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3735 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3736 |
function self_admin_url( $path = '', $scheme = 'admin' ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3737 |
if ( is_network_admin() ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3738 |
$url = network_admin_url( $path, $scheme ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3739 |
} elseif ( is_user_admin() ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3740 |
$url = user_admin_url( $path, $scheme ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3741 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3742 |
$url = admin_url( $path, $scheme ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3743 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3744 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3745 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3746 |
* 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
|
3747 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3748 |
* @since 4.9.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3749 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3750 |
* @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
|
3751 |
* @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
|
3752 |
* @param string $scheme The scheme to use. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3753 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3754 |
return apply_filters( 'self_admin_url', $url, $path, $scheme ); |
0 | 3755 |
} |
3756 |
||
3757 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3758 |
* Sets the scheme for a URL. |
0 | 3759 |
* |
3760 |
* @since 3.4.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3761 |
* @since 4.4.0 The 'rest' scheme was added. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3762 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3763 |
* @param string $url Absolute URL that includes a scheme |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3764 |
* @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
|
3765 |
* 'login_post', 'admin', 'relative', 'rest', 'rpc', or null. Default null. |
16 | 3766 |
* @return string URL with chosen scheme. |
0 | 3767 |
*/ |
3768 |
function set_url_scheme( $url, $scheme = null ) { |
|
3769 |
$orig_scheme = $scheme; |
|
5 | 3770 |
|
3771 |
if ( ! $scheme ) { |
|
3772 |
$scheme = is_ssl() ? 'https' : 'http'; |
|
16 | 3773 |
} elseif ( 'admin' === $scheme || 'login' === $scheme || 'login_post' === $scheme || 'rpc' === $scheme ) { |
5 | 3774 |
$scheme = is_ssl() || force_ssl_admin() ? 'https' : 'http'; |
16 | 3775 |
} elseif ( 'http' !== $scheme && 'https' !== $scheme && 'relative' !== $scheme ) { |
5 | 3776 |
$scheme = is_ssl() ? 'https' : 'http'; |
0 | 3777 |
} |
3778 |
||
3779 |
$url = trim( $url ); |
|
9 | 3780 |
if ( substr( $url, 0, 2 ) === '//' ) { |
0 | 3781 |
$url = 'http:' . $url; |
9 | 3782 |
} |
0 | 3783 |
|
16 | 3784 |
if ( 'relative' === $scheme ) { |
0 | 3785 |
$url = ltrim( preg_replace( '#^\w+://[^/]*#', '', $url ) ); |
16 | 3786 |
if ( '' !== $url && '/' === $url[0] ) { |
9 | 3787 |
$url = '/' . ltrim( $url, "/ \t\n\r\0\x0B" ); |
3788 |
} |
|
0 | 3789 |
} else { |
3790 |
$url = preg_replace( '#^\w+://#', $scheme . '://', $url ); |
|
3791 |
} |
|
3792 |
||
5 | 3793 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3794 |
* Filters the resulting URL after setting the scheme. |
5 | 3795 |
* |
3796 |
* @since 3.4.0 |
|
3797 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3798 |
* @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
|
3799 |
* @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
|
3800 |
* @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
|
3801 |
* 'login_post', 'admin', 'relative', 'rest', 'rpc', or null. |
5 | 3802 |
*/ |
0 | 3803 |
return apply_filters( 'set_url_scheme', $url, $scheme, $orig_scheme ); |
3804 |
} |
|
3805 |
||
3806 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3807 |
* Retrieves the URL to the user's dashboard. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3808 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3809 |
* 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
|
3810 |
* 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
|
3811 |
* cannot edit the current site, the dashboard to the user's primary site is returned. |
0 | 3812 |
* |
3813 |
* @since 3.1.0 |
|
3814 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3815 |
* @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
|
3816 |
* @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
|
3817 |
* both site and user admins. Default empty. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3818 |
* @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
|
3819 |
* 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
|
3820 |
* @return string Dashboard URL link with optional path appended. |
0 | 3821 |
*/ |
5 | 3822 |
function get_dashboard_url( $user_id = 0, $path = '', $scheme = 'admin' ) { |
3823 |
$user_id = $user_id ? (int) $user_id : get_current_user_id(); |
|
0 | 3824 |
|
3825 |
$blogs = get_blogs_of_user( $user_id ); |
|
16 | 3826 |
|
9 | 3827 |
if ( is_multisite() && ! user_can( $user_id, 'manage_network' ) && empty( $blogs ) ) { |
0 | 3828 |
$url = user_admin_url( $path, $scheme ); |
3829 |
} elseif ( ! is_multisite() ) { |
|
3830 |
$url = admin_url( $path, $scheme ); |
|
3831 |
} else { |
|
3832 |
$current_blog = get_current_blog_id(); |
|
16 | 3833 |
|
3834 |
if ( $current_blog && ( user_can( $user_id, 'manage_network' ) || in_array( $current_blog, array_keys( $blogs ), true ) ) ) { |
|
0 | 3835 |
$url = admin_url( $path, $scheme ); |
3836 |
} else { |
|
3837 |
$active = get_active_blog_for_user( $user_id ); |
|
9 | 3838 |
if ( $active ) { |
0 | 3839 |
$url = get_admin_url( $active->blog_id, $path, $scheme ); |
9 | 3840 |
} else { |
0 | 3841 |
$url = user_admin_url( $path, $scheme ); |
9 | 3842 |
} |
0 | 3843 |
} |
3844 |
} |
|
3845 |
||
5 | 3846 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3847 |
* Filters the dashboard URL for a user. |
5 | 3848 |
* |
3849 |
* @since 3.1.0 |
|
3850 |
* |
|
3851 |
* @param string $url The complete URL including scheme and path. |
|
3852 |
* @param int $user_id The user ID. |
|
3853 |
* @param string $path Path relative to the URL. Blank string if no path is specified. |
|
3854 |
* @param string $scheme Scheme to give the URL context. Accepts 'http', 'https', 'login', |
|
3855 |
* 'login_post', 'admin', 'relative' or null. |
|
3856 |
*/ |
|
9 | 3857 |
return apply_filters( 'user_dashboard_url', $url, $user_id, $path, $scheme ); |
0 | 3858 |
} |
3859 |
||
3860 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3861 |
* Retrieves the URL to the user's profile editor. |
0 | 3862 |
* |
3863 |
* @since 3.1.0 |
|
3864 |
* |
|
5 | 3865 |
* @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
|
3866 |
* @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
|
3867 |
* 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
|
3868 |
* @return string Dashboard URL link with optional path appended. |
0 | 3869 |
*/ |
5 | 3870 |
function get_edit_profile_url( $user_id = 0, $scheme = 'admin' ) { |
3871 |
$user_id = $user_id ? (int) $user_id : get_current_user_id(); |
|
0 | 3872 |
|
9 | 3873 |
if ( is_user_admin() ) { |
0 | 3874 |
$url = user_admin_url( 'profile.php', $scheme ); |
9 | 3875 |
} elseif ( is_network_admin() ) { |
0 | 3876 |
$url = network_admin_url( 'profile.php', $scheme ); |
9 | 3877 |
} else { |
5 | 3878 |
$url = get_dashboard_url( $user_id, 'profile.php', $scheme ); |
9 | 3879 |
} |
5 | 3880 |
|
3881 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3882 |
* Filters the URL for a user's profile editor. |
5 | 3883 |
* |
3884 |
* @since 3.1.0 |
|
3885 |
* |
|
3886 |
* @param string $url The complete URL including scheme and path. |
|
3887 |
* @param int $user_id The user ID. |
|
3888 |
* @param string $scheme Scheme to give the URL context. Accepts 'http', 'https', 'login', |
|
3889 |
* 'login_post', 'admin', 'relative' or null. |
|
3890 |
*/ |
|
9 | 3891 |
return apply_filters( 'edit_profile_url', $url, $user_id, $scheme ); |
0 | 3892 |
} |
3893 |
||
3894 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3895 |
* Returns the canonical URL for a post. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3896 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3897 |
* 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
|
3898 |
* pagination arguments too. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3899 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3900 |
* @since 4.6.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3901 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3902 |
* @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
|
3903 |
* @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
|
3904 |
* been published yet. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3905 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3906 |
function wp_get_canonical_url( $post = null ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3907 |
$post = get_post( $post ); |
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 |
if ( ! $post ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3910 |
return false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3911 |
} |
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 |
if ( 'publish' !== $post->post_status ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3914 |
return false; |
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 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3917 |
$canonical_url = get_permalink( $post ); |
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 |
// If a canonical is being generated for the current page, make sure it has pagination if needed. |
16 | 3920 |
if ( get_queried_object_id() === $post->ID ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3921 |
$page = get_query_var( 'page', 0 ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3922 |
if ( $page >= 2 ) { |
16 | 3923 |
if ( ! get_option( 'permalink_structure' ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3924 |
$canonical_url = add_query_arg( 'page', $page, $canonical_url ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3925 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3926 |
$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
|
3927 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3928 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3929 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3930 |
$cpage = get_query_var( 'cpage', 0 ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3931 |
if ( $cpage ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3932 |
$canonical_url = get_comments_pagenum_link( $cpage ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3933 |
} |
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 |
* Filters the canonical URL for a post. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3938 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3939 |
* @since 4.6.0 |
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 |
* @param string $canonical_url The post's canonical URL. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3942 |
* @param WP_Post $post Post object. |
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 |
return apply_filters( 'get_canonical_url', $canonical_url, $post ); |
0 | 3945 |
} |
3946 |
||
3947 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3948 |
* Outputs rel=canonical for singular queries. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3949 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3950 |
* @since 2.9.0 |
9 | 3951 |
* @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
|
3952 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3953 |
function rel_canonical() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3954 |
if ( ! is_singular() ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3955 |
return; |
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 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3958 |
$id = get_queried_object_id(); |
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 |
if ( 0 === $id ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3961 |
return; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3962 |
} |
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 |
$url = wp_get_canonical_url( $id ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3965 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3966 |
if ( ! empty( $url ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3967 |
echo '<link rel="canonical" href="' . esc_url( $url ) . '" />' . "\n"; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3968 |
} |
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 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3972 |
* 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
|
3973 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3974 |
* 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
|
3975 |
* 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
|
3976 |
* 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
|
3977 |
* 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
|
3978 |
* filter. |
0 | 3979 |
* |
9 | 3980 |
* @since 3.0.0 |
0 | 3981 |
* |
16 | 3982 |
* @param int $id Optional. A post or site ID. Default is 0, which means the current post or site. |
3983 |
* @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
|
3984 |
* the post_type of the post is consulted. If 'query', the current query is consulted |
16 | 3985 |
* to determine the ID and context. Default 'post'. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3986 |
* @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
|
3987 |
* and whether to honor this. Default true. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3988 |
* @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
|
3989 |
* are not enabled. |
0 | 3990 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3991 |
function wp_get_shortlink( $id = 0, $context = 'post', $allow_slugs = true ) { |
5 | 3992 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3993 |
* Filters whether to preempt generating a shortlink for the given post. |
5 | 3994 |
* |
16 | 3995 |
* Returning a truthy value from the filter will effectively short-circuit |
3996 |
* the shortlink generation process, returning that value instead. |
|
5 | 3997 |
* |
3998 |
* @since 3.0.0 |
|
3999 |
* |
|
16 | 4000 |
* @param false|string $return Short-circuit return value. Either false or a URL string. |
4001 |
* @param int $id Post ID, or 0 for the current post. |
|
4002 |
* @param string $context The context for the link. One of 'post' or 'query', |
|
4003 |
* @param bool $allow_slugs Whether to allow post slugs in the shortlink. |
|
5 | 4004 |
*/ |
4005 |
$shortlink = apply_filters( 'pre_get_shortlink', false, $id, $context, $allow_slugs ); |
|
4006 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4007 |
if ( false !== $shortlink ) { |
0 | 4008 |
return $shortlink; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4009 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4010 |
|
0 | 4011 |
$post_id = 0; |
16 | 4012 |
if ( 'query' === $context && is_singular() ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4013 |
$post_id = get_queried_object_id(); |
9 | 4014 |
$post = get_post( $post_id ); |
16 | 4015 |
} elseif ( 'post' === $context ) { |
0 | 4016 |
$post = get_post( $id ); |
9 | 4017 |
if ( ! empty( $post->ID ) ) { |
0 | 4018 |
$post_id = $post->ID; |
9 | 4019 |
} |
0 | 4020 |
} |
4021 |
||
4022 |
$shortlink = ''; |
|
4023 |
||
16 | 4024 |
// Return `?p=` link for all public post types. |
0 | 4025 |
if ( ! empty( $post_id ) ) { |
4026 |
$post_type = get_post_type_object( $post->post_type ); |
|
5 | 4027 |
|
16 | 4028 |
if ( 'page' === $post->post_type && get_option( 'page_on_front' ) == $post->ID && 'page' === get_option( 'show_on_front' ) ) { |
5 | 4029 |
$shortlink = home_url( '/' ); |
18 | 4030 |
} elseif ( $post_type && $post_type->public ) { |
5 | 4031 |
$shortlink = home_url( '?p=' . $post_id ); |
4032 |
} |
|
0 | 4033 |
} |
4034 |
||
5 | 4035 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4036 |
* Filters the shortlink for a post. |
5 | 4037 |
* |
4038 |
* @since 3.0.0 |
|
4039 |
* |
|
4040 |
* @param string $shortlink Shortlink URL. |
|
4041 |
* @param int $id Post ID, or 0 for the current post. |
|
4042 |
* @param string $context The context for the link. One of 'post' or 'query', |
|
4043 |
* @param bool $allow_slugs Whether to allow post slugs in the shortlink. Not used by default. |
|
4044 |
*/ |
|
4045 |
return apply_filters( 'get_shortlink', $shortlink, $id, $context, $allow_slugs ); |
|
0 | 4046 |
} |
4047 |
||
4048 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4049 |
* 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
|
4050 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4051 |
* Attached to the {@see 'wp_head'} action. |
0 | 4052 |
* |
4053 |
* @since 3.0.0 |
|
4054 |
*/ |
|
4055 |
function wp_shortlink_wp_head() { |
|
4056 |
$shortlink = wp_get_shortlink( 0, 'query' ); |
|
4057 |
||
9 | 4058 |
if ( empty( $shortlink ) ) { |
0 | 4059 |
return; |
9 | 4060 |
} |
0 | 4061 |
|
4062 |
echo "<link rel='shortlink' href='" . esc_url( $shortlink ) . "' />\n"; |
|
4063 |
} |
|
4064 |
||
4065 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4066 |
* 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
|
4067 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4068 |
* Attached to the {@see 'wp'} action. |
0 | 4069 |
* |
4070 |
* @since 3.0.0 |
|
4071 |
*/ |
|
4072 |
function wp_shortlink_header() { |
|
9 | 4073 |
if ( headers_sent() ) { |
0 | 4074 |
return; |
9 | 4075 |
} |
4076 |
||
4077 |
$shortlink = wp_get_shortlink( 0, 'query' ); |
|
4078 |
||
4079 |
if ( empty( $shortlink ) ) { |
|
0 | 4080 |
return; |
9 | 4081 |
} |
4082 |
||
4083 |
header( 'Link: <' . $shortlink . '>; rel=shortlink', false ); |
|
0 | 4084 |
} |
4085 |
||
4086 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4087 |
* Displays the shortlink for a post. |
0 | 4088 |
* |
4089 |
* Must be called from inside "The Loop" |
|
4090 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4091 |
* Call like the_shortlink( __( 'Shortlinkage FTW' ) ) |
0 | 4092 |
* |
4093 |
* @since 3.0.0 |
|
4094 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4095 |
* @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
|
4096 |
* @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
|
4097 |
* @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
|
4098 |
* @param string $after Optional HTML to display after the link. Default empty. |
0 | 4099 |
*/ |
4100 |
function the_shortlink( $text = '', $title = '', $before = '', $after = '' ) { |
|
4101 |
$post = get_post(); |
|
4102 |
||
9 | 4103 |
if ( empty( $text ) ) { |
4104 |
$text = __( 'This is the short link.' ); |
|
4105 |
} |
|
4106 |
||
4107 |
if ( empty( $title ) ) { |
|
0 | 4108 |
$title = the_title_attribute( array( 'echo' => false ) ); |
9 | 4109 |
} |
0 | 4110 |
|
4111 |
$shortlink = wp_get_shortlink( $post->ID ); |
|
4112 |
||
9 | 4113 |
if ( ! empty( $shortlink ) ) { |
0 | 4114 |
$link = '<a rel="shortlink" href="' . esc_url( $shortlink ) . '" title="' . $title . '">' . $text . '</a>'; |
5 | 4115 |
|
4116 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4117 |
* Filters the short link anchor tag for a post. |
5 | 4118 |
* |
4119 |
* @since 3.0.0 |
|
4120 |
* |
|
4121 |
* @param string $link Shortlink anchor tag. |
|
4122 |
* @param string $shortlink Shortlink URL. |
|
4123 |
* @param string $text Shortlink's text. |
|
4124 |
* @param string $title Shortlink's title attribute. |
|
4125 |
*/ |
|
0 | 4126 |
$link = apply_filters( 'the_shortlink', $link, $shortlink, $text, $title ); |
4127 |
echo $before, $link, $after; |
|
4128 |
} |
|
4129 |
} |
|
5 | 4130 |
|
4131 |
||
4132 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4133 |
* Retrieves the avatar URL. |
5 | 4134 |
* |
4135 |
* @since 4.2.0 |
|
4136 |
* |
|
4137 |
* @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
|
4138 |
* user email, WP_User object, WP_Post object, or WP_Comment object. |
5 | 4139 |
* @param array $args { |
4140 |
* Optional. Arguments to return instead of the default arguments. |
|
4141 |
* |
|
4142 |
* @type int $size Height and width of the avatar in pixels. Default 96. |
|
4143 |
* @type string $default URL for the default image or a default type. Accepts '404' (return |
|
4144 |
* a 404 instead of a default image), 'retro' (8bit), 'monsterid' (monster), |
|
4145 |
* 'wavatar' (cartoon face), 'indenticon' (the "quilt"), 'mystery', 'mm', |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4146 |
* or 'mysteryman' (The Oyster Man), 'blank' (transparent GIF), or |
5 | 4147 |
* 'gravatar_default' (the Gravatar logo). Default is the value of the |
4148 |
* 'avatar_default' option, with a fallback of 'mystery'. |
|
4149 |
* @type bool $force_default Whether to always show the default image, never the Gravatar. Default false. |
|
4150 |
* @type string $rating What rating to display avatars up to. Accepts 'G', 'PG', 'R', 'X', and are |
|
4151 |
* judged in that order. Default is the value of the 'avatar_rating' option. |
|
4152 |
* @type string $scheme URL scheme to use. See set_url_scheme() for accepted values. |
|
4153 |
* Default null. |
|
4154 |
* @type array $processed_args When the function returns, the value will be the processed/sanitized $args |
|
4155 |
* plus a "found_avatar" guess. Pass as a reference. Default null. |
|
4156 |
* } |
|
16 | 4157 |
* @return string|false The URL of the avatar on success, false on failure. |
5 | 4158 |
*/ |
4159 |
function get_avatar_url( $id_or_email, $args = null ) { |
|
4160 |
$args = get_avatar_data( $id_or_email, $args ); |
|
4161 |
return $args['url']; |
|
4162 |
} |
|
4163 |
||
9 | 4164 |
|
4165 |
/** |
|
4166 |
* Check if this comment type allows avatars to be retrieved. |
|
4167 |
* |
|
4168 |
* @since 5.1.0 |
|
4169 |
* |
|
4170 |
* @param string $comment_type Comment type to check. |
|
4171 |
* @return bool Whether the comment type is allowed for retrieving avatars. |
|
4172 |
*/ |
|
4173 |
function is_avatar_comment_type( $comment_type ) { |
|
4174 |
/** |
|
4175 |
* Filters the list of allowed comment types for retrieving avatars. |
|
4176 |
* |
|
4177 |
* @since 3.0.0 |
|
4178 |
* |
|
4179 |
* @param array $types An array of content types. Default only contains 'comment'. |
|
4180 |
*/ |
|
4181 |
$allowed_comment_types = apply_filters( 'get_avatar_comment_types', array( 'comment' ) ); |
|
4182 |
||
4183 |
return in_array( $comment_type, (array) $allowed_comment_types, true ); |
|
4184 |
} |
|
4185 |
||
4186 |
||
5 | 4187 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4188 |
* Retrieves default data about the avatar. |
5 | 4189 |
* |
4190 |
* @since 4.2.0 |
|
4191 |
* |
|
16 | 4192 |
* @param mixed $id_or_email The Gravatar to retrieve. Accepts a user ID, Gravatar MD5 hash, |
4193 |
* user email, WP_User object, WP_Post object, or WP_Comment object. |
|
5 | 4194 |
* @param array $args { |
4195 |
* Optional. Arguments to return instead of the default arguments. |
|
4196 |
* |
|
4197 |
* @type int $size Height and width of the avatar image file in pixels. Default 96. |
|
4198 |
* @type int $height Display height of the avatar in pixels. Defaults to $size. |
|
4199 |
* @type int $width Display width of the avatar in pixels. Defaults to $size. |
|
4200 |
* @type string $default URL for the default image or a default type. Accepts '404' (return |
|
4201 |
* a 404 instead of a default image), 'retro' (8bit), 'monsterid' (monster), |
|
4202 |
* 'wavatar' (cartoon face), 'indenticon' (the "quilt"), 'mystery', 'mm', |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4203 |
* or 'mysteryman' (The Oyster Man), 'blank' (transparent GIF), or |
5 | 4204 |
* 'gravatar_default' (the Gravatar logo). Default is the value of the |
4205 |
* 'avatar_default' option, with a fallback of 'mystery'. |
|
4206 |
* @type bool $force_default Whether to always show the default image, never the Gravatar. Default false. |
|
4207 |
* @type string $rating What rating to display avatars up to. Accepts 'G', 'PG', 'R', 'X', and are |
|
4208 |
* judged in that order. Default is the value of the 'avatar_rating' option. |
|
4209 |
* @type string $scheme URL scheme to use. See set_url_scheme() for accepted values. |
|
4210 |
* Default null. |
|
4211 |
* @type array $processed_args When the function returns, the value will be the processed/sanitized $args |
|
4212 |
* plus a "found_avatar" guess. Pass as a reference. Default null. |
|
4213 |
* @type string $extra_attr HTML attributes to insert in the IMG element. Is not sanitized. Default empty. |
|
4214 |
* } |
|
16 | 4215 |
* @return array { |
5 | 4216 |
* Along with the arguments passed in `$args`, this will contain a couple of extra arguments. |
4217 |
* |
|
4218 |
* @type bool $found_avatar True if we were able to find an avatar for this user, |
|
4219 |
* false or not set if we couldn't. |
|
4220 |
* @type string $url The URL of the avatar we found. |
|
4221 |
* } |
|
4222 |
*/ |
|
4223 |
function get_avatar_data( $id_or_email, $args = null ) { |
|
9 | 4224 |
$args = wp_parse_args( |
4225 |
$args, |
|
4226 |
array( |
|
4227 |
'size' => 96, |
|
4228 |
'height' => null, |
|
4229 |
'width' => null, |
|
4230 |
'default' => get_option( 'avatar_default', 'mystery' ), |
|
4231 |
'force_default' => false, |
|
4232 |
'rating' => get_option( 'avatar_rating' ), |
|
4233 |
'scheme' => null, |
|
16 | 4234 |
'processed_args' => null, // If used, should be a reference. |
9 | 4235 |
'extra_attr' => '', |
4236 |
) |
|
4237 |
); |
|
5 | 4238 |
|
4239 |
if ( is_numeric( $args['size'] ) ) { |
|
4240 |
$args['size'] = absint( $args['size'] ); |
|
4241 |
if ( ! $args['size'] ) { |
|
4242 |
$args['size'] = 96; |
|
4243 |
} |
|
4244 |
} else { |
|
4245 |
$args['size'] = 96; |
|
4246 |
} |
|
4247 |
||
4248 |
if ( is_numeric( $args['height'] ) ) { |
|
4249 |
$args['height'] = absint( $args['height'] ); |
|
4250 |
if ( ! $args['height'] ) { |
|
4251 |
$args['height'] = $args['size']; |
|
4252 |
} |
|
4253 |
} else { |
|
4254 |
$args['height'] = $args['size']; |
|
4255 |
} |
|
4256 |
||
4257 |
if ( is_numeric( $args['width'] ) ) { |
|
4258 |
$args['width'] = absint( $args['width'] ); |
|
4259 |
if ( ! $args['width'] ) { |
|
4260 |
$args['width'] = $args['size']; |
|
4261 |
} |
|
4262 |
} else { |
|
4263 |
$args['width'] = $args['size']; |
|
4264 |
} |
|
4265 |
||
4266 |
if ( empty( $args['default'] ) ) { |
|
4267 |
$args['default'] = get_option( 'avatar_default', 'mystery' ); |
|
4268 |
} |
|
4269 |
||
4270 |
switch ( $args['default'] ) { |
|
9 | 4271 |
case 'mm': |
4272 |
case 'mystery': |
|
4273 |
case 'mysteryman': |
|
5 | 4274 |
$args['default'] = 'mm'; |
4275 |
break; |
|
9 | 4276 |
case 'gravatar_default': |
5 | 4277 |
$args['default'] = false; |
4278 |
break; |
|
4279 |
} |
|
4280 |
||
4281 |
$args['force_default'] = (bool) $args['force_default']; |
|
4282 |
||
4283 |
$args['rating'] = strtolower( $args['rating'] ); |
|
4284 |
||
4285 |
$args['found_avatar'] = false; |
|
4286 |
||
4287 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4288 |
* Filters whether to retrieve the avatar URL early. |
5 | 4289 |
* |
4290 |
* Passing a non-null value in the 'url' member of the return array will |
|
4291 |
* effectively short circuit get_avatar_data(), passing the value through |
|
4292 |
* the {@see 'get_avatar_data'} filter and returning early. |
|
4293 |
* |
|
4294 |
* @since 4.2.0 |
|
4295 |
* |
|
16 | 4296 |
* @param array $args Arguments passed to get_avatar_data(), after processing. |
4297 |
* @param mixed $id_or_email The Gravatar to retrieve. Accepts a user ID, Gravatar MD5 hash, |
|
4298 |
* user email, WP_User object, WP_Post object, or WP_Comment object. |
|
5 | 4299 |
*/ |
4300 |
$args = apply_filters( 'pre_get_avatar_data', $args, $id_or_email ); |
|
4301 |
||
9 | 4302 |
if ( isset( $args['url'] ) ) { |
5 | 4303 |
/** This filter is documented in wp-includes/link-template.php */ |
4304 |
return apply_filters( 'get_avatar_data', $args, $id_or_email ); |
|
4305 |
} |
|
4306 |
||
4307 |
$email_hash = ''; |
|
16 | 4308 |
$user = false; |
4309 |
$email = false; |
|
5 | 4310 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4311 |
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
|
4312 |
$id_or_email = get_comment( $id_or_email ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4313 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4314 |
|
5 | 4315 |
// Process the user identifier. |
4316 |
if ( is_numeric( $id_or_email ) ) { |
|
4317 |
$user = get_user_by( 'id', absint( $id_or_email ) ); |
|
4318 |
} elseif ( is_string( $id_or_email ) ) { |
|
4319 |
if ( strpos( $id_or_email, '@md5.gravatar.com' ) ) { |
|
16 | 4320 |
// MD5 hash. |
5 | 4321 |
list( $email_hash ) = explode( '@', $id_or_email ); |
4322 |
} else { |
|
16 | 4323 |
// Email address. |
5 | 4324 |
$email = $id_or_email; |
4325 |
} |
|
4326 |
} elseif ( $id_or_email instanceof WP_User ) { |
|
16 | 4327 |
// User object. |
5 | 4328 |
$user = $id_or_email; |
4329 |
} elseif ( $id_or_email instanceof WP_Post ) { |
|
16 | 4330 |
// Post object. |
5 | 4331 |
$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
|
4332 |
} elseif ( $id_or_email instanceof WP_Comment ) { |
9 | 4333 |
if ( ! is_avatar_comment_type( get_comment_type( $id_or_email ) ) ) { |
5 | 4334 |
$args['url'] = false; |
4335 |
/** This filter is documented in wp-includes/link-template.php */ |
|
4336 |
return apply_filters( 'get_avatar_data', $args, $id_or_email ); |
|
4337 |
} |
|
4338 |
||
4339 |
if ( ! empty( $id_or_email->user_id ) ) { |
|
4340 |
$user = get_user_by( 'id', (int) $id_or_email->user_id ); |
|
4341 |
} |
|
4342 |
if ( ( ! $user || is_wp_error( $user ) ) && ! empty( $id_or_email->comment_author_email ) ) { |
|
4343 |
$email = $id_or_email->comment_author_email; |
|
4344 |
} |
|
4345 |
} |
|
4346 |
||
4347 |
if ( ! $email_hash ) { |
|
4348 |
if ( $user ) { |
|
4349 |
$email = $user->user_email; |
|
4350 |
} |
|
4351 |
||
4352 |
if ( $email ) { |
|
4353 |
$email_hash = md5( strtolower( trim( $email ) ) ); |
|
4354 |
} |
|
4355 |
} |
|
4356 |
||
4357 |
if ( $email_hash ) { |
|
4358 |
$args['found_avatar'] = true; |
|
9 | 4359 |
$gravatar_server = hexdec( $email_hash[0] ) % 3; |
5 | 4360 |
} else { |
4361 |
$gravatar_server = rand( 0, 2 ); |
|
4362 |
} |
|
4363 |
||
4364 |
$url_args = array( |
|
4365 |
's' => $args['size'], |
|
4366 |
'd' => $args['default'], |
|
4367 |
'f' => $args['force_default'] ? 'y' : false, |
|
4368 |
'r' => $args['rating'], |
|
4369 |
); |
|
4370 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4371 |
if ( is_ssl() ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4372 |
$url = 'https://secure.gravatar.com/avatar/' . $email_hash; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4373 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4374 |
$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
|
4375 |
} |
5 | 4376 |
|
4377 |
$url = add_query_arg( |
|
4378 |
rawurlencode_deep( array_filter( $url_args ) ), |
|
4379 |
set_url_scheme( $url, $args['scheme'] ) |
|
4380 |
); |
|
4381 |
||
4382 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4383 |
* Filters the avatar URL. |
5 | 4384 |
* |
4385 |
* @since 4.2.0 |
|
4386 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4387 |
* @param string $url The URL of the avatar. |
16 | 4388 |
* @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
|
4389 |
* 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
|
4390 |
* @param array $args Arguments passed to get_avatar_data(), after processing. |
5 | 4391 |
*/ |
4392 |
$args['url'] = apply_filters( 'get_avatar_url', $url, $id_or_email, $args ); |
|
4393 |
||
4394 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4395 |
* Filters the avatar data. |
5 | 4396 |
* |
4397 |
* @since 4.2.0 |
|
4398 |
* |
|
16 | 4399 |
* @param array $args Arguments passed to get_avatar_data(), after processing. |
4400 |
* @param mixed $id_or_email The Gravatar to retrieve. Accepts a user ID, Gravatar MD5 hash, |
|
4401 |
* user email, WP_User object, WP_Post object, or WP_Comment object. |
|
5 | 4402 |
*/ |
4403 |
return apply_filters( 'get_avatar_data', $args, $id_or_email ); |
|
4404 |
} |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4405 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4406 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4407 |
* Retrieves the URL of a file in the theme. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4408 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4409 |
* 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
|
4410 |
* 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
|
4411 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4412 |
* @since 4.7.0 |
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 |
* @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
|
4415 |
* @return string The URL of the file. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4416 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4417 |
function get_theme_file_uri( $file = '' ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4418 |
$file = ltrim( $file, '/' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4419 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4420 |
if ( empty( $file ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4421 |
$url = get_stylesheet_directory_uri(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4422 |
} elseif ( file_exists( get_stylesheet_directory() . '/' . $file ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4423 |
$url = get_stylesheet_directory_uri() . '/' . $file; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4424 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4425 |
$url = get_template_directory_uri() . '/' . $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 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4428 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4429 |
* Filters the URL to a file in the theme. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4430 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4431 |
* @since 4.7.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4432 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4433 |
* @param string $url The file URL. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4434 |
* @param string $file The requested file to search for. |
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 |
return apply_filters( 'theme_file_uri', $url, $file ); |
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 |
|
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 |
* 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
|
4441 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4442 |
* @since 4.7.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4443 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4444 |
* @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
|
4445 |
* @return string The URL of the file. |
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 |
function get_parent_theme_file_uri( $file = '' ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4448 |
$file = ltrim( $file, '/' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4449 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4450 |
if ( empty( $file ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4451 |
$url = get_template_directory_uri(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4452 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4453 |
$url = get_template_directory_uri() . '/' . $file; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4454 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4455 |
|
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 |
* 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
|
4458 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4459 |
* @since 4.7.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4460 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4461 |
* @param string $url The file URL. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4462 |
* @param string $file The requested file to search for. |
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 |
return apply_filters( 'parent_theme_file_uri', $url, $file ); |
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 |
|
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 |
* Retrieves the path of a file in the theme. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4469 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4470 |
* 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
|
4471 |
* 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
|
4472 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4473 |
* @since 4.7.0 |
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 |
* @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
|
4476 |
* @return string The path of the file. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4477 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4478 |
function get_theme_file_path( $file = '' ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4479 |
$file = ltrim( $file, '/' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4480 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4481 |
if ( empty( $file ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4482 |
$path = get_stylesheet_directory(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4483 |
} elseif ( file_exists( get_stylesheet_directory() . '/' . $file ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4484 |
$path = get_stylesheet_directory() . '/' . $file; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4485 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4486 |
$path = get_template_directory() . '/' . $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 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4489 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4490 |
* Filters the path to a file in the theme. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4491 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4492 |
* @since 4.7.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4493 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4494 |
* @param string $path The file path. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4495 |
* @param string $file The requested file to search for. |
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 |
return apply_filters( 'theme_file_path', $path, $file ); |
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 |
|
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 |
* 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
|
4502 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4503 |
* @since 4.7.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4504 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4505 |
* @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
|
4506 |
* @return string The path of the file. |
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 |
function get_parent_theme_file_path( $file = '' ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4509 |
$file = ltrim( $file, '/' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4510 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4511 |
if ( empty( $file ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4512 |
$path = get_template_directory(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4513 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4514 |
$path = get_template_directory() . '/' . $file; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4515 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4516 |
|
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 |
* 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
|
4519 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4520 |
* @since 4.7.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4521 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4522 |
* @param string $path The file path. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4523 |
* @param string $file The requested file to search for. |
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 |
return apply_filters( 'parent_theme_file_path', $path, $file ); |
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 |
|
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 |
* Retrieves the URL to the privacy policy page. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4530 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4531 |
* @since 4.9.6 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4532 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4533 |
* @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
|
4534 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4535 |
function get_privacy_policy_url() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4536 |
$url = ''; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4537 |
$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
|
4538 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4539 |
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
|
4540 |
$url = (string) get_permalink( $policy_page_id ); |
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 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4543 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4544 |
* Filters the URL of the privacy policy page. |
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 |
* @since 4.9.6 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4547 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4548 |
* @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
|
4549 |
* if it doesn't exist. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4550 |
* @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
|
4551 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4552 |
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
|
4553 |
} |
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 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4556 |
* Displays the privacy policy link with formatting, when applicable. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4557 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4558 |
* @since 4.9.6 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4559 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4560 |
* @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
|
4561 |
* @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
|
4562 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4563 |
function the_privacy_policy_link( $before = '', $after = '' ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4564 |
echo get_the_privacy_policy_link( $before, $after ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4565 |
} |
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 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4568 |
* Returns the privacy policy link with formatting, when applicable. |
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 |
* @since 4.9.6 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4571 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4572 |
* @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
|
4573 |
* @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
|
4574 |
* @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
|
4575 |
* doesn't exist. |
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 |
function get_the_privacy_policy_link( $before = '', $after = '' ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4578 |
$link = ''; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4579 |
$privacy_policy_url = get_privacy_policy_url(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4580 |
$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
|
4581 |
$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
|
4582 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4583 |
if ( $privacy_policy_url && $page_title ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4584 |
$link = sprintf( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4585 |
'<a class="privacy-policy-link" href="%s">%s</a>', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4586 |
esc_url( $privacy_policy_url ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4587 |
esc_html( $page_title ) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4588 |
); |
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 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4591 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4592 |
* Filters the privacy policy link. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4593 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4594 |
* @since 4.9.6 |
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 |
* @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
|
4597 |
* doesn't exist. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4598 |
* @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
|
4599 |
* if it doesn't exist. |
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 |
$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
|
4602 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4603 |
if ( $link ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4604 |
return $before . $link . $after; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4605 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4606 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4607 |
return ''; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4608 |
} |