wp/wp-includes/link-template.php
changeset 18 be944660c56a
parent 16 a86126ab1dd4
child 19 3d72ae0968f4
equal deleted inserted replaced
17:34716fd837a4 18:be944660c56a
    85 		case 'id':
    85 		case 'id':
    86 		default:
    86 		default:
    87 			echo '<a id="post-' . $post->ID . '"></a>';
    87 			echo '<a id="post-' . $post->ID . '"></a>';
    88 			break;
    88 			break;
    89 	}
    89 	}
       
    90 }
       
    91 
       
    92 /**
       
    93  * Determine whether post should always use a plain permalink structure.
       
    94  *
       
    95  * @since 5.7.0
       
    96  *
       
    97  * @param WP_Post|int|null $post   Optional. Post ID or post object. Defaults to global $post.
       
    98  * @param bool|null        $sample Optional. Whether to force consideration based on sample links.
       
    99  *                                 If omitted, a sample link is generated if a post object is passed
       
   100  *                                 with the filter property set to 'sample'.
       
   101  * @return bool Whether to use a plain permalink structure.
       
   102  */
       
   103 function wp_force_plain_post_permalink( $post = null, $sample = null ) {
       
   104 	if (
       
   105 		null === $sample &&
       
   106 		is_object( $post ) &&
       
   107 		isset( $post->filter ) &&
       
   108 		'sample' === $post->filter
       
   109 	) {
       
   110 		$sample = true;
       
   111 	} else {
       
   112 		$post   = get_post( $post );
       
   113 		$sample = null !== $sample ? $sample : false;
       
   114 	}
       
   115 
       
   116 	if ( ! $post ) {
       
   117 		return true;
       
   118 	}
       
   119 
       
   120 	$post_status_obj = get_post_status_object( get_post_status( $post ) );
       
   121 	$post_type_obj   = get_post_type_object( get_post_type( $post ) );
       
   122 
       
   123 	if ( ! $post_status_obj || ! $post_type_obj ) {
       
   124 		return true;
       
   125 	}
       
   126 
       
   127 	if (
       
   128 		// Publicly viewable links never have plain permalinks.
       
   129 		is_post_status_viewable( $post_status_obj ) ||
       
   130 		(
       
   131 			// Private posts don't have plain permalinks if the user can read them.
       
   132 			$post_status_obj->private &&
       
   133 			current_user_can( 'read_post', $post->ID )
       
   134 		) ||
       
   135 		// Protected posts don't have plain links if getting a sample URL.
       
   136 		( $post_status_obj->protected && $sample )
       
   137 	) {
       
   138 		return false;
       
   139 	}
       
   140 
       
   141 	return true;
    90 }
   142 }
    91 
   143 
    92 /**
   144 /**
    93  * Retrieves the full permalink for the current post or post ID.
   145  * Retrieves the full permalink for the current post or post ID.
    94  *
   146  *
   162 	 * @param WP_Post $post      The post in question.
   214 	 * @param WP_Post $post      The post in question.
   163 	 * @param bool    $leavename Whether to keep the post name.
   215 	 * @param bool    $leavename Whether to keep the post name.
   164 	 */
   216 	 */
   165 	$permalink = apply_filters( 'pre_post_link', $permalink, $post, $leavename );
   217 	$permalink = apply_filters( 'pre_post_link', $permalink, $post, $leavename );
   166 
   218 
   167 	if ( $permalink && ! in_array( $post->post_status, array( 'draft', 'pending', 'auto-draft', 'future' ), true ) ) {
   219 	if (
       
   220 		$permalink &&
       
   221 		! wp_force_plain_post_permalink( $post )
       
   222 	) {
   168 
   223 
   169 		$category = '';
   224 		$category = '';
   170 		if ( strpos( $permalink, '%category%' ) !== false ) {
   225 		if ( strpos( $permalink, '%category%' ) !== false ) {
   171 			$cats = get_the_category( $post->ID );
   226 			$cats = get_the_category( $post->ID );
   172 			if ( $cats ) {
   227 			if ( $cats ) {
   272 
   327 
   273 	$post_link = $wp_rewrite->get_extra_permastruct( $post->post_type );
   328 	$post_link = $wp_rewrite->get_extra_permastruct( $post->post_type );
   274 
   329 
   275 	$slug = $post->post_name;
   330 	$slug = $post->post_name;
   276 
   331 
   277 	$draft_or_pending = get_post_status( $post ) && in_array( get_post_status( $post ), array( 'draft', 'pending', 'auto-draft', 'future' ), true );
   332 	$force_plain_link = wp_force_plain_post_permalink( $post );
   278 
   333 
   279 	$post_type = get_post_type_object( $post->post_type );
   334 	$post_type = get_post_type_object( $post->post_type );
   280 
   335 
   281 	if ( $post_type->hierarchical ) {
   336 	if ( $post_type->hierarchical ) {
   282 		$slug = get_page_uri( $post );
   337 		$slug = get_page_uri( $post );
   283 	}
   338 	}
   284 
   339 
   285 	if ( ! empty( $post_link ) && ( ! $draft_or_pending || $sample ) ) {
   340 	if ( ! empty( $post_link ) && ( ! $force_plain_link || $sample ) ) {
   286 		if ( ! $leavename ) {
   341 		if ( ! $leavename ) {
   287 			$post_link = str_replace( "%$post->post_type%", $slug, $post_link );
   342 			$post_link = str_replace( "%$post->post_type%", $slug, $post_link );
   288 		}
   343 		}
   289 		$post_link = home_url( user_trailingslashit( $post_link ) );
   344 		$post_link = home_url( user_trailingslashit( $post_link ) );
   290 	} else {
   345 	} else {
   291 		if ( $post_type->query_var && ( isset( $post->post_status ) && ! $draft_or_pending ) ) {
   346 		if ( $post_type->query_var && ( isset( $post->post_status ) && ! $force_plain_link ) ) {
   292 			$post_link = add_query_arg( $post_type->query_var, $slug, '' );
   347 			$post_link = add_query_arg( $post_type->query_var, $slug, '' );
   293 		} else {
   348 		} else {
   294 			$post_link = add_query_arg(
   349 			$post_link = add_query_arg(
   295 				array(
   350 				array(
   296 					'post_type' => $post->post_type,
   351 					'post_type' => $post->post_type,
   368 function _get_page_link( $post = false, $leavename = false, $sample = false ) {
   423 function _get_page_link( $post = false, $leavename = false, $sample = false ) {
   369 	global $wp_rewrite;
   424 	global $wp_rewrite;
   370 
   425 
   371 	$post = get_post( $post );
   426 	$post = get_post( $post );
   372 
   427 
   373 	$draft_or_pending = in_array( $post->post_status, array( 'draft', 'pending', 'auto-draft' ), true );
   428 	$force_plain_link = wp_force_plain_post_permalink( $post );
   374 
   429 
   375 	$link = $wp_rewrite->get_page_permastruct();
   430 	$link = $wp_rewrite->get_page_permastruct();
   376 
   431 
   377 	if ( ! empty( $link ) && ( ( isset( $post->post_status ) && ! $draft_or_pending ) || $sample ) ) {
   432 	if ( ! empty( $link ) && ( ( isset( $post->post_status ) && ! $force_plain_link ) || $sample ) ) {
   378 		if ( ! $leavename ) {
   433 		if ( ! $leavename ) {
   379 			$link = str_replace( '%pagename%', get_page_uri( $post ), $link );
   434 			$link = str_replace( '%pagename%', get_page_uri( $post ), $link );
   380 		}
   435 		}
   381 
   436 
   382 		$link = home_url( $link );
   437 		$link = home_url( $link );
   412 function get_attachment_link( $post = null, $leavename = false ) {
   467 function get_attachment_link( $post = null, $leavename = false ) {
   413 	global $wp_rewrite;
   468 	global $wp_rewrite;
   414 
   469 
   415 	$link = false;
   470 	$link = false;
   416 
   471 
   417 	$post   = get_post( $post );
   472 	$post             = get_post( $post );
   418 	$parent = ( $post->post_parent > 0 && $post->post_parent != $post->ID ) ? get_post( $post->post_parent ) : false;
   473 	$force_plain_link = wp_force_plain_post_permalink( $post );
   419 	if ( $parent && ! in_array( $parent->post_type, get_post_types(), true ) ) {
   474 	$parent_id        = $post->post_parent;
   420 		$parent = false;
   475 	$parent           = $parent_id ? get_post( $parent_id ) : false;
   421 	}
   476 	$parent_valid     = true; // Default for no parent.
   422 
   477 	if (
   423 	if ( $wp_rewrite->using_permalinks() && $parent ) {
   478 		$parent_id &&
       
   479 		(
       
   480 			$post->post_parent === $post->ID ||
       
   481 			! $parent ||
       
   482 			! is_post_type_viewable( get_post_type( $parent ) )
       
   483 		)
       
   484 	) {
       
   485 		// Post is either its own parent or parent post unavailable.
       
   486 		$parent_valid = false;
       
   487 	}
       
   488 
       
   489 	if ( $force_plain_link || ! $parent_valid ) {
       
   490 		$link = false;
       
   491 	} elseif ( $wp_rewrite->using_permalinks() && $parent ) {
   424 		if ( 'page' === $parent->post_type ) {
   492 		if ( 'page' === $parent->post_type ) {
   425 			$parentlink = _get_page_link( $post->post_parent ); // Ignores page_on_front.
   493 			$parentlink = _get_page_link( $post->post_parent ); // Ignores page_on_front.
   426 		} else {
   494 		} else {
   427 			$parentlink = get_permalink( $post->post_parent );
   495 			$parentlink = get_permalink( $post->post_parent );
   428 		}
   496 		}
   450 
   518 
   451 	/**
   519 	/**
   452 	 * Filters the permalink for an attachment.
   520 	 * Filters the permalink for an attachment.
   453 	 *
   521 	 *
   454 	 * @since 2.0.0
   522 	 * @since 2.0.0
       
   523 	 * @since 5.6.0 Providing an empty string will now disable
       
   524 	 *              the view attachment page link on the media modal.
   455 	 *
   525 	 *
   456 	 * @param string $link    The attachment's permalink.
   526 	 * @param string $link    The attachment's permalink.
   457 	 * @param int    $post_id Attachment ID.
   527 	 * @param int    $post_id Attachment ID.
   458 	 */
   528 	 */
   459 	return apply_filters( 'attachment_link', $link, $post->ID );
   529 	return apply_filters( 'attachment_link', $link, $post->ID );
   513 		$month = current_time( 'm' );
   583 		$month = current_time( 'm' );
   514 	}
   584 	}
   515 	$monthlink = $wp_rewrite->get_month_permastruct();
   585 	$monthlink = $wp_rewrite->get_month_permastruct();
   516 	if ( ! empty( $monthlink ) ) {
   586 	if ( ! empty( $monthlink ) ) {
   517 		$monthlink = str_replace( '%year%', $year, $monthlink );
   587 		$monthlink = str_replace( '%year%', $year, $monthlink );
   518 		$monthlink = str_replace( '%monthnum%', zeroise( intval( $month ), 2 ), $monthlink );
   588 		$monthlink = str_replace( '%monthnum%', zeroise( (int) $month, 2 ), $monthlink );
   519 		$monthlink = home_url( user_trailingslashit( $monthlink, 'month' ) );
   589 		$monthlink = home_url( user_trailingslashit( $monthlink, 'month' ) );
   520 	} else {
   590 	} else {
   521 		$monthlink = home_url( '?m=' . $year . zeroise( $month, 2 ) );
   591 		$monthlink = home_url( '?m=' . $year . zeroise( $month, 2 ) );
   522 	}
   592 	}
   523 
   593 
   558 	}
   628 	}
   559 
   629 
   560 	$daylink = $wp_rewrite->get_day_permastruct();
   630 	$daylink = $wp_rewrite->get_day_permastruct();
   561 	if ( ! empty( $daylink ) ) {
   631 	if ( ! empty( $daylink ) ) {
   562 		$daylink = str_replace( '%year%', $year, $daylink );
   632 		$daylink = str_replace( '%year%', $year, $daylink );
   563 		$daylink = str_replace( '%monthnum%', zeroise( intval( $month ), 2 ), $daylink );
   633 		$daylink = str_replace( '%monthnum%', zeroise( (int) $month, 2 ), $daylink );
   564 		$daylink = str_replace( '%day%', zeroise( intval( $day ), 2 ), $daylink );
   634 		$daylink = str_replace( '%day%', zeroise( (int) $day, 2 ), $daylink );
   565 		$daylink = home_url( user_trailingslashit( $daylink, 'day' ) );
   635 		$daylink = home_url( user_trailingslashit( $daylink, 'day' ) );
   566 	} else {
   636 	} else {
   567 		$daylink = home_url( '?m=' . $year . zeroise( $month, 2 ) . zeroise( $day, 2 ) );
   637 		$daylink = home_url( '?m=' . $year . zeroise( $month, 2 ) . zeroise( $day, 2 ) );
   568 	}
   638 	}
   569 
   639 
   618 function get_feed_link( $feed = '' ) {
   688 function get_feed_link( $feed = '' ) {
   619 	global $wp_rewrite;
   689 	global $wp_rewrite;
   620 
   690 
   621 	$permalink = $wp_rewrite->get_feed_permastruct();
   691 	$permalink = $wp_rewrite->get_feed_permastruct();
   622 
   692 
   623 	if ( '' !== $permalink ) {
   693 	if ( $permalink ) {
   624 		if ( false !== strpos( $feed, 'comments_' ) ) {
   694 		if ( false !== strpos( $feed, 'comments_' ) ) {
   625 			$feed      = str_replace( 'comments_', '', $feed );
   695 			$feed      = str_replace( 'comments_', '', $feed );
   626 			$permalink = $wp_rewrite->get_comment_feed_permastruct();
   696 			$permalink = $wp_rewrite->get_comment_feed_permastruct();
   627 		}
   697 		}
   628 
   698 
   663  * @since 2.2.0
   733  * @since 2.2.0
   664  *
   734  *
   665  * @param int    $post_id Optional. Post ID. Default is the ID of the global `$post`.
   735  * @param int    $post_id Optional. Post ID. Default is the ID of the global `$post`.
   666  * @param string $feed    Optional. Feed type. Possible values include 'rss2', 'atom'.
   736  * @param string $feed    Optional. Feed type. Possible values include 'rss2', 'atom'.
   667  *                        Default is the value of get_default_feed().
   737  *                        Default is the value of get_default_feed().
   668  * @return string The permalink for the comments feed for the given post.
   738  * @return string The permalink for the comments feed for the given post on success, empty string on failure.
   669  */
   739  */
   670 function get_post_comments_feed_link( $post_id = 0, $feed = '' ) {
   740 function get_post_comments_feed_link( $post_id = 0, $feed = '' ) {
   671 	$post_id = absint( $post_id );
   741 	$post_id = absint( $post_id );
   672 
   742 
   673 	if ( ! $post_id ) {
   743 	if ( ! $post_id ) {
   676 
   746 
   677 	if ( empty( $feed ) ) {
   747 	if ( empty( $feed ) ) {
   678 		$feed = get_default_feed();
   748 		$feed = get_default_feed();
   679 	}
   749 	}
   680 
   750 
   681 	$post       = get_post( $post_id );
   751 	$post = get_post( $post_id );
       
   752 
       
   753 	// Bail out if the post does not exist.
       
   754 	if ( ! $post instanceof WP_Post ) {
       
   755 		return '';
       
   756 	}
       
   757 
   682 	$unattached = 'attachment' === $post->post_type && 0 === (int) $post->post_parent;
   758 	$unattached = 'attachment' === $post->post_type && 0 === (int) $post->post_parent;
   683 
   759 
   684 	if ( get_option( 'permalink_structure' ) ) {
   760 	if ( get_option( 'permalink_structure' ) ) {
   685 		if ( 'page' === get_option( 'show_on_front' ) && get_option( 'page_on_front' ) == $post_id ) {
   761 		if ( 'page' === get_option( 'show_on_front' ) && get_option( 'page_on_front' ) == $post_id ) {
   686 			$url = _get_page_link( $post_id );
   762 			$url = _get_page_link( $post_id );
  1206  * @since 4.5.0 Support for posts was added.
  1282  * @since 4.5.0 Support for posts was added.
  1207  *
  1283  *
  1208  * @global WP_Rewrite $wp_rewrite WordPress rewrite component.
  1284  * @global WP_Rewrite $wp_rewrite WordPress rewrite component.
  1209  *
  1285  *
  1210  * @param string $post_type Post type.
  1286  * @param string $post_type Post type.
  1211  * @return string|false The post type archive permalink.
  1287  * @return string|false The post type archive permalink. False if the post type
       
  1288  *                      does not exist or does not have an archive.
  1212  */
  1289  */
  1213 function get_post_type_archive_link( $post_type ) {
  1290 function get_post_type_archive_link( $post_type ) {
  1214 	global $wp_rewrite;
  1291 	global $wp_rewrite;
  1215 
  1292 
  1216 	$post_type_obj = get_post_type_object( $post_type );
  1293 	$post_type_obj = get_post_type_object( $post_type );
  1261 /**
  1338 /**
  1262  * Retrieves the permalink for a post type archive feed.
  1339  * Retrieves the permalink for a post type archive feed.
  1263  *
  1340  *
  1264  * @since 3.1.0
  1341  * @since 3.1.0
  1265  *
  1342  *
  1266  * @param string $post_type Post type
  1343  * @param string $post_type Post type.
  1267  * @param string $feed      Optional. Feed type. Possible values include 'rss2', 'atom'.
  1344  * @param string $feed      Optional. Feed type. Possible values include 'rss2', 'atom'.
  1268  *                          Default is the value of get_default_feed().
  1345  *                          Default is the value of get_default_feed().
  1269  * @return string|false The post type feed permalink.
  1346  * @return string|false The post type feed permalink. False if the post type
       
  1347  *                      does not exist or does not have an archive.
  1270  */
  1348  */
  1271 function get_post_type_archive_feed_link( $post_type, $feed = '' ) {
  1349 function get_post_type_archive_feed_link( $post_type, $feed = '' ) {
  1272 	$default_feed = get_default_feed();
  1350 	$default_feed = get_default_feed();
  1273 	if ( empty( $feed ) ) {
  1351 	if ( empty( $feed ) ) {
  1274 		$feed = $default_feed;
  1352 		$feed = $default_feed;
  1351  *
  1429  *
  1352  * @since 2.3.0
  1430  * @since 2.3.0
  1353  *
  1431  *
  1354  * @param int|WP_Post $id      Optional. Post ID or post object. Default is the global `$post`.
  1432  * @param int|WP_Post $id      Optional. Post ID or post object. Default is the global `$post`.
  1355  * @param string      $context Optional. How to output the '&' character. Default '&amp;'.
  1433  * @param string      $context Optional. How to output the '&' character. Default '&amp;'.
  1356  * @return string|null The edit post link for the given post. null if the post type is invalid or does
  1434  * @return string|null The edit post link for the given post. Null if the post type does not exist
  1357  *                     not allow an editing UI.
  1435  *                     or does not allow an editing UI.
  1358  */
  1436  */
  1359 function get_edit_post_link( $id = 0, $context = 'display' ) {
  1437 function get_edit_post_link( $id = 0, $context = 'display' ) {
  1360 	$post = get_post( $id );
  1438 	$post = get_post( $id );
  1361 	if ( ! $post ) {
  1439 	if ( ! $post ) {
  1362 		return;
  1440 		return;
  1657  * Retrieves the previous post that is adjacent to the current post.
  1735  * Retrieves the previous post that is adjacent to the current post.
  1658  *
  1736  *
  1659  * @since 1.5.0
  1737  * @since 1.5.0
  1660  *
  1738  *
  1661  * @param bool         $in_same_term   Optional. Whether post should be in a same taxonomy term. Default false.
  1739  * @param bool         $in_same_term   Optional. Whether post should be in a same taxonomy term. Default false.
  1662  * @param array|string $excluded_terms Optional. Array or comma-separated list of excluded term IDs. Default empty.
  1740  * @param int[]|string $excluded_terms Optional. Array or comma-separated list of excluded term IDs. Default empty.
  1663  * @param string       $taxonomy       Optional. Taxonomy, if $in_same_term is true. Default 'category'.
  1741  * @param string       $taxonomy       Optional. Taxonomy, if $in_same_term is true. Default 'category'.
  1664  * @return null|string|WP_Post Post object if successful. Null if global $post is not set. Empty string if no
  1742  * @return null|string|WP_Post Post object if successful. Null if global $post is not set. Empty string if no
  1665  *                             corresponding post exists.
  1743  *                             corresponding post exists.
  1666  */
  1744  */
  1667 function get_previous_post( $in_same_term = false, $excluded_terms = '', $taxonomy = 'category' ) {
  1745 function get_previous_post( $in_same_term = false, $excluded_terms = '', $taxonomy = 'category' ) {
  1672  * Retrieves the next post that is adjacent to the current post.
  1750  * Retrieves the next post that is adjacent to the current post.
  1673  *
  1751  *
  1674  * @since 1.5.0
  1752  * @since 1.5.0
  1675  *
  1753  *
  1676  * @param bool         $in_same_term   Optional. Whether post should be in a same taxonomy term. Default false.
  1754  * @param bool         $in_same_term   Optional. Whether post should be in a same taxonomy term. Default false.
  1677  * @param array|string $excluded_terms Optional. Array or comma-separated list of excluded term IDs. Default empty.
  1755  * @param int[]|string $excluded_terms Optional. Array or comma-separated list of excluded term IDs. Default empty.
  1678  * @param string       $taxonomy       Optional. Taxonomy, if $in_same_term is true. Default 'category'.
  1756  * @param string       $taxonomy       Optional. Taxonomy, if $in_same_term is true. Default 'category'.
  1679  * @return null|string|WP_Post Post object if successful. Null if global $post is not set. Empty string if no
  1757  * @return null|string|WP_Post Post object if successful. Null if global $post is not set. Empty string if no
  1680  *                             corresponding post exists.
  1758  *                             corresponding post exists.
  1681  */
  1759  */
  1682 function get_next_post( $in_same_term = false, $excluded_terms = '', $taxonomy = 'category' ) {
  1760 function get_next_post( $in_same_term = false, $excluded_terms = '', $taxonomy = 'category' ) {
  1691  * @since 2.5.0
  1769  * @since 2.5.0
  1692  *
  1770  *
  1693  * @global wpdb $wpdb WordPress database abstraction object.
  1771  * @global wpdb $wpdb WordPress database abstraction object.
  1694  *
  1772  *
  1695  * @param bool         $in_same_term   Optional. Whether post should be in a same taxonomy term. Default false.
  1773  * @param bool         $in_same_term   Optional. Whether post should be in a same taxonomy term. Default false.
  1696  * @param array|string $excluded_terms Optional. Array or comma-separated list of excluded term IDs. Default empty.
  1774  * @param int[]|string $excluded_terms Optional. Array or comma-separated list of excluded term IDs. Default empty string.
  1697  * @param bool         $previous       Optional. Whether to retrieve previous post. Default true
  1775  * @param bool         $previous       Optional. Whether to retrieve previous post. Default true
  1698  * @param string       $taxonomy       Optional. Taxonomy, if $in_same_term is true. Default 'category'.
  1776  * @param string       $taxonomy       Optional. Taxonomy, if $in_same_term is true. Default 'category'.
  1699  * @return null|string|WP_Post Post object if successful. Null if global $post is not set. Empty string if no
  1777  * @return null|string|WP_Post Post object if successful. Null if global $post is not set. Empty string if no
  1700  *                             corresponding post exists.
  1778  *                             corresponding post exists.
  1701  */
  1779  */
  1737 	 * Filters the IDs of terms excluded from adjacent post queries.
  1815 	 * Filters the IDs of terms excluded from adjacent post queries.
  1738 	 *
  1816 	 *
  1739 	 * The dynamic portion of the hook name, `$adjacent`, refers to the type
  1817 	 * The dynamic portion of the hook name, `$adjacent`, refers to the type
  1740 	 * of adjacency, 'next' or 'previous'.
  1818 	 * of adjacency, 'next' or 'previous'.
  1741 	 *
  1819 	 *
       
  1820 	 * Possible hook names include:
       
  1821 	 *
       
  1822 	 *  - `get_next_post_excluded_terms`
       
  1823 	 *  - `get_previous_post_excluded_terms`
       
  1824 	 *
  1742 	 * @since 4.4.0
  1825 	 * @since 4.4.0
  1743 	 *
  1826 	 *
  1744 	 * @param array $excluded_terms Array of excluded term IDs.
  1827 	 * @param array|string $excluded_terms Array of excluded term IDs. Empty string if none were provided.
  1745 	 */
  1828 	 */
  1746 	$excluded_terms = apply_filters( "get_{$adjacent}_post_excluded_terms", $excluded_terms );
  1829 	$excluded_terms = apply_filters( "get_{$adjacent}_post_excluded_terms", $excluded_terms );
  1747 
  1830 
  1748 	if ( $in_same_term || ! empty( $excluded_terms ) ) {
  1831 	if ( $in_same_term || ! empty( $excluded_terms ) ) {
  1749 		if ( $in_same_term ) {
  1832 		if ( $in_same_term ) {
  1808 	 * Filters the JOIN clause in the SQL for an adjacent post query.
  1891 	 * Filters the JOIN clause in the SQL for an adjacent post query.
  1809 	 *
  1892 	 *
  1810 	 * The dynamic portion of the hook name, `$adjacent`, refers to the type
  1893 	 * The dynamic portion of the hook name, `$adjacent`, refers to the type
  1811 	 * of adjacency, 'next' or 'previous'.
  1894 	 * of adjacency, 'next' or 'previous'.
  1812 	 *
  1895 	 *
       
  1896 	 * Possible hook names include:
       
  1897 	 *
       
  1898 	 *  - `get_next_post_join`
       
  1899 	 *  - `get_previous_post_join`
       
  1900 	 *
  1813 	 * @since 2.5.0
  1901 	 * @since 2.5.0
  1814 	 * @since 4.4.0 Added the `$taxonomy` and `$post` parameters.
  1902 	 * @since 4.4.0 Added the `$taxonomy` and `$post` parameters.
  1815 	 *
  1903 	 *
  1816 	 * @param string  $join           The JOIN clause in the SQL.
  1904 	 * @param string  $join           The JOIN clause in the SQL.
  1817 	 * @param bool    $in_same_term   Whether post should be in a same taxonomy term.
  1905 	 * @param bool    $in_same_term   Whether post should be in a same taxonomy term.
  1825 	 * Filters the WHERE clause in the SQL for an adjacent post query.
  1913 	 * Filters the WHERE clause in the SQL for an adjacent post query.
  1826 	 *
  1914 	 *
  1827 	 * The dynamic portion of the hook name, `$adjacent`, refers to the type
  1915 	 * The dynamic portion of the hook name, `$adjacent`, refers to the type
  1828 	 * of adjacency, 'next' or 'previous'.
  1916 	 * of adjacency, 'next' or 'previous'.
  1829 	 *
  1917 	 *
       
  1918 	 * Possible hook names include:
       
  1919 	 *
       
  1920 	 *  - `get_next_post_where`
       
  1921 	 *  - `get_previous_post_where`
       
  1922 	 *
  1830 	 * @since 2.5.0
  1923 	 * @since 2.5.0
  1831 	 * @since 4.4.0 Added the `$taxonomy` and `$post` parameters.
  1924 	 * @since 4.4.0 Added the `$taxonomy` and `$post` parameters.
  1832 	 *
  1925 	 *
  1833 	 * @param string  $where          The `WHERE` clause in the SQL.
  1926 	 * @param string  $where          The `WHERE` clause in the SQL.
  1834 	 * @param bool    $in_same_term   Whether post should be in a same taxonomy term.
  1927 	 * @param bool    $in_same_term   Whether post should be in a same taxonomy term.
  1841 	/**
  1934 	/**
  1842 	 * Filters the ORDER BY clause in the SQL for an adjacent post query.
  1935 	 * Filters the ORDER BY clause in the SQL for an adjacent post query.
  1843 	 *
  1936 	 *
  1844 	 * The dynamic portion of the hook name, `$adjacent`, refers to the type
  1937 	 * The dynamic portion of the hook name, `$adjacent`, refers to the type
  1845 	 * of adjacency, 'next' or 'previous'.
  1938 	 * of adjacency, 'next' or 'previous'.
       
  1939 	 *
       
  1940 	 * Possible hook names include:
       
  1941 	 *
       
  1942 	 *  - `get_next_post_sort`
       
  1943 	 *  - `get_previous_post_sort`
  1846 	 *
  1944 	 *
  1847 	 * @since 2.5.0
  1945 	 * @since 2.5.0
  1848 	 * @since 4.4.0 Added the `$post` parameter.
  1946 	 * @since 4.4.0 Added the `$post` parameter.
  1849 	 * @since 4.9.0 Added the `$order` parameter.
  1947 	 * @since 4.9.0 Added the `$order` parameter.
  1850 	 *
  1948 	 *
  1885  *
  1983  *
  1886  * @since 2.8.0
  1984  * @since 2.8.0
  1887  *
  1985  *
  1888  * @param string       $title          Optional. Link title format. Default '%title'.
  1986  * @param string       $title          Optional. Link title format. Default '%title'.
  1889  * @param bool         $in_same_term   Optional. Whether link should be in a same taxonomy term. Default false.
  1987  * @param bool         $in_same_term   Optional. Whether link should be in a same taxonomy term. Default false.
  1890  * @param array|string $excluded_terms Optional. Array or comma-separated list of excluded term IDs. Default empty.
  1988  * @param int[]|string $excluded_terms Optional. Array or comma-separated list of excluded term IDs. Default empty.
  1891  * @param bool         $previous       Optional. Whether to display link to previous or next post. Default true.
  1989  * @param bool         $previous       Optional. Whether to display link to previous or next post. Default true.
  1892  * @param string       $taxonomy       Optional. Taxonomy, if $in_same_term is true. Default 'category'.
  1990  * @param string       $taxonomy       Optional. Taxonomy, if $in_same_term is true. Default 'category'.
  1893  * @return string|void The adjacent post relational link URL.
  1991  * @return string|void The adjacent post relational link URL.
  1894  */
  1992  */
  1895 function get_adjacent_post_rel_link( $title = '%title', $in_same_term = false, $excluded_terms = '', $previous = true, $taxonomy = 'category' ) {
  1993 function get_adjacent_post_rel_link( $title = '%title', $in_same_term = false, $excluded_terms = '', $previous = true, $taxonomy = 'category' ) {
  1930 	 * Filters the adjacent post relational link.
  2028 	 * Filters the adjacent post relational link.
  1931 	 *
  2029 	 *
  1932 	 * The dynamic portion of the hook name, `$adjacent`, refers to the type
  2030 	 * The dynamic portion of the hook name, `$adjacent`, refers to the type
  1933 	 * of adjacency, 'next' or 'previous'.
  2031 	 * of adjacency, 'next' or 'previous'.
  1934 	 *
  2032 	 *
       
  2033 	 * Possible hook names include:
       
  2034 	 *
       
  2035 	 *  - `next_post_rel_link`
       
  2036 	 *  - `previous_post_rel_link`
       
  2037 	 *
  1935 	 * @since 2.8.0
  2038 	 * @since 2.8.0
  1936 	 *
  2039 	 *
  1937 	 * @param string $link The relational link.
  2040 	 * @param string $link The relational link.
  1938 	 */
  2041 	 */
  1939 	return apply_filters( "{$adjacent}_post_rel_link", $link );
  2042 	return apply_filters( "{$adjacent}_post_rel_link", $link );
  1944  *
  2047  *
  1945  * @since 2.8.0
  2048  * @since 2.8.0
  1946  *
  2049  *
  1947  * @param string       $title          Optional. Link title format. Default '%title'.
  2050  * @param string       $title          Optional. Link title format. Default '%title'.
  1948  * @param bool         $in_same_term   Optional. Whether link should be in a same taxonomy term. Default false.
  2051  * @param bool         $in_same_term   Optional. Whether link should be in a same taxonomy term. Default false.
  1949  * @param array|string $excluded_terms Optional. Array or comma-separated list of excluded term IDs. Default empty.
  2052  * @param int[]|string $excluded_terms Optional. Array or comma-separated list of excluded term IDs. Default empty.
  1950  * @param string       $taxonomy       Optional. Taxonomy, if $in_same_term is true. Default 'category'.
  2053  * @param string       $taxonomy       Optional. Taxonomy, if $in_same_term is true. Default 'category'.
  1951  */
  2054  */
  1952 function adjacent_posts_rel_link( $title = '%title', $in_same_term = false, $excluded_terms = '', $taxonomy = 'category' ) {
  2055 function adjacent_posts_rel_link( $title = '%title', $in_same_term = false, $excluded_terms = '', $taxonomy = 'category' ) {
  1953 	echo get_adjacent_post_rel_link( $title, $in_same_term, $excluded_terms, true, $taxonomy );
  2056 	echo get_adjacent_post_rel_link( $title, $in_same_term, $excluded_terms, true, $taxonomy );
  1954 	echo get_adjacent_post_rel_link( $title, $in_same_term, $excluded_terms, false, $taxonomy );
  2057 	echo get_adjacent_post_rel_link( $title, $in_same_term, $excluded_terms, false, $taxonomy );
  1959  *
  2062  *
  1960  * This is meant to be attached to actions like 'wp_head'. Do not call this directly in plugins
  2063  * This is meant to be attached to actions like 'wp_head'. Do not call this directly in plugins
  1961  * or theme templates.
  2064  * or theme templates.
  1962  *
  2065  *
  1963  * @since 3.0.0
  2066  * @since 3.0.0
       
  2067  * @since 5.6.0 No longer used in core.
  1964  *
  2068  *
  1965  * @see adjacent_posts_rel_link()
  2069  * @see adjacent_posts_rel_link()
  1966  */
  2070  */
  1967 function adjacent_posts_rel_link_wp_head() {
  2071 function adjacent_posts_rel_link_wp_head() {
  1968 	if ( ! is_single() || is_attachment() ) {
  2072 	if ( ! is_single() || is_attachment() ) {
  1978  *
  2082  *
  1979  * @see get_adjacent_post_rel_link()
  2083  * @see get_adjacent_post_rel_link()
  1980  *
  2084  *
  1981  * @param string       $title          Optional. Link title format. Default '%title'.
  2085  * @param string       $title          Optional. Link title format. Default '%title'.
  1982  * @param bool         $in_same_term   Optional. Whether link should be in a same taxonomy term. Default false.
  2086  * @param bool         $in_same_term   Optional. Whether link should be in a same taxonomy term. Default false.
  1983  * @param array|string $excluded_terms Optional. Array or comma-separated list of excluded term IDs. Default empty.
  2087  * @param int[]|string $excluded_terms Optional. Array or comma-separated list of excluded term IDs. Default empty.
  1984  * @param string       $taxonomy       Optional. Taxonomy, if $in_same_term is true. Default 'category'.
  2088  * @param string       $taxonomy       Optional. Taxonomy, if $in_same_term is true. Default 'category'.
  1985  */
  2089  */
  1986 function next_post_rel_link( $title = '%title', $in_same_term = false, $excluded_terms = '', $taxonomy = 'category' ) {
  2090 function next_post_rel_link( $title = '%title', $in_same_term = false, $excluded_terms = '', $taxonomy = 'category' ) {
  1987 	echo get_adjacent_post_rel_link( $title, $in_same_term, $excluded_terms, false, $taxonomy );
  2091 	echo get_adjacent_post_rel_link( $title, $in_same_term, $excluded_terms, false, $taxonomy );
  1988 }
  2092 }
  1994  *
  2098  *
  1995  * @see get_adjacent_post_rel_link()
  2099  * @see get_adjacent_post_rel_link()
  1996  *
  2100  *
  1997  * @param string       $title          Optional. Link title format. Default '%title'.
  2101  * @param string       $title          Optional. Link title format. Default '%title'.
  1998  * @param bool         $in_same_term   Optional. Whether link should be in a same taxonomy term. Default false.
  2102  * @param bool         $in_same_term   Optional. Whether link should be in a same taxonomy term. Default false.
  1999  * @param array|string $excluded_terms Optional. Array or comma-separated list of excluded term IDs. Default true.
  2103  * @param int[]|string $excluded_terms Optional. Array or comma-separated list of excluded term IDs. Default true.
  2000  * @param string       $taxonomy       Optional. Taxonomy, if $in_same_term is true. Default 'category'.
  2104  * @param string       $taxonomy       Optional. Taxonomy, if $in_same_term is true. Default 'category'.
  2001  */
  2105  */
  2002 function prev_post_rel_link( $title = '%title', $in_same_term = false, $excluded_terms = '', $taxonomy = 'category' ) {
  2106 function prev_post_rel_link( $title = '%title', $in_same_term = false, $excluded_terms = '', $taxonomy = 'category' ) {
  2003 	echo get_adjacent_post_rel_link( $title, $in_same_term, $excluded_terms, true, $taxonomy );
  2107 	echo get_adjacent_post_rel_link( $title, $in_same_term, $excluded_terms, true, $taxonomy );
  2004 }
  2108 }
  2011  *
  2115  *
  2012  * @since 2.8.0
  2116  * @since 2.8.0
  2013  *
  2117  *
  2014  * @param bool         $in_same_term   Optional. Whether returned post should be in a same taxonomy term.
  2118  * @param bool         $in_same_term   Optional. Whether returned post should be in a same taxonomy term.
  2015  *                                     Default false.
  2119  *                                     Default false.
  2016  * @param array|string $excluded_terms Optional. Array or comma-separated list of excluded term IDs.
  2120  * @param int[]|string $excluded_terms Optional. Array or comma-separated list of excluded term IDs.
  2017  *                                     Default empty.
  2121  *                                     Default empty.
  2018  * @param bool         $start          Optional. Whether to retrieve first or last post. Default true
  2122  * @param bool         $start          Optional. Whether to retrieve first or last post. Default true
  2019  * @param string       $taxonomy       Optional. Taxonomy, if $in_same_term is true. Default 'category'.
  2123  * @param string       $taxonomy       Optional. Taxonomy, if $in_same_term is true. Default 'category'.
  2020  * @return null|array Array containing the boundary post object if successful, null otherwise.
  2124  * @return null|array Array containing the boundary post object if successful, null otherwise.
  2021  */
  2125  */
  2075  * @since 3.7.0
  2179  * @since 3.7.0
  2076  *
  2180  *
  2077  * @param string       $format         Optional. Link anchor format. Default '&laquo; %link'.
  2181  * @param string       $format         Optional. Link anchor format. Default '&laquo; %link'.
  2078  * @param string       $link           Optional. Link permalink format. Default '%title'.
  2182  * @param string       $link           Optional. Link permalink format. Default '%title'.
  2079  * @param bool         $in_same_term   Optional. Whether link should be in a same taxonomy term. Default false.
  2183  * @param bool         $in_same_term   Optional. Whether link should be in a same taxonomy term. Default false.
  2080  * @param array|string $excluded_terms Optional. Array or comma-separated list of excluded term IDs. Default empty.
  2184  * @param int[]|string $excluded_terms Optional. Array or comma-separated list of excluded term IDs. Default empty.
  2081  * @param string       $taxonomy       Optional. Taxonomy, if $in_same_term is true. Default 'category'.
  2185  * @param string       $taxonomy       Optional. Taxonomy, if $in_same_term is true. Default 'category'.
  2082  * @return string The link URL of the previous post in relation to the current post.
  2186  * @return string The link URL of the previous post in relation to the current post.
  2083  */
  2187  */
  2084 function get_previous_post_link( $format = '&laquo; %link', $link = '%title', $in_same_term = false, $excluded_terms = '', $taxonomy = 'category' ) {
  2188 function get_previous_post_link( $format = '&laquo; %link', $link = '%title', $in_same_term = false, $excluded_terms = '', $taxonomy = 'category' ) {
  2085 	return get_adjacent_post_link( $format, $link, $in_same_term, $excluded_terms, true, $taxonomy );
  2189 	return get_adjacent_post_link( $format, $link, $in_same_term, $excluded_terms, true, $taxonomy );
  2093  * @see get_previous_post_link()
  2197  * @see get_previous_post_link()
  2094  *
  2198  *
  2095  * @param string       $format         Optional. Link anchor format. Default '&laquo; %link'.
  2199  * @param string       $format         Optional. Link anchor format. Default '&laquo; %link'.
  2096  * @param string       $link           Optional. Link permalink format. Default '%title'.
  2200  * @param string       $link           Optional. Link permalink format. Default '%title'.
  2097  * @param bool         $in_same_term   Optional. Whether link should be in a same taxonomy term. Default false.
  2201  * @param bool         $in_same_term   Optional. Whether link should be in a same taxonomy term. Default false.
  2098  * @param array|string $excluded_terms Optional. Array or comma-separated list of excluded term IDs. Default empty.
  2202  * @param int[]|string $excluded_terms Optional. Array or comma-separated list of excluded term IDs. Default empty.
  2099  * @param string       $taxonomy       Optional. Taxonomy, if $in_same_term is true. Default 'category'.
  2203  * @param string       $taxonomy       Optional. Taxonomy, if $in_same_term is true. Default 'category'.
  2100  */
  2204  */
  2101 function previous_post_link( $format = '&laquo; %link', $link = '%title', $in_same_term = false, $excluded_terms = '', $taxonomy = 'category' ) {
  2205 function previous_post_link( $format = '&laquo; %link', $link = '%title', $in_same_term = false, $excluded_terms = '', $taxonomy = 'category' ) {
  2102 	echo get_previous_post_link( $format, $link, $in_same_term, $excluded_terms, $taxonomy );
  2206 	echo get_previous_post_link( $format, $link, $in_same_term, $excluded_terms, $taxonomy );
  2103 }
  2207 }
  2108  * @since 3.7.0
  2212  * @since 3.7.0
  2109  *
  2213  *
  2110  * @param string       $format         Optional. Link anchor format. Default '&laquo; %link'.
  2214  * @param string       $format         Optional. Link anchor format. Default '&laquo; %link'.
  2111  * @param string       $link           Optional. Link permalink format. Default '%title'.
  2215  * @param string       $link           Optional. Link permalink format. Default '%title'.
  2112  * @param bool         $in_same_term   Optional. Whether link should be in a same taxonomy term. Default false.
  2216  * @param bool         $in_same_term   Optional. Whether link should be in a same taxonomy term. Default false.
  2113  * @param array|string $excluded_terms Optional. Array or comma-separated list of excluded term IDs. Default empty.
  2217  * @param int[]|string $excluded_terms Optional. Array or comma-separated list of excluded term IDs. Default empty.
  2114  * @param string       $taxonomy       Optional. Taxonomy, if $in_same_term is true. Default 'category'.
  2218  * @param string       $taxonomy       Optional. Taxonomy, if $in_same_term is true. Default 'category'.
  2115  * @return string The link URL of the next post in relation to the current post.
  2219  * @return string The link URL of the next post in relation to the current post.
  2116  */
  2220  */
  2117 function get_next_post_link( $format = '%link &raquo;', $link = '%title', $in_same_term = false, $excluded_terms = '', $taxonomy = 'category' ) {
  2221 function get_next_post_link( $format = '%link &raquo;', $link = '%title', $in_same_term = false, $excluded_terms = '', $taxonomy = 'category' ) {
  2118 	return get_adjacent_post_link( $format, $link, $in_same_term, $excluded_terms, false, $taxonomy );
  2222 	return get_adjacent_post_link( $format, $link, $in_same_term, $excluded_terms, false, $taxonomy );
  2126  * @see get_next_post_link()
  2230  * @see get_next_post_link()
  2127  *
  2231  *
  2128  * @param string       $format         Optional. Link anchor format. Default '&laquo; %link'.
  2232  * @param string       $format         Optional. Link anchor format. Default '&laquo; %link'.
  2129  * @param string       $link           Optional. Link permalink format. Default '%title'
  2233  * @param string       $link           Optional. Link permalink format. Default '%title'
  2130  * @param bool         $in_same_term   Optional. Whether link should be in a same taxonomy term. Default false.
  2234  * @param bool         $in_same_term   Optional. Whether link should be in a same taxonomy term. Default false.
  2131  * @param array|string $excluded_terms Optional. Array or comma-separated list of excluded term IDs. Default empty.
  2235  * @param int[]|string $excluded_terms Optional. Array or comma-separated list of excluded term IDs. Default empty.
  2132  * @param string       $taxonomy       Optional. Taxonomy, if $in_same_term is true. Default 'category'.
  2236  * @param string       $taxonomy       Optional. Taxonomy, if $in_same_term is true. Default 'category'.
  2133  */
  2237  */
  2134 function next_post_link( $format = '%link &raquo;', $link = '%title', $in_same_term = false, $excluded_terms = '', $taxonomy = 'category' ) {
  2238 function next_post_link( $format = '%link &raquo;', $link = '%title', $in_same_term = false, $excluded_terms = '', $taxonomy = 'category' ) {
  2135 	echo get_next_post_link( $format, $link, $in_same_term, $excluded_terms, $taxonomy );
  2239 	echo get_next_post_link( $format, $link, $in_same_term, $excluded_terms, $taxonomy );
  2136 }
  2240 }
  2143  * @since 3.7.0
  2247  * @since 3.7.0
  2144  *
  2248  *
  2145  * @param string       $format         Link anchor format.
  2249  * @param string       $format         Link anchor format.
  2146  * @param string       $link           Link permalink format.
  2250  * @param string       $link           Link permalink format.
  2147  * @param bool         $in_same_term   Optional. Whether link should be in a same taxonomy term. Default false.
  2251  * @param bool         $in_same_term   Optional. Whether link should be in a same taxonomy term. Default false.
  2148  * @param array|string $excluded_terms Optional. Array or comma-separated list of excluded terms IDs. Default empty.
  2252  * @param int[]|string $excluded_terms Optional. Array or comma-separated list of excluded terms IDs. Default empty.
  2149  * @param bool         $previous       Optional. Whether to display link to previous or next post. Default true.
  2253  * @param bool         $previous       Optional. Whether to display link to previous or next post. Default true.
  2150  * @param string       $taxonomy       Optional. Taxonomy, if $in_same_term is true. Default 'category'.
  2254  * @param string       $taxonomy       Optional. Taxonomy, if $in_same_term is true. Default 'category'.
  2151  * @return string The link URL of the previous or next post in relation to the current post.
  2255  * @return string The link URL of the previous or next post in relation to the current post.
  2152  */
  2256  */
  2153 function get_adjacent_post_link( $format, $link, $in_same_term = false, $excluded_terms = '', $previous = true, $taxonomy = 'category' ) {
  2257 function get_adjacent_post_link( $format, $link, $in_same_term = false, $excluded_terms = '', $previous = true, $taxonomy = 'category' ) {
  2185 	/**
  2289 	/**
  2186 	 * Filters the adjacent post link.
  2290 	 * Filters the adjacent post link.
  2187 	 *
  2291 	 *
  2188 	 * The dynamic portion of the hook name, `$adjacent`, refers to the type
  2292 	 * The dynamic portion of the hook name, `$adjacent`, refers to the type
  2189 	 * of adjacency, 'next' or 'previous'.
  2293 	 * of adjacency, 'next' or 'previous'.
       
  2294 	 *
       
  2295 	 * Possible hook names include:
       
  2296 	 *
       
  2297 	 *  - `next_post_link`
       
  2298 	 *  - `previous_post_link`
  2190 	 *
  2299 	 *
  2191 	 * @since 2.6.0
  2300 	 * @since 2.6.0
  2192 	 * @since 4.2.0 Added the `$adjacent` parameter.
  2301 	 * @since 4.2.0 Added the `$adjacent` parameter.
  2193 	 *
  2302 	 *
  2194 	 * @param string  $output   The adjacent post link.
  2303 	 * @param string  $output   The adjacent post link.
  2208  * @since 2.5.0
  2317  * @since 2.5.0
  2209  *
  2318  *
  2210  * @param string       $format         Link anchor format.
  2319  * @param string       $format         Link anchor format.
  2211  * @param string       $link           Link permalink format.
  2320  * @param string       $link           Link permalink format.
  2212  * @param bool         $in_same_term   Optional. Whether link should be in a same taxonomy term. Default false.
  2321  * @param bool         $in_same_term   Optional. Whether link should be in a same taxonomy term. Default false.
  2213  * @param array|string $excluded_terms Optional. Array or comma-separated list of excluded category IDs. Default empty.
  2322  * @param int[]|string $excluded_terms Optional. Array or comma-separated list of excluded category IDs. Default empty.
  2214  * @param bool         $previous       Optional. Whether to display link to previous or next post. Default true.
  2323  * @param bool         $previous       Optional. Whether to display link to previous or next post. Default true.
  2215  * @param string       $taxonomy       Optional. Taxonomy, if $in_same_term is true. Default 'category'.
  2324  * @param string       $taxonomy       Optional. Taxonomy, if $in_same_term is true. Default 'category'.
  2216  */
  2325  */
  2217 function adjacent_post_link( $format, $link, $in_same_term = false, $excluded_terms = '', $previous = true, $taxonomy = 'category' ) {
  2326 function adjacent_post_link( $format, $link, $in_same_term = false, $excluded_terms = '', $previous = true, $taxonomy = 'category' ) {
  2218 	echo get_adjacent_post_link( $format, $link, $in_same_term, $excluded_terms, $previous, $taxonomy );
  2327 	echo get_adjacent_post_link( $format, $link, $in_same_term, $excluded_terms, $previous, $taxonomy );
  2315 
  2424 
  2316 	if ( ! is_single() ) {
  2425 	if ( ! is_single() ) {
  2317 		if ( ! $paged ) {
  2426 		if ( ! $paged ) {
  2318 			$paged = 1;
  2427 			$paged = 1;
  2319 		}
  2428 		}
  2320 		$nextpage = intval( $paged ) + 1;
  2429 		$nextpage = (int) $paged + 1;
  2321 		if ( ! $max_page || $max_page >= $nextpage ) {
  2430 		if ( ! $max_page || $max_page >= $nextpage ) {
  2322 			return get_pagenum_link( $nextpage );
  2431 			return get_pagenum_link( $nextpage );
  2323 		}
  2432 		}
  2324 	}
  2433 	}
  2325 }
  2434 }
  2364 
  2473 
  2365 	if ( ! $paged ) {
  2474 	if ( ! $paged ) {
  2366 		$paged = 1;
  2475 		$paged = 1;
  2367 	}
  2476 	}
  2368 
  2477 
  2369 	$nextpage = intval( $paged ) + 1;
  2478 	$nextpage = (int) $paged + 1;
  2370 
  2479 
  2371 	if ( null === $label ) {
  2480 	if ( null === $label ) {
  2372 		$label = __( 'Next Page &raquo;' );
  2481 		$label = __( 'Next Page &raquo;' );
  2373 	}
  2482 	}
  2374 
  2483 
  2413  */
  2522  */
  2414 function get_previous_posts_page_link() {
  2523 function get_previous_posts_page_link() {
  2415 	global $paged;
  2524 	global $paged;
  2416 
  2525 
  2417 	if ( ! is_single() ) {
  2526 	if ( ! is_single() ) {
  2418 		$nextpage = intval( $paged ) - 1;
  2527 		$nextpage = (int) $paged - 1;
  2419 		if ( $nextpage < 1 ) {
  2528 		if ( $nextpage < 1 ) {
  2420 			$nextpage = 1;
  2529 			$nextpage = 1;
  2421 		}
  2530 		}
  2422 		return get_pagenum_link( $nextpage );
  2531 		return get_pagenum_link( $nextpage );
  2423 	}
  2532 	}
  2557  *     Optional. Default post navigation arguments. Default empty array.
  2666  *     Optional. Default post navigation arguments. Default empty array.
  2558  *
  2667  *
  2559  *     @type string       $prev_text          Anchor text to display in the previous post link. Default '%title'.
  2668  *     @type string       $prev_text          Anchor text to display in the previous post link. Default '%title'.
  2560  *     @type string       $next_text          Anchor text to display in the next post link. Default '%title'.
  2669  *     @type string       $next_text          Anchor text to display in the next post link. Default '%title'.
  2561  *     @type bool         $in_same_term       Whether link should be in a same taxonomy term. Default false.
  2670  *     @type bool         $in_same_term       Whether link should be in a same taxonomy term. Default false.
  2562  *     @type array|string $excluded_terms     Array or comma-separated list of excluded term IDs. Default empty.
  2671  *     @type int[]|string $excluded_terms     Array or comma-separated list of excluded term IDs. Default empty.
  2563  *     @type string       $taxonomy           Taxonomy, if `$in_same_term` is true. Default 'category'.
  2672  *     @type string       $taxonomy           Taxonomy, if `$in_same_term` is true. Default 'category'.
  2564  *     @type string       $screen_reader_text Screen reader text for the nav element. Default 'Post navigation'.
  2673  *     @type string       $screen_reader_text Screen reader text for the nav element. Default 'Post navigation'.
  2565  *     @type string       $aria_label         ARIA label text for the nav element. Default 'Posts'.
  2674  *     @type string       $aria_label         ARIA label text for the nav element. Default 'Posts'.
  2566  *     @type string       $class              Custom class for the nav element. Default 'post-navigation'.
  2675  *     @type string       $class              Custom class for the nav element. Default 'post-navigation'.
  2567  * }
  2676  * }
  2886 
  2995 
  2887 	if ( ! $page ) {
  2996 	if ( ! $page ) {
  2888 		$page = 1;
  2997 		$page = 1;
  2889 	}
  2998 	}
  2890 
  2999 
  2891 	$nextpage = intval( $page ) + 1;
  3000 	$nextpage = (int) $page + 1;
  2892 
  3001 
  2893 	if ( empty( $max_page ) ) {
  3002 	if ( empty( $max_page ) ) {
  2894 		$max_page = $wp_query->max_num_comment_pages;
  3003 		$max_page = $wp_query->max_num_comment_pages;
  2895 	}
  3004 	}
  2896 
  3005 
  2941 		return;
  3050 		return;
  2942 	}
  3051 	}
  2943 
  3052 
  2944 	$page = get_query_var( 'cpage' );
  3053 	$page = get_query_var( 'cpage' );
  2945 
  3054 
  2946 	if ( intval( $page ) <= 1 ) {
  3055 	if ( (int) $page <= 1 ) {
  2947 		return;
  3056 		return;
  2948 	}
  3057 	}
  2949 
  3058 
  2950 	$prevpage = intval( $page ) - 1;
  3059 	$prevpage = (int) $page - 1;
  2951 
  3060 
  2952 	if ( empty( $label ) ) {
  3061 	if ( empty( $label ) ) {
  2953 		$label = __( '&laquo; Older Comments' );
  3062 		$label = __( '&laquo; Older Comments' );
  2954 	}
  3063 	}
  2955 
  3064 
  3178  * if is_ssl() evaluates to true; otherwise, it will be the same as the 'home' option.
  3287  * if is_ssl() evaluates to true; otherwise, it will be the same as the 'home' option.
  3179  * If `$scheme` is 'http' or 'https', is_ssl() is overridden.
  3288  * If `$scheme` is 'http' or 'https', is_ssl() is overridden.
  3180  *
  3289  *
  3181  * @since 3.0.0
  3290  * @since 3.0.0
  3182  *
  3291  *
  3183  * @global string $pagenow
  3292  * @param int|null    $blog_id Optional. Site ID. Default null (current site).
  3184  *
       
  3185  * @param int         $blog_id Optional. Site ID. Default null (current site).
       
  3186  * @param string      $path    Optional. Path relative to the home URL. Default empty.
  3293  * @param string      $path    Optional. Path relative to the home URL. Default empty.
  3187  * @param string|null $scheme  Optional. Scheme to give the home URL context. Accepts
  3294  * @param string|null $scheme  Optional. Scheme to give the home URL context. Accepts
  3188  *                             'http', 'https', 'relative', 'rest', or null. Default null.
  3295  *                             'http', 'https', 'relative', 'rest', or null. Default null.
  3189  * @return string Home URL link with optional path appended.
  3296  * @return string Home URL link with optional path appended.
  3190  */
  3297  */
  3191 function get_home_url( $blog_id = null, $path = '', $scheme = null ) {
  3298 function get_home_url( $blog_id = null, $path = '', $scheme = null ) {
  3192 	global $pagenow;
       
  3193 
       
  3194 	$orig_scheme = $scheme;
  3299 	$orig_scheme = $scheme;
  3195 
  3300 
  3196 	if ( empty( $blog_id ) || ! is_multisite() ) {
  3301 	if ( empty( $blog_id ) || ! is_multisite() ) {
  3197 		$url = get_option( 'home' );
  3302 		$url = get_option( 'home' );
  3198 	} else {
  3303 	} else {
  3200 		$url = get_option( 'home' );
  3305 		$url = get_option( 'home' );
  3201 		restore_current_blog();
  3306 		restore_current_blog();
  3202 	}
  3307 	}
  3203 
  3308 
  3204 	if ( ! in_array( $scheme, array( 'http', 'https', 'relative' ), true ) ) {
  3309 	if ( ! in_array( $scheme, array( 'http', 'https', 'relative' ), true ) ) {
  3205 		if ( is_ssl() && ! is_admin() && 'wp-login.php' !== $pagenow ) {
  3310 		if ( is_ssl() ) {
  3206 			$scheme = 'https';
  3311 			$scheme = 'https';
  3207 		} else {
  3312 		} else {
  3208 			$scheme = parse_url( $url, PHP_URL_SCHEME );
  3313 			$scheme = parse_url( $url, PHP_URL_SCHEME );
  3209 		}
  3314 		}
  3210 	}
  3315 	}
  3237  * is_ssl() and 'http' otherwise. If $scheme is 'http' or 'https', is_ssl() is
  3342  * is_ssl() and 'http' otherwise. If $scheme is 'http' or 'https', is_ssl() is
  3238  * overridden.
  3343  * overridden.
  3239  *
  3344  *
  3240  * @since 3.0.0
  3345  * @since 3.0.0
  3241  *
  3346  *
  3242  * @param string $path   Optional. Path relative to the site URL. Default empty.
  3347  * @param string      $path   Optional. Path relative to the site URL. Default empty.
  3243  * @param string $scheme Optional. Scheme to give the site URL context. See set_url_scheme().
  3348  * @param string|null $scheme Optional. Scheme to give the site URL context. See set_url_scheme().
  3244  * @return string Site URL link with optional path appended.
  3349  * @return string Site URL link with optional path appended.
  3245  */
  3350  */
  3246 function site_url( $path = '', $scheme = null ) {
  3351 function site_url( $path = '', $scheme = null ) {
  3247 	return get_site_url( null, $path, $scheme );
  3352 	return get_site_url( null, $path, $scheme );
  3248 }
  3353 }
  3255  * is_ssl() and 'http' otherwise. If `$scheme` is 'http' or 'https',
  3360  * is_ssl() and 'http' otherwise. If `$scheme` is 'http' or 'https',
  3256  * `is_ssl()` is overridden.
  3361  * `is_ssl()` is overridden.
  3257  *
  3362  *
  3258  * @since 3.0.0
  3363  * @since 3.0.0
  3259  *
  3364  *
  3260  * @param int    $blog_id Optional. Site ID. Default null (current site).
  3365  * @param int|null    $blog_id Optional. Site ID. Default null (current site).
  3261  * @param string $path    Optional. Path relative to the site URL. Default empty.
  3366  * @param string      $path    Optional. Path relative to the site URL. Default empty.
  3262  * @param string $scheme  Optional. Scheme to give the site URL context. Accepts
  3367  * @param string|null $scheme  Optional. Scheme to give the site URL context. Accepts
  3263  *                        'http', 'https', 'login', 'login_post', 'admin', or
  3368  *                             'http', 'https', 'login', 'login_post', 'admin', or
  3264  *                        'relative'. Default null.
  3369  *                             'relative'. Default null.
  3265  * @return string Site URL link with optional path appended.
  3370  * @return string Site URL link with optional path appended.
  3266  */
  3371  */
  3267 function get_site_url( $blog_id = null, $path = '', $scheme = null ) {
  3372 function get_site_url( $blog_id = null, $path = '', $scheme = null ) {
  3268 	if ( empty( $blog_id ) || ! is_multisite() ) {
  3373 	if ( empty( $blog_id ) || ! is_multisite() ) {
  3269 		$url = get_option( 'siteurl' );
  3374 		$url = get_option( 'siteurl' );
  3296 /**
  3401 /**
  3297  * Retrieves the URL to the admin area for the current site.
  3402  * Retrieves the URL to the admin area for the current site.
  3298  *
  3403  *
  3299  * @since 2.6.0
  3404  * @since 2.6.0
  3300  *
  3405  *
  3301  * @param string $path   Optional path relative to the admin URL.
  3406  * @param string $path   Optional. Path relative to the admin URL. Default 'admin'.
  3302  * @param string $scheme The scheme to use. Default is 'admin', which obeys force_ssl_admin() and is_ssl().
  3407  * @param string $scheme The scheme to use. Default is 'admin', which obeys force_ssl_admin() and is_ssl().
  3303  *                       'http' or 'https' can be passed to force those schemes.
  3408  *                       'http' or 'https' can be passed to force those schemes.
  3304  * @return string Admin URL link with optional path appended.
  3409  * @return string Admin URL link with optional path appended.
  3305  */
  3410  */
  3306 function admin_url( $path = '', $scheme = 'admin' ) {
  3411 function admin_url( $path = '', $scheme = 'admin' ) {
  3310 /**
  3415 /**
  3311  * Retrieves the URL to the admin area for a given site.
  3416  * Retrieves the URL to the admin area for a given site.
  3312  *
  3417  *
  3313  * @since 3.0.0
  3418  * @since 3.0.0
  3314  *
  3419  *
  3315  * @param int    $blog_id Optional. Site ID. Default null (current site).
  3420  * @param int|null $blog_id Optional. Site ID. Default null (current site).
  3316  * @param string $path    Optional. Path relative to the admin URL. Default empty.
  3421  * @param string   $path    Optional. Path relative to the admin URL. Default empty.
  3317  * @param string $scheme  Optional. The scheme to use. Accepts 'http' or 'https',
  3422  * @param string   $scheme  Optional. The scheme to use. Accepts 'http' or 'https',
  3318  *                        to force those schemes. Default 'admin', which obeys
  3423  *                          to force those schemes. Default 'admin', which obeys
  3319  *                        force_ssl_admin() and is_ssl().
  3424  *                          force_ssl_admin() and is_ssl().
  3320  * @return string Admin URL link with optional path appended.
  3425  * @return string Admin URL link with optional path appended.
  3321  */
  3426  */
  3322 function get_admin_url( $blog_id = null, $path = '', $scheme = 'admin' ) {
  3427 function get_admin_url( $blog_id = null, $path = '', $scheme = 'admin' ) {
  3323 	$url = get_site_url( $blog_id, 'wp-admin/', $scheme );
  3428 	$url = get_site_url( $blog_id, 'wp-admin/', $scheme );
  3324 
  3429 
  3328 
  3433 
  3329 	/**
  3434 	/**
  3330 	 * Filters the admin area URL.
  3435 	 * Filters the admin area URL.
  3331 	 *
  3436 	 *
  3332 	 * @since 2.8.0
  3437 	 * @since 2.8.0
  3333 	 *
  3438 	 * @since 5.8.0 The `$scheme` parameter was added.
  3334 	 * @param string   $url     The complete admin area URL including scheme and path.
  3439 	 *
  3335 	 * @param string   $path    Path relative to the admin area URL. Blank string if no path is specified.
  3440 	 * @param string      $url     The complete admin area URL including scheme and path.
  3336 	 * @param int|null $blog_id Site ID, or null for the current site.
  3441 	 * @param string      $path    Path relative to the admin area URL. Blank string if no path is specified.
  3337 	 */
  3442 	 * @param int|null    $blog_id Site ID, or null for the current site.
  3338 	return apply_filters( 'admin_url', $url, $path, $blog_id );
  3443 	 * @param string|null $scheme  The scheme to use. Accepts 'http', 'https',
       
  3444 	 *                             'admin', or null. Default 'admin', which obeys force_ssl_admin() and is_ssl().
       
  3445 	 */
       
  3446 	return apply_filters( 'admin_url', $url, $path, $blog_id, $scheme );
  3339 }
  3447 }
  3340 
  3448 
  3341 /**
  3449 /**
  3342  * Retrieves the URL to the includes directory.
  3450  * Retrieves the URL to the includes directory.
  3343  *
  3451  *
  3344  * @since 2.6.0
  3452  * @since 2.6.0
  3345  *
  3453  *
  3346  * @param string $path   Optional. Path relative to the includes URL. Default empty.
  3454  * @param string      $path   Optional. Path relative to the includes URL. Default empty.
  3347  * @param string $scheme Optional. Scheme to give the includes URL context. Accepts
  3455  * @param string|null $scheme Optional. Scheme to give the includes URL context. Accepts
  3348  *                       'http', 'https', or 'relative'. Default null.
  3456  *                            'http', 'https', or 'relative'. Default null.
  3349  * @return string Includes URL link with optional path appended.
  3457  * @return string Includes URL link with optional path appended.
  3350  */
  3458  */
  3351 function includes_url( $path = '', $scheme = null ) {
  3459 function includes_url( $path = '', $scheme = null ) {
  3352 	$url = site_url( '/' . WPINC . '/', $scheme );
  3460 	$url = site_url( '/' . WPINC . '/', $scheme );
  3353 
  3461 
  3357 
  3465 
  3358 	/**
  3466 	/**
  3359 	 * Filters the URL to the includes directory.
  3467 	 * Filters the URL to the includes directory.
  3360 	 *
  3468 	 *
  3361 	 * @since 2.8.0
  3469 	 * @since 2.8.0
  3362 	 *
  3470 	 * @since 5.8.0 The `$scheme` parameter was added.
  3363 	 * @param string $url  The complete URL to the includes directory including scheme and path.
  3471 	 *
  3364 	 * @param string $path Path relative to the URL to the wp-includes directory. Blank string
  3472 	 * @param string      $url    The complete URL to the includes directory including scheme and path.
  3365 	 *                     if no path is specified.
  3473 	 * @param string      $path   Path relative to the URL to the wp-includes directory. Blank string
  3366 	 */
  3474 	 *                            if no path is specified.
  3367 	return apply_filters( 'includes_url', $url, $path );
  3475 	 * @param string|null $scheme Scheme to give the includes URL context. Accepts
       
  3476 	 *                            'http', 'https', 'relative', or null. Default null.
       
  3477 	 */
       
  3478 	return apply_filters( 'includes_url', $url, $path, $scheme );
  3368 }
  3479 }
  3369 
  3480 
  3370 /**
  3481 /**
  3371  * Retrieves the URL to the content directory.
  3482  * Retrieves the URL to the content directory.
  3372  *
  3483  *
  3456  *
  3567  *
  3457  * @since 3.0.0
  3568  * @since 3.0.0
  3458  *
  3569  *
  3459  * @see set_url_scheme()
  3570  * @see set_url_scheme()
  3460  *
  3571  *
  3461  * @param string $path   Optional. Path relative to the site URL. Default empty.
  3572  * @param string      $path   Optional. Path relative to the site URL. Default empty.
  3462  * @param string $scheme Optional. Scheme to give the site URL context. Accepts
  3573  * @param string|null $scheme Optional. Scheme to give the site URL context. Accepts
  3463  *                       'http', 'https', or 'relative'. Default null.
  3574  *                            'http', 'https', or 'relative'. Default null.
  3464  * @return string Site URL link with optional path appended.
  3575  * @return string Site URL link with optional path appended.
  3465  */
  3576  */
  3466 function network_site_url( $path = '', $scheme = null ) {
  3577 function network_site_url( $path = '', $scheme = null ) {
  3467 	if ( ! is_multisite() ) {
  3578 	if ( ! is_multisite() ) {
  3468 		return site_url( $path, $scheme );
  3579 		return site_url( $path, $scheme );
  3501  * and 'http' otherwise. If `$scheme` is 'http' or 'https', `is_ssl()` is
  3612  * and 'http' otherwise. If `$scheme` is 'http' or 'https', `is_ssl()` is
  3502  * overridden.
  3613  * overridden.
  3503  *
  3614  *
  3504  * @since 3.0.0
  3615  * @since 3.0.0
  3505  *
  3616  *
  3506  * @param string $path   Optional. Path relative to the home URL. Default empty.
  3617  * @param string      $path   Optional. Path relative to the home URL. Default empty.
  3507  * @param string $scheme Optional. Scheme to give the home URL context. Accepts
  3618  * @param string|null $scheme Optional. Scheme to give the home URL context. Accepts
  3508  *                       'http', 'https', or 'relative'. Default null.
  3619  *                            'http', 'https', or 'relative'. Default null.
  3509  * @return string Home URL link with optional path appended.
  3620  * @return string Home URL link with optional path appended.
  3510  */
  3621  */
  3511 function network_home_url( $path = '', $scheme = null ) {
  3622 function network_home_url( $path = '', $scheme = null ) {
  3512 	if ( ! is_multisite() ) {
  3623 	if ( ! is_multisite() ) {
  3513 		return home_url( $path, $scheme );
  3624 		return home_url( $path, $scheme );
  3515 
  3626 
  3516 	$current_network = get_network();
  3627 	$current_network = get_network();
  3517 	$orig_scheme     = $scheme;
  3628 	$orig_scheme     = $scheme;
  3518 
  3629 
  3519 	if ( ! in_array( $scheme, array( 'http', 'https', 'relative' ), true ) ) {
  3630 	if ( ! in_array( $scheme, array( 'http', 'https', 'relative' ), true ) ) {
  3520 		$scheme = is_ssl() && ! is_admin() ? 'https' : 'http';
  3631 		$scheme = is_ssl() ? 'https' : 'http';
  3521 	}
  3632 	}
  3522 
  3633 
  3523 	if ( 'relative' === $scheme ) {
  3634 	if ( 'relative' === $scheme ) {
  3524 		$url = $current_network->path;
  3635 		$url = $current_network->path;
  3525 	} else {
  3636 	} else {
  3567 
  3678 
  3568 	/**
  3679 	/**
  3569 	 * Filters the network admin URL.
  3680 	 * Filters the network admin URL.
  3570 	 *
  3681 	 *
  3571 	 * @since 3.0.0
  3682 	 * @since 3.0.0
  3572 	 *
  3683 	 * @since 5.8.0 The `$scheme` parameter was added.
  3573 	 * @param string $url  The complete network admin URL including scheme and path.
  3684 	 *
  3574 	 * @param string $path Path relative to the network admin URL. Blank string if
  3685 	 * @param string      $url    The complete network admin URL including scheme and path.
  3575 	 *                     no path is specified.
  3686 	 * @param string      $path   Path relative to the network admin URL. Blank string if
  3576 	 */
  3687 	 *                            no path is specified.
  3577 	return apply_filters( 'network_admin_url', $url, $path );
  3688 	 * @param string|null $scheme The scheme to use. Accepts 'http', 'https',
       
  3689 	 *                            'admin', or null. Default is 'admin', which obeys force_ssl_admin() and is_ssl().
       
  3690 	 */
       
  3691 	return apply_filters( 'network_admin_url', $url, $path, $scheme );
  3578 }
  3692 }
  3579 
  3693 
  3580 /**
  3694 /**
  3581  * Retrieves the URL to the admin area for the current user.
  3695  * Retrieves the URL to the admin area for the current user.
  3582  *
  3696  *
  3596 
  3710 
  3597 	/**
  3711 	/**
  3598 	 * Filters the user admin URL for the current user.
  3712 	 * Filters the user admin URL for the current user.
  3599 	 *
  3713 	 *
  3600 	 * @since 3.1.0
  3714 	 * @since 3.1.0
  3601 	 *
  3715 	 * @since 5.8.0 The `$scheme` parameter was added.
  3602 	 * @param string $url  The complete URL including scheme and path.
  3716 	 *
  3603 	 * @param string $path Path relative to the URL. Blank string if
  3717 	 * @param string      $url    The complete URL including scheme and path.
  3604 	 *                     no path is specified.
  3718 	 * @param string      $path   Path relative to the URL. Blank string if
  3605 	 */
  3719 	 *                            no path is specified.
  3606 	return apply_filters( 'user_admin_url', $url, $path );
  3720 	 * @param string|null $scheme The scheme to use. Accepts 'http', 'https',
       
  3721 	 *                            'admin', or null. Default is 'admin', which obeys force_ssl_admin() and is_ssl().
       
  3722 	 */
       
  3723 	return apply_filters( 'user_admin_url', $url, $path, $scheme );
  3607 }
  3724 }
  3608 
  3725 
  3609 /**
  3726 /**
  3610  * Retrieves the URL to the admin area for either the current site or the network depending on context.
  3727  * Retrieves the URL to the admin area for either the current site or the network depending on context.
  3611  *
  3728  *
  3908 	if ( ! empty( $post_id ) ) {
  4025 	if ( ! empty( $post_id ) ) {
  3909 		$post_type = get_post_type_object( $post->post_type );
  4026 		$post_type = get_post_type_object( $post->post_type );
  3910 
  4027 
  3911 		if ( 'page' === $post->post_type && get_option( 'page_on_front' ) == $post->ID && 'page' === get_option( 'show_on_front' ) ) {
  4028 		if ( 'page' === $post->post_type && get_option( 'page_on_front' ) == $post->ID && 'page' === get_option( 'show_on_front' ) ) {
  3912 			$shortlink = home_url( '/' );
  4029 			$shortlink = home_url( '/' );
  3913 		} elseif ( $post_type->public ) {
  4030 		} elseif ( $post_type && $post_type->public ) {
  3914 			$shortlink = home_url( '?p=' . $post_id );
  4031 			$shortlink = home_url( '?p=' . $post_id );
  3915 		}
  4032 		}
  3916 	}
  4033 	}
  3917 
  4034 
  3918 	/**
  4035 	/**