diff -r 3d4e9c994f10 -r a86126ab1dd4 wp/wp-includes/link-template.php --- a/wp/wp-includes/link-template.php Tue Oct 22 16:11:46 2019 +0200 +++ b/wp/wp-includes/link-template.php Tue Dec 15 13:49:49 2020 +0100 @@ -37,7 +37,7 @@ * * @since 2.2.0 * - * @global WP_Rewrite $wp_rewrite + * @global WP_Rewrite $wp_rewrite WordPress rewrite component. * * @param string $string URL with or without a trailing slash. * @param string $type_of_url Optional. The type of URL being considered (e.g. single, category, etc) @@ -100,7 +100,6 @@ * * @param int|WP_Post $post Optional. Post ID or post object. Default is the global `$post`. * @param bool $leavename Optional. Whether to keep post name or page name. Default false. - * * @return string|false The permalink URL or false if post does not exist. */ function get_the_permalink( $post = 0, $leavename = false ) { @@ -131,7 +130,7 @@ $leavename ? '' : '%pagename%', ); - if ( is_object( $post ) && isset( $post->filter ) && 'sample' == $post->filter ) { + if ( is_object( $post ) && isset( $post->filter ) && 'sample' === $post->filter ) { $sample = true; } else { $post = get_post( $post ); @@ -142,11 +141,11 @@ return false; } - if ( $post->post_type == 'page' ) { + if ( 'page' === $post->post_type ) { return get_page_link( $post, $leavename, $sample ); - } elseif ( $post->post_type == 'attachment' ) { + } elseif ( 'attachment' === $post->post_type ) { return get_attachment_link( $post, $leavename ); - } elseif ( in_array( $post->post_type, get_post_types( array( '_builtin' => false ) ) ) ) { + } elseif ( in_array( $post->post_type, get_post_types( array( '_builtin' => false ) ), true ) ) { return get_post_permalink( $post, $leavename, $sample ); } @@ -165,8 +164,7 @@ */ $permalink = apply_filters( 'pre_post_link', $permalink, $post, $leavename ); - if ( '' != $permalink && ! in_array( $post->post_status, array( 'draft', 'pending', 'auto-draft', 'future' ) ) ) { - $unixtime = strtotime( $post->post_date ); + if ( $permalink && ! in_array( $post->post_status, array( 'draft', 'pending', 'auto-draft', 'future' ), true ) ) { $category = ''; if ( strpos( $permalink, '%category%' ) !== false ) { @@ -196,8 +194,8 @@ $category = get_category_parents( $category_object->parent, false, '/', true ) . $category; } } - // show default category in permalinks, without - // having to assign it explicitly + // Show default category in permalinks, + // without having to assign it explicitly. if ( empty( $category ) ) { $default_category = get_term( get_option( 'default_category' ), 'category' ); if ( $default_category && ! is_wp_error( $default_category ) ) { @@ -212,9 +210,11 @@ $author = $authordata->user_nicename; } - $date = explode( ' ', date( 'Y m d H i s', $unixtime ) ); - $rewritereplace = - array( + // This is not an API call because the permalink is based on the stored post_date value, + // which should be parsed as local time regardless of the default PHP timezone. + $date = explode( ' ', str_replace( array( '-', ':' ), ' ', $post->post_date ) ); + + $rewritereplace = array( $date[0], $date[1], $date[2], @@ -227,9 +227,11 @@ $author, $post->post_name, ); - $permalink = home_url( str_replace( $rewritecode, $rewritereplace, $permalink ) ); - $permalink = user_trailingslashit( $permalink, 'single' ); - } else { // if they're not using the fancy permalink option + + $permalink = home_url( str_replace( $rewritecode, $rewritereplace, $permalink ) ); + $permalink = user_trailingslashit( $permalink, 'single' ); + + } else { // If they're not using the fancy permalink option. $permalink = home_url( '?p=' . $post->ID ); } @@ -252,11 +254,11 @@ * * @since 3.0.0 * - * @global WP_Rewrite $wp_rewrite + * @global WP_Rewrite $wp_rewrite WordPress rewrite component. * * @param int|WP_Post $id Optional. Post ID or post object. Default is the global `$post`. - * @param bool $leavename Optional, defaults to false. Whether to keep post name. Default false. - * @param bool $sample Optional, defaults to false. Is it a sample permalink. Default false. + * @param bool $leavename Optional. Whether to keep post name. Default false. + * @param bool $sample Optional. Is it a sample permalink. Default false. * @return string|WP_Error The post permalink. */ function get_post_permalink( $id = 0, $leavename = false, $sample = false ) { @@ -272,7 +274,7 @@ $slug = $post->post_name; - $draft_or_pending = get_post_status( $post ) && in_array( get_post_status( $post ), array( 'draft', 'pending', 'auto-draft', 'future' ) ); + $draft_or_pending = get_post_status( $post ) && in_array( get_post_status( $post ), array( 'draft', 'pending', 'auto-draft', 'future' ), true ); $post_type = get_post_type_object( $post->post_type ); @@ -329,7 +331,7 @@ function get_page_link( $post = false, $leavename = false, $sample = false ) { $post = get_post( $post ); - if ( 'page' == get_option( 'show_on_front' ) && $post->ID == get_option( 'page_on_front' ) ) { + if ( 'page' === get_option( 'show_on_front' ) && get_option( 'page_on_front' ) == $post->ID ) { $link = home_url( '/' ); } else { $link = _get_page_link( $post, $leavename, $sample ); @@ -355,7 +357,7 @@ * @since 2.1.0 * @access private * - * @global WP_Rewrite $wp_rewrite + * @global WP_Rewrite $wp_rewrite WordPress rewrite component. * * @param int|WP_Post $post Optional. Post ID or object. Default uses the global `$post`. * @param bool $leavename Optional. Whether to keep the page name. Default false. @@ -368,7 +370,7 @@ $post = get_post( $post ); - $draft_or_pending = in_array( $post->post_status, array( 'draft', 'pending', 'auto-draft' ) ); + $draft_or_pending = in_array( $post->post_status, array( 'draft', 'pending', 'auto-draft' ), true ); $link = $wp_rewrite->get_page_permastruct(); @@ -401,7 +403,7 @@ * * @since 2.0.0 * - * @global WP_Rewrite $wp_rewrite + * @global WP_Rewrite $wp_rewrite WordPress rewrite component. * * @param int|object $post Optional. Post ID or object. Default uses the global `$post`. * @param bool $leavename Optional. Whether to keep the page name. Default false. @@ -414,19 +416,19 @@ $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() ) ) { + if ( $parent && ! in_array( $parent->post_type, get_post_types(), true ) ) { $parent = false; } if ( $wp_rewrite->using_permalinks() && $parent ) { - if ( 'page' == $parent->post_type ) { - $parentlink = _get_page_link( $post->post_parent ); // Ignores page_on_front + if ( 'page' === $parent->post_type ) { + $parentlink = _get_page_link( $post->post_parent ); // Ignores page_on_front. } else { $parentlink = get_permalink( $post->post_parent ); } if ( is_numeric( $post->post_name ) || false !== strpos( get_option( 'permalink_structure' ), '%category%' ) ) { - $name = 'attachment/' . $post->post_name; // // is paged so we use the explicit attachment marker + $name = 'attachment/' . $post->post_name; // // is paged so we use the explicit attachment marker. } else { $name = $post->post_name; } @@ -462,9 +464,9 @@ * * @since 1.5.0 * - * @global WP_Rewrite $wp_rewrite - * - * @param int|bool $year False for current year or year for permalink. + * @global WP_Rewrite $wp_rewrite WordPress rewrite component. + * + * @param int|false $year Integer of year. False for current year. * @return string The permalink for the specified year archive. */ function get_year_link( $year ) { @@ -496,10 +498,10 @@ * * @since 1.0.0 * - * @global WP_Rewrite $wp_rewrite - * - * @param bool|int $year False for current year. Integer of year. - * @param bool|int $month False for current month. Integer of month. + * @global WP_Rewrite $wp_rewrite WordPress rewrite component. + * + * @param int|false $year Integer of year. False for current year. + * @param int|false $month Integer of month. False for current month. * @return string The permalink for the specified month and year archive. */ function get_month_link( $year, $month ) { @@ -536,11 +538,11 @@ * * @since 1.0.0 * - * @global WP_Rewrite $wp_rewrite - * - * @param bool|int $year False for current year. Integer of year. - * @param bool|int $month False for current month. Integer of month. - * @param bool|int $day False for current day. Integer of day. + * @global WP_Rewrite $wp_rewrite WordPress rewrite component. + * + * @param int|false $year Integer of year. False for current year. + * @param int|false $month Integer of month. False for current month. + * @param int|false $day Integer of day. False for current day. * @return string The permalink for the specified day, month, and year archive. */ function get_day_link( $year, $month, $day ) { @@ -584,7 +586,8 @@ * @since 3.0.0 * * @param string $anchor The link's anchor text. - * @param string $feed Optional. Feed type. Default empty. + * @param string $feed Optional. Feed type. Possible values include 'rss2', 'atom'. + * Default is the value of get_default_feed(). */ function the_feed_link( $anchor, $feed = '' ) { $link = '' . $anchor . ''; @@ -595,8 +598,8 @@ * @since 3.0.0 * * @param string $link The complete anchor tag for a feed link. - * @param string $feed The feed type, or an empty string for the - * default feed type. + * @param string $feed The feed type. Possible values include 'rss2', 'atom', + * or an empty string for the default feed type. */ echo apply_filters( 'the_feed_link', $link, $feed ); } @@ -606,16 +609,18 @@ * * @since 1.5.0 * - * @global WP_Rewrite $wp_rewrite - * - * @param string $feed Optional. Feed type. Default empty. + * @global WP_Rewrite $wp_rewrite WordPress rewrite component. + * + * @param string $feed Optional. Feed type. Possible values include 'rss2', 'atom'. + * Default is the value of get_default_feed(). * @return string The feed permalink. */ function get_feed_link( $feed = '' ) { global $wp_rewrite; $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(); @@ -646,7 +651,8 @@ * @since 1.5.0 * * @param string $output The feed permalink. - * @param string $feed Feed type. + * @param string $feed The feed type. Possible values include 'rss2', 'atom', + * or an empty string for the default feed type. */ return apply_filters( 'feed_link', $output, $feed ); } @@ -657,7 +663,8 @@ * @since 2.2.0 * * @param int $post_id Optional. Post ID. Default is the ID of the global `$post`. - * @param string $feed Optional. Feed type. Default empty. + * @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. */ function get_post_comments_feed_link( $post_id = 0, $feed = '' ) { @@ -674,8 +681,8 @@ $post = get_post( $post_id ); $unattached = 'attachment' === $post->post_type && 0 === (int) $post->post_parent; - if ( '' != get_option( 'permalink_structure' ) ) { - if ( 'page' == get_option( 'show_on_front' ) && $post_id == get_option( 'page_on_front' ) ) { + if ( get_option( 'permalink_structure' ) ) { + if ( 'page' === get_option( 'show_on_front' ) && get_option( 'page_on_front' ) == $post_id ) { $url = _get_page_link( $post_id ); } else { $url = get_permalink( $post_id ); @@ -683,13 +690,13 @@ if ( $unattached ) { $url = home_url( '/feed/' ); - if ( $feed !== get_default_feed() ) { + if ( get_default_feed() !== $feed ) { $url .= "$feed/"; } $url = add_query_arg( 'attachment_id', $post_id, $url ); } else { $url = trailingslashit( $url ) . 'feed'; - if ( $feed != get_default_feed() ) { + if ( get_default_feed() != $feed ) { $url .= "/$feed"; } $url = user_trailingslashit( $url, 'single_feed' ); @@ -703,7 +710,7 @@ ), home_url( '/' ) ); - } elseif ( 'page' == $post->post_type ) { + } elseif ( 'page' === $post->post_type ) { $url = add_query_arg( array( 'feed' => $feed, @@ -743,7 +750,8 @@ * * @param string $link_text Optional. Descriptive link text. Default 'Comments Feed'. * @param int $post_id Optional. Post ID. Default is the ID of the global `$post`. - * @param string $feed Optional. Feed format. Default empty. + * @param string $feed Optional. Feed type. Possible values include 'rss2', 'atom'. + * Default is the value of get_default_feed(). */ function post_comments_feed_link( $link_text = '', $post_id = '', $feed = '' ) { $url = get_post_comments_feed_link( $post_id, $feed ); @@ -759,7 +767,8 @@ * * @param string $link The complete anchor tag for the comment feed link. * @param int $post_id Post ID. - * @param string $feed The feed type, or an empty string for the default feed type. + * @param string $feed The feed type. Possible values include 'rss2', 'atom', + * or an empty string for the default feed type. */ echo apply_filters( 'post_comments_feed_link_html', $link, $post_id, $feed ); } @@ -773,7 +782,8 @@ * @since 2.5.0 * * @param int $author_id Author ID. - * @param string $feed Optional. Feed type. Default empty. + * @param string $feed Optional. Feed type. Possible values include 'rss2', 'atom'. + * Default is the value of get_default_feed(). * @return string Link to the feed for the author specified by $author_id. */ function get_author_feed_link( $author_id, $feed = '' ) { @@ -784,11 +794,11 @@ $feed = get_default_feed(); } - if ( '' == $permalink_structure ) { + if ( ! $permalink_structure ) { $link = home_url( "?feed=$feed&author=" . $author_id ); } else { $link = get_author_posts_url( $author_id ); - if ( $feed == get_default_feed() ) { + if ( get_default_feed() == $feed ) { $feed_link = 'feed'; } else { $feed_link = "feed/$feed"; @@ -803,7 +813,7 @@ * @since 1.5.1 * * @param string $link The author feed link. - * @param string $feed Feed type. + * @param string $feed Feed type. Possible values include 'rss2', 'atom'. */ $link = apply_filters( 'author_feed_link', $link, $feed ); @@ -819,7 +829,8 @@ * @since 2.5.0 * * @param int $cat_id Category ID. - * @param string $feed Optional. Feed type. Default empty. + * @param string $feed Optional. Feed type. Possible values include 'rss2', 'atom'. + * Default is the value of get_default_feed(). * @return string Link to the feed for the category specified by $cat_id. */ function get_category_feed_link( $cat_id, $feed = '' ) { @@ -836,7 +847,8 @@ * * @param int $term_id Term ID. * @param string $taxonomy Optional. Taxonomy of `$term_id`. Default 'category'. - * @param string $feed Optional. Feed type. Default empty. + * @param string $feed Optional. Feed type. Possible values include 'rss2', 'atom'. + * Default is the value of get_default_feed(). * @return string|false Link to the feed for the term specified by $term_id and $taxonomy. */ function get_term_feed_link( $term_id, $taxonomy = 'category', $feed = '' ) { @@ -854,10 +866,10 @@ $permalink_structure = get_option( 'permalink_structure' ); - if ( '' == $permalink_structure ) { - if ( 'category' == $taxonomy ) { + if ( ! $permalink_structure ) { + if ( 'category' === $taxonomy ) { $link = home_url( "?feed=$feed&cat=$term_id" ); - } elseif ( 'post_tag' == $taxonomy ) { + } elseif ( 'post_tag' === $taxonomy ) { $link = home_url( "?feed=$feed&tag=$term->slug" ); } else { $t = get_taxonomy( $taxonomy ); @@ -865,7 +877,7 @@ } } else { $link = get_term_link( $term_id, $term->taxonomy ); - if ( $feed == get_default_feed() ) { + if ( get_default_feed() == $feed ) { $feed_link = 'feed'; } else { $feed_link = "feed/$feed"; @@ -874,24 +886,24 @@ $link = trailingslashit( $link ) . user_trailingslashit( $feed_link, 'feed' ); } - if ( 'category' == $taxonomy ) { + if ( 'category' === $taxonomy ) { /** * Filters the category feed link. * * @since 1.5.1 * * @param string $link The category feed link. - * @param string $feed Feed type. + * @param string $feed Feed type. Possible values include 'rss2', 'atom'. */ $link = apply_filters( 'category_feed_link', $link, $feed ); - } elseif ( 'post_tag' == $taxonomy ) { + } elseif ( 'post_tag' === $taxonomy ) { /** * Filters the post tag feed link. * * @since 2.3.0 * * @param string $link The tag feed link. - * @param string $feed Feed type. + * @param string $feed Feed type. Possible values include 'rss2', 'atom'. */ $link = apply_filters( 'tag_feed_link', $link, $feed ); } else { @@ -900,8 +912,8 @@ * * @since 3.0.0 * - * @param string $link The taxonomy feed link. - * @param string $feed Feed type. + * @param string $link The taxonomy feed link. + * @param string $feed Feed type. Possible values include 'rss2', 'atom'. * @param string $taxonomy The taxonomy name. */ $link = apply_filters( 'taxonomy_feed_link', $link, $feed, $taxonomy ); @@ -916,7 +928,8 @@ * @since 2.3.0 * * @param int $tag_id Tag ID. - * @param string $feed Optional. Feed type. Default empty. + * @param string $feed Optional. Feed type. Possible values include 'rss2', 'atom'. + * Default is the value of get_default_feed(). * @return string The feed permalink for the given tag. */ function get_tag_feed_link( $tag_id, $feed = '' ) { @@ -948,7 +961,7 @@ * * @since 2.7.0 * - * @param string $link Optional. Anchor text. Default empty. + * @param string $link Optional. Anchor text. If empty, default is 'Edit This'. Default empty. * @param string $before Optional. Display before edit link. Default empty. * @param string $after Optional. Display after edit link. Default empty. * @param WP_Term $tag Optional. Term object. If null, the queried object will be inspected. @@ -971,7 +984,7 @@ * Retrieves the URL for editing a given term. * * @since 3.1.0 - * @since 4.5.0 The `$taxonomy` argument was made optional. + * @since 4.5.0 The `$taxonomy` parameter was made optional. * * @param int $term_id Term ID. * @param string $taxonomy Optional. Taxonomy. Defaults to the taxonomy of the term identified @@ -1027,11 +1040,11 @@ * * @since 3.1.0 * - * @param string $link Optional. Anchor text. Default empty. - * @param string $before Optional. Display before edit link. Default empty. - * @param string $after Optional. Display after edit link. Default empty. - * @param object $term Optional. Term object. If null, the queried object will be inspected. Default null. - * @param bool $echo Optional. Whether or not to echo the return. Default true. + * @param string $link Optional. Anchor text. If empty, default is 'Edit This'. Default empty. + * @param string $before Optional. Display before edit link. Default empty. + * @param string $after Optional. Display after edit link. Default empty. + * @param WP_Term $term Optional. Term object. If null, the queried object will be inspected. Default null. + * @param bool $echo Optional. Whether or not to echo the return. Default true. * @return string|void HTML content. */ function edit_term_link( $link = '', $before = '', $after = '', $term = null, $echo = true ) { @@ -1074,9 +1087,9 @@ /** * Retrieves the permalink for a search. * - * @since 3.0.0 - * - * @global WP_Rewrite $wp_rewrite + * @since 3.0.0 + * + * @global WP_Rewrite $wp_rewrite WordPress rewrite component. * * @param string $query Optional. The query string to use. If empty the current query is used. Default empty. * @return string The search permalink. @@ -1117,10 +1130,11 @@ * * @since 2.5.0 * - * @global WP_Rewrite $wp_rewrite + * @global WP_Rewrite $wp_rewrite WordPress rewrite component. * * @param string $search_query Optional. Search query. Default empty. - * @param string $feed Optional. Feed type. Default empty. + * @param string $feed Optional. Feed type. Possible values include 'rss2', 'atom'. + * Default is the value of get_default_feed(). * @return string The search results feed permalink. */ function get_search_feed_link( $search_query = '', $feed = '' ) { @@ -1146,7 +1160,7 @@ * @since 2.5.0 * * @param string $link Search feed link. - * @param string $feed Feed type. + * @param string $feed Feed type. Possible values include 'rss2', 'atom'. * @param string $type The search type. One of 'posts' or 'comments'. */ return apply_filters( 'search_feed_link', $link, $feed, 'posts' ); @@ -1157,10 +1171,11 @@ * * @since 2.5.0 * - * @global WP_Rewrite $wp_rewrite + * @global WP_Rewrite $wp_rewrite WordPress rewrite component. * * @param string $search_query Optional. Search query. Default empty. - * @param string $feed Optional. Feed type. Default empty. + * @param string $feed Optional. Feed type. Possible values include 'rss2', 'atom'. + * Default is the value of get_default_feed(). * @return string The comments feed search results permalink. */ function get_search_comments_feed_link( $search_query = '', $feed = '' ) { @@ -1190,14 +1205,16 @@ * @since 3.1.0 * @since 4.5.0 Support for posts was added. * - * @global WP_Rewrite $wp_rewrite + * @global WP_Rewrite $wp_rewrite WordPress rewrite component. * * @param string $post_type Post type. * @return string|false The post type archive permalink. */ function get_post_type_archive_link( $post_type ) { global $wp_rewrite; - if ( ! $post_type_obj = get_post_type_object( $post_type ) ) { + + $post_type_obj = get_post_type_object( $post_type ); + if ( ! $post_type_obj ) { return false; } @@ -1205,7 +1222,7 @@ $show_on_front = get_option( 'show_on_front' ); $page_for_posts = get_option( 'page_for_posts' ); - if ( 'page' == $show_on_front && $page_for_posts ) { + if ( 'page' === $show_on_front && $page_for_posts ) { $link = get_permalink( $page_for_posts ); } else { $link = get_home_url(); @@ -1247,7 +1264,8 @@ * @since 3.1.0 * * @param string $post_type Post type - * @param string $feed Optional. Feed type. Default empty. + * @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. */ function get_post_type_archive_feed_link( $post_type, $feed = '' ) { @@ -1256,7 +1274,8 @@ $feed = $default_feed; } - if ( ! $link = get_post_type_archive_link( $post_type ) ) { + $link = get_post_type_archive_link( $post_type ); + if ( ! $link ) { return false; } @@ -1277,7 +1296,7 @@ * @since 3.1.0 * * @param string $link The post type archive feed link. - * @param string $feed Feed type. + * @param string $feed Feed type. Possible values include 'rss2', 'atom'. */ return apply_filters( 'post_type_archive_feed_link', $link, $feed ); } @@ -1338,13 +1357,14 @@ * not allow an editing UI. */ function get_edit_post_link( $id = 0, $context = 'display' ) { - if ( ! $post = get_post( $id ) ) { + $post = get_post( $id ); + if ( ! $post ) { return; } if ( 'revision' === $post->post_type ) { $action = ''; - } elseif ( 'display' == $context ) { + } elseif ( 'display' === $context ) { $action = '&action=edit'; } else { $action = '&action=edit'; @@ -1391,11 +1411,13 @@ * @param string $class Optional. Add custom class to link. Default 'post-edit-link'. */ function edit_post_link( $text = null, $before = '', $after = '', $id = 0, $class = 'post-edit-link' ) { - if ( ! $post = get_post( $id ) ) { + $post = get_post( $id ); + if ( ! $post ) { return; } - if ( ! $url = get_edit_post_link( $post->ID ) ) { + $url = get_edit_post_link( $post->ID ); + if ( ! $url ) { return; } @@ -1426,7 +1448,7 @@ * * @param int|WP_Post $id Optional. Post ID or post object. Default is the global `$post`. * @param string $deprecated Not used. - * @param bool $force_delete Optional. Whether to bypass trash and force deletion. Default false. + * @param bool $force_delete Optional. Whether to bypass Trash and force deletion. Default false. * @return string|void The delete post link URL for the given post. */ function get_delete_post_link( $id = 0, $deprecated = '', $force_delete = false ) { @@ -1434,7 +1456,8 @@ _deprecated_argument( __FUNCTION__, '3.0.0' ); } - if ( ! $post = get_post( $id ) ) { + $post = get_post( $id ); + if ( ! $post ) { return; } @@ -1458,7 +1481,7 @@ * * @param string $link The delete link. * @param int $post_id Post ID. - * @param bool $force_delete Whether to bypass the trash and force deletion. Default false. + * @param bool $force_delete Whether to bypass the Trash and force deletion. Default false. */ return apply_filters( 'get_delete_post_link', wp_nonce_url( $delete_link, "$action-post_{$post->ID}" ), $post->ID, $force_delete ); } @@ -1529,7 +1552,7 @@ * * @since 2.7.0 * - * @param int|stdClass $link Optional. Bookmark ID. Default is the id of the current bookmark. + * @param int|stdClass $link Optional. Bookmark ID. Default is the ID of the current bookmark. * @return string|void The edit bookmark link URL. */ function get_edit_bookmark_link( $link = 0 ) { @@ -1557,7 +1580,7 @@ * * @since 2.7.0 * - * @param string $link Optional. Anchor text. Default empty. + * @param string $link Optional. Anchor text. If empty, default is 'Edit This'. Default empty. * @param string $before Optional. Display before edit link. Default empty. * @param string $after Optional. Display after edit link. Default empty. * @param int $bookmark Optional. Bookmark ID. Default is the current bookmark. @@ -1626,7 +1649,9 @@ return apply_filters( 'get_edit_user_link', $link, $user->ID ); } -// Navigation links +// +// Navigation links. +// /** * Retrieves the previous post that is adjacent to the current post. @@ -1677,7 +1702,8 @@ function get_adjacent_post( $in_same_term = false, $excluded_terms = '', $previous = true, $taxonomy = 'category' ) { global $wpdb; - if ( ( ! $post = get_post() ) || ! taxonomy_exists( $taxonomy ) ) { + $post = get_post(); + if ( ! $post || ! taxonomy_exists( $taxonomy ) ) { return null; } @@ -1690,7 +1716,15 @@ if ( ! empty( $excluded_terms ) && ! is_array( $excluded_terms ) ) { // Back-compat, $excluded_terms used to be $excluded_categories with IDs separated by " and ". if ( false !== strpos( $excluded_terms, ' and ' ) ) { - _deprecated_argument( __FUNCTION__, '3.3.0', sprintf( __( 'Use commas instead of %s to separate excluded terms.' ), "'and'" ) ); + _deprecated_argument( + __FUNCTION__, + '3.3.0', + sprintf( + /* translators: %s: The word 'and'. */ + __( 'Use commas instead of %s to separate excluded terms.' ), + "'and'" + ) + ); $excluded_terms = explode( ' and ', $excluded_terms ); } else { $excluded_terms = explode( ',', $excluded_terms ); @@ -1859,7 +1893,8 @@ * @return string|void The adjacent post relational link URL. */ function get_adjacent_post_rel_link( $title = '%title', $in_same_term = false, $excluded_terms = '', $previous = true, $taxonomy = 'category' ) { - if ( $previous && is_attachment() && $post = get_post() ) { + $post = get_post(); + if ( $previous && is_attachment() && $post ) { $post = get_post( $post->post_parent ); } else { $post = get_adjacent_post( $in_same_term, $excluded_terms, $previous, $taxonomy ); @@ -2087,6 +2122,7 @@ * Displays the next post link that is adjacent to the current post. * * @since 1.5.0 + * * @see get_next_post_link() * * @param string $format Optional. Link anchor format. Default '« %link'. @@ -2187,7 +2223,7 @@ * * @since 1.5.0 * - * @global WP_Rewrite $wp_rewrite + * @global WP_Rewrite $wp_rewrite WordPress rewrite component. * * @param int $pagenum Optional. Page number. Default 1. * @param bool $escape Optional. Whether to escape the URL for display, with esc_url(). Defaults to true. @@ -2233,7 +2269,7 @@ $base = trailingslashit( get_bloginfo( 'url' ) ); - if ( $wp_rewrite->using_index_permalinks() && ( $pagenum > 1 || '' != $request ) ) { + if ( $wp_rewrite->using_index_permalinks() && ( $pagenum > 1 || '' !== $request ) ) { $base .= $wp_rewrite->index . '/'; } @@ -2293,8 +2329,8 @@ * * @since 0.71 * - * @param int $max_page Optional. Max pages. Default 0. - * @param bool $echo Optional. Whether to echo the link. Default true. + * @param int $max_page Optional. Max pages. Default 0. + * @param bool $echo Optional. Whether to echo the link. Default true. * @return string|void The link URL for next posts page if `$echo = false`. */ function next_posts( $max_page = 0, $echo = true ) { @@ -2313,7 +2349,7 @@ * @since 2.7.0 * * @global int $paged - * @global WP_Query $wp_query + * @global WP_Query $wp_query WordPress Query object. * * @param string $label Content for link text. * @param int $max_page Optional. Max pages. Default 0. @@ -2451,7 +2487,7 @@ * * @since 2.8.0 * - * @global WP_Query $wp_query + * @global WP_Query $wp_query WordPress Query object. * * @param string|array $args { * Optional. Arguments to build the post pages link navigation. @@ -2480,7 +2516,7 @@ $max_num_pages = $wp_query->max_num_pages; $paged = get_query_var( 'paged' ); - //only have sep if there's both prev and next results + // Only have sep if there's both prev and next results. if ( $paged < 2 || $paged >= $max_num_pages ) { $args['sep'] = ''; } @@ -2514,6 +2550,8 @@ * * @since 4.1.0 * @since 4.4.0 Introduced the `in_same_term`, `excluded_terms`, and `taxonomy` arguments. + * @since 5.3.0 Added the `aria_label` parameter. + * @since 5.5.0 Added the `class` parameter. * * @param array $args { * Optional. Default post navigation arguments. Default empty array. @@ -2523,11 +2561,18 @@ * @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 string $taxonomy Taxonomy, if `$in_same_term` is true. Default 'category'. - * @type string $screen_reader_text Screen reader text for nav element. Default 'Post navigation'. + * @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'. + * @type string $class Custom class for the nav element. Default 'post-navigation'. * } * @return string Markup for post links. */ function get_the_post_navigation( $args = array() ) { + // Make sure the nav element has an aria-label attribute: fallback to the screen reader text. + if ( ! empty( $args['screen_reader_text'] ) && empty( $args['aria_label'] ) ) { + $args['aria_label'] = $args['screen_reader_text']; + } + $args = wp_parse_args( $args, array( @@ -2537,6 +2582,8 @@ 'excluded_terms' => '', 'taxonomy' => 'category', 'screen_reader_text' => __( 'Post navigation' ), + 'aria_label' => __( 'Posts' ), + 'class' => 'post-navigation', ) ); @@ -2560,7 +2607,7 @@ // Only add markup if there's somewhere to navigate to. if ( $previous || $next ) { - $navigation = _navigation_markup( $previous . $next, 'post-navigation', $args['screen_reader_text'] ); + $navigation = _navigation_markup( $previous . $next, $args['class'], $args['screen_reader_text'], $args['aria_label'] ); } return $navigation; @@ -2582,6 +2629,8 @@ * Returns the navigation to next/previous set of posts, when applicable. * * @since 4.1.0 + * @since 5.3.0 Added the `aria_label` parameter. + * @since 5.5.0 Added the `class` parameter. * * @global WP_Query $wp_query WordPress Query object. * @@ -2592,8 +2641,10 @@ * Default 'Older posts'. * @type string $next_text Anchor text to display in the next posts link. * Default 'Newer posts'. - * @type string $screen_reader_text Screen reader text for nav element. + * @type string $screen_reader_text Screen reader text for the nav element. * Default 'Posts navigation'. + * @type string $aria_label ARIA label text for the nav element. Default 'Posts'. + * @type string $class Custom class for the nav element. Default 'posts-navigation'. * } * @return string Markup for posts links. */ @@ -2602,12 +2653,19 @@ // Don't print empty markup if there's only one page. if ( $GLOBALS['wp_query']->max_num_pages > 1 ) { + // Make sure the nav element has an aria-label attribute: fallback to the screen reader text. + if ( ! empty( $args['screen_reader_text'] ) && empty( $args['aria_label'] ) ) { + $args['aria_label'] = $args['screen_reader_text']; + } + $args = wp_parse_args( $args, array( 'prev_text' => __( 'Older posts' ), 'next_text' => __( 'Newer posts' ), 'screen_reader_text' => __( 'Posts navigation' ), + 'aria_label' => __( 'Posts' ), + 'class' => 'posts-navigation', ) ); @@ -2622,7 +2680,7 @@ $navigation .= ''; } - $navigation = _navigation_markup( $navigation, 'posts-navigation', $args['screen_reader_text'] ); + $navigation = _navigation_markup( $navigation, $args['class'], $args['screen_reader_text'], $args['aria_label'] ); } return $navigation; @@ -2644,12 +2702,16 @@ * Retrieves a paginated navigation to next/previous set of posts, when applicable. * * @since 4.1.0 + * @since 5.3.0 Added the `aria_label` parameter. + * @since 5.5.0 Added the `class` parameter. * * @param array $args { * Optional. Default pagination arguments, see paginate_links(). * * @type string $screen_reader_text Screen reader text for navigation element. * Default 'Posts navigation'. + * @type string $aria_label ARIA label text for the nav element. Default 'Posts'. + * @type string $class Custom class for the nav element. Default 'pagination'. * } * @return string Markup for pagination links. */ @@ -2658,6 +2720,11 @@ // Don't print empty markup if there's only one page. if ( $GLOBALS['wp_query']->max_num_pages > 1 ) { + // Make sure the nav element has an aria-label attribute: fallback to the screen reader text. + if ( ! empty( $args['screen_reader_text'] ) && empty( $args['aria_label'] ) ) { + $args['aria_label'] = $args['screen_reader_text']; + } + $args = wp_parse_args( $args, array( @@ -2665,11 +2732,13 @@ 'prev_text' => _x( 'Previous', 'previous set of posts' ), 'next_text' => _x( 'Next', 'next set of posts' ), 'screen_reader_text' => __( 'Posts navigation' ), + 'aria_label' => __( 'Posts' ), + 'class' => 'pagination', ) ); // Make sure we get a string back. Plain is the next best thing. - if ( isset( $args['type'] ) && 'array' == $args['type'] ) { + if ( isset( $args['type'] ) && 'array' === $args['type'] ) { $args['type'] = 'plain'; } @@ -2677,7 +2746,7 @@ $links = paginate_links( $args ); if ( $links ) { - $navigation = _navigation_markup( $links, 'pagination', $args['screen_reader_text'] ); + $navigation = _navigation_markup( $links, $args['class'], $args['screen_reader_text'], $args['aria_label'] ); } } @@ -2700,20 +2769,28 @@ * Wraps passed links in navigational markup. * * @since 4.1.0 + * @since 5.3.0 Added the `aria_label` parameter. * @access private * * @param string $links Navigational links. - * @param string $class Optional. Custom class for nav element. Default: 'posts-navigation'. - * @param string $screen_reader_text Optional. Screen reader text for nav element. Default: 'Posts navigation'. + * @param string $class Optional. Custom class for the nav element. + * Default 'posts-navigation'. + * @param string $screen_reader_text Optional. Screen reader text for the nav element. + * Default 'Posts navigation'. + * @param string $aria_label Optional. ARIA label for the nav element. + * Defaults to the value of `$screen_reader_text`. * @return string Navigation template tag. */ -function _navigation_markup( $links, $class = 'posts-navigation', $screen_reader_text = '' ) { +function _navigation_markup( $links, $class = 'posts-navigation', $screen_reader_text = '', $aria_label = '' ) { if ( empty( $screen_reader_text ) ) { $screen_reader_text = __( 'Posts navigation' ); } + if ( empty( $aria_label ) ) { + $aria_label = $screen_reader_text; + } $template = ' -