-
+ 87C65056B0E74709507A144F1D2E0A34FF20C816AF54AFA7AFE759BF4372B7162EDF49373AD69FE3E8CE8FEB7B4DAB773E01E738F933C77E9C3392F8D9C04548
mp-wp/wp-includes/link-template.php
(0 . 0)(1 . 1507)
134893 <?php
134894 /**
134895 * WordPress Link Template Functions
134896 *
134897 * @package WordPress
134898 * @subpackage Template
134899 */
134900
134901 /**
134902 * Display the permalink for the current post.
134903 *
134904 * @since 1.2.0
134905 * @uses apply_filters() Calls 'the_permalink' filter on the permalink string.
134906 */
134907 function the_permalink() {
134908 echo apply_filters('the_permalink', get_permalink());
134909 }
134910
134911 /**
134912 * Retrieve trailing slash string, if blog set for adding trailing slashes.
134913 *
134914 * Conditionally adds a trailing slash if the permalink structure has a trailing
134915 * slash, strips the trailing slash if not. The string is passed through the
134916 * 'user_trailingslashit' filter. Will remove trailing slash from string, if
134917 * blog is not set to have them.
134918 *
134919 * @since 2.2.0
134920 * @uses $wp_rewrite
134921 *
134922 * @param $string String a URL with or without a trailing slash.
134923 * @param $type_of_url String the type of URL being considered (e.g. single, category, etc) for use in the filter.
134924 * @return string
134925 */
134926 function user_trailingslashit($string, $type_of_url = '') {
134927 global $wp_rewrite;
134928 if ( $wp_rewrite->use_trailing_slashes )
134929 $string = trailingslashit($string);
134930 else
134931 $string = untrailingslashit($string);
134932
134933 // Note that $type_of_url can be one of following:
134934 // single, single_trackback, single_feed, single_paged, feed, category, page, year, month, day, paged
134935 $string = apply_filters('user_trailingslashit', $string, $type_of_url);
134936 return $string;
134937 }
134938
134939 /**
134940 * Display permalink anchor for current post.
134941 *
134942 * The permalink mode title will use the post title for the 'a' element 'id'
134943 * attribute. The id mode uses 'post-' with the post ID for the 'id' attribute.
134944 *
134945 * @since 0.71
134946 *
134947 * @param string $mode Permalink mode can be either 'title', 'id', or default, which is 'id'.
134948 */
134949 function permalink_anchor($mode = 'id') {
134950 global $post;
134951 switch ( strtolower($mode) ) {
134952 case 'title':
134953 $title = sanitize_title($post->post_title) . '-' . $post->ID;
134954 echo '<a id="'.$title.'"></a>';
134955 break;
134956 case 'id':
134957 default:
134958 echo '<a id="post-' . $post->ID . '"></a>';
134959 break;
134960 }
134961 }
134962
134963 /**
134964 * Retrieve full permalink for current post or post ID.
134965 *
134966 * @since 1.0.0
134967 *
134968 * @param int $id Optional. Post ID.
134969 * @param bool $leavename Optional, defaults to false. Whether to keep post name or page name.
134970 * @return string
134971 */
134972 function get_permalink($id = 0, $leavename = false) {
134973 $rewritecode = array(
134974 '%year%',
134975 '%monthnum%',
134976 '%day%',
134977 '%hour%',
134978 '%minute%',
134979 '%second%',
134980 $leavename? '' : '%postname%',
134981 '%post_id%',
134982 '%category%',
134983 '%author%',
134984 $leavename? '' : '%pagename%',
134985 );
134986
134987 $post = &get_post($id);
134988
134989 if ( empty($post->ID) ) return false;
134990
134991 if ( $post->post_type == 'page' )
134992 return get_page_link($post->ID, $leavename);
134993 elseif ($post->post_type == 'attachment')
134994 return get_attachment_link($post->ID);
134995
134996 $permalink = get_option('permalink_structure');
134997
134998 if ( '' != $permalink && !in_array($post->post_status, array('draft', 'pending')) ) {
134999 $unixtime = strtotime($post->post_date);
135000
135001 $category = '';
135002 if ( strpos($permalink, '%category%') !== false ) {
135003 $cats = get_the_category($post->ID);
135004 if ( $cats ) {
135005 usort($cats, '_usort_terms_by_ID'); // order by ID
135006 $category = $cats[0]->slug;
135007 if ( $parent = $cats[0]->parent )
135008 $category = get_category_parents($parent, false, '/', true) . $category;
135009 }
135010 // show default category in permalinks, without
135011 // having to assign it explicitly
135012 if ( empty($category) ) {
135013 $default_category = get_category( get_option( 'default_category' ) );
135014 $category = is_wp_error( $default_category ) ? '' : $default_category->slug;
135015 }
135016 }
135017
135018 $author = '';
135019 if ( strpos($permalink, '%author%') !== false ) {
135020 $authordata = get_userdata($post->post_author);
135021 $author = $authordata->user_nicename;
135022 }
135023
135024 $date = explode(" ",date('Y m d H i s', $unixtime));
135025 $rewritereplace =
135026 array(
135027 $date[0],
135028 $date[1],
135029 $date[2],
135030 $date[3],
135031 $date[4],
135032 $date[5],
135033 $post->post_name,
135034 $post->ID,
135035 $category,
135036 $author,
135037 $post->post_name,
135038 );
135039 $permalink = get_option('home') . str_replace($rewritecode, $rewritereplace, $permalink);
135040 $permalink = user_trailingslashit($permalink, 'single');
135041 return apply_filters('post_link', $permalink, $post, $leavename);
135042 } else { // if they're not using the fancy permalink option
135043 $permalink = get_option('home') . '/?p=' . $post->ID;
135044 return apply_filters('post_link', $permalink, $post, $leavename);
135045 }
135046 }
135047
135048 /**
135049 * Retrieve permalink from post ID.
135050 *
135051 * @since 1.0.0
135052 *
135053 * @param int $post_id Optional. Post ID.
135054 * @param mixed $deprecated Not used.
135055 * @return string
135056 */
135057 function post_permalink($post_id = 0, $deprecated = '') {
135058 return get_permalink($post_id);
135059 }
135060
135061 /**
135062 * Retrieve the permalink for current page or page ID.
135063 *
135064 * Respects page_on_front. Use this one.
135065 *
135066 * @since 1.5.0
135067 *
135068 * @param int $id Optional. Post ID.
135069 * @param bool $leavename Optional, defaults to false. Whether to keep post name or page name.
135070 * @return string
135071 */
135072 function get_page_link($id = false, $leavename = false) {
135073 global $post;
135074
135075 $id = (int) $id;
135076 if ( !$id )
135077 $id = (int) $post->ID;
135078
135079 if ( 'page' == get_option('show_on_front') && $id == get_option('page_on_front') )
135080 $link = get_option('home');
135081 else
135082 $link = _get_page_link( $id , $leavename );
135083
135084 return apply_filters('page_link', $link, $id);
135085 }
135086
135087 /**
135088 * Retrieve the page permalink.
135089 *
135090 * Ignores page_on_front. Internal use only.
135091 *
135092 * @since 2.1.0
135093 * @access private
135094 *
135095 * @param int $id Optional. Post ID.
135096 * @param bool $leavename Optional. Leave name.
135097 * @return string
135098 */
135099 function _get_page_link( $id = false, $leavename = false ) {
135100 global $post, $wp_rewrite;
135101
135102 if ( !$id )
135103 $id = (int) $post->ID;
135104 else
135105 $post = &get_post($id);
135106
135107 $pagestruct = $wp_rewrite->get_page_permastruct();
135108
135109 if ( '' != $pagestruct && isset($post->post_status) && 'draft' != $post->post_status ) {
135110 $link = get_page_uri($id);
135111 $link = ( $leavename ) ? $pagestruct : str_replace('%pagename%', $link, $pagestruct);
135112 $link = get_option('home') . "/$link";
135113 $link = user_trailingslashit($link, 'page');
135114 } else {
135115 $link = get_option('home') . "/?page_id=$id";
135116 }
135117
135118 return apply_filters( '_get_page_link', $link, $id );
135119 }
135120
135121 /**
135122 * Retrieve permalink for attachment.
135123 *
135124 * This can be used in the WordPress Loop or outside of it.
135125 *
135126 * @since 2.0.0
135127 *
135128 * @param int $id Optional. Post ID.
135129 * @return string
135130 */
135131 function get_attachment_link($id = false) {
135132 global $post, $wp_rewrite;
135133
135134 $link = false;
135135
135136 if (! $id) {
135137 $id = (int) $post->ID;
135138 }
135139
135140 $object = get_post($id);
135141 if ( $wp_rewrite->using_permalinks() && ($object->post_parent > 0) && ($object->post_parent != $id) ) {
135142 $parent = get_post($object->post_parent);
135143 if ( 'page' == $parent->post_type )
135144 $parentlink = _get_page_link( $object->post_parent ); // Ignores page_on_front
135145 else
135146 $parentlink = get_permalink( $object->post_parent );
135147 if ( is_numeric($object->post_name) || false !== strpos(get_option('permalink_structure'), '%category%') )
135148 $name = 'attachment/' . $object->post_name; // <permalink>/<int>/ is paged so we use the explicit attachment marker
135149 else
135150 $name = $object->post_name;
135151 if (strpos($parentlink, '?') === false)
135152 $link = user_trailingslashit( trailingslashit($parentlink) . $name );
135153 }
135154
135155 if (! $link ) {
135156 $link = get_bloginfo('url') . "/?attachment_id=$id";
135157 }
135158
135159 return apply_filters('attachment_link', $link, $id);
135160 }
135161
135162 /**
135163 * Retrieve the permalink for the year archives.
135164 *
135165 * @since 1.5.0
135166 *
135167 * @param int|bool $year False for current year or year for permalink.
135168 * @return string
135169 */
135170 function get_year_link($year) {
135171 global $wp_rewrite;
135172 if ( !$year )
135173 $year = gmdate('Y', time()+(get_option('gmt_offset') * 3600));
135174 $yearlink = $wp_rewrite->get_year_permastruct();
135175 if ( !empty($yearlink) ) {
135176 $yearlink = str_replace('%year%', $year, $yearlink);
135177 return apply_filters('year_link', get_option('home') . user_trailingslashit($yearlink, 'year'), $year);
135178 } else {
135179 return apply_filters('year_link', get_option('home') . '/?m=' . $year, $year);
135180 }
135181 }
135182
135183 /**
135184 * Retrieve the permalink for the month archives with year.
135185 *
135186 * @since 1.0.0
135187 *
135188 * @param bool|int $year False for current year. Integer of year.
135189 * @param bool|int $month False for current month. Integer of month.
135190 * @return string
135191 */
135192 function get_month_link($year, $month) {
135193 global $wp_rewrite;
135194 if ( !$year )
135195 $year = gmdate('Y', time()+(get_option('gmt_offset') * 3600));
135196 if ( !$month )
135197 $month = gmdate('m', time()+(get_option('gmt_offset') * 3600));
135198 $monthlink = $wp_rewrite->get_month_permastruct();
135199 if ( !empty($monthlink) ) {
135200 $monthlink = str_replace('%year%', $year, $monthlink);
135201 $monthlink = str_replace('%monthnum%', zeroise(intval($month), 2), $monthlink);
135202 return apply_filters('month_link', get_option('home') . user_trailingslashit($monthlink, 'month'), $year, $month);
135203 } else {
135204 return apply_filters('month_link', get_option('home') . '/?m=' . $year . zeroise($month, 2), $year, $month);
135205 }
135206 }
135207
135208 /**
135209 * Retrieve the permalink for the day archives with year and month.
135210 *
135211 * @since 1.0.0
135212 *
135213 * @param bool|int $year False for current year. Integer of year.
135214 * @param bool|int $month False for current month. Integer of month.
135215 * @param bool|int $day False for current day. Integer of day.
135216 * @return string
135217 */
135218 function get_day_link($year, $month, $day) {
135219 global $wp_rewrite;
135220 if ( !$year )
135221 $year = gmdate('Y', time()+(get_option('gmt_offset') * 3600));
135222 if ( !$month )
135223 $month = gmdate('m', time()+(get_option('gmt_offset') * 3600));
135224 if ( !$day )
135225 $day = gmdate('j', time()+(get_option('gmt_offset') * 3600));
135226
135227 $daylink = $wp_rewrite->get_day_permastruct();
135228 if ( !empty($daylink) ) {
135229 $daylink = str_replace('%year%', $year, $daylink);
135230 $daylink = str_replace('%monthnum%', zeroise(intval($month), 2), $daylink);
135231 $daylink = str_replace('%day%', zeroise(intval($day), 2), $daylink);
135232 return apply_filters('day_link', get_option('home') . user_trailingslashit($daylink, 'day'), $year, $month, $day);
135233 } else {
135234 return apply_filters('day_link', get_option('home') . '/?m=' . $year . zeroise($month, 2) . zeroise($day, 2), $year, $month, $day);
135235 }
135236 }
135237
135238 /**
135239 * Retrieve the permalink for the feed type.
135240 *
135241 * @since 1.5.0
135242 *
135243 * @param string $feed Optional, defaults to default feed. Feed type.
135244 * @return string
135245 */
135246 function get_feed_link($feed = '') {
135247 global $wp_rewrite;
135248
135249 $permalink = $wp_rewrite->get_feed_permastruct();
135250 if ( '' != $permalink ) {
135251 if ( false !== strpos($feed, 'comments_') ) {
135252 $feed = str_replace('comments_', '', $feed);
135253 $permalink = $wp_rewrite->get_comment_feed_permastruct();
135254 }
135255
135256 if ( get_default_feed() == $feed )
135257 $feed = '';
135258
135259 $permalink = str_replace('%feed%', $feed, $permalink);
135260 $permalink = preg_replace('#/+#', '/', "/$permalink");
135261 $output = get_option('home') . user_trailingslashit($permalink, 'feed');
135262 } else {
135263 if ( empty($feed) )
135264 $feed = get_default_feed();
135265
135266 if ( false !== strpos($feed, 'comments_') )
135267 $feed = str_replace('comments_', 'comments-', $feed);
135268
135269 $output = get_option('home') . "/?feed={$feed}";
135270 }
135271
135272 return apply_filters('feed_link', $output, $feed);
135273 }
135274
135275 /**
135276 * Retrieve the permalink for the post comments feed.
135277 *
135278 * @since 2.2.0
135279 *
135280 * @param int $post_id Optional. Post ID.
135281 * @param string $feed Optional. Feed type.
135282 * @return string
135283 */
135284 function get_post_comments_feed_link($post_id = '', $feed = '') {
135285 global $id;
135286
135287 if ( empty($post_id) )
135288 $post_id = (int) $id;
135289
135290 if ( empty($feed) )
135291 $feed = get_default_feed();
135292
135293 if ( '' != get_option('permalink_structure') ) {
135294 $url = trailingslashit( get_permalink($post_id) ) . 'feed';
135295 if ( $feed != get_default_feed() )
135296 $url .= "/$feed";
135297 $url = user_trailingslashit($url, 'single_feed');
135298 } else {
135299 $type = get_post_field('post_type', $post_id);
135300 if ( 'page' == $type )
135301 $url = get_option('home') . "/?feed=$feed&page_id=$post_id";
135302 else
135303 $url = get_option('home') . "/?feed=$feed&p=$post_id";
135304 }
135305
135306 return apply_filters('post_comments_feed_link', $url);
135307 }
135308
135309 /**
135310 * Display the comment feed link for a post.
135311 *
135312 * Prints out the comment feed link for a post. Link text is placed in the
135313 * anchor. If no link text is specified, default text is used. If no post ID is
135314 * specified, the current post is used.
135315 *
135316 * @package WordPress
135317 * @subpackage Feed
135318 * @since 2.5.0
135319 *
135320 * @param string $link_text Descriptive text.
135321 * @param int $post_id Optional post ID. Default to current post.
135322 * @param string $feed Optional. Feed format.
135323 * @return string Link to the comment feed for the current post.
135324 */
135325 function post_comments_feed_link( $link_text = '', $post_id = '', $feed = '' ) {
135326 $url = get_post_comments_feed_link($post_id, $feed);
135327 if ( empty($link_text) )
135328 $link_text = __('Comments Feed');
135329
135330 echo "<a href='$url'>$link_text</a>";
135331 }
135332
135333 /**
135334 * Retrieve the feed link for a given author.
135335 *
135336 * Returns a link to the feed for all posts by a given author. A specific feed
135337 * can be requested or left blank to get the default feed.
135338 *
135339 * @package WordPress
135340 * @subpackage Feed
135341 * @since 2.5.0
135342 *
135343 * @param int $author_id ID of an author.
135344 * @param string $feed Optional. Feed type.
135345 * @return string Link to the feed for the author specified by $author_id.
135346 */
135347 function get_author_feed_link( $author_id, $feed = '' ) {
135348 $author_id = (int) $author_id;
135349 $permalink_structure = get_option('permalink_structure');
135350
135351 if ( empty($feed) )
135352 $feed = get_default_feed();
135353
135354 if ( '' == $permalink_structure ) {
135355 $link = get_option('home') . "?feed=$feed&author=" . $author_id;
135356 } else {
135357 $link = get_author_posts_url($author_id);
135358 if ( $feed == get_default_feed() )
135359 $feed_link = 'feed';
135360 else
135361 $feed_link = "feed/$feed";
135362
135363 $link = trailingslashit($link) . user_trailingslashit($feed_link, 'feed');
135364 }
135365
135366 $link = apply_filters('author_feed_link', $link, $feed);
135367
135368 return $link;
135369 }
135370
135371 /**
135372 * Retrieve the feed link for a category.
135373 *
135374 * Returns a link to the feed for all post in a given category. A specific feed
135375 * can be requested or left blank to get the default feed.
135376 *
135377 * @package WordPress
135378 * @subpackage Feed
135379 * @since 2.5.0
135380 *
135381 * @param int $cat_id ID of a category.
135382 * @param string $feed Optional. Feed type.
135383 * @return string Link to the feed for the category specified by $cat_id.
135384 */
135385 function get_category_feed_link($cat_id, $feed = '') {
135386 $cat_id = (int) $cat_id;
135387
135388 $category = get_category($cat_id);
135389
135390 if ( empty($category) || is_wp_error($category) )
135391 return false;
135392
135393 if ( empty($feed) )
135394 $feed = get_default_feed();
135395
135396 $permalink_structure = get_option('permalink_structure');
135397
135398 if ( '' == $permalink_structure ) {
135399 $link = get_option('home') . "?feed=$feed&cat=" . $cat_id;
135400 } else {
135401 $link = get_category_link($cat_id);
135402 if( $feed == get_default_feed() )
135403 $feed_link = 'feed';
135404 else
135405 $feed_link = "feed/$feed";
135406
135407 $link = trailingslashit($link) . user_trailingslashit($feed_link, 'feed');
135408 }
135409
135410 $link = apply_filters('category_feed_link', $link, $feed);
135411
135412 return $link;
135413 }
135414
135415 /**
135416 * Retrieve permalink for feed of tag.
135417 *
135418 * @since 2.3.0
135419 *
135420 * @param int $tag_id Tag ID.
135421 * @param string $feed Optional. Feed type.
135422 * @return string
135423 */
135424 function get_tag_feed_link($tag_id, $feed = '') {
135425 $tag_id = (int) $tag_id;
135426
135427 $tag = get_tag($tag_id);
135428
135429 if ( empty($tag) || is_wp_error($tag) )
135430 return false;
135431
135432 $permalink_structure = get_option('permalink_structure');
135433
135434 if ( empty($feed) )
135435 $feed = get_default_feed();
135436
135437 if ( '' == $permalink_structure ) {
135438 $link = get_option('home') . "?feed=$feed&tag=" . $tag->slug;
135439 } else {
135440 $link = get_tag_link($tag->term_id);
135441 if ( $feed == get_default_feed() )
135442 $feed_link = 'feed';
135443 else
135444 $feed_link = "feed/$feed";
135445 $link = trailingslashit($link) . user_trailingslashit($feed_link, 'feed');
135446 }
135447
135448 $link = apply_filters('tag_feed_link', $link, $feed);
135449
135450 return $link;
135451 }
135452
135453 /**
135454 * Retrieve edit tag link.
135455 *
135456 * @since 2.7.0
135457 *
135458 * @param int $tag_id Tag ID
135459 * @return string
135460 */
135461 function get_edit_tag_link( $tag_id = 0 ) {
135462 $tag = get_term($tag_id, 'post_tag');
135463
135464 if ( !current_user_can('manage_categories') )
135465 return;
135466
135467 $location = admin_url('edit-tags.php?action=edit&tag_ID=') . $tag->term_id;
135468 return apply_filters( 'get_edit_tag_link', $location );
135469 }
135470
135471 /**
135472 * Display or retrieve edit tag link with formatting.
135473 *
135474 * @since 2.7.0
135475 *
135476 * @param string $link Optional. Anchor text.
135477 * @param string $before Optional. Display before edit link.
135478 * @param string $after Optional. Display after edit link.
135479 * @param int|object $tag Tag object or ID
135480 * @return string|null HTML content, if $echo is set to false.
135481 */
135482 function edit_tag_link( $link = '', $before = '', $after = '', $tag = null ) {
135483 $tag = get_term($tag, 'post_tag');
135484
135485 if ( !current_user_can('manage_categories') )
135486 return;
135487
135488 if ( empty($link) )
135489 $link = __('Edit This');
135490
135491 $link = '<a href="' . get_edit_tag_link( $tag->term_id ) . '" title="' . __( 'Edit tag' ) . '">' . $link . '</a>';
135492 echo $before . apply_filters( 'edit_tag_link', $link, $tag->term_id ) . $after;
135493 }
135494
135495 /**
135496 * Retrieve the permalink for the feed of the search results.
135497 *
135498 * @since 2.5.0
135499 *
135500 * @param string $search_query Optional. Search query.
135501 * @param string $feed Optional. Feed type.
135502 * @return string
135503 */
135504 function get_search_feed_link($search_query = '', $feed = '') {
135505 if ( empty($search_query) )
135506 $search = attribute_escape(get_search_query());
135507 else
135508 $search = attribute_escape(stripslashes($search_query));
135509
135510 if ( empty($feed) )
135511 $feed = get_default_feed();
135512
135513 $link = get_option('home') . "?s=$search&feed=$feed";
135514
135515 $link = apply_filters('search_feed_link', $link);
135516
135517 return $link;
135518 }
135519
135520 /**
135521 * Retrieve the permalink for the comments feed of the search results.
135522 *
135523 * @since 2.5.0
135524 *
135525 * @param string $search_query Optional. Search query.
135526 * @param string $feed Optional. Feed type.
135527 * @return string
135528 */
135529 function get_search_comments_feed_link($search_query = '', $feed = '') {
135530 if ( empty($search_query) )
135531 $search = attribute_escape(get_search_query());
135532 else
135533 $search = attribute_escape(stripslashes($search_query));
135534
135535 if ( empty($feed) )
135536 $feed = get_default_feed();
135537
135538 $link = get_option('home') . "?s=$search&feed=comments-$feed";
135539
135540 $link = apply_filters('search_feed_link', $link);
135541
135542 return $link;
135543 }
135544
135545 /**
135546 * Retrieve edit posts link for post.
135547 *
135548 * Can be used within the WordPress loop or outside of it. Can be used with
135549 * pages, posts, attachments, and revisions.
135550 *
135551 * @since 2.3.0
135552 *
135553 * @param int $id Optional. Post ID.
135554 * @param string $context Optional, default to display. How to write the '&', defaults to '&'.
135555 * @return string
135556 */
135557 function get_edit_post_link( $id = 0, $context = 'display' ) {
135558 if ( !$post = &get_post( $id ) )
135559 return;
135560
135561 if ( 'display' == $context )
135562 $action = 'action=edit&';
135563 else
135564 $action = 'action=edit&';
135565
135566 switch ( $post->post_type ) :
135567 case 'page' :
135568 if ( !current_user_can( 'edit_page', $post->ID ) )
135569 return;
135570 $file = 'page';
135571 $var = 'post';
135572 break;
135573 case 'attachment' :
135574 if ( !current_user_can( 'edit_post', $post->ID ) )
135575 return;
135576 $file = 'media';
135577 $var = 'attachment_id';
135578 break;
135579 case 'revision' :
135580 if ( !current_user_can( 'edit_post', $post->ID ) )
135581 return;
135582 $file = 'revision';
135583 $var = 'revision';
135584 $action = '';
135585 break;
135586 default :
135587 if ( !current_user_can( 'edit_post', $post->ID ) )
135588 return;
135589 $file = 'post';
135590 $var = 'post';
135591 break;
135592 endswitch;
135593
135594 return apply_filters( 'get_edit_post_link', admin_url("$file.php?{$action}$var=$post->ID"), $post->ID, $context );
135595 }
135596
135597 /**
135598 * Retrieve edit posts link for post.
135599 *
135600 * @since 1.0.0
135601 *
135602 * @param string $link Optional. Anchor text.
135603 * @param string $before Optional. Display before edit link.
135604 * @param string $after Optional. Display after edit link.
135605 */
135606 function edit_post_link( $link = 'Edit This', $before = '', $after = '' ) {
135607 global $post;
135608
135609 if ( $post->post_type == 'page' ) {
135610 if ( !current_user_can( 'edit_page', $post->ID ) )
135611 return;
135612 } else {
135613 if ( !current_user_can( 'edit_post', $post->ID ) )
135614 return;
135615 }
135616
135617 $link = '<a href="' . get_edit_post_link( $post->ID ) . '" title="' . attribute_escape( __( 'Edit post' ) ) . '">' . $link . '</a>';
135618 echo $before . apply_filters( 'edit_post_link', $link, $post->ID ) . $after;
135619 }
135620
135621 /**
135622 * Retrieve edit comment link.
135623 *
135624 * @since 2.3.0
135625 *
135626 * @param int $comment_id Optional. Comment ID.
135627 * @return string
135628 */
135629 function get_edit_comment_link( $comment_id = 0 ) {
135630 $comment = &get_comment( $comment_id );
135631 $post = &get_post( $comment->comment_post_ID );
135632
135633 if ( $post->post_type == 'page' ) {
135634 if ( !current_user_can( 'edit_page', $post->ID ) )
135635 return;
135636 } else {
135637 if ( !current_user_can( 'edit_post', $post->ID ) )
135638 return;
135639 }
135640
135641 $location = admin_url('comment.php?action=editcomment&c=') . $comment->comment_ID;
135642 return apply_filters( 'get_edit_comment_link', $location );
135643 }
135644
135645 /**
135646 * Display or retrieve edit comment link with formatting.
135647 *
135648 * @since 1.0.0
135649 *
135650 * @param string $link Optional. Anchor text.
135651 * @param string $before Optional. Display before edit link.
135652 * @param string $after Optional. Display after edit link.
135653 * @return string|null HTML content, if $echo is set to false.
135654 */
135655 function edit_comment_link( $link = 'Edit This', $before = '', $after = '' ) {
135656 global $comment, $post;
135657
135658 if ( $post->post_type == 'attachment' ) {
135659 } elseif ( $post->post_type == 'page' ) {
135660 if ( !current_user_can( 'edit_page', $post->ID ) )
135661 return;
135662 } else {
135663 if ( !current_user_can( 'edit_post', $post->ID ) )
135664 return;
135665 }
135666
135667 $link = '<a href="' . get_edit_comment_link( $comment->comment_ID ) . '" title="' . __( 'Edit comment' ) . '">' . $link . '</a>';
135668 echo $before . apply_filters( 'edit_comment_link', $link, $comment->comment_ID ) . $after;
135669 }
135670
135671 /**
135672 * Display edit bookmark (literally a URL external to blog) link.
135673 *
135674 * @since 2.7.0
135675 *
135676 * @param int $link Optional. Bookmark ID.
135677 * @return string
135678 */
135679 function get_edit_bookmark_link( $link = 0 ) {
135680 $link = get_bookmark( $link );
135681
135682 if ( !current_user_can('manage_links') )
135683 return;
135684
135685 $location = admin_url('link.php?action=edit&link_id=') . $link->link_id;
135686 return apply_filters( 'get_edit_bookmark_link', $location, $link->link_id );
135687 }
135688
135689 /**
135690 * Display edit bookmark (literally a URL external to blog) link anchor content.
135691 *
135692 * @since 2.7.0
135693 *
135694 * @param string $link Optional. Anchor text.
135695 * @param string $before Optional. Display before edit link.
135696 * @param string $after Optional. Display after edit link.
135697 * @param int $bookmark Optional. Bookmark ID.
135698 */
135699 function edit_bookmark_link( $link = '', $before = '', $after = '', $bookmark = null ) {
135700 $bookmark = get_bookmark($bookmark);
135701
135702 if ( !current_user_can('manage_links') )
135703 return;
135704
135705 if ( empty($link) )
135706 $link = __('Edit This');
135707
135708 $link = '<a href="' . get_edit_bookmark_link( $link ) . '" title="' . __( 'Edit link' ) . '">' . $link . '</a>';
135709 echo $before . apply_filters( 'edit_bookmark_link', $link, $bookmark->link_id ) . $after;
135710 }
135711
135712 // Navigation links
135713
135714 /**
135715 * Retrieve previous post link that is adjacent to current post.
135716 *
135717 * @since 1.5.0
135718 *
135719 * @param bool $in_same_cat Optional. Whether link should be in same category.
135720 * @param string $excluded_categories Optional. Excluded categories IDs.
135721 * @return string
135722 */
135723 function get_previous_post($in_same_cat = false, $excluded_categories = '') {
135724 return get_adjacent_post($in_same_cat, $excluded_categories);
135725 }
135726
135727 /**
135728 * Retrieve next post link that is adjacent to current post.
135729 *
135730 * @since 1.5.0
135731 *
135732 * @param bool $in_same_cat Optional. Whether link should be in same category.
135733 * @param string $excluded_categories Optional. Excluded categories IDs.
135734 * @return string
135735 */
135736 function get_next_post($in_same_cat = false, $excluded_categories = '') {
135737 return get_adjacent_post($in_same_cat, $excluded_categories, false);
135738 }
135739
135740 /**
135741 * Retrieve adjacent post link.
135742 *
135743 * Can either be next or previous post link.
135744 *
135745 * @since 2.5.0
135746 *
135747 * @param bool $in_same_cat Optional. Whether link should be in same category.
135748 * @param string $excluded_categories Optional. Excluded categories IDs.
135749 * @param bool $previous Optional. Whether to retrieve previous post.
135750 * @return string
135751 */
135752 function get_adjacent_post($in_same_cat = false, $excluded_categories = '', $previous = true) {
135753 global $post, $wpdb;
135754
135755 if( empty($post) || !is_single() || is_attachment() )
135756 return null;
135757
135758 $current_post_date = $post->post_date;
135759
135760 $join = '';
135761 $posts_in_ex_cats_sql = '';
135762 if ( $in_same_cat || !empty($excluded_categories) ) {
135763 $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";
135764
135765 if ( $in_same_cat ) {
135766 $cat_array = wp_get_object_terms($post->ID, 'category', 'fields=ids');
135767 $join .= " AND tt.taxonomy = 'category' AND tt.term_id IN (" . implode(',', $cat_array) . ")";
135768 }
135769
135770 $posts_in_ex_cats_sql = "AND tt.taxonomy = 'category'";
135771 if ( !empty($excluded_categories) ) {
135772 $excluded_categories = array_map('intval', explode(' and ', $excluded_categories));
135773 if ( !empty($cat_array) ) {
135774 $excluded_categories = array_diff($excluded_categories, $cat_array);
135775 $posts_in_ex_cats_sql = '';
135776 }
135777
135778 if ( !empty($excluded_categories) ) {
135779 $posts_in_ex_cats_sql = " AND tt.taxonomy = 'category' AND tt.term_id NOT IN (" . implode($excluded_categories, ',') . ')';
135780 }
135781 }
135782 }
135783
135784 $adjacent = $previous ? 'previous' : 'next';
135785 $op = $previous ? '<' : '>';
135786 $order = $previous ? 'DESC' : 'ASC';
135787
135788 $join = apply_filters( "get_{$adjacent}_post_join", $join, $in_same_cat, $excluded_categories );
135789 $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 );
135790 $sort = apply_filters( "get_{$adjacent}_post_sort", "ORDER BY p.post_date $order LIMIT 1" );
135791
135792 return $wpdb->get_row("SELECT p.* FROM $wpdb->posts AS p $join $where $sort");
135793 }
135794
135795 /**
135796 * Display previous post link that is adjacent to the current post.
135797 *
135798 * @since 1.5.0
135799 *
135800 * @param string $format Optional. Link anchor format.
135801 * @param string $link Optional. Link permalink format.
135802 * @param bool $in_same_cat Optional. Whether link should be in same category.
135803 * @param string $excluded_categories Optional. Excluded categories IDs.
135804 */
135805 function previous_post_link($format='« %link', $link='%title', $in_same_cat = false, $excluded_categories = '') {
135806 adjacent_post_link($format, $link, $in_same_cat, $excluded_categories, true);
135807 }
135808
135809 /**
135810 * Display next post link that is adjacent to the current post.
135811 *
135812 * @since 1.5.0
135813 *
135814 * @param string $format Optional. Link anchor format.
135815 * @param string $link Optional. Link permalink format.
135816 * @param bool $in_same_cat Optional. Whether link should be in same category.
135817 * @param string $excluded_categories Optional. Excluded categories IDs.
135818 */
135819 function next_post_link($format='%link »', $link='%title', $in_same_cat = false, $excluded_categories = '') {
135820 adjacent_post_link($format, $link, $in_same_cat, $excluded_categories, false);
135821 }
135822
135823 /**
135824 * Display adjacent post link.
135825 *
135826 * Can be either next post link or previous.
135827 *
135828 * @since 2.5.0
135829 *
135830 * @param string $format Link anchor format.
135831 * @param string $link Link permalink format.
135832 * @param bool $in_same_cat Optional. Whether link should be in same category.
135833 * @param string $excluded_categories Optional. Excluded categories IDs.
135834 * @param bool $previous Optional, default is true. Whether display link to previous post.
135835 */
135836 function adjacent_post_link($format, $link, $in_same_cat = false, $excluded_categories = '', $previous = true) {
135837 if ( $previous && is_attachment() )
135838 $post = & get_post($GLOBALS['post']->post_parent);
135839 else
135840 $post = get_adjacent_post($in_same_cat, $excluded_categories, $previous);
135841
135842 if ( !$post )
135843 return;
135844
135845 $title = $post->post_title;
135846
135847 if ( empty($post->post_title) )
135848 $title = $previous ? __('Previous Post') : __('Next Post');
135849
135850 $title = apply_filters('the_title', $title, $post);
135851 $date = mysql2date(get_option('date_format'), $post->post_date);
135852
135853 $string = '<a href="'.get_permalink($post).'">';
135854 $link = str_replace('%title', $title, $link);
135855 $link = str_replace('%date', $date, $link);
135856 $link = $string . $link . '</a>';
135857
135858 $format = str_replace('%link', $link, $format);
135859
135860 $adjacent = $previous ? 'previous' : 'next';
135861 echo apply_filters( "{$adjacent}_post_link", $format, $link );
135862 }
135863
135864 /**
135865 * Retrieve get links for page numbers.
135866 *
135867 * @since 1.5.0
135868 *
135869 * @param int $pagenum Optional. Page ID.
135870 * @return string
135871 */
135872 function get_pagenum_link($pagenum = 1) {
135873 global $wp_rewrite;
135874
135875 $pagenum = (int) $pagenum;
135876
135877 $request = remove_query_arg( 'paged' );
135878
135879 $home_root = parse_url(get_option('home'));
135880 $home_root = ( isset($home_root['path']) ) ? $home_root['path'] : '';
135881 $home_root = preg_quote( trailingslashit( $home_root ), '|' );
135882
135883 $request = preg_replace('|^'. $home_root . '|', '', $request);
135884 $request = preg_replace('|^/+|', '', $request);
135885
135886 if ( !$wp_rewrite->using_permalinks() || is_admin() ) {
135887 $base = trailingslashit( get_bloginfo( 'home' ) );
135888
135889 if ( $pagenum > 1 ) {
135890 $result = add_query_arg( 'paged', $pagenum, $base . $request );
135891 } else {
135892 $result = $base . $request;
135893 }
135894 } else {
135895 $qs_regex = '|\?.*?$|';
135896 preg_match( $qs_regex, $request, $qs_match );
135897
135898 if ( !empty( $qs_match[0] ) ) {
135899 $query_string = $qs_match[0];
135900 $request = preg_replace( $qs_regex, '', $request );
135901 } else {
135902 $query_string = '';
135903 }
135904
135905 $request = preg_replace( '|page/\d+/?$|', '', $request);
135906 $request = preg_replace( '|^index\.php|', '', $request);
135907 $request = ltrim($request, '/');
135908
135909 $base = trailingslashit( get_bloginfo( 'url' ) );
135910
135911 if ( $wp_rewrite->using_index_permalinks() && ( $pagenum > 1 || '' != $request ) )
135912 $base .= 'index.php/';
135913
135914 if ( $pagenum > 1 ) {
135915 $request = ( ( !empty( $request ) ) ? trailingslashit( $request ) : $request ) . user_trailingslashit( 'page/' . $pagenum, 'paged' );
135916 }
135917
135918 $result = $base . $request . $query_string;
135919 }
135920
135921 $result = apply_filters('get_pagenum_link', $result);
135922
135923 return $result;
135924 }
135925
135926 /**
135927 * Retrieve next posts pages link.
135928 *
135929 * Backported from 2.1.3 to 2.0.10.
135930 *
135931 * @since 2.0.10
135932 *
135933 * @param int $max_page Optional. Max pages.
135934 * @return string
135935 */
135936 function get_next_posts_page_link($max_page = 0) {
135937 global $paged;
135938
135939 if ( !is_single() ) {
135940 if ( !$paged )
135941 $paged = 1;
135942 $nextpage = intval($paged) + 1;
135943 if ( !$max_page || $max_page >= $nextpage )
135944 return get_pagenum_link($nextpage);
135945 }
135946 }
135947
135948 /**
135949 * Display or return the next posts pages link.
135950 *
135951 * @since 0.71
135952 *
135953 * @param int $max_page Optional. Max pages.
135954 * @param boolean $echo Optional. Echo or return;
135955 */
135956 function next_posts( $max_page = 0, $echo = true ) {
135957 $output = clean_url( get_next_posts_page_link( $max_page ) );
135958
135959 if ( $echo )
135960 echo $output;
135961 else
135962 return $output;
135963 }
135964
135965 /**
135966 * Return the next posts pages link.
135967 *
135968 * @since 2.7.0
135969 *
135970 * @param string $label Content for link text.
135971 * @param int $max_page Optional. Max pages.
135972 * @return string|null
135973 */
135974 function get_next_posts_link( $label = 'Next Page »', $max_page = 0 ) {
135975 global $paged, $wp_query;
135976
135977 if ( !$max_page ) {
135978 $max_page = $wp_query->max_num_pages;
135979 }
135980
135981 if ( !$paged )
135982 $paged = 1;
135983
135984 $nextpage = intval($paged) + 1;
135985
135986 if ( !is_single() && ( empty($paged) || $nextpage <= $max_page) ) {
135987 $attr = apply_filters( 'next_posts_link_attributes', '' );
135988 return '<a href="' . next_posts( $max_page, false ) . "\" $attr>". preg_replace('/&([^#])(?![a-z]{1,8};)/', '&$1', $label) .'</a>';
135989 }
135990 }
135991
135992 /**
135993 * Display the next posts pages link.
135994 *
135995 * @since 0.71
135996 * @uses get_next_posts_link()
135997 *
135998 * @param string $label Content for link text.
135999 * @param int $max_page Optional. Max pages.
136000 */
136001 function next_posts_link( $label = 'Next Page »', $max_page = 0 ) {
136002 echo get_next_posts_link( $label, $max_page );
136003 }
136004
136005 /**
136006 * Retrieve previous post pages link.
136007 *
136008 * Will only return string, if not on a single page or post.
136009 *
136010 * Backported to 2.0.10 from 2.1.3.
136011 *
136012 * @since 2.0.10
136013 *
136014 * @return string|null
136015 */
136016 function get_previous_posts_page_link() {
136017 global $paged;
136018
136019 if ( !is_single() ) {
136020 $nextpage = intval($paged) - 1;
136021 if ( $nextpage < 1 )
136022 $nextpage = 1;
136023 return get_pagenum_link($nextpage);
136024 }
136025 }
136026
136027 /**
136028 * Display or return the previous posts pages link.
136029 *
136030 * @since 0.71
136031 *
136032 * @param boolean $echo Optional. Echo or return;
136033 */
136034 function previous_posts( $echo = true ) {
136035 $output = clean_url( get_previous_posts_page_link() );
136036
136037 if ( $echo )
136038 echo $output;
136039 else
136040 return $output;
136041 }
136042
136043 /**
136044 * Return the previous posts pages link.
136045 *
136046 * @since 2.7.0
136047 *
136048 * @param string $label Optional. Previous page link text.
136049 * @return string|null
136050 */
136051 function get_previous_posts_link( $label = '« Previous Page' ) {
136052 global $paged;
136053
136054 if ( !is_single() && $paged > 1 ) {
136055 $attr = apply_filters( 'previous_posts_link_attributes', '' );
136056 return '<a href="' . previous_posts( false ) . "\" $attr>". preg_replace( '/&([^#])(?![a-z]{1,8};)/', '&$1', $label ) .'</a>';
136057 }
136058 }
136059
136060 /**
136061 * Display the previous posts page link.
136062 *
136063 * @since 0.71
136064 * @uses get_previous_posts_link()
136065 *
136066 * @param string $label Optional. Previous page link text.
136067 */
136068 function previous_posts_link( $label = '« Previous Page' ) {
136069 echo get_previous_posts_link( $label );
136070 }
136071
136072 /**
136073 * Display post pages link navigation for previous and next pages.
136074 *
136075 * @since 0.71
136076 *
136077 * @param string $sep Optional. Separator for posts navigation links.
136078 * @param string $prelabel Optional. Label for previous pages.
136079 * @param string $nxtlabel Optional Label for next pages.
136080 */
136081 function posts_nav_link( $sep = ' — ', $prelabel = '« Previous Page', $nxtlabel = 'Next Page »' ) {
136082 global $wp_query;
136083 if ( !is_singular() ) {
136084 $max_num_pages = $wp_query->max_num_pages;
136085 $paged = get_query_var('paged');
136086
136087 //only have sep if there's both prev and next results
136088 if ($paged < 2 || $paged >= $max_num_pages) {
136089 $sep = '';
136090 }
136091
136092 if ( $max_num_pages > 1 ) {
136093 previous_posts_link($prelabel);
136094 echo preg_replace('/&([^#])(?![a-z]{1,8};)/', '&$1', $sep);
136095 next_posts_link($nxtlabel);
136096 }
136097 }
136098 }
136099
136100 /**
136101 * Retrieve page numbers links.
136102 *
136103 * @since 2.7.0
136104 *
136105 * @param int $pagenum Optional. Page number.
136106 * @return string
136107 */
136108 function get_comments_pagenum_link( $pagenum = 1, $max_page = 0 ) {
136109 global $post, $wp_rewrite;
136110
136111 $pagenum = (int) $pagenum;
136112
136113 $result = get_permalink( $post->ID );
136114
136115 if ( 'newest' == get_option('default_comments_page') ) {
136116 if ( $pagenum != $max_page ) {
136117 if ( $wp_rewrite->using_permalinks() )
136118 $result = user_trailingslashit( trailingslashit($result) . 'comment-page-' . $pagenum, 'commentpaged');
136119 else
136120 $result = add_query_arg( 'cpage', $pagenum, $result );
136121 }
136122 } elseif ( $pagenum > 1 ) {
136123 if ( $wp_rewrite->using_permalinks() )
136124 $result = user_trailingslashit( trailingslashit($result) . 'comment-page-' . $pagenum, 'commentpaged');
136125 else
136126 $result = add_query_arg( 'cpage', $pagenum, $result );
136127 }
136128
136129 $result .= '#comments';
136130
136131 $result = apply_filters('get_comments_pagenum_link', $result);
136132
136133 return $result;
136134 }
136135
136136 /**
136137 * Display link to next comments pages.
136138 *
136139 * @since 2.7.0
136140 *
136141 * @param string $label Optional. Label for link text.
136142 * @param int $max_page Optional. Max page.
136143 */
136144 function next_comments_link($label='', $max_page = 0) {
136145 global $wp_query;
136146
136147 if ( !is_singular() )
136148 return;
136149
136150 $page = get_query_var('cpage');
136151
136152 if ( !$page )
136153 $page = 1;
136154
136155 $nextpage = intval($page) + 1;
136156
136157 if ( empty($max_page) )
136158 $max_page = $wp_query->max_num_comment_pages;
136159
136160 if ( empty($max_page) )
136161 $max_page = get_comment_pages_count();
136162
136163 if ( $nextpage > $max_page )
136164 return;
136165
136166 if ( empty($label) )
136167 $label = __('Newer Comments »');
136168
136169 echo '<a href="' . clean_url( get_comments_pagenum_link( $nextpage, $max_page ) );
136170 $attr = apply_filters( 'next_comments_link_attributes', '' );
136171 echo "\" $attr>". preg_replace('/&([^#])(?![a-z]{1,8};)/', '&$1', $label) .'</a>';
136172 }
136173
136174 /**
136175 * Display the previous comments page link.
136176 *
136177 * @since 2.7.0
136178 *
136179 * @param string $label Optional. Label for comments link text.
136180 */
136181 function previous_comments_link($label='') {
136182
136183 if ( !is_singular() )
136184 return;
136185
136186 $page = get_query_var('cpage');
136187
136188 if ( !$page )
136189 $page = 1;
136190
136191 if ( $page <= 1 )
136192 return;
136193
136194 $prevpage = intval($page) - 1;
136195
136196 if ( empty($label) )
136197 $label = __('« Older Comments');
136198
136199 echo '<a href="' . clean_url(get_comments_pagenum_link($prevpage));
136200 $attr = apply_filters( 'previous_comments_link_attributes', '' );
136201 echo "\" $attr>". preg_replace('/&([^#])(?![a-z]{1,8};)/', '&$1', $label) .'</a>';
136202 }
136203
136204 /**
136205 * Create pagination links for the comments on the current post.
136206 *
136207 * @see paginate_links()
136208 * @since 2.7.0
136209 *
136210 * @param string|array $args Optional args. See paginate_links.
136211 * @return string Markup for pagination links.
136212 */
136213 function paginate_comments_links($args = array()) {
136214 global $wp_query, $wp_rewrite;
136215
136216 if ( !is_singular() )
136217 return;
136218
136219 $page = get_query_var('cpage');
136220 if ( !$page )
136221 $page = 1;
136222 $max_page = get_comment_pages_count();
136223 $defaults = array(
136224 'base' => add_query_arg( 'cpage', '%#%' ),
136225 'format' => '',
136226 'total' => $max_page,
136227 'current' => $page,
136228 'echo' => true,
136229 'add_fragment' => '#comments'
136230 );
136231 if ( $wp_rewrite->using_permalinks() )
136232 $defaults['base'] = user_trailingslashit(get_permalink() . 'comment-page-%#%', 'commentpaged');
136233
136234 $args = wp_parse_args( $args, $defaults );
136235 $page_links = paginate_links( $args );
136236
136237 if ( $args['echo'] )
136238 echo $page_links;
136239 else
136240 return $page_links;
136241 }
136242
136243 /**
136244 * Retrieve shortcut link.
136245 *
136246 * Use this in 'a' element 'href' attribute.
136247 *
136248 * @since 2.6.0
136249 *
136250 * @return string
136251 */
136252 function get_shortcut_link() {
136253 $link = "javascript:
136254 var d=document,
136255 w=window,
136256 e=w.getSelection,
136257 k=d.getSelection,
136258 x=d.selection,
136259 s=(e?e():(k)?k():(x?x.createRange().text:0)),
136260 f='" . admin_url('press-this.php') . "',
136261 l=d.location,
136262 e=encodeURIComponent,
136263 g=f+'?u='+e(l.href)+'&t='+e(d.title)+'&s='+e(s)+'&v=2';
136264 function a(){
136265 if(!w.open(g,'t','toolbar=0,resizable=0,scrollbars=1,status=1,width=720,height=570')){
136266 l.href=g;
136267 }
136268 }";
136269 if (strpos($_SERVER['HTTP_USER_AGENT'], 'Firefox') !== false)
136270 $link .= 'setTimeout(a,0);';
136271 else
136272 $link .= 'a();';
136273
136274 $link .= "void(0);";
136275
136276 $link = str_replace(array("\r", "\n", "\t"), '', $link);
136277
136278 return apply_filters('shortcut_link', $link);
136279 }
136280
136281 /**
136282 * Retrieve the site url.
136283 *
136284 * Returns the 'site_url' option with the appropriate protocol, 'https' if
136285 * is_ssl() and 'http' otherwise. If $scheme is 'http' or 'https', is_ssl() is
136286 * overridden.
136287 *
136288 * @package WordPress
136289 * @since 2.6.0
136290 *
136291 * @param string $path Optional. Path relative to the site url.
136292 * @param string $scheme Optional. Scheme to give the site url context. Currently 'http','https', 'login', 'login_post', or 'admin'.
136293 * @return string Site url link with optional path appended.
136294 */
136295 function site_url($path = '', $scheme = null) {
136296 // should the list of allowed schemes be maintained elsewhere?
136297 $orig_scheme = $scheme;
136298 if ( !in_array($scheme, array('http', 'https')) ) {
136299 if ( ('login_post' == $scheme) && ( force_ssl_login() || force_ssl_admin() ) )
136300 $scheme = 'https';
136301 elseif ( ('login' == $scheme) && ( force_ssl_admin() ) )
136302 $scheme = 'https';
136303 elseif ( ('admin' == $scheme) && force_ssl_admin() )
136304 $scheme = 'https';
136305 else
136306 $scheme = ( is_ssl() ? 'https' : 'http' );
136307 }
136308
136309 $url = str_replace( 'http://', "{$scheme}://", get_option('siteurl') );
136310
136311 if ( !empty($path) && is_string($path) && strpos($path, '..') === false )
136312 $url .= '/' . ltrim($path, '/');
136313
136314 return apply_filters('site_url', $url, $path, $orig_scheme);
136315 }
136316
136317 /**
136318 * Retrieve the url to the admin area.
136319 *
136320 * @package WordPress
136321 * @since 2.6.0
136322 *
136323 * @param string $path Optional path relative to the admin url
136324 * @return string Admin url link with optional path appended
136325 */
136326 function admin_url($path = '') {
136327 $url = site_url('wp-admin/', 'admin');
136328
136329 if ( !empty($path) && is_string($path) && strpos($path, '..') === false )
136330 $url .= ltrim($path, '/');
136331
136332 return $url;
136333 }
136334
136335 /**
136336 * Retrieve the url to the includes directory.
136337 *
136338 * @package WordPress
136339 * @since 2.6.0
136340 *
136341 * @param string $path Optional. Path relative to the includes url.
136342 * @return string Includes url link with optional path appended.
136343 */
136344 function includes_url($path = '') {
136345 $url = site_url() . '/' . WPINC . '/';
136346
136347 if ( !empty($path) && is_string($path) && strpos($path, '..') === false )
136348 $url .= ltrim($path, '/');
136349
136350 return $url;
136351 }
136352
136353 /**
136354 * Retrieve the url to the content directory.
136355 *
136356 * @package WordPress
136357 * @since 2.6.0
136358 *
136359 * @param string $path Optional. Path relative to the content url.
136360 * @return string Content url link with optional path appended.
136361 */
136362 function content_url($path = '') {
136363 $scheme = ( is_ssl() ? 'https' : 'http' );
136364 $url = WP_CONTENT_URL;
136365 if ( 0 === strpos($url, 'http') ) {
136366 if ( is_ssl() )
136367 $url = str_replace( 'http://', "{$scheme}://", $url );
136368 }
136369
136370 if ( !empty($path) && is_string($path) && strpos($path, '..') === false )
136371 $url .= '/' . ltrim($path, '/');
136372
136373 return $url;
136374 }
136375
136376 /**
136377 * Retrieve the url to the plugins directory.
136378 *
136379 * @package WordPress
136380 * @since 2.6.0
136381 *
136382 * @param string $path Optional. Path relative to the plugins url.
136383 * @return string Plugins url link with optional path appended.
136384 */
136385 function plugins_url($path = '') {
136386 $scheme = ( is_ssl() ? 'https' : 'http' );
136387 $url = WP_PLUGIN_URL;
136388 if ( 0 === strpos($url, 'http') ) {
136389 if ( is_ssl() )
136390 $url = str_replace( 'http://', "{$scheme}://", $url );
136391 }
136392
136393 if ( !empty($path) && is_string($path) && strpos($path, '..') === false )
136394 $url .= '/' . ltrim($path, '/');
136395
136396 return $url;
136397 }
136398
136399 ?>