From 0fa05bacca9b5cf56a904bca165580a210d25a3d Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Sat, 18 Jun 2022 15:36:20 +0000 Subject: [PATCH] Docs: Consistently declare the `$wp_query` global in link template functions. This ensures that the global is explicitly declared and documented in: * `get_next_posts_link()` * `get_posts_nav_link()` * `get_the_posts_navigation()` * `get_the_posts_pagination()` * `get_next_comments_link()` Follow-up to [30065]. Props mt8.biz, sabernhardt. Fixes #43164. git-svn-id: https://develop.svn.wordpress.org/trunk@53520 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/link-template.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/wp-includes/link-template.php b/src/wp-includes/link-template.php index fc1a89fd29..3e33865bd0 100644 --- a/src/wp-includes/link-template.php +++ b/src/wp-includes/link-template.php @@ -2765,10 +2765,12 @@ function the_post_navigation( $args = array() ) { * @return string Markup for posts links. */ function get_the_posts_navigation( $args = array() ) { + global $wp_query; + $navigation = ''; // Don't print empty markup if there's only one page. - if ( $GLOBALS['wp_query']->max_num_pages > 1 ) { + if ( $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']; @@ -2821,6 +2823,8 @@ function the_posts_navigation( $args = array() ) { * @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. + * * @param array $args { * Optional. Default pagination arguments, see paginate_links(). * @@ -2832,10 +2836,12 @@ function the_posts_navigation( $args = array() ) { * @return string Markup for pagination links. */ function get_the_posts_pagination( $args = array() ) { + global $wp_query; + $navigation = ''; // Don't print empty markup if there's only one page. - if ( $GLOBALS['wp_query']->max_num_pages > 1 ) { + if ( $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'];