Skip to content

Commit d5c9ae5

Browse files
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. git-svn-id: https://develop.svn.wordpress.org/trunk@59767 602fd350-edb4-49c9-b593-d223f7449a82
1 parent c22e267 commit d5c9ae5

File tree

2 files changed

+23
-24
lines changed

2 files changed

+23
-24
lines changed

src/wp-admin/includes/class-wp-list-table.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -780,9 +780,9 @@ protected function months_dropdown( $post_type ) {
780780
printf(
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
}
788788
?>

src/wp-admin/includes/media.php

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2845,38 +2845,37 @@ function media_upload_library_form( $errors ) {
28452845

28462846
<div class="alignleft actions">
28472847
<?php
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+
);
28482854

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+
$month_count = count( $months );
2856+
$selected_month = isset( $_GET['m'] ) ? (int) $_GET['m'] : 0;
28552857

2856-
if ( $month_count && ! ( 1 == $month_count && 0 == $arc_result[0]->mmonth ) ) {
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+
$month = zeroise( $arc_row->month, 2 );
2869+
$year = $arc_row->year;
28682870

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";
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+
);
28782878
}
2879-
28802879
?>
28812880
</select>
28822881
<?php } ?>

0 commit comments

Comments
 (0)