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