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