--- a/wp/wp-includes/link-template.php Tue Dec 15 15:52:01 2020 +0100
+++ b/wp/wp-includes/link-template.php Wed Sep 21 18:19:35 2022 +0200
@@ -90,6 +90,58 @@
}
/**
+ * Determine whether post should always use a plain permalink structure.
+ *
+ * @since 5.7.0
+ *
+ * @param WP_Post|int|null $post Optional. Post ID or post object. Defaults to global $post.
+ * @param bool|null $sample Optional. Whether to force consideration based on sample links.
+ * If omitted, a sample link is generated if a post object is passed
+ * with the filter property set to 'sample'.
+ * @return bool Whether to use a plain permalink structure.
+ */
+function wp_force_plain_post_permalink( $post = null, $sample = null ) {
+ if (
+ null === $sample &&
+ is_object( $post ) &&
+ isset( $post->filter ) &&
+ 'sample' === $post->filter
+ ) {
+ $sample = true;
+ } else {
+ $post = get_post( $post );
+ $sample = null !== $sample ? $sample : false;
+ }
+
+ if ( ! $post ) {
+ return true;
+ }
+
+ $post_status_obj = get_post_status_object( get_post_status( $post ) );
+ $post_type_obj = get_post_type_object( get_post_type( $post ) );
+
+ if ( ! $post_status_obj || ! $post_type_obj ) {
+ return true;
+ }
+
+ if (
+ // Publicly viewable links never have plain permalinks.
+ is_post_status_viewable( $post_status_obj ) ||
+ (
+ // Private posts don't have plain permalinks if the user can read them.
+ $post_status_obj->private &&
+ current_user_can( 'read_post', $post->ID )
+ ) ||
+ // Protected posts don't have plain links if getting a sample URL.
+ ( $post_status_obj->protected && $sample )
+ ) {
+ return false;
+ }
+
+ return true;
+}
+
+/**
* Retrieves the full permalink for the current post or post ID.
*
* This function is an alias for get_permalink().
@@ -164,7 +216,10 @@
*/
$permalink = apply_filters( 'pre_post_link', $permalink, $post, $leavename );
- if ( $permalink && ! in_array( $post->post_status, array( 'draft', 'pending', 'auto-draft', 'future' ), true ) ) {
+ if (
+ $permalink &&
+ ! wp_force_plain_post_permalink( $post )
+ ) {
$category = '';
if ( strpos( $permalink, '%category%' ) !== false ) {
@@ -274,7 +329,7 @@
$slug = $post->post_name;
- $draft_or_pending = get_post_status( $post ) && in_array( get_post_status( $post ), array( 'draft', 'pending', 'auto-draft', 'future' ), true );
+ $force_plain_link = wp_force_plain_post_permalink( $post );
$post_type = get_post_type_object( $post->post_type );
@@ -282,13 +337,13 @@
$slug = get_page_uri( $post );
}
- if ( ! empty( $post_link ) && ( ! $draft_or_pending || $sample ) ) {
+ if ( ! empty( $post_link ) && ( ! $force_plain_link || $sample ) ) {
if ( ! $leavename ) {
$post_link = str_replace( "%$post->post_type%", $slug, $post_link );
}
$post_link = home_url( user_trailingslashit( $post_link ) );
} else {
- if ( $post_type->query_var && ( isset( $post->post_status ) && ! $draft_or_pending ) ) {
+ if ( $post_type->query_var && ( isset( $post->post_status ) && ! $force_plain_link ) ) {
$post_link = add_query_arg( $post_type->query_var, $slug, '' );
} else {
$post_link = add_query_arg(
@@ -370,11 +425,11 @@
$post = get_post( $post );
- $draft_or_pending = in_array( $post->post_status, array( 'draft', 'pending', 'auto-draft' ), true );
+ $force_plain_link = wp_force_plain_post_permalink( $post );
$link = $wp_rewrite->get_page_permastruct();
- if ( ! empty( $link ) && ( ( isset( $post->post_status ) && ! $draft_or_pending ) || $sample ) ) {
+ if ( ! empty( $link ) && ( ( isset( $post->post_status ) && ! $force_plain_link ) || $sample ) ) {
if ( ! $leavename ) {
$link = str_replace( '%pagename%', get_page_uri( $post ), $link );
}
@@ -414,13 +469,26 @@
$link = false;
- $post = get_post( $post );
- $parent = ( $post->post_parent > 0 && $post->post_parent != $post->ID ) ? get_post( $post->post_parent ) : false;
- if ( $parent && ! in_array( $parent->post_type, get_post_types(), true ) ) {
- $parent = false;
+ $post = get_post( $post );
+ $force_plain_link = wp_force_plain_post_permalink( $post );
+ $parent_id = $post->post_parent;
+ $parent = $parent_id ? get_post( $parent_id ) : false;
+ $parent_valid = true; // Default for no parent.
+ if (
+ $parent_id &&
+ (
+ $post->post_parent === $post->ID ||
+ ! $parent ||
+ ! is_post_type_viewable( get_post_type( $parent ) )
+ )
+ ) {
+ // Post is either its own parent or parent post unavailable.
+ $parent_valid = false;
}
- if ( $wp_rewrite->using_permalinks() && $parent ) {
+ if ( $force_plain_link || ! $parent_valid ) {
+ $link = false;
+ } elseif ( $wp_rewrite->using_permalinks() && $parent ) {
if ( 'page' === $parent->post_type ) {
$parentlink = _get_page_link( $post->post_parent ); // Ignores page_on_front.
} else {
@@ -452,6 +520,8 @@
* Filters the permalink for an attachment.
*
* @since 2.0.0
+ * @since 5.6.0 Providing an empty string will now disable
+ * the view attachment page link on the media modal.
*
* @param string $link The attachment's permalink.
* @param int $post_id Attachment ID.
@@ -515,7 +585,7 @@
$monthlink = $wp_rewrite->get_month_permastruct();
if ( ! empty( $monthlink ) ) {
$monthlink = str_replace( '%year%', $year, $monthlink );
- $monthlink = str_replace( '%monthnum%', zeroise( intval( $month ), 2 ), $monthlink );
+ $monthlink = str_replace( '%monthnum%', zeroise( (int) $month, 2 ), $monthlink );
$monthlink = home_url( user_trailingslashit( $monthlink, 'month' ) );
} else {
$monthlink = home_url( '?m=' . $year . zeroise( $month, 2 ) );
@@ -560,8 +630,8 @@
$daylink = $wp_rewrite->get_day_permastruct();
if ( ! empty( $daylink ) ) {
$daylink = str_replace( '%year%', $year, $daylink );
- $daylink = str_replace( '%monthnum%', zeroise( intval( $month ), 2 ), $daylink );
- $daylink = str_replace( '%day%', zeroise( intval( $day ), 2 ), $daylink );
+ $daylink = str_replace( '%monthnum%', zeroise( (int) $month, 2 ), $daylink );
+ $daylink = str_replace( '%day%', zeroise( (int) $day, 2 ), $daylink );
$daylink = home_url( user_trailingslashit( $daylink, 'day' ) );
} else {
$daylink = home_url( '?m=' . $year . zeroise( $month, 2 ) . zeroise( $day, 2 ) );
@@ -620,7 +690,7 @@
$permalink = $wp_rewrite->get_feed_permastruct();
- if ( '' !== $permalink ) {
+ if ( $permalink ) {
if ( false !== strpos( $feed, 'comments_' ) ) {
$feed = str_replace( 'comments_', '', $feed );
$permalink = $wp_rewrite->get_comment_feed_permastruct();
@@ -665,7 +735,7 @@
* @param int $post_id Optional. Post ID. Default is the ID of the global `$post`.
* @param string $feed Optional. Feed type. Possible values include 'rss2', 'atom'.
* Default is the value of get_default_feed().
- * @return string The permalink for the comments feed for the given post.
+ * @return string The permalink for the comments feed for the given post on success, empty string on failure.
*/
function get_post_comments_feed_link( $post_id = 0, $feed = '' ) {
$post_id = absint( $post_id );
@@ -678,7 +748,13 @@
$feed = get_default_feed();
}
- $post = get_post( $post_id );
+ $post = get_post( $post_id );
+
+ // Bail out if the post does not exist.
+ if ( ! $post instanceof WP_Post ) {
+ return '';
+ }
+
$unattached = 'attachment' === $post->post_type && 0 === (int) $post->post_parent;
if ( get_option( 'permalink_structure' ) ) {
@@ -1208,7 +1284,8 @@
* @global WP_Rewrite $wp_rewrite WordPress rewrite component.
*
* @param string $post_type Post type.
- * @return string|false The post type archive permalink.
+ * @return string|false The post type archive permalink. False if the post type
+ * does not exist or does not have an archive.
*/
function get_post_type_archive_link( $post_type ) {
global $wp_rewrite;
@@ -1263,10 +1340,11 @@
*
* @since 3.1.0
*
- * @param string $post_type Post type
+ * @param string $post_type Post type.
* @param string $feed Optional. Feed type. Possible values include 'rss2', 'atom'.
* Default is the value of get_default_feed().
- * @return string|false The post type feed permalink.
+ * @return string|false The post type feed permalink. False if the post type
+ * does not exist or does not have an archive.
*/
function get_post_type_archive_feed_link( $post_type, $feed = '' ) {
$default_feed = get_default_feed();
@@ -1353,8 +1431,8 @@
*
* @param int|WP_Post $id Optional. Post ID or post object. Default is the global `$post`.
* @param string $context Optional. How to output the '&' character. Default '&'.
- * @return string|null The edit post link for the given post. null if the post type is invalid or does
- * not allow an editing UI.
+ * @return string|null The edit post link for the given post. Null if the post type does not exist
+ * or does not allow an editing UI.
*/
function get_edit_post_link( $id = 0, $context = 'display' ) {
$post = get_post( $id );
@@ -1659,7 +1737,7 @@
* @since 1.5.0
*
* @param bool $in_same_term Optional. Whether post should be in a same taxonomy term. Default false.
- * @param array|string $excluded_terms Optional. Array or comma-separated list of excluded term IDs. Default empty.
+ * @param int[]|string $excluded_terms Optional. Array or comma-separated list of excluded term IDs. Default empty.
* @param string $taxonomy Optional. Taxonomy, if $in_same_term is true. Default 'category'.
* @return null|string|WP_Post Post object if successful. Null if global $post is not set. Empty string if no
* corresponding post exists.
@@ -1674,7 +1752,7 @@
* @since 1.5.0
*
* @param bool $in_same_term Optional. Whether post should be in a same taxonomy term. Default false.
- * @param array|string $excluded_terms Optional. Array or comma-separated list of excluded term IDs. Default empty.
+ * @param int[]|string $excluded_terms Optional. Array or comma-separated list of excluded term IDs. Default empty.
* @param string $taxonomy Optional. Taxonomy, if $in_same_term is true. Default 'category'.
* @return null|string|WP_Post Post object if successful. Null if global $post is not set. Empty string if no
* corresponding post exists.
@@ -1693,7 +1771,7 @@
* @global wpdb $wpdb WordPress database abstraction object.
*
* @param bool $in_same_term Optional. Whether post should be in a same taxonomy term. Default false.
- * @param array|string $excluded_terms Optional. Array or comma-separated list of excluded term IDs. Default empty.
+ * @param int[]|string $excluded_terms Optional. Array or comma-separated list of excluded term IDs. Default empty string.
* @param bool $previous Optional. Whether to retrieve previous post. Default true
* @param string $taxonomy Optional. Taxonomy, if $in_same_term is true. Default 'category'.
* @return null|string|WP_Post Post object if successful. Null if global $post is not set. Empty string if no
@@ -1739,9 +1817,14 @@
* The dynamic portion of the hook name, `$adjacent`, refers to the type
* of adjacency, 'next' or 'previous'.
*
+ * Possible hook names include:
+ *
+ * - `get_next_post_excluded_terms`
+ * - `get_previous_post_excluded_terms`
+ *
* @since 4.4.0
*
- * @param array $excluded_terms Array of excluded term IDs.
+ * @param array|string $excluded_terms Array of excluded term IDs. Empty string if none were provided.
*/
$excluded_terms = apply_filters( "get_{$adjacent}_post_excluded_terms", $excluded_terms );
@@ -1810,6 +1893,11 @@
* The dynamic portion of the hook name, `$adjacent`, refers to the type
* of adjacency, 'next' or 'previous'.
*
+ * Possible hook names include:
+ *
+ * - `get_next_post_join`
+ * - `get_previous_post_join`
+ *
* @since 2.5.0
* @since 4.4.0 Added the `$taxonomy` and `$post` parameters.
*
@@ -1827,6 +1915,11 @@
* The dynamic portion of the hook name, `$adjacent`, refers to the type
* of adjacency, 'next' or 'previous'.
*
+ * Possible hook names include:
+ *
+ * - `get_next_post_where`
+ * - `get_previous_post_where`
+ *
* @since 2.5.0
* @since 4.4.0 Added the `$taxonomy` and `$post` parameters.
*
@@ -1844,6 +1937,11 @@
* The dynamic portion of the hook name, `$adjacent`, refers to the type
* of adjacency, 'next' or 'previous'.
*
+ * Possible hook names include:
+ *
+ * - `get_next_post_sort`
+ * - `get_previous_post_sort`
+ *
* @since 2.5.0
* @since 4.4.0 Added the `$post` parameter.
* @since 4.9.0 Added the `$order` parameter.
@@ -1887,7 +1985,7 @@
*
* @param string $title Optional. Link title format. Default '%title'.
* @param bool $in_same_term Optional. Whether link should be in a same taxonomy term. Default false.
- * @param array|string $excluded_terms Optional. Array or comma-separated list of excluded term IDs. Default empty.
+ * @param int[]|string $excluded_terms Optional. Array or comma-separated list of excluded term IDs. Default empty.
* @param bool $previous Optional. Whether to display link to previous or next post. Default true.
* @param string $taxonomy Optional. Taxonomy, if $in_same_term is true. Default 'category'.
* @return string|void The adjacent post relational link URL.
@@ -1932,6 +2030,11 @@
* The dynamic portion of the hook name, `$adjacent`, refers to the type
* of adjacency, 'next' or 'previous'.
*
+ * Possible hook names include:
+ *
+ * - `next_post_rel_link`
+ * - `previous_post_rel_link`
+ *
* @since 2.8.0
*
* @param string $link The relational link.
@@ -1946,7 +2049,7 @@
*
* @param string $title Optional. Link title format. Default '%title'.
* @param bool $in_same_term Optional. Whether link should be in a same taxonomy term. Default false.
- * @param array|string $excluded_terms Optional. Array or comma-separated list of excluded term IDs. Default empty.
+ * @param int[]|string $excluded_terms Optional. Array or comma-separated list of excluded term IDs. Default empty.
* @param string $taxonomy Optional. Taxonomy, if $in_same_term is true. Default 'category'.
*/
function adjacent_posts_rel_link( $title = '%title', $in_same_term = false, $excluded_terms = '', $taxonomy = 'category' ) {
@@ -1961,6 +2064,7 @@
* or theme templates.
*
* @since 3.0.0
+ * @since 5.6.0 No longer used in core.
*
* @see adjacent_posts_rel_link()
*/
@@ -1980,7 +2084,7 @@
*
* @param string $title Optional. Link title format. Default '%title'.
* @param bool $in_same_term Optional. Whether link should be in a same taxonomy term. Default false.
- * @param array|string $excluded_terms Optional. Array or comma-separated list of excluded term IDs. Default empty.
+ * @param int[]|string $excluded_terms Optional. Array or comma-separated list of excluded term IDs. Default empty.
* @param string $taxonomy Optional. Taxonomy, if $in_same_term is true. Default 'category'.
*/
function next_post_rel_link( $title = '%title', $in_same_term = false, $excluded_terms = '', $taxonomy = 'category' ) {
@@ -1996,7 +2100,7 @@
*
* @param string $title Optional. Link title format. Default '%title'.
* @param bool $in_same_term Optional. Whether link should be in a same taxonomy term. Default false.
- * @param array|string $excluded_terms Optional. Array or comma-separated list of excluded term IDs. Default true.
+ * @param int[]|string $excluded_terms Optional. Array or comma-separated list of excluded term IDs. Default true.
* @param string $taxonomy Optional. Taxonomy, if $in_same_term is true. Default 'category'.
*/
function prev_post_rel_link( $title = '%title', $in_same_term = false, $excluded_terms = '', $taxonomy = 'category' ) {
@@ -2013,7 +2117,7 @@
*
* @param bool $in_same_term Optional. Whether returned post should be in a same taxonomy term.
* Default false.
- * @param array|string $excluded_terms Optional. Array or comma-separated list of excluded term IDs.
+ * @param int[]|string $excluded_terms Optional. Array or comma-separated list of excluded term IDs.
* Default empty.
* @param bool $start Optional. Whether to retrieve first or last post. Default true
* @param string $taxonomy Optional. Taxonomy, if $in_same_term is true. Default 'category'.
@@ -2077,7 +2181,7 @@
* @param string $format Optional. Link anchor format. Default '« %link'.
* @param string $link Optional. Link permalink format. Default '%title'.
* @param bool $in_same_term Optional. Whether link should be in a same taxonomy term. Default false.
- * @param array|string $excluded_terms Optional. Array or comma-separated list of excluded term IDs. Default empty.
+ * @param int[]|string $excluded_terms Optional. Array or comma-separated list of excluded term IDs. Default empty.
* @param string $taxonomy Optional. Taxonomy, if $in_same_term is true. Default 'category'.
* @return string The link URL of the previous post in relation to the current post.
*/
@@ -2095,7 +2199,7 @@
* @param string $format Optional. Link anchor format. Default '« %link'.
* @param string $link Optional. Link permalink format. Default '%title'.
* @param bool $in_same_term Optional. Whether link should be in a same taxonomy term. Default false.
- * @param array|string $excluded_terms Optional. Array or comma-separated list of excluded term IDs. Default empty.
+ * @param int[]|string $excluded_terms Optional. Array or comma-separated list of excluded term IDs. Default empty.
* @param string $taxonomy Optional. Taxonomy, if $in_same_term is true. Default 'category'.
*/
function previous_post_link( $format = '« %link', $link = '%title', $in_same_term = false, $excluded_terms = '', $taxonomy = 'category' ) {
@@ -2110,7 +2214,7 @@
* @param string $format Optional. Link anchor format. Default '« %link'.
* @param string $link Optional. Link permalink format. Default '%title'.
* @param bool $in_same_term Optional. Whether link should be in a same taxonomy term. Default false.
- * @param array|string $excluded_terms Optional. Array or comma-separated list of excluded term IDs. Default empty.
+ * @param int[]|string $excluded_terms Optional. Array or comma-separated list of excluded term IDs. Default empty.
* @param string $taxonomy Optional. Taxonomy, if $in_same_term is true. Default 'category'.
* @return string The link URL of the next post in relation to the current post.
*/
@@ -2128,7 +2232,7 @@
* @param string $format Optional. Link anchor format. Default '« %link'.
* @param string $link Optional. Link permalink format. Default '%title'
* @param bool $in_same_term Optional. Whether link should be in a same taxonomy term. Default false.
- * @param array|string $excluded_terms Optional. Array or comma-separated list of excluded term IDs. Default empty.
+ * @param int[]|string $excluded_terms Optional. Array or comma-separated list of excluded term IDs. Default empty.
* @param string $taxonomy Optional. Taxonomy, if $in_same_term is true. Default 'category'.
*/
function next_post_link( $format = '%link »', $link = '%title', $in_same_term = false, $excluded_terms = '', $taxonomy = 'category' ) {
@@ -2145,7 +2249,7 @@
* @param string $format Link anchor format.
* @param string $link Link permalink format.
* @param bool $in_same_term Optional. Whether link should be in a same taxonomy term. Default false.
- * @param array|string $excluded_terms Optional. Array or comma-separated list of excluded terms IDs. Default empty.
+ * @param int[]|string $excluded_terms Optional. Array or comma-separated list of excluded terms IDs. Default empty.
* @param bool $previous Optional. Whether to display link to previous or next post. Default true.
* @param string $taxonomy Optional. Taxonomy, if $in_same_term is true. Default 'category'.
* @return string The link URL of the previous or next post in relation to the current post.
@@ -2188,6 +2292,11 @@
* The dynamic portion of the hook name, `$adjacent`, refers to the type
* of adjacency, 'next' or 'previous'.
*
+ * Possible hook names include:
+ *
+ * - `next_post_link`
+ * - `previous_post_link`
+ *
* @since 2.6.0
* @since 4.2.0 Added the `$adjacent` parameter.
*
@@ -2210,7 +2319,7 @@
* @param string $format Link anchor format.
* @param string $link Link permalink format.
* @param bool $in_same_term Optional. Whether link should be in a same taxonomy term. Default false.
- * @param array|string $excluded_terms Optional. Array or comma-separated list of excluded category IDs. Default empty.
+ * @param int[]|string $excluded_terms Optional. Array or comma-separated list of excluded category IDs. Default empty.
* @param bool $previous Optional. Whether to display link to previous or next post. Default true.
* @param string $taxonomy Optional. Taxonomy, if $in_same_term is true. Default 'category'.
*/
@@ -2317,7 +2426,7 @@
if ( ! $paged ) {
$paged = 1;
}
- $nextpage = intval( $paged ) + 1;
+ $nextpage = (int) $paged + 1;
if ( ! $max_page || $max_page >= $nextpage ) {
return get_pagenum_link( $nextpage );
}
@@ -2366,7 +2475,7 @@
$paged = 1;
}
- $nextpage = intval( $paged ) + 1;
+ $nextpage = (int) $paged + 1;
if ( null === $label ) {
$label = __( 'Next Page »' );
@@ -2415,7 +2524,7 @@
global $paged;
if ( ! is_single() ) {
- $nextpage = intval( $paged ) - 1;
+ $nextpage = (int) $paged - 1;
if ( $nextpage < 1 ) {
$nextpage = 1;
}
@@ -2559,7 +2668,7 @@
* @type string $prev_text Anchor text to display in the previous post link. Default '%title'.
* @type string $next_text Anchor text to display in the next post link. Default '%title'.
* @type bool $in_same_term Whether link should be in a same taxonomy term. Default false.
- * @type array|string $excluded_terms Array or comma-separated list of excluded term IDs. Default empty.
+ * @type int[]|string $excluded_terms Array or comma-separated list of excluded term IDs. Default empty.
* @type string $taxonomy Taxonomy, if `$in_same_term` is true. Default 'category'.
* @type string $screen_reader_text Screen reader text for the nav element. Default 'Post navigation'.
* @type string $aria_label ARIA label text for the nav element. Default 'Posts'.
@@ -2888,7 +2997,7 @@
$page = 1;
}
- $nextpage = intval( $page ) + 1;
+ $nextpage = (int) $page + 1;
if ( empty( $max_page ) ) {
$max_page = $wp_query->max_num_comment_pages;
@@ -2943,11 +3052,11 @@
$page = get_query_var( 'cpage' );
- if ( intval( $page ) <= 1 ) {
+ if ( (int) $page <= 1 ) {
return;
}
- $prevpage = intval( $page ) - 1;
+ $prevpage = (int) $page - 1;
if ( empty( $label ) ) {
$label = __( '« Older Comments' );
@@ -3180,17 +3289,13 @@
*
* @since 3.0.0
*
- * @global string $pagenow
- *
- * @param int $blog_id Optional. Site ID. Default null (current site).
+ * @param int|null $blog_id Optional. Site ID. Default null (current site).
* @param string $path Optional. Path relative to the home URL. Default empty.
* @param string|null $scheme Optional. Scheme to give the home URL context. Accepts
* 'http', 'https', 'relative', 'rest', or null. Default null.
* @return string Home URL link with optional path appended.
*/
function get_home_url( $blog_id = null, $path = '', $scheme = null ) {
- global $pagenow;
-
$orig_scheme = $scheme;
if ( empty( $blog_id ) || ! is_multisite() ) {
@@ -3202,7 +3307,7 @@
}
if ( ! in_array( $scheme, array( 'http', 'https', 'relative' ), true ) ) {
- if ( is_ssl() && ! is_admin() && 'wp-login.php' !== $pagenow ) {
+ if ( is_ssl() ) {
$scheme = 'https';
} else {
$scheme = parse_url( $url, PHP_URL_SCHEME );
@@ -3239,8 +3344,8 @@
*
* @since 3.0.0
*
- * @param string $path Optional. Path relative to the site URL. Default empty.
- * @param string $scheme Optional. Scheme to give the site URL context. See set_url_scheme().
+ * @param string $path Optional. Path relative to the site URL. Default empty.
+ * @param string|null $scheme Optional. Scheme to give the site URL context. See set_url_scheme().
* @return string Site URL link with optional path appended.
*/
function site_url( $path = '', $scheme = null ) {
@@ -3257,11 +3362,11 @@
*
* @since 3.0.0
*
- * @param int $blog_id Optional. Site ID. Default null (current site).
- * @param string $path Optional. Path relative to the site URL. Default empty.
- * @param string $scheme Optional. Scheme to give the site URL context. Accepts
- * 'http', 'https', 'login', 'login_post', 'admin', or
- * 'relative'. Default null.
+ * @param int|null $blog_id Optional. Site ID. Default null (current site).
+ * @param string $path Optional. Path relative to the site URL. Default empty.
+ * @param string|null $scheme Optional. Scheme to give the site URL context. Accepts
+ * 'http', 'https', 'login', 'login_post', 'admin', or
+ * 'relative'. Default null.
* @return string Site URL link with optional path appended.
*/
function get_site_url( $blog_id = null, $path = '', $scheme = null ) {
@@ -3298,7 +3403,7 @@
*
* @since 2.6.0
*
- * @param string $path Optional path relative to the admin URL.
+ * @param string $path Optional. Path relative to the admin URL. Default 'admin'.
* @param string $scheme The scheme to use. Default is 'admin', which obeys force_ssl_admin() and is_ssl().
* 'http' or 'https' can be passed to force those schemes.
* @return string Admin URL link with optional path appended.
@@ -3312,11 +3417,11 @@
*
* @since 3.0.0
*
- * @param int $blog_id Optional. Site ID. Default null (current site).
- * @param string $path Optional. Path relative to the admin URL. Default empty.
- * @param string $scheme Optional. The scheme to use. Accepts 'http' or 'https',
- * to force those schemes. Default 'admin', which obeys
- * force_ssl_admin() and is_ssl().
+ * @param int|null $blog_id Optional. Site ID. Default null (current site).
+ * @param string $path Optional. Path relative to the admin URL. Default empty.
+ * @param string $scheme Optional. The scheme to use. Accepts 'http' or 'https',
+ * to force those schemes. Default 'admin', which obeys
+ * force_ssl_admin() and is_ssl().
* @return string Admin URL link with optional path appended.
*/
function get_admin_url( $blog_id = null, $path = '', $scheme = 'admin' ) {
@@ -3330,12 +3435,15 @@
* Filters the admin area URL.
*
* @since 2.8.0
+ * @since 5.8.0 The `$scheme` parameter was added.
*
- * @param string $url The complete admin area URL including scheme and path.
- * @param string $path Path relative to the admin area URL. Blank string if no path is specified.
- * @param int|null $blog_id Site ID, or null for the current site.
+ * @param string $url The complete admin area URL including scheme and path.
+ * @param string $path Path relative to the admin area URL. Blank string if no path is specified.
+ * @param int|null $blog_id Site ID, or null for the current site.
+ * @param string|null $scheme The scheme to use. Accepts 'http', 'https',
+ * 'admin', or null. Default 'admin', which obeys force_ssl_admin() and is_ssl().
*/
- return apply_filters( 'admin_url', $url, $path, $blog_id );
+ return apply_filters( 'admin_url', $url, $path, $blog_id, $scheme );
}
/**
@@ -3343,9 +3451,9 @@
*
* @since 2.6.0
*
- * @param string $path Optional. Path relative to the includes URL. Default empty.
- * @param string $scheme Optional. Scheme to give the includes URL context. Accepts
- * 'http', 'https', or 'relative'. Default null.
+ * @param string $path Optional. Path relative to the includes URL. Default empty.
+ * @param string|null $scheme Optional. Scheme to give the includes URL context. Accepts
+ * 'http', 'https', or 'relative'. Default null.
* @return string Includes URL link with optional path appended.
*/
function includes_url( $path = '', $scheme = null ) {
@@ -3359,12 +3467,15 @@
* Filters the URL to the includes directory.
*
* @since 2.8.0
+ * @since 5.8.0 The `$scheme` parameter was added.
*
- * @param string $url The complete URL to the includes directory including scheme and path.
- * @param string $path Path relative to the URL to the wp-includes directory. Blank string
- * if no path is specified.
+ * @param string $url The complete URL to the includes directory including scheme and path.
+ * @param string $path Path relative to the URL to the wp-includes directory. Blank string
+ * if no path is specified.
+ * @param string|null $scheme Scheme to give the includes URL context. Accepts
+ * 'http', 'https', 'relative', or null. Default null.
*/
- return apply_filters( 'includes_url', $url, $path );
+ return apply_filters( 'includes_url', $url, $path, $scheme );
}
/**
@@ -3458,9 +3569,9 @@
*
* @see set_url_scheme()
*
- * @param string $path Optional. Path relative to the site URL. Default empty.
- * @param string $scheme Optional. Scheme to give the site URL context. Accepts
- * 'http', 'https', or 'relative'. Default null.
+ * @param string $path Optional. Path relative to the site URL. Default empty.
+ * @param string|null $scheme Optional. Scheme to give the site URL context. Accepts
+ * 'http', 'https', or 'relative'. Default null.
* @return string Site URL link with optional path appended.
*/
function network_site_url( $path = '', $scheme = null ) {
@@ -3503,9 +3614,9 @@
*
* @since 3.0.0
*
- * @param string $path Optional. Path relative to the home URL. Default empty.
- * @param string $scheme Optional. Scheme to give the home URL context. Accepts
- * 'http', 'https', or 'relative'. Default null.
+ * @param string $path Optional. Path relative to the home URL. Default empty.
+ * @param string|null $scheme Optional. Scheme to give the home URL context. Accepts
+ * 'http', 'https', or 'relative'. Default null.
* @return string Home URL link with optional path appended.
*/
function network_home_url( $path = '', $scheme = null ) {
@@ -3517,7 +3628,7 @@
$orig_scheme = $scheme;
if ( ! in_array( $scheme, array( 'http', 'https', 'relative' ), true ) ) {
- $scheme = is_ssl() && ! is_admin() ? 'https' : 'http';
+ $scheme = is_ssl() ? 'https' : 'http';
}
if ( 'relative' === $scheme ) {
@@ -3569,12 +3680,15 @@
* Filters the network admin URL.
*
* @since 3.0.0
+ * @since 5.8.0 The `$scheme` parameter was added.
*
- * @param string $url The complete network admin URL including scheme and path.
- * @param string $path Path relative to the network admin URL. Blank string if
- * no path is specified.
+ * @param string $url The complete network admin URL including scheme and path.
+ * @param string $path Path relative to the network admin URL. Blank string if
+ * no path is specified.
+ * @param string|null $scheme The scheme to use. Accepts 'http', 'https',
+ * 'admin', or null. Default is 'admin', which obeys force_ssl_admin() and is_ssl().
*/
- return apply_filters( 'network_admin_url', $url, $path );
+ return apply_filters( 'network_admin_url', $url, $path, $scheme );
}
/**
@@ -3598,12 +3712,15 @@
* Filters the user admin URL for the current user.
*
* @since 3.1.0
+ * @since 5.8.0 The `$scheme` parameter was added.
*
- * @param string $url The complete URL including scheme and path.
- * @param string $path Path relative to the URL. Blank string if
- * no path is specified.
+ * @param string $url The complete URL including scheme and path.
+ * @param string $path Path relative to the URL. Blank string if
+ * no path is specified.
+ * @param string|null $scheme The scheme to use. Accepts 'http', 'https',
+ * 'admin', or null. Default is 'admin', which obeys force_ssl_admin() and is_ssl().
*/
- return apply_filters( 'user_admin_url', $url, $path );
+ return apply_filters( 'user_admin_url', $url, $path, $scheme );
}
/**
@@ -3910,7 +4027,7 @@
if ( 'page' === $post->post_type && get_option( 'page_on_front' ) == $post->ID && 'page' === get_option( 'show_on_front' ) ) {
$shortlink = home_url( '/' );
- } elseif ( $post_type->public ) {
+ } elseif ( $post_type && $post_type->public ) {
$shortlink = home_url( '?p=' . $post_id );
}
}