web/wp-includes/link-template.php
changeset 204 09a1c134465b
parent 194 32102edaa81b
equal deleted inserted replaced
203:f507feede89a 204:09a1c134465b
    52  *
    52  *
    53  * @since 0.71
    53  * @since 0.71
    54  *
    54  *
    55  * @param string $mode Permalink mode can be either 'title', 'id', or default, which is 'id'.
    55  * @param string $mode Permalink mode can be either 'title', 'id', or default, which is 'id'.
    56  */
    56  */
    57 function permalink_anchor($mode = 'id') {
    57 function permalink_anchor( $mode = 'id' ) {
    58 	global $post;
    58 	$post = get_post();
    59 	switch ( strtolower($mode) ) {
    59 	switch ( strtolower( $mode ) ) {
    60 		case 'title':
    60 		case 'title':
    61 			$title = sanitize_title($post->post_title) . '-' . $post->ID;
    61 			$title = sanitize_title( $post->post_title ) . '-' . $post->ID;
    62 			echo '<a id="'.$title.'"></a>';
    62 			echo '<a id="'.$title.'"></a>';
    63 			break;
    63 			break;
    64 		case 'id':
    64 		case 'id':
    65 		default:
    65 		default:
    66 			echo '<a id="post-' . $post->ID . '"></a>';
    66 			echo '<a id="post-' . $post->ID . '"></a>';
    75  *
    75  *
    76  * @param int $id Optional. Post ID.
    76  * @param int $id Optional. Post ID.
    77  * @param bool $leavename Optional, defaults to false. Whether to keep post name or page name.
    77  * @param bool $leavename Optional, defaults to false. Whether to keep post name or page name.
    78  * @return string
    78  * @return string
    79  */
    79  */
    80 function get_permalink($id = 0, $leavename = false) {
    80 function get_permalink( $id = 0, $leavename = false ) {
    81 	$rewritecode = array(
    81 	$rewritecode = array(
    82 		'%year%',
    82 		'%year%',
    83 		'%monthnum%',
    83 		'%monthnum%',
    84 		'%day%',
    84 		'%day%',
    85 		'%hour%',
    85 		'%hour%',
    94 
    94 
    95 	if ( is_object($id) && isset($id->filter) && 'sample' == $id->filter ) {
    95 	if ( is_object($id) && isset($id->filter) && 'sample' == $id->filter ) {
    96 		$post = $id;
    96 		$post = $id;
    97 		$sample = true;
    97 		$sample = true;
    98 	} else {
    98 	} else {
    99 		$post = &get_post($id);
    99 		$post = get_post($id);
   100 		$sample = false;
   100 		$sample = false;
   101 	}
   101 	}
   102 
   102 
   103 	if ( empty($post->ID) )
   103 	if ( empty($post->ID) )
   104 		return false;
   104 		return false;
   105 
   105 
   106 	if ( $post->post_type == 'page' )
   106 	if ( $post->post_type == 'page' )
   107 		return get_page_link($post->ID, $leavename, $sample);
   107 		return get_page_link($post->ID, $leavename, $sample);
   108 	elseif ( $post->post_type == 'attachment' )
   108 	elseif ( $post->post_type == 'attachment' )
   109 		return get_attachment_link($post->ID);
   109 		return get_attachment_link( $post->ID, $leavename );
   110 	elseif ( in_array($post->post_type, get_post_types( array('_builtin' => false) ) ) )
   110 	elseif ( in_array($post->post_type, get_post_types( array('_builtin' => false) ) ) )
   111 		return get_post_permalink($post->ID, $leavename, $sample);
   111 		return get_post_permalink($post->ID, $leavename, $sample);
   112 
   112 
   113 	$permalink = get_option('permalink_structure');
   113 	$permalink = get_option('permalink_structure');
   114 
   114 
   120 		$category = '';
   120 		$category = '';
   121 		if ( strpos($permalink, '%category%') !== false ) {
   121 		if ( strpos($permalink, '%category%') !== false ) {
   122 			$cats = get_the_category($post->ID);
   122 			$cats = get_the_category($post->ID);
   123 			if ( $cats ) {
   123 			if ( $cats ) {
   124 				usort($cats, '_usort_terms_by_ID'); // order by ID
   124 				usort($cats, '_usort_terms_by_ID'); // order by ID
   125 				$category = $cats[0]->slug;
   125 				$category_object = apply_filters( 'post_link_category', $cats[0], $cats, $post );
   126 				if ( $parent = $cats[0]->parent )
   126 				$category_object = get_term( $category_object, 'category' );
       
   127 				$category = $category_object->slug;
       
   128 				if ( $parent = $category_object->parent )
   127 					$category = get_category_parents($parent, false, '/', true) . $category;
   129 					$category = get_category_parents($parent, false, '/', true) . $category;
   128 			}
   130 			}
   129 			// show default category in permalinks, without
   131 			// show default category in permalinks, without
   130 			// having to assign it explicitly
   132 			// having to assign it explicitly
   131 			if ( empty($category) ) {
   133 			if ( empty($category) ) {
   174  * @return string
   176  * @return string
   175  */
   177  */
   176 function get_post_permalink( $id = 0, $leavename = false, $sample = false ) {
   178 function get_post_permalink( $id = 0, $leavename = false, $sample = false ) {
   177 	global $wp_rewrite;
   179 	global $wp_rewrite;
   178 
   180 
   179 	$post = &get_post($id);
   181 	$post = get_post($id);
   180 
   182 
   181 	if ( is_wp_error( $post ) )
   183 	if ( is_wp_error( $post ) )
   182 		return $post;
   184 		return $post;
   183 
   185 
   184 	$post_link = $wp_rewrite->get_extra_permastruct($post->post_type);
   186 	$post_link = $wp_rewrite->get_extra_permastruct($post->post_type);
   228  *
   230  *
   229  * Respects page_on_front. Use this one.
   231  * Respects page_on_front. Use this one.
   230  *
   232  *
   231  * @since 1.5.0
   233  * @since 1.5.0
   232  *
   234  *
   233  * @param int $id Optional. Post ID.
   235  * @param mixed $post Optional. Post ID or object.
   234  * @param bool $leavename Optional, defaults to false. Whether to keep page name.
   236  * @param bool $leavename Optional, defaults to false. Whether to keep page name.
   235  * @param bool $sample Optional, defaults to false. Is it a sample permalink.
   237  * @param bool $sample Optional, defaults to false. Is it a sample permalink.
   236  * @return string
   238  * @return string
   237  */
   239  */
   238 function get_page_link( $id = false, $leavename = false, $sample = false ) {
   240 function get_page_link( $post = false, $leavename = false, $sample = false ) {
   239 	global $post;
   241 	$post = get_post( $post );
   240 
   242 
   241 	$id = (int) $id;
   243 	if ( 'page' == get_option( 'show_on_front' ) && $post->ID == get_option( 'page_on_front' ) )
   242 	if ( !$id )
       
   243 		$id = (int) $post->ID;
       
   244 
       
   245 	if ( 'page' == get_option('show_on_front') && $id == get_option('page_on_front') )
       
   246 		$link = home_url('/');
   244 		$link = home_url('/');
   247 	else
   245 	else
   248 		$link = _get_page_link( $id , $leavename, $sample );
   246 		$link = _get_page_link( $post, $leavename, $sample );
   249 
   247 
   250 	return apply_filters('page_link', $link, $id, $sample);
   248 	return apply_filters( 'page_link', $link, $post->ID, $sample );
   251 }
   249 }
   252 
   250 
   253 /**
   251 /**
   254  * Retrieve the page permalink.
   252  * Retrieve the page permalink.
   255  *
   253  *
   256  * Ignores page_on_front. Internal use only.
   254  * Ignores page_on_front. Internal use only.
   257  *
   255  *
   258  * @since 2.1.0
   256  * @since 2.1.0
   259  * @access private
   257  * @access private
   260  *
   258  *
   261  * @param int $id Optional. Post ID.
   259  * @param mixed $post Optional. Post ID or object.
   262  * @param bool $leavename Optional. Leave name.
   260  * @param bool $leavename Optional. Leave name.
   263  * @param bool $sample Optional. Sample permalink.
   261  * @param bool $sample Optional. Sample permalink.
   264  * @return string
   262  * @return string
   265  */
   263  */
   266 function _get_page_link( $id = false, $leavename = false, $sample = false ) {
   264 function _get_page_link( $post = false, $leavename = false, $sample = false ) {
   267 	global $post, $wp_rewrite;
   265 	global $wp_rewrite;
   268 
   266 
   269 	if ( !$id )
   267 	$post = get_post( $post );
   270 		$id = (int) $post->ID;
       
   271 	else
       
   272 		$post = &get_post($id);
       
   273 
   268 
   274 	$draft_or_pending = in_array( $post->post_status, array( 'draft', 'pending', 'auto-draft' ) );
   269 	$draft_or_pending = in_array( $post->post_status, array( 'draft', 'pending', 'auto-draft' ) );
   275 
   270 
   276 	$link = $wp_rewrite->get_page_permastruct();
   271 	$link = $wp_rewrite->get_page_permastruct();
   277 
   272 
   278 	if ( !empty($link) && ( ( isset($post->post_status) && !$draft_or_pending ) || $sample ) ) {
   273 	if ( !empty($link) && ( ( isset($post->post_status) && !$draft_or_pending ) || $sample ) ) {
   279 		if ( ! $leavename ) {
   274 		if ( ! $leavename ) {
   280 			$link = str_replace('%pagename%', get_page_uri($id), $link);
   275 			$link = str_replace('%pagename%', get_page_uri( $post ), $link);
   281 		}
   276 		}
   282 
   277 
   283 		$link = home_url($link);
   278 		$link = home_url($link);
   284 		$link = user_trailingslashit($link, 'page');
   279 		$link = user_trailingslashit($link, 'page');
   285 	} else {
   280 	} else {
   286 		$link = home_url("?page_id=$id");
   281 		$link = home_url( '?page_id=' . $post->ID );
   287 	}
   282 	}
   288 
   283 
   289 	return apply_filters( '_get_page_link', $link, $id );
   284 	return apply_filters( '_get_page_link', $link, $post->ID );
   290 }
   285 }
   291 
   286 
   292 /**
   287 /**
   293  * Retrieve permalink for attachment.
   288  * Retrieve permalink for attachment.
   294  *
   289  *
   295  * This can be used in the WordPress Loop or outside of it.
   290  * This can be used in the WordPress Loop or outside of it.
   296  *
   291  *
   297  * @since 2.0.0
   292  * @since 2.0.0
   298  *
   293  *
   299  * @param int $id Optional. Post ID.
   294  * @param mixed $post Optional. Post ID or object.
   300  * @return string
   295  * @param bool $leavename Optional. Leave name.
   301  */
   296  * @return string
   302 function get_attachment_link($id = false) {
   297  */
   303 	global $post, $wp_rewrite;
   298 function get_attachment_link( $post = null, $leavename = false ) {
       
   299 	global $wp_rewrite;
   304 
   300 
   305 	$link = false;
   301 	$link = false;
   306 
   302 
   307 	if ( ! $id)
   303 	$post = get_post( $post );
   308 		$id = (int) $post->ID;
   304 
   309 
   305 	if ( $wp_rewrite->using_permalinks() && ( $post->post_parent > 0 ) && ( $post->post_parent != $post->ID ) ) {
   310 	$object = get_post($id);
   306 		$parent = get_post($post->post_parent);
   311 	if ( $wp_rewrite->using_permalinks() && ($object->post_parent > 0) && ($object->post_parent != $id) ) {
       
   312 		$parent = get_post($object->post_parent);
       
   313 		if ( 'page' == $parent->post_type )
   307 		if ( 'page' == $parent->post_type )
   314 			$parentlink = _get_page_link( $object->post_parent ); // Ignores page_on_front
   308 			$parentlink = _get_page_link( $post->post_parent ); // Ignores page_on_front
   315 		else
   309 		else
   316 			$parentlink = get_permalink( $object->post_parent );
   310 			$parentlink = get_permalink( $post->post_parent );
   317 
   311 
   318 		if ( is_numeric($object->post_name) || false !== strpos(get_option('permalink_structure'), '%category%') )
   312 		if ( is_numeric($post->post_name) || false !== strpos(get_option('permalink_structure'), '%category%') )
   319 			$name = 'attachment/' . $object->post_name; // <permalink>/<int>/ is paged so we use the explicit attachment marker
   313 			$name = 'attachment/' . $post->post_name; // <permalink>/<int>/ is paged so we use the explicit attachment marker
   320 		else
   314 		else
   321 			$name = $object->post_name;
   315 			$name = $post->post_name;
   322 
   316 
   323 		if ( strpos($parentlink, '?') === false )
   317 		if ( strpos($parentlink, '?') === false )
   324 			$link = user_trailingslashit( trailingslashit($parentlink) . $name );
   318 			$link = user_trailingslashit( trailingslashit($parentlink) . '%postname%' );
       
   319 
       
   320 		if ( ! $leavename )
       
   321 			$link = str_replace( '%postname%', $name, $link );
   325 	}
   322 	}
   326 
   323 
   327 	if ( ! $link )
   324 	if ( ! $link )
   328 		$link = home_url( "/?attachment_id=$id" );
   325 		$link = home_url( '/?attachment_id=' . $post->ID );
   329 
   326 
   330 	return apply_filters('attachment_link', $link, $id);
   327 	return apply_filters( 'attachment_link', $link, $post->ID );
   331 }
   328 }
   332 
   329 
   333 /**
   330 /**
   334  * Retrieve the permalink for the year archives.
   331  * Retrieve the permalink for the year archives.
   335  *
   332  *
   485 			$url .= "/$feed";
   482 			$url .= "/$feed";
   486 		$url = user_trailingslashit($url, 'single_feed');
   483 		$url = user_trailingslashit($url, 'single_feed');
   487 	} else {
   484 	} else {
   488 		$type = get_post_field('post_type', $post_id);
   485 		$type = get_post_field('post_type', $post_id);
   489 		if ( 'page' == $type )
   486 		if ( 'page' == $type )
   490 			$url = home_url("?feed=$feed&amp;page_id=$post_id");
   487 			$url = add_query_arg( array( 'feed' => $feed, 'page_id' => $post_id ), home_url( '/' ) );
   491 		else
   488 		else
   492 			$url = home_url("?feed=$feed&amp;p=$post_id");
   489 			$url = add_query_arg( array( 'feed' => $feed, 'p' => $post_id ), home_url( '/' ) );
   493 	}
   490 	}
   494 
   491 
   495 	return apply_filters('post_comments_feed_link', $url);
   492 	return apply_filters('post_comments_feed_link', $url);
   496 }
   493 }
   497 
   494 
   510  * @param int $post_id Optional post ID. Default to current post.
   507  * @param int $post_id Optional post ID. Default to current post.
   511  * @param string $feed Optional. Feed format.
   508  * @param string $feed Optional. Feed format.
   512  * @return string Link to the comment feed for the current post.
   509  * @return string Link to the comment feed for the current post.
   513 */
   510 */
   514 function post_comments_feed_link( $link_text = '', $post_id = '', $feed = '' ) {
   511 function post_comments_feed_link( $link_text = '', $post_id = '', $feed = '' ) {
   515 	$url = get_post_comments_feed_link($post_id, $feed);
   512 	$url = esc_url( get_post_comments_feed_link( $post_id, $feed ) );
   516 	if ( empty($link_text) )
   513 	if ( empty($link_text) )
   517 		$link_text = __('Comments Feed');
   514 		$link_text = __('Comments Feed');
   518 
   515 
   519 	echo apply_filters( 'post_comments_feed_link_html', "<a href='$url'>$link_text</a>", $post_id, $feed );
   516 	echo apply_filters( 'post_comments_feed_link_html', "<a href='$url'>$link_text</a>", $post_id, $feed );
   520 }
   517 }
   622 	}
   619 	}
   623 
   620 
   624 	if ( 'category' == $taxonomy )
   621 	if ( 'category' == $taxonomy )
   625 		$link = apply_filters( 'category_feed_link', $link, $feed );
   622 		$link = apply_filters( 'category_feed_link', $link, $feed );
   626 	elseif ( 'post_tag' == $taxonomy )
   623 	elseif ( 'post_tag' == $taxonomy )
   627 		$link = apply_filters( 'category_feed_link', $link, $feed );
   624 		$link = apply_filters( 'tag_feed_link', $link, $feed );
   628 	else
   625 	else
   629 		$link = apply_filters( 'taxonomy_feed_link', $link, $feed, $taxonomy );
   626 		$link = apply_filters( 'taxonomy_feed_link', $link, $feed, $taxonomy );
   630 
   627 
   631 	return $link;
   628 	return $link;
   632 }
   629 }
   894  * @param int $id Optional. Post ID.
   891  * @param int $id Optional. Post ID.
   895  * @param string $context Optional, defaults to display. How to write the '&', defaults to '&amp;'.
   892  * @param string $context Optional, defaults to display. How to write the '&', defaults to '&amp;'.
   896  * @return string
   893  * @return string
   897  */
   894  */
   898 function get_edit_post_link( $id = 0, $context = 'display' ) {
   895 function get_edit_post_link( $id = 0, $context = 'display' ) {
   899 	if ( !$post = &get_post( $id ) )
   896 	if ( ! $post = get_post( $id ) )
   900 		return;
   897 		return;
   901 
   898 
   902 	if ( 'display' == $context )
   899 	if ( 'display' == $context )
   903 		$action = '&amp;action=edit';
   900 		$action = '&amp;action=edit';
   904 	else
   901 	else
   923  * @param string $before Optional. Display before edit link.
   920  * @param string $before Optional. Display before edit link.
   924  * @param string $after Optional. Display after edit link.
   921  * @param string $after Optional. Display after edit link.
   925  * @param int $id Optional. Post ID.
   922  * @param int $id Optional. Post ID.
   926  */
   923  */
   927 function edit_post_link( $link = null, $before = '', $after = '', $id = 0 ) {
   924 function edit_post_link( $link = null, $before = '', $after = '', $id = 0 ) {
   928 	if ( !$post = &get_post( $id ) )
   925 	if ( !$post = get_post( $id ) )
   929 		return;
   926 		return;
   930 
   927 
   931 	if ( !$url = get_edit_post_link( $post->ID ) )
   928 	if ( !$url = get_edit_post_link( $post->ID ) )
   932 		return;
   929 		return;
   933 
   930 
   953  */
   950  */
   954 function get_delete_post_link( $id = 0, $deprecated = '', $force_delete = false ) {
   951 function get_delete_post_link( $id = 0, $deprecated = '', $force_delete = false ) {
   955 	if ( ! empty( $deprecated ) )
   952 	if ( ! empty( $deprecated ) )
   956 		_deprecated_argument( __FUNCTION__, '3.0' );
   953 		_deprecated_argument( __FUNCTION__, '3.0' );
   957 
   954 
   958 	if ( !$post = &get_post( $id ) )
   955 	if ( !$post = get_post( $id ) )
   959 		return;
   956 		return;
   960 
   957 
   961 	$post_type_object = get_post_type_object( $post->post_type );
   958 	$post_type_object = get_post_type_object( $post->post_type );
   962 	if ( !$post_type_object )
   959 	if ( !$post_type_object )
   963 		return;
   960 		return;
   967 
   964 
   968 	$action = ( $force_delete || !EMPTY_TRASH_DAYS ) ? 'delete' : 'trash';
   965 	$action = ( $force_delete || !EMPTY_TRASH_DAYS ) ? 'delete' : 'trash';
   969 
   966 
   970 	$delete_link = add_query_arg( 'action', $action, admin_url( sprintf( $post_type_object->_edit_link, $post->ID ) ) );
   967 	$delete_link = add_query_arg( 'action', $action, admin_url( sprintf( $post_type_object->_edit_link, $post->ID ) ) );
   971 
   968 
   972 	return apply_filters( 'get_delete_post_link', wp_nonce_url( $delete_link, "$action-{$post->post_type}_{$post->ID}" ), $post->ID, $force_delete );
   969 	return apply_filters( 'get_delete_post_link', wp_nonce_url( $delete_link, "$action-post_{$post->ID}" ), $post->ID, $force_delete );
   973 }
   970 }
   974 
   971 
   975 /**
   972 /**
   976  * Retrieve edit comment link.
   973  * Retrieve edit comment link.
   977  *
   974  *
   979  *
   976  *
   980  * @param int $comment_id Optional. Comment ID.
   977  * @param int $comment_id Optional. Comment ID.
   981  * @return string
   978  * @return string
   982  */
   979  */
   983 function get_edit_comment_link( $comment_id = 0 ) {
   980 function get_edit_comment_link( $comment_id = 0 ) {
   984 	$comment = &get_comment( $comment_id );
   981 	$comment = get_comment( $comment_id );
   985 
   982 
   986 	if ( !current_user_can( 'edit_comment', $comment->comment_ID ) )
   983 	if ( !current_user_can( 'edit_comment', $comment->comment_ID ) )
   987 		return;
   984 		return;
   988 
   985 
   989 	$location = admin_url('comment.php?action=editcomment&amp;c=') . $comment->comment_ID;
   986 	$location = admin_url('comment.php?action=editcomment&amp;c=') . $comment->comment_ID;
  1052 
  1049 
  1053 	$link = '<a href="' . get_edit_bookmark_link( $bookmark ) . '" title="' . esc_attr__( 'Edit Link' ) . '">' . $link . '</a>';
  1050 	$link = '<a href="' . get_edit_bookmark_link( $bookmark ) . '" title="' . esc_attr__( 'Edit Link' ) . '">' . $link . '</a>';
  1054 	echo $before . apply_filters( 'edit_bookmark_link', $link, $bookmark->link_id ) . $after;
  1051 	echo $before . apply_filters( 'edit_bookmark_link', $link, $bookmark->link_id ) . $after;
  1055 }
  1052 }
  1056 
  1053 
       
  1054 /**
       
  1055  * Retrieve edit user link
       
  1056  *
       
  1057  * @since 3.5.0
       
  1058  *
       
  1059  * @param int $user_id Optional. User ID. Defaults to the current user.
       
  1060  * @return string URL to edit user page or empty string.
       
  1061  */
       
  1062 function get_edit_user_link( $user_id = null ) {
       
  1063 	if ( ! $user_id )
       
  1064 		$user_id = get_current_user_id();
       
  1065 
       
  1066 	if ( empty( $user_id ) || ! current_user_can( 'edit_user', $user_id ) )
       
  1067 		return '';
       
  1068 
       
  1069 	$user = get_userdata( $user_id );
       
  1070 
       
  1071 	if ( ! $user )
       
  1072 		return '';
       
  1073 
       
  1074 	if ( get_current_user_id() == $user->ID )
       
  1075 		$link = get_edit_profile_url( $user->ID );
       
  1076 	else
       
  1077 		$link = add_query_arg( 'user_id', $user->ID, self_admin_url( 'user-edit.php' ) );
       
  1078 
       
  1079 	return apply_filters( 'get_edit_user_link', $link, $user->ID );
       
  1080 }
       
  1081 
  1057 // Navigation links
  1082 // Navigation links
  1058 
  1083 
  1059 /**
  1084 /**
  1060  * Retrieve previous post that is adjacent to current post.
  1085  * Retrieve previous post that is adjacent to current post.
  1061  *
  1086  *
  1093  * @param array|string $excluded_categories Optional. Array or comma-separated list of excluded category IDs.
  1118  * @param array|string $excluded_categories Optional. Array or comma-separated list of excluded category IDs.
  1094  * @param bool $previous Optional. Whether to retrieve previous post.
  1119  * @param bool $previous Optional. Whether to retrieve previous post.
  1095  * @return mixed Post object if successful. Null if global $post is not set. Empty string if no corresponding post exists.
  1120  * @return mixed Post object if successful. Null if global $post is not set. Empty string if no corresponding post exists.
  1096  */
  1121  */
  1097 function get_adjacent_post( $in_same_cat = false, $excluded_categories = '', $previous = true ) {
  1122 function get_adjacent_post( $in_same_cat = false, $excluded_categories = '', $previous = true ) {
  1098 	global $post, $wpdb;
  1123 	global $wpdb;
  1099 
  1124 
  1100 	if ( empty( $post ) )
  1125 	if ( ! $post = get_post() )
  1101 		return null;
  1126 		return null;
  1102 
  1127 
  1103 	$current_post_date = $post->post_date;
  1128 	$current_post_date = $post->post_date;
  1104 
  1129 
  1105 	$join = '';
  1130 	$join = '';
  1106 	$posts_in_ex_cats_sql = '';
  1131 	$posts_in_ex_cats_sql = '';
  1107 	if ( $in_same_cat || ! empty( $excluded_categories ) ) {
  1132 	if ( $in_same_cat || ! empty( $excluded_categories ) ) {
  1108 		$join = " INNER JOIN $wpdb->term_relationships AS tr ON p.ID = tr.object_id INNER JOIN $wpdb->term_taxonomy tt ON tr.term_taxonomy_id = tt.term_taxonomy_id";
  1133 		$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";
  1109 
  1134 
  1110 		if ( $in_same_cat ) {
  1135 		if ( $in_same_cat ) {
       
  1136 			if ( ! is_object_in_taxonomy( $post->post_type, 'category' ) )
       
  1137 				return '';
  1111 			$cat_array = wp_get_object_terms($post->ID, 'category', array('fields' => 'ids'));
  1138 			$cat_array = wp_get_object_terms($post->ID, 'category', array('fields' => 'ids'));
       
  1139 			if ( ! $cat_array || is_wp_error( $cat_array ) )
       
  1140 				return '';
  1112 			$join .= " AND tt.taxonomy = 'category' AND tt.term_id IN (" . implode(',', $cat_array) . ")";
  1141 			$join .= " AND tt.taxonomy = 'category' AND tt.term_id IN (" . implode(',', $cat_array) . ")";
  1113 		}
  1142 		}
  1114 
  1143 
  1115 		$posts_in_ex_cats_sql = "AND tt.taxonomy = 'category'";
  1144 		$posts_in_ex_cats_sql = "AND tt.taxonomy = 'category'";
  1116 		if ( ! empty( $excluded_categories ) ) {
  1145 		if ( ! empty( $excluded_categories ) ) {
  1143 
  1172 
  1144 	$join  = apply_filters( "get_{$adjacent}_post_join", $join, $in_same_cat, $excluded_categories );
  1173 	$join  = apply_filters( "get_{$adjacent}_post_join", $join, $in_same_cat, $excluded_categories );
  1145 	$where = apply_filters( "get_{$adjacent}_post_where", $wpdb->prepare("WHERE p.post_date $op %s AND p.post_type = %s AND p.post_status = 'publish' $posts_in_ex_cats_sql", $current_post_date, $post->post_type), $in_same_cat, $excluded_categories );
  1174 	$where = apply_filters( "get_{$adjacent}_post_where", $wpdb->prepare("WHERE p.post_date $op %s AND p.post_type = %s AND p.post_status = 'publish' $posts_in_ex_cats_sql", $current_post_date, $post->post_type), $in_same_cat, $excluded_categories );
  1146 	$sort  = apply_filters( "get_{$adjacent}_post_sort", "ORDER BY p.post_date $order LIMIT 1" );
  1175 	$sort  = apply_filters( "get_{$adjacent}_post_sort", "ORDER BY p.post_date $order LIMIT 1" );
  1147 
  1176 
  1148 	$query = "SELECT p.* FROM $wpdb->posts AS p $join $where $sort";
  1177 	$query = "SELECT p.id FROM $wpdb->posts AS p $join $where $sort";
  1149 	$query_key = 'adjacent_post_' . md5($query);
  1178 	$query_key = 'adjacent_post_' . md5($query);
  1150 	$result = wp_cache_get($query_key, 'counts');
  1179 	$result = wp_cache_get($query_key, 'counts');
  1151 	if ( false !== $result )
  1180 	if ( false !== $result ) {
       
  1181 		if ( $result )
       
  1182 			$result = get_post( $result );
  1152 		return $result;
  1183 		return $result;
  1153 
  1184 	}
  1154 	$result = $wpdb->get_row("SELECT p.* FROM $wpdb->posts AS p $join $where $sort");
  1185 
       
  1186 	$result = $wpdb->get_var( $query );
  1155 	if ( null === $result )
  1187 	if ( null === $result )
  1156 		$result = '';
  1188 		$result = '';
  1157 
  1189 
  1158 	wp_cache_set($query_key, $result, 'counts');
  1190 	wp_cache_set($query_key, $result, 'counts');
       
  1191 
       
  1192 	if ( $result )
       
  1193 		$result = get_post( $result );
       
  1194 
  1159 	return $result;
  1195 	return $result;
  1160 }
  1196 }
  1161 
  1197 
  1162 /**
  1198 /**
  1163  * Get adjacent post relational link.
  1199  * Get adjacent post relational link.
  1171  * @param array|string $excluded_categories Optional. Array or comma-separated list of excluded category IDs.
  1207  * @param array|string $excluded_categories Optional. Array or comma-separated list of excluded category IDs.
  1172  * @param bool $previous Optional, default is true. Whether to display link to previous or next post.
  1208  * @param bool $previous Optional, default is true. Whether to display link to previous or next post.
  1173  * @return string
  1209  * @return string
  1174  */
  1210  */
  1175 function get_adjacent_post_rel_link($title = '%title', $in_same_cat = false, $excluded_categories = '', $previous = true) {
  1211 function get_adjacent_post_rel_link($title = '%title', $in_same_cat = false, $excluded_categories = '', $previous = true) {
  1176 	if ( $previous && is_attachment() && is_object( $GLOBALS['post'] ) )
  1212 	if ( $previous && is_attachment() && $post = get_post() )
  1177 		$post = & get_post($GLOBALS['post']->post_parent);
  1213 		$post = get_post( $post->post_parent );
  1178 	else
  1214 	else
  1179 		$post = get_adjacent_post($in_same_cat,$excluded_categories,$previous);
  1215 		$post = get_adjacent_post( $in_same_cat, $excluded_categories, $previous );
  1180 
  1216 
  1181 	if ( empty($post) )
  1217 	if ( empty($post) )
  1182 		return;
  1218 		return;
  1183 
  1219 
  1184 	if ( empty($post->post_title) )
  1220 	if ( empty($post->post_title) )
  1185 		$post->post_title = $previous ? __('Previous Post') : __('Next Post');
  1221 		$post_title = $previous ? __('Previous Post') : __('Next Post');
       
  1222 	else
       
  1223 		$post_title = $post->post_title;
  1186 
  1224 
  1187 	$date = mysql2date(get_option('date_format'), $post->post_date);
  1225 	$date = mysql2date(get_option('date_format'), $post->post_date);
  1188 
  1226 
  1189 	$title = str_replace('%title', $post->post_title, $title);
  1227 	$title = str_replace('%title', $post_title, $title);
  1190 	$title = str_replace('%date', $date, $title);
  1228 	$title = str_replace('%date', $date, $title);
  1191 	$title = apply_filters('the_title', $title, $post->ID);
  1229 	$title = apply_filters('the_title', $title, $post->ID);
  1192 
  1230 
  1193 	$link = $previous ? "<link rel='prev' title='" : "<link rel='next' title='";
  1231 	$link = $previous ? "<link rel='prev' title='" : "<link rel='next' title='";
  1194 	$link .= esc_attr( $title );
  1232 	$link .= esc_attr( $title );
  1263  * @param array|string $excluded_categories Optional. Array or comma-separated list of excluded category IDs.
  1301  * @param array|string $excluded_categories Optional. Array or comma-separated list of excluded category IDs.
  1264  * @param bool $start Optional. Whether to retrieve first or last post.
  1302  * @param bool $start Optional. Whether to retrieve first or last post.
  1265  * @return object
  1303  * @return object
  1266  */
  1304  */
  1267 function get_boundary_post( $in_same_cat = false, $excluded_categories = '', $start = true ) {
  1305 function get_boundary_post( $in_same_cat = false, $excluded_categories = '', $start = true ) {
  1268 	global $post;
  1306 	$post = get_post();
  1269 
  1307 	if ( ! $post || ! is_single() || is_attachment() )
  1270 	if ( empty($post) || ! is_single() || is_attachment() )
       
  1271 		return null;
  1308 		return null;
  1272 
  1309 
  1273 	$cat_array = array();
  1310 	$cat_array = array();
  1274 	if( ! is_array( $excluded_categories ) )
  1311 	if( ! is_array( $excluded_categories ) )
  1275 		$excluded_categories = explode( ',', $excluded_categories );
  1312 		$excluded_categories = explode( ',', $excluded_categories );
  1335  * @param string $link Link permalink format.
  1372  * @param string $link Link permalink format.
  1336  * @param bool $in_same_cat Optional. Whether link should be in a same category.
  1373  * @param bool $in_same_cat Optional. Whether link should be in a same category.
  1337  * @param array|string $excluded_categories Optional. Array or comma-separated list of excluded category IDs.
  1374  * @param array|string $excluded_categories Optional. Array or comma-separated list of excluded category IDs.
  1338  * @param bool $previous Optional, default is true. Whether to display link to previous or next post.
  1375  * @param bool $previous Optional, default is true. Whether to display link to previous or next post.
  1339  */
  1376  */
  1340 function adjacent_post_link($format, $link, $in_same_cat = false, $excluded_categories = '', $previous = true) {
  1377 function adjacent_post_link( $format, $link, $in_same_cat = false, $excluded_categories = '', $previous = true ) {
  1341 	if ( $previous && is_attachment() )
  1378 	if ( $previous && is_attachment() )
  1342 		$post = & get_post($GLOBALS['post']->post_parent);
  1379 		$post = get_post( get_post()->post_parent );
  1343 	else
  1380 	else
  1344 		$post = get_adjacent_post($in_same_cat, $excluded_categories, $previous);
  1381 		$post = get_adjacent_post( $in_same_cat, $excluded_categories, $previous );
  1345 
  1382 
  1346 	if ( !$post )
  1383 	if ( ! $post ) {
  1347 		return;
  1384 		$output = '';
  1348 
  1385 	} else {
  1349 	$title = $post->post_title;
  1386 		$title = $post->post_title;
  1350 
  1387 
  1351 	if ( empty($post->post_title) )
  1388 		if ( empty( $post->post_title ) )
  1352 		$title = $previous ? __('Previous Post') : __('Next Post');
  1389 			$title = $previous ? __( 'Previous Post' ) : __( 'Next Post' );
  1353 
  1390 
  1354 	$title = apply_filters('the_title', $title, $post->ID);
  1391 		$title = apply_filters( 'the_title', $title, $post->ID );
  1355 	$date = mysql2date(get_option('date_format'), $post->post_date);
  1392 		$date = mysql2date( get_option( 'date_format' ), $post->post_date );
  1356 	$rel = $previous ? 'prev' : 'next';
  1393 		$rel = $previous ? 'prev' : 'next';
  1357 
  1394 
  1358 	$string = '<a href="'.get_permalink($post).'" rel="'.$rel.'">';
  1395 		$string = '<a href="' . get_permalink( $post ) . '" rel="'.$rel.'">';
  1359 	$link = str_replace('%title', $title, $link);
  1396 		$inlink = str_replace( '%title', $title, $link );
  1360 	$link = str_replace('%date', $date, $link);
  1397 		$inlink = str_replace( '%date', $date, $inlink );
  1361 	$link = $string . $link . '</a>';
  1398 		$inlink = $string . $inlink . '</a>';
  1362 
  1399 
  1363 	$format = str_replace('%link', $link, $format);
  1400 		$output = str_replace( '%link', $inlink, $format );
       
  1401 	}
  1364 
  1402 
  1365 	$adjacent = $previous ? 'previous' : 'next';
  1403 	$adjacent = $previous ? 'previous' : 'next';
  1366 	echo apply_filters( "{$adjacent}_post_link", $format, $link );
  1404 
       
  1405 	echo apply_filters( "{$adjacent}_post_link", $output, $format, $link, $post );
  1367 }
  1406 }
  1368 
  1407 
  1369 /**
  1408 /**
  1370  * Retrieve links for page numbers.
  1409  * Retrieve links for page numbers.
  1371  *
  1410  *
  1383 
  1422 
  1384 	$request = remove_query_arg( 'paged' );
  1423 	$request = remove_query_arg( 'paged' );
  1385 
  1424 
  1386 	$home_root = parse_url(home_url());
  1425 	$home_root = parse_url(home_url());
  1387 	$home_root = ( isset($home_root['path']) ) ? $home_root['path'] : '';
  1426 	$home_root = ( isset($home_root['path']) ) ? $home_root['path'] : '';
  1388 	$home_root = preg_quote( trailingslashit( $home_root ), '|' );
  1427 	$home_root = preg_quote( $home_root, '|' );
  1389 
  1428 
  1390 	$request = preg_replace('|^'. $home_root . '|', '', $request);
  1429 	$request = preg_replace('|^'. $home_root . '|i', '', $request);
  1391 	$request = preg_replace('|^/+|', '', $request);
  1430 	$request = preg_replace('|^/+|', '', $request);
  1392 
  1431 
  1393 	if ( !$wp_rewrite->using_permalinks() || is_admin() ) {
  1432 	if ( !$wp_rewrite->using_permalinks() || is_admin() ) {
  1394 		$base = trailingslashit( get_bloginfo( 'url' ) );
  1433 		$base = trailingslashit( get_bloginfo( 'url' ) );
  1395 
  1434 
  1408 		} else {
  1447 		} else {
  1409 			$query_string = '';
  1448 			$query_string = '';
  1410 		}
  1449 		}
  1411 
  1450 
  1412 		$request = preg_replace( "|$wp_rewrite->pagination_base/\d+/?$|", '', $request);
  1451 		$request = preg_replace( "|$wp_rewrite->pagination_base/\d+/?$|", '', $request);
  1413 		$request = preg_replace( '|^index\.php|', '', $request);
  1452 		$request = preg_replace( '|^index\.php|i', '', $request);
  1414 		$request = ltrim($request, '/');
  1453 		$request = ltrim($request, '/');
  1415 
  1454 
  1416 		$base = trailingslashit( get_bloginfo( 'url' ) );
  1455 		$base = trailingslashit( get_bloginfo( 'url' ) );
  1417 
  1456 
  1418 		if ( $wp_rewrite->using_index_permalinks() && ( $pagenum > 1 || '' != $request ) )
  1457 		if ( $wp_rewrite->using_index_permalinks() && ( $pagenum > 1 || '' != $request ) )
  1644  *
  1683  *
  1645  * @param int $pagenum Optional. Page number.
  1684  * @param int $pagenum Optional. Page number.
  1646  * @return string
  1685  * @return string
  1647  */
  1686  */
  1648 function get_comments_pagenum_link( $pagenum = 1, $max_page = 0 ) {
  1687 function get_comments_pagenum_link( $pagenum = 1, $max_page = 0 ) {
  1649 	global $post, $wp_rewrite;
  1688 	global $wp_rewrite;
  1650 
  1689 
  1651 	$pagenum = (int) $pagenum;
  1690 	$pagenum = (int) $pagenum;
  1652 
  1691 
  1653 	$result = get_permalink( $post->ID );
  1692 	$result = get_permalink();
  1654 
  1693 
  1655 	if ( 'newest' == get_option('default_comments_page') ) {
  1694 	if ( 'newest' == get_option('default_comments_page') ) {
  1656 		if ( $pagenum != $max_page ) {
  1695 		if ( $pagenum != $max_page ) {
  1657 			if ( $wp_rewrite->using_permalinks() )
  1696 			if ( $wp_rewrite->using_permalinks() )
  1658 				$result = user_trailingslashit( trailingslashit($result) . 'comment-page-' . $pagenum, 'commentpaged');
  1697 				$result = user_trailingslashit( trailingslashit($result) . 'comment-page-' . $pagenum, 'commentpaged');
  1840  * @param  string $path   (optional) Path relative to the home url.
  1879  * @param  string $path   (optional) Path relative to the home url.
  1841  * @param  string $scheme (optional) Scheme to give the home url context. Currently 'http', 'https', or 'relative'.
  1880  * @param  string $scheme (optional) Scheme to give the home url context. Currently 'http', 'https', or 'relative'.
  1842  * @return string Home url link with optional path appended.
  1881  * @return string Home url link with optional path appended.
  1843 */
  1882 */
  1844 function home_url( $path = '', $scheme = null ) {
  1883 function home_url( $path = '', $scheme = null ) {
  1845 	return get_home_url(null, $path, $scheme);
  1884 	return get_home_url( null, $path, $scheme );
  1846 }
  1885 }
  1847 
  1886 
  1848 /**
  1887 /**
  1849  * Retrieve the home url for a given site.
  1888  * Retrieve the home url for a given site.
  1850  *
  1889  *
  1861  * @return string Home url link with optional path appended.
  1900  * @return string Home url link with optional path appended.
  1862 */
  1901 */
  1863 function get_home_url( $blog_id = null, $path = '', $scheme = null ) {
  1902 function get_home_url( $blog_id = null, $path = '', $scheme = null ) {
  1864 	$orig_scheme = $scheme;
  1903 	$orig_scheme = $scheme;
  1865 
  1904 
  1866 	if ( !in_array( $scheme, array( 'http', 'https', 'relative' ) ) )
  1905 	if ( empty( $blog_id ) || !is_multisite() ) {
  1867 		$scheme = is_ssl() && !is_admin() ? 'https' : 'http';
       
  1868 
       
  1869 	if ( empty( $blog_id ) || !is_multisite() )
       
  1870 		$url = get_option( 'home' );
  1906 		$url = get_option( 'home' );
  1871 	else
  1907 	} else {
  1872 		$url = get_blog_option( $blog_id, 'home' );
  1908 		switch_to_blog( $blog_id );
  1873 
  1909 		$url = get_option( 'home' );
  1874 	if ( 'relative' == $scheme )
  1910 		restore_current_blog();
  1875 		$url = preg_replace( '#^.+://[^/]*#', '', $url );
  1911 	}
  1876 	elseif ( 'http' != $scheme )
  1912 
  1877 		$url = str_replace( 'http://', "$scheme://", $url );
  1913 	if ( ! in_array( $scheme, array( 'http', 'https', 'relative' ) ) ) {
  1878 
  1914 		if ( is_ssl() && ! is_admin() )
  1879 	if ( !empty( $path ) && is_string( $path ) && strpos( $path, '..' ) === false )
  1915 			$scheme = 'https';
       
  1916 		else
       
  1917 			$scheme = parse_url( $url, PHP_URL_SCHEME );
       
  1918 	}
       
  1919 
       
  1920 	$url = set_url_scheme( $url, $scheme );
       
  1921 
       
  1922 	if ( ! empty( $path ) && is_string( $path ) && strpos( $path, '..' ) === false )
  1880 		$url .= '/' . ltrim( $path, '/' );
  1923 		$url .= '/' . ltrim( $path, '/' );
  1881 
  1924 
  1882 	return apply_filters( 'home_url', $url, $path, $orig_scheme, $blog_id );
  1925 	return apply_filters( 'home_url', $url, $path, $orig_scheme, $blog_id );
  1883 }
  1926 }
  1884 
  1927 
  1893  * @since 2.6.0
  1936  * @since 2.6.0
  1894  *
  1937  *
  1895  * @uses get_site_url()
  1938  * @uses get_site_url()
  1896  *
  1939  *
  1897  * @param string $path Optional. Path relative to the site url.
  1940  * @param string $path Optional. Path relative to the site url.
  1898  * @param string $scheme Optional. Scheme to give the site url context. Currently 'http', 'https', 'login', 'login_post', 'admin', or 'relative'.
  1941  * @param string $scheme Optional. Scheme to give the site url context. See set_url_scheme().
  1899  * @return string Site url link with optional path appended.
  1942  * @return string Site url link with optional path appended.
  1900 */
  1943 */
  1901 function site_url( $path = '', $scheme = null ) {
  1944 function site_url( $path = '', $scheme = null ) {
  1902 	return get_site_url(null, $path, $scheme);
  1945 	return get_site_url( null, $path, $scheme );
  1903 }
  1946 }
  1904 
  1947 
  1905 /**
  1948 /**
  1906  * Retrieve the site url for a given site.
  1949  * Retrieve the site url for a given site.
  1907  *
  1950  *
  1916  * @param string $path Optional. Path relative to the site url.
  1959  * @param string $path Optional. Path relative to the site url.
  1917  * @param string $scheme Optional. Scheme to give the site url context. Currently 'http', 'https', 'login', 'login_post', 'admin', or 'relative'.
  1960  * @param string $scheme Optional. Scheme to give the site url context. Currently 'http', 'https', 'login', 'login_post', 'admin', or 'relative'.
  1918  * @return string Site url link with optional path appended.
  1961  * @return string Site url link with optional path appended.
  1919 */
  1962 */
  1920 function get_site_url( $blog_id = null, $path = '', $scheme = null ) {
  1963 function get_site_url( $blog_id = null, $path = '', $scheme = null ) {
  1921 	// should the list of allowed schemes be maintained elsewhere?
  1964 	if ( empty( $blog_id ) || !is_multisite() ) {
  1922 	$orig_scheme = $scheme;
       
  1923 	if ( !in_array( $scheme, array( 'http', 'https', 'relative' ) ) ) {
       
  1924 		if ( ( 'login_post' == $scheme || 'rpc' == $scheme ) && ( force_ssl_login() || force_ssl_admin() ) )
       
  1925 			$scheme = 'https';
       
  1926 		elseif ( ( 'login' == $scheme ) && force_ssl_admin() )
       
  1927 			$scheme = 'https';
       
  1928 		elseif ( ( 'admin' == $scheme ) && force_ssl_admin() )
       
  1929 			$scheme = 'https';
       
  1930 		else
       
  1931 			$scheme = ( is_ssl() ? 'https' : 'http' );
       
  1932 	}
       
  1933 
       
  1934 	if ( empty( $blog_id ) || !is_multisite() )
       
  1935 		$url = get_option( 'siteurl' );
  1965 		$url = get_option( 'siteurl' );
  1936 	else
  1966 	} else {
  1937 		$url = get_blog_option( $blog_id, 'siteurl' );
  1967 		switch_to_blog( $blog_id );
  1938 
  1968 		$url = get_option( 'siteurl' );
  1939 	if ( 'relative' == $scheme )
  1969 		restore_current_blog();
  1940 		$url = preg_replace( '#^.+://[^/]*#', '', $url );
  1970 	}
  1941 	elseif ( 'http' != $scheme )
  1971 
  1942 		$url = str_replace( 'http://', "{$scheme}://", $url );
  1972 	$url = set_url_scheme( $url, $scheme );
  1943 
  1973 
  1944 	if ( !empty( $path ) && is_string( $path ) && strpos( $path, '..' ) === false )
  1974 	if ( ! empty( $path ) && is_string( $path ) && strpos( $path, '..' ) === false )
  1945 		$url .= '/' . ltrim( $path, '/' );
  1975 		$url .= '/' . ltrim( $path, '/' );
  1946 
  1976 
  1947 	return apply_filters( 'site_url', $url, $path, $orig_scheme, $blog_id );
  1977 	return apply_filters( 'site_url', $url, $path, $scheme, $blog_id );
  1948 }
  1978 }
  1949 
  1979 
  1950 /**
  1980 /**
  1951  * Retrieve the url to the admin area for the current site.
  1981  * Retrieve the url to the admin area for the current site.
  1952  *
  1982  *
  1956  * @param string $path Optional path relative to the admin url.
  1986  * @param string $path Optional path relative to the admin url.
  1957  * @param string $scheme The scheme to use. Default is 'admin', which obeys force_ssl_admin() and is_ssl(). 'http' or 'https' can be passed to force those schemes.
  1987  * @param string $scheme The scheme to use. Default is 'admin', which obeys force_ssl_admin() and is_ssl(). 'http' or 'https' can be passed to force those schemes.
  1958  * @return string Admin url link with optional path appended.
  1988  * @return string Admin url link with optional path appended.
  1959 */
  1989 */
  1960 function admin_url( $path = '', $scheme = 'admin' ) {
  1990 function admin_url( $path = '', $scheme = 'admin' ) {
  1961 	return get_admin_url(null, $path, $scheme);
  1991 	return get_admin_url( null, $path, $scheme );
  1962 }
  1992 }
  1963 
  1993 
  1964 /**
  1994 /**
  1965  * Retrieve the url to the admin area for a given site.
  1995  * Retrieve the url to the admin area for a given site.
  1966  *
  1996  *
  1973  * @return string Admin url link with optional path appended.
  2003  * @return string Admin url link with optional path appended.
  1974 */
  2004 */
  1975 function get_admin_url( $blog_id = null, $path = '', $scheme = 'admin' ) {
  2005 function get_admin_url( $blog_id = null, $path = '', $scheme = 'admin' ) {
  1976 	$url = get_site_url($blog_id, 'wp-admin/', $scheme);
  2006 	$url = get_site_url($blog_id, 'wp-admin/', $scheme);
  1977 
  2007 
  1978 	if ( !empty($path) && is_string($path) && strpos($path, '..') === false )
  2008 	if ( !empty( $path ) && is_string( $path ) && strpos( $path, '..' ) === false )
  1979 		$url .= ltrim($path, '/');
  2009 		$url .= ltrim( $path, '/' );
  1980 
  2010 
  1981 	return apply_filters('admin_url', $url, $path, $blog_id);
  2011 	return apply_filters( 'admin_url', $url, $path, $blog_id );
  1982 }
  2012 }
  1983 
  2013 
  1984 /**
  2014 /**
  1985  * Retrieve the url to the includes directory.
  2015  * Retrieve the url to the includes directory.
  1986  *
  2016  *
  2007  *
  2037  *
  2008  * @param string $path Optional. Path relative to the content url.
  2038  * @param string $path Optional. Path relative to the content url.
  2009  * @return string Content url link with optional path appended.
  2039  * @return string Content url link with optional path appended.
  2010 */
  2040 */
  2011 function content_url($path = '') {
  2041 function content_url($path = '') {
  2012 	$url = WP_CONTENT_URL;
  2042 	$url = set_url_scheme( WP_CONTENT_URL );
  2013 	if ( 0 === strpos($url, 'http') && is_ssl() )
       
  2014 		$url = str_replace( 'http://', 'https://', $url );
       
  2015 
  2043 
  2016 	if ( !empty($path) && is_string($path) && strpos($path, '..') === false )
  2044 	if ( !empty($path) && is_string($path) && strpos($path, '..') === false )
  2017 		$url .= '/' . ltrim($path, '/');
  2045 		$url .= '/' . ltrim($path, '/');
  2018 
  2046 
  2019 	return apply_filters('content_url', $url, $path);
  2047 	return apply_filters('content_url', $url, $path);
  2041 	if ( !empty($plugin) && 0 === strpos($plugin, $mu_plugin_dir) )
  2069 	if ( !empty($plugin) && 0 === strpos($plugin, $mu_plugin_dir) )
  2042 		$url = WPMU_PLUGIN_URL;
  2070 		$url = WPMU_PLUGIN_URL;
  2043 	else
  2071 	else
  2044 		$url = WP_PLUGIN_URL;
  2072 		$url = WP_PLUGIN_URL;
  2045 
  2073 
  2046 	if ( 0 === strpos($url, 'http') && is_ssl() )
  2074 
  2047 		$url = str_replace( 'http://', 'https://', $url );
  2075 	$url = set_url_scheme( $url );
  2048 
  2076 
  2049 	if ( !empty($plugin) && is_string($plugin) ) {
  2077 	if ( !empty($plugin) && is_string($plugin) ) {
  2050 		$folder = dirname(plugin_basename($plugin));
  2078 		$folder = dirname(plugin_basename($plugin));
  2051 		if ( '.' != $folder )
  2079 		if ( '.' != $folder )
  2052 			$url .= '/' . ltrim($folder, '/');
  2080 			$url .= '/' . ltrim($folder, '/');
  2067  *
  2095  *
  2068  * @package WordPress
  2096  * @package WordPress
  2069  * @since 3.0.0
  2097  * @since 3.0.0
  2070  *
  2098  *
  2071  * @param string $path Optional. Path relative to the site url.
  2099  * @param string $path Optional. Path relative to the site url.
  2072  * @param string $scheme Optional. Scheme to give the site url context. Currently 'http', 'https', 'login', 'login_post', 'admin', or 'relative'.
  2100  * @param string $scheme Optional. Scheme to give the site url context. See set_url_scheme().
  2073  * @return string Site url link with optional path appended.
  2101  * @return string Site url link with optional path appended.
  2074 */
  2102 */
  2075 function network_site_url( $path = '', $scheme = null ) {
  2103 function network_site_url( $path = '', $scheme = null ) {
  2076 	global $current_site;
  2104 	global $current_site;
  2077 
  2105 
  2078 	if ( !is_multisite() )
  2106 	if ( ! is_multisite() )
  2079 		return site_url($path, $scheme);
  2107 		return site_url($path, $scheme);
  2080 
       
  2081 	$orig_scheme = $scheme;
       
  2082 	if ( !in_array( $scheme, array( 'http', 'https', 'relative' ) ) ) {
       
  2083 		if ( ( 'login_post' == $scheme || 'rpc' == $scheme ) && ( force_ssl_login() || force_ssl_admin() ) )
       
  2084 			$scheme = 'https';
       
  2085 		elseif ( ('login' == $scheme) && ( force_ssl_admin() ) )
       
  2086 			$scheme = 'https';
       
  2087 		elseif ( ('admin' == $scheme) && force_ssl_admin() )
       
  2088 			$scheme = 'https';
       
  2089 		else
       
  2090 			$scheme = ( is_ssl() ? 'https' : 'http' );
       
  2091 	}
       
  2092 
  2108 
  2093 	if ( 'relative' == $scheme )
  2109 	if ( 'relative' == $scheme )
  2094 		$url = $current_site->path;
  2110 		$url = $current_site->path;
  2095 	else
  2111 	else
  2096 		$url = $scheme . '://' . $current_site->domain . $current_site->path;
  2112 		$url = set_url_scheme( 'http://' . $current_site->domain . $current_site->path, $scheme );
  2097 
  2113 
  2098 	if ( !empty($path) && is_string($path) && strpos($path, '..') === false )
  2114 	if ( ! empty( $path ) && is_string( $path ) && strpos( $path, '..' ) === false )
  2099 		$url .= ltrim($path, '/');
  2115 		$url .= ltrim( $path, '/' );
  2100 
  2116 
  2101 	return apply_filters('network_site_url', $url, $path, $orig_scheme);
  2117 	return apply_filters( 'network_site_url', $url, $path, $scheme );
  2102 }
  2118 }
  2103 
  2119 
  2104 /**
  2120 /**
  2105  * Retrieve the home url for the current network.
  2121  * Retrieve the home url for the current network.
  2106  *
  2122  *
  2116  * @return string Home url link with optional path appended.
  2132  * @return string Home url link with optional path appended.
  2117 */
  2133 */
  2118 function network_home_url( $path = '', $scheme = null ) {
  2134 function network_home_url( $path = '', $scheme = null ) {
  2119 	global $current_site;
  2135 	global $current_site;
  2120 
  2136 
  2121 	if ( !is_multisite() )
  2137 	if ( ! is_multisite() )
  2122 		return home_url($path, $scheme);
  2138 		return home_url($path, $scheme);
  2123 
  2139 
  2124 	$orig_scheme = $scheme;
  2140 	$orig_scheme = $scheme;
  2125 
  2141 
  2126 	if ( !in_array( $scheme, array( 'http', 'https', 'relative' ) ) )
  2142 	if ( ! in_array( $scheme, array( 'http', 'https', 'relative' ) ) )
  2127 		$scheme = is_ssl() && !is_admin() ? 'https' : 'http';
  2143 		$scheme = is_ssl() && ! is_admin() ? 'https' : 'http';
  2128 
  2144 
  2129 	if ( 'relative' == $scheme )
  2145 	if ( 'relative' == $scheme )
  2130 		$url = $current_site->path;
  2146 		$url = $current_site->path;
  2131 	else
  2147 	else
  2132 		$url = $scheme . '://' . $current_site->domain . $current_site->path;
  2148 		$url = set_url_scheme( 'http://' . $current_site->domain . $current_site->path, $scheme );
  2133 
  2149 
  2134 	if ( !empty( $path ) && is_string( $path ) && strpos( $path, '..' ) === false )
  2150 	if ( ! empty( $path ) && is_string( $path ) && strpos( $path, '..' ) === false )
  2135 		$url .= ltrim( $path, '/' );
  2151 		$url .= ltrim( $path, '/' );
  2136 
  2152 
  2137 	return apply_filters( 'network_home_url', $url, $path, $orig_scheme);
  2153 	return apply_filters( 'network_home_url', $url, $path, $orig_scheme);
  2138 }
  2154 }
  2139 
  2155 
  2300 	global $wp_the_query;
  2316 	global $wp_the_query;
  2301 	if ( !$id = $wp_the_query->get_queried_object_id() )
  2317 	if ( !$id = $wp_the_query->get_queried_object_id() )
  2302 		return;
  2318 		return;
  2303 
  2319 
  2304 	$link = get_permalink( $id );
  2320 	$link = get_permalink( $id );
       
  2321 
       
  2322 	if ( $page = get_query_var('cpage') )
       
  2323 		$link = get_comments_pagenum_link( $page );
       
  2324 
  2305 	echo "<link rel='canonical' href='$link' />\n";
  2325 	echo "<link rel='canonical' href='$link' />\n";
  2306 }
  2326 }
  2307 
  2327 
  2308 /**
  2328 /**
  2309  * Return a shortlink for a post, page, attachment, or blog.
  2329  * Return a shortlink for a post, page, attachment, or blog.
  2399  * @param string $title Optional The tooltip for the link. Must be sanitized. Defaults to the sanitized post title.
  2419  * @param string $title Optional The tooltip for the link. Must be sanitized. Defaults to the sanitized post title.
  2400  * @param string $before Optional HTML to display before the link.
  2420  * @param string $before Optional HTML to display before the link.
  2401  * @param string $after Optional HTML to display after the link.
  2421  * @param string $after Optional HTML to display after the link.
  2402  */
  2422  */
  2403 function the_shortlink( $text = '', $title = '', $before = '', $after = '' ) {
  2423 function the_shortlink( $text = '', $title = '', $before = '', $after = '' ) {
  2404 	global $post;
  2424 	$post = get_post();
  2405 
  2425 
  2406 	if ( empty( $text ) )
  2426 	if ( empty( $text ) )
  2407 		$text = __('This is the short link.');
  2427 		$text = __('This is the short link.');
  2408 
  2428 
  2409 	if ( empty( $title ) )
  2429 	if ( empty( $title ) )