Make WordPress Core

Changeset 59767


Ignore:
Timestamp:
02/06/2025 12:22:22 PM (3 hours ago)
Author:
SergeyBiryukov
Message:

Coding Standards: Use strict comparison in media_upload_library_form().

Includes bringing some consistency with a similar fragment in WP_List_Table::months_dropdown().

Follow-up to [3724], [7062], [15491], [59755].

Props aristath, poena, afercia, SergeyBiryukov.
See #62279.

Location:
trunk/src/wp-admin/includes
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/class-wp-list-table.php

    r59755 r59767  
    781781                "<option %s value='%s'>%s</option>\n",
    782782                selected( $selected_month, $year . $month, false ),
    783                 esc_attr( $arc_row->year . $month ),
     783                esc_attr( $year . $month ),
    784784                /* translators: 1: Month name, 2: 4-digit year. */
    785                 sprintf( __( '%1$s %2$d' ), $wp_locale->get_month( $month ), $year )
     785                esc_html( sprintf( __( '%1$s %2$d' ), $wp_locale->get_month( $month ), $year ) )
    786786            );
    787787        }
  • trunk/src/wp-admin/includes/media.php

    r59751 r59767  
    28462846    <div class="alignleft actions">
    28472847        <?php
    2848 
    2849         $arc_query = "SELECT DISTINCT YEAR(post_date) AS yyear, MONTH(post_date) AS mmonth FROM $wpdb->posts WHERE post_type = 'attachment' ORDER BY post_date DESC";
    2850 
    2851         $arc_result = $wpdb->get_results( $arc_query );
    2852 
    2853         $month_count    = count( $arc_result );
    2854         $selected_month = isset( $_GET['m'] ) ? $_GET['m'] : 0;
    2855 
    2856         if ( $month_count && ! ( 1 == $month_count && 0 == $arc_result[0]->mmonth ) ) {
     2848        $months = $wpdb->get_results(
     2849            "SELECT DISTINCT YEAR( post_date ) AS year, MONTH( post_date ) AS month
     2850            FROM $wpdb->posts
     2851            WHERE post_type = 'attachment'
     2852            ORDER BY post_date DESC"
     2853        );
     2854
     2855        $month_count    = count( $months );
     2856        $selected_month = isset( $_GET['m'] ) ? (int) $_GET['m'] : 0;
     2857
     2858        if ( $month_count && ( 1 !== $month_count || 0 !== (int) $months[0]->month ) ) {
    28572859            ?>
    28582860            <select name='m'>
    2859             <option<?php selected( $selected_month, 0 ); ?> value='0'><?php _e( 'All dates' ); ?></option>
     2861                <option<?php selected( $selected_month, 0 ); ?> value='0'><?php _e( 'All dates' ); ?></option>
    28602862            <?php
    2861 
    2862             foreach ( $arc_result as $arc_row ) {
    2863                 if ( 0 == $arc_row->yyear ) {
     2863            foreach ( $months as $arc_row ) {
     2864                if ( 0 === (int) $arc_row->year ) {
    28642865                    continue;
    28652866                }
    28662867
    2867                 $arc_row->mmonth = zeroise( $arc_row->mmonth, 2 );
    2868 
    2869                 if ( $arc_row->yyear . $arc_row->mmonth == $selected_month ) {
    2870                     $default = ' selected="selected"';
    2871                 } else {
    2872                     $default = '';
    2873                 }
    2874 
    2875                 echo "<option$default value='" . esc_attr( $arc_row->yyear . $arc_row->mmonth ) . "'>";
    2876                 echo esc_html( $wp_locale->get_month( $arc_row->mmonth ) . " $arc_row->yyear" );
    2877                 echo "</option>\n";
    2878             }
    2879 
     2868                $month = zeroise( $arc_row->month, 2 );
     2869                $year  = $arc_row->year;
     2870
     2871                printf(
     2872                    "<option %s value='%s'>%s</option>\n",
     2873                    selected( $selected_month, $year . $month, false ),
     2874                    esc_attr( $year . $month ),
     2875                    /* translators: 1: Month name, 2: 4-digit year. */
     2876                    esc_html( sprintf( __( '%1$s %2$d' ), $wp_locale->get_month( $month ), $year ) )
     2877                );
     2878            }
    28802879            ?>
    28812880            </select>
Note: See TracChangeset for help on using the changeset viewer.