Changeset 53429
- Timestamp:
- 05/22/2022 03:15:47 PM (2 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/query.php
r53395 r53429 940 940 function have_posts() { 941 941 global $wp_query; 942 943 if ( ! isset( $wp_query ) ) { 944 return false; 945 } 946 942 947 return $wp_query->have_posts(); 943 948 } … … 958 963 function in_the_loop() { 959 964 global $wp_query; 965 966 if ( ! isset( $wp_query ) ) { 967 return false; 968 } 969 960 970 return $wp_query->in_the_loop; 961 971 } … … 970 980 function rewind_posts() { 971 981 global $wp_query; 982 983 if ( ! isset( $wp_query ) ) { 984 return; 985 } 986 972 987 $wp_query->rewind_posts(); 973 988 } … … 982 997 function the_post() { 983 998 global $wp_query; 999 1000 if ( ! isset( $wp_query ) ) { 1001 return; 1002 } 1003 984 1004 $wp_query->the_post(); 985 1005 } … … 1000 1020 function have_comments() { 1001 1021 global $wp_query; 1022 1023 if ( ! isset( $wp_query ) ) { 1024 return false; 1025 } 1026 1002 1027 return $wp_query->have_comments(); 1003 1028 } … … 1009 1034 * 1010 1035 * @global WP_Query $wp_query WordPress Query object. 1011 *1012 * @return null1013 1036 */ 1014 1037 function the_comment() { 1015 1038 global $wp_query; 1016 return $wp_query->the_comment(); 1039 1040 if ( ! isset( $wp_query ) ) { 1041 return; 1042 } 1043 1044 $wp_query->the_comment(); 1017 1045 } 1018 1046 -
trunk/tests/phpunit/tests/query/conditionals.php
r53400 r53429 1661 1661 } 1662 1662 1663 /** 1664 * @ticket 55722 1665 * 1666 * @dataProvider data_loop_functions_do_not_trigger_a_fatal_error_if_wp_query_is_not_set 1667 * 1668 * @param string $function_name The name of the function to test. 1669 * @param false|null $expected Expected return value. 1670 */ 1671 public function test_loop_functions_do_not_trigger_a_fatal_error_if_wp_query_is_not_set( $function_name, $expected ) { 1672 unset( $GLOBALS['wp_query'] ); 1673 1674 $this->assertSame( $expected, call_user_func( $function_name ) ); 1675 } 1676 1677 /** 1678 * Data provider. 1679 * 1680 * @return array[] Test parameters { 1681 * @type string $function_name The name of the function to test. 1682 * @type false|null $expected Expected return value. 1683 * } 1684 */ 1685 public function data_loop_functions_do_not_trigger_a_fatal_error_if_wp_query_is_not_set() { 1686 return array( 1687 array( 'have_posts', false ), 1688 array( 'in_the_loop', false ), 1689 array( 'rewind_posts', null ), 1690 array( 'the_post', null ), 1691 array( 'have_comments', false ), 1692 array( 'the_comment', null ), 1693 ); 1694 } 1695 1663 1696 }
Note: See TracChangeset
for help on using the changeset viewer.