changeset 194 | 32102edaa81b |
parent 136 | bde1974c263b |
child 204 | 09a1c134465b |
193:2f6f6f7551ca | 194:32102edaa81b |
---|---|
25 * blog is not set to have them. |
25 * blog is not set to have them. |
26 * |
26 * |
27 * @since 2.2.0 |
27 * @since 2.2.0 |
28 * @uses $wp_rewrite |
28 * @uses $wp_rewrite |
29 * |
29 * |
30 * @param $string String a URL with or without a trailing slash. |
30 * @param string $string URL with or without a trailing slash. |
31 * @param $type_of_url String the type of URL being considered (e.g. single, category, etc) for use in the filter. |
31 * @param string $type_of_url The type of URL being considered (e.g. single, category, etc) for use in the filter. |
32 * @return string |
32 * @return string |
33 */ |
33 */ |
34 function user_trailingslashit($string, $type_of_url = '') { |
34 function user_trailingslashit($string, $type_of_url = '') { |
35 global $wp_rewrite; |
35 global $wp_rewrite; |
36 if ( $wp_rewrite->use_trailing_slashes ) |
36 if ( $wp_rewrite->use_trailing_slashes ) |
37 $string = trailingslashit($string); |
37 $string = trailingslashit($string); |
38 else |
38 else |
39 $string = untrailingslashit($string); |
39 $string = untrailingslashit($string); |
40 |
40 |
41 // Note that $type_of_url can be one of following: |
41 // Note that $type_of_url can be one of following: |
42 // single, single_trackback, single_feed, single_paged, feed, category, page, year, month, day, paged |
42 // single, single_trackback, single_feed, single_paged, feed, category, page, year, month, day, paged, post_type_archive |
43 $string = apply_filters('user_trailingslashit', $string, $type_of_url); |
43 $string = apply_filters('user_trailingslashit', $string, $type_of_url); |
44 return $string; |
44 return $string; |
45 } |
45 } |
46 |
46 |
47 /** |
47 /** |
98 } else { |
98 } else { |
99 $post = &get_post($id); |
99 $post = &get_post($id); |
100 $sample = false; |
100 $sample = false; |
101 } |
101 } |
102 |
102 |
103 if ( empty($post->ID) ) return false; |
103 if ( empty($post->ID) ) |
104 return false; |
|
104 |
105 |
105 if ( $post->post_type == 'page' ) |
106 if ( $post->post_type == 'page' ) |
106 return get_page_link($post->ID, $leavename, $sample); |
107 return get_page_link($post->ID, $leavename, $sample); |
107 elseif ($post->post_type == 'attachment') |
108 elseif ( $post->post_type == 'attachment' ) |
108 return get_attachment_link($post->ID); |
109 return get_attachment_link($post->ID); |
110 elseif ( in_array($post->post_type, get_post_types( array('_builtin' => false) ) ) ) |
|
111 return get_post_permalink($post->ID, $leavename, $sample); |
|
109 |
112 |
110 $permalink = get_option('permalink_structure'); |
113 $permalink = get_option('permalink_structure'); |
111 |
114 |
112 if ( '' != $permalink && !in_array($post->post_status, array('draft', 'pending')) ) { |
115 $permalink = apply_filters('pre_post_link', $permalink, $post, $leavename); |
116 |
|
117 if ( '' != $permalink && !in_array($post->post_status, array('draft', 'pending', 'auto-draft')) ) { |
|
113 $unixtime = strtotime($post->post_date); |
118 $unixtime = strtotime($post->post_date); |
114 |
119 |
115 $category = ''; |
120 $category = ''; |
116 if ( strpos($permalink, '%category%') !== false ) { |
121 if ( strpos($permalink, '%category%') !== false ) { |
117 $cats = get_the_category($post->ID); |
122 $cats = get_the_category($post->ID); |
148 $post->ID, |
153 $post->ID, |
149 $category, |
154 $category, |
150 $author, |
155 $author, |
151 $post->post_name, |
156 $post->post_name, |
152 ); |
157 ); |
153 $permalink = get_option('home') . str_replace($rewritecode, $rewritereplace, $permalink); |
158 $permalink = home_url( str_replace($rewritecode, $rewritereplace, $permalink) ); |
154 $permalink = user_trailingslashit($permalink, 'single'); |
159 $permalink = user_trailingslashit($permalink, 'single'); |
155 return apply_filters('post_link', $permalink, $post, $leavename); |
|
156 } else { // if they're not using the fancy permalink option |
160 } else { // if they're not using the fancy permalink option |
157 $permalink = trailingslashit(get_option('home')) . '?p=' . $post->ID; |
161 $permalink = home_url('?p=' . $post->ID); |
158 return apply_filters('post_link', $permalink, $post, $leavename); |
162 } |
159 } |
163 return apply_filters('post_link', $permalink, $post, $leavename); |
164 } |
|
165 |
|
166 /** |
|
167 * Retrieve the permalink for a post with a custom post type. |
|
168 * |
|
169 * @since 3.0.0 |
|
170 * |
|
171 * @param int $id Optional. Post ID. |
|
172 * @param bool $leavename Optional, defaults to false. Whether to keep post name. |
|
173 * @param bool $sample Optional, defaults to false. Is it a sample permalink. |
|
174 * @return string |
|
175 */ |
|
176 function get_post_permalink( $id = 0, $leavename = false, $sample = false ) { |
|
177 global $wp_rewrite; |
|
178 |
|
179 $post = &get_post($id); |
|
180 |
|
181 if ( is_wp_error( $post ) ) |
|
182 return $post; |
|
183 |
|
184 $post_link = $wp_rewrite->get_extra_permastruct($post->post_type); |
|
185 |
|
186 $slug = $post->post_name; |
|
187 |
|
188 $draft_or_pending = isset($post->post_status) && in_array( $post->post_status, array( 'draft', 'pending', 'auto-draft' ) ); |
|
189 |
|
190 $post_type = get_post_type_object($post->post_type); |
|
191 |
|
192 if ( !empty($post_link) && ( !$draft_or_pending || $sample ) ) { |
|
193 if ( ! $leavename ) { |
|
194 if ( $post_type->hierarchical ) |
|
195 $slug = get_page_uri($id); |
|
196 $post_link = str_replace("%$post->post_type%", $slug, $post_link); |
|
197 } |
|
198 $post_link = home_url( user_trailingslashit($post_link) ); |
|
199 } else { |
|
200 if ( $post_type->query_var && ( isset($post->post_status) && !$draft_or_pending ) ) |
|
201 $post_link = add_query_arg($post_type->query_var, $slug, ''); |
|
202 else |
|
203 $post_link = add_query_arg(array('post_type' => $post->post_type, 'p' => $post->ID), ''); |
|
204 $post_link = home_url($post_link); |
|
205 } |
|
206 |
|
207 return apply_filters('post_type_link', $post_link, $post, $leavename, $sample); |
|
160 } |
208 } |
161 |
209 |
162 /** |
210 /** |
163 * Retrieve permalink from post ID. |
211 * Retrieve permalink from post ID. |
164 * |
212 * |
166 * |
214 * |
167 * @param int $post_id Optional. Post ID. |
215 * @param int $post_id Optional. Post ID. |
168 * @param mixed $deprecated Not used. |
216 * @param mixed $deprecated Not used. |
169 * @return string |
217 * @return string |
170 */ |
218 */ |
171 function post_permalink($post_id = 0, $deprecated = '') { |
219 function post_permalink( $post_id = 0, $deprecated = '' ) { |
220 if ( !empty( $deprecated ) ) |
|
221 _deprecated_argument( __FUNCTION__, '1.3' ); |
|
222 |
|
172 return get_permalink($post_id); |
223 return get_permalink($post_id); |
173 } |
224 } |
174 |
225 |
175 /** |
226 /** |
176 * Retrieve the permalink for current page or page ID. |
227 * Retrieve the permalink for current page or page ID. |
190 $id = (int) $id; |
241 $id = (int) $id; |
191 if ( !$id ) |
242 if ( !$id ) |
192 $id = (int) $post->ID; |
243 $id = (int) $post->ID; |
193 |
244 |
194 if ( 'page' == get_option('show_on_front') && $id == get_option('page_on_front') ) |
245 if ( 'page' == get_option('show_on_front') && $id == get_option('page_on_front') ) |
195 $link = get_option('home'); |
246 $link = home_url('/'); |
196 else |
247 else |
197 $link = _get_page_link( $id , $leavename, $sample ); |
248 $link = _get_page_link( $id , $leavename, $sample ); |
198 |
249 |
199 return apply_filters('page_link', $link, $id); |
250 return apply_filters('page_link', $link, $id, $sample); |
200 } |
251 } |
201 |
252 |
202 /** |
253 /** |
203 * Retrieve the page permalink. |
254 * Retrieve the page permalink. |
204 * |
255 * |
218 if ( !$id ) |
269 if ( !$id ) |
219 $id = (int) $post->ID; |
270 $id = (int) $post->ID; |
220 else |
271 else |
221 $post = &get_post($id); |
272 $post = &get_post($id); |
222 |
273 |
223 $pagestruct = $wp_rewrite->get_page_permastruct(); |
274 $draft_or_pending = in_array( $post->post_status, array( 'draft', 'pending', 'auto-draft' ) ); |
224 |
275 |
225 if ( '' != $pagestruct && ( ( isset($post->post_status) && 'draft' != $post->post_status && 'pending' != $post->post_status ) || $sample ) ) { |
276 $link = $wp_rewrite->get_page_permastruct(); |
226 $link = get_page_uri($id); |
277 |
227 $link = ( $leavename ) ? $pagestruct : str_replace('%pagename%', $link, $pagestruct); |
278 if ( !empty($link) && ( ( isset($post->post_status) && !$draft_or_pending ) || $sample ) ) { |
228 $link = trailingslashit(get_option('home')) . "$link"; |
279 if ( ! $leavename ) { |
280 $link = str_replace('%pagename%', get_page_uri($id), $link); |
|
281 } |
|
282 |
|
283 $link = home_url($link); |
|
229 $link = user_trailingslashit($link, 'page'); |
284 $link = user_trailingslashit($link, 'page'); |
230 } else { |
285 } else { |
231 $link = trailingslashit(get_option('home')) . "?page_id=$id"; |
286 $link = home_url("?page_id=$id"); |
232 } |
287 } |
233 |
288 |
234 return apply_filters( '_get_page_link', $link, $id ); |
289 return apply_filters( '_get_page_link', $link, $id ); |
235 } |
290 } |
236 |
291 |
247 function get_attachment_link($id = false) { |
302 function get_attachment_link($id = false) { |
248 global $post, $wp_rewrite; |
303 global $post, $wp_rewrite; |
249 |
304 |
250 $link = false; |
305 $link = false; |
251 |
306 |
252 if (! $id) { |
307 if ( ! $id) |
253 $id = (int) $post->ID; |
308 $id = (int) $post->ID; |
254 } |
|
255 |
309 |
256 $object = get_post($id); |
310 $object = get_post($id); |
257 if ( $wp_rewrite->using_permalinks() && ($object->post_parent > 0) && ($object->post_parent != $id) ) { |
311 if ( $wp_rewrite->using_permalinks() && ($object->post_parent > 0) && ($object->post_parent != $id) ) { |
258 $parent = get_post($object->post_parent); |
312 $parent = get_post($object->post_parent); |
259 if ( 'page' == $parent->post_type ) |
313 if ( 'page' == $parent->post_type ) |
260 $parentlink = _get_page_link( $object->post_parent ); // Ignores page_on_front |
314 $parentlink = _get_page_link( $object->post_parent ); // Ignores page_on_front |
261 else |
315 else |
262 $parentlink = get_permalink( $object->post_parent ); |
316 $parentlink = get_permalink( $object->post_parent ); |
317 |
|
263 if ( is_numeric($object->post_name) || false !== strpos(get_option('permalink_structure'), '%category%') ) |
318 if ( is_numeric($object->post_name) || false !== strpos(get_option('permalink_structure'), '%category%') ) |
264 $name = 'attachment/' . $object->post_name; // <permalink>/<int>/ is paged so we use the explicit attachment marker |
319 $name = 'attachment/' . $object->post_name; // <permalink>/<int>/ is paged so we use the explicit attachment marker |
265 else |
320 else |
266 $name = $object->post_name; |
321 $name = $object->post_name; |
267 if (strpos($parentlink, '?') === false) |
322 |
323 if ( strpos($parentlink, '?') === false ) |
|
268 $link = user_trailingslashit( trailingslashit($parentlink) . $name ); |
324 $link = user_trailingslashit( trailingslashit($parentlink) . $name ); |
269 } |
325 } |
270 |
326 |
271 if (! $link ) { |
327 if ( ! $link ) |
272 $link = trailingslashit(get_bloginfo('url')) . "?attachment_id=$id"; |
328 $link = home_url( "/?attachment_id=$id" ); |
273 } |
|
274 |
329 |
275 return apply_filters('attachment_link', $link, $id); |
330 return apply_filters('attachment_link', $link, $id); |
276 } |
331 } |
277 |
332 |
278 /** |
333 /** |
284 * @return string |
339 * @return string |
285 */ |
340 */ |
286 function get_year_link($year) { |
341 function get_year_link($year) { |
287 global $wp_rewrite; |
342 global $wp_rewrite; |
288 if ( !$year ) |
343 if ( !$year ) |
289 $year = gmdate('Y', time()+(get_option('gmt_offset') * 3600)); |
344 $year = gmdate('Y', current_time('timestamp')); |
290 $yearlink = $wp_rewrite->get_year_permastruct(); |
345 $yearlink = $wp_rewrite->get_year_permastruct(); |
291 if ( !empty($yearlink) ) { |
346 if ( !empty($yearlink) ) { |
292 $yearlink = str_replace('%year%', $year, $yearlink); |
347 $yearlink = str_replace('%year%', $year, $yearlink); |
293 return apply_filters('year_link', get_option('home') . user_trailingslashit($yearlink, 'year'), $year); |
348 return apply_filters('year_link', home_url( user_trailingslashit($yearlink, 'year') ), $year); |
294 } else { |
349 } else { |
295 return apply_filters('year_link', trailingslashit(get_option('home')) . '?m=' . $year, $year); |
350 return apply_filters('year_link', home_url('?m=' . $year), $year); |
296 } |
351 } |
297 } |
352 } |
298 |
353 |
299 /** |
354 /** |
300 * Retrieve the permalink for the month archives with year. |
355 * Retrieve the permalink for the month archives with year. |
306 * @return string |
361 * @return string |
307 */ |
362 */ |
308 function get_month_link($year, $month) { |
363 function get_month_link($year, $month) { |
309 global $wp_rewrite; |
364 global $wp_rewrite; |
310 if ( !$year ) |
365 if ( !$year ) |
311 $year = gmdate('Y', time()+(get_option('gmt_offset') * 3600)); |
366 $year = gmdate('Y', current_time('timestamp')); |
312 if ( !$month ) |
367 if ( !$month ) |
313 $month = gmdate('m', time()+(get_option('gmt_offset') * 3600)); |
368 $month = gmdate('m', current_time('timestamp')); |
314 $monthlink = $wp_rewrite->get_month_permastruct(); |
369 $monthlink = $wp_rewrite->get_month_permastruct(); |
315 if ( !empty($monthlink) ) { |
370 if ( !empty($monthlink) ) { |
316 $monthlink = str_replace('%year%', $year, $monthlink); |
371 $monthlink = str_replace('%year%', $year, $monthlink); |
317 $monthlink = str_replace('%monthnum%', zeroise(intval($month), 2), $monthlink); |
372 $monthlink = str_replace('%monthnum%', zeroise(intval($month), 2), $monthlink); |
318 return apply_filters('month_link', get_option('home') . user_trailingslashit($monthlink, 'month'), $year, $month); |
373 return apply_filters('month_link', home_url( user_trailingslashit($monthlink, 'month') ), $year, $month); |
319 } else { |
374 } else { |
320 return apply_filters('month_link', trailingslashit(get_option('home')) . '?m=' . $year . zeroise($month, 2), $year, $month); |
375 return apply_filters('month_link', home_url( '?m=' . $year . zeroise($month, 2) ), $year, $month); |
321 } |
376 } |
322 } |
377 } |
323 |
378 |
324 /** |
379 /** |
325 * Retrieve the permalink for the day archives with year and month. |
380 * Retrieve the permalink for the day archives with year and month. |
332 * @return string |
387 * @return string |
333 */ |
388 */ |
334 function get_day_link($year, $month, $day) { |
389 function get_day_link($year, $month, $day) { |
335 global $wp_rewrite; |
390 global $wp_rewrite; |
336 if ( !$year ) |
391 if ( !$year ) |
337 $year = gmdate('Y', time()+(get_option('gmt_offset') * 3600)); |
392 $year = gmdate('Y', current_time('timestamp')); |
338 if ( !$month ) |
393 if ( !$month ) |
339 $month = gmdate('m', time()+(get_option('gmt_offset') * 3600)); |
394 $month = gmdate('m', current_time('timestamp')); |
340 if ( !$day ) |
395 if ( !$day ) |
341 $day = gmdate('j', time()+(get_option('gmt_offset') * 3600)); |
396 $day = gmdate('j', current_time('timestamp')); |
342 |
397 |
343 $daylink = $wp_rewrite->get_day_permastruct(); |
398 $daylink = $wp_rewrite->get_day_permastruct(); |
344 if ( !empty($daylink) ) { |
399 if ( !empty($daylink) ) { |
345 $daylink = str_replace('%year%', $year, $daylink); |
400 $daylink = str_replace('%year%', $year, $daylink); |
346 $daylink = str_replace('%monthnum%', zeroise(intval($month), 2), $daylink); |
401 $daylink = str_replace('%monthnum%', zeroise(intval($month), 2), $daylink); |
347 $daylink = str_replace('%day%', zeroise(intval($day), 2), $daylink); |
402 $daylink = str_replace('%day%', zeroise(intval($day), 2), $daylink); |
348 return apply_filters('day_link', get_option('home') . user_trailingslashit($daylink, 'day'), $year, $month, $day); |
403 return apply_filters('day_link', home_url( user_trailingslashit($daylink, 'day') ), $year, $month, $day); |
349 } else { |
404 } else { |
350 return apply_filters('day_link', trailingslashit(get_option('home')) . '?m=' . $year . zeroise($month, 2) . zeroise($day, 2), $year, $month, $day); |
405 return apply_filters('day_link', home_url( '?m=' . $year . zeroise($month, 2) . zeroise($day, 2) ), $year, $month, $day); |
351 } |
406 } |
407 } |
|
408 |
|
409 /** |
|
410 * Display the permalink for the feed type. |
|
411 * |
|
412 * @since 3.0.0 |
|
413 * |
|
414 * @param string $anchor The link's anchor text. |
|
415 * @param string $feed Optional, defaults to default feed. Feed type. |
|
416 */ |
|
417 function the_feed_link( $anchor, $feed = '' ) { |
|
418 $link = '<a href="' . esc_url( get_feed_link( $feed ) ) . '">' . $anchor . '</a>'; |
|
419 echo apply_filters( 'the_feed_link', $link, $feed ); |
|
352 } |
420 } |
353 |
421 |
354 /** |
422 /** |
355 * Retrieve the permalink for the feed type. |
423 * Retrieve the permalink for the feed type. |
356 * |
424 * |
372 if ( get_default_feed() == $feed ) |
440 if ( get_default_feed() == $feed ) |
373 $feed = ''; |
441 $feed = ''; |
374 |
442 |
375 $permalink = str_replace('%feed%', $feed, $permalink); |
443 $permalink = str_replace('%feed%', $feed, $permalink); |
376 $permalink = preg_replace('#/+#', '/', "/$permalink"); |
444 $permalink = preg_replace('#/+#', '/', "/$permalink"); |
377 $output = get_option('home') . user_trailingslashit($permalink, 'feed'); |
445 $output = home_url( user_trailingslashit($permalink, 'feed') ); |
378 } else { |
446 } else { |
379 if ( empty($feed) ) |
447 if ( empty($feed) ) |
380 $feed = get_default_feed(); |
448 $feed = get_default_feed(); |
381 |
449 |
382 if ( false !== strpos($feed, 'comments_') ) |
450 if ( false !== strpos($feed, 'comments_') ) |
383 $feed = str_replace('comments_', 'comments-', $feed); |
451 $feed = str_replace('comments_', 'comments-', $feed); |
384 |
452 |
385 $output = trailingslashit(get_option('home')) . "?feed={$feed}"; |
453 $output = home_url("?feed={$feed}"); |
386 } |
454 } |
387 |
455 |
388 return apply_filters('feed_link', $output, $feed); |
456 return apply_filters('feed_link', $output, $feed); |
389 } |
457 } |
390 |
458 |
395 * |
463 * |
396 * @param int $post_id Optional. Post ID. |
464 * @param int $post_id Optional. Post ID. |
397 * @param string $feed Optional. Feed type. |
465 * @param string $feed Optional. Feed type. |
398 * @return string |
466 * @return string |
399 */ |
467 */ |
400 function get_post_comments_feed_link($post_id = '', $feed = '') { |
468 function get_post_comments_feed_link($post_id = 0, $feed = '') { |
401 global $id; |
469 $post_id = absint( $post_id ); |
402 |
470 |
403 if ( empty($post_id) ) |
471 if ( ! $post_id ) |
404 $post_id = (int) $id; |
472 $post_id = get_the_ID(); |
405 |
473 |
406 if ( empty($feed) ) |
474 if ( empty( $feed ) ) |
407 $feed = get_default_feed(); |
475 $feed = get_default_feed(); |
408 |
476 |
409 if ( '' != get_option('permalink_structure') ) { |
477 if ( '' != get_option('permalink_structure') ) { |
410 $url = trailingslashit( get_permalink($post_id) ) . 'feed'; |
478 if ( 'page' == get_option('show_on_front') && $post_id == get_option('page_on_front') ) |
479 $url = _get_page_link( $post_id ); |
|
480 else |
|
481 $url = get_permalink($post_id); |
|
482 |
|
483 $url = trailingslashit($url) . 'feed'; |
|
411 if ( $feed != get_default_feed() ) |
484 if ( $feed != get_default_feed() ) |
412 $url .= "/$feed"; |
485 $url .= "/$feed"; |
413 $url = user_trailingslashit($url, 'single_feed'); |
486 $url = user_trailingslashit($url, 'single_feed'); |
414 } else { |
487 } else { |
415 $type = get_post_field('post_type', $post_id); |
488 $type = get_post_field('post_type', $post_id); |
416 if ( 'page' == $type ) |
489 if ( 'page' == $type ) |
417 $url = trailingslashit(get_option('home')) . "?feed=$feed&page_id=$post_id"; |
490 $url = home_url("?feed=$feed&page_id=$post_id"); |
418 else |
491 else |
419 $url = trailingslashit(get_option('home')) . "?feed=$feed&p=$post_id"; |
492 $url = home_url("?feed=$feed&p=$post_id"); |
420 } |
493 } |
421 |
494 |
422 return apply_filters('post_comments_feed_link', $url); |
495 return apply_filters('post_comments_feed_link', $url); |
423 } |
496 } |
424 |
497 |
432 * @package WordPress |
505 * @package WordPress |
433 * @subpackage Feed |
506 * @subpackage Feed |
434 * @since 2.5.0 |
507 * @since 2.5.0 |
435 * |
508 * |
436 * @param string $link_text Descriptive text. |
509 * @param string $link_text Descriptive text. |
437 * @param int $post_id Optional post ID. Default to current post. |
510 * @param int $post_id Optional post ID. Default to current post. |
438 * @param string $feed Optional. Feed format. |
511 * @param string $feed Optional. Feed format. |
439 * @return string Link to the comment feed for the current post. |
512 * @return string Link to the comment feed for the current post. |
440 */ |
513 */ |
441 function post_comments_feed_link( $link_text = '', $post_id = '', $feed = '' ) { |
514 function post_comments_feed_link( $link_text = '', $post_id = '', $feed = '' ) { |
442 $url = get_post_comments_feed_link($post_id, $feed); |
515 $url = get_post_comments_feed_link($post_id, $feed); |
466 |
539 |
467 if ( empty($feed) ) |
540 if ( empty($feed) ) |
468 $feed = get_default_feed(); |
541 $feed = get_default_feed(); |
469 |
542 |
470 if ( '' == $permalink_structure ) { |
543 if ( '' == $permalink_structure ) { |
471 $link = trailingslashit(get_option('home')) . "?feed=$feed&author=" . $author_id; |
544 $link = home_url("?feed=$feed&author=" . $author_id); |
472 } else { |
545 } else { |
473 $link = get_author_posts_url($author_id); |
546 $link = get_author_posts_url($author_id); |
474 if ( $feed == get_default_feed() ) |
547 if ( $feed == get_default_feed() ) |
475 $feed_link = 'feed'; |
548 $feed_link = 'feed'; |
476 else |
549 else |
485 } |
558 } |
486 |
559 |
487 /** |
560 /** |
488 * Retrieve the feed link for a category. |
561 * Retrieve the feed link for a category. |
489 * |
562 * |
490 * Returns a link to the feed for all post in a given category. A specific feed |
563 * Returns a link to the feed for all posts in a given category. A specific feed |
491 * can be requested or left blank to get the default feed. |
564 * can be requested or left blank to get the default feed. |
492 * |
565 * |
493 * @package WordPress |
566 * @package WordPress |
494 * @subpackage Feed |
567 * @subpackage Feed |
495 * @since 2.5.0 |
568 * @since 2.5.0 |
497 * @param int $cat_id ID of a category. |
570 * @param int $cat_id ID of a category. |
498 * @param string $feed Optional. Feed type. |
571 * @param string $feed Optional. Feed type. |
499 * @return string Link to the feed for the category specified by $cat_id. |
572 * @return string Link to the feed for the category specified by $cat_id. |
500 */ |
573 */ |
501 function get_category_feed_link($cat_id, $feed = '') { |
574 function get_category_feed_link($cat_id, $feed = '') { |
502 $cat_id = (int) $cat_id; |
575 return get_term_feed_link($cat_id, 'category', $feed); |
503 |
576 } |
504 $category = get_category($cat_id); |
577 |
505 |
578 /** |
506 if ( empty($category) || is_wp_error($category) ) |
579 * Retrieve the feed link for a term. |
580 * |
|
581 * Returns a link to the feed for all posts in a given term. A specific feed |
|
582 * can be requested or left blank to get the default feed. |
|
583 * |
|
584 * @since 3.0 |
|
585 * |
|
586 * @param int $term_id ID of a category. |
|
587 * @param string $taxonomy Optional. Taxonomy of $term_id |
|
588 * @param string $feed Optional. Feed type. |
|
589 * @return string Link to the feed for the term specified by $term_id and $taxonomy. |
|
590 */ |
|
591 function get_term_feed_link( $term_id, $taxonomy = 'category', $feed = '' ) { |
|
592 $term_id = ( int ) $term_id; |
|
593 |
|
594 $term = get_term( $term_id, $taxonomy ); |
|
595 |
|
596 if ( empty( $term ) || is_wp_error( $term ) ) |
|
507 return false; |
597 return false; |
508 |
598 |
509 if ( empty($feed) ) |
599 if ( empty( $feed ) ) |
510 $feed = get_default_feed(); |
600 $feed = get_default_feed(); |
511 |
601 |
512 $permalink_structure = get_option('permalink_structure'); |
602 $permalink_structure = get_option( 'permalink_structure' ); |
513 |
603 |
514 if ( '' == $permalink_structure ) { |
604 if ( '' == $permalink_structure ) { |
515 $link = trailingslashit(get_option('home')) . "?feed=$feed&cat=" . $cat_id; |
605 if ( 'category' == $taxonomy ) { |
606 $link = home_url("?feed=$feed&cat=$term_id"); |
|
607 } |
|
608 elseif ( 'post_tag' == $taxonomy ) { |
|
609 $link = home_url("?feed=$feed&tag=$term->slug"); |
|
610 } else { |
|
611 $t = get_taxonomy( $taxonomy ); |
|
612 $link = home_url("?feed=$feed&$t->query_var=$term->slug"); |
|
613 } |
|
516 } else { |
614 } else { |
517 $link = get_category_link($cat_id); |
615 $link = get_term_link( $term_id, $term->taxonomy ); |
518 if( $feed == get_default_feed() ) |
|
519 $feed_link = 'feed'; |
|
520 else |
|
521 $feed_link = "feed/$feed"; |
|
522 |
|
523 $link = trailingslashit($link) . user_trailingslashit($feed_link, 'feed'); |
|
524 } |
|
525 |
|
526 $link = apply_filters('category_feed_link', $link, $feed); |
|
527 |
|
528 return $link; |
|
529 } |
|
530 |
|
531 /** |
|
532 * Retrieve permalink for feed of tag. |
|
533 * |
|
534 * @since 2.3.0 |
|
535 * |
|
536 * @param int $tag_id Tag ID. |
|
537 * @param string $feed Optional. Feed type. |
|
538 * @return string |
|
539 */ |
|
540 function get_tag_feed_link($tag_id, $feed = '') { |
|
541 $tag_id = (int) $tag_id; |
|
542 |
|
543 $tag = get_tag($tag_id); |
|
544 |
|
545 if ( empty($tag) || is_wp_error($tag) ) |
|
546 return false; |
|
547 |
|
548 $permalink_structure = get_option('permalink_structure'); |
|
549 |
|
550 if ( empty($feed) ) |
|
551 $feed = get_default_feed(); |
|
552 |
|
553 if ( '' == $permalink_structure ) { |
|
554 $link = trailingslashit(get_option('home')) . "?feed=$feed&tag=" . $tag->slug; |
|
555 } else { |
|
556 $link = get_tag_link($tag->term_id); |
|
557 if ( $feed == get_default_feed() ) |
616 if ( $feed == get_default_feed() ) |
558 $feed_link = 'feed'; |
617 $feed_link = 'feed'; |
559 else |
618 else |
560 $feed_link = "feed/$feed"; |
619 $feed_link = "feed/$feed"; |
561 $link = trailingslashit($link) . user_trailingslashit($feed_link, 'feed'); |
620 |
562 } |
621 $link = trailingslashit( $link ) . user_trailingslashit( $feed_link, 'feed' ); |
563 |
622 } |
564 $link = apply_filters('tag_feed_link', $link, $feed); |
623 |
624 if ( 'category' == $taxonomy ) |
|
625 $link = apply_filters( 'category_feed_link', $link, $feed ); |
|
626 elseif ( 'post_tag' == $taxonomy ) |
|
627 $link = apply_filters( 'category_feed_link', $link, $feed ); |
|
628 else |
|
629 $link = apply_filters( 'taxonomy_feed_link', $link, $feed, $taxonomy ); |
|
565 |
630 |
566 return $link; |
631 return $link; |
567 } |
632 } |
568 |
633 |
569 /** |
634 /** |
635 * Retrieve permalink for feed of tag. |
|
636 * |
|
637 * @since 2.3.0 |
|
638 * |
|
639 * @param int $tag_id Tag ID. |
|
640 * @param string $feed Optional. Feed type. |
|
641 * @return string |
|
642 */ |
|
643 function get_tag_feed_link($tag_id, $feed = '') { |
|
644 return get_term_feed_link($tag_id, 'post_tag', $feed); |
|
645 } |
|
646 |
|
647 /** |
|
570 * Retrieve edit tag link. |
648 * Retrieve edit tag link. |
571 * |
649 * |
572 * @since 2.7.0 |
650 * @since 2.7.0 |
573 * |
651 * |
574 * @param int $tag_id Tag ID |
652 * @param int $tag_id Tag ID |
575 * @return string |
653 * @param string $taxonomy Taxonomy |
576 */ |
654 * @return string |
577 function get_edit_tag_link( $tag_id = 0, $taxonomy = 'post_tag' ) { |
655 */ |
578 $tag = get_term($tag_id, $taxonomy); |
656 function get_edit_tag_link( $tag_id, $taxonomy = 'post_tag' ) { |
579 |
657 return apply_filters( 'get_edit_tag_link', get_edit_term_link( $tag_id, $taxonomy ) ); |
580 if ( !current_user_can('manage_categories') ) |
|
581 return; |
|
582 |
|
583 $location = admin_url('edit-tags.php?action=edit&taxonomy=' . $taxonomy . '&tag_ID=' . $tag->term_id); |
|
584 return apply_filters( 'get_edit_tag_link', $location ); |
|
585 } |
658 } |
586 |
659 |
587 /** |
660 /** |
588 * Display or retrieve edit tag link with formatting. |
661 * Display or retrieve edit tag link with formatting. |
589 * |
662 * |
591 * |
664 * |
592 * @param string $link Optional. Anchor text. |
665 * @param string $link Optional. Anchor text. |
593 * @param string $before Optional. Display before edit link. |
666 * @param string $before Optional. Display before edit link. |
594 * @param string $after Optional. Display after edit link. |
667 * @param string $after Optional. Display after edit link. |
595 * @param int|object $tag Tag object or ID |
668 * @param int|object $tag Tag object or ID |
596 * @return string|null HTML content, if $echo is set to false. |
669 * @return string HTML content. |
597 */ |
670 */ |
598 function edit_tag_link( $link = '', $before = '', $after = '', $tag = null ) { |
671 function edit_tag_link( $link = '', $before = '', $after = '', $tag = null ) { |
599 $tag = get_term($tag, 'post_tag'); |
672 $link = edit_term_link( $link, '', '', false, $tag ); |
600 |
673 echo $before . apply_filters( 'edit_tag_link', $link ) . $after; |
601 if ( !current_user_can('manage_categories') ) |
674 } |
602 return; |
675 |
603 |
676 /** |
604 if ( empty($link) ) |
677 * Retrieve edit term url. |
678 * |
|
679 * @since 3.1.0 |
|
680 * |
|
681 * @param int $term_id Term ID |
|
682 * @param string $taxonomy Taxonomy |
|
683 * @param string $object_type The object type |
|
684 * @return string |
|
685 */ |
|
686 function get_edit_term_link( $term_id, $taxonomy, $object_type = '' ) { |
|
687 $tax = get_taxonomy( $taxonomy ); |
|
688 if ( !current_user_can( $tax->cap->edit_terms ) ) |
|
689 return; |
|
690 |
|
691 $term = get_term( $term_id, $taxonomy ); |
|
692 |
|
693 $args = array( |
|
694 'action' => 'edit', |
|
695 'taxonomy' => $taxonomy, |
|
696 'tag_ID' => $term->term_id, |
|
697 ); |
|
698 |
|
699 if ( $object_type ) |
|
700 $args['post_type'] = $object_type; |
|
701 |
|
702 $location = add_query_arg( $args, admin_url( 'edit-tags.php' ) ); |
|
703 |
|
704 return apply_filters( 'get_edit_term_link', $location, $term_id, $taxonomy, $object_type ); |
|
705 } |
|
706 |
|
707 /** |
|
708 * Display or retrieve edit term link with formatting. |
|
709 * |
|
710 * @since 3.1.0 |
|
711 * |
|
712 * @param string $link Optional. Anchor text. |
|
713 * @param string $before Optional. Display before edit link. |
|
714 * @param string $after Optional. Display after edit link. |
|
715 * @param object $term Term object |
|
716 * @return string HTML content. |
|
717 */ |
|
718 function edit_term_link( $link = '', $before = '', $after = '', $term = null, $echo = true ) { |
|
719 if ( is_null( $term ) ) { |
|
720 $term = get_queried_object(); |
|
721 } |
|
722 |
|
723 $tax = get_taxonomy( $term->taxonomy ); |
|
724 if ( !current_user_can($tax->cap->edit_terms) ) |
|
725 return; |
|
726 |
|
727 if ( empty( $link ) ) |
|
605 $link = __('Edit This'); |
728 $link = __('Edit This'); |
606 |
729 |
607 $link = '<a href="' . get_edit_tag_link( $tag->term_id ) . '" title="' . __( 'Edit tag' ) . '">' . $link . '</a>'; |
730 $link = '<a href="' . get_edit_term_link( $term->term_id, $term->taxonomy ) . '" title="' . $link . '">' . $link . '</a>'; |
608 echo $before . apply_filters( 'edit_tag_link', $link, $tag->term_id ) . $after; |
731 $link = $before . apply_filters( 'edit_term_link', $link, $term->term_id ) . $after; |
732 |
|
733 if ( $echo ) |
|
734 echo $link; |
|
735 else |
|
736 return $link; |
|
737 } |
|
738 |
|
739 /** |
|
740 * Retrieve permalink for search. |
|
741 * |
|
742 * @since 3.0.0 |
|
743 * @param string $query Optional. The query string to use. If empty the current query is used. |
|
744 * @return string |
|
745 */ |
|
746 function get_search_link( $query = '' ) { |
|
747 global $wp_rewrite; |
|
748 |
|
749 if ( empty($query) ) |
|
750 $search = get_search_query( false ); |
|
751 else |
|
752 $search = stripslashes($query); |
|
753 |
|
754 $permastruct = $wp_rewrite->get_search_permastruct(); |
|
755 |
|
756 if ( empty( $permastruct ) ) { |
|
757 $link = home_url('?s=' . urlencode($search) ); |
|
758 } else { |
|
759 $search = urlencode($search); |
|
760 $search = str_replace('%2F', '/', $search); // %2F(/) is not valid within a URL, send it unencoded. |
|
761 $link = str_replace( '%search%', $search, $permastruct ); |
|
762 $link = home_url( user_trailingslashit( $link, 'search' ) ); |
|
763 } |
|
764 |
|
765 return apply_filters( 'search_link', $link, $search ); |
|
609 } |
766 } |
610 |
767 |
611 /** |
768 /** |
612 * Retrieve the permalink for the feed of the search results. |
769 * Retrieve the permalink for the feed of the search results. |
613 * |
770 * |
616 * @param string $search_query Optional. Search query. |
773 * @param string $search_query Optional. Search query. |
617 * @param string $feed Optional. Feed type. |
774 * @param string $feed Optional. Feed type. |
618 * @return string |
775 * @return string |
619 */ |
776 */ |
620 function get_search_feed_link($search_query = '', $feed = '') { |
777 function get_search_feed_link($search_query = '', $feed = '') { |
621 if ( empty($search_query) ) |
778 global $wp_rewrite; |
622 $search = esc_attr( urlencode(get_search_query()) ); |
779 $link = get_search_link($search_query); |
623 else |
|
624 $search = esc_attr( urlencode(stripslashes($search_query)) ); |
|
625 |
780 |
626 if ( empty($feed) ) |
781 if ( empty($feed) ) |
627 $feed = get_default_feed(); |
782 $feed = get_default_feed(); |
628 |
783 |
629 $link = trailingslashit(get_option('home')) . "?s=$search&feed=$feed"; |
784 $permastruct = $wp_rewrite->get_search_permastruct(); |
630 |
785 |
631 $link = apply_filters('search_feed_link', $link); |
786 if ( empty($permastruct) ) { |
787 $link = add_query_arg('feed', $feed, $link); |
|
788 } else { |
|
789 $link = trailingslashit($link); |
|
790 $link .= "feed/$feed/"; |
|
791 } |
|
792 |
|
793 $link = apply_filters('search_feed_link', $link, $feed, 'posts'); |
|
632 |
794 |
633 return $link; |
795 return $link; |
634 } |
796 } |
635 |
797 |
636 /** |
798 /** |
641 * @param string $search_query Optional. Search query. |
803 * @param string $search_query Optional. Search query. |
642 * @param string $feed Optional. Feed type. |
804 * @param string $feed Optional. Feed type. |
643 * @return string |
805 * @return string |
644 */ |
806 */ |
645 function get_search_comments_feed_link($search_query = '', $feed = '') { |
807 function get_search_comments_feed_link($search_query = '', $feed = '') { |
646 if ( empty($search_query) ) |
808 global $wp_rewrite; |
647 $search = esc_attr( urlencode(get_search_query()) ); |
|
648 else |
|
649 $search = esc_attr( urlencode(stripslashes($search_query)) ); |
|
650 |
809 |
651 if ( empty($feed) ) |
810 if ( empty($feed) ) |
652 $feed = get_default_feed(); |
811 $feed = get_default_feed(); |
653 |
812 |
654 $link = trailingslashit(get_option('home')) . "?s=$search&feed=comments-$feed"; |
813 $link = get_search_feed_link($search_query, $feed); |
655 |
814 |
656 $link = apply_filters('search_feed_link', $link); |
815 $permastruct = $wp_rewrite->get_search_permastruct(); |
816 |
|
817 if ( empty($permastruct) ) |
|
818 $link = add_query_arg('feed', 'comments-' . $feed, $link); |
|
819 else |
|
820 $link = add_query_arg('withcomments', 1, $link); |
|
821 |
|
822 $link = apply_filters('search_feed_link', $link, $feed, 'comments'); |
|
657 |
823 |
658 return $link; |
824 return $link; |
825 } |
|
826 |
|
827 /** |
|
828 * Retrieve the permalink for a post type archive. |
|
829 * |
|
830 * @since 3.1.0 |
|
831 * |
|
832 * @param string $post_type Post type |
|
833 * @return string |
|
834 */ |
|
835 function get_post_type_archive_link( $post_type ) { |
|
836 global $wp_rewrite; |
|
837 if ( ! $post_type_obj = get_post_type_object( $post_type ) ) |
|
838 return false; |
|
839 |
|
840 if ( ! $post_type_obj->has_archive ) |
|
841 return false; |
|
842 |
|
843 if ( get_option( 'permalink_structure' ) && is_array( $post_type_obj->rewrite ) ) { |
|
844 $struct = ( true === $post_type_obj->has_archive ) ? $post_type_obj->rewrite['slug'] : $post_type_obj->has_archive; |
|
845 if ( $post_type_obj->rewrite['with_front'] ) |
|
846 $struct = $wp_rewrite->front . $struct; |
|
847 else |
|
848 $struct = $wp_rewrite->root . $struct; |
|
849 $link = home_url( user_trailingslashit( $struct, 'post_type_archive' ) ); |
|
850 } else { |
|
851 $link = home_url( '?post_type=' . $post_type ); |
|
852 } |
|
853 |
|
854 return apply_filters( 'post_type_archive_link', $link, $post_type ); |
|
855 } |
|
856 |
|
857 /** |
|
858 * Retrieve the permalink for a post type archive feed. |
|
859 * |
|
860 * @since 3.1.0 |
|
861 * |
|
862 * @param string $post_type Post type |
|
863 * @param string $feed Optional. Feed type |
|
864 * @return string |
|
865 */ |
|
866 function get_post_type_archive_feed_link( $post_type, $feed = '' ) { |
|
867 $default_feed = get_default_feed(); |
|
868 if ( empty( $feed ) ) |
|
869 $feed = $default_feed; |
|
870 |
|
871 if ( ! $link = get_post_type_archive_link( $post_type ) ) |
|
872 return false; |
|
873 $post_type_obj = get_post_type_object( $post_type ); |
|
874 if ( $post_type_obj->rewrite['feeds'] && get_option( 'permalink_structure' ) ) { |
|
875 $link = trailingslashit($link); |
|
876 $link .= 'feed/'; |
|
877 if ( $feed != $default_feed ) |
|
878 $link .= "$feed/"; |
|
879 } else { |
|
880 $link = add_query_arg( 'feed', $feed, $link ); |
|
881 } |
|
882 |
|
883 return apply_filters( 'post_type_archive_feed_link', $link, $feed ); |
|
659 } |
884 } |
660 |
885 |
661 /** |
886 /** |
662 * Retrieve edit posts link for post. |
887 * Retrieve edit posts link for post. |
663 * |
888 * |
665 * pages, posts, attachments, and revisions. |
890 * pages, posts, attachments, and revisions. |
666 * |
891 * |
667 * @since 2.3.0 |
892 * @since 2.3.0 |
668 * |
893 * |
669 * @param int $id Optional. Post ID. |
894 * @param int $id Optional. Post ID. |
670 * @param string $context Optional, default to display. How to write the '&', defaults to '&'. |
895 * @param string $context Optional, defaults to display. How to write the '&', defaults to '&'. |
671 * @return string |
896 * @return string |
672 */ |
897 */ |
673 function get_edit_post_link( $id = 0, $context = 'display' ) { |
898 function get_edit_post_link( $id = 0, $context = 'display' ) { |
674 if ( !$post = &get_post( $id ) ) |
899 if ( !$post = &get_post( $id ) ) |
675 return; |
900 return; |
676 |
901 |
677 if ( 'display' == $context ) |
902 if ( 'display' == $context ) |
678 $action = 'action=edit&'; |
903 $action = '&action=edit'; |
679 else |
904 else |
680 $action = 'action=edit&'; |
905 $action = '&action=edit'; |
681 |
906 |
682 switch ( $post->post_type ) : |
907 $post_type_object = get_post_type_object( $post->post_type ); |
683 case 'page' : |
908 if ( !$post_type_object ) |
684 if ( !current_user_can( 'edit_page', $post->ID ) ) |
909 return; |
685 return; |
910 |
686 $file = 'page'; |
911 if ( !current_user_can( $post_type_object->cap->edit_post, $post->ID ) ) |
687 $var = 'post'; |
912 return; |
688 break; |
913 |
689 case 'attachment' : |
914 return apply_filters( 'get_edit_post_link', admin_url( sprintf($post_type_object->_edit_link . $action, $post->ID) ), $post->ID, $context ); |
690 if ( !current_user_can( 'edit_post', $post->ID ) ) |
|
691 return; |
|
692 $file = 'media'; |
|
693 $var = 'attachment_id'; |
|
694 break; |
|
695 case 'revision' : |
|
696 if ( !current_user_can( 'edit_post', $post->ID ) ) |
|
697 return; |
|
698 $file = 'revision'; |
|
699 $var = 'revision'; |
|
700 $action = ''; |
|
701 break; |
|
702 default : |
|
703 if ( !current_user_can( 'edit_post', $post->ID ) ) |
|
704 return apply_filters( 'get_edit_post_link', '', $post->ID, $context );; |
|
705 $file = 'post'; |
|
706 $var = 'post'; |
|
707 break; |
|
708 endswitch; |
|
709 |
|
710 return apply_filters( 'get_edit_post_link', admin_url("$file.php?{$action}$var=$post->ID"), $post->ID, $context ); |
|
711 } |
915 } |
712 |
916 |
713 /** |
917 /** |
714 * Display edit post link for post. |
918 * Display edit post link for post. |
715 * |
919 * |
728 return; |
932 return; |
729 |
933 |
730 if ( null === $link ) |
934 if ( null === $link ) |
731 $link = __('Edit This'); |
935 $link = __('Edit This'); |
732 |
936 |
733 $link = '<a class="post-edit-link" href="' . $url . '" title="' . esc_attr( __( 'Edit post' ) ) . '">' . $link . '</a>'; |
937 $post_type_obj = get_post_type_object( $post->post_type ); |
938 $link = '<a class="post-edit-link" href="' . $url . '" title="' . esc_attr( $post_type_obj->labels->edit_item ) . '">' . $link . '</a>'; |
|
734 echo $before . apply_filters( 'edit_post_link', $link, $post->ID ) . $after; |
939 echo $before . apply_filters( 'edit_post_link', $link, $post->ID ) . $after; |
735 } |
940 } |
736 |
941 |
737 /** |
942 /** |
738 * Retrieve delete posts link for post. |
943 * Retrieve delete posts link for post. |
739 * |
944 * |
740 * Can be used within the WordPress loop or outside of it. Can be used with |
945 * Can be used within the WordPress loop or outside of it, with any post type. |
741 * pages, posts, attachments, and revisions. |
|
742 * |
946 * |
743 * @since 2.9.0 |
947 * @since 2.9.0 |
744 * |
948 * |
745 * @param int $id Optional. Post ID. |
949 * @param int $id Optional. Post ID. |
746 * @param string $context Optional, default to display. How to write the '&', defaults to '&'. |
950 * @param string $deprecated Not used. |
747 * @return string |
951 * @param bool $force_delete Whether to bypass trash and force deletion. Default is false. |
748 */ |
952 * @return string |
749 function get_delete_post_link($id = 0, $context = 'display') { |
953 */ |
954 function get_delete_post_link( $id = 0, $deprecated = '', $force_delete = false ) { |
|
955 if ( ! empty( $deprecated ) ) |
|
956 _deprecated_argument( __FUNCTION__, '3.0' ); |
|
957 |
|
750 if ( !$post = &get_post( $id ) ) |
958 if ( !$post = &get_post( $id ) ) |
751 return; |
959 return; |
752 |
960 |
753 if ( 'display' == $context ) |
961 $post_type_object = get_post_type_object( $post->post_type ); |
754 $action = 'action=trash&'; |
962 if ( !$post_type_object ) |
755 else |
963 return; |
756 $action = 'action=trash&'; |
964 |
757 |
965 if ( !current_user_can( $post_type_object->cap->delete_post, $post->ID ) ) |
758 switch ( $post->post_type ) : |
966 return; |
759 case 'page' : |
967 |
760 if ( !current_user_can( 'delete_page', $post->ID ) ) |
968 $action = ( $force_delete || !EMPTY_TRASH_DAYS ) ? 'delete' : 'trash'; |
761 return; |
969 |
762 $file = 'page'; |
970 $delete_link = add_query_arg( 'action', $action, admin_url( sprintf( $post_type_object->_edit_link, $post->ID ) ) ); |
763 $var = 'post'; |
971 |
764 break; |
972 return apply_filters( 'get_delete_post_link', wp_nonce_url( $delete_link, "$action-{$post->post_type}_{$post->ID}" ), $post->ID, $force_delete ); |
765 case 'attachment' : |
|
766 if ( !current_user_can( 'delete_post', $post->ID ) ) |
|
767 return; |
|
768 $file = 'media'; |
|
769 $var = 'attachment_id'; |
|
770 break; |
|
771 case 'revision' : |
|
772 if ( !current_user_can( 'delete_post', $post->ID ) ) |
|
773 return; |
|
774 $file = 'revision'; |
|
775 $var = 'revision'; |
|
776 $action = ''; |
|
777 break; |
|
778 default : |
|
779 if ( !current_user_can( 'edit_post', $post->ID ) ) |
|
780 return apply_filters( 'get_delete_post_link', '', $post->ID, $context );; |
|
781 $file = 'post'; |
|
782 $var = 'post'; |
|
783 break; |
|
784 endswitch; |
|
785 |
|
786 return apply_filters( 'get_delete_post_link', wp_nonce_url( admin_url("$file.php?{$action}$var=$post->ID"), "trash-{$file}_" . $post->ID ), $context ); |
|
787 } |
973 } |
788 |
974 |
789 /** |
975 /** |
790 * Retrieve edit comment link. |
976 * Retrieve edit comment link. |
791 * |
977 * |
794 * @param int $comment_id Optional. Comment ID. |
980 * @param int $comment_id Optional. Comment ID. |
795 * @return string |
981 * @return string |
796 */ |
982 */ |
797 function get_edit_comment_link( $comment_id = 0 ) { |
983 function get_edit_comment_link( $comment_id = 0 ) { |
798 $comment = &get_comment( $comment_id ); |
984 $comment = &get_comment( $comment_id ); |
799 $post = &get_post( $comment->comment_post_ID ); |
985 |
800 |
986 if ( !current_user_can( 'edit_comment', $comment->comment_ID ) ) |
801 if ( $post->post_type == 'page' ) { |
987 return; |
802 if ( !current_user_can( 'edit_page', $post->ID ) ) |
|
803 return; |
|
804 } else { |
|
805 if ( !current_user_can( 'edit_post', $post->ID ) ) |
|
806 return; |
|
807 } |
|
808 |
988 |
809 $location = admin_url('comment.php?action=editcomment&c=') . $comment->comment_ID; |
989 $location = admin_url('comment.php?action=editcomment&c=') . $comment->comment_ID; |
810 return apply_filters( 'get_edit_comment_link', $location ); |
990 return apply_filters( 'get_edit_comment_link', $location ); |
811 } |
991 } |
812 |
992 |
819 * @param string $before Optional. Display before edit link. |
999 * @param string $before Optional. Display before edit link. |
820 * @param string $after Optional. Display after edit link. |
1000 * @param string $after Optional. Display after edit link. |
821 * @return string|null HTML content, if $echo is set to false. |
1001 * @return string|null HTML content, if $echo is set to false. |
822 */ |
1002 */ |
823 function edit_comment_link( $link = null, $before = '', $after = '' ) { |
1003 function edit_comment_link( $link = null, $before = '', $after = '' ) { |
824 global $comment, $post; |
1004 global $comment; |
825 |
1005 |
826 if ( $post->post_type == 'page' ) { |
1006 if ( !current_user_can( 'edit_comment', $comment->comment_ID ) ) |
827 if ( !current_user_can( 'edit_page', $post->ID ) ) |
1007 return; |
828 return; |
|
829 } else { |
|
830 if ( !current_user_can( 'edit_post', $post->ID ) ) |
|
831 return; |
|
832 } |
|
833 |
1008 |
834 if ( null === $link ) |
1009 if ( null === $link ) |
835 $link = __('Edit This'); |
1010 $link = __('Edit This'); |
836 |
1011 |
837 $link = '<a class="comment-edit-link" href="' . get_edit_comment_link( $comment->comment_ID ) . '" title="' . __( 'Edit comment' ) . '">' . $link . '</a>'; |
1012 $link = '<a class="comment-edit-link" href="' . get_edit_comment_link( $comment->comment_ID ) . '" title="' . esc_attr__( 'Edit comment' ) . '">' . $link . '</a>'; |
838 echo $before . apply_filters( 'edit_comment_link', $link, $comment->comment_ID ) . $after; |
1013 echo $before . apply_filters( 'edit_comment_link', $link, $comment->comment_ID ) . $after; |
839 } |
1014 } |
840 |
1015 |
841 /** |
1016 /** |
842 * Display edit bookmark (literally a URL external to blog) link. |
1017 * Display edit bookmark (literally a URL external to blog) link. |
873 return; |
1048 return; |
874 |
1049 |
875 if ( empty($link) ) |
1050 if ( empty($link) ) |
876 $link = __('Edit This'); |
1051 $link = __('Edit This'); |
877 |
1052 |
878 $link = '<a href="' . get_edit_bookmark_link( $link ) . '" title="' . __( 'Edit link' ) . '">' . $link . '</a>'; |
1053 $link = '<a href="' . get_edit_bookmark_link( $bookmark ) . '" title="' . esc_attr__( 'Edit Link' ) . '">' . $link . '</a>'; |
879 echo $before . apply_filters( 'edit_bookmark_link', $link, $bookmark->link_id ) . $after; |
1054 echo $before . apply_filters( 'edit_bookmark_link', $link, $bookmark->link_id ) . $after; |
880 } |
1055 } |
881 |
1056 |
882 // Navigation links |
1057 // Navigation links |
883 |
1058 |
884 /** |
1059 /** |
885 * Retrieve previous post link that is adjacent to current post. |
1060 * Retrieve previous post that is adjacent to current post. |
886 * |
1061 * |
887 * @since 1.5.0 |
1062 * @since 1.5.0 |
888 * |
1063 * |
889 * @param bool $in_same_cat Optional. Whether link should be in same category. |
1064 * @param bool $in_same_cat Optional. Whether post should be in a same category. |
890 * @param string $excluded_categories Optional. Excluded categories IDs. |
1065 * @param array|string $excluded_categories Optional. Array or comma-separated list of excluded category IDs. |
891 * @return string |
1066 * @return mixed Post object if successful. Null if global $post is not set. Empty string if no corresponding post exists. |
892 */ |
1067 */ |
893 function get_previous_post($in_same_cat = false, $excluded_categories = '') { |
1068 function get_previous_post($in_same_cat = false, $excluded_categories = '') { |
894 return get_adjacent_post($in_same_cat, $excluded_categories); |
1069 return get_adjacent_post($in_same_cat, $excluded_categories); |
895 } |
1070 } |
896 |
1071 |
897 /** |
1072 /** |
898 * Retrieve next post link that is adjacent to current post. |
1073 * Retrieve next post that is adjacent to current post. |
899 * |
1074 * |
900 * @since 1.5.0 |
1075 * @since 1.5.0 |
901 * |
1076 * |
902 * @param bool $in_same_cat Optional. Whether link should be in same category. |
1077 * @param bool $in_same_cat Optional. Whether post should be in a same category. |
903 * @param string $excluded_categories Optional. Excluded categories IDs. |
1078 * @param array|string $excluded_categories Optional. Array or comma-separated list of excluded category IDs. |
904 * @return string |
1079 * @return mixed Post object if successful. Null if global $post is not set. Empty string if no corresponding post exists. |
905 */ |
1080 */ |
906 function get_next_post($in_same_cat = false, $excluded_categories = '') { |
1081 function get_next_post($in_same_cat = false, $excluded_categories = '') { |
907 return get_adjacent_post($in_same_cat, $excluded_categories, false); |
1082 return get_adjacent_post($in_same_cat, $excluded_categories, false); |
908 } |
1083 } |
909 |
1084 |
910 /** |
1085 /** |
911 * Retrieve adjacent post link. |
1086 * Retrieve adjacent post. |
912 * |
1087 * |
913 * Can either be next or previous post link. |
1088 * Can either be next or previous post. |
914 * |
1089 * |
915 * @since 2.5.0 |
1090 * @since 2.5.0 |
916 * |
1091 * |
917 * @param bool $in_same_cat Optional. Whether link should be in same category. |
1092 * @param bool $in_same_cat Optional. Whether post should be in a same category. |
918 * @param string $excluded_categories Optional. Excluded categories IDs. |
1093 * @param array|string $excluded_categories Optional. Array or comma-separated list of excluded category IDs. |
919 * @param bool $previous Optional. Whether to retrieve previous post. |
1094 * @param bool $previous Optional. Whether to retrieve previous post. |
920 * @return string |
1095 * @return mixed Post object if successful. Null if global $post is not set. Empty string if no corresponding post exists. |
921 */ |
1096 */ |
922 function get_adjacent_post($in_same_cat = false, $excluded_categories = '', $previous = true) { |
1097 function get_adjacent_post( $in_same_cat = false, $excluded_categories = '', $previous = true ) { |
923 global $post, $wpdb; |
1098 global $post, $wpdb; |
924 |
1099 |
925 if ( empty($post) || !is_single() || is_attachment() ) |
1100 if ( empty( $post ) ) |
926 return null; |
1101 return null; |
927 |
1102 |
928 $current_post_date = $post->post_date; |
1103 $current_post_date = $post->post_date; |
929 |
1104 |
930 $join = ''; |
1105 $join = ''; |
931 $posts_in_ex_cats_sql = ''; |
1106 $posts_in_ex_cats_sql = ''; |
932 if ( $in_same_cat || !empty($excluded_categories) ) { |
1107 if ( $in_same_cat || ! empty( $excluded_categories ) ) { |
933 $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"; |
1108 $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"; |
934 |
1109 |
935 if ( $in_same_cat ) { |
1110 if ( $in_same_cat ) { |
936 $cat_array = wp_get_object_terms($post->ID, 'category', 'fields=ids'); |
1111 $cat_array = wp_get_object_terms($post->ID, 'category', array('fields' => 'ids')); |
937 $join .= " AND tt.taxonomy = 'category' AND tt.term_id IN (" . implode(',', $cat_array) . ")"; |
1112 $join .= " AND tt.taxonomy = 'category' AND tt.term_id IN (" . implode(',', $cat_array) . ")"; |
938 } |
1113 } |
939 |
1114 |
940 $posts_in_ex_cats_sql = "AND tt.taxonomy = 'category'"; |
1115 $posts_in_ex_cats_sql = "AND tt.taxonomy = 'category'"; |
941 if ( !empty($excluded_categories) ) { |
1116 if ( ! empty( $excluded_categories ) ) { |
942 $excluded_categories = array_map('intval', explode(' and ', $excluded_categories)); |
1117 if ( ! is_array( $excluded_categories ) ) { |
943 if ( !empty($cat_array) ) { |
1118 // back-compat, $excluded_categories used to be IDs separated by " and " |
1119 if ( strpos( $excluded_categories, ' and ' ) !== false ) { |
|
1120 _deprecated_argument( __FUNCTION__, '3.3', sprintf( __( 'Use commas instead of %s to separate excluded categories.' ), "'and'" ) ); |
|
1121 $excluded_categories = explode( ' and ', $excluded_categories ); |
|
1122 } else { |
|
1123 $excluded_categories = explode( ',', $excluded_categories ); |
|
1124 } |
|
1125 } |
|
1126 |
|
1127 $excluded_categories = array_map( 'intval', $excluded_categories ); |
|
1128 |
|
1129 if ( ! empty( $cat_array ) ) { |
|
944 $excluded_categories = array_diff($excluded_categories, $cat_array); |
1130 $excluded_categories = array_diff($excluded_categories, $cat_array); |
945 $posts_in_ex_cats_sql = ''; |
1131 $posts_in_ex_cats_sql = ''; |
946 } |
1132 } |
947 |
1133 |
948 if ( !empty($excluded_categories) ) { |
1134 if ( !empty($excluded_categories) ) { |
979 * Can either be next or previous post relational link. |
1165 * Can either be next or previous post relational link. |
980 * |
1166 * |
981 * @since 2.8.0 |
1167 * @since 2.8.0 |
982 * |
1168 * |
983 * @param string $title Optional. Link title format. |
1169 * @param string $title Optional. Link title format. |
984 * @param bool $in_same_cat Optional. Whether link should be in same category. |
1170 * @param bool $in_same_cat Optional. Whether link should be in a same category. |
985 * @param string $excluded_categories Optional. Excluded categories IDs. |
1171 * @param array|string $excluded_categories Optional. Array or comma-separated list of excluded category IDs. |
986 * @param bool $previous Optional, default is true. Whether display link to previous post. |
1172 * @param bool $previous Optional, default is true. Whether to display link to previous or next post. |
987 * @return string |
1173 * @return string |
988 */ |
1174 */ |
989 function get_adjacent_post_rel_link($title = '%title', $in_same_cat = false, $excluded_categories = '', $previous = true) { |
1175 function get_adjacent_post_rel_link($title = '%title', $in_same_cat = false, $excluded_categories = '', $previous = true) { |
990 if ( $previous && is_attachment() ) |
1176 if ( $previous && is_attachment() && is_object( $GLOBALS['post'] ) ) |
991 $post = & get_post($GLOBALS['post']->post_parent); |
1177 $post = & get_post($GLOBALS['post']->post_parent); |
992 else |
1178 else |
993 $post = get_adjacent_post($in_same_cat,$excluded_categories,$previous); |
1179 $post = get_adjacent_post($in_same_cat,$excluded_categories,$previous); |
994 |
1180 |
995 if ( empty($post) ) |
1181 if ( empty($post) ) |
1000 |
1186 |
1001 $date = mysql2date(get_option('date_format'), $post->post_date); |
1187 $date = mysql2date(get_option('date_format'), $post->post_date); |
1002 |
1188 |
1003 $title = str_replace('%title', $post->post_title, $title); |
1189 $title = str_replace('%title', $post->post_title, $title); |
1004 $title = str_replace('%date', $date, $title); |
1190 $title = str_replace('%date', $date, $title); |
1005 $title = apply_filters('the_title', $title, $post); |
1191 $title = apply_filters('the_title', $title, $post->ID); |
1006 |
1192 |
1007 $link = $previous ? "<link rel='prev' title='" : "<link rel='next' title='"; |
1193 $link = $previous ? "<link rel='prev' title='" : "<link rel='next' title='"; |
1008 $link .= esc_attr( $title ); |
1194 $link .= esc_attr( $title ); |
1009 $link .= "' href='" . get_permalink($post) . "' />\n"; |
1195 $link .= "' href='" . get_permalink($post) . "' />\n"; |
1010 |
1196 |
1016 * Display relational links for the posts adjacent to the current post. |
1202 * Display relational links for the posts adjacent to the current post. |
1017 * |
1203 * |
1018 * @since 2.8.0 |
1204 * @since 2.8.0 |
1019 * |
1205 * |
1020 * @param string $title Optional. Link title format. |
1206 * @param string $title Optional. Link title format. |
1021 * @param bool $in_same_cat Optional. Whether link should be in same category. |
1207 * @param bool $in_same_cat Optional. Whether link should be in a same category. |
1022 * @param string $excluded_categories Optional. Excluded categories IDs. |
1208 * @param array|string $excluded_categories Optional. Array or comma-separated list of excluded category IDs. |
1023 */ |
1209 */ |
1024 function adjacent_posts_rel_link($title = '%title', $in_same_cat = false, $excluded_categories = '') { |
1210 function adjacent_posts_rel_link($title = '%title', $in_same_cat = false, $excluded_categories = '') { |
1025 echo get_adjacent_post_rel_link($title, $in_same_cat, $excluded_categories = '', true); |
1211 echo get_adjacent_post_rel_link($title, $in_same_cat, $excluded_categories = '', true); |
1026 echo get_adjacent_post_rel_link($title, $in_same_cat, $excluded_categories = '', false); |
1212 echo get_adjacent_post_rel_link($title, $in_same_cat, $excluded_categories = '', false); |
1027 } |
1213 } |
1028 |
1214 |
1029 /** |
1215 /** |
1216 * Display relational links for the posts adjacent to the current post for single post pages. |
|
1217 * |
|
1218 * This is meant to be attached to actions like 'wp_head'. Do not call this directly in plugins or theme templates. |
|
1219 * @since 3.0.0 |
|
1220 * |
|
1221 */ |
|
1222 function adjacent_posts_rel_link_wp_head() { |
|
1223 if ( !is_singular() || is_attachment() ) |
|
1224 return; |
|
1225 adjacent_posts_rel_link(); |
|
1226 } |
|
1227 |
|
1228 /** |
|
1030 * Display relational link for the next post adjacent to the current post. |
1229 * Display relational link for the next post adjacent to the current post. |
1031 * |
1230 * |
1032 * @since 2.8.0 |
1231 * @since 2.8.0 |
1033 * |
1232 * |
1034 * @param string $title Optional. Link title format. |
1233 * @param string $title Optional. Link title format. |
1035 * @param bool $in_same_cat Optional. Whether link should be in same category. |
1234 * @param bool $in_same_cat Optional. Whether link should be in a same category. |
1036 * @param string $excluded_categories Optional. Excluded categories IDs. |
1235 * @param array|string $excluded_categories Optional. Array or comma-separated list of excluded category IDs. |
1037 */ |
1236 */ |
1038 function next_post_rel_link($title = '%title', $in_same_cat = false, $excluded_categories = '') { |
1237 function next_post_rel_link($title = '%title', $in_same_cat = false, $excluded_categories = '') { |
1039 echo get_adjacent_post_rel_link($title, $in_same_cat, $excluded_categories = '', false); |
1238 echo get_adjacent_post_rel_link($title, $in_same_cat, $excluded_categories = '', false); |
1040 } |
1239 } |
1041 |
1240 |
1043 * Display relational link for the previous post adjacent to the current post. |
1242 * Display relational link for the previous post adjacent to the current post. |
1044 * |
1243 * |
1045 * @since 2.8.0 |
1244 * @since 2.8.0 |
1046 * |
1245 * |
1047 * @param string $title Optional. Link title format. |
1246 * @param string $title Optional. Link title format. |
1048 * @param bool $in_same_cat Optional. Whether link should be in same category. |
1247 * @param bool $in_same_cat Optional. Whether link should be in a same category. |
1049 * @param string $excluded_categories Optional. Excluded categories IDs. |
1248 * @param array|string $excluded_categories Optional. Array or comma-separated list of excluded category IDs. |
1050 */ |
1249 */ |
1051 function prev_post_rel_link($title = '%title', $in_same_cat = false, $excluded_categories = '') { |
1250 function prev_post_rel_link($title = '%title', $in_same_cat = false, $excluded_categories = '') { |
1052 echo get_adjacent_post_rel_link($title, $in_same_cat, $excluded_categories = '', true); |
1251 echo get_adjacent_post_rel_link($title, $in_same_cat, $excluded_categories = '', true); |
1053 } |
1252 } |
1054 |
1253 |
1055 /** |
1254 /** |
1056 * Retrieve boundary post. |
1255 * Retrieve boundary post. |
1057 * |
1256 * |
1058 * Boundary being either the first or last post by publish date within the contraitns specified |
1257 * Boundary being either the first or last post by publish date within the constraints specified |
1059 * by in same category or excluded categories. |
1258 * by $in_same_cat or $excluded_categories. |
1060 * |
1259 * |
1061 * @since 2.8.0 |
1260 * @since 2.8.0 |
1062 * |
1261 * |
1063 * @param bool $in_same_cat Optional. Whether returned post should be in same category. |
1262 * @param bool $in_same_cat Optional. Whether returned post should be in a same category. |
1064 * @param string $excluded_categories Optional. Excluded categories IDs. |
1263 * @param array|string $excluded_categories Optional. Array or comma-separated list of excluded category IDs. |
1065 * @param bool $previous Optional. Whether to retrieve first post. |
1264 * @param bool $start Optional. Whether to retrieve first or last post. |
1066 * @return object |
1265 * @return object |
1067 */ |
1266 */ |
1068 function get_boundary_post($in_same_cat = false, $excluded_categories = '', $start = true) { |
1267 function get_boundary_post( $in_same_cat = false, $excluded_categories = '', $start = true ) { |
1069 global $post, $wpdb; |
1268 global $post; |
1070 |
1269 |
1071 if ( empty($post) || !is_single() || is_attachment() ) |
1270 if ( empty($post) || ! is_single() || is_attachment() ) |
1072 return null; |
1271 return null; |
1073 |
1272 |
1074 $cat_array = array(); |
1273 $cat_array = array(); |
1075 $excluded_categories = array(); |
1274 if( ! is_array( $excluded_categories ) ) |
1076 if ( !empty($in_same_cat) || !empty($excluded_categories) ) { |
1275 $excluded_categories = explode( ',', $excluded_categories ); |
1077 if ( !empty($in_same_cat) ) { |
1276 |
1078 $cat_array = wp_get_object_terms($post->ID, 'category', 'fields=ids'); |
1277 if ( $in_same_cat || ! empty( $excluded_categories ) ) { |
1079 } |
1278 if ( $in_same_cat ) |
1080 |
1279 $cat_array = wp_get_object_terms( $post->ID, 'category', array( 'fields' => 'ids' ) ); |
1081 if ( !empty($excluded_categories) ) { |
1280 |
1082 $excluded_categories = array_map('intval', explode(',', $excluded_categories)); |
1281 if ( ! empty( $excluded_categories ) ) { |
1083 |
1282 $excluded_categories = array_map( 'intval', $excluded_categories ); |
1084 if ( !empty($cat_array) ) |
1283 $excluded_categories = array_diff( $excluded_categories, $cat_array ); |
1085 $excluded_categories = array_diff($excluded_categories, $cat_array); |
|
1086 |
1284 |
1087 $inverse_cats = array(); |
1285 $inverse_cats = array(); |
1088 foreach ( $excluded_categories as $excluded_category) |
1286 foreach ( $excluded_categories as $excluded_category ) |
1089 $inverse_cats[] = $excluded_category * -1; |
1287 $inverse_cats[] = $excluded_category * -1; |
1090 $excluded_categories = $inverse_cats; |
1288 $excluded_categories = $inverse_cats; |
1091 } |
1289 } |
1092 } |
1290 } |
1093 |
1291 |
1094 $categories = implode(',', array_merge($cat_array, $excluded_categories) ); |
1292 $categories = implode( ',', array_merge( $cat_array, $excluded_categories ) ); |
1095 |
1293 |
1096 $order = $start ? 'ASC' : 'DESC'; |
1294 $order = $start ? 'ASC' : 'DESC'; |
1097 |
1295 |
1098 return get_posts( array('numberposts' => 1, 'order' => $order, 'orderby' => 'ID', 'category' => $categories) ); |
1296 return get_posts( array('numberposts' => 1, 'category' => $categories, 'order' => $order, 'update_post_term_cache' => false, 'update_post_meta_cache' => false) ); |
1099 } |
|
1100 |
|
1101 /** |
|
1102 * Get boundary post relational link. |
|
1103 * |
|
1104 * Can either be start or end post relational link. |
|
1105 * |
|
1106 * @since 2.8.0 |
|
1107 * |
|
1108 * @param string $title Optional. Link title format. |
|
1109 * @param bool $in_same_cat Optional. Whether link should be in same category. |
|
1110 * @param string $excluded_categories Optional. Excluded categories IDs. |
|
1111 * @param bool $start Optional, default is true. Whether display link to first post. |
|
1112 * @return string |
|
1113 */ |
|
1114 function get_boundary_post_rel_link($title = '%title', $in_same_cat = false, $excluded_categories = '', $start = true) { |
|
1115 $posts = get_boundary_post($in_same_cat,$excluded_categories,$start); |
|
1116 // Even though we limited get_posts to return only 1 item it still returns an array of objects. |
|
1117 $post = $posts[0]; |
|
1118 |
|
1119 if ( empty($post) ) |
|
1120 return; |
|
1121 |
|
1122 if ( empty($post->post_title) ) |
|
1123 $post->post_title = $start ? __('First Post') : __('Last Post'); |
|
1124 |
|
1125 $date = mysql2date(get_option('date_format'), $post->post_date); |
|
1126 |
|
1127 $title = str_replace('%title', $post->post_title, $title); |
|
1128 $title = str_replace('%date', $date, $title); |
|
1129 $title = apply_filters('the_title', $title, $post); |
|
1130 |
|
1131 $link = $start ? "<link rel='start' title='" : "<link rel='end' title='"; |
|
1132 $link .= esc_attr($title); |
|
1133 $link .= "' href='" . get_permalink($post) . "' />\n"; |
|
1134 |
|
1135 $boundary = $start ? 'start' : 'end'; |
|
1136 return apply_filters( "{$boundary}_post_rel_link", $link ); |
|
1137 } |
|
1138 |
|
1139 /** |
|
1140 * Display relational link for the first post. |
|
1141 * |
|
1142 * @since 2.8.0 |
|
1143 * |
|
1144 * @param string $title Optional. Link title format. |
|
1145 * @param bool $in_same_cat Optional. Whether link should be in same category. |
|
1146 * @param string $excluded_categories Optional. Excluded categories IDs. |
|
1147 */ |
|
1148 function start_post_rel_link($title = '%title', $in_same_cat = false, $excluded_categories = '') { |
|
1149 echo get_boundary_post_rel_link($title, $in_same_cat, $excluded_categories, true); |
|
1150 } |
|
1151 |
|
1152 /** |
|
1153 * Get site index relational link. |
|
1154 * |
|
1155 * @since 2.8.0 |
|
1156 * |
|
1157 * @return string |
|
1158 */ |
|
1159 function get_index_rel_link() { |
|
1160 $link = "<link rel='index' title='" . esc_attr(get_bloginfo('name')) . "' href='" . get_bloginfo('siteurl') . "' />\n"; |
|
1161 return apply_filters( "index_rel_link", $link ); |
|
1162 } |
|
1163 |
|
1164 /** |
|
1165 * Display relational link for the site index. |
|
1166 * |
|
1167 * @since 2.8.0 |
|
1168 */ |
|
1169 function index_rel_link() { |
|
1170 echo get_index_rel_link(); |
|
1171 } |
|
1172 |
|
1173 /** |
|
1174 * Get parent post relational link. |
|
1175 * |
|
1176 * @since 2.8.0 |
|
1177 * |
|
1178 * @param string $title Optional. Link title format. |
|
1179 * @return string |
|
1180 */ |
|
1181 function get_parent_post_rel_link($title = '%title') { |
|
1182 if ( ! empty( $GLOBALS['post'] ) && ! empty( $GLOBALS['post']->post_parent ) ) |
|
1183 $post = & get_post($GLOBALS['post']->post_parent); |
|
1184 |
|
1185 if ( empty($post) ) |
|
1186 return; |
|
1187 |
|
1188 $date = mysql2date(get_option('date_format'), $post->post_date); |
|
1189 |
|
1190 $title = str_replace('%title', $post->post_title, $title); |
|
1191 $title = str_replace('%date', $date, $title); |
|
1192 $title = apply_filters('the_title', $title, $post); |
|
1193 |
|
1194 $link = "<link rel='up' title='"; |
|
1195 $link .= esc_attr( $title ); |
|
1196 $link .= "' href='" . get_permalink($post) . "' />\n"; |
|
1197 |
|
1198 return apply_filters( "parent_post_rel_link", $link ); |
|
1199 } |
|
1200 |
|
1201 /** |
|
1202 * Display relational link for parent item |
|
1203 * |
|
1204 * @since 2.8.0 |
|
1205 */ |
|
1206 function parent_post_rel_link($title = '%title') { |
|
1207 echo get_parent_post_rel_link($title); |
|
1208 } |
1297 } |
1209 |
1298 |
1210 /** |
1299 /** |
1211 * Display previous post link that is adjacent to the current post. |
1300 * Display previous post link that is adjacent to the current post. |
1212 * |
1301 * |
1213 * @since 1.5.0 |
1302 * @since 1.5.0 |
1214 * |
1303 * |
1215 * @param string $format Optional. Link anchor format. |
1304 * @param string $format Optional. Link anchor format. |
1216 * @param string $link Optional. Link permalink format. |
1305 * @param string $link Optional. Link permalink format. |
1217 * @param bool $in_same_cat Optional. Whether link should be in same category. |
1306 * @param bool $in_same_cat Optional. Whether link should be in a same category. |
1218 * @param string $excluded_categories Optional. Excluded categories IDs. |
1307 * @param array|string $excluded_categories Optional. Array or comma-separated list of excluded category IDs. |
1219 */ |
1308 */ |
1220 function previous_post_link($format='« %link', $link='%title', $in_same_cat = false, $excluded_categories = '') { |
1309 function previous_post_link($format='« %link', $link='%title', $in_same_cat = false, $excluded_categories = '') { |
1221 adjacent_post_link($format, $link, $in_same_cat, $excluded_categories, true); |
1310 adjacent_post_link($format, $link, $in_same_cat, $excluded_categories, true); |
1222 } |
1311 } |
1223 |
1312 |
1226 * |
1315 * |
1227 * @since 1.5.0 |
1316 * @since 1.5.0 |
1228 * |
1317 * |
1229 * @param string $format Optional. Link anchor format. |
1318 * @param string $format Optional. Link anchor format. |
1230 * @param string $link Optional. Link permalink format. |
1319 * @param string $link Optional. Link permalink format. |
1231 * @param bool $in_same_cat Optional. Whether link should be in same category. |
1320 * @param bool $in_same_cat Optional. Whether link should be in a same category. |
1232 * @param string $excluded_categories Optional. Excluded categories IDs. |
1321 * @param array|string $excluded_categories Optional. Array or comma-separated list of excluded category IDs. |
1233 */ |
1322 */ |
1234 function next_post_link($format='%link »', $link='%title', $in_same_cat = false, $excluded_categories = '') { |
1323 function next_post_link($format='%link »', $link='%title', $in_same_cat = false, $excluded_categories = '') { |
1235 adjacent_post_link($format, $link, $in_same_cat, $excluded_categories, false); |
1324 adjacent_post_link($format, $link, $in_same_cat, $excluded_categories, false); |
1236 } |
1325 } |
1237 |
1326 |
1242 * |
1331 * |
1243 * @since 2.5.0 |
1332 * @since 2.5.0 |
1244 * |
1333 * |
1245 * @param string $format Link anchor format. |
1334 * @param string $format Link anchor format. |
1246 * @param string $link Link permalink format. |
1335 * @param string $link Link permalink format. |
1247 * @param bool $in_same_cat Optional. Whether link should be in same category. |
1336 * @param bool $in_same_cat Optional. Whether link should be in a same category. |
1248 * @param string $excluded_categories Optional. Excluded categories IDs. |
1337 * @param array|string $excluded_categories Optional. Array or comma-separated list of excluded category IDs. |
1249 * @param bool $previous Optional, default is true. Whether display link to previous post. |
1338 * @param bool $previous Optional, default is true. Whether to display link to previous or next post. |
1250 */ |
1339 */ |
1251 function adjacent_post_link($format, $link, $in_same_cat = false, $excluded_categories = '', $previous = true) { |
1340 function adjacent_post_link($format, $link, $in_same_cat = false, $excluded_categories = '', $previous = true) { |
1252 if ( $previous && is_attachment() ) |
1341 if ( $previous && is_attachment() ) |
1253 $post = & get_post($GLOBALS['post']->post_parent); |
1342 $post = & get_post($GLOBALS['post']->post_parent); |
1254 else |
1343 else |
1260 $title = $post->post_title; |
1349 $title = $post->post_title; |
1261 |
1350 |
1262 if ( empty($post->post_title) ) |
1351 if ( empty($post->post_title) ) |
1263 $title = $previous ? __('Previous Post') : __('Next Post'); |
1352 $title = $previous ? __('Previous Post') : __('Next Post'); |
1264 |
1353 |
1265 $title = apply_filters('the_title', $title, $post); |
1354 $title = apply_filters('the_title', $title, $post->ID); |
1266 $date = mysql2date(get_option('date_format'), $post->post_date); |
1355 $date = mysql2date(get_option('date_format'), $post->post_date); |
1267 $rel = $previous ? 'prev' : 'next'; |
1356 $rel = $previous ? 'prev' : 'next'; |
1268 |
1357 |
1269 $string = '<a href="'.get_permalink($post).'" rel="'.$rel.'">'; |
1358 $string = '<a href="'.get_permalink($post).'" rel="'.$rel.'">'; |
1270 $link = str_replace('%title', $title, $link); |
1359 $link = str_replace('%title', $title, $link); |
1276 $adjacent = $previous ? 'previous' : 'next'; |
1365 $adjacent = $previous ? 'previous' : 'next'; |
1277 echo apply_filters( "{$adjacent}_post_link", $format, $link ); |
1366 echo apply_filters( "{$adjacent}_post_link", $format, $link ); |
1278 } |
1367 } |
1279 |
1368 |
1280 /** |
1369 /** |
1281 * Retrieve get links for page numbers. |
1370 * Retrieve links for page numbers. |
1282 * |
1371 * |
1283 * @since 1.5.0 |
1372 * @since 1.5.0 |
1284 * |
1373 * |
1285 * @param int $pagenum Optional. Page ID. |
1374 * @param int $pagenum Optional. Page ID. |
1286 * @return string |
1375 * @param bool $escape Optional. Whether to escape the URL for display, with esc_url(). Defaults to true. |
1287 */ |
1376 * Otherwise, prepares the URL with esc_url_raw(). |
1288 function get_pagenum_link($pagenum = 1) { |
1377 * @return string |
1378 */ |
|
1379 function get_pagenum_link($pagenum = 1, $escape = true ) { |
|
1289 global $wp_rewrite; |
1380 global $wp_rewrite; |
1290 |
1381 |
1291 $pagenum = (int) $pagenum; |
1382 $pagenum = (int) $pagenum; |
1292 |
1383 |
1293 $request = remove_query_arg( 'paged' ); |
1384 $request = remove_query_arg( 'paged' ); |
1294 |
1385 |
1295 $home_root = parse_url(get_option('home')); |
1386 $home_root = parse_url(home_url()); |
1296 $home_root = ( isset($home_root['path']) ) ? $home_root['path'] : ''; |
1387 $home_root = ( isset($home_root['path']) ) ? $home_root['path'] : ''; |
1297 $home_root = preg_quote( trailingslashit( $home_root ), '|' ); |
1388 $home_root = preg_quote( trailingslashit( $home_root ), '|' ); |
1298 |
1389 |
1299 $request = preg_replace('|^'. $home_root . '|', '', $request); |
1390 $request = preg_replace('|^'. $home_root . '|', '', $request); |
1300 $request = preg_replace('|^/+|', '', $request); |
1391 $request = preg_replace('|^/+|', '', $request); |
1301 |
1392 |
1302 if ( !$wp_rewrite->using_permalinks() || is_admin() ) { |
1393 if ( !$wp_rewrite->using_permalinks() || is_admin() ) { |
1303 $base = trailingslashit( get_bloginfo( 'home' ) ); |
1394 $base = trailingslashit( get_bloginfo( 'url' ) ); |
1304 |
1395 |
1305 if ( $pagenum > 1 ) { |
1396 if ( $pagenum > 1 ) { |
1306 $result = add_query_arg( 'paged', $pagenum, $base . $request ); |
1397 $result = add_query_arg( 'paged', $pagenum, $base . $request ); |
1307 } else { |
1398 } else { |
1308 $result = $base . $request; |
1399 $result = $base . $request; |
1316 $request = preg_replace( $qs_regex, '', $request ); |
1407 $request = preg_replace( $qs_regex, '', $request ); |
1317 } else { |
1408 } else { |
1318 $query_string = ''; |
1409 $query_string = ''; |
1319 } |
1410 } |
1320 |
1411 |
1321 $request = preg_replace( '|page/\d+/?$|', '', $request); |
1412 $request = preg_replace( "|$wp_rewrite->pagination_base/\d+/?$|", '', $request); |
1322 $request = preg_replace( '|^index\.php|', '', $request); |
1413 $request = preg_replace( '|^index\.php|', '', $request); |
1323 $request = ltrim($request, '/'); |
1414 $request = ltrim($request, '/'); |
1324 |
1415 |
1325 $base = trailingslashit( get_bloginfo( 'url' ) ); |
1416 $base = trailingslashit( get_bloginfo( 'url' ) ); |
1326 |
1417 |
1327 if ( $wp_rewrite->using_index_permalinks() && ( $pagenum > 1 || '' != $request ) ) |
1418 if ( $wp_rewrite->using_index_permalinks() && ( $pagenum > 1 || '' != $request ) ) |
1328 $base .= 'index.php/'; |
1419 $base .= 'index.php/'; |
1329 |
1420 |
1330 if ( $pagenum > 1 ) { |
1421 if ( $pagenum > 1 ) { |
1331 $request = ( ( !empty( $request ) ) ? trailingslashit( $request ) : $request ) . user_trailingslashit( 'page/' . $pagenum, 'paged' ); |
1422 $request = ( ( !empty( $request ) ) ? trailingslashit( $request ) : $request ) . user_trailingslashit( $wp_rewrite->pagination_base . "/" . $pagenum, 'paged' ); |
1332 } |
1423 } |
1333 |
1424 |
1334 $result = $base . $request . $query_string; |
1425 $result = $base . $request . $query_string; |
1335 } |
1426 } |
1336 |
1427 |
1337 $result = apply_filters('get_pagenum_link', $result); |
1428 $result = apply_filters('get_pagenum_link', $result); |
1338 |
1429 |
1339 return $result; |
1430 if ( $escape ) |
1340 } |
1431 return esc_url( $result ); |
1341 |
1432 else |
1342 /** |
1433 return esc_url_raw( $result ); |
1343 * Retrieve next posts pages link. |
1434 } |
1435 |
|
1436 /** |
|
1437 * Retrieve next posts page link. |
|
1344 * |
1438 * |
1345 * Backported from 2.1.3 to 2.0.10. |
1439 * Backported from 2.1.3 to 2.0.10. |
1346 * |
1440 * |
1347 * @since 2.0.10 |
1441 * @since 2.0.10 |
1348 * |
1442 * |
1360 return get_pagenum_link($nextpage); |
1454 return get_pagenum_link($nextpage); |
1361 } |
1455 } |
1362 } |
1456 } |
1363 |
1457 |
1364 /** |
1458 /** |
1365 * Display or return the next posts pages link. |
1459 * Display or return the next posts page link. |
1366 * |
1460 * |
1367 * @since 0.71 |
1461 * @since 0.71 |
1368 * |
1462 * |
1369 * @param int $max_page Optional. Max pages. |
1463 * @param int $max_page Optional. Max pages. |
1370 * @param boolean $echo Optional. Echo or return; |
1464 * @param boolean $echo Optional. Echo or return; |
1377 else |
1471 else |
1378 return $output; |
1472 return $output; |
1379 } |
1473 } |
1380 |
1474 |
1381 /** |
1475 /** |
1382 * Return the next posts pages link. |
1476 * Return the next posts page link. |
1383 * |
1477 * |
1384 * @since 2.7.0 |
1478 * @since 2.7.0 |
1385 * |
1479 * |
1386 * @param string $label Content for link text. |
1480 * @param string $label Content for link text. |
1387 * @param int $max_page Optional. Max pages. |
1481 * @param int $max_page Optional. Max pages. |
1388 * @return string|null |
1482 * @return string|null |
1389 */ |
1483 */ |
1390 function get_next_posts_link( $label = 'Next Page »', $max_page = 0 ) { |
1484 function get_next_posts_link( $label = null, $max_page = 0 ) { |
1391 global $paged, $wp_query; |
1485 global $paged, $wp_query; |
1392 |
1486 |
1393 if ( !$max_page ) { |
1487 if ( !$max_page ) |
1394 $max_page = $wp_query->max_num_pages; |
1488 $max_page = $wp_query->max_num_pages; |
1395 } |
|
1396 |
1489 |
1397 if ( !$paged ) |
1490 if ( !$paged ) |
1398 $paged = 1; |
1491 $paged = 1; |
1399 |
1492 |
1400 $nextpage = intval($paged) + 1; |
1493 $nextpage = intval($paged) + 1; |
1401 |
1494 |
1402 if ( !is_single() && ( empty($paged) || $nextpage <= $max_page) ) { |
1495 if ( null === $label ) |
1496 $label = __( 'Next Page »' ); |
|
1497 |
|
1498 if ( !is_single() && ( $nextpage <= $max_page ) ) { |
|
1403 $attr = apply_filters( 'next_posts_link_attributes', '' ); |
1499 $attr = apply_filters( 'next_posts_link_attributes', '' ); |
1404 return '<a href="' . next_posts( $max_page, false ) . "\" $attr>". preg_replace('/&([^#])(?![a-z]{1,8};)/', '&$1', $label) .'</a>'; |
1500 return '<a href="' . next_posts( $max_page, false ) . "\" $attr>" . preg_replace('/&([^#])(?![a-z]{1,8};)/i', '&$1', $label) . '</a>'; |
1405 } |
1501 } |
1406 } |
1502 } |
1407 |
1503 |
1408 /** |
1504 /** |
1409 * Display the next posts pages link. |
1505 * Display the next posts page link. |
1410 * |
1506 * |
1411 * @since 0.71 |
1507 * @since 0.71 |
1412 * @uses get_next_posts_link() |
1508 * @uses get_next_posts_link() |
1413 * |
1509 * |
1414 * @param string $label Content for link text. |
1510 * @param string $label Content for link text. |
1415 * @param int $max_page Optional. Max pages. |
1511 * @param int $max_page Optional. Max pages. |
1416 */ |
1512 */ |
1417 function next_posts_link( $label = 'Next Page »', $max_page = 0 ) { |
1513 function next_posts_link( $label = null, $max_page = 0 ) { |
1418 echo get_next_posts_link( $label, $max_page ); |
1514 echo get_next_posts_link( $label, $max_page ); |
1419 } |
1515 } |
1420 |
1516 |
1421 /** |
1517 /** |
1422 * Retrieve previous post pages link. |
1518 * Retrieve previous posts page link. |
1423 * |
1519 * |
1424 * Will only return string, if not on a single page or post. |
1520 * Will only return string, if not on a single page or post. |
1425 * |
1521 * |
1426 * Backported to 2.0.10 from 2.1.3. |
1522 * Backported to 2.0.10 from 2.1.3. |
1427 * |
1523 * |
1439 return get_pagenum_link($nextpage); |
1535 return get_pagenum_link($nextpage); |
1440 } |
1536 } |
1441 } |
1537 } |
1442 |
1538 |
1443 /** |
1539 /** |
1444 * Display or return the previous posts pages link. |
1540 * Display or return the previous posts page link. |
1445 * |
1541 * |
1446 * @since 0.71 |
1542 * @since 0.71 |
1447 * |
1543 * |
1448 * @param boolean $echo Optional. Echo or return; |
1544 * @param boolean $echo Optional. Echo or return; |
1449 */ |
1545 */ |
1455 else |
1551 else |
1456 return $output; |
1552 return $output; |
1457 } |
1553 } |
1458 |
1554 |
1459 /** |
1555 /** |
1460 * Return the previous posts pages link. |
1556 * Return the previous posts page link. |
1461 * |
1557 * |
1462 * @since 2.7.0 |
1558 * @since 2.7.0 |
1463 * |
1559 * |
1464 * @param string $label Optional. Previous page link text. |
1560 * @param string $label Optional. Previous page link text. |
1465 * @return string|null |
1561 * @return string|null |
1466 */ |
1562 */ |
1467 function get_previous_posts_link( $label = '« Previous Page' ) { |
1563 function get_previous_posts_link( $label = null ) { |
1468 global $paged; |
1564 global $paged; |
1565 |
|
1566 if ( null === $label ) |
|
1567 $label = __( '« Previous Page' ); |
|
1469 |
1568 |
1470 if ( !is_single() && $paged > 1 ) { |
1569 if ( !is_single() && $paged > 1 ) { |
1471 $attr = apply_filters( 'previous_posts_link_attributes', '' ); |
1570 $attr = apply_filters( 'previous_posts_link_attributes', '' ); |
1472 return '<a href="' . previous_posts( false ) . "\" $attr>". preg_replace( '/&([^#])(?![a-z]{1,8};)/', '&$1', $label ) .'</a>'; |
1571 return '<a href="' . previous_posts( false ) . "\" $attr>". preg_replace( '/&([^#])(?![a-z]{1,8};)/i', '&$1', $label ) .'</a>'; |
1473 } |
1572 } |
1474 } |
1573 } |
1475 |
1574 |
1476 /** |
1575 /** |
1477 * Display the previous posts page link. |
1576 * Display the previous posts page link. |
1479 * @since 0.71 |
1578 * @since 0.71 |
1480 * @uses get_previous_posts_link() |
1579 * @uses get_previous_posts_link() |
1481 * |
1580 * |
1482 * @param string $label Optional. Previous page link text. |
1581 * @param string $label Optional. Previous page link text. |
1483 */ |
1582 */ |
1484 function previous_posts_link( $label = '« Previous Page' ) { |
1583 function previous_posts_link( $label = null ) { |
1485 echo get_previous_posts_link( $label ); |
1584 echo get_previous_posts_link( $label ); |
1486 } |
1585 } |
1487 |
1586 |
1488 /** |
1587 /** |
1489 * Return post pages link navigation for previous and next pages. |
1588 * Return post pages link navigation for previous and next pages. |
1514 $args['sep'] = ''; |
1613 $args['sep'] = ''; |
1515 } |
1614 } |
1516 |
1615 |
1517 if ( $max_num_pages > 1 ) { |
1616 if ( $max_num_pages > 1 ) { |
1518 $return = get_previous_posts_link($args['prelabel']); |
1617 $return = get_previous_posts_link($args['prelabel']); |
1519 $return .= preg_replace('/&([^#])(?![a-z]{1,8};)/', '&$1', $args['sep']); |
1618 $return .= preg_replace('/&([^#])(?![a-z]{1,8};)/i', '&$1', $args['sep']); |
1520 $return .= get_next_posts_link($args['nxtlabel']); |
1619 $return .= get_next_posts_link($args['nxtlabel']); |
1521 } |
1620 } |
1522 } |
1621 } |
1523 return $return; |
1622 return $return; |
1524 |
1623 |
1537 $args = array_filter( compact('sep', 'prelabel', 'nxtlabel') ); |
1636 $args = array_filter( compact('sep', 'prelabel', 'nxtlabel') ); |
1538 echo get_posts_nav_link($args); |
1637 echo get_posts_nav_link($args); |
1539 } |
1638 } |
1540 |
1639 |
1541 /** |
1640 /** |
1542 * Retrieve page numbers links. |
1641 * Retrieve comments page number link. |
1543 * |
1642 * |
1544 * @since 2.7.0 |
1643 * @since 2.7.0 |
1545 * |
1644 * |
1546 * @param int $pagenum Optional. Page number. |
1645 * @param int $pagenum Optional. Page number. |
1547 * @return string |
1646 * @return string |
1573 |
1672 |
1574 return $result; |
1673 return $result; |
1575 } |
1674 } |
1576 |
1675 |
1577 /** |
1676 /** |
1578 * Return the link to next comments pages. |
1677 * Return the link to next comments page. |
1579 * |
1678 * |
1580 * @since 2.7.1 |
1679 * @since 2.7.1 |
1581 * |
1680 * |
1582 * @param string $label Optional. Label for link text. |
1681 * @param string $label Optional. Label for link text. |
1583 * @param int $max_page Optional. Max page. |
1682 * @param int $max_page Optional. Max page. |
1603 return; |
1702 return; |
1604 |
1703 |
1605 if ( empty($label) ) |
1704 if ( empty($label) ) |
1606 $label = __('Newer Comments »'); |
1705 $label = __('Newer Comments »'); |
1607 |
1706 |
1608 return '<a href="' . esc_url( get_comments_pagenum_link( $nextpage, $max_page ) ) . '" ' . apply_filters( 'next_comments_link_attributes', '' ) . '>'. preg_replace('/&([^#])(?![a-z]{1,8};)/', '&$1', $label) .'</a>'; |
1707 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>'; |
1609 } |
1708 } |
1610 |
1709 |
1611 /** |
1710 /** |
1612 * Display the link to next comments pages. |
1711 * Display the link to next comments page. |
1613 * |
1712 * |
1614 * @since 2.7.0 |
1713 * @since 2.7.0 |
1615 * |
1714 * |
1616 * @param string $label Optional. Label for link text. |
1715 * @param string $label Optional. Label for link text. |
1617 * @param int $max_page Optional. Max page. |
1716 * @param int $max_page Optional. Max page. |
1640 $prevpage = intval($page) - 1; |
1739 $prevpage = intval($page) - 1; |
1641 |
1740 |
1642 if ( empty($label) ) |
1741 if ( empty($label) ) |
1643 $label = __('« Older Comments'); |
1742 $label = __('« Older Comments'); |
1644 |
1743 |
1645 return '<a href="' . esc_url( get_comments_pagenum_link( $prevpage ) ) . '" ' . apply_filters( 'previous_comments_link_attributes', '' ) . '>' . preg_replace('/&([^#])(?![a-z]{1,8};)/', '&$1', $label) .'</a>'; |
1744 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>'; |
1646 } |
1745 } |
1647 |
1746 |
1648 /** |
1747 /** |
1649 * Display the previous comments page link. |
1748 * Display the previous comments page link. |
1650 * |
1749 * |
1660 * Create pagination links for the comments on the current post. |
1759 * Create pagination links for the comments on the current post. |
1661 * |
1760 * |
1662 * @see paginate_links() |
1761 * @see paginate_links() |
1663 * @since 2.7.0 |
1762 * @since 2.7.0 |
1664 * |
1763 * |
1665 * @param string|array $args Optional args. See paginate_links. |
1764 * @param string|array $args Optional args. See paginate_links(). |
1666 * @return string Markup for pagination links. |
1765 * @return string Markup for pagination links. |
1667 */ |
1766 */ |
1668 function paginate_comments_links($args = array()) { |
1767 function paginate_comments_links($args = array()) { |
1669 global $wp_query, $wp_rewrite; |
1768 global $wp_rewrite; |
1670 |
1769 |
1671 if ( !is_singular() || !get_option('page_comments') ) |
1770 if ( !is_singular() || !get_option('page_comments') ) |
1672 return; |
1771 return; |
1673 |
1772 |
1674 $page = get_query_var('cpage'); |
1773 $page = get_query_var('cpage'); |
1694 else |
1793 else |
1695 return $page_links; |
1794 return $page_links; |
1696 } |
1795 } |
1697 |
1796 |
1698 /** |
1797 /** |
1699 * Retrieve shortcut link. |
1798 * Retrieve the Press This bookmarklet link. |
1700 * |
1799 * |
1701 * Use this in 'a' element 'href' attribute. |
1800 * Use this in 'a' element 'href' attribute. |
1702 * |
1801 * |
1703 * @since 2.6.0 |
1802 * @since 2.6.0 |
1704 * |
1803 * |
1705 * @return string |
1804 * @return string |
1706 */ |
1805 */ |
1707 function get_shortcut_link() { |
1806 function get_shortcut_link() { |
1807 // In case of breaking changes, version this. #WP20071 |
|
1708 $link = "javascript: |
1808 $link = "javascript: |
1709 var d=document, |
1809 var d=document, |
1710 w=window, |
1810 w=window, |
1711 e=w.getSelection, |
1811 e=w.getSelection, |
1712 k=d.getSelection, |
1812 k=d.getSelection, |
1724 |
1824 |
1725 return apply_filters('shortcut_link', $link); |
1825 return apply_filters('shortcut_link', $link); |
1726 } |
1826 } |
1727 |
1827 |
1728 /** |
1828 /** |
1729 * Retrieve the site url. |
1829 * Retrieve the home url for the current site. |
1730 * |
1830 * |
1731 * Returns the 'site_url' option with the appropriate protocol, 'https' if |
1831 * Returns the 'home' option with the appropriate protocol, 'https' if |
1732 * is_ssl() and 'http' otherwise. If $scheme is 'http' or 'https', is_ssl() is |
1832 * is_ssl() and 'http' otherwise. If $scheme is 'http' or 'https', is_ssl() is |
1733 * overridden. |
1833 * overridden. |
1734 * |
1834 * |
1735 * @package WordPress |
1835 * @package WordPress |
1836 * @since 3.0.0 |
|
1837 * |
|
1838 * @uses get_home_url() |
|
1839 * |
|
1840 * @param string $path (optional) Path relative to the home url. |
|
1841 * @param string $scheme (optional) Scheme to give the home url context. Currently 'http', 'https', or 'relative'. |
|
1842 * @return string Home url link with optional path appended. |
|
1843 */ |
|
1844 function home_url( $path = '', $scheme = null ) { |
|
1845 return get_home_url(null, $path, $scheme); |
|
1846 } |
|
1847 |
|
1848 /** |
|
1849 * Retrieve the home url for a given site. |
|
1850 * |
|
1851 * Returns the 'home' option with the appropriate protocol, 'https' if |
|
1852 * is_ssl() and 'http' otherwise. If $scheme is 'http' or 'https', is_ssl() is |
|
1853 * overridden. |
|
1854 * |
|
1855 * @package WordPress |
|
1856 * @since 3.0.0 |
|
1857 * |
|
1858 * @param int $blog_id (optional) Blog ID. Defaults to current blog. |
|
1859 * @param string $path (optional) Path relative to the home url. |
|
1860 * @param string $scheme (optional) Scheme to give the home url context. Currently 'http', 'https', or 'relative'. |
|
1861 * @return string Home url link with optional path appended. |
|
1862 */ |
|
1863 function get_home_url( $blog_id = null, $path = '', $scheme = null ) { |
|
1864 $orig_scheme = $scheme; |
|
1865 |
|
1866 if ( !in_array( $scheme, array( 'http', 'https', 'relative' ) ) ) |
|
1867 $scheme = is_ssl() && !is_admin() ? 'https' : 'http'; |
|
1868 |
|
1869 if ( empty( $blog_id ) || !is_multisite() ) |
|
1870 $url = get_option( 'home' ); |
|
1871 else |
|
1872 $url = get_blog_option( $blog_id, 'home' ); |
|
1873 |
|
1874 if ( 'relative' == $scheme ) |
|
1875 $url = preg_replace( '#^.+://[^/]*#', '', $url ); |
|
1876 elseif ( 'http' != $scheme ) |
|
1877 $url = str_replace( 'http://', "$scheme://", $url ); |
|
1878 |
|
1879 if ( !empty( $path ) && is_string( $path ) && strpos( $path, '..' ) === false ) |
|
1880 $url .= '/' . ltrim( $path, '/' ); |
|
1881 |
|
1882 return apply_filters( 'home_url', $url, $path, $orig_scheme, $blog_id ); |
|
1883 } |
|
1884 |
|
1885 /** |
|
1886 * Retrieve the site url for the current site. |
|
1887 * |
|
1888 * Returns the 'site_url' option with the appropriate protocol, 'https' if |
|
1889 * is_ssl() and 'http' otherwise. If $scheme is 'http' or 'https', is_ssl() is |
|
1890 * overridden. |
|
1891 * |
|
1892 * @package WordPress |
|
1736 * @since 2.6.0 |
1893 * @since 2.6.0 |
1737 * |
1894 * |
1895 * @uses get_site_url() |
|
1896 * |
|
1738 * @param string $path Optional. Path relative to the site url. |
1897 * @param string $path Optional. Path relative to the site url. |
1739 * @param string $scheme Optional. Scheme to give the site url context. Currently 'http','https', 'login', 'login_post', or 'admin'. |
1898 * @param string $scheme Optional. Scheme to give the site url context. Currently 'http', 'https', 'login', 'login_post', 'admin', or 'relative'. |
1740 * @return string Site url link with optional path appended. |
1899 * @return string Site url link with optional path appended. |
1741 */ |
1900 */ |
1742 function site_url($path = '', $scheme = null) { |
1901 function site_url( $path = '', $scheme = null ) { |
1902 return get_site_url(null, $path, $scheme); |
|
1903 } |
|
1904 |
|
1905 /** |
|
1906 * Retrieve the site url for a given site. |
|
1907 * |
|
1908 * Returns the 'site_url' option with the appropriate protocol, 'https' if |
|
1909 * is_ssl() and 'http' otherwise. If $scheme is 'http' or 'https', is_ssl() is |
|
1910 * overridden. |
|
1911 * |
|
1912 * @package WordPress |
|
1913 * @since 3.0.0 |
|
1914 * |
|
1915 * @param int $blog_id (optional) Blog ID. Defaults to current blog. |
|
1916 * @param string $path Optional. Path relative to the site url. |
|
1917 * @param string $scheme Optional. Scheme to give the site url context. Currently 'http', 'https', 'login', 'login_post', 'admin', or 'relative'. |
|
1918 * @return string Site url link with optional path appended. |
|
1919 */ |
|
1920 function get_site_url( $blog_id = null, $path = '', $scheme = null ) { |
|
1743 // should the list of allowed schemes be maintained elsewhere? |
1921 // should the list of allowed schemes be maintained elsewhere? |
1744 $orig_scheme = $scheme; |
1922 $orig_scheme = $scheme; |
1745 if ( !in_array($scheme, array('http', 'https')) ) { |
1923 if ( !in_array( $scheme, array( 'http', 'https', 'relative' ) ) ) { |
1924 if ( ( 'login_post' == $scheme || 'rpc' == $scheme ) && ( force_ssl_login() || force_ssl_admin() ) ) |
|
1925 $scheme = 'https'; |
|
1926 elseif ( ( 'login' == $scheme ) && force_ssl_admin() ) |
|
1927 $scheme = 'https'; |
|
1928 elseif ( ( 'admin' == $scheme ) && force_ssl_admin() ) |
|
1929 $scheme = 'https'; |
|
1930 else |
|
1931 $scheme = ( is_ssl() ? 'https' : 'http' ); |
|
1932 } |
|
1933 |
|
1934 if ( empty( $blog_id ) || !is_multisite() ) |
|
1935 $url = get_option( 'siteurl' ); |
|
1936 else |
|
1937 $url = get_blog_option( $blog_id, 'siteurl' ); |
|
1938 |
|
1939 if ( 'relative' == $scheme ) |
|
1940 $url = preg_replace( '#^.+://[^/]*#', '', $url ); |
|
1941 elseif ( 'http' != $scheme ) |
|
1942 $url = str_replace( 'http://', "{$scheme}://", $url ); |
|
1943 |
|
1944 if ( !empty( $path ) && is_string( $path ) && strpos( $path, '..' ) === false ) |
|
1945 $url .= '/' . ltrim( $path, '/' ); |
|
1946 |
|
1947 return apply_filters( 'site_url', $url, $path, $orig_scheme, $blog_id ); |
|
1948 } |
|
1949 |
|
1950 /** |
|
1951 * Retrieve the url to the admin area for the current site. |
|
1952 * |
|
1953 * @package WordPress |
|
1954 * @since 2.6.0 |
|
1955 * |
|
1956 * @param string $path Optional path relative to the admin url. |
|
1957 * @param string $scheme The scheme to use. Default is 'admin', which obeys force_ssl_admin() and is_ssl(). 'http' or 'https' can be passed to force those schemes. |
|
1958 * @return string Admin url link with optional path appended. |
|
1959 */ |
|
1960 function admin_url( $path = '', $scheme = 'admin' ) { |
|
1961 return get_admin_url(null, $path, $scheme); |
|
1962 } |
|
1963 |
|
1964 /** |
|
1965 * Retrieve the url to the admin area for a given site. |
|
1966 * |
|
1967 * @package WordPress |
|
1968 * @since 3.0.0 |
|
1969 * |
|
1970 * @param int $blog_id (optional) Blog ID. Defaults to current blog. |
|
1971 * @param string $path Optional path relative to the admin url. |
|
1972 * @param string $scheme The scheme to use. Default is 'admin', which obeys force_ssl_admin() and is_ssl(). 'http' or 'https' can be passed to force those schemes. |
|
1973 * @return string Admin url link with optional path appended. |
|
1974 */ |
|
1975 function get_admin_url( $blog_id = null, $path = '', $scheme = 'admin' ) { |
|
1976 $url = get_site_url($blog_id, 'wp-admin/', $scheme); |
|
1977 |
|
1978 if ( !empty($path) && is_string($path) && strpos($path, '..') === false ) |
|
1979 $url .= ltrim($path, '/'); |
|
1980 |
|
1981 return apply_filters('admin_url', $url, $path, $blog_id); |
|
1982 } |
|
1983 |
|
1984 /** |
|
1985 * Retrieve the url to the includes directory. |
|
1986 * |
|
1987 * @package WordPress |
|
1988 * @since 2.6.0 |
|
1989 * |
|
1990 * @param string $path Optional. Path relative to the includes url. |
|
1991 * @return string Includes url link with optional path appended. |
|
1992 */ |
|
1993 function includes_url($path = '') { |
|
1994 $url = site_url() . '/' . WPINC . '/'; |
|
1995 |
|
1996 if ( !empty($path) && is_string($path) && strpos($path, '..') === false ) |
|
1997 $url .= ltrim($path, '/'); |
|
1998 |
|
1999 return apply_filters('includes_url', $url, $path); |
|
2000 } |
|
2001 |
|
2002 /** |
|
2003 * Retrieve the url to the content directory. |
|
2004 * |
|
2005 * @package WordPress |
|
2006 * @since 2.6.0 |
|
2007 * |
|
2008 * @param string $path Optional. Path relative to the content url. |
|
2009 * @return string Content url link with optional path appended. |
|
2010 */ |
|
2011 function content_url($path = '') { |
|
2012 $url = WP_CONTENT_URL; |
|
2013 if ( 0 === strpos($url, 'http') && is_ssl() ) |
|
2014 $url = str_replace( 'http://', 'https://', $url ); |
|
2015 |
|
2016 if ( !empty($path) && is_string($path) && strpos($path, '..') === false ) |
|
2017 $url .= '/' . ltrim($path, '/'); |
|
2018 |
|
2019 return apply_filters('content_url', $url, $path); |
|
2020 } |
|
2021 |
|
2022 /** |
|
2023 * Retrieve the url to the plugins directory or to a specific file within that directory. |
|
2024 * You can hardcode the plugin slug in $path or pass __FILE__ as a second argument to get the correct folder name. |
|
2025 * |
|
2026 * @package WordPress |
|
2027 * @since 2.6.0 |
|
2028 * |
|
2029 * @param string $path Optional. Path relative to the plugins url. |
|
2030 * @param string $plugin Optional. The plugin file that you want to be relative to - i.e. pass in __FILE__ |
|
2031 * @return string Plugins url link with optional path appended. |
|
2032 */ |
|
2033 function plugins_url($path = '', $plugin = '') { |
|
2034 |
|
2035 $mu_plugin_dir = WPMU_PLUGIN_DIR; |
|
2036 foreach ( array('path', 'plugin', 'mu_plugin_dir') as $var ) { |
|
2037 $$var = str_replace('\\' ,'/', $$var); // sanitize for Win32 installs |
|
2038 $$var = preg_replace('|/+|', '/', $$var); |
|
2039 } |
|
2040 |
|
2041 if ( !empty($plugin) && 0 === strpos($plugin, $mu_plugin_dir) ) |
|
2042 $url = WPMU_PLUGIN_URL; |
|
2043 else |
|
2044 $url = WP_PLUGIN_URL; |
|
2045 |
|
2046 if ( 0 === strpos($url, 'http') && is_ssl() ) |
|
2047 $url = str_replace( 'http://', 'https://', $url ); |
|
2048 |
|
2049 if ( !empty($plugin) && is_string($plugin) ) { |
|
2050 $folder = dirname(plugin_basename($plugin)); |
|
2051 if ( '.' != $folder ) |
|
2052 $url .= '/' . ltrim($folder, '/'); |
|
2053 } |
|
2054 |
|
2055 if ( !empty($path) && is_string($path) && strpos($path, '..') === false ) |
|
2056 $url .= '/' . ltrim($path, '/'); |
|
2057 |
|
2058 return apply_filters('plugins_url', $url, $path, $plugin); |
|
2059 } |
|
2060 |
|
2061 /** |
|
2062 * Retrieve the site url for the current network. |
|
2063 * |
|
2064 * Returns the site url with the appropriate protocol, 'https' if |
|
2065 * is_ssl() and 'http' otherwise. If $scheme is 'http' or 'https', is_ssl() is |
|
2066 * overridden. |
|
2067 * |
|
2068 * @package WordPress |
|
2069 * @since 3.0.0 |
|
2070 * |
|
2071 * @param string $path Optional. Path relative to the site url. |
|
2072 * @param string $scheme Optional. Scheme to give the site url context. Currently 'http', 'https', 'login', 'login_post', 'admin', or 'relative'. |
|
2073 * @return string Site url link with optional path appended. |
|
2074 */ |
|
2075 function network_site_url( $path = '', $scheme = null ) { |
|
2076 global $current_site; |
|
2077 |
|
2078 if ( !is_multisite() ) |
|
2079 return site_url($path, $scheme); |
|
2080 |
|
2081 $orig_scheme = $scheme; |
|
2082 if ( !in_array( $scheme, array( 'http', 'https', 'relative' ) ) ) { |
|
1746 if ( ( 'login_post' == $scheme || 'rpc' == $scheme ) && ( force_ssl_login() || force_ssl_admin() ) ) |
2083 if ( ( 'login_post' == $scheme || 'rpc' == $scheme ) && ( force_ssl_login() || force_ssl_admin() ) ) |
1747 $scheme = 'https'; |
2084 $scheme = 'https'; |
1748 elseif ( ('login' == $scheme) && ( force_ssl_admin() ) ) |
2085 elseif ( ('login' == $scheme) && ( force_ssl_admin() ) ) |
1749 $scheme = 'https'; |
2086 $scheme = 'https'; |
1750 elseif ( ('admin' == $scheme) && force_ssl_admin() ) |
2087 elseif ( ('admin' == $scheme) && force_ssl_admin() ) |
1751 $scheme = 'https'; |
2088 $scheme = 'https'; |
1752 else |
2089 else |
1753 $scheme = ( is_ssl() ? 'https' : 'http' ); |
2090 $scheme = ( is_ssl() ? 'https' : 'http' ); |
1754 } |
2091 } |
1755 |
2092 |
1756 $url = str_replace( 'http://', "{$scheme}://", get_option('siteurl') ); |
2093 if ( 'relative' == $scheme ) |
1757 |
2094 $url = $current_site->path; |
1758 if ( !empty($path) && is_string($path) && strpos($path, '..') === false ) |
2095 else |
1759 $url .= '/' . ltrim($path, '/'); |
2096 $url = $scheme . '://' . $current_site->domain . $current_site->path; |
1760 |
|
1761 return apply_filters('site_url', $url, $path, $orig_scheme); |
|
1762 } |
|
1763 |
|
1764 /** |
|
1765 * Retrieve the url to the admin area. |
|
1766 * |
|
1767 * @package WordPress |
|
1768 * @since 2.6.0 |
|
1769 * |
|
1770 * @param string $path Optional path relative to the admin url |
|
1771 * @return string Admin url link with optional path appended |
|
1772 */ |
|
1773 function admin_url($path = '') { |
|
1774 $url = site_url('wp-admin/', 'admin'); |
|
1775 |
2097 |
1776 if ( !empty($path) && is_string($path) && strpos($path, '..') === false ) |
2098 if ( !empty($path) && is_string($path) && strpos($path, '..') === false ) |
1777 $url .= ltrim($path, '/'); |
2099 $url .= ltrim($path, '/'); |
1778 |
2100 |
1779 return apply_filters('admin_url', $url, $path); |
2101 return apply_filters('network_site_url', $url, $path, $orig_scheme); |
1780 } |
2102 } |
1781 |
2103 |
1782 /** |
2104 /** |
1783 * Retrieve the url to the includes directory. |
2105 * Retrieve the home url for the current network. |
2106 * |
|
2107 * Returns the home url with the appropriate protocol, 'https' if |
|
2108 * is_ssl() and 'http' otherwise. If $scheme is 'http' or 'https', is_ssl() is |
|
2109 * overridden. |
|
1784 * |
2110 * |
1785 * @package WordPress |
2111 * @package WordPress |
1786 * @since 2.6.0 |
2112 * @since 3.0.0 |
1787 * |
2113 * |
1788 * @param string $path Optional. Path relative to the includes url. |
2114 * @param string $path (optional) Path relative to the home url. |
1789 * @return string Includes url link with optional path appended. |
2115 * @param string $scheme (optional) Scheme to give the home url context. Currently 'http', 'https', or 'relative'. |
2116 * @return string Home url link with optional path appended. |
|
1790 */ |
2117 */ |
1791 function includes_url($path = '') { |
2118 function network_home_url( $path = '', $scheme = null ) { |
1792 $url = site_url() . '/' . WPINC . '/'; |
2119 global $current_site; |
2120 |
|
2121 if ( !is_multisite() ) |
|
2122 return home_url($path, $scheme); |
|
2123 |
|
2124 $orig_scheme = $scheme; |
|
2125 |
|
2126 if ( !in_array( $scheme, array( 'http', 'https', 'relative' ) ) ) |
|
2127 $scheme = is_ssl() && !is_admin() ? 'https' : 'http'; |
|
2128 |
|
2129 if ( 'relative' == $scheme ) |
|
2130 $url = $current_site->path; |
|
2131 else |
|
2132 $url = $scheme . '://' . $current_site->domain . $current_site->path; |
|
2133 |
|
2134 if ( !empty( $path ) && is_string( $path ) && strpos( $path, '..' ) === false ) |
|
2135 $url .= ltrim( $path, '/' ); |
|
2136 |
|
2137 return apply_filters( 'network_home_url', $url, $path, $orig_scheme); |
|
2138 } |
|
2139 |
|
2140 /** |
|
2141 * Retrieve the url to the admin area for the network. |
|
2142 * |
|
2143 * @package WordPress |
|
2144 * @since 3.0.0 |
|
2145 * |
|
2146 * @param string $path Optional path relative to the admin url. |
|
2147 * @param string $scheme The scheme to use. Default is 'admin', which obeys force_ssl_admin() and is_ssl(). 'http' or 'https' can be passed to force those schemes. |
|
2148 * @return string Admin url link with optional path appended. |
|
2149 */ |
|
2150 function network_admin_url( $path = '', $scheme = 'admin' ) { |
|
2151 if ( ! is_multisite() ) |
|
2152 return admin_url( $path, $scheme ); |
|
2153 |
|
2154 $url = network_site_url('wp-admin/network/', $scheme); |
|
1793 |
2155 |
1794 if ( !empty($path) && is_string($path) && strpos($path, '..') === false ) |
2156 if ( !empty($path) && is_string($path) && strpos($path, '..') === false ) |
1795 $url .= ltrim($path, '/'); |
2157 $url .= ltrim($path, '/'); |
1796 |
2158 |
1797 return apply_filters('includes_url', $url, $path); |
2159 return apply_filters('network_admin_url', $url, $path); |
1798 } |
2160 } |
1799 |
2161 |
1800 /** |
2162 /** |
1801 * Retrieve the url to the content directory. |
2163 * Retrieve the url to the admin area for the current user. |
1802 * |
2164 * |
1803 * @package WordPress |
2165 * @package WordPress |
1804 * @since 2.6.0 |
2166 * @since 3.0.0 |
1805 * |
2167 * |
1806 * @param string $path Optional. Path relative to the content url. |
2168 * @param string $path Optional path relative to the admin url. |
1807 * @return string Content url link with optional path appended. |
2169 * @param string $scheme The scheme to use. Default is 'admin', which obeys force_ssl_admin() and is_ssl(). 'http' or 'https' can be passed to force those schemes. |
2170 * @return string Admin url link with optional path appended. |
|
1808 */ |
2171 */ |
1809 function content_url($path = '') { |
2172 function user_admin_url( $path = '', $scheme = 'admin' ) { |
1810 $scheme = ( is_ssl() ? 'https' : 'http' ); |
2173 $url = network_site_url('wp-admin/user/', $scheme); |
1811 $url = WP_CONTENT_URL; |
|
1812 if ( 0 === strpos($url, 'http') ) { |
|
1813 if ( is_ssl() ) |
|
1814 $url = str_replace( 'http://', "{$scheme}://", $url ); |
|
1815 } |
|
1816 |
2174 |
1817 if ( !empty($path) && is_string($path) && strpos($path, '..') === false ) |
2175 if ( !empty($path) && is_string($path) && strpos($path, '..') === false ) |
1818 $url .= '/' . ltrim($path, '/'); |
2176 $url .= ltrim($path, '/'); |
1819 |
2177 |
1820 return apply_filters('content_url', $url, $path); |
2178 return apply_filters('user_admin_url', $url, $path); |
1821 } |
2179 } |
1822 |
2180 |
1823 /** |
2181 /** |
1824 * Retrieve the url to the plugins directory or to a specific file within that directory. |
2182 * Retrieve the url to the admin area for either the current blog or the network depending on context. |
1825 * You can hardcode the plugin slug in $path or pass __FILE__ as a second argument to get the correct folder name. |
|
1826 * |
2183 * |
1827 * @package WordPress |
2184 * @package WordPress |
1828 * @since 2.6.0 |
2185 * @since 3.1.0 |
1829 * |
2186 * |
1830 * @param string $path Optional. Path relative to the plugins url. |
2187 * @param string $path Optional path relative to the admin url. |
1831 * @param string $plugin Optional. The plugin file that you want to be relative to - i.e. pass in __FILE__ |
2188 * @param string $scheme The scheme to use. Default is 'admin', which obeys force_ssl_admin() and is_ssl(). 'http' or 'https' can be passed to force those schemes. |
1832 * @return string Plugins url link with optional path appended. |
2189 * @return string Admin url link with optional path appended. |
1833 */ |
2190 */ |
1834 function plugins_url($path = '', $plugin = '') { |
2191 function self_admin_url($path = '', $scheme = 'admin') { |
1835 $scheme = ( is_ssl() ? 'https' : 'http' ); |
2192 if ( is_network_admin() ) |
1836 |
2193 return network_admin_url($path, $scheme); |
1837 if ( $plugin !== '' && preg_match('#^' . preg_quote(WPMU_PLUGIN_DIR . DIRECTORY_SEPARATOR, '#') . '#', $plugin) ) { |
2194 elseif ( is_user_admin() ) |
1838 $url = WPMU_PLUGIN_URL; |
2195 return user_admin_url($path, $scheme); |
2196 else |
|
2197 return admin_url($path, $scheme); |
|
2198 } |
|
2199 |
|
2200 /** |
|
2201 * Set the scheme for a URL |
|
2202 * |
|
2203 * @since 3.4.0 |
|
2204 * |
|
2205 * @param string $url Absolute url that includes a scheme |
|
2206 * @param string $scheme Optional. Scheme to give $url. Currently 'http', 'https', 'login', 'login_post', 'admin', or 'relative'. |
|
2207 * @return string $url URL with chosen scheme. |
|
2208 */ |
|
2209 function set_url_scheme( $url, $scheme = null ) { |
|
2210 $orig_scheme = $scheme; |
|
2211 if ( ! in_array( $scheme, array( 'http', 'https', 'relative' ) ) ) { |
|
2212 if ( ( 'login_post' == $scheme || 'rpc' == $scheme ) && ( force_ssl_login() || force_ssl_admin() ) ) |
|
2213 $scheme = 'https'; |
|
2214 elseif ( ( 'login' == $scheme ) && force_ssl_admin() ) |
|
2215 $scheme = 'https'; |
|
2216 elseif ( ( 'admin' == $scheme ) && force_ssl_admin() ) |
|
2217 $scheme = 'https'; |
|
2218 else |
|
2219 $scheme = ( is_ssl() ? 'https' : 'http' ); |
|
2220 } |
|
2221 |
|
2222 if ( 'relative' == $scheme ) |
|
2223 $url = preg_replace( '#^.+://[^/]*#', '', $url ); |
|
2224 else |
|
2225 $url = preg_replace( '#^.+://#', $scheme . '://', $url ); |
|
2226 |
|
2227 return apply_filters( 'set_url_scheme', $url, $scheme, $orig_scheme ); |
|
2228 } |
|
2229 |
|
2230 /** |
|
2231 * Get the URL to the user's dashboard. |
|
2232 * |
|
2233 * If a user does not belong to any site, the global user dashboard is used. If the user belongs to the current site, |
|
2234 * the dashboard for the current site is returned. If the user cannot edit the current site, the dashboard to the user's |
|
2235 * primary blog is returned. |
|
2236 * |
|
2237 * @since 3.1.0 |
|
2238 * |
|
2239 * @param int $user_id User ID |
|
2240 * @param string $path Optional path relative to the dashboard. Use only paths known to both blog and user admins. |
|
2241 * @param string $scheme The scheme to use. Default is 'admin', which obeys force_ssl_admin() and is_ssl(). 'http' or 'https' can be passed to force those schemes. |
|
2242 * @return string Dashboard url link with optional path appended. |
|
2243 */ |
|
2244 function get_dashboard_url( $user_id, $path = '', $scheme = 'admin' ) { |
|
2245 $user_id = (int) $user_id; |
|
2246 |
|
2247 $blogs = get_blogs_of_user( $user_id ); |
|
2248 if ( ! is_super_admin() && empty($blogs) ) { |
|
2249 $url = user_admin_url( $path, $scheme ); |
|
2250 } elseif ( ! is_multisite() ) { |
|
2251 $url = admin_url( $path, $scheme ); |
|
1839 } else { |
2252 } else { |
1840 $url = WP_PLUGIN_URL; |
2253 $current_blog = get_current_blog_id(); |
1841 } |
2254 if ( $current_blog && ( is_super_admin( $user_id ) || in_array( $current_blog, array_keys( $blogs ) ) ) ) { |
1842 |
2255 $url = admin_url( $path, $scheme ); |
1843 if ( 0 === strpos($url, 'http') ) { |
2256 } else { |
1844 if ( is_ssl() ) |
2257 $active = get_active_blog_for_user( $user_id ); |
1845 $url = str_replace( 'http://', "{$scheme}://", $url ); |
2258 if ( $active ) |
1846 } |
2259 $url = get_admin_url( $active->blog_id, $path, $scheme ); |
1847 |
2260 else |
1848 if ( !empty($plugin) && is_string($plugin) ) { |
2261 $url = user_admin_url( $path, $scheme ); |
1849 $folder = dirname(plugin_basename($plugin)); |
2262 } |
1850 if ('.' != $folder) |
2263 } |
1851 $url .= '/' . ltrim($folder, '/'); |
2264 |
1852 } |
2265 return apply_filters( 'user_dashboard_url', $url, $user_id, $path, $scheme); |
1853 |
2266 } |
1854 if ( !empty($path) && is_string($path) && strpos($path, '..') === false ) |
2267 |
1855 $url .= '/' . ltrim($path, '/'); |
2268 /** |
1856 |
2269 * Get the URL to the user's profile editor. |
1857 return apply_filters('plugins_url', $url, $path, $plugin); |
2270 * |
1858 } |
2271 * @since 3.1.0 |
1859 |
2272 * |
1860 /** |
2273 * @param int $user User ID |
1861 * Output rel=canonical for singular queries |
2274 * @param string $scheme The scheme to use. Default is 'admin', which obeys force_ssl_admin() and is_ssl(). 'http' or 'https' can be passed to force those schemes. |
2275 * @return string Dashboard url link with optional path appended. |
|
2276 */ |
|
2277 function get_edit_profile_url( $user, $scheme = 'admin' ) { |
|
2278 $user = (int) $user; |
|
2279 |
|
2280 if ( is_user_admin() ) |
|
2281 $url = user_admin_url( 'profile.php', $scheme ); |
|
2282 elseif ( is_network_admin() ) |
|
2283 $url = network_admin_url( 'profile.php', $scheme ); |
|
2284 else |
|
2285 $url = get_dashboard_url( $user, 'profile.php', $scheme ); |
|
2286 |
|
2287 return apply_filters( 'edit_profile_url', $url, $user, $scheme); |
|
2288 } |
|
2289 |
|
2290 /** |
|
2291 * Output rel=canonical for singular queries. |
|
1862 * |
2292 * |
1863 * @package WordPress |
2293 * @package WordPress |
1864 * @since 2.9.0 |
2294 * @since 2.9.0 |
1865 */ |
2295 */ |
1866 function rel_canonical() { |
2296 function rel_canonical() { |
1873 |
2303 |
1874 $link = get_permalink( $id ); |
2304 $link = get_permalink( $id ); |
1875 echo "<link rel='canonical' href='$link' />\n"; |
2305 echo "<link rel='canonical' href='$link' />\n"; |
1876 } |
2306 } |
1877 |
2307 |
1878 ?> |
2308 /** |
2309 * Return a shortlink for a post, page, attachment, or blog. |
|
2310 * |
|
2311 * This function exists to provide a shortlink tag that all themes and plugins can target. A plugin must hook in to |
|
2312 * provide the actual shortlinks. Default shortlink support is limited to providing ?p= style links for posts. |
|
2313 * Plugins can short-circuit this function via the pre_get_shortlink filter or filter the output |
|
2314 * via the get_shortlink filter. |
|
2315 * |
|
2316 * @since 3.0.0. |
|
2317 * |
|
2318 * @param int $id A post or blog id. Default is 0, which means the current post or blog. |
|
2319 * @param string $context Whether the id is a 'blog' id, 'post' id, or 'media' id. If 'post', the post_type of the post is consulted. If 'query', the current query is consulted to determine the id and context. Default is 'post'. |
|
2320 * @param bool $allow_slugs Whether to allow post slugs in the shortlink. It is up to the plugin how and whether to honor this. |
|
2321 * @return string A shortlink or an empty string if no shortlink exists for the requested resource or if shortlinks are not enabled. |
|
2322 */ |
|
2323 function wp_get_shortlink($id = 0, $context = 'post', $allow_slugs = true) { |
|
2324 // Allow plugins to short-circuit this function. |
|
2325 $shortlink = apply_filters('pre_get_shortlink', false, $id, $context, $allow_slugs); |
|
2326 if ( false !== $shortlink ) |
|
2327 return $shortlink; |
|
2328 |
|
2329 global $wp_query; |
|
2330 $post_id = 0; |
|
2331 if ( 'query' == $context && is_single() ) { |
|
2332 $post_id = $wp_query->get_queried_object_id(); |
|
2333 } elseif ( 'post' == $context ) { |
|
2334 $post = get_post($id); |
|
2335 $post_id = $post->ID; |
|
2336 } |
|
2337 |
|
2338 $shortlink = ''; |
|
2339 |
|
2340 // Return p= link for posts. |
|
2341 if ( !empty($post_id) && '' != get_option('permalink_structure') ) { |
|
2342 $post = get_post($post_id); |
|
2343 if ( isset($post->post_type) && 'post' == $post->post_type ) |
|
2344 $shortlink = home_url('?p=' . $post->ID); |
|
2345 } |
|
2346 |
|
2347 return apply_filters('get_shortlink', $shortlink, $id, $context, $allow_slugs); |
|
2348 } |
|
2349 |
|
2350 /** |
|
2351 * Inject rel=shortlink into head if a shortlink is defined for the current page. |
|
2352 * |
|
2353 * Attached to the wp_head action. |
|
2354 * |
|
2355 * @since 3.0.0 |
|
2356 * |
|
2357 * @uses wp_get_shortlink() |
|
2358 */ |
|
2359 function wp_shortlink_wp_head() { |
|
2360 $shortlink = wp_get_shortlink( 0, 'query' ); |
|
2361 |
|
2362 if ( empty( $shortlink ) ) |
|
2363 return; |
|
2364 |
|
2365 echo "<link rel='shortlink' href='" . esc_url( $shortlink ) . "' />\n"; |
|
2366 } |
|
2367 |
|
2368 /** |
|
2369 * Send a Link: rel=shortlink header if a shortlink is defined for the current page. |
|
2370 * |
|
2371 * Attached to the wp action. |
|
2372 * |
|
2373 * @since 3.0.0 |
|
2374 * |
|
2375 * @uses wp_get_shortlink() |
|
2376 */ |
|
2377 function wp_shortlink_header() { |
|
2378 if ( headers_sent() ) |
|
2379 return; |
|
2380 |
|
2381 $shortlink = wp_get_shortlink(0, 'query'); |
|
2382 |
|
2383 if ( empty($shortlink) ) |
|
2384 return; |
|
2385 |
|
2386 header('Link: <' . $shortlink . '>; rel=shortlink', false); |
|
2387 } |
|
2388 |
|
2389 /** |
|
2390 * Display the Short Link for a Post |
|
2391 * |
|
2392 * Must be called from inside "The Loop" |
|
2393 * |
|
2394 * Call like the_shortlink(__('Shortlinkage FTW')) |
|
2395 * |
|
2396 * @since 3.0.0 |
|
2397 * |
|
2398 * @param string $text Optional The link text or HTML to be displayed. Defaults to 'This is the short link.' |
|
2399 * @param string $title Optional The tooltip for the link. Must be sanitized. Defaults to the sanitized post title. |
|
2400 * @param string $before Optional HTML to display before the link. |
|
2401 * @param string $after Optional HTML to display after the link. |
|
2402 */ |
|
2403 function the_shortlink( $text = '', $title = '', $before = '', $after = '' ) { |
|
2404 global $post; |
|
2405 |
|
2406 if ( empty( $text ) ) |
|
2407 $text = __('This is the short link.'); |
|
2408 |
|
2409 if ( empty( $title ) ) |
|
2410 $title = the_title_attribute( array( 'echo' => false ) ); |
|
2411 |
|
2412 $shortlink = wp_get_shortlink( $post->ID ); |
|
2413 |
|
2414 if ( !empty( $shortlink ) ) { |
|
2415 $link = '<a rel="shortlink" href="' . esc_url( $shortlink ) . '" title="' . $title . '">' . $text . '</a>'; |
|
2416 $link = apply_filters( 'the_shortlink', $link, $shortlink, $text, $title ); |
|
2417 echo $before, $link, $after; |
|
2418 } |
|
2419 } |