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