Ticket #52220: 52220.diff
| File 52220.diff, 3.0 KB (added by , 3 months ago) |
|---|
-
src/wp-includes/functions.php
diff --git a/src/wp-includes/functions.php b/src/wp-includes/functions.php index f5002a45de..3fb1d15e30 100644
a b function send_nosniff_header() { 7171 7171 7172 7172 /** 7173 7173 * Returns a MySQL expression for selecting the week number based on the start_of_week option. 7174 * @ticket 52220 - Former used MySQL::WEEK modes 0 and 1 changed to 2 and 3 respectively. 7175 * Modes 0 and 1 return weeks numbers from 0 to 53, while modes 2 and 3 return week numbers from 1 to 53 which is corresponds to our documentation: 7176 * https://github.com/WordPress/wordpress-develop/blob/de2572b1da20f0fe6f53eebd6b8bf10ae066dd2f/src/wp-includes/class-wp-query.php#L807 7177 * Also, WP ignores GET parameter w=0 and didn't allow to select posts from the first week (w=0) of the year correctly with 0 and 1 used modes. 7178 * Modes 2 and 3 fix this issue and allow to select posts from the first week of the year correctly. 7174 7179 * 7175 7180 * @ignore 7176 7181 * @since 3.0.0 … … function _wp_mysql_week( $column ) { 7182 7187 $start_of_week = (int) get_option( 'start_of_week' ); 7183 7188 switch ( $start_of_week ) { 7184 7189 case 1: 7185 return "WEEK( $column, 1)";7190 return "WEEK( $column, 3 )"; 7186 7191 case 2: 7187 7192 case 3: 7188 7193 case 4: 7189 7194 case 5: 7190 7195 case 6: 7191 return "WEEK( DATE_SUB( $column, INTERVAL $start_of_week DAY ), 0)";7196 return "WEEK( DATE_SUB( $column, INTERVAL $start_of_week DAY ), 2 )"; 7192 7197 case 0: 7193 7198 default: 7194 return "WEEK( $column, 0)";7199 return "WEEK( $column, 2 )"; 7195 7200 } 7196 7201 } 7197 7202 -
tests/phpunit/tests/functions/wpMysqlWeek.php
diff --git a/tests/phpunit/tests/functions/wpMysqlWeek.php b/tests/phpunit/tests/functions/wpMysqlWeek.php index 3649ee6c4c..340f614889 100644
a b class Tests_Functions_WpMysqlWeek extends WP_UnitTestCase { 31 31 */ 32 32 public function data_wp_mysql_week() { 33 33 return array( 34 array( '1969-12-25', 0, 'WEEK( col_name, 0)' ),35 array( '1969-12-25', 1, 'WEEK( col_name, 1)' ),36 array( '1969-12-25', 2, 'WEEK( DATE_SUB( col_name, INTERVAL 2 DAY ), 0)' ),37 array( '1969-12-25', 3, 'WEEK( DATE_SUB( col_name, INTERVAL 3 DAY ), 0)' ),38 array( '1969-12-25', 4, 'WEEK( DATE_SUB( col_name, INTERVAL 4 DAY ), 0)' ),39 array( '1969-12-25', 5, 'WEEK( DATE_SUB( col_name, INTERVAL 5 DAY ), 0)' ),40 array( '1969-12-25', 6, 'WEEK( DATE_SUB( col_name, INTERVAL 6 DAY ), 0)' ),41 array( '1969-12-25', 9, 'WEEK( col_name, 0)' ),34 array( '1969-12-25', 0, 'WEEK( col_name, 2 )' ), 35 array( '1969-12-25', 1, 'WEEK( col_name, 3 )' ), 36 array( '1969-12-25', 2, 'WEEK( DATE_SUB( col_name, INTERVAL 2 DAY ), 2 )' ), 37 array( '1969-12-25', 3, 'WEEK( DATE_SUB( col_name, INTERVAL 3 DAY ), 2 )' ), 38 array( '1969-12-25', 4, 'WEEK( DATE_SUB( col_name, INTERVAL 4 DAY ), 2 )' ), 39 array( '1969-12-25', 5, 'WEEK( DATE_SUB( col_name, INTERVAL 5 DAY ), 2 )' ), 40 array( '1969-12-25', 6, 'WEEK( DATE_SUB( col_name, INTERVAL 6 DAY ), 2 )' ), 41 array( '1969-12-25', 9, 'WEEK( col_name, 2 )' ), 42 42 ); 43 43 } 44 44 }
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)