wp/wp-includes/link-template.php
changeset 9 177826044cd9
parent 7 cf61fcea0001
child 16 a86126ab1dd4
equal deleted inserted replaced
8:c7c34916027a 9:177826044cd9
    42  * @param string $string      URL with or without a trailing slash.
    42  * @param string $string      URL with or without a trailing slash.
    43  * @param string $type_of_url Optional. The type of URL being considered (e.g. single, category, etc)
    43  * @param string $type_of_url Optional. The type of URL being considered (e.g. single, category, etc)
    44  *                            for use in the filter. Default empty string.
    44  *                            for use in the filter. Default empty string.
    45  * @return string The URL with the trailing slash appended or stripped.
    45  * @return string The URL with the trailing slash appended or stripped.
    46  */
    46  */
    47 function user_trailingslashit($string, $type_of_url = '') {
    47 function user_trailingslashit( $string, $type_of_url = '' ) {
    48 	global $wp_rewrite;
    48 	global $wp_rewrite;
    49 	if ( $wp_rewrite->use_trailing_slashes )
    49 	if ( $wp_rewrite->use_trailing_slashes ) {
    50 		$string = trailingslashit($string);
    50 		$string = trailingslashit( $string );
    51 	else
    51 	} else {
    52 		$string = untrailingslashit($string);
    52 		$string = untrailingslashit( $string );
       
    53 	}
    53 
    54 
    54 	/**
    55 	/**
    55 	 * Filters the trailing-slashed string, depending on whether the site is set to use trailing slashes.
    56 	 * Filters the trailing-slashed string, depending on whether the site is set to use trailing slashes.
    56 	 *
    57 	 *
    57 	 * @since 2.2.0
    58 	 * @since 2.2.0
    77 function permalink_anchor( $mode = 'id' ) {
    78 function permalink_anchor( $mode = 'id' ) {
    78 	$post = get_post();
    79 	$post = get_post();
    79 	switch ( strtolower( $mode ) ) {
    80 	switch ( strtolower( $mode ) ) {
    80 		case 'title':
    81 		case 'title':
    81 			$title = sanitize_title( $post->post_title ) . '-' . $post->ID;
    82 			$title = sanitize_title( $post->post_title ) . '-' . $post->ID;
    82 			echo '<a id="'.$title.'"></a>';
    83 			echo '<a id="' . $title . '"></a>';
    83 			break;
    84 			break;
    84 		case 'id':
    85 		case 'id':
    85 		default:
    86 		default:
    86 			echo '<a id="post-' . $post->ID . '"></a>';
    87 			echo '<a id="post-' . $post->ID . '"></a>';
    87 			break;
    88 			break;
   121 		'%monthnum%',
   122 		'%monthnum%',
   122 		'%day%',
   123 		'%day%',
   123 		'%hour%',
   124 		'%hour%',
   124 		'%minute%',
   125 		'%minute%',
   125 		'%second%',
   126 		'%second%',
   126 		$leavename? '' : '%postname%',
   127 		$leavename ? '' : '%postname%',
   127 		'%post_id%',
   128 		'%post_id%',
   128 		'%category%',
   129 		'%category%',
   129 		'%author%',
   130 		'%author%',
   130 		$leavename? '' : '%pagename%',
   131 		$leavename ? '' : '%pagename%',
   131 	);
   132 	);
   132 
   133 
   133 	if ( is_object( $post ) && isset( $post->filter ) && 'sample' == $post->filter ) {
   134 	if ( is_object( $post ) && isset( $post->filter ) && 'sample' == $post->filter ) {
   134 		$sample = true;
   135 		$sample = true;
   135 	} else {
   136 	} else {
   136 		$post = get_post( $post );
   137 		$post   = get_post( $post );
   137 		$sample = false;
   138 		$sample = false;
   138 	}
   139 	}
   139 
   140 
   140 	if ( empty($post->ID) )
   141 	if ( empty( $post->ID ) ) {
   141 		return false;
   142 		return false;
   142 
   143 	}
   143 	if ( $post->post_type == 'page' )
   144 
   144 		return get_page_link($post, $leavename, $sample);
   145 	if ( $post->post_type == 'page' ) {
   145 	elseif ( $post->post_type == 'attachment' )
   146 		return get_page_link( $post, $leavename, $sample );
       
   147 	} elseif ( $post->post_type == 'attachment' ) {
   146 		return get_attachment_link( $post, $leavename );
   148 		return get_attachment_link( $post, $leavename );
   147 	elseif ( in_array($post->post_type, get_post_types( array('_builtin' => false) ) ) )
   149 	} elseif ( in_array( $post->post_type, get_post_types( array( '_builtin' => false ) ) ) ) {
   148 		return get_post_permalink($post, $leavename, $sample);
   150 		return get_post_permalink( $post, $leavename, $sample );
   149 
   151 	}
   150 	$permalink = get_option('permalink_structure');
   152 
       
   153 	$permalink = get_option( 'permalink_structure' );
   151 
   154 
   152 	/**
   155 	/**
   153 	 * Filters the permalink structure for a post before token replacement occurs.
   156 	 * Filters the permalink structure for a post before token replacement occurs.
   154 	 *
   157 	 *
   155 	 * Only applies to posts with post_type of 'post'.
   158 	 * Only applies to posts with post_type of 'post'.
   160 	 * @param WP_Post $post      The post in question.
   163 	 * @param WP_Post $post      The post in question.
   161 	 * @param bool    $leavename Whether to keep the post name.
   164 	 * @param bool    $leavename Whether to keep the post name.
   162 	 */
   165 	 */
   163 	$permalink = apply_filters( 'pre_post_link', $permalink, $post, $leavename );
   166 	$permalink = apply_filters( 'pre_post_link', $permalink, $post, $leavename );
   164 
   167 
   165 	if ( '' != $permalink && !in_array( $post->post_status, array( 'draft', 'pending', 'auto-draft', 'future' ) ) ) {
   168 	if ( '' != $permalink && ! in_array( $post->post_status, array( 'draft', 'pending', 'auto-draft', 'future' ) ) ) {
   166 		$unixtime = strtotime($post->post_date);
   169 		$unixtime = strtotime( $post->post_date );
   167 
   170 
   168 		$category = '';
   171 		$category = '';
   169 		if ( strpos($permalink, '%category%') !== false ) {
   172 		if ( strpos( $permalink, '%category%' ) !== false ) {
   170 			$cats = get_the_category($post->ID);
   173 			$cats = get_the_category( $post->ID );
   171 			if ( $cats ) {
   174 			if ( $cats ) {
   172 				$cats = wp_list_sort( $cats, array(
   175 				$cats = wp_list_sort(
   173 					'term_id' => 'ASC',
   176 					$cats,
   174 				) );
   177 					array(
       
   178 						'term_id' => 'ASC',
       
   179 					)
       
   180 				);
   175 
   181 
   176 				/**
   182 				/**
   177 				 * Filters the category that gets used in the %category% permalink token.
   183 				 * Filters the category that gets used in the %category% permalink token.
   178 				 *
   184 				 *
   179 				 * @since 3.5.0
   185 				 * @since 3.5.0
   183 				 * @param WP_Post  $post The post in question.
   189 				 * @param WP_Post  $post The post in question.
   184 				 */
   190 				 */
   185 				$category_object = apply_filters( 'post_link_category', $cats[0], $cats, $post );
   191 				$category_object = apply_filters( 'post_link_category', $cats[0], $cats, $post );
   186 
   192 
   187 				$category_object = get_term( $category_object, 'category' );
   193 				$category_object = get_term( $category_object, 'category' );
   188 				$category = $category_object->slug;
   194 				$category        = $category_object->slug;
   189 				if ( $parent = $category_object->parent )
   195 				if ( $category_object->parent ) {
   190 					$category = get_category_parents($parent, false, '/', true) . $category;
   196 					$category = get_category_parents( $category_object->parent, false, '/', true ) . $category;
       
   197 				}
   191 			}
   198 			}
   192 			// show default category in permalinks, without
   199 			// show default category in permalinks, without
   193 			// having to assign it explicitly
   200 			// having to assign it explicitly
   194 			if ( empty($category) ) {
   201 			if ( empty( $category ) ) {
   195 				$default_category = get_term( get_option( 'default_category' ), 'category' );
   202 				$default_category = get_term( get_option( 'default_category' ), 'category' );
   196 				if ( $default_category && ! is_wp_error( $default_category ) ) {
   203 				if ( $default_category && ! is_wp_error( $default_category ) ) {
   197 					$category = $default_category->slug;
   204 					$category = $default_category->slug;
   198 				}
   205 				}
   199 			}
   206 			}
   200 		}
   207 		}
   201 
   208 
   202 		$author = '';
   209 		$author = '';
   203 		if ( strpos($permalink, '%author%') !== false ) {
   210 		if ( strpos( $permalink, '%author%' ) !== false ) {
   204 			$authordata = get_userdata($post->post_author);
   211 			$authordata = get_userdata( $post->post_author );
   205 			$author = $authordata->user_nicename;
   212 			$author     = $authordata->user_nicename;
   206 		}
   213 		}
   207 
   214 
   208 		$date = explode(" ",date('Y m d H i s', $unixtime));
   215 		$date           = explode( ' ', date( 'Y m d H i s', $unixtime ) );
   209 		$rewritereplace =
   216 		$rewritereplace =
   210 		array(
   217 		array(
   211 			$date[0],
   218 			$date[0],
   212 			$date[1],
   219 			$date[1],
   213 			$date[2],
   220 			$date[2],
   218 			$post->ID,
   225 			$post->ID,
   219 			$category,
   226 			$category,
   220 			$author,
   227 			$author,
   221 			$post->post_name,
   228 			$post->post_name,
   222 		);
   229 		);
   223 		$permalink = home_url( str_replace($rewritecode, $rewritereplace, $permalink) );
   230 		$permalink      = home_url( str_replace( $rewritecode, $rewritereplace, $permalink ) );
   224 		$permalink = user_trailingslashit($permalink, 'single');
   231 		$permalink      = user_trailingslashit( $permalink, 'single' );
   225 	} else { // if they're not using the fancy permalink option
   232 	} else { // if they're not using the fancy permalink option
   226 		$permalink = home_url('?p=' . $post->ID);
   233 		$permalink = home_url( '?p=' . $post->ID );
   227 	}
   234 	}
   228 
   235 
   229 	/**
   236 	/**
   230 	 * Filters the permalink for a post.
   237 	 * Filters the permalink for a post.
   231 	 *
   238 	 *
   253  * @return string|WP_Error The post permalink.
   260  * @return string|WP_Error The post permalink.
   254  */
   261  */
   255 function get_post_permalink( $id = 0, $leavename = false, $sample = false ) {
   262 function get_post_permalink( $id = 0, $leavename = false, $sample = false ) {
   256 	global $wp_rewrite;
   263 	global $wp_rewrite;
   257 
   264 
   258 	$post = get_post($id);
   265 	$post = get_post( $id );
   259 
   266 
   260 	if ( is_wp_error( $post ) )
   267 	if ( is_wp_error( $post ) ) {
   261 		return $post;
   268 		return $post;
   262 
   269 	}
   263 	$post_link = $wp_rewrite->get_extra_permastruct($post->post_type);
   270 
       
   271 	$post_link = $wp_rewrite->get_extra_permastruct( $post->post_type );
   264 
   272 
   265 	$slug = $post->post_name;
   273 	$slug = $post->post_name;
   266 
   274 
   267 	$draft_or_pending = get_post_status( $post ) && in_array( get_post_status( $post ), array( 'draft', 'pending', 'auto-draft', 'future' ) );
   275 	$draft_or_pending = get_post_status( $post ) && in_array( get_post_status( $post ), array( 'draft', 'pending', 'auto-draft', 'future' ) );
   268 
   276 
   269 	$post_type = get_post_type_object($post->post_type);
   277 	$post_type = get_post_type_object( $post->post_type );
   270 
   278 
   271 	if ( $post_type->hierarchical ) {
   279 	if ( $post_type->hierarchical ) {
   272 		$slug = get_page_uri( $post );
   280 		$slug = get_page_uri( $post );
   273 	}
   281 	}
   274 
   282 
   275 	if ( !empty($post_link) && ( !$draft_or_pending || $sample ) ) {
   283 	if ( ! empty( $post_link ) && ( ! $draft_or_pending || $sample ) ) {
   276 		if ( ! $leavename ) {
   284 		if ( ! $leavename ) {
   277 			$post_link = str_replace("%$post->post_type%", $slug, $post_link);
   285 			$post_link = str_replace( "%$post->post_type%", $slug, $post_link );
   278 		}
   286 		}
   279 		$post_link = home_url( user_trailingslashit($post_link) );
   287 		$post_link = home_url( user_trailingslashit( $post_link ) );
   280 	} else {
   288 	} else {
   281 		if ( $post_type->query_var && ( isset($post->post_status) && !$draft_or_pending ) )
   289 		if ( $post_type->query_var && ( isset( $post->post_status ) && ! $draft_or_pending ) ) {
   282 			$post_link = add_query_arg($post_type->query_var, $slug, '');
   290 			$post_link = add_query_arg( $post_type->query_var, $slug, '' );
   283 		else
   291 		} else {
   284 			$post_link = add_query_arg(array('post_type' => $post->post_type, 'p' => $post->ID), '');
   292 			$post_link = add_query_arg(
   285 		$post_link = home_url($post_link);
   293 				array(
       
   294 					'post_type' => $post->post_type,
       
   295 					'p'         => $post->ID,
       
   296 				),
       
   297 				''
       
   298 			);
       
   299 		}
       
   300 		$post_link = home_url( $post_link );
   286 	}
   301 	}
   287 
   302 
   288 	/**
   303 	/**
   289 	 * Filters the permalink for a post of a custom post type.
   304 	 * Filters the permalink for a post of a custom post type.
   290 	 *
   305 	 *
   312  * @return string The page permalink.
   327  * @return string The page permalink.
   313  */
   328  */
   314 function get_page_link( $post = false, $leavename = false, $sample = false ) {
   329 function get_page_link( $post = false, $leavename = false, $sample = false ) {
   315 	$post = get_post( $post );
   330 	$post = get_post( $post );
   316 
   331 
   317 	if ( 'page' == get_option( 'show_on_front' ) && $post->ID == get_option( 'page_on_front' ) )
   332 	if ( 'page' == get_option( 'show_on_front' ) && $post->ID == get_option( 'page_on_front' ) ) {
   318 		$link = home_url('/');
   333 		$link = home_url( '/' );
   319 	else
   334 	} else {
   320 		$link = _get_page_link( $post, $leavename, $sample );
   335 		$link = _get_page_link( $post, $leavename, $sample );
       
   336 	}
   321 
   337 
   322 	/**
   338 	/**
   323 	 * Filters the permalink for a page.
   339 	 * Filters the permalink for a page.
   324 	 *
   340 	 *
   325 	 * @since 1.5.0
   341 	 * @since 1.5.0
   354 
   370 
   355 	$draft_or_pending = in_array( $post->post_status, array( 'draft', 'pending', 'auto-draft' ) );
   371 	$draft_or_pending = in_array( $post->post_status, array( 'draft', 'pending', 'auto-draft' ) );
   356 
   372 
   357 	$link = $wp_rewrite->get_page_permastruct();
   373 	$link = $wp_rewrite->get_page_permastruct();
   358 
   374 
   359 	if ( !empty($link) && ( ( isset($post->post_status) && !$draft_or_pending ) || $sample ) ) {
   375 	if ( ! empty( $link ) && ( ( isset( $post->post_status ) && ! $draft_or_pending ) || $sample ) ) {
   360 		if ( ! $leavename ) {
   376 		if ( ! $leavename ) {
   361 			$link = str_replace('%pagename%', get_page_uri( $post ), $link);
   377 			$link = str_replace( '%pagename%', get_page_uri( $post ), $link );
   362 		}
   378 		}
   363 
   379 
   364 		$link = home_url($link);
   380 		$link = home_url( $link );
   365 		$link = user_trailingslashit($link, 'page');
   381 		$link = user_trailingslashit( $link, 'page' );
   366 	} else {
   382 	} else {
   367 		$link = home_url( '?page_id=' . $post->ID );
   383 		$link = home_url( '?page_id=' . $post->ID );
   368 	}
   384 	}
   369 
   385 
   370 	/**
   386 	/**
   394 function get_attachment_link( $post = null, $leavename = false ) {
   410 function get_attachment_link( $post = null, $leavename = false ) {
   395 	global $wp_rewrite;
   411 	global $wp_rewrite;
   396 
   412 
   397 	$link = false;
   413 	$link = false;
   398 
   414 
   399 	$post = get_post( $post );
   415 	$post   = get_post( $post );
   400 	$parent = ( $post->post_parent > 0 && $post->post_parent != $post->ID ) ? get_post( $post->post_parent ) : false;
   416 	$parent = ( $post->post_parent > 0 && $post->post_parent != $post->ID ) ? get_post( $post->post_parent ) : false;
   401 	if ( $parent && ! in_array( $parent->post_type, get_post_types() ) ) {
   417 	if ( $parent && ! in_array( $parent->post_type, get_post_types() ) ) {
   402 		$parent = false;
   418 		$parent = false;
   403 	}
   419 	}
   404 
   420 
   405 	if ( $wp_rewrite->using_permalinks() && $parent ) {
   421 	if ( $wp_rewrite->using_permalinks() && $parent ) {
   406 		if ( 'page' == $parent->post_type )
   422 		if ( 'page' == $parent->post_type ) {
   407 			$parentlink = _get_page_link( $post->post_parent ); // Ignores page_on_front
   423 			$parentlink = _get_page_link( $post->post_parent ); // Ignores page_on_front
   408 		else
   424 		} else {
   409 			$parentlink = get_permalink( $post->post_parent );
   425 			$parentlink = get_permalink( $post->post_parent );
   410 
   426 		}
   411 		if ( is_numeric($post->post_name) || false !== strpos(get_option('permalink_structure'), '%category%') )
   427 
       
   428 		if ( is_numeric( $post->post_name ) || false !== strpos( get_option( 'permalink_structure' ), '%category%' ) ) {
   412 			$name = 'attachment/' . $post->post_name; // <permalink>/<int>/ is paged so we use the explicit attachment marker
   429 			$name = 'attachment/' . $post->post_name; // <permalink>/<int>/ is paged so we use the explicit attachment marker
   413 		else
   430 		} else {
   414 			$name = $post->post_name;
   431 			$name = $post->post_name;
   415 
   432 		}
   416 		if ( strpos($parentlink, '?') === false )
   433 
   417 			$link = user_trailingslashit( trailingslashit($parentlink) . '%postname%' );
   434 		if ( strpos( $parentlink, '?' ) === false ) {
   418 
   435 			$link = user_trailingslashit( trailingslashit( $parentlink ) . '%postname%' );
   419 		if ( ! $leavename )
   436 		}
       
   437 
       
   438 		if ( ! $leavename ) {
   420 			$link = str_replace( '%postname%', $name, $link );
   439 			$link = str_replace( '%postname%', $name, $link );
       
   440 		}
   421 	} elseif ( $wp_rewrite->using_permalinks() && ! $leavename ) {
   441 	} elseif ( $wp_rewrite->using_permalinks() && ! $leavename ) {
   422 		$link = home_url( user_trailingslashit( $post->post_name ) );
   442 		$link = home_url( user_trailingslashit( $post->post_name ) );
   423 	}
   443 	}
   424 
   444 
   425 	if ( ! $link )
   445 	if ( ! $link ) {
   426 		$link = home_url( '/?attachment_id=' . $post->ID );
   446 		$link = home_url( '/?attachment_id=' . $post->ID );
       
   447 	}
   427 
   448 
   428 	/**
   449 	/**
   429 	 * Filters the permalink for an attachment.
   450 	 * Filters the permalink for an attachment.
   430 	 *
   451 	 *
   431 	 * @since 2.0.0
   452 	 * @since 2.0.0
   446  * @param int|bool $year False for current year or year for permalink.
   467  * @param int|bool $year False for current year or year for permalink.
   447  * @return string The permalink for the specified year archive.
   468  * @return string The permalink for the specified year archive.
   448  */
   469  */
   449 function get_year_link( $year ) {
   470 function get_year_link( $year ) {
   450 	global $wp_rewrite;
   471 	global $wp_rewrite;
   451 	if ( !$year )
   472 	if ( ! $year ) {
   452 		$year = gmdate('Y', current_time('timestamp'));
   473 		$year = current_time( 'Y' );
       
   474 	}
   453 	$yearlink = $wp_rewrite->get_year_permastruct();
   475 	$yearlink = $wp_rewrite->get_year_permastruct();
   454 	if ( !empty($yearlink) ) {
   476 	if ( ! empty( $yearlink ) ) {
   455 		$yearlink = str_replace('%year%', $year, $yearlink);
   477 		$yearlink = str_replace( '%year%', $year, $yearlink );
   456 		$yearlink = home_url( user_trailingslashit( $yearlink, 'year' ) );
   478 		$yearlink = home_url( user_trailingslashit( $yearlink, 'year' ) );
   457 	} else {
   479 	} else {
   458 		$yearlink = home_url( '?m=' . $year );
   480 		$yearlink = home_url( '?m=' . $year );
   459 	}
   481 	}
   460 
   482 
   478  *
   500  *
   479  * @param bool|int $year  False for current year. Integer of year.
   501  * @param bool|int $year  False for current year. Integer of year.
   480  * @param bool|int $month False for current month. Integer of month.
   502  * @param bool|int $month False for current month. Integer of month.
   481  * @return string The permalink for the specified month and year archive.
   503  * @return string The permalink for the specified month and year archive.
   482  */
   504  */
   483 function get_month_link($year, $month) {
   505 function get_month_link( $year, $month ) {
   484 	global $wp_rewrite;
   506 	global $wp_rewrite;
   485 	if ( !$year )
   507 	if ( ! $year ) {
   486 		$year = gmdate('Y', current_time('timestamp'));
   508 		$year = current_time( 'Y' );
   487 	if ( !$month )
   509 	}
   488 		$month = gmdate('m', current_time('timestamp'));
   510 	if ( ! $month ) {
       
   511 		$month = current_time( 'm' );
       
   512 	}
   489 	$monthlink = $wp_rewrite->get_month_permastruct();
   513 	$monthlink = $wp_rewrite->get_month_permastruct();
   490 	if ( !empty($monthlink) ) {
   514 	if ( ! empty( $monthlink ) ) {
   491 		$monthlink = str_replace('%year%', $year, $monthlink);
   515 		$monthlink = str_replace( '%year%', $year, $monthlink );
   492 		$monthlink = str_replace('%monthnum%', zeroise(intval($month), 2), $monthlink);
   516 		$monthlink = str_replace( '%monthnum%', zeroise( intval( $month ), 2 ), $monthlink );
   493 		$monthlink = home_url( user_trailingslashit( $monthlink, 'month' ) );
   517 		$monthlink = home_url( user_trailingslashit( $monthlink, 'month' ) );
   494 	} else {
   518 	} else {
   495 		$monthlink = home_url( '?m=' . $year . zeroise( $month, 2 ) );
   519 		$monthlink = home_url( '?m=' . $year . zeroise( $month, 2 ) );
   496 	}
   520 	}
   497 
   521 
   517  * @param bool|int $year  False for current year. Integer of year.
   541  * @param bool|int $year  False for current year. Integer of year.
   518  * @param bool|int $month False for current month. Integer of month.
   542  * @param bool|int $month False for current month. Integer of month.
   519  * @param bool|int $day   False for current day. Integer of day.
   543  * @param bool|int $day   False for current day. Integer of day.
   520  * @return string The permalink for the specified day, month, and year archive.
   544  * @return string The permalink for the specified day, month, and year archive.
   521  */
   545  */
   522 function get_day_link($year, $month, $day) {
   546 function get_day_link( $year, $month, $day ) {
   523 	global $wp_rewrite;
   547 	global $wp_rewrite;
   524 	if ( !$year )
   548 	if ( ! $year ) {
   525 		$year = gmdate('Y', current_time('timestamp'));
   549 		$year = current_time( 'Y' );
   526 	if ( !$month )
   550 	}
   527 		$month = gmdate('m', current_time('timestamp'));
   551 	if ( ! $month ) {
   528 	if ( !$day )
   552 		$month = current_time( 'm' );
   529 		$day = gmdate('j', current_time('timestamp'));
   553 	}
       
   554 	if ( ! $day ) {
       
   555 		$day = current_time( 'j' );
       
   556 	}
   530 
   557 
   531 	$daylink = $wp_rewrite->get_day_permastruct();
   558 	$daylink = $wp_rewrite->get_day_permastruct();
   532 	if ( !empty($daylink) ) {
   559 	if ( ! empty( $daylink ) ) {
   533 		$daylink = str_replace('%year%', $year, $daylink);
   560 		$daylink = str_replace( '%year%', $year, $daylink );
   534 		$daylink = str_replace('%monthnum%', zeroise(intval($month), 2), $daylink);
   561 		$daylink = str_replace( '%monthnum%', zeroise( intval( $month ), 2 ), $daylink );
   535 		$daylink = str_replace('%day%', zeroise(intval($day), 2), $daylink);
   562 		$daylink = str_replace( '%day%', zeroise( intval( $day ), 2 ), $daylink );
   536 		$daylink = home_url( user_trailingslashit( $daylink, 'day' ) );
   563 		$daylink = home_url( user_trailingslashit( $daylink, 'day' ) );
   537 	} else {
   564 	} else {
   538 		$daylink = home_url( '?m=' . $year . zeroise( $month, 2 ) . zeroise( $day, 2 ) );
   565 		$daylink = home_url( '?m=' . $year . zeroise( $month, 2 ) . zeroise( $day, 2 ) );
   539 	}
   566 	}
   540 
   567 
   587 function get_feed_link( $feed = '' ) {
   614 function get_feed_link( $feed = '' ) {
   588 	global $wp_rewrite;
   615 	global $wp_rewrite;
   589 
   616 
   590 	$permalink = $wp_rewrite->get_feed_permastruct();
   617 	$permalink = $wp_rewrite->get_feed_permastruct();
   591 	if ( '' != $permalink ) {
   618 	if ( '' != $permalink ) {
   592 		if ( false !== strpos($feed, 'comments_') ) {
   619 		if ( false !== strpos( $feed, 'comments_' ) ) {
   593 			$feed = str_replace('comments_', '', $feed);
   620 			$feed      = str_replace( 'comments_', '', $feed );
   594 			$permalink = $wp_rewrite->get_comment_feed_permastruct();
   621 			$permalink = $wp_rewrite->get_comment_feed_permastruct();
   595 		}
   622 		}
   596 
   623 
   597 		if ( get_default_feed() == $feed )
   624 		if ( get_default_feed() == $feed ) {
   598 			$feed = '';
   625 			$feed = '';
   599 
   626 		}
   600 		$permalink = str_replace('%feed%', $feed, $permalink);
   627 
   601 		$permalink = preg_replace('#/+#', '/', "/$permalink");
   628 		$permalink = str_replace( '%feed%', $feed, $permalink );
   602 		$output =  home_url( user_trailingslashit($permalink, 'feed') );
   629 		$permalink = preg_replace( '#/+#', '/', "/$permalink" );
   603 	} else {
   630 		$output    = home_url( user_trailingslashit( $permalink, 'feed' ) );
   604 		if ( empty($feed) )
   631 	} else {
       
   632 		if ( empty( $feed ) ) {
   605 			$feed = get_default_feed();
   633 			$feed = get_default_feed();
   606 
   634 		}
   607 		if ( false !== strpos($feed, 'comments_') )
   635 
   608 			$feed = str_replace('comments_', 'comments-', $feed);
   636 		if ( false !== strpos( $feed, 'comments_' ) ) {
   609 
   637 			$feed = str_replace( 'comments_', 'comments-', $feed );
   610 		$output = home_url("?feed={$feed}");
   638 		}
       
   639 
       
   640 		$output = home_url( "?feed={$feed}" );
   611 	}
   641 	}
   612 
   642 
   613 	/**
   643 	/**
   614 	 * Filters the feed type permalink.
   644 	 * Filters the feed type permalink.
   615 	 *
   645 	 *
   631  * @return string The permalink for the comments feed for the given post.
   661  * @return string The permalink for the comments feed for the given post.
   632  */
   662  */
   633 function get_post_comments_feed_link( $post_id = 0, $feed = '' ) {
   663 function get_post_comments_feed_link( $post_id = 0, $feed = '' ) {
   634 	$post_id = absint( $post_id );
   664 	$post_id = absint( $post_id );
   635 
   665 
   636 	if ( ! $post_id )
   666 	if ( ! $post_id ) {
   637 		$post_id = get_the_ID();
   667 		$post_id = get_the_ID();
   638 
   668 	}
   639 	if ( empty( $feed ) )
   669 
       
   670 	if ( empty( $feed ) ) {
   640 		$feed = get_default_feed();
   671 		$feed = get_default_feed();
   641 
   672 	}
   642 	$post = get_post( $post_id );
   673 
       
   674 	$post       = get_post( $post_id );
   643 	$unattached = 'attachment' === $post->post_type && 0 === (int) $post->post_parent;
   675 	$unattached = 'attachment' === $post->post_type && 0 === (int) $post->post_parent;
   644 
   676 
   645 	if ( '' != get_option('permalink_structure') ) {
   677 	if ( '' != get_option( 'permalink_structure' ) ) {
   646 		if ( 'page' == get_option('show_on_front') && $post_id == get_option('page_on_front') )
   678 		if ( 'page' == get_option( 'show_on_front' ) && $post_id == get_option( 'page_on_front' ) ) {
   647 			$url = _get_page_link( $post_id );
   679 			$url = _get_page_link( $post_id );
   648 		else
   680 		} else {
   649 			$url = get_permalink($post_id);
   681 			$url = get_permalink( $post_id );
       
   682 		}
   650 
   683 
   651 		if ( $unattached ) {
   684 		if ( $unattached ) {
   652 			$url =  home_url( '/feed/' );
   685 			$url = home_url( '/feed/' );
   653 			if ( $feed !== get_default_feed() ) {
   686 			if ( $feed !== get_default_feed() ) {
   654 				$url .= "$feed/";
   687 				$url .= "$feed/";
   655 			}
   688 			}
   656 			$url = add_query_arg( 'attachment_id', $post_id, $url );
   689 			$url = add_query_arg( 'attachment_id', $post_id, $url );
   657 		} else {
   690 		} else {
   658 			$url = trailingslashit($url) . 'feed';
   691 			$url = trailingslashit( $url ) . 'feed';
   659 			if ( $feed != get_default_feed() )
   692 			if ( $feed != get_default_feed() ) {
   660 				$url .= "/$feed";
   693 				$url .= "/$feed";
   661 			$url = user_trailingslashit($url, 'single_feed');
   694 			}
       
   695 			$url = user_trailingslashit( $url, 'single_feed' );
   662 		}
   696 		}
   663 	} else {
   697 	} else {
   664 		if ( $unattached ) {
   698 		if ( $unattached ) {
   665 			$url = add_query_arg( array( 'feed' => $feed, 'attachment_id' => $post_id ), home_url( '/' ) );
   699 			$url = add_query_arg(
       
   700 				array(
       
   701 					'feed'          => $feed,
       
   702 					'attachment_id' => $post_id,
       
   703 				),
       
   704 				home_url( '/' )
       
   705 			);
   666 		} elseif ( 'page' == $post->post_type ) {
   706 		} elseif ( 'page' == $post->post_type ) {
   667 			$url = add_query_arg( array( 'feed' => $feed, 'page_id' => $post_id ), home_url( '/' ) );
   707 			$url = add_query_arg(
       
   708 				array(
       
   709 					'feed'    => $feed,
       
   710 					'page_id' => $post_id,
       
   711 				),
       
   712 				home_url( '/' )
       
   713 			);
   668 		} else {
   714 		} else {
   669 			$url = add_query_arg( array( 'feed' => $feed, 'p' => $post_id ), home_url( '/' ) );
   715 			$url = add_query_arg(
       
   716 				array(
       
   717 					'feed' => $feed,
       
   718 					'p'    => $post_id,
       
   719 				),
       
   720 				home_url( '/' )
       
   721 			);
   670 		}
   722 		}
   671 	}
   723 	}
   672 
   724 
   673 	/**
   725 	/**
   674 	 * Filters the post comments feed permalink.
   726 	 * Filters the post comments feed permalink.
   694  * @param string $feed      Optional. Feed format. Default empty.
   746  * @param string $feed      Optional. Feed format. Default empty.
   695  */
   747  */
   696 function post_comments_feed_link( $link_text = '', $post_id = '', $feed = '' ) {
   748 function post_comments_feed_link( $link_text = '', $post_id = '', $feed = '' ) {
   697 	$url = get_post_comments_feed_link( $post_id, $feed );
   749 	$url = get_post_comments_feed_link( $post_id, $feed );
   698 	if ( empty( $link_text ) ) {
   750 	if ( empty( $link_text ) ) {
   699 		$link_text = __('Comments Feed');
   751 		$link_text = __( 'Comments Feed' );
   700 	}
   752 	}
   701 
   753 
   702 	$link = '<a href="' . esc_url( $url ) . '">' . $link_text . '</a>';
   754 	$link = '<a href="' . esc_url( $url ) . '">' . $link_text . '</a>';
   703 	/**
   755 	/**
   704 	 * Filters the post comment feed link anchor tag.
   756 	 * Filters the post comment feed link anchor tag.
   723  * @param int    $author_id Author ID.
   775  * @param int    $author_id Author ID.
   724  * @param string $feed      Optional. Feed type. Default empty.
   776  * @param string $feed      Optional. Feed type. Default empty.
   725  * @return string Link to the feed for the author specified by $author_id.
   777  * @return string Link to the feed for the author specified by $author_id.
   726  */
   778  */
   727 function get_author_feed_link( $author_id, $feed = '' ) {
   779 function get_author_feed_link( $author_id, $feed = '' ) {
   728 	$author_id = (int) $author_id;
   780 	$author_id           = (int) $author_id;
   729 	$permalink_structure = get_option('permalink_structure');
   781 	$permalink_structure = get_option( 'permalink_structure' );
   730 
   782 
   731 	if ( empty($feed) )
   783 	if ( empty( $feed ) ) {
   732 		$feed = get_default_feed();
   784 		$feed = get_default_feed();
       
   785 	}
   733 
   786 
   734 	if ( '' == $permalink_structure ) {
   787 	if ( '' == $permalink_structure ) {
   735 		$link = home_url("?feed=$feed&amp;author=" . $author_id);
   788 		$link = home_url( "?feed=$feed&amp;author=" . $author_id );
   736 	} else {
   789 	} else {
   737 		$link = get_author_posts_url($author_id);
   790 		$link = get_author_posts_url( $author_id );
   738 		if ( $feed == get_default_feed() )
   791 		if ( $feed == get_default_feed() ) {
   739 			$feed_link = 'feed';
   792 			$feed_link = 'feed';
   740 		else
   793 		} else {
   741 			$feed_link = "feed/$feed";
   794 			$feed_link = "feed/$feed";
   742 
   795 		}
   743 		$link = trailingslashit($link) . user_trailingslashit($feed_link, 'feed');
   796 
       
   797 		$link = trailingslashit( $link ) . user_trailingslashit( $feed_link, 'feed' );
   744 	}
   798 	}
   745 
   799 
   746 	/**
   800 	/**
   747 	 * Filters the feed link for a given author.
   801 	 * Filters the feed link for a given author.
   748 	 *
   802 	 *
   784  * @param string $taxonomy Optional. Taxonomy of `$term_id`. Default 'category'.
   838  * @param string $taxonomy Optional. Taxonomy of `$term_id`. Default 'category'.
   785  * @param string $feed     Optional. Feed type. Default empty.
   839  * @param string $feed     Optional. Feed type. Default empty.
   786  * @return string|false Link to the feed for the term specified by $term_id and $taxonomy.
   840  * @return string|false Link to the feed for the term specified by $term_id and $taxonomy.
   787  */
   841  */
   788 function get_term_feed_link( $term_id, $taxonomy = 'category', $feed = '' ) {
   842 function get_term_feed_link( $term_id, $taxonomy = 'category', $feed = '' ) {
   789 	$term_id = ( int ) $term_id;
   843 	$term_id = (int) $term_id;
   790 
   844 
   791 	$term = get_term( $term_id, $taxonomy  );
   845 	$term = get_term( $term_id, $taxonomy );
   792 
   846 
   793 	if ( empty( $term ) || is_wp_error( $term ) )
   847 	if ( empty( $term ) || is_wp_error( $term ) ) {
   794 		return false;
   848 		return false;
   795 
   849 	}
   796 	if ( empty( $feed ) )
   850 
       
   851 	if ( empty( $feed ) ) {
   797 		$feed = get_default_feed();
   852 		$feed = get_default_feed();
       
   853 	}
   798 
   854 
   799 	$permalink_structure = get_option( 'permalink_structure' );
   855 	$permalink_structure = get_option( 'permalink_structure' );
   800 
   856 
   801 	if ( '' == $permalink_structure ) {
   857 	if ( '' == $permalink_structure ) {
   802 		if ( 'category' == $taxonomy ) {
   858 		if ( 'category' == $taxonomy ) {
   803 			$link = home_url("?feed=$feed&amp;cat=$term_id");
   859 			$link = home_url( "?feed=$feed&amp;cat=$term_id" );
   804 		}
   860 		} elseif ( 'post_tag' == $taxonomy ) {
   805 		elseif ( 'post_tag' == $taxonomy ) {
   861 			$link = home_url( "?feed=$feed&amp;tag=$term->slug" );
   806 			$link = home_url("?feed=$feed&amp;tag=$term->slug");
       
   807 		} else {
   862 		} else {
   808 			$t = get_taxonomy( $taxonomy );
   863 			$t    = get_taxonomy( $taxonomy );
   809 			$link = home_url("?feed=$feed&amp;$t->query_var=$term->slug");
   864 			$link = home_url( "?feed=$feed&amp;$t->query_var=$term->slug" );
   810 		}
   865 		}
   811 	} else {
   866 	} else {
   812 		$link = get_term_link( $term_id, $term->taxonomy );
   867 		$link = get_term_link( $term_id, $term->taxonomy );
   813 		if ( $feed == get_default_feed() )
   868 		if ( $feed == get_default_feed() ) {
   814 			$feed_link = 'feed';
   869 			$feed_link = 'feed';
   815 		else
   870 		} else {
   816 			$feed_link = "feed/$feed";
   871 			$feed_link = "feed/$feed";
       
   872 		}
   817 
   873 
   818 		$link = trailingslashit( $link ) . user_trailingslashit( $feed_link, 'feed' );
   874 		$link = trailingslashit( $link ) . user_trailingslashit( $feed_link, 'feed' );
   819 	}
   875 	}
   820 
   876 
   821 	if ( 'category' == $taxonomy ) {
   877 	if ( 'category' == $taxonomy ) {
   977  * @param object $term   Optional. Term object. If null, the queried object will be inspected. Default null.
  1033  * @param object $term   Optional. Term object. If null, the queried object will be inspected. Default null.
   978  * @param bool   $echo   Optional. Whether or not to echo the return. Default true.
  1034  * @param bool   $echo   Optional. Whether or not to echo the return. Default true.
   979  * @return string|void HTML content.
  1035  * @return string|void HTML content.
   980  */
  1036  */
   981 function edit_term_link( $link = '', $before = '', $after = '', $term = null, $echo = true ) {
  1037 function edit_term_link( $link = '', $before = '', $after = '', $term = null, $echo = true ) {
   982 	if ( is_null( $term ) )
  1038 	if ( is_null( $term ) ) {
   983 		$term = get_queried_object();
  1039 		$term = get_queried_object();
   984 
  1040 	}
   985 	if ( ! $term )
  1041 
       
  1042 	if ( ! $term ) {
   986 		return;
  1043 		return;
       
  1044 	}
   987 
  1045 
   988 	$tax = get_taxonomy( $term->taxonomy );
  1046 	$tax = get_taxonomy( $term->taxonomy );
   989 	if ( ! current_user_can( 'edit_term', $term->term_id ) ) {
  1047 	if ( ! current_user_can( 'edit_term', $term->term_id ) ) {
   990 		return;
  1048 		return;
   991 	}
  1049 	}
   992 
  1050 
   993 	if ( empty( $link ) )
  1051 	if ( empty( $link ) ) {
   994 		$link = __('Edit This');
  1052 		$link = __( 'Edit This' );
       
  1053 	}
   995 
  1054 
   996 	$link = '<a href="' . get_edit_term_link( $term->term_id, $term->taxonomy ) . '">' . $link . '</a>';
  1055 	$link = '<a href="' . get_edit_term_link( $term->term_id, $term->taxonomy ) . '">' . $link . '</a>';
   997 
  1056 
   998 	/**
  1057 	/**
   999 	 * Filters the anchor tag for the edit link of a term.
  1058 	 * Filters the anchor tag for the edit link of a term.
  1003 	 * @param string $link    The anchor tag for the edit link.
  1062 	 * @param string $link    The anchor tag for the edit link.
  1004 	 * @param int    $term_id Term ID.
  1063 	 * @param int    $term_id Term ID.
  1005 	 */
  1064 	 */
  1006 	$link = $before . apply_filters( 'edit_term_link', $link, $term->term_id ) . $after;
  1065 	$link = $before . apply_filters( 'edit_term_link', $link, $term->term_id ) . $after;
  1007 
  1066 
  1008 	if ( $echo )
  1067 	if ( $echo ) {
  1009 		echo $link;
  1068 		echo $link;
  1010 	else
  1069 	} else {
  1011 		return $link;
  1070 		return $link;
       
  1071 	}
  1012 }
  1072 }
  1013 
  1073 
  1014 /**
  1074 /**
  1015  * Retrieves the permalink for a search.
  1075  * Retrieves the permalink for a search.
  1016  *
  1076  *
  1022  * @return string The search permalink.
  1082  * @return string The search permalink.
  1023  */
  1083  */
  1024 function get_search_link( $query = '' ) {
  1084 function get_search_link( $query = '' ) {
  1025 	global $wp_rewrite;
  1085 	global $wp_rewrite;
  1026 
  1086 
  1027 	if ( empty($query) )
  1087 	if ( empty( $query ) ) {
  1028 		$search = get_search_query( false );
  1088 		$search = get_search_query( false );
  1029 	else
  1089 	} else {
  1030 		$search = stripslashes($query);
  1090 		$search = stripslashes( $query );
       
  1091 	}
  1031 
  1092 
  1032 	$permastruct = $wp_rewrite->get_search_permastruct();
  1093 	$permastruct = $wp_rewrite->get_search_permastruct();
  1033 
  1094 
  1034 	if ( empty( $permastruct ) ) {
  1095 	if ( empty( $permastruct ) ) {
  1035 		$link = home_url('?s=' . urlencode($search) );
  1096 		$link = home_url( '?s=' . urlencode( $search ) );
  1036 	} else {
  1097 	} else {
  1037 		$search = urlencode($search);
  1098 		$search = urlencode( $search );
  1038 		$search = str_replace('%2F', '/', $search); // %2F(/) is not valid within a URL, send it un-encoded.
  1099 		$search = str_replace( '%2F', '/', $search ); // %2F(/) is not valid within a URL, send it un-encoded.
  1039 		$link = str_replace( '%search%', $search, $permastruct );
  1100 		$link   = str_replace( '%search%', $search, $permastruct );
  1040 		$link = home_url( user_trailingslashit( $link, 'search' ) );
  1101 		$link   = home_url( user_trailingslashit( $link, 'search' ) );
  1041 	}
  1102 	}
  1042 
  1103 
  1043 	/**
  1104 	/**
  1044 	 * Filters the search permalink.
  1105 	 * Filters the search permalink.
  1045 	 *
  1106 	 *
  1060  *
  1121  *
  1061  * @param string $search_query Optional. Search query. Default empty.
  1122  * @param string $search_query Optional. Search query. Default empty.
  1062  * @param string $feed         Optional. Feed type. Default empty.
  1123  * @param string $feed         Optional. Feed type. Default empty.
  1063  * @return string The search results feed permalink.
  1124  * @return string The search results feed permalink.
  1064  */
  1125  */
  1065 function get_search_feed_link($search_query = '', $feed = '') {
  1126 function get_search_feed_link( $search_query = '', $feed = '' ) {
  1066 	global $wp_rewrite;
  1127 	global $wp_rewrite;
  1067 	$link = get_search_link($search_query);
  1128 	$link = get_search_link( $search_query );
  1068 
  1129 
  1069 	if ( empty($feed) )
  1130 	if ( empty( $feed ) ) {
  1070 		$feed = get_default_feed();
  1131 		$feed = get_default_feed();
       
  1132 	}
  1071 
  1133 
  1072 	$permastruct = $wp_rewrite->get_search_permastruct();
  1134 	$permastruct = $wp_rewrite->get_search_permastruct();
  1073 
  1135 
  1074 	if ( empty($permastruct) ) {
  1136 	if ( empty( $permastruct ) ) {
  1075 		$link = add_query_arg('feed', $feed, $link);
  1137 		$link = add_query_arg( 'feed', $feed, $link );
  1076 	} else {
  1138 	} else {
  1077 		$link = trailingslashit($link);
  1139 		$link  = trailingslashit( $link );
  1078 		$link .= "feed/$feed/";
  1140 		$link .= "feed/$feed/";
  1079 	}
  1141 	}
  1080 
  1142 
  1081 	/**
  1143 	/**
  1082 	 * Filters the search feed link.
  1144 	 * Filters the search feed link.
  1099  *
  1161  *
  1100  * @param string $search_query Optional. Search query. Default empty.
  1162  * @param string $search_query Optional. Search query. Default empty.
  1101  * @param string $feed         Optional. Feed type. Default empty.
  1163  * @param string $feed         Optional. Feed type. Default empty.
  1102  * @return string The comments feed search results permalink.
  1164  * @return string The comments feed search results permalink.
  1103  */
  1165  */
  1104 function get_search_comments_feed_link($search_query = '', $feed = '') {
  1166 function get_search_comments_feed_link( $search_query = '', $feed = '' ) {
  1105 	global $wp_rewrite;
  1167 	global $wp_rewrite;
  1106 
  1168 
  1107 	if ( empty($feed) )
  1169 	if ( empty( $feed ) ) {
  1108 		$feed = get_default_feed();
  1170 		$feed = get_default_feed();
  1109 
  1171 	}
  1110 	$link = get_search_feed_link($search_query, $feed);
  1172 
       
  1173 	$link = get_search_feed_link( $search_query, $feed );
  1111 
  1174 
  1112 	$permastruct = $wp_rewrite->get_search_permastruct();
  1175 	$permastruct = $wp_rewrite->get_search_permastruct();
  1113 
  1176 
  1114 	if ( empty($permastruct) )
  1177 	if ( empty( $permastruct ) ) {
  1115 		$link = add_query_arg('feed', 'comments-' . $feed, $link);
  1178 		$link = add_query_arg( 'feed', 'comments-' . $feed, $link );
  1116 	else
  1179 	} else {
  1117 		$link = add_query_arg('withcomments', 1, $link);
  1180 		$link = add_query_arg( 'withcomments', 1, $link );
       
  1181 	}
  1118 
  1182 
  1119 	/** This filter is documented in wp-includes/link-template.php */
  1183 	/** This filter is documented in wp-includes/link-template.php */
  1120 	return apply_filters( 'search_feed_link', $link, $feed, 'comments' );
  1184 	return apply_filters( 'search_feed_link', $link, $feed, 'comments' );
  1121 }
  1185 }
  1122 
  1186 
  1131  * @param string $post_type Post type.
  1195  * @param string $post_type Post type.
  1132  * @return string|false The post type archive permalink.
  1196  * @return string|false The post type archive permalink.
  1133  */
  1197  */
  1134 function get_post_type_archive_link( $post_type ) {
  1198 function get_post_type_archive_link( $post_type ) {
  1135 	global $wp_rewrite;
  1199 	global $wp_rewrite;
  1136 	if ( ! $post_type_obj = get_post_type_object( $post_type ) )
  1200 	if ( ! $post_type_obj = get_post_type_object( $post_type ) ) {
  1137 		return false;
  1201 		return false;
       
  1202 	}
  1138 
  1203 
  1139 	if ( 'post' === $post_type ) {
  1204 	if ( 'post' === $post_type ) {
  1140 		$show_on_front = get_option( 'show_on_front' );
  1205 		$show_on_front  = get_option( 'show_on_front' );
  1141 		$page_for_posts  = get_option( 'page_for_posts' );
  1206 		$page_for_posts = get_option( 'page_for_posts' );
  1142 
  1207 
  1143 		if ( 'page' == $show_on_front && $page_for_posts ) {
  1208 		if ( 'page' == $show_on_front && $page_for_posts ) {
  1144 			$link = get_permalink( $page_for_posts );
  1209 			$link = get_permalink( $page_for_posts );
  1145 		} else {
  1210 		} else {
  1146 			$link = get_home_url();
  1211 			$link = get_home_url();
  1147 		}
  1212 		}
  1148 		/** This filter is documented in wp-includes/link-template.php */
  1213 		/** This filter is documented in wp-includes/link-template.php */
  1149 		return apply_filters( 'post_type_archive_link', $link, $post_type );
  1214 		return apply_filters( 'post_type_archive_link', $link, $post_type );
  1150 	}
  1215 	}
  1151 
  1216 
  1152 	if ( ! $post_type_obj->has_archive )
  1217 	if ( ! $post_type_obj->has_archive ) {
  1153 		return false;
  1218 		return false;
       
  1219 	}
  1154 
  1220 
  1155 	if ( get_option( 'permalink_structure' ) && is_array( $post_type_obj->rewrite ) ) {
  1221 	if ( get_option( 'permalink_structure' ) && is_array( $post_type_obj->rewrite ) ) {
  1156 		$struct = ( true === $post_type_obj->has_archive ) ? $post_type_obj->rewrite['slug'] : $post_type_obj->has_archive;
  1222 		$struct = ( true === $post_type_obj->has_archive ) ? $post_type_obj->rewrite['slug'] : $post_type_obj->has_archive;
  1157 		if ( $post_type_obj->rewrite['with_front'] )
  1223 		if ( $post_type_obj->rewrite['with_front'] ) {
  1158 			$struct = $wp_rewrite->front . $struct;
  1224 			$struct = $wp_rewrite->front . $struct;
  1159 		else
  1225 		} else {
  1160 			$struct = $wp_rewrite->root . $struct;
  1226 			$struct = $wp_rewrite->root . $struct;
       
  1227 		}
  1161 		$link = home_url( user_trailingslashit( $struct, 'post_type_archive' ) );
  1228 		$link = home_url( user_trailingslashit( $struct, 'post_type_archive' ) );
  1162 	} else {
  1229 	} else {
  1163 		$link = home_url( '?post_type=' . $post_type );
  1230 		$link = home_url( '?post_type=' . $post_type );
  1164 	}
  1231 	}
  1165 
  1232 
  1183  * @param string $feed      Optional. Feed type. Default empty.
  1250  * @param string $feed      Optional. Feed type. Default empty.
  1184  * @return string|false The post type feed permalink.
  1251  * @return string|false The post type feed permalink.
  1185  */
  1252  */
  1186 function get_post_type_archive_feed_link( $post_type, $feed = '' ) {
  1253 function get_post_type_archive_feed_link( $post_type, $feed = '' ) {
  1187 	$default_feed = get_default_feed();
  1254 	$default_feed = get_default_feed();
  1188 	if ( empty( $feed ) )
  1255 	if ( empty( $feed ) ) {
  1189 		$feed = $default_feed;
  1256 		$feed = $default_feed;
  1190 
  1257 	}
  1191 	if ( ! $link = get_post_type_archive_link( $post_type ) )
  1258 
       
  1259 	if ( ! $link = get_post_type_archive_link( $post_type ) ) {
  1192 		return false;
  1260 		return false;
       
  1261 	}
  1193 
  1262 
  1194 	$post_type_obj = get_post_type_object( $post_type );
  1263 	$post_type_obj = get_post_type_object( $post_type );
  1195 	if ( get_option( 'permalink_structure' ) && is_array( $post_type_obj->rewrite ) && $post_type_obj->rewrite['feeds'] ) {
  1264 	if ( get_option( 'permalink_structure' ) && is_array( $post_type_obj->rewrite ) && $post_type_obj->rewrite['feeds'] ) {
  1196 		$link = trailingslashit( $link );
  1265 		$link  = trailingslashit( $link );
  1197 		$link .= 'feed/';
  1266 		$link .= 'feed/';
  1198 		if ( $feed != $default_feed )
  1267 		if ( $feed != $default_feed ) {
  1199 			$link .= "$feed/";
  1268 			$link .= "$feed/";
       
  1269 		}
  1200 	} else {
  1270 	} else {
  1201 		$link = add_query_arg( 'feed', $feed, $link );
  1271 		$link = add_query_arg( 'feed', $feed, $link );
  1202 	}
  1272 	}
  1203 
  1273 
  1204 	/**
  1274 	/**
  1237 		if ( ! $preview_link ) {
  1307 		if ( ! $preview_link ) {
  1238 			$preview_link = set_url_scheme( get_permalink( $post ) );
  1308 			$preview_link = set_url_scheme( get_permalink( $post ) );
  1239 		}
  1309 		}
  1240 
  1310 
  1241 		$query_args['preview'] = 'true';
  1311 		$query_args['preview'] = 'true';
  1242 		$preview_link = add_query_arg( $query_args, $preview_link );
  1312 		$preview_link          = add_query_arg( $query_args, $preview_link );
  1243 	}
  1313 	}
  1244 
  1314 
  1245 	/**
  1315 	/**
  1246 	 * Filters the URL used for a post preview.
  1316 	 * Filters the URL used for a post preview.
  1247 	 *
  1317 	 *
  1266  * @param string      $context Optional. How to output the '&' character. Default '&amp;'.
  1336  * @param string      $context Optional. How to output the '&' character. Default '&amp;'.
  1267  * @return string|null The edit post link for the given post. null if the post type is invalid or does
  1337  * @return string|null The edit post link for the given post. null if the post type is invalid or does
  1268  *                     not allow an editing UI.
  1338  *                     not allow an editing UI.
  1269  */
  1339  */
  1270 function get_edit_post_link( $id = 0, $context = 'display' ) {
  1340 function get_edit_post_link( $id = 0, $context = 'display' ) {
  1271 	if ( ! $post = get_post( $id ) )
  1341 	if ( ! $post = get_post( $id ) ) {
  1272 		return;
  1342 		return;
  1273 
  1343 	}
  1274 	if ( 'revision' === $post->post_type )
  1344 
       
  1345 	if ( 'revision' === $post->post_type ) {
  1275 		$action = '';
  1346 		$action = '';
  1276 	elseif ( 'display' == $context )
  1347 	} elseif ( 'display' == $context ) {
  1277 		$action = '&amp;action=edit';
  1348 		$action = '&amp;action=edit';
  1278 	else
  1349 	} else {
  1279 		$action = '&action=edit';
  1350 		$action = '&action=edit';
       
  1351 	}
  1280 
  1352 
  1281 	$post_type_object = get_post_type_object( $post->post_type );
  1353 	$post_type_object = get_post_type_object( $post->post_type );
  1282 	if ( !$post_type_object )
  1354 	if ( ! $post_type_object ) {
  1283 		return;
  1355 		return;
  1284 
  1356 	}
  1285 	if ( !current_user_can( 'edit_post', $post->ID ) )
  1357 
       
  1358 	if ( ! current_user_can( 'edit_post', $post->ID ) ) {
  1286 		return;
  1359 		return;
       
  1360 	}
  1287 
  1361 
  1288 	if ( $post_type_object->_edit_link ) {
  1362 	if ( $post_type_object->_edit_link ) {
  1289 		$link = admin_url( sprintf( $post_type_object->_edit_link . $action, $post->ID ) );
  1363 		$link = admin_url( sprintf( $post_type_object->_edit_link . $action, $post->ID ) );
  1290 	} else {
  1364 	} else {
  1291 		$link = '';
  1365 		$link = '';
  1354  * @param string      $deprecated   Not used.
  1428  * @param string      $deprecated   Not used.
  1355  * @param bool        $force_delete Optional. Whether to bypass trash and force deletion. Default false.
  1429  * @param bool        $force_delete Optional. Whether to bypass trash and force deletion. Default false.
  1356  * @return string|void The delete post link URL for the given post.
  1430  * @return string|void The delete post link URL for the given post.
  1357  */
  1431  */
  1358 function get_delete_post_link( $id = 0, $deprecated = '', $force_delete = false ) {
  1432 function get_delete_post_link( $id = 0, $deprecated = '', $force_delete = false ) {
  1359 	if ( ! empty( $deprecated ) )
  1433 	if ( ! empty( $deprecated ) ) {
  1360 		_deprecated_argument( __FUNCTION__, '3.0.0' );
  1434 		_deprecated_argument( __FUNCTION__, '3.0.0' );
  1361 
  1435 	}
  1362 	if ( !$post = get_post( $id ) )
  1436 
       
  1437 	if ( ! $post = get_post( $id ) ) {
  1363 		return;
  1438 		return;
       
  1439 	}
  1364 
  1440 
  1365 	$post_type_object = get_post_type_object( $post->post_type );
  1441 	$post_type_object = get_post_type_object( $post->post_type );
  1366 	if ( !$post_type_object )
  1442 	if ( ! $post_type_object ) {
  1367 		return;
  1443 		return;
  1368 
  1444 	}
  1369 	if ( !current_user_can( 'delete_post', $post->ID ) )
  1445 
       
  1446 	if ( ! current_user_can( 'delete_post', $post->ID ) ) {
  1370 		return;
  1447 		return;
  1371 
  1448 	}
  1372 	$action = ( $force_delete || !EMPTY_TRASH_DAYS ) ? 'delete' : 'trash';
  1449 
       
  1450 	$action = ( $force_delete || ! EMPTY_TRASH_DAYS ) ? 'delete' : 'trash';
  1373 
  1451 
  1374 	$delete_link = add_query_arg( 'action', $action, admin_url( sprintf( $post_type_object->_edit_link, $post->ID ) ) );
  1452 	$delete_link = add_query_arg( 'action', $action, admin_url( sprintf( $post_type_object->_edit_link, $post->ID ) ) );
  1375 
  1453 
  1376 	/**
  1454 	/**
  1377 	 * Filters the post delete link.
  1455 	 * Filters the post delete link.
  1394  * @return string|void The edit comment link URL for the given comment.
  1472  * @return string|void The edit comment link URL for the given comment.
  1395  */
  1473  */
  1396 function get_edit_comment_link( $comment_id = 0 ) {
  1474 function get_edit_comment_link( $comment_id = 0 ) {
  1397 	$comment = get_comment( $comment_id );
  1475 	$comment = get_comment( $comment_id );
  1398 
  1476 
  1399 	if ( !current_user_can( 'edit_comment', $comment->comment_ID ) )
  1477 	if ( ! current_user_can( 'edit_comment', $comment->comment_ID ) ) {
  1400 		return;
  1478 		return;
  1401 
  1479 	}
  1402 	$location = admin_url('comment.php?action=editcomment&amp;c=') . $comment->comment_ID;
  1480 
       
  1481 	$location = admin_url( 'comment.php?action=editcomment&amp;c=' ) . $comment->comment_ID;
  1403 
  1482 
  1404 	/**
  1483 	/**
  1405 	 * Filters the comment edit link.
  1484 	 * Filters the comment edit link.
  1406 	 *
  1485 	 *
  1407 	 * @since 2.3.0
  1486 	 * @since 2.3.0
  1454  * @return string|void The edit bookmark link URL.
  1533  * @return string|void The edit bookmark link URL.
  1455  */
  1534  */
  1456 function get_edit_bookmark_link( $link = 0 ) {
  1535 function get_edit_bookmark_link( $link = 0 ) {
  1457 	$link = get_bookmark( $link );
  1536 	$link = get_bookmark( $link );
  1458 
  1537 
  1459 	if ( !current_user_can('manage_links') )
  1538 	if ( ! current_user_can( 'manage_links' ) ) {
  1460 		return;
  1539 		return;
  1461 
  1540 	}
  1462 	$location = admin_url('link.php?action=edit&amp;link_id=') . $link->link_id;
  1541 
       
  1542 	$location = admin_url( 'link.php?action=edit&amp;link_id=' ) . $link->link_id;
  1463 
  1543 
  1464 	/**
  1544 	/**
  1465 	 * Filters the bookmark edit link.
  1545 	 * Filters the bookmark edit link.
  1466 	 *
  1546 	 *
  1467 	 * @since 2.7.0
  1547 	 * @since 2.7.0
  1481  * @param string $before   Optional. Display before edit link. Default empty.
  1561  * @param string $before   Optional. Display before edit link. Default empty.
  1482  * @param string $after    Optional. Display after edit link. Default empty.
  1562  * @param string $after    Optional. Display after edit link. Default empty.
  1483  * @param int    $bookmark Optional. Bookmark ID. Default is the current bookmark.
  1563  * @param int    $bookmark Optional. Bookmark ID. Default is the current bookmark.
  1484  */
  1564  */
  1485 function edit_bookmark_link( $link = '', $before = '', $after = '', $bookmark = null ) {
  1565 function edit_bookmark_link( $link = '', $before = '', $after = '', $bookmark = null ) {
  1486 	$bookmark = get_bookmark($bookmark);
  1566 	$bookmark = get_bookmark( $bookmark );
  1487 
  1567 
  1488 	if ( !current_user_can('manage_links') )
  1568 	if ( ! current_user_can( 'manage_links' ) ) {
  1489 		return;
  1569 		return;
  1490 
  1570 	}
  1491 	if ( empty($link) )
  1571 
  1492 		$link = __('Edit This');
  1572 	if ( empty( $link ) ) {
       
  1573 		$link = __( 'Edit This' );
       
  1574 	}
  1493 
  1575 
  1494 	$link = '<a href="' . esc_url( get_edit_bookmark_link( $bookmark ) ) . '">' . $link . '</a>';
  1576 	$link = '<a href="' . esc_url( get_edit_bookmark_link( $bookmark ) ) . '">' . $link . '</a>';
  1495 
  1577 
  1496 	/**
  1578 	/**
  1497 	 * Filters the bookmark edit link anchor tag.
  1579 	 * Filters the bookmark edit link anchor tag.
  1511  *
  1593  *
  1512  * @param int $user_id Optional. User ID. Defaults to the current user.
  1594  * @param int $user_id Optional. User ID. Defaults to the current user.
  1513  * @return string URL to edit user page or empty string.
  1595  * @return string URL to edit user page or empty string.
  1514  */
  1596  */
  1515 function get_edit_user_link( $user_id = null ) {
  1597 function get_edit_user_link( $user_id = null ) {
  1516 	if ( ! $user_id )
  1598 	if ( ! $user_id ) {
  1517 		$user_id = get_current_user_id();
  1599 		$user_id = get_current_user_id();
  1518 
  1600 	}
  1519 	if ( empty( $user_id ) || ! current_user_can( 'edit_user', $user_id ) )
  1601 
       
  1602 	if ( empty( $user_id ) || ! current_user_can( 'edit_user', $user_id ) ) {
  1520 		return '';
  1603 		return '';
       
  1604 	}
  1521 
  1605 
  1522 	$user = get_userdata( $user_id );
  1606 	$user = get_userdata( $user_id );
  1523 
  1607 
  1524 	if ( ! $user )
  1608 	if ( ! $user ) {
  1525 		return '';
  1609 		return '';
  1526 
  1610 	}
  1527 	if ( get_current_user_id() == $user->ID )
  1611 
       
  1612 	if ( get_current_user_id() == $user->ID ) {
  1528 		$link = get_edit_profile_url( $user->ID );
  1613 		$link = get_edit_profile_url( $user->ID );
  1529 	else
  1614 	} else {
  1530 		$link = add_query_arg( 'user_id', $user->ID, self_admin_url( 'user-edit.php' ) );
  1615 		$link = add_query_arg( 'user_id', $user->ID, self_admin_url( 'user-edit.php' ) );
       
  1616 	}
  1531 
  1617 
  1532 	/**
  1618 	/**
  1533 	 * Filters the user edit link.
  1619 	 * Filters the user edit link.
  1534 	 *
  1620 	 *
  1535 	 * @since 3.5.0
  1621 	 * @since 3.5.0
  1589  *                             corresponding post exists.
  1675  *                             corresponding post exists.
  1590  */
  1676  */
  1591 function get_adjacent_post( $in_same_term = false, $excluded_terms = '', $previous = true, $taxonomy = 'category' ) {
  1677 function get_adjacent_post( $in_same_term = false, $excluded_terms = '', $previous = true, $taxonomy = 'category' ) {
  1592 	global $wpdb;
  1678 	global $wpdb;
  1593 
  1679 
  1594 	if ( ( ! $post = get_post() ) || ! taxonomy_exists( $taxonomy ) )
  1680 	if ( ( ! $post = get_post() ) || ! taxonomy_exists( $taxonomy ) ) {
  1595 		return null;
  1681 		return null;
       
  1682 	}
  1596 
  1683 
  1597 	$current_post_date = $post->post_date;
  1684 	$current_post_date = $post->post_date;
  1598 
  1685 
  1599 	$join = '';
  1686 	$join     = '';
  1600 	$where = '';
  1687 	$where    = '';
  1601 	$adjacent = $previous ? 'previous' : 'next';
  1688 	$adjacent = $previous ? 'previous' : 'next';
  1602 
  1689 
       
  1690 	if ( ! empty( $excluded_terms ) && ! is_array( $excluded_terms ) ) {
       
  1691 		// Back-compat, $excluded_terms used to be $excluded_categories with IDs separated by " and ".
       
  1692 		if ( false !== strpos( $excluded_terms, ' and ' ) ) {
       
  1693 			_deprecated_argument( __FUNCTION__, '3.3.0', sprintf( __( 'Use commas instead of %s to separate excluded terms.' ), "'and'" ) );
       
  1694 			$excluded_terms = explode( ' and ', $excluded_terms );
       
  1695 		} else {
       
  1696 			$excluded_terms = explode( ',', $excluded_terms );
       
  1697 		}
       
  1698 
       
  1699 		$excluded_terms = array_map( 'intval', $excluded_terms );
       
  1700 	}
       
  1701 
       
  1702 	/**
       
  1703 	 * Filters the IDs of terms excluded from adjacent post queries.
       
  1704 	 *
       
  1705 	 * The dynamic portion of the hook name, `$adjacent`, refers to the type
       
  1706 	 * of adjacency, 'next' or 'previous'.
       
  1707 	 *
       
  1708 	 * @since 4.4.0
       
  1709 	 *
       
  1710 	 * @param array $excluded_terms Array of excluded term IDs.
       
  1711 	 */
       
  1712 	$excluded_terms = apply_filters( "get_{$adjacent}_post_excluded_terms", $excluded_terms );
       
  1713 
  1603 	if ( $in_same_term || ! empty( $excluded_terms ) ) {
  1714 	if ( $in_same_term || ! empty( $excluded_terms ) ) {
  1604 		if ( ! empty( $excluded_terms ) && ! is_array( $excluded_terms ) ) {
  1715 		if ( $in_same_term ) {
  1605 			// back-compat, $excluded_terms used to be $excluded_terms with IDs separated by " and "
  1716 			$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";
  1606 			if ( false !== strpos( $excluded_terms, ' and ' ) ) {
  1717 			$where .= $wpdb->prepare( 'AND tt.taxonomy = %s', $taxonomy );
  1607 				_deprecated_argument( __FUNCTION__, '3.3.0', sprintf( __( 'Use commas instead of %s to separate excluded terms.' ), "'and'" ) );
  1718 
  1608 				$excluded_terms = explode( ' and ', $excluded_terms );
  1719 			if ( ! is_object_in_taxonomy( $post->post_type, $taxonomy ) ) {
  1609 			} else {
  1720 				return '';
  1610 				$excluded_terms = explode( ',', $excluded_terms );
       
  1611 			}
  1721 			}
  1612 
       
  1613 			$excluded_terms = array_map( 'intval', $excluded_terms );
       
  1614 		}
       
  1615 
       
  1616 		if ( $in_same_term ) {
       
  1617 			$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";
       
  1618 			$where .= $wpdb->prepare( "AND tt.taxonomy = %s", $taxonomy );
       
  1619 
       
  1620 			if ( ! is_object_in_taxonomy( $post->post_type, $taxonomy ) )
       
  1621 				return '';
       
  1622 			$term_array = wp_get_object_terms( $post->ID, $taxonomy, array( 'fields' => 'ids' ) );
  1722 			$term_array = wp_get_object_terms( $post->ID, $taxonomy, array( 'fields' => 'ids' ) );
  1623 
  1723 
  1624 			// Remove any exclusions from the term array to include.
  1724 			// Remove any exclusions from the term array to include.
  1625 			$term_array = array_diff( $term_array, (array) $excluded_terms );
  1725 			$term_array = array_diff( $term_array, (array) $excluded_terms );
  1626 			$term_array = array_map( 'intval', $term_array );
  1726 			$term_array = array_map( 'intval', $term_array );
  1627 
  1727 
  1628 			if ( ! $term_array || is_wp_error( $term_array ) )
  1728 			if ( ! $term_array || is_wp_error( $term_array ) ) {
  1629 				return '';
  1729 				return '';
  1630 
  1730 			}
  1631 			$where .= " AND tt.term_id IN (" . implode( ',', $term_array ) . ")";
  1731 
  1632 		}
  1732 			$where .= ' AND tt.term_id IN (' . implode( ',', $term_array ) . ')';
  1633 
  1733 		}
  1634 		/**
       
  1635 		 * Filters the IDs of terms excluded from adjacent post queries.
       
  1636 		 *
       
  1637 		 * The dynamic portion of the hook name, `$adjacent`, refers to the type
       
  1638 		 * of adjacency, 'next' or 'previous'.
       
  1639 		 *
       
  1640 		 * @since 4.4.0
       
  1641 		 *
       
  1642 		 * @param string $excluded_terms Array of excluded term IDs.
       
  1643 		 */
       
  1644 		$excluded_terms = apply_filters( "get_{$adjacent}_post_excluded_terms", $excluded_terms );
       
  1645 
  1734 
  1646 		if ( ! empty( $excluded_terms ) ) {
  1735 		if ( ! empty( $excluded_terms ) ) {
  1647 			$where .= " AND p.ID NOT IN ( SELECT tr.object_id FROM $wpdb->term_relationships tr LEFT JOIN $wpdb->term_taxonomy tt ON (tr.term_taxonomy_id = tt.term_taxonomy_id) WHERE tt.term_id IN (" . implode( ',', array_map( 'intval', $excluded_terms ) ) . ') )';
  1736 			$where .= " AND p.ID NOT IN ( SELECT tr.object_id FROM $wpdb->term_relationships tr LEFT JOIN $wpdb->term_taxonomy tt ON (tr.term_taxonomy_id = tt.term_taxonomy_id) WHERE tt.term_id IN (" . implode( ',', array_map( 'intval', $excluded_terms ) ) . ') )';
  1648 		}
  1737 		}
  1649 	}
  1738 	}
  1663 		/*
  1752 		/*
  1664 		 * Results should include private posts belonging to the current user, or private posts where the
  1753 		 * Results should include private posts belonging to the current user, or private posts where the
  1665 		 * current user has the 'read_private_posts' cap.
  1754 		 * current user has the 'read_private_posts' cap.
  1666 		 */
  1755 		 */
  1667 		$private_states = get_post_stati( array( 'private' => true ) );
  1756 		$private_states = get_post_stati( array( 'private' => true ) );
  1668 		$where .= " AND ( p.post_status = 'publish'";
  1757 		$where         .= " AND ( p.post_status = 'publish'";
  1669 		foreach ( (array) $private_states as $state ) {
  1758 		foreach ( (array) $private_states as $state ) {
  1670 			if ( current_user_can( $read_private_cap ) ) {
  1759 			if ( current_user_can( $read_private_cap ) ) {
  1671 				$where .= $wpdb->prepare( " OR p.post_status = %s", $state );
  1760 				$where .= $wpdb->prepare( ' OR p.post_status = %s', $state );
  1672 			} else {
  1761 			} else {
  1673 				$where .= $wpdb->prepare( " OR (p.post_author = %d AND p.post_status = %s)", $user_id, $state );
  1762 				$where .= $wpdb->prepare( ' OR (p.post_author = %d AND p.post_status = %s)', $user_id, $state );
  1674 			}
  1763 			}
  1675 		}
  1764 		}
  1676 		$where .= " )";
  1765 		$where .= ' )';
  1677 	} else {
  1766 	} else {
  1678 		$where .= " AND p.post_status = 'publish'";
  1767 		$where .= " AND p.post_status = 'publish'";
  1679 	}
  1768 	}
  1680 
  1769 
  1681 	$op = $previous ? '<' : '>';
  1770 	$op    = $previous ? '<' : '>';
  1682 	$order = $previous ? 'DESC' : 'ASC';
  1771 	$order = $previous ? 'DESC' : 'ASC';
  1683 
  1772 
  1684 	/**
  1773 	/**
  1685 	 * Filters the JOIN clause in the SQL for an adjacent post query.
  1774 	 * Filters the JOIN clause in the SQL for an adjacent post query.
  1686 	 *
  1775 	 *
  1727 	 *
  1816 	 *
  1728 	 * @param string $order_by The `ORDER BY` clause in the SQL.
  1817 	 * @param string $order_by The `ORDER BY` clause in the SQL.
  1729 	 * @param WP_Post $post    WP_Post object.
  1818 	 * @param WP_Post $post    WP_Post object.
  1730 	 * @param string  $order   Sort order. 'DESC' for previous post, 'ASC' for next.
  1819 	 * @param string  $order   Sort order. 'DESC' for previous post, 'ASC' for next.
  1731 	 */
  1820 	 */
  1732 	$sort  = apply_filters( "get_{$adjacent}_post_sort", "ORDER BY p.post_date $order LIMIT 1", $post, $order );
  1821 	$sort = apply_filters( "get_{$adjacent}_post_sort", "ORDER BY p.post_date $order LIMIT 1", $post, $order );
  1733 
  1822 
  1734 	$query = "SELECT p.ID FROM $wpdb->posts AS p $join $where $sort";
  1823 	$query     = "SELECT p.ID FROM $wpdb->posts AS p $join $where $sort";
  1735 	$query_key = 'adjacent_post_' . md5( $query );
  1824 	$query_key = 'adjacent_post_' . md5( $query );
  1736 	$result = wp_cache_get( $query_key, 'counts' );
  1825 	$result    = wp_cache_get( $query_key, 'counts' );
  1737 	if ( false !== $result ) {
  1826 	if ( false !== $result ) {
  1738 		if ( $result )
  1827 		if ( $result ) {
  1739 			$result = get_post( $result );
  1828 			$result = get_post( $result );
       
  1829 		}
  1740 		return $result;
  1830 		return $result;
  1741 	}
  1831 	}
  1742 
  1832 
  1743 	$result = $wpdb->get_var( $query );
  1833 	$result = $wpdb->get_var( $query );
  1744 	if ( null === $result )
  1834 	if ( null === $result ) {
  1745 		$result = '';
  1835 		$result = '';
       
  1836 	}
  1746 
  1837 
  1747 	wp_cache_set( $query_key, $result, 'counts' );
  1838 	wp_cache_set( $query_key, $result, 'counts' );
  1748 
  1839 
  1749 	if ( $result )
  1840 	if ( $result ) {
  1750 		$result = get_post( $result );
  1841 		$result = get_post( $result );
       
  1842 	}
  1751 
  1843 
  1752 	return $result;
  1844 	return $result;
  1753 }
  1845 }
  1754 
  1846 
  1755 /**
  1847 /**
  1765  * @param bool         $previous       Optional. Whether to display link to previous or next post. Default true.
  1857  * @param bool         $previous       Optional. Whether to display link to previous or next post. Default true.
  1766  * @param string       $taxonomy       Optional. Taxonomy, if $in_same_term is true. Default 'category'.
  1858  * @param string       $taxonomy       Optional. Taxonomy, if $in_same_term is true. Default 'category'.
  1767  * @return string|void The adjacent post relational link URL.
  1859  * @return string|void The adjacent post relational link URL.
  1768  */
  1860  */
  1769 function get_adjacent_post_rel_link( $title = '%title', $in_same_term = false, $excluded_terms = '', $previous = true, $taxonomy = 'category' ) {
  1861 function get_adjacent_post_rel_link( $title = '%title', $in_same_term = false, $excluded_terms = '', $previous = true, $taxonomy = 'category' ) {
  1770 	if ( $previous && is_attachment() && $post = get_post() )
  1862 	if ( $previous && is_attachment() && $post = get_post() ) {
  1771 		$post = get_post( $post->post_parent );
  1863 		$post = get_post( $post->post_parent );
  1772 	else
  1864 	} else {
  1773 		$post = get_adjacent_post( $in_same_term, $excluded_terms, $previous, $taxonomy );
  1865 		$post = get_adjacent_post( $in_same_term, $excluded_terms, $previous, $taxonomy );
  1774 
  1866 	}
  1775 	if ( empty( $post ) )
  1867 
       
  1868 	if ( empty( $post ) ) {
  1776 		return;
  1869 		return;
  1777 
  1870 	}
  1778 	$post_title = the_title_attribute( array( 'echo' => false, 'post' => $post ) );
  1871 
  1779 
  1872 	$post_title = the_title_attribute(
  1780 	if ( empty( $post_title ) )
  1873 		array(
       
  1874 			'echo' => false,
       
  1875 			'post' => $post,
       
  1876 		)
       
  1877 	);
       
  1878 
       
  1879 	if ( empty( $post_title ) ) {
  1781 		$post_title = $previous ? __( 'Previous Post' ) : __( 'Next Post' );
  1880 		$post_title = $previous ? __( 'Previous Post' ) : __( 'Next Post' );
       
  1881 	}
  1782 
  1882 
  1783 	$date = mysql2date( get_option( 'date_format' ), $post->post_date );
  1883 	$date = mysql2date( get_option( 'date_format' ), $post->post_date );
  1784 
  1884 
  1785 	$title = str_replace( '%title', $post_title, $title );
  1885 	$title = str_replace( '%title', $post_title, $title );
  1786 	$title = str_replace( '%date', $date, $title );
  1886 	$title = str_replace( '%date', $date, $title );
  1787 
  1887 
  1788 	$link = $previous ? "<link rel='prev' title='" : "<link rel='next' title='";
  1888 	$link  = $previous ? "<link rel='prev' title='" : "<link rel='next' title='";
  1789 	$link .= esc_attr( $title );
  1889 	$link .= esc_attr( $title );
  1790 	$link .= "' href='" . get_permalink( $post ) . "' />\n";
  1890 	$link .= "' href='" . get_permalink( $post ) . "' />\n";
  1791 
  1891 
  1792 	$adjacent = $previous ? 'previous' : 'next';
  1892 	$adjacent = $previous ? 'previous' : 'next';
  1793 
  1893 
  1884  * @param string       $taxonomy       Optional. Taxonomy, if $in_same_term is true. Default 'category'.
  1984  * @param string       $taxonomy       Optional. Taxonomy, if $in_same_term is true. Default 'category'.
  1885  * @return null|array Array containing the boundary post object if successful, null otherwise.
  1985  * @return null|array Array containing the boundary post object if successful, null otherwise.
  1886  */
  1986  */
  1887 function get_boundary_post( $in_same_term = false, $excluded_terms = '', $start = true, $taxonomy = 'category' ) {
  1987 function get_boundary_post( $in_same_term = false, $excluded_terms = '', $start = true, $taxonomy = 'category' ) {
  1888 	$post = get_post();
  1988 	$post = get_post();
  1889 	if ( ! $post || ! is_single() || is_attachment() || ! taxonomy_exists( $taxonomy ) )
  1989 	if ( ! $post || ! is_single() || is_attachment() || ! taxonomy_exists( $taxonomy ) ) {
  1890 		return null;
  1990 		return null;
       
  1991 	}
  1891 
  1992 
  1892 	$query_args = array(
  1993 	$query_args = array(
  1893 		'posts_per_page' => 1,
  1994 		'posts_per_page'         => 1,
  1894 		'order' => $start ? 'ASC' : 'DESC',
  1995 		'order'                  => $start ? 'ASC' : 'DESC',
  1895 		'update_post_term_cache' => false,
  1996 		'update_post_term_cache' => false,
  1896 		'update_post_meta_cache' => false
  1997 		'update_post_meta_cache' => false,
  1897 	);
  1998 	);
  1898 
  1999 
  1899 	$term_array = array();
  2000 	$term_array = array();
  1900 
  2001 
  1901 	if ( ! is_array( $excluded_terms ) ) {
  2002 	if ( ! is_array( $excluded_terms ) ) {
  1902 		if ( ! empty( $excluded_terms ) )
  2003 		if ( ! empty( $excluded_terms ) ) {
  1903 			$excluded_terms = explode( ',', $excluded_terms );
  2004 			$excluded_terms = explode( ',', $excluded_terms );
  1904 		else
  2005 		} else {
  1905 			$excluded_terms = array();
  2006 			$excluded_terms = array();
       
  2007 		}
  1906 	}
  2008 	}
  1907 
  2009 
  1908 	if ( $in_same_term || ! empty( $excluded_terms ) ) {
  2010 	if ( $in_same_term || ! empty( $excluded_terms ) ) {
  1909 		if ( $in_same_term )
  2011 		if ( $in_same_term ) {
  1910 			$term_array = wp_get_object_terms( $post->ID, $taxonomy, array( 'fields' => 'ids' ) );
  2012 			$term_array = wp_get_object_terms( $post->ID, $taxonomy, array( 'fields' => 'ids' ) );
       
  2013 		}
  1911 
  2014 
  1912 		if ( ! empty( $excluded_terms ) ) {
  2015 		if ( ! empty( $excluded_terms ) ) {
  1913 			$excluded_terms = array_map( 'intval', $excluded_terms );
  2016 			$excluded_terms = array_map( 'intval', $excluded_terms );
  1914 			$excluded_terms = array_diff( $excluded_terms, $term_array );
  2017 			$excluded_terms = array_diff( $excluded_terms, $term_array );
  1915 
  2018 
  1916 			$inverse_terms = array();
  2019 			$inverse_terms = array();
  1917 			foreach ( $excluded_terms as $excluded_term )
  2020 			foreach ( $excluded_terms as $excluded_term ) {
  1918 				$inverse_terms[] = $excluded_term * -1;
  2021 				$inverse_terms[] = $excluded_term * -1;
       
  2022 			}
  1919 			$excluded_terms = $inverse_terms;
  2023 			$excluded_terms = $inverse_terms;
  1920 		}
  2024 		}
  1921 
  2025 
  1922 		$query_args[ 'tax_query' ] = array( array(
  2026 		$query_args['tax_query'] = array(
  1923 			'taxonomy' => $taxonomy,
  2027 			array(
  1924 			'terms' => array_merge( $term_array, $excluded_terms )
  2028 				'taxonomy' => $taxonomy,
  1925 		) );
  2029 				'terms'    => array_merge( $term_array, $excluded_terms ),
       
  2030 			),
       
  2031 		);
  1926 	}
  2032 	}
  1927 
  2033 
  1928 	return get_posts( $query_args );
  2034 	return get_posts( $query_args );
  1929 }
  2035 }
  1930 
  2036 
  1988  * @param bool         $in_same_term   Optional. Whether link should be in a same taxonomy term. Default false.
  2094  * @param bool         $in_same_term   Optional. Whether link should be in a same taxonomy term. Default false.
  1989  * @param array|string $excluded_terms Optional. Array or comma-separated list of excluded term IDs. Default empty.
  2095  * @param array|string $excluded_terms Optional. Array or comma-separated list of excluded term IDs. Default empty.
  1990  * @param string       $taxonomy       Optional. Taxonomy, if $in_same_term is true. Default 'category'.
  2096  * @param string       $taxonomy       Optional. Taxonomy, if $in_same_term is true. Default 'category'.
  1991  */
  2097  */
  1992 function next_post_link( $format = '%link &raquo;', $link = '%title', $in_same_term = false, $excluded_terms = '', $taxonomy = 'category' ) {
  2098 function next_post_link( $format = '%link &raquo;', $link = '%title', $in_same_term = false, $excluded_terms = '', $taxonomy = 'category' ) {
  1993 	 echo get_next_post_link( $format, $link, $in_same_term, $excluded_terms, $taxonomy );
  2099 	echo get_next_post_link( $format, $link, $in_same_term, $excluded_terms, $taxonomy );
  1994 }
  2100 }
  1995 
  2101 
  1996 /**
  2102 /**
  1997  * Retrieves the adjacent post link.
  2103  * Retrieves the adjacent post link.
  1998  *
  2104  *
  2007  * @param bool         $previous       Optional. Whether to display link to previous or next post. Default true.
  2113  * @param bool         $previous       Optional. Whether to display link to previous or next post. Default true.
  2008  * @param string       $taxonomy       Optional. Taxonomy, if $in_same_term is true. Default 'category'.
  2114  * @param string       $taxonomy       Optional. Taxonomy, if $in_same_term is true. Default 'category'.
  2009  * @return string The link URL of the previous or next post in relation to the current post.
  2115  * @return string The link URL of the previous or next post in relation to the current post.
  2010  */
  2116  */
  2011 function get_adjacent_post_link( $format, $link, $in_same_term = false, $excluded_terms = '', $previous = true, $taxonomy = 'category' ) {
  2117 function get_adjacent_post_link( $format, $link, $in_same_term = false, $excluded_terms = '', $previous = true, $taxonomy = 'category' ) {
  2012 	if ( $previous && is_attachment() )
  2118 	if ( $previous && is_attachment() ) {
  2013 		$post = get_post( get_post()->post_parent );
  2119 		$post = get_post( get_post()->post_parent );
  2014 	else
  2120 	} else {
  2015 		$post = get_adjacent_post( $in_same_term, $excluded_terms, $previous, $taxonomy );
  2121 		$post = get_adjacent_post( $in_same_term, $excluded_terms, $previous, $taxonomy );
       
  2122 	}
  2016 
  2123 
  2017 	if ( ! $post ) {
  2124 	if ( ! $post ) {
  2018 		$output = '';
  2125 		$output = '';
  2019 	} else {
  2126 	} else {
  2020 		$title = $post->post_title;
  2127 		$title = $post->post_title;
  2021 
  2128 
  2022 		if ( empty( $post->post_title ) )
  2129 		if ( empty( $post->post_title ) ) {
  2023 			$title = $previous ? __( 'Previous Post' ) : __( 'Next Post' );
  2130 			$title = $previous ? __( 'Previous Post' ) : __( 'Next Post' );
       
  2131 		}
  2024 
  2132 
  2025 		/** This filter is documented in wp-includes/post-template.php */
  2133 		/** This filter is documented in wp-includes/post-template.php */
  2026 		$title = apply_filters( 'the_title', $title, $post->ID );
  2134 		$title = apply_filters( 'the_title', $title, $post->ID );
  2027 
  2135 
  2028 		$date = mysql2date( get_option( 'date_format' ), $post->post_date );
  2136 		$date = mysql2date( get_option( 'date_format' ), $post->post_date );
  2029 		$rel = $previous ? 'prev' : 'next';
  2137 		$rel  = $previous ? 'prev' : 'next';
  2030 
  2138 
  2031 		$string = '<a href="' . get_permalink( $post ) . '" rel="'.$rel.'">';
  2139 		$string = '<a href="' . get_permalink( $post ) . '" rel="' . $rel . '">';
  2032 		$inlink = str_replace( '%title', $title, $link );
  2140 		$inlink = str_replace( '%title', $title, $link );
  2033 		$inlink = str_replace( '%date', $date, $inlink );
  2141 		$inlink = str_replace( '%date', $date, $inlink );
  2034 		$inlink = $string . $inlink . '</a>';
  2142 		$inlink = $string . $inlink . '</a>';
  2035 
  2143 
  2036 		$output = str_replace( '%link', $inlink, $format );
  2144 		$output = str_replace( '%link', $inlink, $format );
  2079  *
  2187  *
  2080  * @since 1.5.0
  2188  * @since 1.5.0
  2081  *
  2189  *
  2082  * @global WP_Rewrite $wp_rewrite
  2190  * @global WP_Rewrite $wp_rewrite
  2083  *
  2191  *
  2084  * @param int  $pagenum Optional. Page ID. Default 1.
  2192  * @param int  $pagenum Optional. Page number. Default 1.
  2085  * @param bool $escape  Optional. Whether to escape the URL for display, with esc_url(). Defaults to true.
  2193  * @param bool $escape  Optional. Whether to escape the URL for display, with esc_url(). Defaults to true.
  2086  * 	                    Otherwise, prepares the URL with esc_url_raw().
  2194  *                      Otherwise, prepares the URL with esc_url_raw().
  2087  * @return string The link URL for the given page number.
  2195  * @return string The link URL for the given page number.
  2088  */
  2196  */
  2089 function get_pagenum_link($pagenum = 1, $escape = true ) {
  2197 function get_pagenum_link( $pagenum = 1, $escape = true ) {
  2090 	global $wp_rewrite;
  2198 	global $wp_rewrite;
  2091 
  2199 
  2092 	$pagenum = (int) $pagenum;
  2200 	$pagenum = (int) $pagenum;
  2093 
  2201 
  2094 	$request = remove_query_arg( 'paged' );
  2202 	$request = remove_query_arg( 'paged' );
  2095 
  2203 
  2096 	$home_root = parse_url(home_url());
  2204 	$home_root = parse_url( home_url() );
  2097 	$home_root = ( isset($home_root['path']) ) ? $home_root['path'] : '';
  2205 	$home_root = ( isset( $home_root['path'] ) ) ? $home_root['path'] : '';
  2098 	$home_root = preg_quote( $home_root, '|' );
  2206 	$home_root = preg_quote( $home_root, '|' );
  2099 
  2207 
  2100 	$request = preg_replace('|^'. $home_root . '|i', '', $request);
  2208 	$request = preg_replace( '|^' . $home_root . '|i', '', $request );
  2101 	$request = preg_replace('|^/+|', '', $request);
  2209 	$request = preg_replace( '|^/+|', '', $request );
  2102 
  2210 
  2103 	if ( !$wp_rewrite->using_permalinks() || is_admin() ) {
  2211 	if ( ! $wp_rewrite->using_permalinks() || is_admin() ) {
  2104 		$base = trailingslashit( get_bloginfo( 'url' ) );
  2212 		$base = trailingslashit( get_bloginfo( 'url' ) );
  2105 
  2213 
  2106 		if ( $pagenum > 1 ) {
  2214 		if ( $pagenum > 1 ) {
  2107 			$result = add_query_arg( 'paged', $pagenum, $base . $request );
  2215 			$result = add_query_arg( 'paged', $pagenum, $base . $request );
  2108 		} else {
  2216 		} else {
  2110 		}
  2218 		}
  2111 	} else {
  2219 	} else {
  2112 		$qs_regex = '|\?.*?$|';
  2220 		$qs_regex = '|\?.*?$|';
  2113 		preg_match( $qs_regex, $request, $qs_match );
  2221 		preg_match( $qs_regex, $request, $qs_match );
  2114 
  2222 
  2115 		if ( !empty( $qs_match[0] ) ) {
  2223 		if ( ! empty( $qs_match[0] ) ) {
  2116 			$query_string = $qs_match[0];
  2224 			$query_string = $qs_match[0];
  2117 			$request = preg_replace( $qs_regex, '', $request );
  2225 			$request      = preg_replace( $qs_regex, '', $request );
  2118 		} else {
  2226 		} else {
  2119 			$query_string = '';
  2227 			$query_string = '';
  2120 		}
  2228 		}
  2121 
  2229 
  2122 		$request = preg_replace( "|$wp_rewrite->pagination_base/\d+/?$|", '', $request);
  2230 		$request = preg_replace( "|$wp_rewrite->pagination_base/\d+/?$|", '', $request );
  2123 		$request = preg_replace( '|^' . preg_quote( $wp_rewrite->index, '|' ) . '|i', '', $request);
  2231 		$request = preg_replace( '|^' . preg_quote( $wp_rewrite->index, '|' ) . '|i', '', $request );
  2124 		$request = ltrim($request, '/');
  2232 		$request = ltrim( $request, '/' );
  2125 
  2233 
  2126 		$base = trailingslashit( get_bloginfo( 'url' ) );
  2234 		$base = trailingslashit( get_bloginfo( 'url' ) );
  2127 
  2235 
  2128 		if ( $wp_rewrite->using_index_permalinks() && ( $pagenum > 1 || '' != $request ) )
  2236 		if ( $wp_rewrite->using_index_permalinks() && ( $pagenum > 1 || '' != $request ) ) {
  2129 			$base .= $wp_rewrite->index . '/';
  2237 			$base .= $wp_rewrite->index . '/';
       
  2238 		}
  2130 
  2239 
  2131 		if ( $pagenum > 1 ) {
  2240 		if ( $pagenum > 1 ) {
  2132 			$request = ( ( !empty( $request ) ) ? trailingslashit( $request ) : $request ) . user_trailingslashit( $wp_rewrite->pagination_base . "/" . $pagenum, 'paged' );
  2241 			$request = ( ( ! empty( $request ) ) ? trailingslashit( $request ) : $request ) . user_trailingslashit( $wp_rewrite->pagination_base . '/' . $pagenum, 'paged' );
  2133 		}
  2242 		}
  2134 
  2243 
  2135 		$result = $base . $request . $query_string;
  2244 		$result = $base . $request . $query_string;
  2136 	}
  2245 	}
  2137 
  2246 
  2138 	/**
  2247 	/**
  2139 	 * Filters the page number link for the current request.
  2248 	 * Filters the page number link for the current request.
  2140 	 *
  2249 	 *
  2141 	 * @since 2.5.0
  2250 	 * @since 2.5.0
  2142 	 *
  2251 	 * @since 5.2.0 Added the `$pagenum` argument.
  2143 	 * @param string $result The page number link.
  2252 	 *
  2144 	 */
  2253 	 * @param string $result  The page number link.
  2145 	$result = apply_filters( 'get_pagenum_link', $result );
  2254 	 * @param int    $pagenum The page number.
  2146 
  2255 	 */
  2147 	if ( $escape )
  2256 	$result = apply_filters( 'get_pagenum_link', $result, $pagenum );
       
  2257 
       
  2258 	if ( $escape ) {
  2148 		return esc_url( $result );
  2259 		return esc_url( $result );
  2149 	else
  2260 	} else {
  2150 		return esc_url_raw( $result );
  2261 		return esc_url_raw( $result );
       
  2262 	}
  2151 }
  2263 }
  2152 
  2264 
  2153 /**
  2265 /**
  2154  * Retrieves the next posts page link.
  2266  * Retrieves the next posts page link.
  2155  *
  2267  *
  2160  * @global int $paged
  2272  * @global int $paged
  2161  *
  2273  *
  2162  * @param int $max_page Optional. Max pages. Default 0.
  2274  * @param int $max_page Optional. Max pages. Default 0.
  2163  * @return string|void The link URL for next posts page.
  2275  * @return string|void The link URL for next posts page.
  2164  */
  2276  */
  2165 function get_next_posts_page_link($max_page = 0) {
  2277 function get_next_posts_page_link( $max_page = 0 ) {
  2166 	global $paged;
  2278 	global $paged;
  2167 
  2279 
  2168 	if ( !is_single() ) {
  2280 	if ( ! is_single() ) {
  2169 		if ( !$paged )
  2281 		if ( ! $paged ) {
  2170 			$paged = 1;
  2282 			$paged = 1;
  2171 		$nextpage = intval($paged) + 1;
  2283 		}
  2172 		if ( !$max_page || $max_page >= $nextpage )
  2284 		$nextpage = intval( $paged ) + 1;
  2173 			return get_pagenum_link($nextpage);
  2285 		if ( ! $max_page || $max_page >= $nextpage ) {
       
  2286 			return get_pagenum_link( $nextpage );
       
  2287 		}
  2174 	}
  2288 	}
  2175 }
  2289 }
  2176 
  2290 
  2177 /**
  2291 /**
  2178  * Displays or retrieves the next posts page link.
  2292  * Displays or retrieves the next posts page link.
  2184  * @return string|void The link URL for next posts page if `$echo = false`.
  2298  * @return string|void The link URL for next posts page if `$echo = false`.
  2185  */
  2299  */
  2186 function next_posts( $max_page = 0, $echo = true ) {
  2300 function next_posts( $max_page = 0, $echo = true ) {
  2187 	$output = esc_url( get_next_posts_page_link( $max_page ) );
  2301 	$output = esc_url( get_next_posts_page_link( $max_page ) );
  2188 
  2302 
  2189 	if ( $echo )
  2303 	if ( $echo ) {
  2190 		echo $output;
  2304 		echo $output;
  2191 	else
  2305 	} else {
  2192 		return $output;
  2306 		return $output;
       
  2307 	}
  2193 }
  2308 }
  2194 
  2309 
  2195 /**
  2310 /**
  2196  * Retrieves the next posts page link.
  2311  * Retrieves the next posts page link.
  2197  *
  2312  *
  2205  * @return string|void HTML-formatted next posts page link.
  2320  * @return string|void HTML-formatted next posts page link.
  2206  */
  2321  */
  2207 function get_next_posts_link( $label = null, $max_page = 0 ) {
  2322 function get_next_posts_link( $label = null, $max_page = 0 ) {
  2208 	global $paged, $wp_query;
  2323 	global $paged, $wp_query;
  2209 
  2324 
  2210 	if ( !$max_page )
  2325 	if ( ! $max_page ) {
  2211 		$max_page = $wp_query->max_num_pages;
  2326 		$max_page = $wp_query->max_num_pages;
  2212 
  2327 	}
  2213 	if ( !$paged )
  2328 
       
  2329 	if ( ! $paged ) {
  2214 		$paged = 1;
  2330 		$paged = 1;
  2215 
  2331 	}
  2216 	$nextpage = intval($paged) + 1;
  2332 
  2217 
  2333 	$nextpage = intval( $paged ) + 1;
  2218 	if ( null === $label )
  2334 
       
  2335 	if ( null === $label ) {
  2219 		$label = __( 'Next Page &raquo;' );
  2336 		$label = __( 'Next Page &raquo;' );
  2220 
  2337 	}
  2221 	if ( !is_single() && ( $nextpage <= $max_page ) ) {
  2338 
       
  2339 	if ( ! is_single() && ( $nextpage <= $max_page ) ) {
  2222 		/**
  2340 		/**
  2223 		 * Filters the anchor tag attributes for the next posts page link.
  2341 		 * Filters the anchor tag attributes for the next posts page link.
  2224 		 *
  2342 		 *
  2225 		 * @since 2.7.0
  2343 		 * @since 2.7.0
  2226 		 *
  2344 		 *
  2227 		 * @param string $attributes Attributes for the anchor tag.
  2345 		 * @param string $attributes Attributes for the anchor tag.
  2228 		 */
  2346 		 */
  2229 		$attr = apply_filters( 'next_posts_link_attributes', '' );
  2347 		$attr = apply_filters( 'next_posts_link_attributes', '' );
  2230 
  2348 
  2231 		return '<a href="' . next_posts( $max_page, false ) . "\" $attr>" . preg_replace('/&([^#])(?![a-z]{1,8};)/i', '&#038;$1', $label) . '</a>';
  2349 		return '<a href="' . next_posts( $max_page, false ) . "\" $attr>" . preg_replace( '/&([^#])(?![a-z]{1,8};)/i', '&#038;$1', $label ) . '</a>';
  2232 	}
  2350 	}
  2233 }
  2351 }
  2234 
  2352 
  2235 /**
  2353 /**
  2236  * Displays the next posts page link.
  2354  * Displays the next posts page link.
  2258  * @return string|void The link for the previous posts page.
  2376  * @return string|void The link for the previous posts page.
  2259  */
  2377  */
  2260 function get_previous_posts_page_link() {
  2378 function get_previous_posts_page_link() {
  2261 	global $paged;
  2379 	global $paged;
  2262 
  2380 
  2263 	if ( !is_single() ) {
  2381 	if ( ! is_single() ) {
  2264 		$nextpage = intval($paged) - 1;
  2382 		$nextpage = intval( $paged ) - 1;
  2265 		if ( $nextpage < 1 )
  2383 		if ( $nextpage < 1 ) {
  2266 			$nextpage = 1;
  2384 			$nextpage = 1;
  2267 		return get_pagenum_link($nextpage);
  2385 		}
       
  2386 		return get_pagenum_link( $nextpage );
  2268 	}
  2387 	}
  2269 }
  2388 }
  2270 
  2389 
  2271 /**
  2390 /**
  2272  * Displays or retrieves the previous posts page link.
  2391  * Displays or retrieves the previous posts page link.
  2277  * @return string|void The previous posts page link if `$echo = false`.
  2396  * @return string|void The previous posts page link if `$echo = false`.
  2278  */
  2397  */
  2279 function previous_posts( $echo = true ) {
  2398 function previous_posts( $echo = true ) {
  2280 	$output = esc_url( get_previous_posts_page_link() );
  2399 	$output = esc_url( get_previous_posts_page_link() );
  2281 
  2400 
  2282 	if ( $echo )
  2401 	if ( $echo ) {
  2283 		echo $output;
  2402 		echo $output;
  2284 	else
  2403 	} else {
  2285 		return $output;
  2404 		return $output;
       
  2405 	}
  2286 }
  2406 }
  2287 
  2407 
  2288 /**
  2408 /**
  2289  * Retrieves the previous posts page link.
  2409  * Retrieves the previous posts page link.
  2290  *
  2410  *
  2296  * @return string|void HTML-formatted previous page link.
  2416  * @return string|void HTML-formatted previous page link.
  2297  */
  2417  */
  2298 function get_previous_posts_link( $label = null ) {
  2418 function get_previous_posts_link( $label = null ) {
  2299 	global $paged;
  2419 	global $paged;
  2300 
  2420 
  2301 	if ( null === $label )
  2421 	if ( null === $label ) {
  2302 		$label = __( '&laquo; Previous Page' );
  2422 		$label = __( '&laquo; Previous Page' );
  2303 
  2423 	}
  2304 	if ( !is_single() && $paged > 1 ) {
  2424 
       
  2425 	if ( ! is_single() && $paged > 1 ) {
  2305 		/**
  2426 		/**
  2306 		 * Filters the anchor tag attributes for the previous posts page link.
  2427 		 * Filters the anchor tag attributes for the previous posts page link.
  2307 		 *
  2428 		 *
  2308 		 * @since 2.7.0
  2429 		 * @since 2.7.0
  2309 		 *
  2430 		 *
  2310 		 * @param string $attributes Attributes for the anchor tag.
  2431 		 * @param string $attributes Attributes for the anchor tag.
  2311 		 */
  2432 		 */
  2312 		$attr = apply_filters( 'previous_posts_link_attributes', '' );
  2433 		$attr = apply_filters( 'previous_posts_link_attributes', '' );
  2313 		return '<a href="' . previous_posts( false ) . "\" $attr>". preg_replace( '/&([^#])(?![a-z]{1,8};)/i', '&#038;$1', $label ) .'</a>';
  2434 		return '<a href="' . previous_posts( false ) . "\" $attr>" . preg_replace( '/&([^#])(?![a-z]{1,8};)/i', '&#038;$1', $label ) . '</a>';
  2314 	}
  2435 	}
  2315 }
  2436 }
  2316 
  2437 
  2317 /**
  2438 /**
  2318  * Displays the previous posts page link.
  2439  * Displays the previous posts page link.
  2346 function get_posts_nav_link( $args = array() ) {
  2467 function get_posts_nav_link( $args = array() ) {
  2347 	global $wp_query;
  2468 	global $wp_query;
  2348 
  2469 
  2349 	$return = '';
  2470 	$return = '';
  2350 
  2471 
  2351 	if ( !is_singular() ) {
  2472 	if ( ! is_singular() ) {
  2352 		$defaults = array(
  2473 		$defaults = array(
  2353 			'sep' => ' &#8212; ',
  2474 			'sep'      => ' &#8212; ',
  2354 			'prelabel' => __('&laquo; Previous Page'),
  2475 			'prelabel' => __( '&laquo; Previous Page' ),
  2355 			'nxtlabel' => __('Next Page &raquo;'),
  2476 			'nxtlabel' => __( 'Next Page &raquo;' ),
  2356 		);
  2477 		);
  2357 		$args = wp_parse_args( $args, $defaults );
  2478 		$args     = wp_parse_args( $args, $defaults );
  2358 
  2479 
  2359 		$max_num_pages = $wp_query->max_num_pages;
  2480 		$max_num_pages = $wp_query->max_num_pages;
  2360 		$paged = get_query_var('paged');
  2481 		$paged         = get_query_var( 'paged' );
  2361 
  2482 
  2362 		//only have sep if there's both prev and next results
  2483 		//only have sep if there's both prev and next results
  2363 		if ($paged < 2 || $paged >= $max_num_pages) {
  2484 		if ( $paged < 2 || $paged >= $max_num_pages ) {
  2364 			$args['sep'] = '';
  2485 			$args['sep'] = '';
  2365 		}
  2486 		}
  2366 
  2487 
  2367 		if ( $max_num_pages > 1 ) {
  2488 		if ( $max_num_pages > 1 ) {
  2368 			$return = get_previous_posts_link($args['prelabel']);
  2489 			$return  = get_previous_posts_link( $args['prelabel'] );
  2369 			$return .= preg_replace('/&([^#])(?![a-z]{1,8};)/i', '&#038;$1', $args['sep']);
  2490 			$return .= preg_replace( '/&([^#])(?![a-z]{1,8};)/i', '&#038;$1', $args['sep'] );
  2370 			$return .= get_next_posts_link($args['nxtlabel']);
  2491 			$return .= get_next_posts_link( $args['nxtlabel'] );
  2371 		}
  2492 		}
  2372 	}
  2493 	}
  2373 	return $return;
  2494 	return $return;
  2374 
  2495 
  2375 }
  2496 }
  2382  * @param string $sep      Optional. Separator for posts navigation links. Default empty.
  2503  * @param string $sep      Optional. Separator for posts navigation links. Default empty.
  2383  * @param string $prelabel Optional. Label for previous pages. Default empty.
  2504  * @param string $prelabel Optional. Label for previous pages. Default empty.
  2384  * @param string $nxtlabel Optional Label for next pages. Default empty.
  2505  * @param string $nxtlabel Optional Label for next pages. Default empty.
  2385  */
  2506  */
  2386 function posts_nav_link( $sep = '', $prelabel = '', $nxtlabel = '' ) {
  2507 function posts_nav_link( $sep = '', $prelabel = '', $nxtlabel = '' ) {
  2387 	$args = array_filter( compact('sep', 'prelabel', 'nxtlabel') );
  2508 	$args = array_filter( compact( 'sep', 'prelabel', 'nxtlabel' ) );
  2388 	echo get_posts_nav_link($args);
  2509 	echo get_posts_nav_link( $args );
  2389 }
  2510 }
  2390 
  2511 
  2391 /**
  2512 /**
  2392  * Retrieves the navigation to next/previous post, when applicable.
  2513  * Retrieves the navigation to next/previous post, when applicable.
  2393  *
  2514  *
  2405  *     @type string       $screen_reader_text Screen reader text for nav element. Default 'Post navigation'.
  2526  *     @type string       $screen_reader_text Screen reader text for nav element. Default 'Post navigation'.
  2406  * }
  2527  * }
  2407  * @return string Markup for post links.
  2528  * @return string Markup for post links.
  2408  */
  2529  */
  2409 function get_the_post_navigation( $args = array() ) {
  2530 function get_the_post_navigation( $args = array() ) {
  2410 	$args = wp_parse_args( $args, array(
  2531 	$args = wp_parse_args(
  2411 		'prev_text'          => '%title',
  2532 		$args,
  2412 		'next_text'          => '%title',
  2533 		array(
  2413 		'in_same_term'       => false,
  2534 			'prev_text'          => '%title',
  2414 		'excluded_terms'     => '',
  2535 			'next_text'          => '%title',
  2415 		'taxonomy'           => 'category',
  2536 			'in_same_term'       => false,
  2416 		'screen_reader_text' => __( 'Post navigation' ),
  2537 			'excluded_terms'     => '',
  2417 	) );
  2538 			'taxonomy'           => 'category',
       
  2539 			'screen_reader_text' => __( 'Post navigation' ),
       
  2540 		)
       
  2541 	);
  2418 
  2542 
  2419 	$navigation = '';
  2543 	$navigation = '';
  2420 
  2544 
  2421 	$previous = get_previous_post_link(
  2545 	$previous = get_previous_post_link(
  2422 		'<div class="nav-previous">%link</div>',
  2546 		'<div class="nav-previous">%link</div>',
  2476 function get_the_posts_navigation( $args = array() ) {
  2600 function get_the_posts_navigation( $args = array() ) {
  2477 	$navigation = '';
  2601 	$navigation = '';
  2478 
  2602 
  2479 	// Don't print empty markup if there's only one page.
  2603 	// Don't print empty markup if there's only one page.
  2480 	if ( $GLOBALS['wp_query']->max_num_pages > 1 ) {
  2604 	if ( $GLOBALS['wp_query']->max_num_pages > 1 ) {
  2481 		$args = wp_parse_args( $args, array(
  2605 		$args = wp_parse_args(
  2482 			'prev_text'          => __( 'Older posts' ),
  2606 			$args,
  2483 			'next_text'          => __( 'Newer posts' ),
  2607 			array(
  2484 			'screen_reader_text' => __( 'Posts navigation' ),
  2608 				'prev_text'          => __( 'Older posts' ),
  2485 		) );
  2609 				'next_text'          => __( 'Newer posts' ),
       
  2610 				'screen_reader_text' => __( 'Posts navigation' ),
       
  2611 			)
       
  2612 		);
  2486 
  2613 
  2487 		$next_link = get_previous_posts_link( $args['next_text'] );
  2614 		$next_link = get_previous_posts_link( $args['next_text'] );
  2488 		$prev_link = get_next_posts_link( $args['prev_text'] );
  2615 		$prev_link = get_next_posts_link( $args['prev_text'] );
  2489 
  2616 
  2490 		if ( $prev_link ) {
  2617 		if ( $prev_link ) {
  2529 function get_the_posts_pagination( $args = array() ) {
  2656 function get_the_posts_pagination( $args = array() ) {
  2530 	$navigation = '';
  2657 	$navigation = '';
  2531 
  2658 
  2532 	// Don't print empty markup if there's only one page.
  2659 	// Don't print empty markup if there's only one page.
  2533 	if ( $GLOBALS['wp_query']->max_num_pages > 1 ) {
  2660 	if ( $GLOBALS['wp_query']->max_num_pages > 1 ) {
  2534 		$args = wp_parse_args( $args, array(
  2661 		$args = wp_parse_args(
  2535 			'mid_size'           => 1,
  2662 			$args,
  2536 			'prev_text'          => _x( 'Previous', 'previous set of posts' ),
  2663 			array(
  2537 			'next_text'          => _x( 'Next', 'next set of posts' ),
  2664 				'mid_size'           => 1,
  2538 			'screen_reader_text' => __( 'Posts navigation' ),
  2665 				'prev_text'          => _x( 'Previous', 'previous set of posts' ),
  2539 		) );
  2666 				'next_text'          => _x( 'Next', 'next set of posts' ),
       
  2667 				'screen_reader_text' => __( 'Posts navigation' ),
       
  2668 			)
       
  2669 		);
  2540 
  2670 
  2541 		// Make sure we get a string back. Plain is the next best thing.
  2671 		// Make sure we get a string back. Plain is the next best thing.
  2542 		if ( isset( $args['type'] ) && 'array' == $args['type'] ) {
  2672 		if ( isset( $args['type'] ) && 'array' == $args['type'] ) {
  2543 			$args['type'] = 'plain';
  2673 			$args['type'] = 'plain';
  2544 		}
  2674 		}
  2627 
  2757 
  2628 	$pagenum = (int) $pagenum;
  2758 	$pagenum = (int) $pagenum;
  2629 
  2759 
  2630 	$result = get_permalink();
  2760 	$result = get_permalink();
  2631 
  2761 
  2632 	if ( 'newest' == get_option('default_comments_page') ) {
  2762 	if ( 'newest' == get_option( 'default_comments_page' ) ) {
  2633 		if ( $pagenum != $max_page ) {
  2763 		if ( $pagenum != $max_page ) {
  2634 			if ( $wp_rewrite->using_permalinks() )
  2764 			if ( $wp_rewrite->using_permalinks() ) {
  2635 				$result = user_trailingslashit( trailingslashit($result) . $wp_rewrite->comments_pagination_base . '-' . $pagenum, 'commentpaged');
  2765 				$result = user_trailingslashit( trailingslashit( $result ) . $wp_rewrite->comments_pagination_base . '-' . $pagenum, 'commentpaged' );
  2636 			else
  2766 			} else {
  2637 				$result = add_query_arg( 'cpage', $pagenum, $result );
  2767 				$result = add_query_arg( 'cpage', $pagenum, $result );
       
  2768 			}
  2638 		}
  2769 		}
  2639 	} elseif ( $pagenum > 1 ) {
  2770 	} elseif ( $pagenum > 1 ) {
  2640 		if ( $wp_rewrite->using_permalinks() )
  2771 		if ( $wp_rewrite->using_permalinks() ) {
  2641 			$result = user_trailingslashit( trailingslashit($result) . $wp_rewrite->comments_pagination_base . '-' . $pagenum, 'commentpaged');
  2772 			$result = user_trailingslashit( trailingslashit( $result ) . $wp_rewrite->comments_pagination_base . '-' . $pagenum, 'commentpaged' );
  2642 		else
  2773 		} else {
  2643 			$result = add_query_arg( 'cpage', $pagenum, $result );
  2774 			$result = add_query_arg( 'cpage', $pagenum, $result );
       
  2775 		}
  2644 	}
  2776 	}
  2645 
  2777 
  2646 	$result .= '#comments';
  2778 	$result .= '#comments';
  2647 
  2779 
  2648 	/**
  2780 	/**
  2667  * @return string|void HTML-formatted link for the next page of comments.
  2799  * @return string|void HTML-formatted link for the next page of comments.
  2668  */
  2800  */
  2669 function get_next_comments_link( $label = '', $max_page = 0 ) {
  2801 function get_next_comments_link( $label = '', $max_page = 0 ) {
  2670 	global $wp_query;
  2802 	global $wp_query;
  2671 
  2803 
  2672 	if ( ! is_singular() )
  2804 	if ( ! is_singular() ) {
  2673 		return;
  2805 		return;
  2674 
  2806 	}
  2675 	$page = get_query_var('cpage');
  2807 
       
  2808 	$page = get_query_var( 'cpage' );
  2676 
  2809 
  2677 	if ( ! $page ) {
  2810 	if ( ! $page ) {
  2678 		$page = 1;
  2811 		$page = 1;
  2679 	}
  2812 	}
  2680 
  2813 
  2681 	$nextpage = intval($page) + 1;
  2814 	$nextpage = intval( $page ) + 1;
  2682 
  2815 
  2683 	if ( empty($max_page) )
  2816 	if ( empty( $max_page ) ) {
  2684 		$max_page = $wp_query->max_num_comment_pages;
  2817 		$max_page = $wp_query->max_num_comment_pages;
  2685 
  2818 	}
  2686 	if ( empty($max_page) )
  2819 
       
  2820 	if ( empty( $max_page ) ) {
  2687 		$max_page = get_comment_pages_count();
  2821 		$max_page = get_comment_pages_count();
  2688 
  2822 	}
  2689 	if ( $nextpage > $max_page )
  2823 
       
  2824 	if ( $nextpage > $max_page ) {
  2690 		return;
  2825 		return;
  2691 
  2826 	}
  2692 	if ( empty($label) )
  2827 
  2693 		$label = __('Newer Comments &raquo;');
  2828 	if ( empty( $label ) ) {
       
  2829 		$label = __( 'Newer Comments &raquo;' );
       
  2830 	}
  2694 
  2831 
  2695 	/**
  2832 	/**
  2696 	 * Filters the anchor tag attributes for the next comments page link.
  2833 	 * Filters the anchor tag attributes for the next comments page link.
  2697 	 *
  2834 	 *
  2698 	 * @since 2.7.0
  2835 	 * @since 2.7.0
  2699 	 *
  2836 	 *
  2700 	 * @param string $attributes Attributes for the anchor tag.
  2837 	 * @param string $attributes Attributes for the anchor tag.
  2701 	 */
  2838 	 */
  2702 	return '<a href="' . esc_url( get_comments_pagenum_link( $nextpage, $max_page ) ) . '" ' . apply_filters( 'next_comments_link_attributes', '' ) . '>'. preg_replace('/&([^#])(?![a-z]{1,8};)/i', '&#038;$1', $label) .'</a>';
  2839 	return '<a href="' . esc_url( get_comments_pagenum_link( $nextpage, $max_page ) ) . '" ' . apply_filters( 'next_comments_link_attributes', '' ) . '>' . preg_replace( '/&([^#])(?![a-z]{1,8};)/i', '&#038;$1', $label ) . '</a>';
  2703 }
  2840 }
  2704 
  2841 
  2705 /**
  2842 /**
  2706  * Displays the link to the next comments page.
  2843  * Displays the link to the next comments page.
  2707  *
  2844  *
  2721  *
  2858  *
  2722  * @param string $label Optional. Label for comments link text. Default empty.
  2859  * @param string $label Optional. Label for comments link text. Default empty.
  2723  * @return string|void HTML-formatted link for the previous page of comments.
  2860  * @return string|void HTML-formatted link for the previous page of comments.
  2724  */
  2861  */
  2725 function get_previous_comments_link( $label = '' ) {
  2862 function get_previous_comments_link( $label = '' ) {
  2726 	if ( ! is_singular() )
  2863 	if ( ! is_singular() ) {
  2727 		return;
  2864 		return;
  2728 
  2865 	}
  2729 	$page = get_query_var('cpage');
  2866 
  2730 
  2867 	$page = get_query_var( 'cpage' );
  2731 	if ( intval($page) <= 1 )
  2868 
       
  2869 	if ( intval( $page ) <= 1 ) {
  2732 		return;
  2870 		return;
  2733 
  2871 	}
  2734 	$prevpage = intval($page) - 1;
  2872 
  2735 
  2873 	$prevpage = intval( $page ) - 1;
  2736 	if ( empty($label) )
  2874 
  2737 		$label = __('&laquo; Older Comments');
  2875 	if ( empty( $label ) ) {
       
  2876 		$label = __( '&laquo; Older Comments' );
       
  2877 	}
  2738 
  2878 
  2739 	/**
  2879 	/**
  2740 	 * Filters the anchor tag attributes for the previous comments page link.
  2880 	 * Filters the anchor tag attributes for the previous comments page link.
  2741 	 *
  2881 	 *
  2742 	 * @since 2.7.0
  2882 	 * @since 2.7.0
  2743 	 *
  2883 	 *
  2744 	 * @param string $attributes Attributes for the anchor tag.
  2884 	 * @param string $attributes Attributes for the anchor tag.
  2745 	 */
  2885 	 */
  2746 	return '<a href="' . esc_url( get_comments_pagenum_link( $prevpage ) ) . '" ' . apply_filters( 'previous_comments_link_attributes', '' ) . '>' . preg_replace('/&([^#])(?![a-z]{1,8};)/i', '&#038;$1', $label) .'</a>';
  2886 	return '<a href="' . esc_url( get_comments_pagenum_link( $prevpage ) ) . '" ' . apply_filters( 'previous_comments_link_attributes', '' ) . '>' . preg_replace( '/&([^#])(?![a-z]{1,8};)/i', '&#038;$1', $label ) . '</a>';
  2747 }
  2887 }
  2748 
  2888 
  2749 /**
  2889 /**
  2750  * Displays the link to the previous comments page.
  2890  * Displays the link to the previous comments page.
  2751  *
  2891  *
  2764  * @since 2.7.0
  2904  * @since 2.7.0
  2765  *
  2905  *
  2766  * @global WP_Rewrite $wp_rewrite
  2906  * @global WP_Rewrite $wp_rewrite
  2767  *
  2907  *
  2768  * @param string|array $args Optional args. See paginate_links(). Default empty array.
  2908  * @param string|array $args Optional args. See paginate_links(). Default empty array.
  2769  * @return string|void Markup for pagination links.
  2909  * @return string|array|void Markup for comment page links or array of comment page links.
  2770  */
  2910  */
  2771 function paginate_comments_links( $args = array() ) {
  2911 function paginate_comments_links( $args = array() ) {
  2772 	global $wp_rewrite;
  2912 	global $wp_rewrite;
  2773 
  2913 
  2774 	if ( ! is_singular() )
  2914 	if ( ! is_singular() ) {
  2775 		return;
  2915 		return;
  2776 
  2916 	}
  2777 	$page = get_query_var('cpage');
  2917 
  2778 	if ( !$page )
  2918 	$page = get_query_var( 'cpage' );
       
  2919 	if ( ! $page ) {
  2779 		$page = 1;
  2920 		$page = 1;
       
  2921 	}
  2780 	$max_page = get_comment_pages_count();
  2922 	$max_page = get_comment_pages_count();
  2781 	$defaults = array(
  2923 	$defaults = array(
  2782 		'base' => add_query_arg( 'cpage', '%#%' ),
  2924 		'base'         => add_query_arg( 'cpage', '%#%' ),
  2783 		'format' => '',
  2925 		'format'       => '',
  2784 		'total' => $max_page,
  2926 		'total'        => $max_page,
  2785 		'current' => $page,
  2927 		'current'      => $page,
  2786 		'echo' => true,
  2928 		'echo'         => true,
  2787 		'add_fragment' => '#comments'
  2929 		'type'         => 'plain',
       
  2930 		'add_fragment' => '#comments',
  2788 	);
  2931 	);
  2789 	if ( $wp_rewrite->using_permalinks() )
  2932 	if ( $wp_rewrite->using_permalinks() ) {
  2790 		$defaults['base'] = user_trailingslashit(trailingslashit(get_permalink()) . $wp_rewrite->comments_pagination_base . '-%#%', 'commentpaged');
  2933 		$defaults['base'] = user_trailingslashit( trailingslashit( get_permalink() ) . $wp_rewrite->comments_pagination_base . '-%#%', 'commentpaged' );
  2791 
  2934 	}
  2792 	$args = wp_parse_args( $args, $defaults );
  2935 
       
  2936 	$args       = wp_parse_args( $args, $defaults );
  2793 	$page_links = paginate_links( $args );
  2937 	$page_links = paginate_links( $args );
  2794 
  2938 
  2795 	if ( $args['echo'] )
  2939 	if ( $args['echo'] && 'array' !== $args['type'] ) {
  2796 		echo $page_links;
  2940 		echo $page_links;
  2797 	else
  2941 	} else {
  2798 		return $page_links;
  2942 		return $page_links;
       
  2943 	}
  2799 }
  2944 }
  2800 
  2945 
  2801 /**
  2946 /**
  2802  * Retrieves navigation to next/previous set of comments, when applicable.
  2947  * Retrieves navigation to next/previous set of comments, when applicable.
  2803  *
  2948  *
  2817 function get_the_comments_navigation( $args = array() ) {
  2962 function get_the_comments_navigation( $args = array() ) {
  2818 	$navigation = '';
  2963 	$navigation = '';
  2819 
  2964 
  2820 	// Are there comments to navigate through?
  2965 	// Are there comments to navigate through?
  2821 	if ( get_comment_pages_count() > 1 ) {
  2966 	if ( get_comment_pages_count() > 1 ) {
  2822 		$args = wp_parse_args( $args, array(
  2967 		$args = wp_parse_args(
  2823 			'prev_text'          => __( 'Older comments' ),
  2968 			$args,
  2824 			'next_text'          => __( 'Newer comments' ),
  2969 			array(
  2825 			'screen_reader_text' => __( 'Comments navigation' ),
  2970 				'prev_text'          => __( 'Older comments' ),
  2826 		) );
  2971 				'next_text'          => __( 'Newer comments' ),
       
  2972 				'screen_reader_text' => __( 'Comments navigation' ),
       
  2973 			)
       
  2974 		);
  2827 
  2975 
  2828 		$prev_link = get_previous_comments_link( $args['prev_text'] );
  2976 		$prev_link = get_previous_comments_link( $args['prev_text'] );
  2829 		$next_link = get_next_comments_link( $args['next_text'] );
  2977 		$next_link = get_next_comments_link( $args['next_text'] );
  2830 
  2978 
  2831 		if ( $prev_link ) {
  2979 		if ( $prev_link ) {
  2866  *     @type string $screen_reader_text Screen reader text for nav element. Default 'Comments navigation'.
  3014  *     @type string $screen_reader_text Screen reader text for nav element. Default 'Comments navigation'.
  2867  * }
  3015  * }
  2868  * @return string Markup for pagination links.
  3016  * @return string Markup for pagination links.
  2869  */
  3017  */
  2870 function get_the_comments_pagination( $args = array() ) {
  3018 function get_the_comments_pagination( $args = array() ) {
  2871 	$navigation = '';
  3019 	$navigation   = '';
  2872 	$args       = wp_parse_args( $args, array(
  3020 	$args         = wp_parse_args(
  2873 		'screen_reader_text' => __( 'Comments navigation' ),
  3021 		$args,
  2874 	) );
  3022 		array(
       
  3023 			'screen_reader_text' => __( 'Comments navigation' ),
       
  3024 		)
       
  3025 	);
  2875 	$args['echo'] = false;
  3026 	$args['echo'] = false;
  2876 
  3027 
  2877 	// Make sure we get a string back. Plain is the next best thing.
  3028 	// Make sure we get a string back. Plain is the next best thing.
  2878 	if ( isset( $args['type'] ) && 'array' == $args['type'] ) {
  3029 	if ( isset( $args['type'] ) && 'array' == $args['type'] ) {
  2879 		$args['type'] = 'plain';
  3030 		$args['type'] = 'plain';
  2937 function get_home_url( $blog_id = null, $path = '', $scheme = null ) {
  3088 function get_home_url( $blog_id = null, $path = '', $scheme = null ) {
  2938 	global $pagenow;
  3089 	global $pagenow;
  2939 
  3090 
  2940 	$orig_scheme = $scheme;
  3091 	$orig_scheme = $scheme;
  2941 
  3092 
  2942 	if ( empty( $blog_id ) || !is_multisite() ) {
  3093 	if ( empty( $blog_id ) || ! is_multisite() ) {
  2943 		$url = get_option( 'home' );
  3094 		$url = get_option( 'home' );
  2944 	} else {
  3095 	} else {
  2945 		switch_to_blog( $blog_id );
  3096 		switch_to_blog( $blog_id );
  2946 		$url = get_option( 'home' );
  3097 		$url = get_option( 'home' );
  2947 		restore_current_blog();
  3098 		restore_current_blog();
  2948 	}
  3099 	}
  2949 
  3100 
  2950 	if ( ! in_array( $scheme, array( 'http', 'https', 'relative' ) ) ) {
  3101 	if ( ! in_array( $scheme, array( 'http', 'https', 'relative' ) ) ) {
  2951 		if ( is_ssl() && ! is_admin() && 'wp-login.php' !== $pagenow )
  3102 		if ( is_ssl() && ! is_admin() && 'wp-login.php' !== $pagenow ) {
  2952 			$scheme = 'https';
  3103 			$scheme = 'https';
  2953 		else
  3104 		} else {
  2954 			$scheme = parse_url( $url, PHP_URL_SCHEME );
  3105 			$scheme = parse_url( $url, PHP_URL_SCHEME );
       
  3106 		}
  2955 	}
  3107 	}
  2956 
  3108 
  2957 	$url = set_url_scheme( $url, $scheme );
  3109 	$url = set_url_scheme( $url, $scheme );
  2958 
  3110 
  2959 	if ( $path && is_string( $path ) )
  3111 	if ( $path && is_string( $path ) ) {
  2960 		$url .= '/' . ltrim( $path, '/' );
  3112 		$url .= '/' . ltrim( $path, '/' );
       
  3113 	}
  2961 
  3114 
  2962 	/**
  3115 	/**
  2963 	 * Filters the home URL.
  3116 	 * Filters the home URL.
  2964 	 *
  3117 	 *
  2965 	 * @since 3.0.0
  3118 	 * @since 3.0.0
  3007  *                        'http', 'https', 'login', 'login_post', 'admin', or
  3160  *                        'http', 'https', 'login', 'login_post', 'admin', or
  3008  *                        'relative'. Default null.
  3161  *                        'relative'. Default null.
  3009  * @return string Site URL link with optional path appended.
  3162  * @return string Site URL link with optional path appended.
  3010  */
  3163  */
  3011 function get_site_url( $blog_id = null, $path = '', $scheme = null ) {
  3164 function get_site_url( $blog_id = null, $path = '', $scheme = null ) {
  3012 	if ( empty( $blog_id ) || !is_multisite() ) {
  3165 	if ( empty( $blog_id ) || ! is_multisite() ) {
  3013 		$url = get_option( 'siteurl' );
  3166 		$url = get_option( 'siteurl' );
  3014 	} else {
  3167 	} else {
  3015 		switch_to_blog( $blog_id );
  3168 		switch_to_blog( $blog_id );
  3016 		$url = get_option( 'siteurl' );
  3169 		$url = get_option( 'siteurl' );
  3017 		restore_current_blog();
  3170 		restore_current_blog();
  3018 	}
  3171 	}
  3019 
  3172 
  3020 	$url = set_url_scheme( $url, $scheme );
  3173 	$url = set_url_scheme( $url, $scheme );
  3021 
  3174 
  3022 	if ( $path && is_string( $path ) )
  3175 	if ( $path && is_string( $path ) ) {
  3023 		$url .= '/' . ltrim( $path, '/' );
  3176 		$url .= '/' . ltrim( $path, '/' );
       
  3177 	}
  3024 
  3178 
  3025 	/**
  3179 	/**
  3026 	 * Filters the site URL.
  3180 	 * Filters the site URL.
  3027 	 *
  3181 	 *
  3028 	 * @since 2.7.0
  3182 	 * @since 2.7.0
  3061  *                        to force those schemes. Default 'admin', which obeys
  3215  *                        to force those schemes. Default 'admin', which obeys
  3062  *                        force_ssl_admin() and is_ssl().
  3216  *                        force_ssl_admin() and is_ssl().
  3063  * @return string Admin URL link with optional path appended.
  3217  * @return string Admin URL link with optional path appended.
  3064  */
  3218  */
  3065 function get_admin_url( $blog_id = null, $path = '', $scheme = 'admin' ) {
  3219 function get_admin_url( $blog_id = null, $path = '', $scheme = 'admin' ) {
  3066 	$url = get_site_url($blog_id, 'wp-admin/', $scheme);
  3220 	$url = get_site_url( $blog_id, 'wp-admin/', $scheme );
  3067 
  3221 
  3068 	if ( $path && is_string( $path ) )
  3222 	if ( $path && is_string( $path ) ) {
  3069 		$url .= ltrim( $path, '/' );
  3223 		$url .= ltrim( $path, '/' );
       
  3224 	}
  3070 
  3225 
  3071 	/**
  3226 	/**
  3072 	 * Filters the admin area URL.
  3227 	 * Filters the admin area URL.
  3073 	 *
  3228 	 *
  3074 	 * @since 2.8.0
  3229 	 * @since 2.8.0
  3091  * @return string Includes URL link with optional path appended.
  3246  * @return string Includes URL link with optional path appended.
  3092  */
  3247  */
  3093 function includes_url( $path = '', $scheme = null ) {
  3248 function includes_url( $path = '', $scheme = null ) {
  3094 	$url = site_url( '/' . WPINC . '/', $scheme );
  3249 	$url = site_url( '/' . WPINC . '/', $scheme );
  3095 
  3250 
  3096 	if ( $path && is_string( $path ) )
  3251 	if ( $path && is_string( $path ) ) {
  3097 		$url .= ltrim($path, '/');
  3252 		$url .= ltrim( $path, '/' );
       
  3253 	}
  3098 
  3254 
  3099 	/**
  3255 	/**
  3100 	 * Filters the URL to the includes directory.
  3256 	 * Filters the URL to the includes directory.
  3101 	 *
  3257 	 *
  3102 	 * @since 2.8.0
  3258 	 * @since 2.8.0
  3117  * @return string Content URL link with optional path appended.
  3273  * @return string Content URL link with optional path appended.
  3118  */
  3274  */
  3119 function content_url( $path = '' ) {
  3275 function content_url( $path = '' ) {
  3120 	$url = set_url_scheme( WP_CONTENT_URL );
  3276 	$url = set_url_scheme( WP_CONTENT_URL );
  3121 
  3277 
  3122 	if ( $path && is_string( $path ) )
  3278 	if ( $path && is_string( $path ) ) {
  3123 		$url .= '/' . ltrim($path, '/');
  3279 		$url .= '/' . ltrim( $path, '/' );
       
  3280 	}
  3124 
  3281 
  3125 	/**
  3282 	/**
  3126 	 * Filters the URL to the content directory.
  3283 	 * Filters the URL to the content directory.
  3127 	 *
  3284 	 *
  3128 	 * @since 2.8.0
  3285 	 * @since 2.8.0
  3129 	 *
  3286 	 *
  3130 	 * @param string $url  The complete URL to the content directory including scheme and path.
  3287 	 * @param string $url  The complete URL to the content directory including scheme and path.
  3131 	 * @param string $path Path relative to the URL to the content directory. Blank string
  3288 	 * @param string $path Path relative to the URL to the content directory. Blank string
  3132 	 *                     if no path is specified.
  3289 	 *                     if no path is specified.
  3133 	 */
  3290 	 */
  3134 	return apply_filters( 'content_url', $url, $path);
  3291 	return apply_filters( 'content_url', $url, $path );
  3135 }
  3292 }
  3136 
  3293 
  3137 /**
  3294 /**
  3138  * Retrieves a URL within the plugins or mu-plugins directory.
  3295  * Retrieves a URL within the plugins or mu-plugins directory.
  3139  *
  3296  *
  3148  *                        Typically this is done by passing `__FILE__` as the argument.
  3305  *                        Typically this is done by passing `__FILE__` as the argument.
  3149  * @return string Plugins URL link with optional paths appended.
  3306  * @return string Plugins URL link with optional paths appended.
  3150  */
  3307  */
  3151 function plugins_url( $path = '', $plugin = '' ) {
  3308 function plugins_url( $path = '', $plugin = '' ) {
  3152 
  3309 
  3153 	$path = wp_normalize_path( $path );
  3310 	$path          = wp_normalize_path( $path );
  3154 	$plugin = wp_normalize_path( $plugin );
  3311 	$plugin        = wp_normalize_path( $plugin );
  3155 	$mu_plugin_dir = wp_normalize_path( WPMU_PLUGIN_DIR );
  3312 	$mu_plugin_dir = wp_normalize_path( WPMU_PLUGIN_DIR );
  3156 
  3313 
  3157 	if ( !empty($plugin) && 0 === strpos($plugin, $mu_plugin_dir) )
  3314 	if ( ! empty( $plugin ) && 0 === strpos( $plugin, $mu_plugin_dir ) ) {
  3158 		$url = WPMU_PLUGIN_URL;
  3315 		$url = WPMU_PLUGIN_URL;
  3159 	else
  3316 	} else {
  3160 		$url = WP_PLUGIN_URL;
  3317 		$url = WP_PLUGIN_URL;
  3161 
  3318 	}
  3162 
  3319 
  3163 	$url = set_url_scheme( $url );
  3320 	$url = set_url_scheme( $url );
  3164 
  3321 
  3165 	if ( !empty($plugin) && is_string($plugin) ) {
  3322 	if ( ! empty( $plugin ) && is_string( $plugin ) ) {
  3166 		$folder = dirname(plugin_basename($plugin));
  3323 		$folder = dirname( plugin_basename( $plugin ) );
  3167 		if ( '.' != $folder )
  3324 		if ( '.' != $folder ) {
  3168 			$url .= '/' . ltrim($folder, '/');
  3325 			$url .= '/' . ltrim( $folder, '/' );
  3169 	}
  3326 		}
  3170 
  3327 	}
  3171 	if ( $path && is_string( $path ) )
  3328 
  3172 		$url .= '/' . ltrim($path, '/');
  3329 	if ( $path && is_string( $path ) ) {
       
  3330 		$url .= '/' . ltrim( $path, '/' );
       
  3331 	}
  3173 
  3332 
  3174 	/**
  3333 	/**
  3175 	 * Filters the URL to the plugins directory.
  3334 	 * Filters the URL to the plugins directory.
  3176 	 *
  3335 	 *
  3177 	 * @since 2.8.0
  3336 	 * @since 2.8.0
  3200  * @param string $scheme Optional. Scheme to give the site URL context. Accepts
  3359  * @param string $scheme Optional. Scheme to give the site URL context. Accepts
  3201  *                       'http', 'https', or 'relative'. Default null.
  3360  *                       'http', 'https', or 'relative'. Default null.
  3202  * @return string Site URL link with optional path appended.
  3361  * @return string Site URL link with optional path appended.
  3203  */
  3362  */
  3204 function network_site_url( $path = '', $scheme = null ) {
  3363 function network_site_url( $path = '', $scheme = null ) {
  3205 	if ( ! is_multisite() )
  3364 	if ( ! is_multisite() ) {
  3206 		return site_url($path, $scheme);
  3365 		return site_url( $path, $scheme );
       
  3366 	}
  3207 
  3367 
  3208 	$current_network = get_network();
  3368 	$current_network = get_network();
  3209 
  3369 
  3210 	if ( 'relative' == $scheme )
  3370 	if ( 'relative' == $scheme ) {
  3211 		$url = $current_network->path;
  3371 		$url = $current_network->path;
  3212 	else
  3372 	} else {
  3213 		$url = set_url_scheme( 'http://' . $current_network->domain . $current_network->path, $scheme );
  3373 		$url = set_url_scheme( 'http://' . $current_network->domain . $current_network->path, $scheme );
  3214 
  3374 	}
  3215 	if ( $path && is_string( $path ) )
  3375 
       
  3376 	if ( $path && is_string( $path ) ) {
  3216 		$url .= ltrim( $path, '/' );
  3377 		$url .= ltrim( $path, '/' );
       
  3378 	}
  3217 
  3379 
  3218 	/**
  3380 	/**
  3219 	 * Filters the network site URL.
  3381 	 * Filters the network site URL.
  3220 	 *
  3382 	 *
  3221 	 * @since 3.0.0
  3383 	 * @since 3.0.0
  3242  * @param  string $scheme Optional. Scheme to give the home URL context. Accepts
  3404  * @param  string $scheme Optional. Scheme to give the home URL context. Accepts
  3243  *                        'http', 'https', or 'relative'. Default null.
  3405  *                        'http', 'https', or 'relative'. Default null.
  3244  * @return string Home URL link with optional path appended.
  3406  * @return string Home URL link with optional path appended.
  3245  */
  3407  */
  3246 function network_home_url( $path = '', $scheme = null ) {
  3408 function network_home_url( $path = '', $scheme = null ) {
  3247 	if ( ! is_multisite() )
  3409 	if ( ! is_multisite() ) {
  3248 		return home_url($path, $scheme);
  3410 		return home_url( $path, $scheme );
       
  3411 	}
  3249 
  3412 
  3250 	$current_network = get_network();
  3413 	$current_network = get_network();
  3251 	$orig_scheme = $scheme;
  3414 	$orig_scheme     = $scheme;
  3252 
  3415 
  3253 	if ( ! in_array( $scheme, array( 'http', 'https', 'relative' ) ) )
  3416 	if ( ! in_array( $scheme, array( 'http', 'https', 'relative' ) ) ) {
  3254 		$scheme = is_ssl() && ! is_admin() ? 'https' : 'http';
  3417 		$scheme = is_ssl() && ! is_admin() ? 'https' : 'http';
  3255 
  3418 	}
  3256 	if ( 'relative' == $scheme )
  3419 
       
  3420 	if ( 'relative' == $scheme ) {
  3257 		$url = $current_network->path;
  3421 		$url = $current_network->path;
  3258 	else
  3422 	} else {
  3259 		$url = set_url_scheme( 'http://' . $current_network->domain . $current_network->path, $scheme );
  3423 		$url = set_url_scheme( 'http://' . $current_network->domain . $current_network->path, $scheme );
  3260 
  3424 	}
  3261 	if ( $path && is_string( $path ) )
  3425 
       
  3426 	if ( $path && is_string( $path ) ) {
  3262 		$url .= ltrim( $path, '/' );
  3427 		$url .= ltrim( $path, '/' );
       
  3428 	}
  3263 
  3429 
  3264 	/**
  3430 	/**
  3265 	 * Filters the network home URL.
  3431 	 * Filters the network home URL.
  3266 	 *
  3432 	 *
  3267 	 * @since 3.0.0
  3433 	 * @since 3.0.0
  3270 	 * @param string      $path        Path relative to the network home URL. Blank string
  3436 	 * @param string      $path        Path relative to the network home URL. Blank string
  3271 	 *                                 if no path is specified.
  3437 	 *                                 if no path is specified.
  3272 	 * @param string|null $orig_scheme Scheme to give the URL context. Accepts 'http', 'https',
  3438 	 * @param string|null $orig_scheme Scheme to give the URL context. Accepts 'http', 'https',
  3273 	 *                                 'relative' or null.
  3439 	 *                                 'relative' or null.
  3274 	 */
  3440 	 */
  3275 	return apply_filters( 'network_home_url', $url, $path, $orig_scheme);
  3441 	return apply_filters( 'network_home_url', $url, $path, $orig_scheme );
  3276 }
  3442 }
  3277 
  3443 
  3278 /**
  3444 /**
  3279  * Retrieves the URL to the admin area for the network.
  3445  * Retrieves the URL to the admin area for the network.
  3280  *
  3446  *
  3284  * @param string $scheme Optional. The scheme to use. Default is 'admin', which obeys force_ssl_admin()
  3450  * @param string $scheme Optional. The scheme to use. Default is 'admin', which obeys force_ssl_admin()
  3285  *                       and is_ssl(). 'http' or 'https' can be passed to force those schemes.
  3451  *                       and is_ssl(). 'http' or 'https' can be passed to force those schemes.
  3286  * @return string Admin URL link with optional path appended.
  3452  * @return string Admin URL link with optional path appended.
  3287  */
  3453  */
  3288 function network_admin_url( $path = '', $scheme = 'admin' ) {
  3454 function network_admin_url( $path = '', $scheme = 'admin' ) {
  3289 	if ( ! is_multisite() )
  3455 	if ( ! is_multisite() ) {
  3290 		return admin_url( $path, $scheme );
  3456 		return admin_url( $path, $scheme );
  3291 
  3457 	}
  3292 	$url = network_site_url('wp-admin/network/', $scheme);
  3458 
  3293 
  3459 	$url = network_site_url( 'wp-admin/network/', $scheme );
  3294 	if ( $path && is_string( $path ) )
  3460 
  3295 		$url .= ltrim($path, '/');
  3461 	if ( $path && is_string( $path ) ) {
       
  3462 		$url .= ltrim( $path, '/' );
       
  3463 	}
  3296 
  3464 
  3297 	/**
  3465 	/**
  3298 	 * Filters the network admin URL.
  3466 	 * Filters the network admin URL.
  3299 	 *
  3467 	 *
  3300 	 * @since 3.0.0
  3468 	 * @since 3.0.0
  3315  * @param string $scheme Optional. The scheme to use. Default is 'admin', which obeys force_ssl_admin()
  3483  * @param string $scheme Optional. The scheme to use. Default is 'admin', which obeys force_ssl_admin()
  3316  *                       and is_ssl(). 'http' or 'https' can be passed to force those schemes.
  3484  *                       and is_ssl(). 'http' or 'https' can be passed to force those schemes.
  3317  * @return string Admin URL link with optional path appended.
  3485  * @return string Admin URL link with optional path appended.
  3318  */
  3486  */
  3319 function user_admin_url( $path = '', $scheme = 'admin' ) {
  3487 function user_admin_url( $path = '', $scheme = 'admin' ) {
  3320 	$url = network_site_url('wp-admin/user/', $scheme);
  3488 	$url = network_site_url( 'wp-admin/user/', $scheme );
  3321 
  3489 
  3322 	if ( $path && is_string( $path ) )
  3490 	if ( $path && is_string( $path ) ) {
  3323 		$url .= ltrim($path, '/');
  3491 		$url .= ltrim( $path, '/' );
       
  3492 	}
  3324 
  3493 
  3325 	/**
  3494 	/**
  3326 	 * Filters the user admin URL for the current user.
  3495 	 * Filters the user admin URL for the current user.
  3327 	 *
  3496 	 *
  3328 	 * @since 3.1.0
  3497 	 * @since 3.1.0
  3386 	} elseif ( $scheme !== 'http' && $scheme !== 'https' && $scheme !== 'relative' ) {
  3555 	} elseif ( $scheme !== 'http' && $scheme !== 'https' && $scheme !== 'relative' ) {
  3387 		$scheme = is_ssl() ? 'https' : 'http';
  3556 		$scheme = is_ssl() ? 'https' : 'http';
  3388 	}
  3557 	}
  3389 
  3558 
  3390 	$url = trim( $url );
  3559 	$url = trim( $url );
  3391 	if ( substr( $url, 0, 2 ) === '//' )
  3560 	if ( substr( $url, 0, 2 ) === '//' ) {
  3392 		$url = 'http:' . $url;
  3561 		$url = 'http:' . $url;
       
  3562 	}
  3393 
  3563 
  3394 	if ( 'relative' == $scheme ) {
  3564 	if ( 'relative' == $scheme ) {
  3395 		$url = ltrim( preg_replace( '#^\w+://[^/]*#', '', $url ) );
  3565 		$url = ltrim( preg_replace( '#^\w+://[^/]*#', '', $url ) );
  3396 		if ( $url !== '' && $url[0] === '/' )
  3566 		if ( $url !== '' && $url[0] === '/' ) {
  3397 			$url = '/' . ltrim($url , "/ \t\n\r\0\x0B" );
  3567 			$url = '/' . ltrim( $url, "/ \t\n\r\0\x0B" );
       
  3568 		}
  3398 	} else {
  3569 	} else {
  3399 		$url = preg_replace( '#^\w+://#', $scheme . '://', $url );
  3570 		$url = preg_replace( '#^\w+://#', $scheme . '://', $url );
  3400 	}
  3571 	}
  3401 
  3572 
  3402 	/**
  3573 	/**
  3430  */
  3601  */
  3431 function get_dashboard_url( $user_id = 0, $path = '', $scheme = 'admin' ) {
  3602 function get_dashboard_url( $user_id = 0, $path = '', $scheme = 'admin' ) {
  3432 	$user_id = $user_id ? (int) $user_id : get_current_user_id();
  3603 	$user_id = $user_id ? (int) $user_id : get_current_user_id();
  3433 
  3604 
  3434 	$blogs = get_blogs_of_user( $user_id );
  3605 	$blogs = get_blogs_of_user( $user_id );
  3435 	if ( is_multisite() && ! user_can( $user_id, 'manage_network' ) && empty($blogs) ) {
  3606 	if ( is_multisite() && ! user_can( $user_id, 'manage_network' ) && empty( $blogs ) ) {
  3436 		$url = user_admin_url( $path, $scheme );
  3607 		$url = user_admin_url( $path, $scheme );
  3437 	} elseif ( ! is_multisite() ) {
  3608 	} elseif ( ! is_multisite() ) {
  3438 		$url = admin_url( $path, $scheme );
  3609 		$url = admin_url( $path, $scheme );
  3439 	} else {
  3610 	} else {
  3440 		$current_blog = get_current_blog_id();
  3611 		$current_blog = get_current_blog_id();
  3441 		if ( $current_blog  && ( user_can( $user_id, 'manage_network' ) || in_array( $current_blog, array_keys( $blogs ) ) ) ) {
  3612 		if ( $current_blog && ( user_can( $user_id, 'manage_network' ) || in_array( $current_blog, array_keys( $blogs ) ) ) ) {
  3442 			$url = admin_url( $path, $scheme );
  3613 			$url = admin_url( $path, $scheme );
  3443 		} else {
  3614 		} else {
  3444 			$active = get_active_blog_for_user( $user_id );
  3615 			$active = get_active_blog_for_user( $user_id );
  3445 			if ( $active )
  3616 			if ( $active ) {
  3446 				$url = get_admin_url( $active->blog_id, $path, $scheme );
  3617 				$url = get_admin_url( $active->blog_id, $path, $scheme );
  3447 			else
  3618 			} else {
  3448 				$url = user_admin_url( $path, $scheme );
  3619 				$url = user_admin_url( $path, $scheme );
       
  3620 			}
  3449 		}
  3621 		}
  3450 	}
  3622 	}
  3451 
  3623 
  3452 	/**
  3624 	/**
  3453 	 * Filters the dashboard URL for a user.
  3625 	 * Filters the dashboard URL for a user.
  3458 	 * @param int    $user_id The user ID.
  3630 	 * @param int    $user_id The user ID.
  3459 	 * @param string $path    Path relative to the URL. Blank string if no path is specified.
  3631 	 * @param string $path    Path relative to the URL. Blank string if no path is specified.
  3460 	 * @param string $scheme  Scheme to give the URL context. Accepts 'http', 'https', 'login',
  3632 	 * @param string $scheme  Scheme to give the URL context. Accepts 'http', 'https', 'login',
  3461 	 *                        'login_post', 'admin', 'relative' or null.
  3633 	 *                        'login_post', 'admin', 'relative' or null.
  3462 	 */
  3634 	 */
  3463 	return apply_filters( 'user_dashboard_url', $url, $user_id, $path, $scheme);
  3635 	return apply_filters( 'user_dashboard_url', $url, $user_id, $path, $scheme );
  3464 }
  3636 }
  3465 
  3637 
  3466 /**
  3638 /**
  3467  * Retrieves the URL to the user's profile editor.
  3639  * Retrieves the URL to the user's profile editor.
  3468  *
  3640  *
  3474  * @return string Dashboard URL link with optional path appended.
  3646  * @return string Dashboard URL link with optional path appended.
  3475  */
  3647  */
  3476 function get_edit_profile_url( $user_id = 0, $scheme = 'admin' ) {
  3648 function get_edit_profile_url( $user_id = 0, $scheme = 'admin' ) {
  3477 	$user_id = $user_id ? (int) $user_id : get_current_user_id();
  3649 	$user_id = $user_id ? (int) $user_id : get_current_user_id();
  3478 
  3650 
  3479 	if ( is_user_admin() )
  3651 	if ( is_user_admin() ) {
  3480 		$url = user_admin_url( 'profile.php', $scheme );
  3652 		$url = user_admin_url( 'profile.php', $scheme );
  3481 	elseif ( is_network_admin() )
  3653 	} elseif ( is_network_admin() ) {
  3482 		$url = network_admin_url( 'profile.php', $scheme );
  3654 		$url = network_admin_url( 'profile.php', $scheme );
  3483 	else
  3655 	} else {
  3484 		$url = get_dashboard_url( $user_id, 'profile.php', $scheme );
  3656 		$url = get_dashboard_url( $user_id, 'profile.php', $scheme );
       
  3657 	}
  3485 
  3658 
  3486 	/**
  3659 	/**
  3487 	 * Filters the URL for a user's profile editor.
  3660 	 * Filters the URL for a user's profile editor.
  3488 	 *
  3661 	 *
  3489 	 * @since 3.1.0
  3662 	 * @since 3.1.0
  3491 	 * @param string $url     The complete URL including scheme and path.
  3664 	 * @param string $url     The complete URL including scheme and path.
  3492 	 * @param int    $user_id The user ID.
  3665 	 * @param int    $user_id The user ID.
  3493 	 * @param string $scheme  Scheme to give the URL context. Accepts 'http', 'https', 'login',
  3666 	 * @param string $scheme  Scheme to give the URL context. Accepts 'http', 'https', 'login',
  3494 	 *                        'login_post', 'admin', 'relative' or null.
  3667 	 *                        'login_post', 'admin', 'relative' or null.
  3495 	 */
  3668 	 */
  3496 	return apply_filters( 'edit_profile_url', $url, $user_id, $scheme);
  3669 	return apply_filters( 'edit_profile_url', $url, $user_id, $scheme );
  3497 }
  3670 }
  3498 
  3671 
  3499 /**
  3672 /**
  3500  * Returns the canonical URL for a post.
  3673  * Returns the canonical URL for a post.
  3501  *
  3674  *
  3551 
  3724 
  3552 /**
  3725 /**
  3553  * Outputs rel=canonical for singular queries.
  3726  * Outputs rel=canonical for singular queries.
  3554  *
  3727  *
  3555  * @since 2.9.0
  3728  * @since 2.9.0
  3556  * @since 4.6.0 Adjusted to use wp_get_canonical_url().
  3729  * @since 4.6.0 Adjusted to use `wp_get_canonical_url()`.
  3557  */
  3730  */
  3558 function rel_canonical() {
  3731 function rel_canonical() {
  3559 	if ( ! is_singular() ) {
  3732 	if ( ! is_singular() ) {
  3560 		return;
  3733 		return;
  3561 	}
  3734 	}
  3580  * A plugin must hook in to provide the actual shortlinks. Default shortlink support is
  3753  * A plugin must hook in to provide the actual shortlinks. Default shortlink support is
  3581  * limited to providing ?p= style links for posts. Plugins can short-circuit this function
  3754  * limited to providing ?p= style links for posts. Plugins can short-circuit this function
  3582  * via the {@see 'pre_get_shortlink'} filter or filter the output via the {@see 'get_shortlink'}
  3755  * via the {@see 'pre_get_shortlink'} filter or filter the output via the {@see 'get_shortlink'}
  3583  * filter.
  3756  * filter.
  3584  *
  3757  *
  3585  * @since 3.0.0.
  3758  * @since 3.0.0
  3586  *
  3759  *
  3587  * @param int    $id          Optional. A post or site id. Default is 0, which means the current post or site.
  3760  * @param int    $id          Optional. A post or site id. Default is 0, which means the current post or site.
  3588  * @param string $context     Optional. Whether the id is a 'site' id, 'post' id, or 'media' id. If 'post',
  3761  * @param string $context     Optional. Whether the id is a 'site' id, 'post' id, or 'media' id. If 'post',
  3589  *                            the post_type of the post is consulted. If 'query', the current query is consulted
  3762  *                            the post_type of the post is consulted. If 'query', the current query is consulted
  3590  *                            to determine the id and context. Default 'post'.
  3763  *                            to determine the id and context. Default 'post'.
  3614 	}
  3787 	}
  3615 
  3788 
  3616 	$post_id = 0;
  3789 	$post_id = 0;
  3617 	if ( 'query' == $context && is_singular() ) {
  3790 	if ( 'query' == $context && is_singular() ) {
  3618 		$post_id = get_queried_object_id();
  3791 		$post_id = get_queried_object_id();
  3619 		$post = get_post( $post_id );
  3792 		$post    = get_post( $post_id );
  3620 	} elseif ( 'post' == $context ) {
  3793 	} elseif ( 'post' == $context ) {
  3621 		$post = get_post( $id );
  3794 		$post = get_post( $id );
  3622 		if ( ! empty( $post->ID ) )
  3795 		if ( ! empty( $post->ID ) ) {
  3623 			$post_id = $post->ID;
  3796 			$post_id = $post->ID;
       
  3797 		}
  3624 	}
  3798 	}
  3625 
  3799 
  3626 	$shortlink = '';
  3800 	$shortlink = '';
  3627 
  3801 
  3628 	// Return p= link for all public post types.
  3802 	// Return p= link for all public post types.
  3657  * @since 3.0.0
  3831  * @since 3.0.0
  3658  */
  3832  */
  3659 function wp_shortlink_wp_head() {
  3833 function wp_shortlink_wp_head() {
  3660 	$shortlink = wp_get_shortlink( 0, 'query' );
  3834 	$shortlink = wp_get_shortlink( 0, 'query' );
  3661 
  3835 
  3662 	if ( empty( $shortlink ) )
  3836 	if ( empty( $shortlink ) ) {
  3663 		return;
  3837 		return;
       
  3838 	}
  3664 
  3839 
  3665 	echo "<link rel='shortlink' href='" . esc_url( $shortlink ) . "' />\n";
  3840 	echo "<link rel='shortlink' href='" . esc_url( $shortlink ) . "' />\n";
  3666 }
  3841 }
  3667 
  3842 
  3668 /**
  3843 /**
  3671  * Attached to the {@see 'wp'} action.
  3846  * Attached to the {@see 'wp'} action.
  3672  *
  3847  *
  3673  * @since 3.0.0
  3848  * @since 3.0.0
  3674  */
  3849  */
  3675 function wp_shortlink_header() {
  3850 function wp_shortlink_header() {
  3676 	if ( headers_sent() )
  3851 	if ( headers_sent() ) {
  3677 		return;
  3852 		return;
  3678 
  3853 	}
  3679 	$shortlink = wp_get_shortlink(0, 'query');
  3854 
  3680 
  3855 	$shortlink = wp_get_shortlink( 0, 'query' );
  3681 	if ( empty($shortlink) )
  3856 
       
  3857 	if ( empty( $shortlink ) ) {
  3682 		return;
  3858 		return;
  3683 
  3859 	}
  3684 	header('Link: <' . $shortlink . '>; rel=shortlink', false);
  3860 
       
  3861 	header( 'Link: <' . $shortlink . '>; rel=shortlink', false );
  3685 }
  3862 }
  3686 
  3863 
  3687 /**
  3864 /**
  3688  * Displays the shortlink for a post.
  3865  * Displays the shortlink for a post.
  3689  *
  3866  *
  3699  * @param string $after  Optional HTML to display after the link. Default empty.
  3876  * @param string $after  Optional HTML to display after the link. Default empty.
  3700  */
  3877  */
  3701 function the_shortlink( $text = '', $title = '', $before = '', $after = '' ) {
  3878 function the_shortlink( $text = '', $title = '', $before = '', $after = '' ) {
  3702 	$post = get_post();
  3879 	$post = get_post();
  3703 
  3880 
  3704 	if ( empty( $text ) )
  3881 	if ( empty( $text ) ) {
  3705 		$text = __('This is the short link.');
  3882 		$text = __( 'This is the short link.' );
  3706 
  3883 	}
  3707 	if ( empty( $title ) )
  3884 
       
  3885 	if ( empty( $title ) ) {
  3708 		$title = the_title_attribute( array( 'echo' => false ) );
  3886 		$title = the_title_attribute( array( 'echo' => false ) );
       
  3887 	}
  3709 
  3888 
  3710 	$shortlink = wp_get_shortlink( $post->ID );
  3889 	$shortlink = wp_get_shortlink( $post->ID );
  3711 
  3890 
  3712 	if ( !empty( $shortlink ) ) {
  3891 	if ( ! empty( $shortlink ) ) {
  3713 		$link = '<a rel="shortlink" href="' . esc_url( $shortlink ) . '" title="' . $title . '">' . $text . '</a>';
  3892 		$link = '<a rel="shortlink" href="' . esc_url( $shortlink ) . '" title="' . $title . '">' . $text . '</a>';
  3714 
  3893 
  3715 		/**
  3894 		/**
  3716 		 * Filters the short link anchor tag for a post.
  3895 		 * Filters the short link anchor tag for a post.
  3717 		 *
  3896 		 *
  3757  */
  3936  */
  3758 function get_avatar_url( $id_or_email, $args = null ) {
  3937 function get_avatar_url( $id_or_email, $args = null ) {
  3759 	$args = get_avatar_data( $id_or_email, $args );
  3938 	$args = get_avatar_data( $id_or_email, $args );
  3760 	return $args['url'];
  3939 	return $args['url'];
  3761 }
  3940 }
       
  3941 
       
  3942 
       
  3943 /**
       
  3944  * Check if this comment type allows avatars to be retrieved.
       
  3945  *
       
  3946  * @since 5.1.0
       
  3947  *
       
  3948  * @param string $comment_type Comment type to check.
       
  3949  * @return bool Whether the comment type is allowed for retrieving avatars.
       
  3950  */
       
  3951 function is_avatar_comment_type( $comment_type ) {
       
  3952 	/**
       
  3953 	 * Filters the list of allowed comment types for retrieving avatars.
       
  3954 	 *
       
  3955 	 * @since 3.0.0
       
  3956 	 *
       
  3957 	 * @param array $types An array of content types. Default only contains 'comment'.
       
  3958 	 */
       
  3959 	$allowed_comment_types = apply_filters( 'get_avatar_comment_types', array( 'comment' ) );
       
  3960 
       
  3961 	return in_array( $comment_type, (array) $allowed_comment_types, true );
       
  3962 }
       
  3963 
  3762 
  3964 
  3763 /**
  3965 /**
  3764  * Retrieves default data about the avatar.
  3966  * Retrieves default data about the avatar.
  3765  *
  3967  *
  3766  * @since 4.2.0
  3968  * @since 4.2.0
  3795  *                                false or not set if we couldn't.
  3997  *                                false or not set if we couldn't.
  3796  *     @type string $url          The URL of the avatar we found.
  3998  *     @type string $url          The URL of the avatar we found.
  3797  * }
  3999  * }
  3798  */
  4000  */
  3799 function get_avatar_data( $id_or_email, $args = null ) {
  4001 function get_avatar_data( $id_or_email, $args = null ) {
  3800 	$args = wp_parse_args( $args, array(
  4002 	$args = wp_parse_args(
  3801 		'size'           => 96,
  4003 		$args,
  3802 		'height'         => null,
  4004 		array(
  3803 		'width'          => null,
  4005 			'size'           => 96,
  3804 		'default'        => get_option( 'avatar_default', 'mystery' ),
  4006 			'height'         => null,
  3805 		'force_default'  => false,
  4007 			'width'          => null,
  3806 		'rating'         => get_option( 'avatar_rating' ),
  4008 			'default'        => get_option( 'avatar_default', 'mystery' ),
  3807 		'scheme'         => null,
  4009 			'force_default'  => false,
  3808 		'processed_args' => null, // if used, should be a reference
  4010 			'rating'         => get_option( 'avatar_rating' ),
  3809 		'extra_attr'     => '',
  4011 			'scheme'         => null,
  3810 	) );
  4012 			'processed_args' => null, // if used, should be a reference
       
  4013 			'extra_attr'     => '',
       
  4014 		)
       
  4015 	);
  3811 
  4016 
  3812 	if ( is_numeric( $args['size'] ) ) {
  4017 	if ( is_numeric( $args['size'] ) ) {
  3813 		$args['size'] = absint( $args['size'] );
  4018 		$args['size'] = absint( $args['size'] );
  3814 		if ( ! $args['size'] ) {
  4019 		if ( ! $args['size'] ) {
  3815 			$args['size'] = 96;
  4020 			$args['size'] = 96;
  3839 	if ( empty( $args['default'] ) ) {
  4044 	if ( empty( $args['default'] ) ) {
  3840 		$args['default'] = get_option( 'avatar_default', 'mystery' );
  4045 		$args['default'] = get_option( 'avatar_default', 'mystery' );
  3841 	}
  4046 	}
  3842 
  4047 
  3843 	switch ( $args['default'] ) {
  4048 	switch ( $args['default'] ) {
  3844 		case 'mm' :
  4049 		case 'mm':
  3845 		case 'mystery' :
  4050 		case 'mystery':
  3846 		case 'mysteryman' :
  4051 		case 'mysteryman':
  3847 			$args['default'] = 'mm';
  4052 			$args['default'] = 'mm';
  3848 			break;
  4053 			break;
  3849 		case 'gravatar_default' :
  4054 		case 'gravatar_default':
  3850 			$args['default'] = false;
  4055 			$args['default'] = false;
  3851 			break;
  4056 			break;
  3852 	}
  4057 	}
  3853 
  4058 
  3854 	$args['force_default'] = (bool) $args['force_default'];
  4059 	$args['force_default'] = (bool) $args['force_default'];
  3870 	 * @param mixed  $id_or_email The Gravatar to retrieve. Accepts a user_id, gravatar md5 hash,
  4075 	 * @param mixed  $id_or_email The Gravatar to retrieve. Accepts a user_id, gravatar md5 hash,
  3871 	 *                            user email, WP_User object, WP_Post object, or WP_Comment object.
  4076 	 *                            user email, WP_User object, WP_Post object, or WP_Comment object.
  3872 	 */
  4077 	 */
  3873 	$args = apply_filters( 'pre_get_avatar_data', $args, $id_or_email );
  4078 	$args = apply_filters( 'pre_get_avatar_data', $args, $id_or_email );
  3874 
  4079 
  3875 	if ( isset( $args['url'] ) && ! is_null( $args['url'] ) ) {
  4080 	if ( isset( $args['url'] ) ) {
  3876 		/** This filter is documented in wp-includes/link-template.php */
  4081 		/** This filter is documented in wp-includes/link-template.php */
  3877 		return apply_filters( 'get_avatar_data', $args, $id_or_email );
  4082 		return apply_filters( 'get_avatar_data', $args, $id_or_email );
  3878 	}
  4083 	}
  3879 
  4084 
  3880 	$email_hash = '';
  4085 	$email_hash = '';
  3881 	$user = $email = false;
  4086 	$user       = $email = false;
  3882 
  4087 
  3883 	if ( is_object( $id_or_email ) && isset( $id_or_email->comment_ID ) ) {
  4088 	if ( is_object( $id_or_email ) && isset( $id_or_email->comment_ID ) ) {
  3884 		$id_or_email = get_comment( $id_or_email );
  4089 		$id_or_email = get_comment( $id_or_email );
  3885 	}
  4090 	}
  3886 
  4091 
  3900 		$user = $id_or_email;
  4105 		$user = $id_or_email;
  3901 	} elseif ( $id_or_email instanceof WP_Post ) {
  4106 	} elseif ( $id_or_email instanceof WP_Post ) {
  3902 		// Post Object
  4107 		// Post Object
  3903 		$user = get_user_by( 'id', (int) $id_or_email->post_author );
  4108 		$user = get_user_by( 'id', (int) $id_or_email->post_author );
  3904 	} elseif ( $id_or_email instanceof WP_Comment ) {
  4109 	} elseif ( $id_or_email instanceof WP_Comment ) {
  3905 		/**
  4110 		if ( ! is_avatar_comment_type( get_comment_type( $id_or_email ) ) ) {
  3906 		 * Filters the list of allowed comment types for retrieving avatars.
       
  3907 		 *
       
  3908 		 * @since 3.0.0
       
  3909 		 *
       
  3910 		 * @param array $types An array of content types. Default only contains 'comment'.
       
  3911 		 */
       
  3912 		$allowed_comment_types = apply_filters( 'get_avatar_comment_types', array( 'comment' ) );
       
  3913 		if ( ! empty( $id_or_email->comment_type ) && ! in_array( $id_or_email->comment_type, (array) $allowed_comment_types ) ) {
       
  3914 			$args['url'] = false;
  4111 			$args['url'] = false;
  3915 			/** This filter is documented in wp-includes/link-template.php */
  4112 			/** This filter is documented in wp-includes/link-template.php */
  3916 			return apply_filters( 'get_avatar_data', $args, $id_or_email );
  4113 			return apply_filters( 'get_avatar_data', $args, $id_or_email );
  3917 		}
  4114 		}
  3918 
  4115 
  3934 		}
  4131 		}
  3935 	}
  4132 	}
  3936 
  4133 
  3937 	if ( $email_hash ) {
  4134 	if ( $email_hash ) {
  3938 		$args['found_avatar'] = true;
  4135 		$args['found_avatar'] = true;
  3939 		$gravatar_server = hexdec( $email_hash[0] ) % 3;
  4136 		$gravatar_server      = hexdec( $email_hash[0] ) % 3;
  3940 	} else {
  4137 	} else {
  3941 		$gravatar_server = rand( 0, 2 );
  4138 		$gravatar_server = rand( 0, 2 );
  3942 	}
  4139 	}
  3943 
  4140 
  3944 	$url_args = array(
  4141 	$url_args = array(