Changeset 42343 for trunk/src/wp-includes/date.php
- Timestamp:
- 11/30/2017 11:09:33 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/date.php
r41162 r42343 264 264 */ 265 265 public function get_compare( $query ) { 266 if ( ! empty( $query['compare'] ) && in_array( $query['compare'], array( '=', '!=', '>', '>=', '<', '<=', 'IN', 'NOT IN', 'BETWEEN', 'NOT BETWEEN' ) ) ) 266 if ( ! empty( $query['compare'] ) && in_array( $query['compare'], array( '=', '!=', '>', '>=', '<', '<=', 'IN', 'NOT IN', 'BETWEEN', 'NOT BETWEEN' ) ) ) { 267 267 return strtoupper( $query['compare'] ); 268 } 268 269 269 270 return $this->compare; … … 294 295 * values generate errors too. 295 296 */ 296 if ( array_key_exists( 'before', $date_query ) && is_array( $date_query['before'] ) ) {297 if ( array_key_exists( 'before', $date_query ) && is_array( $date_query['before'] ) ) { 297 298 $valid = $this->validate_date_values( $date_query['before'] ); 298 299 } 299 300 300 if ( array_key_exists( 'after', $date_query ) && is_array( $date_query['after'] ) ) {301 if ( array_key_exists( 'after', $date_query ) && is_array( $date_query['after'] ) ) { 301 302 $valid = $this->validate_date_values( $date_query['after'] ); 302 303 } … … 325 326 $min_max_checks['dayofyear'] = array( 326 327 'min' => 1, 327 'max' => $max_days_of_year 328 'max' => $max_days_of_year, 328 329 ); 329 330 … … 331 332 $min_max_checks['dayofweek'] = array( 332 333 'min' => 1, 333 'max' => 7 334 'max' => 7, 334 335 ); 335 336 … … 337 338 $min_max_checks['dayofweek_iso'] = array( 338 339 'min' => 1, 339 'max' => 7 340 'max' => 7, 340 341 ); 341 342 … … 343 344 $min_max_checks['month'] = array( 344 345 'min' => 1, 345 'max' => 12 346 'max' => 12, 346 347 ); 347 348 … … 361 362 $min_max_checks['week'] = array( 362 363 'min' => 1, 363 'max' => $week_count 364 'max' => $week_count, 364 365 ); 365 366 … … 367 368 $min_max_checks['day'] = array( 368 369 'min' => 1, 369 'max' => 31 370 'max' => 31, 370 371 ); 371 372 … … 373 374 $min_max_checks['hour'] = array( 374 375 'min' => 0, 375 'max' => 23 376 'max' => 23, 376 377 ); 377 378 … … 379 380 $min_max_checks['minute'] = array( 380 381 'min' => 0, 381 'max' => 59 382 'max' => 59, 382 383 ); 383 384 … … 385 386 $min_max_checks['second'] = array( 386 387 'min' => 0, 387 'max' => 59 388 'max' => 59, 388 389 ); 389 390 … … 439 440 $valid = false; 440 441 } 441 442 442 } elseif ( $day_exists && $month_exists ) { 443 443 /* … … 481 481 482 482 $valid_columns = array( 483 'post_date', 'post_date_gmt', 'post_modified', 484 'post_modified_gmt', 'comment_date', 'comment_date_gmt', 485 'user_registered', 'registered', 'last_updated', 483 'post_date', 484 'post_date_gmt', 485 'post_modified', 486 'post_modified_gmt', 487 'comment_date', 488 'comment_date_gmt', 489 'user_registered', 490 'registered', 491 'last_updated', 486 492 ); 487 493 … … 497 503 * are 'post_date', 'post_date_gmt', 'post_modified', 498 504 * 'post_modified_gmt', 'comment_date', 'comment_date_gmt', 499 * 505 * 'user_registered' 500 506 */ 501 507 if ( ! in_array( $column, apply_filters( 'date_query_valid_columns', $valid_columns ) ) ) { … … 504 510 505 511 $known_columns = array( 506 $wpdb->posts => array(512 $wpdb->posts => array( 507 513 'post_date', 508 514 'post_date_gmt', … … 514 520 'comment_date_gmt', 515 521 ), 516 $wpdb->users => array(522 $wpdb->users => array( 517 523 'user_registered', 518 524 ), 519 $wpdb->blogs => array(525 $wpdb->blogs => array( 520 526 'registered', 521 527 'last_updated', … … 530 536 } 531 537 } 532 533 538 } 534 539 … … 616 621 $indent = ''; 617 622 for ( $i = 0; $i < $depth; $i++ ) { 618 $indent .= " ";623 $indent .= ' '; 619 624 } 620 625 … … 638 643 639 644 $sql_chunks['join'] = array_merge( $sql_chunks['join'], $clause_sql['join'] ); 640 // This is a subquery, so we recurse.645 // This is a subquery, so we recurse. 641 646 } else { 642 647 $clause_sql = $this->get_sql_for_query( $clause, $depth + 1 ); … … 735 740 // Specific value queries. 736 741 737 if ( isset( $query['year'] ) && $value = $this->build_value( $compare, $query['year'] ) ) 742 if ( isset( $query['year'] ) && $value = $this->build_value( $compare, $query['year'] ) ) { 738 743 $where_parts[] = "YEAR( $column ) $compare $value"; 744 } 739 745 740 746 if ( isset( $query['month'] ) && $value = $this->build_value( $compare, $query['month'] ) ) { … … 748 754 $where_parts[] = _wp_mysql_week( $column ) . " $compare $value"; 749 755 } 750 if ( isset( $query['dayofyear'] ) && $value = $this->build_value( $compare, $query['dayofyear'] ) ) 756 if ( isset( $query['dayofyear'] ) && $value = $this->build_value( $compare, $query['dayofyear'] ) ) { 751 757 $where_parts[] = "DAYOFYEAR( $column ) $compare $value"; 752 753 if ( isset( $query['day'] ) && $value = $this->build_value( $compare, $query['day'] ) ) 758 } 759 760 if ( isset( $query['day'] ) && $value = $this->build_value( $compare, $query['day'] ) ) { 754 761 $where_parts[] = "DAYOFMONTH( $column ) $compare $value"; 755 756 if ( isset( $query['dayofweek'] ) && $value = $this->build_value( $compare, $query['dayofweek'] ) ) 762 } 763 764 if ( isset( $query['dayofweek'] ) && $value = $this->build_value( $compare, $query['dayofweek'] ) ) { 757 765 $where_parts[] = "DAYOFWEEK( $column ) $compare $value"; 758 759 if ( isset( $query['dayofweek_iso'] ) && $value = $this->build_value( $compare, $query['dayofweek_iso'] ) ) 766 } 767 768 if ( isset( $query['dayofweek_iso'] ) && $value = $this->build_value( $compare, $query['dayofweek_iso'] ) ) { 760 769 $where_parts[] = "WEEKDAY( $column ) + 1 $compare $value"; 770 } 761 771 762 772 if ( isset( $query['hour'] ) || isset( $query['minute'] ) || isset( $query['second'] ) ) { … … 793 803 */ 794 804 public function build_value( $compare, $value ) { 795 if ( ! isset( $value ) ) 805 if ( ! isset( $value ) ) { 796 806 return false; 807 } 797 808 798 809 switch ( $compare ) { … … 904 915 $datetime = array_map( 'absint', $datetime ); 905 916 906 if ( ! isset( $datetime['year'] ) ) 917 if ( ! isset( $datetime['year'] ) ) { 907 918 $datetime['year'] = gmdate( 'Y', $now ); 908 909 if ( ! isset( $datetime['month'] ) ) 919 } 920 921 if ( ! isset( $datetime['month'] ) ) { 910 922 $datetime['month'] = ( $default_to_max ) ? 12 : 1; 911 912 if ( ! isset( $datetime['day'] ) ) 923 } 924 925 if ( ! isset( $datetime['day'] ) ) { 913 926 $datetime['day'] = ( $default_to_max ) ? (int) date( 't', mktime( 0, 0, 0, $datetime['month'], 1, $datetime['year'] ) ) : 1; 914 915 if ( ! isset( $datetime['hour'] ) ) 927 } 928 929 if ( ! isset( $datetime['hour'] ) ) { 916 930 $datetime['hour'] = ( $default_to_max ) ? 23 : 0; 917 918 if ( ! isset( $datetime['minute'] ) ) 931 } 932 933 if ( ! isset( $datetime['minute'] ) ) { 919 934 $datetime['minute'] = ( $default_to_max ) ? 59 : 0; 920 921 if ( ! isset( $datetime['second'] ) ) 935 } 936 937 if ( ! isset( $datetime['second'] ) ) { 922 938 $datetime['second'] = ( $default_to_max ) ? 59 : 0; 939 } 923 940 924 941 return sprintf( '%04d-%02d-%02d %02d:%02d:%02d', $datetime['year'], $datetime['month'], $datetime['day'], $datetime['hour'], $datetime['minute'], $datetime['second'] ); … … 945 962 946 963 // Have to have at least one 947 if ( ! isset( $hour ) && ! isset( $minute ) && ! isset( $second ) ) 964 if ( ! isset( $hour ) && ! isset( $minute ) && ! isset( $second ) ) { 948 965 return false; 966 } 949 967 950 968 // Complex combined queries aren't supported for multi-value queries … … 952 970 $return = array(); 953 971 954 if ( isset( $hour ) && false !== ( $value = $this->build_value( $compare, $hour ) ) ) 972 if ( isset( $hour ) && false !== ( $value = $this->build_value( $compare, $hour ) ) ) { 955 973 $return[] = "HOUR( $column ) $compare $value"; 956 957 if ( isset( $minute ) && false !== ( $value = $this->build_value( $compare, $minute ) ) ) 974 } 975 976 if ( isset( $minute ) && false !== ( $value = $this->build_value( $compare, $minute ) ) ) { 958 977 $return[] = "MINUTE( $column ) $compare $value"; 959 960 if ( isset( $second ) && false !== ( $value = $this->build_value( $compare, $second ) ) ) 978 } 979 980 if ( isset( $second ) && false !== ( $value = $this->build_value( $compare, $second ) ) ) { 961 981 $return[] = "SECOND( $column ) $compare $value"; 982 } 962 983 963 984 return implode( ' AND ', $return ); … … 974 995 975 996 // Single units were already handled. Since hour & second isn't allowed, minute must to be set. 976 if ( ! isset( $minute ) ) 997 if ( ! isset( $minute ) ) { 977 998 return false; 999 } 978 1000 979 1001 $format = $time = '';
Note: See TracChangeset
for help on using the changeset viewer.