Make WordPress Core

Ticket #52220: 52220.diff

File 52220.diff, 3.0 KB (added by sawf1y, 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() {  
    71717171
    71727172/**
    71737173 * 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.
    71747179 *
    71757180 * @ignore
    71767181 * @since 3.0.0
    … … function _wp_mysql_week( $column ) {  
    71827187        $start_of_week = (int) get_option( 'start_of_week' );
    71837188        switch ( $start_of_week ) {
    71847189                case 1:
    7185                         return "WEEK( $column, 1 )";
     7190                        return "WEEK( $column, 3 )";
    71867191                case 2:
    71877192                case 3:
    71887193                case 4:
    71897194                case 5:
    71907195                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 )";
    71927197                case 0:
    71937198                default:
    7194                         return "WEEK( $column, 0 )";
     7199                        return "WEEK( $column, 2 )";
    71957200        }
    71967201}
    71977202
  • 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 {  
    3131         */
    3232        public function data_wp_mysql_week() {
    3333                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 )' ),
    4242                );
    4343        }
    4444}