|
1 <?php |
|
2 /** |
|
3 * WordPress Link Template Functions |
|
4 * |
|
5 * @package WordPress |
|
6 * @subpackage Template |
|
7 */ |
|
8 |
|
9 /** |
|
10 * Display the permalink for the current post. |
|
11 * |
|
12 * @since 1.2.0 |
|
13 * @uses apply_filters() Calls 'the_permalink' filter on the permalink string. |
|
14 */ |
|
15 function the_permalink() { |
|
16 echo apply_filters('the_permalink', get_permalink()); |
|
17 } |
|
18 |
|
19 /** |
|
20 * Retrieve trailing slash string, if blog set for adding trailing slashes. |
|
21 * |
|
22 * Conditionally adds a trailing slash if the permalink structure has a trailing |
|
23 * slash, strips the trailing slash if not. The string is passed through the |
|
24 * 'user_trailingslashit' filter. Will remove trailing slash from string, if |
|
25 * blog is not set to have them. |
|
26 * |
|
27 * @since 2.2.0 |
|
28 * @uses $wp_rewrite |
|
29 * |
|
30 * @param $string String a 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. |
|
32 * @return string |
|
33 */ |
|
34 function user_trailingslashit($string, $type_of_url = '') { |
|
35 global $wp_rewrite; |
|
36 if ( $wp_rewrite->use_trailing_slashes ) |
|
37 $string = trailingslashit($string); |
|
38 else |
|
39 $string = untrailingslashit($string); |
|
40 |
|
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 |
|
43 $string = apply_filters('user_trailingslashit', $string, $type_of_url); |
|
44 return $string; |
|
45 } |
|
46 |
|
47 /** |
|
48 * Display permalink anchor for current post. |
|
49 * |
|
50 * The permalink mode title will use the post title for the 'a' element 'id' |
|
51 * attribute. The id mode uses 'post-' with the post ID for the 'id' attribute. |
|
52 * |
|
53 * @since 0.71 |
|
54 * |
|
55 * @param string $mode Permalink mode can be either 'title', 'id', or default, which is 'id'. |
|
56 */ |
|
57 function permalink_anchor($mode = 'id') { |
|
58 global $post; |
|
59 switch ( strtolower($mode) ) { |
|
60 case 'title': |
|
61 $title = sanitize_title($post->post_title) . '-' . $post->ID; |
|
62 echo '<a id="'.$title.'"></a>'; |
|
63 break; |
|
64 case 'id': |
|
65 default: |
|
66 echo '<a id="post-' . $post->ID . '"></a>'; |
|
67 break; |
|
68 } |
|
69 } |
|
70 |
|
71 /** |
|
72 * Retrieve full permalink for current post or post ID. |
|
73 * |
|
74 * @since 1.0.0 |
|
75 * |
|
76 * @param int $id Optional. Post ID. |
|
77 * @param bool $leavename Optional, defaults to false. Whether to keep post name or page name. |
|
78 * @return string |
|
79 */ |
|
80 function get_permalink($id = 0, $leavename = false) { |
|
81 $rewritecode = array( |
|
82 '%year%', |
|
83 '%monthnum%', |
|
84 '%day%', |
|
85 '%hour%', |
|
86 '%minute%', |
|
87 '%second%', |
|
88 $leavename? '' : '%postname%', |
|
89 '%post_id%', |
|
90 '%category%', |
|
91 '%author%', |
|
92 $leavename? '' : '%pagename%', |
|
93 ); |
|
94 |
|
95 if ( is_object($id) && isset($id->filter) && 'sample' == $id->filter ) { |
|
96 $post = $id; |
|
97 $sample = true; |
|
98 } else { |
|
99 $post = &get_post($id); |
|
100 $sample = false; |
|
101 } |
|
102 |
|
103 if ( empty($post->ID) ) return false; |
|
104 |
|
105 if ( $post->post_type == 'page' ) |
|
106 return get_page_link($post->ID, $leavename, $sample); |
|
107 elseif ($post->post_type == 'attachment') |
|
108 return get_attachment_link($post->ID); |
|
109 |
|
110 $permalink = get_option('permalink_structure'); |
|
111 |
|
112 if ( '' != $permalink && !in_array($post->post_status, array('draft', 'pending')) ) { |
|
113 $unixtime = strtotime($post->post_date); |
|
114 |
|
115 $category = ''; |
|
116 if ( strpos($permalink, '%category%') !== false ) { |
|
117 $cats = get_the_category($post->ID); |
|
118 if ( $cats ) { |
|
119 usort($cats, '_usort_terms_by_ID'); // order by ID |
|
120 $category = $cats[0]->slug; |
|
121 if ( $parent = $cats[0]->parent ) |
|
122 $category = get_category_parents($parent, false, '/', true) . $category; |
|
123 } |
|
124 // show default category in permalinks, without |
|
125 // having to assign it explicitly |
|
126 if ( empty($category) ) { |
|
127 $default_category = get_category( get_option( 'default_category' ) ); |
|
128 $category = is_wp_error( $default_category ) ? '' : $default_category->slug; |
|
129 } |
|
130 } |
|
131 |
|
132 $author = ''; |
|
133 if ( strpos($permalink, '%author%') !== false ) { |
|
134 $authordata = get_userdata($post->post_author); |
|
135 $author = $authordata->user_nicename; |
|
136 } |
|
137 |
|
138 $date = explode(" ",date('Y m d H i s', $unixtime)); |
|
139 $rewritereplace = |
|
140 array( |
|
141 $date[0], |
|
142 $date[1], |
|
143 $date[2], |
|
144 $date[3], |
|
145 $date[4], |
|
146 $date[5], |
|
147 $post->post_name, |
|
148 $post->ID, |
|
149 $category, |
|
150 $author, |
|
151 $post->post_name, |
|
152 ); |
|
153 $permalink = get_option('home') . str_replace($rewritecode, $rewritereplace, $permalink); |
|
154 $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 |
|
157 $permalink = trailingslashit(get_option('home')) . '?p=' . $post->ID; |
|
158 return apply_filters('post_link', $permalink, $post, $leavename); |
|
159 } |
|
160 } |
|
161 |
|
162 /** |
|
163 * Retrieve permalink from post ID. |
|
164 * |
|
165 * @since 1.0.0 |
|
166 * |
|
167 * @param int $post_id Optional. Post ID. |
|
168 * @param mixed $deprecated Not used. |
|
169 * @return string |
|
170 */ |
|
171 function post_permalink($post_id = 0, $deprecated = '') { |
|
172 return get_permalink($post_id); |
|
173 } |
|
174 |
|
175 /** |
|
176 * Retrieve the permalink for current page or page ID. |
|
177 * |
|
178 * Respects page_on_front. Use this one. |
|
179 * |
|
180 * @since 1.5.0 |
|
181 * |
|
182 * @param int $id Optional. Post ID. |
|
183 * @param bool $leavename Optional, defaults to false. Whether to keep page name. |
|
184 * @param bool $sample Optional, defaults to false. Is it a sample permalink. |
|
185 * @return string |
|
186 */ |
|
187 function get_page_link( $id = false, $leavename = false, $sample = false ) { |
|
188 global $post; |
|
189 |
|
190 $id = (int) $id; |
|
191 if ( !$id ) |
|
192 $id = (int) $post->ID; |
|
193 |
|
194 if ( 'page' == get_option('show_on_front') && $id == get_option('page_on_front') ) |
|
195 $link = get_option('home'); |
|
196 else |
|
197 $link = _get_page_link( $id , $leavename, $sample ); |
|
198 |
|
199 return apply_filters('page_link', $link, $id); |
|
200 } |
|
201 |
|
202 /** |
|
203 * Retrieve the page permalink. |
|
204 * |
|
205 * Ignores page_on_front. Internal use only. |
|
206 * |
|
207 * @since 2.1.0 |
|
208 * @access private |
|
209 * |
|
210 * @param int $id Optional. Post ID. |
|
211 * @param bool $leavename Optional. Leave name. |
|
212 * @param bool $sample Optional. Sample permalink. |
|
213 * @return string |
|
214 */ |
|
215 function _get_page_link( $id = false, $leavename = false, $sample = false ) { |
|
216 global $post, $wp_rewrite; |
|
217 |
|
218 if ( !$id ) |
|
219 $id = (int) $post->ID; |
|
220 else |
|
221 $post = &get_post($id); |
|
222 |
|
223 $pagestruct = $wp_rewrite->get_page_permastruct(); |
|
224 |
|
225 if ( '' != $pagestruct && ( ( isset($post->post_status) && 'draft' != $post->post_status ) || $sample ) ) { |
|
226 $link = get_page_uri($id); |
|
227 $link = ( $leavename ) ? $pagestruct : str_replace('%pagename%', $link, $pagestruct); |
|
228 $link = trailingslashit(get_option('home')) . "$link"; |
|
229 $link = user_trailingslashit($link, 'page'); |
|
230 } else { |
|
231 $link = trailingslashit(get_option('home')) . "?page_id=$id"; |
|
232 } |
|
233 |
|
234 return apply_filters( '_get_page_link', $link, $id ); |
|
235 } |
|
236 |
|
237 /** |
|
238 * Retrieve permalink for attachment. |
|
239 * |
|
240 * This can be used in the WordPress Loop or outside of it. |
|
241 * |
|
242 * @since 2.0.0 |
|
243 * |
|
244 * @param int $id Optional. Post ID. |
|
245 * @return string |
|
246 */ |
|
247 function get_attachment_link($id = false) { |
|
248 global $post, $wp_rewrite; |
|
249 |
|
250 $link = false; |
|
251 |
|
252 if (! $id) { |
|
253 $id = (int) $post->ID; |
|
254 } |
|
255 |
|
256 $object = get_post($id); |
|
257 if ( $wp_rewrite->using_permalinks() && ($object->post_parent > 0) && ($object->post_parent != $id) ) { |
|
258 $parent = get_post($object->post_parent); |
|
259 if ( 'page' == $parent->post_type ) |
|
260 $parentlink = _get_page_link( $object->post_parent ); // Ignores page_on_front |
|
261 else |
|
262 $parentlink = get_permalink( $object->post_parent ); |
|
263 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 |
|
265 else |
|
266 $name = $object->post_name; |
|
267 if (strpos($parentlink, '?') === false) |
|
268 $link = user_trailingslashit( trailingslashit($parentlink) . $name ); |
|
269 } |
|
270 |
|
271 if (! $link ) { |
|
272 $link = trailingslashit(get_bloginfo('url')) . "?attachment_id=$id"; |
|
273 } |
|
274 |
|
275 return apply_filters('attachment_link', $link, $id); |
|
276 } |
|
277 |
|
278 /** |
|
279 * Retrieve the permalink for the year archives. |
|
280 * |
|
281 * @since 1.5.0 |
|
282 * |
|
283 * @param int|bool $year False for current year or year for permalink. |
|
284 * @return string |
|
285 */ |
|
286 function get_year_link($year) { |
|
287 global $wp_rewrite; |
|
288 if ( !$year ) |
|
289 $year = gmdate('Y', time()+(get_option('gmt_offset') * 3600)); |
|
290 $yearlink = $wp_rewrite->get_year_permastruct(); |
|
291 if ( !empty($yearlink) ) { |
|
292 $yearlink = str_replace('%year%', $year, $yearlink); |
|
293 return apply_filters('year_link', get_option('home') . user_trailingslashit($yearlink, 'year'), $year); |
|
294 } else { |
|
295 return apply_filters('year_link', trailingslashit(get_option('home')) . '?m=' . $year, $year); |
|
296 } |
|
297 } |
|
298 |
|
299 /** |
|
300 * Retrieve the permalink for the month archives with year. |
|
301 * |
|
302 * @since 1.0.0 |
|
303 * |
|
304 * @param bool|int $year False for current year. Integer of year. |
|
305 * @param bool|int $month False for current month. Integer of month. |
|
306 * @return string |
|
307 */ |
|
308 function get_month_link($year, $month) { |
|
309 global $wp_rewrite; |
|
310 if ( !$year ) |
|
311 $year = gmdate('Y', time()+(get_option('gmt_offset') * 3600)); |
|
312 if ( !$month ) |
|
313 $month = gmdate('m', time()+(get_option('gmt_offset') * 3600)); |
|
314 $monthlink = $wp_rewrite->get_month_permastruct(); |
|
315 if ( !empty($monthlink) ) { |
|
316 $monthlink = str_replace('%year%', $year, $monthlink); |
|
317 $monthlink = str_replace('%monthnum%', zeroise(intval($month), 2), $monthlink); |
|
318 return apply_filters('month_link', get_option('home') . user_trailingslashit($monthlink, 'month'), $year, $month); |
|
319 } else { |
|
320 return apply_filters('month_link', trailingslashit(get_option('home')) . '?m=' . $year . zeroise($month, 2), $year, $month); |
|
321 } |
|
322 } |
|
323 |
|
324 /** |
|
325 * Retrieve the permalink for the day archives with year and month. |
|
326 * |
|
327 * @since 1.0.0 |
|
328 * |
|
329 * @param bool|int $year False for current year. Integer of year. |
|
330 * @param bool|int $month False for current month. Integer of month. |
|
331 * @param bool|int $day False for current day. Integer of day. |
|
332 * @return string |
|
333 */ |
|
334 function get_day_link($year, $month, $day) { |
|
335 global $wp_rewrite; |
|
336 if ( !$year ) |
|
337 $year = gmdate('Y', time()+(get_option('gmt_offset') * 3600)); |
|
338 if ( !$month ) |
|
339 $month = gmdate('m', time()+(get_option('gmt_offset') * 3600)); |
|
340 if ( !$day ) |
|
341 $day = gmdate('j', time()+(get_option('gmt_offset') * 3600)); |
|
342 |
|
343 $daylink = $wp_rewrite->get_day_permastruct(); |
|
344 if ( !empty($daylink) ) { |
|
345 $daylink = str_replace('%year%', $year, $daylink); |
|
346 $daylink = str_replace('%monthnum%', zeroise(intval($month), 2), $daylink); |
|
347 $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); |
|
349 } else { |
|
350 return apply_filters('day_link', trailingslashit(get_option('home')) . '?m=' . $year . zeroise($month, 2) . zeroise($day, 2), $year, $month, $day); |
|
351 } |
|
352 } |
|
353 |
|
354 /** |
|
355 * Retrieve the permalink for the feed type. |
|
356 * |
|
357 * @since 1.5.0 |
|
358 * |
|
359 * @param string $feed Optional, defaults to default feed. Feed type. |
|
360 * @return string |
|
361 */ |
|
362 function get_feed_link($feed = '') { |
|
363 global $wp_rewrite; |
|
364 |
|
365 $permalink = $wp_rewrite->get_feed_permastruct(); |
|
366 if ( '' != $permalink ) { |
|
367 if ( false !== strpos($feed, 'comments_') ) { |
|
368 $feed = str_replace('comments_', '', $feed); |
|
369 $permalink = $wp_rewrite->get_comment_feed_permastruct(); |
|
370 } |
|
371 |
|
372 if ( get_default_feed() == $feed ) |
|
373 $feed = ''; |
|
374 |
|
375 $permalink = str_replace('%feed%', $feed, $permalink); |
|
376 $permalink = preg_replace('#/+#', '/', "/$permalink"); |
|
377 $output = get_option('home') . user_trailingslashit($permalink, 'feed'); |
|
378 } else { |
|
379 if ( empty($feed) ) |
|
380 $feed = get_default_feed(); |
|
381 |
|
382 if ( false !== strpos($feed, 'comments_') ) |
|
383 $feed = str_replace('comments_', 'comments-', $feed); |
|
384 |
|
385 $output = trailingslashit(get_option('home')) . "?feed={$feed}"; |
|
386 } |
|
387 |
|
388 return apply_filters('feed_link', $output, $feed); |
|
389 } |
|
390 |
|
391 /** |
|
392 * Retrieve the permalink for the post comments feed. |
|
393 * |
|
394 * @since 2.2.0 |
|
395 * |
|
396 * @param int $post_id Optional. Post ID. |
|
397 * @param string $feed Optional. Feed type. |
|
398 * @return string |
|
399 */ |
|
400 function get_post_comments_feed_link($post_id = '', $feed = '') { |
|
401 global $id; |
|
402 |
|
403 if ( empty($post_id) ) |
|
404 $post_id = (int) $id; |
|
405 |
|
406 if ( empty($feed) ) |
|
407 $feed = get_default_feed(); |
|
408 |
|
409 if ( '' != get_option('permalink_structure') ) { |
|
410 $url = trailingslashit( get_permalink($post_id) ) . 'feed'; |
|
411 if ( $feed != get_default_feed() ) |
|
412 $url .= "/$feed"; |
|
413 $url = user_trailingslashit($url, 'single_feed'); |
|
414 } else { |
|
415 $type = get_post_field('post_type', $post_id); |
|
416 if ( 'page' == $type ) |
|
417 $url = trailingslashit(get_option('home')) . "?feed=$feed&page_id=$post_id"; |
|
418 else |
|
419 $url = trailingslashit(get_option('home')) . "?feed=$feed&p=$post_id"; |
|
420 } |
|
421 |
|
422 return apply_filters('post_comments_feed_link', $url); |
|
423 } |
|
424 |
|
425 /** |
|
426 * Display the comment feed link for a post. |
|
427 * |
|
428 * Prints out the comment feed link for a post. Link text is placed in the |
|
429 * anchor. If no link text is specified, default text is used. If no post ID is |
|
430 * specified, the current post is used. |
|
431 * |
|
432 * @package WordPress |
|
433 * @subpackage Feed |
|
434 * @since 2.5.0 |
|
435 * |
|
436 * @param string $link_text Descriptive text. |
|
437 * @param int $post_id Optional post ID. Default to current post. |
|
438 * @param string $feed Optional. Feed format. |
|
439 * @return string Link to the comment feed for the current post. |
|
440 */ |
|
441 function post_comments_feed_link( $link_text = '', $post_id = '', $feed = '' ) { |
|
442 $url = get_post_comments_feed_link($post_id, $feed); |
|
443 if ( empty($link_text) ) |
|
444 $link_text = __('Comments Feed'); |
|
445 |
|
446 echo apply_filters( 'post_comments_feed_link_html', "<a href='$url'>$link_text</a>", $post_id, $feed ); |
|
447 } |
|
448 |
|
449 /** |
|
450 * Retrieve the feed link for a given author. |
|
451 * |
|
452 * Returns a link to the feed for all posts by a given author. A specific feed |
|
453 * can be requested or left blank to get the default feed. |
|
454 * |
|
455 * @package WordPress |
|
456 * @subpackage Feed |
|
457 * @since 2.5.0 |
|
458 * |
|
459 * @param int $author_id ID of an author. |
|
460 * @param string $feed Optional. Feed type. |
|
461 * @return string Link to the feed for the author specified by $author_id. |
|
462 */ |
|
463 function get_author_feed_link( $author_id, $feed = '' ) { |
|
464 $author_id = (int) $author_id; |
|
465 $permalink_structure = get_option('permalink_structure'); |
|
466 |
|
467 if ( empty($feed) ) |
|
468 $feed = get_default_feed(); |
|
469 |
|
470 if ( '' == $permalink_structure ) { |
|
471 $link = trailingslashit(get_option('home')) . "?feed=$feed&author=" . $author_id; |
|
472 } else { |
|
473 $link = get_author_posts_url($author_id); |
|
474 if ( $feed == get_default_feed() ) |
|
475 $feed_link = 'feed'; |
|
476 else |
|
477 $feed_link = "feed/$feed"; |
|
478 |
|
479 $link = trailingslashit($link) . user_trailingslashit($feed_link, 'feed'); |
|
480 } |
|
481 |
|
482 $link = apply_filters('author_feed_link', $link, $feed); |
|
483 |
|
484 return $link; |
|
485 } |
|
486 |
|
487 /** |
|
488 * Retrieve the feed link for a category. |
|
489 * |
|
490 * Returns a link to the feed for all post in a given category. A specific feed |
|
491 * can be requested or left blank to get the default feed. |
|
492 * |
|
493 * @package WordPress |
|
494 * @subpackage Feed |
|
495 * @since 2.5.0 |
|
496 * |
|
497 * @param int $cat_id ID of a category. |
|
498 * @param string $feed Optional. Feed type. |
|
499 * @return string Link to the feed for the category specified by $cat_id. |
|
500 */ |
|
501 function get_category_feed_link($cat_id, $feed = '') { |
|
502 $cat_id = (int) $cat_id; |
|
503 |
|
504 $category = get_category($cat_id); |
|
505 |
|
506 if ( empty($category) || is_wp_error($category) ) |
|
507 return false; |
|
508 |
|
509 if ( empty($feed) ) |
|
510 $feed = get_default_feed(); |
|
511 |
|
512 $permalink_structure = get_option('permalink_structure'); |
|
513 |
|
514 if ( '' == $permalink_structure ) { |
|
515 $link = trailingslashit(get_option('home')) . "?feed=$feed&cat=" . $cat_id; |
|
516 } else { |
|
517 $link = get_category_link($cat_id); |
|
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() ) |
|
558 $feed_link = 'feed'; |
|
559 else |
|
560 $feed_link = "feed/$feed"; |
|
561 $link = trailingslashit($link) . user_trailingslashit($feed_link, 'feed'); |
|
562 } |
|
563 |
|
564 $link = apply_filters('tag_feed_link', $link, $feed); |
|
565 |
|
566 return $link; |
|
567 } |
|
568 |
|
569 /** |
|
570 * Retrieve edit tag link. |
|
571 * |
|
572 * @since 2.7.0 |
|
573 * |
|
574 * @param int $tag_id Tag ID |
|
575 * @return string |
|
576 */ |
|
577 function get_edit_tag_link( $tag_id = 0, $taxonomy = 'post_tag' ) { |
|
578 $tag = get_term($tag_id, $taxonomy); |
|
579 |
|
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 } |
|
586 |
|
587 /** |
|
588 * Display or retrieve edit tag link with formatting. |
|
589 * |
|
590 * @since 2.7.0 |
|
591 * |
|
592 * @param string $link Optional. Anchor text. |
|
593 * @param string $before Optional. Display before edit link. |
|
594 * @param string $after Optional. Display after edit link. |
|
595 * @param int|object $tag Tag object or ID |
|
596 * @return string|null HTML content, if $echo is set to false. |
|
597 */ |
|
598 function edit_tag_link( $link = '', $before = '', $after = '', $tag = null ) { |
|
599 $tag = get_term($tag, 'post_tag'); |
|
600 |
|
601 if ( !current_user_can('manage_categories') ) |
|
602 return; |
|
603 |
|
604 if ( empty($link) ) |
|
605 $link = __('Edit This'); |
|
606 |
|
607 $link = '<a href="' . get_edit_tag_link( $tag->term_id ) . '" title="' . __( 'Edit tag' ) . '">' . $link . '</a>'; |
|
608 echo $before . apply_filters( 'edit_tag_link', $link, $tag->term_id ) . $after; |
|
609 } |
|
610 |
|
611 /** |
|
612 * Retrieve the permalink for the feed of the search results. |
|
613 * |
|
614 * @since 2.5.0 |
|
615 * |
|
616 * @param string $search_query Optional. Search query. |
|
617 * @param string $feed Optional. Feed type. |
|
618 * @return string |
|
619 */ |
|
620 function get_search_feed_link($search_query = '', $feed = '') { |
|
621 if ( empty($search_query) ) |
|
622 $search = esc_attr(get_search_query()); |
|
623 else |
|
624 $search = esc_attr(stripslashes($search_query)); |
|
625 |
|
626 if ( empty($feed) ) |
|
627 $feed = get_default_feed(); |
|
628 |
|
629 $link = trailingslashit(get_option('home')) . "?s=$search&feed=$feed"; |
|
630 |
|
631 $link = apply_filters('search_feed_link', $link); |
|
632 |
|
633 return $link; |
|
634 } |
|
635 |
|
636 /** |
|
637 * Retrieve the permalink for the comments feed of the search results. |
|
638 * |
|
639 * @since 2.5.0 |
|
640 * |
|
641 * @param string $search_query Optional. Search query. |
|
642 * @param string $feed Optional. Feed type. |
|
643 * @return string |
|
644 */ |
|
645 function get_search_comments_feed_link($search_query = '', $feed = '') { |
|
646 if ( empty($search_query) ) |
|
647 $search = esc_attr(get_search_query()); |
|
648 else |
|
649 $search = esc_attr(stripslashes($search_query)); |
|
650 |
|
651 if ( empty($feed) ) |
|
652 $feed = get_default_feed(); |
|
653 |
|
654 $link = trailingslashit(get_option('home')) . "?s=$search&feed=comments-$feed"; |
|
655 |
|
656 $link = apply_filters('search_feed_link', $link); |
|
657 |
|
658 return $link; |
|
659 } |
|
660 |
|
661 /** |
|
662 * Retrieve edit posts link for post. |
|
663 * |
|
664 * Can be used within the WordPress loop or outside of it. Can be used with |
|
665 * pages, posts, attachments, and revisions. |
|
666 * |
|
667 * @since 2.3.0 |
|
668 * |
|
669 * @param int $id Optional. Post ID. |
|
670 * @param string $context Optional, default to display. How to write the '&', defaults to '&'. |
|
671 * @return string |
|
672 */ |
|
673 function get_edit_post_link( $id = 0, $context = 'display' ) { |
|
674 if ( !$post = &get_post( $id ) ) |
|
675 return; |
|
676 |
|
677 if ( 'display' == $context ) |
|
678 $action = 'action=edit&'; |
|
679 else |
|
680 $action = 'action=edit&'; |
|
681 |
|
682 switch ( $post->post_type ) : |
|
683 case 'page' : |
|
684 if ( !current_user_can( 'edit_page', $post->ID ) ) |
|
685 return; |
|
686 $file = 'page'; |
|
687 $var = 'post'; |
|
688 break; |
|
689 case 'attachment' : |
|
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; |
|
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 } |
|
712 |
|
713 /** |
|
714 * Display edit post link for post. |
|
715 * |
|
716 * @since 1.0.0 |
|
717 * |
|
718 * @param string $link Optional. Anchor text. |
|
719 * @param string $before Optional. Display before edit link. |
|
720 * @param string $after Optional. Display after edit link. |
|
721 * @param int $id Optional. Post ID. |
|
722 */ |
|
723 function edit_post_link( $link = 'Edit This', $before = '', $after = '', $id = 0 ) { |
|
724 if ( !$post = &get_post( $id ) ) |
|
725 return; |
|
726 |
|
727 if ( !$url = get_edit_post_link( $post->ID ) ) |
|
728 return; |
|
729 |
|
730 $link = '<a class="post-edit-link" href="' . $url . '" title="' . esc_attr( __( 'Edit post' ) ) . '">' . $link . '</a>'; |
|
731 echo $before . apply_filters( 'edit_post_link', $link, $post->ID ) . $after; |
|
732 } |
|
733 |
|
734 /** |
|
735 * Retrieve edit comment link. |
|
736 * |
|
737 * @since 2.3.0 |
|
738 * |
|
739 * @param int $comment_id Optional. Comment ID. |
|
740 * @return string |
|
741 */ |
|
742 function get_edit_comment_link( $comment_id = 0 ) { |
|
743 $comment = &get_comment( $comment_id ); |
|
744 $post = &get_post( $comment->comment_post_ID ); |
|
745 |
|
746 if ( $post->post_type == 'page' ) { |
|
747 if ( !current_user_can( 'edit_page', $post->ID ) ) |
|
748 return; |
|
749 } else { |
|
750 if ( !current_user_can( 'edit_post', $post->ID ) ) |
|
751 return; |
|
752 } |
|
753 |
|
754 $location = admin_url('comment.php?action=editcomment&c=') . $comment->comment_ID; |
|
755 return apply_filters( 'get_edit_comment_link', $location ); |
|
756 } |
|
757 |
|
758 /** |
|
759 * Display or retrieve edit comment link with formatting. |
|
760 * |
|
761 * @since 1.0.0 |
|
762 * |
|
763 * @param string $link Optional. Anchor text. |
|
764 * @param string $before Optional. Display before edit link. |
|
765 * @param string $after Optional. Display after edit link. |
|
766 * @return string|null HTML content, if $echo is set to false. |
|
767 */ |
|
768 function edit_comment_link( $link = 'Edit This', $before = '', $after = '' ) { |
|
769 global $comment, $post; |
|
770 |
|
771 if ( $post->post_type == 'page' ) { |
|
772 if ( !current_user_can( 'edit_page', $post->ID ) ) |
|
773 return; |
|
774 } else { |
|
775 if ( !current_user_can( 'edit_post', $post->ID ) ) |
|
776 return; |
|
777 } |
|
778 |
|
779 $link = '<a class="comment-edit-link" href="' . get_edit_comment_link( $comment->comment_ID ) . '" title="' . __( 'Edit comment' ) . '">' . $link . '</a>'; |
|
780 echo $before . apply_filters( 'edit_comment_link', $link, $comment->comment_ID ) . $after; |
|
781 } |
|
782 |
|
783 /** |
|
784 * Display edit bookmark (literally a URL external to blog) link. |
|
785 * |
|
786 * @since 2.7.0 |
|
787 * |
|
788 * @param int $link Optional. Bookmark ID. |
|
789 * @return string |
|
790 */ |
|
791 function get_edit_bookmark_link( $link = 0 ) { |
|
792 $link = get_bookmark( $link ); |
|
793 |
|
794 if ( !current_user_can('manage_links') ) |
|
795 return; |
|
796 |
|
797 $location = admin_url('link.php?action=edit&link_id=') . $link->link_id; |
|
798 return apply_filters( 'get_edit_bookmark_link', $location, $link->link_id ); |
|
799 } |
|
800 |
|
801 /** |
|
802 * Display edit bookmark (literally a URL external to blog) link anchor content. |
|
803 * |
|
804 * @since 2.7.0 |
|
805 * |
|
806 * @param string $link Optional. Anchor text. |
|
807 * @param string $before Optional. Display before edit link. |
|
808 * @param string $after Optional. Display after edit link. |
|
809 * @param int $bookmark Optional. Bookmark ID. |
|
810 */ |
|
811 function edit_bookmark_link( $link = '', $before = '', $after = '', $bookmark = null ) { |
|
812 $bookmark = get_bookmark($bookmark); |
|
813 |
|
814 if ( !current_user_can('manage_links') ) |
|
815 return; |
|
816 |
|
817 if ( empty($link) ) |
|
818 $link = __('Edit This'); |
|
819 |
|
820 $link = '<a href="' . get_edit_bookmark_link( $link ) . '" title="' . __( 'Edit link' ) . '">' . $link . '</a>'; |
|
821 echo $before . apply_filters( 'edit_bookmark_link', $link, $bookmark->link_id ) . $after; |
|
822 } |
|
823 |
|
824 // Navigation links |
|
825 |
|
826 /** |
|
827 * Retrieve previous post link that is adjacent to current post. |
|
828 * |
|
829 * @since 1.5.0 |
|
830 * |
|
831 * @param bool $in_same_cat Optional. Whether link should be in same category. |
|
832 * @param string $excluded_categories Optional. Excluded categories IDs. |
|
833 * @return string |
|
834 */ |
|
835 function get_previous_post($in_same_cat = false, $excluded_categories = '') { |
|
836 return get_adjacent_post($in_same_cat, $excluded_categories); |
|
837 } |
|
838 |
|
839 /** |
|
840 * Retrieve next post link that is adjacent to current post. |
|
841 * |
|
842 * @since 1.5.0 |
|
843 * |
|
844 * @param bool $in_same_cat Optional. Whether link should be in same category. |
|
845 * @param string $excluded_categories Optional. Excluded categories IDs. |
|
846 * @return string |
|
847 */ |
|
848 function get_next_post($in_same_cat = false, $excluded_categories = '') { |
|
849 return get_adjacent_post($in_same_cat, $excluded_categories, false); |
|
850 } |
|
851 |
|
852 /** |
|
853 * Retrieve adjacent post link. |
|
854 * |
|
855 * Can either be next or previous post link. |
|
856 * |
|
857 * @since 2.5.0 |
|
858 * |
|
859 * @param bool $in_same_cat Optional. Whether link should be in same category. |
|
860 * @param string $excluded_categories Optional. Excluded categories IDs. |
|
861 * @param bool $previous Optional. Whether to retrieve previous post. |
|
862 * @return string |
|
863 */ |
|
864 function get_adjacent_post($in_same_cat = false, $excluded_categories = '', $previous = true) { |
|
865 global $post, $wpdb; |
|
866 |
|
867 if ( empty($post) || !is_single() || is_attachment() ) |
|
868 return null; |
|
869 |
|
870 $current_post_date = $post->post_date; |
|
871 |
|
872 $join = ''; |
|
873 $posts_in_ex_cats_sql = ''; |
|
874 if ( $in_same_cat || !empty($excluded_categories) ) { |
|
875 $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"; |
|
876 |
|
877 if ( $in_same_cat ) { |
|
878 $cat_array = wp_get_object_terms($post->ID, 'category', 'fields=ids'); |
|
879 $join .= " AND tt.taxonomy = 'category' AND tt.term_id IN (" . implode(',', $cat_array) . ")"; |
|
880 } |
|
881 |
|
882 $posts_in_ex_cats_sql = "AND tt.taxonomy = 'category'"; |
|
883 if ( !empty($excluded_categories) ) { |
|
884 $excluded_categories = array_map('intval', explode(' and ', $excluded_categories)); |
|
885 if ( !empty($cat_array) ) { |
|
886 $excluded_categories = array_diff($excluded_categories, $cat_array); |
|
887 $posts_in_ex_cats_sql = ''; |
|
888 } |
|
889 |
|
890 if ( !empty($excluded_categories) ) { |
|
891 $posts_in_ex_cats_sql = " AND tt.taxonomy = 'category' AND tt.term_id NOT IN (" . implode($excluded_categories, ',') . ')'; |
|
892 } |
|
893 } |
|
894 } |
|
895 |
|
896 $adjacent = $previous ? 'previous' : 'next'; |
|
897 $op = $previous ? '<' : '>'; |
|
898 $order = $previous ? 'DESC' : 'ASC'; |
|
899 |
|
900 $join = apply_filters( "get_{$adjacent}_post_join", $join, $in_same_cat, $excluded_categories ); |
|
901 $where = apply_filters( "get_{$adjacent}_post_where", $wpdb->prepare("WHERE p.post_date $op %s AND p.post_type = 'post' AND p.post_status = 'publish' $posts_in_ex_cats_sql", $current_post_date), $in_same_cat, $excluded_categories ); |
|
902 $sort = apply_filters( "get_{$adjacent}_post_sort", "ORDER BY p.post_date $order LIMIT 1" ); |
|
903 |
|
904 $query = "SELECT p.* FROM $wpdb->posts AS p $join $where $sort"; |
|
905 $query_key = 'adjacent_post_' . md5($query); |
|
906 $result = wp_cache_get($query_key, 'counts'); |
|
907 if ( false !== $result ) |
|
908 return $result; |
|
909 |
|
910 $result = $wpdb->get_row("SELECT p.* FROM $wpdb->posts AS p $join $where $sort"); |
|
911 if ( null === $result ) |
|
912 $result = ''; |
|
913 |
|
914 wp_cache_set($query_key, $result, 'counts'); |
|
915 return $result; |
|
916 } |
|
917 |
|
918 /** |
|
919 * Get adjacent post relational link. |
|
920 * |
|
921 * Can either be next or previous post relational link. |
|
922 * |
|
923 * @since 2.8.0 |
|
924 * |
|
925 * @param string $title Optional. Link title format. |
|
926 * @param bool $in_same_cat Optional. Whether link should be in same category. |
|
927 * @param string $excluded_categories Optional. Excluded categories IDs. |
|
928 * @param bool $previous Optional, default is true. Whether display link to previous post. |
|
929 * @return string |
|
930 */ |
|
931 function get_adjacent_post_rel_link($title = '%title', $in_same_cat = false, $excluded_categories = '', $previous = true) { |
|
932 if ( $previous && is_attachment() ) |
|
933 $post = & get_post($GLOBALS['post']->post_parent); |
|
934 else |
|
935 $post = get_adjacent_post($in_same_cat,$excluded_categories,$previous); |
|
936 |
|
937 if ( empty($post) ) |
|
938 return; |
|
939 |
|
940 if ( empty($post->post_title) ) |
|
941 $post->post_title = $previous ? __('Previous Post') : __('Next Post'); |
|
942 |
|
943 $date = mysql2date(get_option('date_format'), $post->post_date); |
|
944 |
|
945 $title = str_replace('%title', $post->post_title, $title); |
|
946 $title = str_replace('%date', $date, $title); |
|
947 $title = apply_filters('the_title', $title, $post); |
|
948 |
|
949 $link = $previous ? "<link rel='prev' title='" : "<link rel='next' title='"; |
|
950 $link .= esc_attr( $title ); |
|
951 $link .= "' href='" . get_permalink($post) . "' />\n"; |
|
952 |
|
953 $adjacent = $previous ? 'previous' : 'next'; |
|
954 return apply_filters( "{$adjacent}_post_rel_link", $link ); |
|
955 } |
|
956 |
|
957 /** |
|
958 * Display relational links for the posts adjacent to the current post. |
|
959 * |
|
960 * @since 2.8.0 |
|
961 * |
|
962 * @param string $title Optional. Link title format. |
|
963 * @param bool $in_same_cat Optional. Whether link should be in same category. |
|
964 * @param string $excluded_categories Optional. Excluded categories IDs. |
|
965 */ |
|
966 function adjacent_posts_rel_link($title = '%title', $in_same_cat = false, $excluded_categories = '') { |
|
967 echo get_adjacent_post_rel_link($title, $in_same_cat, $excluded_categories = '', true); |
|
968 echo get_adjacent_post_rel_link($title, $in_same_cat, $excluded_categories = '', false); |
|
969 } |
|
970 |
|
971 /** |
|
972 * Display relational link for the next post adjacent to the current post. |
|
973 * |
|
974 * @since 2.8.0 |
|
975 * |
|
976 * @param string $title Optional. Link title format. |
|
977 * @param bool $in_same_cat Optional. Whether link should be in same category. |
|
978 * @param string $excluded_categories Optional. Excluded categories IDs. |
|
979 */ |
|
980 function next_post_rel_link($title = '%title', $in_same_cat = false, $excluded_categories = '') { |
|
981 echo get_adjacent_post_rel_link($title, $in_same_cat, $excluded_categories = '', false); |
|
982 } |
|
983 |
|
984 /** |
|
985 * Display relational link for the previous post adjacent to the current post. |
|
986 * |
|
987 * @since 2.8.0 |
|
988 * |
|
989 * @param string $title Optional. Link title format. |
|
990 * @param bool $in_same_cat Optional. Whether link should be in same category. |
|
991 * @param string $excluded_categories Optional. Excluded categories IDs. |
|
992 */ |
|
993 function prev_post_rel_link($title = '%title', $in_same_cat = false, $excluded_categories = '') { |
|
994 echo get_adjacent_post_rel_link($title, $in_same_cat, $excluded_categories = '', true); |
|
995 } |
|
996 |
|
997 /** |
|
998 * Retrieve boundary post. |
|
999 * |
|
1000 * Boundary being either the first or last post by publish date within the contraitns specified |
|
1001 * by in same category or excluded categories. |
|
1002 * |
|
1003 * @since 2.8.0 |
|
1004 * |
|
1005 * @param bool $in_same_cat Optional. Whether returned post should be in same category. |
|
1006 * @param string $excluded_categories Optional. Excluded categories IDs. |
|
1007 * @param bool $previous Optional. Whether to retrieve first post. |
|
1008 * @return object |
|
1009 */ |
|
1010 function get_boundary_post($in_same_cat = false, $excluded_categories = '', $start = true) { |
|
1011 global $post, $wpdb; |
|
1012 |
|
1013 if ( empty($post) || !is_single() || is_attachment() ) |
|
1014 return null; |
|
1015 |
|
1016 $cat_array = array(); |
|
1017 $excluded_categories = array(); |
|
1018 if ( !empty($in_same_cat) || !empty($excluded_categories) ) { |
|
1019 if ( !empty($in_same_cat) ) { |
|
1020 $cat_array = wp_get_object_terms($post->ID, 'category', 'fields=ids'); |
|
1021 } |
|
1022 |
|
1023 if ( !empty($excluded_categories) ) { |
|
1024 $excluded_categories = array_map('intval', explode(',', $excluded_categories)); |
|
1025 |
|
1026 if ( !empty($cat_array) ) |
|
1027 $excluded_categories = array_diff($excluded_categories, $cat_array); |
|
1028 |
|
1029 $inverse_cats = array(); |
|
1030 foreach ( $excluded_categories as $excluded_category) |
|
1031 $inverse_cats[] = $excluded_category * -1; |
|
1032 $excluded_categories = $inverse_cats; |
|
1033 } |
|
1034 } |
|
1035 |
|
1036 $categories = implode(',', array_merge($cat_array, $excluded_categories) ); |
|
1037 |
|
1038 $order = $start ? 'ASC' : 'DESC'; |
|
1039 |
|
1040 return get_posts( array('numberposts' => 1, 'order' => $order, 'orderby' => 'ID', 'category' => $categories) ); |
|
1041 } |
|
1042 |
|
1043 /** |
|
1044 * Get boundary post relational link. |
|
1045 * |
|
1046 * Can either be start or end post relational link. |
|
1047 * |
|
1048 * @since 2.8.0 |
|
1049 * |
|
1050 * @param string $title Optional. Link title format. |
|
1051 * @param bool $in_same_cat Optional. Whether link should be in same category. |
|
1052 * @param string $excluded_categories Optional. Excluded categories IDs. |
|
1053 * @param bool $start Optional, default is true. Whether display link to first post. |
|
1054 * @return string |
|
1055 */ |
|
1056 function get_boundary_post_rel_link($title = '%title', $in_same_cat = false, $excluded_categories = '', $start = true) { |
|
1057 $posts = get_boundary_post($in_same_cat,$excluded_categories,$start); |
|
1058 // Even though we limited get_posts to return only 1 item it still returns an array of objects. |
|
1059 $post = $posts[0]; |
|
1060 |
|
1061 if ( empty($post) ) |
|
1062 return; |
|
1063 |
|
1064 if ( empty($post->post_title) ) |
|
1065 $post->post_title = $start ? __('First Post') : __('Last Post'); |
|
1066 |
|
1067 $date = mysql2date(get_option('date_format'), $post->post_date); |
|
1068 |
|
1069 $title = str_replace('%title', $post->post_title, $title); |
|
1070 $title = str_replace('%date', $date, $title); |
|
1071 $title = apply_filters('the_title', $title, $post); |
|
1072 |
|
1073 $link = $start ? "<link rel='start' title='" : "<link rel='end' title='"; |
|
1074 $link .= esc_attr($title); |
|
1075 $link .= "' href='" . get_permalink($post) . "' />\n"; |
|
1076 |
|
1077 $boundary = $start ? 'start' : 'end'; |
|
1078 return apply_filters( "{$boundary}_post_rel_link", $link ); |
|
1079 } |
|
1080 |
|
1081 /** |
|
1082 * Display relational link for the first post. |
|
1083 * |
|
1084 * @since 2.8.0 |
|
1085 * |
|
1086 * @param string $title Optional. Link title format. |
|
1087 * @param bool $in_same_cat Optional. Whether link should be in same category. |
|
1088 * @param string $excluded_categories Optional. Excluded categories IDs. |
|
1089 */ |
|
1090 function start_post_rel_link($title = '%title', $in_same_cat = false, $excluded_categories = '') { |
|
1091 echo get_boundary_post_rel_link($title, $in_same_cat, $excluded_categories, true); |
|
1092 } |
|
1093 |
|
1094 /** |
|
1095 * Get site index relational link. |
|
1096 * |
|
1097 * @since 2.8.0 |
|
1098 * |
|
1099 * @return string |
|
1100 */ |
|
1101 function get_index_rel_link() { |
|
1102 $link = "<link rel='index' title='" . esc_attr(get_bloginfo('name')) . "' href='" . get_bloginfo('siteurl') . "' />\n"; |
|
1103 return apply_filters( "index_rel_link", $link ); |
|
1104 } |
|
1105 |
|
1106 /** |
|
1107 * Display relational link for the site index. |
|
1108 * |
|
1109 * @since 2.8.0 |
|
1110 */ |
|
1111 function index_rel_link() { |
|
1112 echo get_index_rel_link(); |
|
1113 } |
|
1114 |
|
1115 /** |
|
1116 * Get parent post relational link. |
|
1117 * |
|
1118 * @since 2.8.0 |
|
1119 * |
|
1120 * @param string $title Optional. Link title format. |
|
1121 * @return string |
|
1122 */ |
|
1123 function get_parent_post_rel_link($title = '%title') { |
|
1124 if ( ! empty( $GLOBALS['post'] ) && ! empty( $GLOBALS['post']->post_parent ) ) |
|
1125 $post = & get_post($GLOBALS['post']->post_parent); |
|
1126 |
|
1127 if ( empty($post) ) |
|
1128 return; |
|
1129 |
|
1130 $date = mysql2date(get_option('date_format'), $post->post_date); |
|
1131 |
|
1132 $title = str_replace('%title', $post->post_title, $title); |
|
1133 $title = str_replace('%date', $date, $title); |
|
1134 $title = apply_filters('the_title', $title, $post); |
|
1135 |
|
1136 $link = "<link rel='up' title='"; |
|
1137 $link .= esc_attr( $title ); |
|
1138 $link .= "' href='" . get_permalink($post) . "' />\n"; |
|
1139 |
|
1140 return apply_filters( "parent_post_rel_link", $link ); |
|
1141 } |
|
1142 |
|
1143 /** |
|
1144 * Display relational link for parent item |
|
1145 * |
|
1146 * @since 2.8.0 |
|
1147 */ |
|
1148 function parent_post_rel_link($title = '%title') { |
|
1149 echo get_parent_post_rel_link($title); |
|
1150 } |
|
1151 |
|
1152 /** |
|
1153 * Display previous post link that is adjacent to the current post. |
|
1154 * |
|
1155 * @since 1.5.0 |
|
1156 * |
|
1157 * @param string $format Optional. Link anchor format. |
|
1158 * @param string $link Optional. Link permalink format. |
|
1159 * @param bool $in_same_cat Optional. Whether link should be in same category. |
|
1160 * @param string $excluded_categories Optional. Excluded categories IDs. |
|
1161 */ |
|
1162 function previous_post_link($format='« %link', $link='%title', $in_same_cat = false, $excluded_categories = '') { |
|
1163 adjacent_post_link($format, $link, $in_same_cat, $excluded_categories, true); |
|
1164 } |
|
1165 |
|
1166 /** |
|
1167 * Display next post link that is adjacent to the current post. |
|
1168 * |
|
1169 * @since 1.5.0 |
|
1170 * |
|
1171 * @param string $format Optional. Link anchor format. |
|
1172 * @param string $link Optional. Link permalink format. |
|
1173 * @param bool $in_same_cat Optional. Whether link should be in same category. |
|
1174 * @param string $excluded_categories Optional. Excluded categories IDs. |
|
1175 */ |
|
1176 function next_post_link($format='%link »', $link='%title', $in_same_cat = false, $excluded_categories = '') { |
|
1177 adjacent_post_link($format, $link, $in_same_cat, $excluded_categories, false); |
|
1178 } |
|
1179 |
|
1180 /** |
|
1181 * Display adjacent post link. |
|
1182 * |
|
1183 * Can be either next post link or previous. |
|
1184 * |
|
1185 * @since 2.5.0 |
|
1186 * |
|
1187 * @param string $format Link anchor format. |
|
1188 * @param string $link Link permalink format. |
|
1189 * @param bool $in_same_cat Optional. Whether link should be in same category. |
|
1190 * @param string $excluded_categories Optional. Excluded categories IDs. |
|
1191 * @param bool $previous Optional, default is true. Whether display link to previous post. |
|
1192 */ |
|
1193 function adjacent_post_link($format, $link, $in_same_cat = false, $excluded_categories = '', $previous = true) { |
|
1194 if ( $previous && is_attachment() ) |
|
1195 $post = & get_post($GLOBALS['post']->post_parent); |
|
1196 else |
|
1197 $post = get_adjacent_post($in_same_cat, $excluded_categories, $previous); |
|
1198 |
|
1199 if ( !$post ) |
|
1200 return; |
|
1201 |
|
1202 $title = $post->post_title; |
|
1203 |
|
1204 if ( empty($post->post_title) ) |
|
1205 $title = $previous ? __('Previous Post') : __('Next Post'); |
|
1206 |
|
1207 $title = apply_filters('the_title', $title, $post); |
|
1208 $date = mysql2date(get_option('date_format'), $post->post_date); |
|
1209 |
|
1210 $string = '<a href="'.get_permalink($post).'">'; |
|
1211 $link = str_replace('%title', $title, $link); |
|
1212 $link = str_replace('%date', $date, $link); |
|
1213 $link = $string . $link . '</a>'; |
|
1214 |
|
1215 $format = str_replace('%link', $link, $format); |
|
1216 |
|
1217 $adjacent = $previous ? 'previous' : 'next'; |
|
1218 echo apply_filters( "{$adjacent}_post_link", $format, $link ); |
|
1219 } |
|
1220 |
|
1221 /** |
|
1222 * Retrieve get links for page numbers. |
|
1223 * |
|
1224 * @since 1.5.0 |
|
1225 * |
|
1226 * @param int $pagenum Optional. Page ID. |
|
1227 * @return string |
|
1228 */ |
|
1229 function get_pagenum_link($pagenum = 1) { |
|
1230 global $wp_rewrite; |
|
1231 |
|
1232 $pagenum = (int) $pagenum; |
|
1233 |
|
1234 $request = remove_query_arg( 'paged' ); |
|
1235 |
|
1236 $home_root = parse_url(get_option('home')); |
|
1237 $home_root = ( isset($home_root['path']) ) ? $home_root['path'] : ''; |
|
1238 $home_root = preg_quote( trailingslashit( $home_root ), '|' ); |
|
1239 |
|
1240 $request = preg_replace('|^'. $home_root . '|', '', $request); |
|
1241 $request = preg_replace('|^/+|', '', $request); |
|
1242 |
|
1243 if ( !$wp_rewrite->using_permalinks() || is_admin() ) { |
|
1244 $base = trailingslashit( get_bloginfo( 'home' ) ); |
|
1245 |
|
1246 if ( $pagenum > 1 ) { |
|
1247 $result = add_query_arg( 'paged', $pagenum, $base . $request ); |
|
1248 } else { |
|
1249 $result = $base . $request; |
|
1250 } |
|
1251 } else { |
|
1252 $qs_regex = '|\?.*?$|'; |
|
1253 preg_match( $qs_regex, $request, $qs_match ); |
|
1254 |
|
1255 if ( !empty( $qs_match[0] ) ) { |
|
1256 $query_string = $qs_match[0]; |
|
1257 $request = preg_replace( $qs_regex, '', $request ); |
|
1258 } else { |
|
1259 $query_string = ''; |
|
1260 } |
|
1261 |
|
1262 $request = preg_replace( '|page/\d+/?$|', '', $request); |
|
1263 $request = preg_replace( '|^index\.php|', '', $request); |
|
1264 $request = ltrim($request, '/'); |
|
1265 |
|
1266 $base = trailingslashit( get_bloginfo( 'url' ) ); |
|
1267 |
|
1268 if ( $wp_rewrite->using_index_permalinks() && ( $pagenum > 1 || '' != $request ) ) |
|
1269 $base .= 'index.php/'; |
|
1270 |
|
1271 if ( $pagenum > 1 ) { |
|
1272 $request = ( ( !empty( $request ) ) ? trailingslashit( $request ) : $request ) . user_trailingslashit( 'page/' . $pagenum, 'paged' ); |
|
1273 } |
|
1274 |
|
1275 $result = $base . $request . $query_string; |
|
1276 } |
|
1277 |
|
1278 $result = apply_filters('get_pagenum_link', $result); |
|
1279 |
|
1280 return $result; |
|
1281 } |
|
1282 |
|
1283 /** |
|
1284 * Retrieve next posts pages link. |
|
1285 * |
|
1286 * Backported from 2.1.3 to 2.0.10. |
|
1287 * |
|
1288 * @since 2.0.10 |
|
1289 * |
|
1290 * @param int $max_page Optional. Max pages. |
|
1291 * @return string |
|
1292 */ |
|
1293 function get_next_posts_page_link($max_page = 0) { |
|
1294 global $paged; |
|
1295 |
|
1296 if ( !is_single() ) { |
|
1297 if ( !$paged ) |
|
1298 $paged = 1; |
|
1299 $nextpage = intval($paged) + 1; |
|
1300 if ( !$max_page || $max_page >= $nextpage ) |
|
1301 return get_pagenum_link($nextpage); |
|
1302 } |
|
1303 } |
|
1304 |
|
1305 /** |
|
1306 * Display or return the next posts pages link. |
|
1307 * |
|
1308 * @since 0.71 |
|
1309 * |
|
1310 * @param int $max_page Optional. Max pages. |
|
1311 * @param boolean $echo Optional. Echo or return; |
|
1312 */ |
|
1313 function next_posts( $max_page = 0, $echo = true ) { |
|
1314 $output = esc_url( get_next_posts_page_link( $max_page ) ); |
|
1315 |
|
1316 if ( $echo ) |
|
1317 echo $output; |
|
1318 else |
|
1319 return $output; |
|
1320 } |
|
1321 |
|
1322 /** |
|
1323 * Return the next posts pages link. |
|
1324 * |
|
1325 * @since 2.7.0 |
|
1326 * |
|
1327 * @param string $label Content for link text. |
|
1328 * @param int $max_page Optional. Max pages. |
|
1329 * @return string|null |
|
1330 */ |
|
1331 function get_next_posts_link( $label = 'Next Page »', $max_page = 0 ) { |
|
1332 global $paged, $wp_query; |
|
1333 |
|
1334 if ( !$max_page ) { |
|
1335 $max_page = $wp_query->max_num_pages; |
|
1336 } |
|
1337 |
|
1338 if ( !$paged ) |
|
1339 $paged = 1; |
|
1340 |
|
1341 $nextpage = intval($paged) + 1; |
|
1342 |
|
1343 if ( !is_single() && ( empty($paged) || $nextpage <= $max_page) ) { |
|
1344 $attr = apply_filters( 'next_posts_link_attributes', '' ); |
|
1345 return '<a href="' . next_posts( $max_page, false ) . "\" $attr>". preg_replace('/&([^#])(?![a-z]{1,8};)/', '&$1', $label) .'</a>'; |
|
1346 } |
|
1347 } |
|
1348 |
|
1349 /** |
|
1350 * Display the next posts pages link. |
|
1351 * |
|
1352 * @since 0.71 |
|
1353 * @uses get_next_posts_link() |
|
1354 * |
|
1355 * @param string $label Content for link text. |
|
1356 * @param int $max_page Optional. Max pages. |
|
1357 */ |
|
1358 function next_posts_link( $label = 'Next Page »', $max_page = 0 ) { |
|
1359 echo get_next_posts_link( $label, $max_page ); |
|
1360 } |
|
1361 |
|
1362 /** |
|
1363 * Retrieve previous post pages link. |
|
1364 * |
|
1365 * Will only return string, if not on a single page or post. |
|
1366 * |
|
1367 * Backported to 2.0.10 from 2.1.3. |
|
1368 * |
|
1369 * @since 2.0.10 |
|
1370 * |
|
1371 * @return string|null |
|
1372 */ |
|
1373 function get_previous_posts_page_link() { |
|
1374 global $paged; |
|
1375 |
|
1376 if ( !is_single() ) { |
|
1377 $nextpage = intval($paged) - 1; |
|
1378 if ( $nextpage < 1 ) |
|
1379 $nextpage = 1; |
|
1380 return get_pagenum_link($nextpage); |
|
1381 } |
|
1382 } |
|
1383 |
|
1384 /** |
|
1385 * Display or return the previous posts pages link. |
|
1386 * |
|
1387 * @since 0.71 |
|
1388 * |
|
1389 * @param boolean $echo Optional. Echo or return; |
|
1390 */ |
|
1391 function previous_posts( $echo = true ) { |
|
1392 $output = esc_url( get_previous_posts_page_link() ); |
|
1393 |
|
1394 if ( $echo ) |
|
1395 echo $output; |
|
1396 else |
|
1397 return $output; |
|
1398 } |
|
1399 |
|
1400 /** |
|
1401 * Return the previous posts pages link. |
|
1402 * |
|
1403 * @since 2.7.0 |
|
1404 * |
|
1405 * @param string $label Optional. Previous page link text. |
|
1406 * @return string|null |
|
1407 */ |
|
1408 function get_previous_posts_link( $label = '« Previous Page' ) { |
|
1409 global $paged; |
|
1410 |
|
1411 if ( !is_single() && $paged > 1 ) { |
|
1412 $attr = apply_filters( 'previous_posts_link_attributes', '' ); |
|
1413 return '<a href="' . previous_posts( false ) . "\" $attr>". preg_replace( '/&([^#])(?![a-z]{1,8};)/', '&$1', $label ) .'</a>'; |
|
1414 } |
|
1415 } |
|
1416 |
|
1417 /** |
|
1418 * Display the previous posts page link. |
|
1419 * |
|
1420 * @since 0.71 |
|
1421 * @uses get_previous_posts_link() |
|
1422 * |
|
1423 * @param string $label Optional. Previous page link text. |
|
1424 */ |
|
1425 function previous_posts_link( $label = '« Previous Page' ) { |
|
1426 echo get_previous_posts_link( $label ); |
|
1427 } |
|
1428 |
|
1429 /** |
|
1430 * Return post pages link navigation for previous and next pages. |
|
1431 * |
|
1432 * @since 2.8 |
|
1433 * |
|
1434 * @param string|array $args Optional args. |
|
1435 * @return string The posts link navigation. |
|
1436 */ |
|
1437 function get_posts_nav_link( $args = array() ) { |
|
1438 global $wp_query; |
|
1439 |
|
1440 $return = ''; |
|
1441 |
|
1442 if ( !is_singular() ) { |
|
1443 $defaults = array( |
|
1444 'sep' => ' — ', |
|
1445 'prelabel' => __('« Previous Page'), |
|
1446 'nxtlabel' => __('Next Page »'), |
|
1447 ); |
|
1448 $args = wp_parse_args( $args, $defaults ); |
|
1449 |
|
1450 $max_num_pages = $wp_query->max_num_pages; |
|
1451 $paged = get_query_var('paged'); |
|
1452 |
|
1453 //only have sep if there's both prev and next results |
|
1454 if ($paged < 2 || $paged >= $max_num_pages) { |
|
1455 $args['sep'] = ''; |
|
1456 } |
|
1457 |
|
1458 if ( $max_num_pages > 1 ) { |
|
1459 $return = get_previous_posts_link($args['prelabel']); |
|
1460 $return .= preg_replace('/&([^#])(?![a-z]{1,8};)/', '&$1', $args['sep']); |
|
1461 $return .= get_next_posts_link($args['nxtlabel']); |
|
1462 } |
|
1463 } |
|
1464 return $return; |
|
1465 |
|
1466 } |
|
1467 |
|
1468 /** |
|
1469 * Display post pages link navigation for previous and next pages. |
|
1470 * |
|
1471 * @since 0.71 |
|
1472 * |
|
1473 * @param string $sep Optional. Separator for posts navigation links. |
|
1474 * @param string $prelabel Optional. Label for previous pages. |
|
1475 * @param string $nxtlabel Optional Label for next pages. |
|
1476 */ |
|
1477 function posts_nav_link( $sep = '', $prelabel = '', $nxtlabel = '' ) { |
|
1478 $args = array_filter( compact('sep', 'prelabel', 'nxtlabel') ); |
|
1479 echo get_posts_nav_link($args); |
|
1480 } |
|
1481 |
|
1482 /** |
|
1483 * Retrieve page numbers links. |
|
1484 * |
|
1485 * @since 2.7.0 |
|
1486 * |
|
1487 * @param int $pagenum Optional. Page number. |
|
1488 * @return string |
|
1489 */ |
|
1490 function get_comments_pagenum_link( $pagenum = 1, $max_page = 0 ) { |
|
1491 global $post, $wp_rewrite; |
|
1492 |
|
1493 $pagenum = (int) $pagenum; |
|
1494 |
|
1495 $result = get_permalink( $post->ID ); |
|
1496 |
|
1497 if ( 'newest' == get_option('default_comments_page') ) { |
|
1498 if ( $pagenum != $max_page ) { |
|
1499 if ( $wp_rewrite->using_permalinks() ) |
|
1500 $result = user_trailingslashit( trailingslashit($result) . 'comment-page-' . $pagenum, 'commentpaged'); |
|
1501 else |
|
1502 $result = add_query_arg( 'cpage', $pagenum, $result ); |
|
1503 } |
|
1504 } elseif ( $pagenum > 1 ) { |
|
1505 if ( $wp_rewrite->using_permalinks() ) |
|
1506 $result = user_trailingslashit( trailingslashit($result) . 'comment-page-' . $pagenum, 'commentpaged'); |
|
1507 else |
|
1508 $result = add_query_arg( 'cpage', $pagenum, $result ); |
|
1509 } |
|
1510 |
|
1511 $result .= '#comments'; |
|
1512 |
|
1513 $result = apply_filters('get_comments_pagenum_link', $result); |
|
1514 |
|
1515 return $result; |
|
1516 } |
|
1517 |
|
1518 /** |
|
1519 * Return the link to next comments pages. |
|
1520 * |
|
1521 * @since 2.7.1 |
|
1522 * |
|
1523 * @param string $label Optional. Label for link text. |
|
1524 * @param int $max_page Optional. Max page. |
|
1525 * @return string|null |
|
1526 */ |
|
1527 function get_next_comments_link( $label = '', $max_page = 0 ) { |
|
1528 global $wp_query; |
|
1529 |
|
1530 if ( !is_singular() || !get_option('page_comments') ) |
|
1531 return; |
|
1532 |
|
1533 $page = get_query_var('cpage'); |
|
1534 |
|
1535 $nextpage = intval($page) + 1; |
|
1536 |
|
1537 if ( empty($max_page) ) |
|
1538 $max_page = $wp_query->max_num_comment_pages; |
|
1539 |
|
1540 if ( empty($max_page) ) |
|
1541 $max_page = get_comment_pages_count(); |
|
1542 |
|
1543 if ( $nextpage > $max_page ) |
|
1544 return; |
|
1545 |
|
1546 if ( empty($label) ) |
|
1547 $label = __('Newer Comments »'); |
|
1548 |
|
1549 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>'; |
|
1550 } |
|
1551 |
|
1552 /** |
|
1553 * Display the link to next comments pages. |
|
1554 * |
|
1555 * @since 2.7.0 |
|
1556 * |
|
1557 * @param string $label Optional. Label for link text. |
|
1558 * @param int $max_page Optional. Max page. |
|
1559 */ |
|
1560 function next_comments_link( $label = '', $max_page = 0 ) { |
|
1561 echo get_next_comments_link( $label, $max_page ); |
|
1562 } |
|
1563 |
|
1564 /** |
|
1565 * Return the previous comments page link. |
|
1566 * |
|
1567 * @since 2.7.1 |
|
1568 * |
|
1569 * @param string $label Optional. Label for comments link text. |
|
1570 * @return string|null |
|
1571 */ |
|
1572 function get_previous_comments_link( $label = '' ) { |
|
1573 if ( !is_singular() || !get_option('page_comments') ) |
|
1574 return; |
|
1575 |
|
1576 $page = get_query_var('cpage'); |
|
1577 |
|
1578 if ( intval($page) <= 1 ) |
|
1579 return; |
|
1580 |
|
1581 $prevpage = intval($page) - 1; |
|
1582 |
|
1583 if ( empty($label) ) |
|
1584 $label = __('« Older Comments'); |
|
1585 |
|
1586 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>'; |
|
1587 } |
|
1588 |
|
1589 /** |
|
1590 * Display the previous comments page link. |
|
1591 * |
|
1592 * @since 2.7.0 |
|
1593 * |
|
1594 * @param string $label Optional. Label for comments link text. |
|
1595 */ |
|
1596 function previous_comments_link( $label = '' ) { |
|
1597 echo get_previous_comments_link( $label ); |
|
1598 } |
|
1599 |
|
1600 /** |
|
1601 * Create pagination links for the comments on the current post. |
|
1602 * |
|
1603 * @see paginate_links() |
|
1604 * @since 2.7.0 |
|
1605 * |
|
1606 * @param string|array $args Optional args. See paginate_links. |
|
1607 * @return string Markup for pagination links. |
|
1608 */ |
|
1609 function paginate_comments_links($args = array()) { |
|
1610 global $wp_query, $wp_rewrite; |
|
1611 |
|
1612 if ( !is_singular() || !get_option('page_comments') ) |
|
1613 return; |
|
1614 |
|
1615 $page = get_query_var('cpage'); |
|
1616 if ( !$page ) |
|
1617 $page = 1; |
|
1618 $max_page = get_comment_pages_count(); |
|
1619 $defaults = array( |
|
1620 'base' => add_query_arg( 'cpage', '%#%' ), |
|
1621 'format' => '', |
|
1622 'total' => $max_page, |
|
1623 'current' => $page, |
|
1624 'echo' => true, |
|
1625 'add_fragment' => '#comments' |
|
1626 ); |
|
1627 if ( $wp_rewrite->using_permalinks() ) |
|
1628 $defaults['base'] = user_trailingslashit(trailingslashit(get_permalink()) . 'comment-page-%#%', 'commentpaged'); |
|
1629 |
|
1630 $args = wp_parse_args( $args, $defaults ); |
|
1631 $page_links = paginate_links( $args ); |
|
1632 |
|
1633 if ( $args['echo'] ) |
|
1634 echo $page_links; |
|
1635 else |
|
1636 return $page_links; |
|
1637 } |
|
1638 |
|
1639 /** |
|
1640 * Retrieve shortcut link. |
|
1641 * |
|
1642 * Use this in 'a' element 'href' attribute. |
|
1643 * |
|
1644 * @since 2.6.0 |
|
1645 * |
|
1646 * @return string |
|
1647 */ |
|
1648 function get_shortcut_link() { |
|
1649 $link = "javascript: |
|
1650 var d=document, |
|
1651 w=window, |
|
1652 e=w.getSelection, |
|
1653 k=d.getSelection, |
|
1654 x=d.selection, |
|
1655 s=(e?e():(k)?k():(x?x.createRange().text:0)), |
|
1656 f='" . admin_url('press-this.php') . "', |
|
1657 l=d.location, |
|
1658 e=encodeURIComponent, |
|
1659 g=f+'?u='+e(l.href)+'&t='+e(d.title)+'&s='+e(s)+'&v=2'; |
|
1660 function a(){ |
|
1661 if(!w.open(g,'t','toolbar=0,resizable=0,scrollbars=1,status=1,width=720,height=570')){ |
|
1662 l.href=g; |
|
1663 } |
|
1664 }"; |
|
1665 if (strpos($_SERVER['HTTP_USER_AGENT'], 'Firefox') !== false) |
|
1666 $link .= 'setTimeout(a,0);'; |
|
1667 else |
|
1668 $link .= 'a();'; |
|
1669 |
|
1670 $link .= "void(0);"; |
|
1671 |
|
1672 $link = str_replace(array("\r", "\n", "\t"), '', $link); |
|
1673 |
|
1674 return apply_filters('shortcut_link', $link); |
|
1675 } |
|
1676 |
|
1677 /** |
|
1678 * Retrieve the site url. |
|
1679 * |
|
1680 * Returns the 'site_url' option with the appropriate protocol, 'https' if |
|
1681 * is_ssl() and 'http' otherwise. If $scheme is 'http' or 'https', is_ssl() is |
|
1682 * overridden. |
|
1683 * |
|
1684 * @package WordPress |
|
1685 * @since 2.6.0 |
|
1686 * |
|
1687 * @param string $path Optional. Path relative to the site url. |
|
1688 * @param string $scheme Optional. Scheme to give the site url context. Currently 'http','https', 'login', 'login_post', or 'admin'. |
|
1689 * @return string Site url link with optional path appended. |
|
1690 */ |
|
1691 function site_url($path = '', $scheme = null) { |
|
1692 // should the list of allowed schemes be maintained elsewhere? |
|
1693 $orig_scheme = $scheme; |
|
1694 if ( !in_array($scheme, array('http', 'https')) ) { |
|
1695 if ( ( 'login_post' == $scheme || 'rpc' == $scheme ) && ( force_ssl_login() || force_ssl_admin() ) ) |
|
1696 $scheme = 'https'; |
|
1697 elseif ( ('login' == $scheme) && ( force_ssl_admin() ) ) |
|
1698 $scheme = 'https'; |
|
1699 elseif ( ('admin' == $scheme) && force_ssl_admin() ) |
|
1700 $scheme = 'https'; |
|
1701 else |
|
1702 $scheme = ( is_ssl() ? 'https' : 'http' ); |
|
1703 } |
|
1704 |
|
1705 $url = str_replace( 'http://', "{$scheme}://", get_option('siteurl') ); |
|
1706 |
|
1707 if ( !empty($path) && is_string($path) && strpos($path, '..') === false ) |
|
1708 $url .= '/' . ltrim($path, '/'); |
|
1709 |
|
1710 return apply_filters('site_url', $url, $path, $orig_scheme); |
|
1711 } |
|
1712 |
|
1713 /** |
|
1714 * Retrieve the url to the admin area. |
|
1715 * |
|
1716 * @package WordPress |
|
1717 * @since 2.6.0 |
|
1718 * |
|
1719 * @param string $path Optional path relative to the admin url |
|
1720 * @return string Admin url link with optional path appended |
|
1721 */ |
|
1722 function admin_url($path = '') { |
|
1723 $url = site_url('wp-admin/', 'admin'); |
|
1724 |
|
1725 if ( !empty($path) && is_string($path) && strpos($path, '..') === false ) |
|
1726 $url .= ltrim($path, '/'); |
|
1727 |
|
1728 return apply_filters('admin_url', $url, $path); |
|
1729 } |
|
1730 |
|
1731 /** |
|
1732 * Retrieve the url to the includes directory. |
|
1733 * |
|
1734 * @package WordPress |
|
1735 * @since 2.6.0 |
|
1736 * |
|
1737 * @param string $path Optional. Path relative to the includes url. |
|
1738 * @return string Includes url link with optional path appended. |
|
1739 */ |
|
1740 function includes_url($path = '') { |
|
1741 $url = site_url() . '/' . WPINC . '/'; |
|
1742 |
|
1743 if ( !empty($path) && is_string($path) && strpos($path, '..') === false ) |
|
1744 $url .= ltrim($path, '/'); |
|
1745 |
|
1746 return apply_filters('includes_url', $url, $path); |
|
1747 } |
|
1748 |
|
1749 /** |
|
1750 * Retrieve the url to the content directory. |
|
1751 * |
|
1752 * @package WordPress |
|
1753 * @since 2.6.0 |
|
1754 * |
|
1755 * @param string $path Optional. Path relative to the content url. |
|
1756 * @return string Content url link with optional path appended. |
|
1757 */ |
|
1758 function content_url($path = '') { |
|
1759 $scheme = ( is_ssl() ? 'https' : 'http' ); |
|
1760 $url = WP_CONTENT_URL; |
|
1761 if ( 0 === strpos($url, 'http') ) { |
|
1762 if ( is_ssl() ) |
|
1763 $url = str_replace( 'http://', "{$scheme}://", $url ); |
|
1764 } |
|
1765 |
|
1766 if ( !empty($path) && is_string($path) && strpos($path, '..') === false ) |
|
1767 $url .= '/' . ltrim($path, '/'); |
|
1768 |
|
1769 return apply_filters('content_url', $url, $path); |
|
1770 } |
|
1771 |
|
1772 /** |
|
1773 * Retrieve the url to the plugins directory or to a specific file within that directory. |
|
1774 * You can hardcode the plugin slug in $path or pass __FILE__ as a second argument to get the correct folder name. |
|
1775 * |
|
1776 * @package WordPress |
|
1777 * @since 2.6.0 |
|
1778 * |
|
1779 * @param string $path Optional. Path relative to the plugins url. |
|
1780 * @param string $plugin Optional. The plugin file that you want to be relative to - i.e. pass in __FILE__ |
|
1781 * @return string Plugins url link with optional path appended. |
|
1782 */ |
|
1783 function plugins_url($path = '', $plugin = '') { |
|
1784 $scheme = ( is_ssl() ? 'https' : 'http' ); |
|
1785 |
|
1786 if ( $plugin !== '' && preg_match('#^' . preg_quote(WPMU_PLUGIN_DIR . DIRECTORY_SEPARATOR, '#') . '#', $plugin) ) { |
|
1787 $url = WPMU_PLUGIN_URL; |
|
1788 } else { |
|
1789 $url = WP_PLUGIN_URL; |
|
1790 } |
|
1791 |
|
1792 if ( 0 === strpos($url, 'http') ) { |
|
1793 if ( is_ssl() ) |
|
1794 $url = str_replace( 'http://', "{$scheme}://", $url ); |
|
1795 } |
|
1796 |
|
1797 if ( !empty($plugin) && is_string($plugin) ) { |
|
1798 $folder = dirname(plugin_basename($plugin)); |
|
1799 if ('.' != $folder) |
|
1800 $url .= '/' . ltrim($folder, '/'); |
|
1801 } |
|
1802 |
|
1803 if ( !empty($path) && is_string($path) && strpos($path, '..') === false ) |
|
1804 $url .= '/' . ltrim($path, '/'); |
|
1805 |
|
1806 return apply_filters('plugins_url', $url, $path, $plugin); |
|
1807 } |
|
1808 |
|
1809 ?> |