]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-includes/link-template.php
Wordpress 2.7.1-scripts
[autoinstalls/wordpress.git] / wp-includes / link-template.php
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         else
98                 $post = &get_post($id);
99
100         if ( empty($post->ID) ) return false;
101
102         if ( $post->post_type == 'page' )
103                 return get_page_link($post->ID, $leavename);
104         elseif ($post->post_type == 'attachment')
105                 return get_attachment_link($post->ID);
106
107         $permalink = get_option('permalink_structure');
108
109         if ( '' != $permalink && !in_array($post->post_status, array('draft', 'pending')) ) {
110                 $unixtime = strtotime($post->post_date);
111
112                 $category = '';
113                 if ( strpos($permalink, '%category%') !== false ) {
114                         $cats = get_the_category($post->ID);
115                         if ( $cats ) {
116                                 usort($cats, '_usort_terms_by_ID'); // order by ID
117                                 $category = $cats[0]->slug;
118                                 if ( $parent = $cats[0]->parent )
119                                         $category = get_category_parents($parent, false, '/', true) . $category;
120                         }
121                         // show default category in permalinks, without
122                         // having to assign it explicitly
123                         if ( empty($category) ) {
124                                 $default_category = get_category( get_option( 'default_category' ) );
125                                 $category = is_wp_error( $default_category ) ? '' : $default_category->slug;
126                         }
127                 }
128
129                 $author = '';
130                 if ( strpos($permalink, '%author%') !== false ) {
131                         $authordata = get_userdata($post->post_author);
132                         $author = $authordata->user_nicename;
133                 }
134
135                 $date = explode(" ",date('Y m d H i s', $unixtime));
136                 $rewritereplace =
137                 array(
138                         $date[0],
139                         $date[1],
140                         $date[2],
141                         $date[3],
142                         $date[4],
143                         $date[5],
144                         $post->post_name,
145                         $post->ID,
146                         $category,
147                         $author,
148                         $post->post_name,
149                 );
150                 $permalink = get_option('home') . str_replace($rewritecode, $rewritereplace, $permalink);
151                 $permalink = user_trailingslashit($permalink, 'single');
152                 return apply_filters('post_link', $permalink, $post, $leavename);
153         } else { // if they're not using the fancy permalink option
154                 $permalink = get_option('home') . '/?p=' . $post->ID;
155                 return apply_filters('post_link', $permalink, $post, $leavename);
156         }
157 }
158
159 /**
160  * Retrieve permalink from post ID.
161  *
162  * @since 1.0.0
163  *
164  * @param int $post_id Optional. Post ID.
165  * @param mixed $deprecated Not used.
166  * @return string
167  */
168 function post_permalink($post_id = 0, $deprecated = '') {
169         return get_permalink($post_id);
170 }
171
172 /**
173  * Retrieve the permalink for current page or page ID.
174  *
175  * Respects page_on_front. Use this one.
176  *
177  * @since 1.5.0
178  *
179  * @param int $id Optional. Post ID.
180  * @param bool $leavename Optional, defaults to false. Whether to keep post name or page name.
181  * @return string
182  */
183 function get_page_link($id = false, $leavename = false) {
184         global $post;
185
186         $id = (int) $id;
187         if ( !$id )
188                 $id = (int) $post->ID;
189
190         if ( 'page' == get_option('show_on_front') && $id == get_option('page_on_front') )
191                 $link = get_option('home');
192         else
193                 $link = _get_page_link( $id , $leavename );
194
195         return apply_filters('page_link', $link, $id);
196 }
197
198 /**
199  * Retrieve the page permalink.
200  *
201  * Ignores page_on_front. Internal use only.
202  *
203  * @since 2.1.0
204  * @access private
205  *
206  * @param int $id Optional. Post ID.
207  * @param bool $leavename Optional. Leave name.
208  * @return string
209  */
210 function _get_page_link( $id = false, $leavename = false ) {
211         global $post, $wp_rewrite;
212
213         if ( !$id )
214                 $id = (int) $post->ID;
215         else
216                 $post = &get_post($id);
217
218         $pagestruct = $wp_rewrite->get_page_permastruct();
219
220         if ( '' != $pagestruct && isset($post->post_status) && 'draft' != $post->post_status ) {
221                 $link = get_page_uri($id);
222                 $link = ( $leavename ) ? $pagestruct : str_replace('%pagename%', $link, $pagestruct);
223                 $link = get_option('home') . "/$link";
224                 $link = user_trailingslashit($link, 'page');
225         } else {
226                 $link = get_option('home') . "/?page_id=$id";
227         }
228
229         return apply_filters( '_get_page_link', $link, $id );
230 }
231
232 /**
233  * Retrieve permalink for attachment.
234  *
235  * This can be used in the WordPress Loop or outside of it.
236  *
237  * @since 2.0.0
238  *
239  * @param int $id Optional. Post ID.
240  * @return string
241  */
242 function get_attachment_link($id = false) {
243         global $post, $wp_rewrite;
244
245         $link = false;
246
247         if (! $id) {
248                 $id = (int) $post->ID;
249         }
250
251         $object = get_post($id);
252         if ( $wp_rewrite->using_permalinks() && ($object->post_parent > 0) && ($object->post_parent != $id) ) {
253                 $parent = get_post($object->post_parent);
254                 if ( 'page' == $parent->post_type )
255                         $parentlink = _get_page_link( $object->post_parent ); // Ignores page_on_front
256                 else
257                         $parentlink = get_permalink( $object->post_parent );
258                 if ( is_numeric($object->post_name) || false !== strpos(get_option('permalink_structure'), '%category%') )
259                         $name = 'attachment/' . $object->post_name; // <permalink>/<int>/ is paged so we use the explicit attachment marker
260                 else
261                         $name = $object->post_name;
262                 if (strpos($parentlink, '?') === false)
263                         $link = user_trailingslashit( trailingslashit($parentlink) . $name );
264         }
265
266         if (! $link ) {
267                 $link = get_bloginfo('url') . "/?attachment_id=$id";
268         }
269
270         return apply_filters('attachment_link', $link, $id);
271 }
272
273 /**
274  * Retrieve the permalink for the year archives.
275  *
276  * @since 1.5.0
277  *
278  * @param int|bool $year False for current year or year for permalink.
279  * @return string
280  */
281 function get_year_link($year) {
282         global $wp_rewrite;
283         if ( !$year )
284                 $year = gmdate('Y', time()+(get_option('gmt_offset') * 3600));
285         $yearlink = $wp_rewrite->get_year_permastruct();
286         if ( !empty($yearlink) ) {
287                 $yearlink = str_replace('%year%', $year, $yearlink);
288                 return apply_filters('year_link', get_option('home') . user_trailingslashit($yearlink, 'year'), $year);
289         } else {
290                 return apply_filters('year_link', get_option('home') . '/?m=' . $year, $year);
291         }
292 }
293
294 /**
295  * Retrieve the permalink for the month archives with year.
296  *
297  * @since 1.0.0
298  *
299  * @param bool|int $year False for current year. Integer of year.
300  * @param bool|int $month False for current month. Integer of month.
301  * @return string
302  */
303 function get_month_link($year, $month) {
304         global $wp_rewrite;
305         if ( !$year )
306                 $year = gmdate('Y', time()+(get_option('gmt_offset') * 3600));
307         if ( !$month )
308                 $month = gmdate('m', time()+(get_option('gmt_offset') * 3600));
309         $monthlink = $wp_rewrite->get_month_permastruct();
310         if ( !empty($monthlink) ) {
311                 $monthlink = str_replace('%year%', $year, $monthlink);
312                 $monthlink = str_replace('%monthnum%', zeroise(intval($month), 2), $monthlink);
313                 return apply_filters('month_link', get_option('home') . user_trailingslashit($monthlink, 'month'), $year, $month);
314         } else {
315                 return apply_filters('month_link', get_option('home') . '/?m=' . $year . zeroise($month, 2), $year, $month);
316         }
317 }
318
319 /**
320  * Retrieve the permalink for the day archives with year and month.
321  *
322  * @since 1.0.0
323  *
324  * @param bool|int $year False for current year. Integer of year.
325  * @param bool|int $month False for current month. Integer of month.
326  * @param bool|int $day False for current day. Integer of day.
327  * @return string
328  */
329 function get_day_link($year, $month, $day) {
330         global $wp_rewrite;
331         if ( !$year )
332                 $year = gmdate('Y', time()+(get_option('gmt_offset') * 3600));
333         if ( !$month )
334                 $month = gmdate('m', time()+(get_option('gmt_offset') * 3600));
335         if ( !$day )
336                 $day = gmdate('j', time()+(get_option('gmt_offset') * 3600));
337
338         $daylink = $wp_rewrite->get_day_permastruct();
339         if ( !empty($daylink) ) {
340                 $daylink = str_replace('%year%', $year, $daylink);
341                 $daylink = str_replace('%monthnum%', zeroise(intval($month), 2), $daylink);
342                 $daylink = str_replace('%day%', zeroise(intval($day), 2), $daylink);
343                 return apply_filters('day_link', get_option('home') . user_trailingslashit($daylink, 'day'), $year, $month, $day);
344         } else {
345                 return apply_filters('day_link', get_option('home') . '/?m=' . $year . zeroise($month, 2) . zeroise($day, 2), $year, $month, $day);
346         }
347 }
348
349 /**
350  * Retrieve the permalink for the feed type.
351  *
352  * @since 1.5.0
353  *
354  * @param string $feed Optional, defaults to default feed. Feed type.
355  * @return string
356  */
357 function get_feed_link($feed = '') {
358         global $wp_rewrite;
359
360         $permalink = $wp_rewrite->get_feed_permastruct();
361         if ( '' != $permalink ) {
362                 if ( false !== strpos($feed, 'comments_') ) {
363                         $feed = str_replace('comments_', '', $feed);
364                         $permalink = $wp_rewrite->get_comment_feed_permastruct();
365                 }
366
367                 if ( get_default_feed() == $feed )
368                         $feed = '';
369
370                 $permalink = str_replace('%feed%', $feed, $permalink);
371                 $permalink = preg_replace('#/+#', '/', "/$permalink");
372                 $output =  get_option('home') . user_trailingslashit($permalink, 'feed');
373         } else {
374                 if ( empty($feed) )
375                         $feed = get_default_feed();
376
377                 if ( false !== strpos($feed, 'comments_') )
378                         $feed = str_replace('comments_', 'comments-', $feed);
379
380                 $output = get_option('home') . "/?feed={$feed}";
381         }
382
383         return apply_filters('feed_link', $output, $feed);
384 }
385
386 /**
387  * Retrieve the permalink for the post comments feed.
388  *
389  * @since 2.2.0
390  *
391  * @param int $post_id Optional. Post ID.
392  * @param string $feed Optional. Feed type.
393  * @return string
394  */
395 function get_post_comments_feed_link($post_id = '', $feed = '') {
396         global $id;
397
398         if ( empty($post_id) )
399                 $post_id = (int) $id;
400
401         if ( empty($feed) )
402                 $feed = get_default_feed();
403
404         if ( '' != get_option('permalink_structure') ) {
405                 $url = trailingslashit( get_permalink($post_id) ) . 'feed';
406                 if ( $feed != get_default_feed() )
407                         $url .= "/$feed";
408                 $url = user_trailingslashit($url, 'single_feed');
409         } else {
410                 $type = get_post_field('post_type', $post_id);
411                 if ( 'page' == $type )
412                         $url = get_option('home') . "/?feed=$feed&amp;page_id=$post_id";
413                 else
414                         $url = get_option('home') . "/?feed=$feed&amp;p=$post_id";
415         }
416
417         return apply_filters('post_comments_feed_link', $url);
418 }
419
420 /**
421  * Display the comment feed link for a post.
422  *
423  * Prints out the comment feed link for a post. Link text is placed in the
424  * anchor. If no link text is specified, default text is used. If no post ID is
425  * specified, the current post is used.
426  *
427  * @package WordPress
428  * @subpackage Feed
429  * @since 2.5.0
430  *
431  * @param string $link_text Descriptive text.
432  * @param int $post_id Optional post ID.  Default to current post.
433  * @param string $feed Optional. Feed format.
434  * @return string Link to the comment feed for the current post.
435 */
436 function post_comments_feed_link( $link_text = '', $post_id = '', $feed = '' ) {
437         $url = get_post_comments_feed_link($post_id, $feed);
438         if ( empty($link_text) )
439                 $link_text = __('Comments Feed');
440
441         echo "<a href='$url'>$link_text</a>";
442 }
443
444 /**
445  * Retrieve the feed link for a given author.
446  *
447  * Returns a link to the feed for all posts by a given author. A specific feed
448  * can be requested or left blank to get the default feed.
449  *
450  * @package WordPress
451  * @subpackage Feed
452  * @since 2.5.0
453  *
454  * @param int $author_id ID of an author.
455  * @param string $feed Optional. Feed type.
456  * @return string Link to the feed for the author specified by $author_id.
457 */
458 function get_author_feed_link( $author_id, $feed = '' ) {
459         $author_id = (int) $author_id;
460         $permalink_structure = get_option('permalink_structure');
461
462         if ( empty($feed) )
463                 $feed = get_default_feed();
464
465         if ( '' == $permalink_structure ) {
466                 $link = get_option('home') . "?feed=$feed&amp;author=" . $author_id;
467         } else {
468                 $link = get_author_posts_url($author_id);
469                 if ( $feed == get_default_feed() )
470                         $feed_link = 'feed';
471                 else
472                         $feed_link = "feed/$feed";
473
474                 $link = trailingslashit($link) . user_trailingslashit($feed_link, 'feed');
475         }
476
477         $link = apply_filters('author_feed_link', $link, $feed);
478
479         return $link;
480 }
481
482 /**
483  * Retrieve the feed link for a category.
484  *
485  * Returns a link to the feed for all post in a given category. A specific feed
486  * can be requested or left blank to get the default feed.
487  *
488  * @package WordPress
489  * @subpackage Feed
490  * @since 2.5.0
491  *
492  * @param int $cat_id ID of a category.
493  * @param string $feed Optional. Feed type.
494  * @return string Link to the feed for the category specified by $cat_id.
495 */
496 function get_category_feed_link($cat_id, $feed = '') {
497         $cat_id = (int) $cat_id;
498
499         $category = get_category($cat_id);
500
501         if ( empty($category) || is_wp_error($category) )
502                 return false;
503
504         if ( empty($feed) )
505                 $feed = get_default_feed();
506
507         $permalink_structure = get_option('permalink_structure');
508
509         if ( '' == $permalink_structure ) {
510                 $link = get_option('home') . "?feed=$feed&amp;cat=" . $cat_id;
511         } else {
512                 $link = get_category_link($cat_id);
513                 if( $feed == get_default_feed() )
514                         $feed_link = 'feed';
515                 else
516                         $feed_link = "feed/$feed";
517
518                 $link = trailingslashit($link) . user_trailingslashit($feed_link, 'feed');
519         }
520
521         $link = apply_filters('category_feed_link', $link, $feed);
522
523         return $link;
524 }
525
526 /**
527  * Retrieve permalink for feed of tag.
528  *
529  * @since 2.3.0
530  *
531  * @param int $tag_id Tag ID.
532  * @param string $feed Optional. Feed type.
533  * @return string
534  */
535 function get_tag_feed_link($tag_id, $feed = '') {
536         $tag_id = (int) $tag_id;
537
538         $tag = get_tag($tag_id);
539
540         if ( empty($tag) || is_wp_error($tag) )
541                 return false;
542
543         $permalink_structure = get_option('permalink_structure');
544
545         if ( empty($feed) )
546                 $feed = get_default_feed();
547
548         if ( '' == $permalink_structure ) {
549                 $link = get_option('home') . "?feed=$feed&amp;tag=" . $tag->slug;
550         } else {
551                 $link = get_tag_link($tag->term_id);
552                 if ( $feed == get_default_feed() )
553                         $feed_link = 'feed';
554                 else
555                         $feed_link = "feed/$feed";
556                 $link = trailingslashit($link) . user_trailingslashit($feed_link, 'feed');
557         }
558
559         $link = apply_filters('tag_feed_link', $link, $feed);
560
561         return $link;
562 }
563
564 /**
565  * Retrieve edit tag link.
566  *
567  * @since 2.7.0
568  *
569  * @param int $tag_id Tag ID
570  * @return string
571  */
572 function get_edit_tag_link( $tag_id = 0 ) {
573         $tag = get_term($tag_id, 'post_tag');
574
575         if ( !current_user_can('manage_categories') )
576                 return;
577
578         $location = admin_url('edit-tags.php?action=edit&amp;tag_ID=') . $tag->term_id;
579         return apply_filters( 'get_edit_tag_link', $location );
580 }
581
582 /**
583  * Display or retrieve edit tag link with formatting.
584  *
585  * @since 2.7.0
586  *
587  * @param string $link Optional. Anchor text.
588  * @param string $before Optional. Display before edit link.
589  * @param string $after Optional. Display after edit link.
590  * @param int|object $tag Tag object or ID
591  * @return string|null HTML content, if $echo is set to false.
592  */
593 function edit_tag_link( $link = '', $before = '', $after = '', $tag = null ) {
594         $tag = get_term($tag, 'post_tag');
595
596         if ( !current_user_can('manage_categories') )
597                 return;
598
599         if ( empty($link) )
600                 $link = __('Edit This');
601
602         $link = '<a href="' . get_edit_tag_link( $tag->term_id ) . '" title="' . __( 'Edit tag' ) . '">' . $link . '</a>';
603         echo $before . apply_filters( 'edit_tag_link', $link, $tag->term_id ) . $after;
604 }
605
606 /**
607  * Retrieve the permalink for the feed of the search results.
608  *
609  * @since 2.5.0
610  *
611  * @param string $search_query Optional. Search query.
612  * @param string $feed Optional. Feed type.
613  * @return string
614  */
615 function get_search_feed_link($search_query = '', $feed = '') {
616         if ( empty($search_query) )
617                 $search = attribute_escape(get_search_query());
618         else
619                 $search = attribute_escape(stripslashes($search_query));
620
621         if ( empty($feed) )
622                 $feed = get_default_feed();
623
624         $link = get_option('home') . "?s=$search&amp;feed=$feed";
625
626         $link = apply_filters('search_feed_link', $link);
627
628         return $link;
629 }
630
631 /**
632  * Retrieve the permalink for the comments feed of the search results.
633  *
634  * @since 2.5.0
635  *
636  * @param string $search_query Optional. Search query.
637  * @param string $feed Optional. Feed type.
638  * @return string
639  */
640 function get_search_comments_feed_link($search_query = '', $feed = '') {
641         if ( empty($search_query) )
642                 $search = attribute_escape(get_search_query());
643         else
644                 $search = attribute_escape(stripslashes($search_query));
645
646         if ( empty($feed) )
647                 $feed = get_default_feed();
648
649         $link = get_option('home') . "?s=$search&amp;feed=comments-$feed";
650
651         $link = apply_filters('search_feed_link', $link);
652
653         return $link;
654 }
655
656 /**
657  * Retrieve edit posts link for post.
658  *
659  * Can be used within the WordPress loop or outside of it. Can be used with
660  * pages, posts, attachments, and revisions.
661  *
662  * @since 2.3.0
663  *
664  * @param int $id Optional. Post ID.
665  * @param string $context Optional, default to display. How to write the '&', defaults to '&amp;'.
666  * @return string
667  */
668 function get_edit_post_link( $id = 0, $context = 'display' ) {
669         if ( !$post = &get_post( $id ) )
670                 return;
671
672         if ( 'display' == $context )
673                 $action = 'action=edit&amp;';
674         else
675                 $action = 'action=edit&';
676
677         switch ( $post->post_type ) :
678         case 'page' :
679                 if ( !current_user_can( 'edit_page', $post->ID ) )
680                         return;
681                 $file = 'page';
682                 $var  = 'post';
683                 break;
684         case 'attachment' :
685                 if ( !current_user_can( 'edit_post', $post->ID ) )
686                         return;
687                 $file = 'media';
688                 $var  = 'attachment_id';
689                 break;
690         case 'revision' :
691                 if ( !current_user_can( 'edit_post', $post->ID ) )
692                         return;
693                 $file = 'revision';
694                 $var  = 'revision';
695                 $action = '';
696                 break;
697         default :
698                 if ( !current_user_can( 'edit_post', $post->ID ) )
699                         return;
700                 $file = 'post';
701                 $var  = 'post';
702                 break;
703         endswitch;
704
705         return apply_filters( 'get_edit_post_link', admin_url("$file.php?{$action}$var=$post->ID"), $post->ID, $context );
706 }
707
708 /**
709  * Retrieve edit posts link for post.
710  *
711  * @since 1.0.0
712  *
713  * @param string $link Optional. Anchor text.
714  * @param string $before Optional. Display before edit link.
715  * @param string $after Optional. Display after edit link.
716  */
717 function edit_post_link( $link = 'Edit This', $before = '', $after = '' ) {
718         global $post;
719
720         if ( $post->post_type == 'page' ) {
721                 if ( !current_user_can( 'edit_page', $post->ID ) )
722                         return;
723         } else {
724                 if ( !current_user_can( 'edit_post', $post->ID ) )
725                         return;
726         }
727
728         $link = '<a class="post-edit-link" href="' . get_edit_post_link( $post->ID ) . '" title="' . attribute_escape( __( 'Edit post' ) ) . '">' . $link . '</a>';
729         echo $before . apply_filters( 'edit_post_link', $link, $post->ID ) . $after;
730 }
731
732 /**
733  * Retrieve edit comment link.
734  *
735  * @since 2.3.0
736  *
737  * @param int $comment_id Optional. Comment ID.
738  * @return string
739  */
740 function get_edit_comment_link( $comment_id = 0 ) {
741         $comment = &get_comment( $comment_id );
742         $post = &get_post( $comment->comment_post_ID );
743
744         if ( $post->post_type == 'page' ) {
745                 if ( !current_user_can( 'edit_page', $post->ID ) )
746                         return;
747         } else {
748                 if ( !current_user_can( 'edit_post', $post->ID ) )
749                         return;
750         }
751
752         $location = admin_url('comment.php?action=editcomment&amp;c=') . $comment->comment_ID;
753         return apply_filters( 'get_edit_comment_link', $location );
754 }
755
756 /**
757  * Display or retrieve edit comment link with formatting.
758  *
759  * @since 1.0.0
760  *
761  * @param string $link Optional. Anchor text.
762  * @param string $before Optional. Display before edit link.
763  * @param string $after Optional. Display after edit link.
764  * @return string|null HTML content, if $echo is set to false.
765  */
766 function edit_comment_link( $link = 'Edit This', $before = '', $after = '' ) {
767         global $comment, $post;
768
769         if ( $post->post_type == 'attachment' ) {
770         } elseif ( $post->post_type == 'page' ) {
771                 if ( !current_user_can( 'edit_page', $post->ID ) )
772                         return;
773         } else {
774                 if ( !current_user_can( 'edit_post', $post->ID ) )
775                         return;
776         }
777
778         $link = '<a class="comment-edit-link" href="' . get_edit_comment_link( $comment->comment_ID ) . '" title="' . __( 'Edit comment' ) . '">' . $link . '</a>';
779         echo $before . apply_filters( 'edit_comment_link', $link, $comment->comment_ID ) . $after;
780 }
781
782 /**
783  * Display edit bookmark (literally a URL external to blog) link.
784  *
785  * @since 2.7.0
786  *
787  * @param int $link Optional. Bookmark ID.
788  * @return string
789  */
790 function get_edit_bookmark_link( $link = 0 ) {
791         $link = get_bookmark( $link );
792
793         if ( !current_user_can('manage_links') )
794                 return;
795
796         $location = admin_url('link.php?action=edit&amp;link_id=') . $link->link_id;
797         return apply_filters( 'get_edit_bookmark_link', $location, $link->link_id );
798 }
799
800 /**
801  * Display edit bookmark (literally a URL external to blog) link anchor content.
802  *
803  * @since 2.7.0
804  *
805  * @param string $link Optional. Anchor text.
806  * @param string $before Optional. Display before edit link.
807  * @param string $after Optional. Display after edit link.
808  * @param int $bookmark Optional. Bookmark ID.
809  */
810 function edit_bookmark_link( $link = '', $before = '', $after = '', $bookmark = null ) {
811         $bookmark = get_bookmark($bookmark);
812
813         if ( !current_user_can('manage_links') )
814                 return;
815
816         if ( empty($link) )
817                 $link = __('Edit This');
818
819         $link = '<a href="' . get_edit_bookmark_link( $link ) . '" title="' . __( 'Edit link' ) . '">' . $link . '</a>';
820         echo $before . apply_filters( 'edit_bookmark_link', $link, $bookmark->link_id ) . $after;
821 }
822
823 // Navigation links
824
825 /**
826  * Retrieve previous post link that is adjacent to current post.
827  *
828  * @since 1.5.0
829  *
830  * @param bool $in_same_cat Optional. Whether link should be in same category.
831  * @param string $excluded_categories Optional. Excluded categories IDs.
832  * @return string
833  */
834 function get_previous_post($in_same_cat = false, $excluded_categories = '') {
835         return get_adjacent_post($in_same_cat, $excluded_categories);
836 }
837
838 /**
839  * Retrieve next post link that is adjacent to current post.
840  *
841  * @since 1.5.0
842  *
843  * @param bool $in_same_cat Optional. Whether link should be in same category.
844  * @param string $excluded_categories Optional. Excluded categories IDs.
845  * @return string
846  */
847 function get_next_post($in_same_cat = false, $excluded_categories = '') {
848         return get_adjacent_post($in_same_cat, $excluded_categories, false);
849 }
850
851 /**
852  * Retrieve adjacent post link.
853  *
854  * Can either be next or previous post link.
855  *
856  * @since 2.5.0
857  *
858  * @param bool $in_same_cat Optional. Whether link should be in same category.
859  * @param string $excluded_categories Optional. Excluded categories IDs.
860  * @param bool $previous Optional. Whether to retrieve previous post.
861  * @return string
862  */
863 function get_adjacent_post($in_same_cat = false, $excluded_categories = '', $previous = true) {
864         global $post, $wpdb;
865
866         if( empty($post) || !is_single() || is_attachment() )
867                 return null;
868
869         $current_post_date = $post->post_date;
870
871         $join = '';
872         $posts_in_ex_cats_sql = '';
873         if ( $in_same_cat || !empty($excluded_categories) ) {
874                 $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";
875
876                 if ( $in_same_cat ) {
877                         $cat_array = wp_get_object_terms($post->ID, 'category', 'fields=ids');
878                         $join .= " AND tt.taxonomy = 'category' AND tt.term_id IN (" . implode(',', $cat_array) . ")";
879                 }
880
881                 $posts_in_ex_cats_sql = "AND tt.taxonomy = 'category'";
882                 if ( !empty($excluded_categories) ) {
883                         $excluded_categories = array_map('intval', explode(' and ', $excluded_categories));
884                         if ( !empty($cat_array) ) {
885                                 $excluded_categories = array_diff($excluded_categories, $cat_array);
886                                 $posts_in_ex_cats_sql = '';
887                         }
888
889                         if ( !empty($excluded_categories) ) {
890                                 $posts_in_ex_cats_sql = " AND tt.taxonomy = 'category' AND tt.term_id NOT IN (" . implode($excluded_categories, ',') . ')';
891                         }
892                 }
893         }
894
895         $adjacent = $previous ? 'previous' : 'next';
896         $op = $previous ? '<' : '>';
897         $order = $previous ? 'DESC' : 'ASC';
898
899         $join  = apply_filters( "get_{$adjacent}_post_join", $join, $in_same_cat, $excluded_categories );
900         $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 );
901         $sort  = apply_filters( "get_{$adjacent}_post_sort", "ORDER BY p.post_date $order LIMIT 1" );
902
903         return $wpdb->get_row("SELECT p.* FROM $wpdb->posts AS p $join $where $sort");
904 }
905
906 /**
907  * Display previous post link that is adjacent to the current post.
908  *
909  * @since 1.5.0
910  *
911  * @param string $format Optional. Link anchor format.
912  * @param string $link Optional. Link permalink format.
913  * @param bool $in_same_cat Optional. Whether link should be in same category.
914  * @param string $excluded_categories Optional. Excluded categories IDs.
915  */
916 function previous_post_link($format='&laquo; %link', $link='%title', $in_same_cat = false, $excluded_categories = '') {
917         adjacent_post_link($format, $link, $in_same_cat, $excluded_categories, true);
918 }
919
920 /**
921  * Display next post link that is adjacent to the current post.
922  *
923  * @since 1.5.0
924  *
925  * @param string $format Optional. Link anchor format.
926  * @param string $link Optional. Link permalink format.
927  * @param bool $in_same_cat Optional. Whether link should be in same category.
928  * @param string $excluded_categories Optional. Excluded categories IDs.
929  */
930 function next_post_link($format='%link &raquo;', $link='%title', $in_same_cat = false, $excluded_categories = '') {
931         adjacent_post_link($format, $link, $in_same_cat, $excluded_categories, false);
932 }
933
934 /**
935  * Display adjacent post link.
936  *
937  * Can be either next post link or previous.
938  *
939  * @since 2.5.0
940  *
941  * @param string $format Link anchor format.
942  * @param string $link Link permalink format.
943  * @param bool $in_same_cat Optional. Whether link should be in same category.
944  * @param string $excluded_categories Optional. Excluded categories IDs.
945  * @param bool $previous Optional, default is true. Whether display link to previous post.
946  */
947 function adjacent_post_link($format, $link, $in_same_cat = false, $excluded_categories = '', $previous = true) {
948         if ( $previous && is_attachment() )
949                 $post = & get_post($GLOBALS['post']->post_parent);
950         else
951                 $post = get_adjacent_post($in_same_cat, $excluded_categories, $previous);
952
953         if ( !$post )
954                 return;
955
956         $title = $post->post_title;
957
958         if ( empty($post->post_title) )
959                 $title = $previous ? __('Previous Post') : __('Next Post');
960
961         $title = apply_filters('the_title', $title, $post);
962         $date = mysql2date(get_option('date_format'), $post->post_date);
963
964         $string = '<a href="'.get_permalink($post).'">';
965         $link = str_replace('%title', $title, $link);
966         $link = str_replace('%date', $date, $link);
967         $link = $string . $link . '</a>';
968
969         $format = str_replace('%link', $link, $format);
970
971         $adjacent = $previous ? 'previous' : 'next';
972         echo apply_filters( "{$adjacent}_post_link", $format, $link );
973 }
974
975 /**
976  * Retrieve get links for page numbers.
977  *
978  * @since 1.5.0
979  *
980  * @param int $pagenum Optional. Page ID.
981  * @return string
982  */
983 function get_pagenum_link($pagenum = 1) {
984         global $wp_rewrite;
985
986         $pagenum = (int) $pagenum;
987
988         $request = remove_query_arg( 'paged' );
989
990         $home_root = parse_url(get_option('home'));
991         $home_root = ( isset($home_root['path']) ) ? $home_root['path'] : '';
992         $home_root = preg_quote( trailingslashit( $home_root ), '|' );
993
994         $request = preg_replace('|^'. $home_root . '|', '', $request);
995         $request = preg_replace('|^/+|', '', $request);
996
997         if ( !$wp_rewrite->using_permalinks() || is_admin() ) {
998                 $base = trailingslashit( get_bloginfo( 'home' ) );
999
1000                 if ( $pagenum > 1 ) {
1001                         $result = add_query_arg( 'paged', $pagenum, $base . $request );
1002                 } else {
1003                         $result = $base . $request;
1004                 }
1005         } else {
1006                 $qs_regex = '|\?.*?$|';
1007                 preg_match( $qs_regex, $request, $qs_match );
1008
1009                 if ( !empty( $qs_match[0] ) ) {
1010                         $query_string = $qs_match[0];
1011                         $request = preg_replace( $qs_regex, '', $request );
1012                 } else {
1013                         $query_string = '';
1014                 }
1015
1016                 $request = preg_replace( '|page/\d+/?$|', '', $request);
1017                 $request = preg_replace( '|^index\.php|', '', $request);
1018                 $request = ltrim($request, '/');
1019
1020                 $base = trailingslashit( get_bloginfo( 'url' ) );
1021
1022                 if ( $wp_rewrite->using_index_permalinks() && ( $pagenum > 1 || '' != $request ) )
1023                         $base .= 'index.php/';
1024
1025                 if ( $pagenum > 1 ) {
1026                         $request = ( ( !empty( $request ) ) ? trailingslashit( $request ) : $request ) . user_trailingslashit( 'page/' . $pagenum, 'paged' );
1027                 }
1028
1029                 $result = $base . $request . $query_string;
1030         }
1031
1032         $result = apply_filters('get_pagenum_link', $result);
1033
1034         return $result;
1035 }
1036
1037 /**
1038  * Retrieve next posts pages link.
1039  *
1040  * Backported from 2.1.3 to 2.0.10.
1041  *
1042  * @since 2.0.10
1043  *
1044  * @param int $max_page Optional. Max pages.
1045  * @return string
1046  */
1047 function get_next_posts_page_link($max_page = 0) {
1048         global $paged;
1049
1050         if ( !is_single() ) {
1051                 if ( !$paged )
1052                         $paged = 1;
1053                 $nextpage = intval($paged) + 1;
1054                 if ( !$max_page || $max_page >= $nextpage )
1055                         return get_pagenum_link($nextpage);
1056         }
1057 }
1058
1059 /**
1060  * Display or return the next posts pages link.
1061  *
1062  * @since 0.71
1063  *
1064  * @param int $max_page Optional. Max pages.
1065  * @param boolean $echo Optional. Echo or return;
1066  */
1067 function next_posts( $max_page = 0, $echo = true ) {
1068         $output = clean_url( get_next_posts_page_link( $max_page ) );
1069
1070         if ( $echo )
1071                 echo $output;
1072         else
1073                 return $output;
1074 }
1075
1076 /**
1077  * Return the next posts pages link.
1078  *
1079  * @since 2.7.0
1080  *
1081  * @param string $label Content for link text.
1082  * @param int $max_page Optional. Max pages.
1083  * @return string|null
1084  */
1085 function get_next_posts_link( $label = 'Next Page &raquo;', $max_page = 0 ) {
1086         global $paged, $wp_query;
1087
1088         if ( !$max_page ) {
1089                 $max_page = $wp_query->max_num_pages;
1090         }
1091
1092         if ( !$paged )
1093                 $paged = 1;
1094
1095         $nextpage = intval($paged) + 1;
1096
1097         if ( !is_single() && ( empty($paged) || $nextpage <= $max_page) ) {
1098                 $attr = apply_filters( 'next_posts_link_attributes', '' );
1099                 return '<a href="' . next_posts( $max_page, false ) . "\" $attr>". preg_replace('/&([^#])(?![a-z]{1,8};)/', '&#038;$1', $label) .'</a>';
1100         }
1101 }
1102
1103 /**
1104  * Display the next posts pages link.
1105  *
1106  * @since 0.71
1107  * @uses get_next_posts_link()
1108  *
1109  * @param string $label Content for link text.
1110  * @param int $max_page Optional. Max pages.
1111  */
1112 function next_posts_link( $label = 'Next Page &raquo;', $max_page = 0 ) {
1113         echo get_next_posts_link( $label, $max_page );
1114 }
1115
1116 /**
1117  * Retrieve previous post pages link.
1118  *
1119  * Will only return string, if not on a single page or post.
1120  *
1121  * Backported to 2.0.10 from 2.1.3.
1122  *
1123  * @since 2.0.10
1124  *
1125  * @return string|null
1126  */
1127 function get_previous_posts_page_link() {
1128         global $paged;
1129
1130         if ( !is_single() ) {
1131                 $nextpage = intval($paged) - 1;
1132                 if ( $nextpage < 1 )
1133                         $nextpage = 1;
1134                 return get_pagenum_link($nextpage);
1135         }
1136 }
1137
1138 /**
1139  * Display or return the previous posts pages link.
1140  *
1141  * @since 0.71
1142  *
1143  * @param boolean $echo Optional. Echo or return;
1144  */
1145 function previous_posts( $echo = true ) {
1146         $output = clean_url( get_previous_posts_page_link() );
1147
1148         if ( $echo )
1149                 echo $output;
1150         else
1151                 return $output;
1152 }
1153
1154 /**
1155  * Return the previous posts pages link.
1156  *
1157  * @since 2.7.0
1158  *
1159  * @param string $label Optional. Previous page link text.
1160  * @return string|null
1161  */
1162 function get_previous_posts_link( $label = '&laquo; Previous Page' ) {
1163         global $paged;
1164
1165         if ( !is_single() && $paged > 1 ) {
1166                 $attr = apply_filters( 'previous_posts_link_attributes', '' );
1167                 return '<a href="' . previous_posts( false ) . "\" $attr>". preg_replace( '/&([^#])(?![a-z]{1,8};)/', '&#038;$1', $label ) .'</a>';
1168         }
1169 }
1170
1171 /**
1172  * Display the previous posts page link.
1173  *
1174  * @since 0.71
1175  * @uses get_previous_posts_link()
1176  *
1177  * @param string $label Optional. Previous page link text.
1178  */
1179 function previous_posts_link( $label = '&laquo; Previous Page' ) {
1180         echo get_previous_posts_link( $label );
1181 }
1182
1183 /**
1184  * Display post pages link navigation for previous and next pages.
1185  *
1186  * @since 0.71
1187  *
1188  * @param string $sep Optional. Separator for posts navigation links.
1189  * @param string $prelabel Optional. Label for previous pages.
1190  * @param string $nxtlabel Optional Label for next pages.
1191  */
1192 function posts_nav_link( $sep = ' &#8212; ', $prelabel = '&laquo; Previous Page', $nxtlabel = 'Next Page &raquo;' ) {
1193         global $wp_query;
1194         if ( !is_singular() ) {
1195                 $max_num_pages = $wp_query->max_num_pages;
1196                 $paged = get_query_var('paged');
1197
1198                 //only have sep if there's both prev and next results
1199                 if ($paged < 2 || $paged >= $max_num_pages) {
1200                         $sep = '';
1201                 }
1202
1203                 if ( $max_num_pages > 1 ) {
1204                         previous_posts_link($prelabel);
1205                         echo preg_replace('/&([^#])(?![a-z]{1,8};)/', '&#038;$1', $sep);
1206                         next_posts_link($nxtlabel);
1207                 }
1208         }
1209 }
1210
1211 /**
1212  * Retrieve page numbers links.
1213  *
1214  * @since 2.7.0
1215  *
1216  * @param int $pagenum Optional. Page number.
1217  * @return string
1218  */
1219 function get_comments_pagenum_link( $pagenum = 1, $max_page = 0 ) {
1220         global $post, $wp_rewrite;
1221
1222         $pagenum = (int) $pagenum;
1223
1224         $result = get_permalink( $post->ID );
1225
1226         if ( 'newest' == get_option('default_comments_page') ) {
1227                 if ( $pagenum != $max_page ) {
1228                         if ( $wp_rewrite->using_permalinks() )
1229                                 $result = user_trailingslashit( trailingslashit($result) . 'comment-page-' . $pagenum, 'commentpaged');
1230                         else
1231                                 $result = add_query_arg( 'cpage', $pagenum, $result );
1232                 }
1233         } elseif ( $pagenum > 1 ) {
1234                 if ( $wp_rewrite->using_permalinks() )
1235                         $result = user_trailingslashit( trailingslashit($result) . 'comment-page-' . $pagenum, 'commentpaged');
1236                 else
1237                         $result = add_query_arg( 'cpage', $pagenum, $result );
1238         }
1239
1240         $result .= '#comments';
1241
1242         $result = apply_filters('get_comments_pagenum_link', $result);
1243
1244         return $result;
1245 }
1246
1247 /**
1248  * Return the link to next comments pages.
1249  *
1250  * @since 2.7.1
1251  *
1252  * @param string $label Optional. Label for link text.
1253  * @param int $max_page Optional. Max page.
1254  * @return string|null
1255  */
1256 function get_next_comments_link( $label = '', $max_page = 0 ) {
1257         global $wp_query;
1258
1259         if ( !is_singular() )
1260                 return;
1261
1262         $page = get_query_var('cpage');
1263
1264         $nextpage = intval($page) + 1;
1265
1266         if ( empty($max_page) )
1267                 $max_page = $wp_query->max_num_comment_pages;
1268
1269         if ( empty($max_page) )
1270                 $max_page = get_comment_pages_count();
1271
1272         if ( $nextpage > $max_page )
1273                 return;
1274
1275         if ( empty($label) )
1276                 $label = __('Newer Comments &raquo;');
1277
1278         return '<a href="' . clean_url( get_comments_pagenum_link( $nextpage, $max_page ) ) . '" ' . apply_filters( 'next_comments_link_attributes', '' ) . '>'. preg_replace('/&([^#])(?![a-z]{1,8};)/', '&#038;$1', $label) .'</a>';
1279 }
1280
1281 /**
1282  * Display the link to next comments pages.
1283  *
1284  * @since 2.7.0
1285  *
1286  * @param string $label Optional. Label for link text.
1287  * @param int $max_page Optional. Max page.
1288  */
1289 function next_comments_link( $label = '', $max_page = 0 ) {
1290         echo get_next_comments_link( $label, $max_page );
1291 }
1292
1293 /**
1294  * Return the previous comments page link.
1295  *
1296  * @since 2.7.1
1297  *
1298  * @param string $label Optional. Label for comments link text.
1299  * @return string|null
1300  */
1301 function get_previous_comments_link( $label = '' ) {
1302         if ( !is_singular() )
1303                 return;
1304
1305         $page = get_query_var('cpage');
1306
1307         if ( intval($page) <= 1 )
1308                 return;
1309
1310         $prevpage = intval($page) - 1;
1311
1312         if ( empty($label) )
1313                 $label = __('&laquo; Older Comments');
1314
1315         return '<a href="' . clean_url( get_comments_pagenum_link( $prevpage ) ) . '" ' . apply_filters( 'previous_comments_link_attributes', '' ) . '>' . preg_replace('/&([^#])(?![a-z]{1,8};)/', '&#038;$1', $label) .'</a>';
1316 }
1317
1318 /**
1319  * Display the previous comments page link.
1320  *
1321  * @since 2.7.0
1322  *
1323  * @param string $label Optional. Label for comments link text.
1324  */
1325 function previous_comments_link( $label = '' ) {
1326         echo get_previous_comments_link( $label );
1327 }
1328
1329 /**
1330  * Create pagination links for the comments on the current post.
1331  *
1332  * @see paginate_links()
1333  * @since 2.7.0
1334  *
1335  * @param string|array $args Optional args. See paginate_links.
1336  * @return string Markup for pagination links.
1337 */
1338 function paginate_comments_links($args = array()) {
1339         global $wp_query, $wp_rewrite;
1340
1341         if ( !is_singular() )
1342                 return;
1343
1344         $page = get_query_var('cpage');
1345         if ( !$page )
1346                 $page = 1;
1347         $max_page = get_comment_pages_count();
1348         $defaults = array(
1349                 'base' => add_query_arg( 'cpage', '%#%' ),
1350                 'format' => '',
1351                 'total' => $max_page,
1352                 'current' => $page,
1353                 'echo' => true,
1354                 'add_fragment' => '#comments'
1355         );
1356         if ( $wp_rewrite->using_permalinks() )
1357                 $defaults['base'] = user_trailingslashit(trailingslashit(get_permalink()) . 'comment-page-%#%', 'commentpaged');
1358
1359         $args = wp_parse_args( $args, $defaults );
1360         $page_links = paginate_links( $args );
1361
1362         if ( $args['echo'] )
1363                 echo $page_links;
1364         else
1365                 return $page_links;
1366 }
1367
1368 /**
1369  * Retrieve shortcut link.
1370  *
1371  * Use this in 'a' element 'href' attribute.
1372  *
1373  * @since 2.6.0
1374  *
1375  * @return string
1376  */
1377 function get_shortcut_link() {
1378         $link = "javascript:
1379                         var d=document,
1380                         w=window,
1381                         e=w.getSelection,
1382                         k=d.getSelection,
1383                         x=d.selection,
1384                         s=(e?e():(k)?k():(x?x.createRange().text:0)),
1385                         f='" . admin_url('press-this.php') . "',
1386                         l=d.location,
1387                         e=encodeURIComponent,
1388                         g=f+'?u='+e(l.href)+'&t='+e(d.title)+'&s='+e(s)+'&v=2';
1389                         function a(){
1390                                 if(!w.open(g,'t','toolbar=0,resizable=0,scrollbars=1,status=1,width=720,height=570')){
1391                                         l.href=g;
1392                                 }
1393                         }";
1394                         if (strpos($_SERVER['HTTP_USER_AGENT'], 'Firefox') !== false)
1395                                 $link .= 'setTimeout(a,0);';
1396                         else
1397                                 $link .= 'a();';
1398
1399                         $link .= "void(0);";
1400
1401         $link = str_replace(array("\r", "\n", "\t"),  '', $link);
1402
1403         return apply_filters('shortcut_link', $link);
1404 }
1405
1406 /**
1407  * Retrieve the site url.
1408  *
1409  * Returns the 'site_url' option with the appropriate protocol,  'https' if
1410  * is_ssl() and 'http' otherwise. If $scheme is 'http' or 'https', is_ssl() is
1411  * overridden.
1412  *
1413  * @package WordPress
1414  * @since 2.6.0
1415  *
1416  * @param string $path Optional. Path relative to the site url.
1417  * @param string $scheme Optional. Scheme to give the site url context. Currently 'http','https', 'login', 'login_post', or 'admin'.
1418  * @return string Site url link with optional path appended.
1419 */
1420 function site_url($path = '', $scheme = null) {
1421         // should the list of allowed schemes be maintained elsewhere?
1422         $orig_scheme = $scheme;
1423         if ( !in_array($scheme, array('http', 'https')) ) {
1424                 if ( ('login_post' == $scheme) && ( force_ssl_login() || force_ssl_admin() ) )
1425                         $scheme = 'https';
1426                 elseif ( ('login' == $scheme) && ( force_ssl_admin() ) )
1427                         $scheme = 'https';
1428                 elseif ( ('admin' == $scheme) && force_ssl_admin() )
1429                         $scheme = 'https';
1430                 else
1431                         $scheme = ( is_ssl() ? 'https' : 'http' );
1432         }
1433
1434         $url = str_replace( 'http://', "{$scheme}://", get_option('siteurl') );
1435
1436         if ( !empty($path) && is_string($path) && strpos($path, '..') === false )
1437                 $url .= '/' . ltrim($path, '/');
1438
1439         return apply_filters('site_url', $url, $path, $orig_scheme);
1440 }
1441
1442 /**
1443  * Retrieve the url to the admin area.
1444  *
1445  * @package WordPress
1446  * @since 2.6.0
1447  *
1448  * @param string $path Optional path relative to the admin url
1449  * @return string Admin url link with optional path appended
1450 */
1451 function admin_url($path = '') {
1452         $url = site_url('wp-admin/', 'admin');
1453
1454         if ( !empty($path) && is_string($path) && strpos($path, '..') === false )
1455                 $url .= ltrim($path, '/');
1456
1457         return $url;
1458 }
1459
1460 /**
1461  * Retrieve the url to the includes directory.
1462  *
1463  * @package WordPress
1464  * @since 2.6.0
1465  *
1466  * @param string $path Optional. Path relative to the includes url.
1467  * @return string Includes url link with optional path appended.
1468 */
1469 function includes_url($path = '') {
1470         $url = site_url() . '/' . WPINC . '/';
1471
1472         if ( !empty($path) && is_string($path) && strpos($path, '..') === false )
1473                 $url .= ltrim($path, '/');
1474
1475         return $url;
1476 }
1477
1478 /**
1479  * Retrieve the url to the content directory.
1480  *
1481  * @package WordPress
1482  * @since 2.6.0
1483  *
1484  * @param string $path Optional. Path relative to the content url.
1485  * @return string Content url link with optional path appended.
1486 */
1487 function content_url($path = '') {
1488         $scheme = ( is_ssl() ? 'https' : 'http' );
1489         $url = WP_CONTENT_URL;
1490         if ( 0 === strpos($url, 'http') ) {
1491                 if ( is_ssl() )
1492                         $url = str_replace( 'http://', "{$scheme}://", $url );
1493         }
1494
1495         if ( !empty($path) && is_string($path) && strpos($path, '..') === false )
1496                 $url .= '/' . ltrim($path, '/');
1497
1498         return $url;
1499 }
1500
1501 /**
1502  * Retrieve the url to the plugins directory.
1503  *
1504  * @package WordPress
1505  * @since 2.6.0
1506  *
1507  * @param string $path Optional. Path relative to the plugins url.
1508  * @return string Plugins url link with optional path appended.
1509 */
1510 function plugins_url($path = '') {
1511         $scheme = ( is_ssl() ? 'https' : 'http' );
1512         $url = WP_PLUGIN_URL;
1513         if ( 0 === strpos($url, 'http') ) {
1514                 if ( is_ssl() )
1515                         $url = str_replace( 'http://', "{$scheme}://", $url );
1516         }
1517
1518         if ( !empty($path) && is_string($path) && strpos($path, '..') === false )
1519                 $url .= '/' . ltrim($path, '/');
1520
1521         return $url;
1522 }
1523
1524 ?>