Displays a monthly timestamp dropdown for filtering.
Description
See also
Parameters
- $timestamp_property
-
(string) (Required) The timestamp property.
Source
File: src/db-objects/submissions/submissions-list-table.php
protected function timestamp_months_dropdown( $timestamp_property ) { global $wp_locale; $where = ''; $where_args = array(); if ( ! empty( $_GET['form_id'] ) ) { $where .= ' AND form_id = %d'; $where_args[] = (int) $_GET['form_id']; } if ( method_exists( $this->manager, 'get_author_property' ) ) { $author_property = $this->manager->get_author_property(); $capabilities = $this->manager->capabilities(); if ( ! $capabilities || ! $capabilities->current_user_can( 'edit_others_items' ) ) { $where .= " AND $author_property = %d"; $where_args[] = get_current_user_id(); } } if ( method_exists( $this->manager, 'get_status_property' ) ) { $status_property = $this->manager->get_status_property(); $internal_statuses = array_keys( $this->manager->statuses()->query( array( 'internal' => true ) ) ); if ( ! empty( $internal_statuses ) ) { $where .= " AND $status_property NOT IN (" . implode( ',', array_fill( 0, count( $internal_statuses ), '%s' ) ) . ')'; $where_args = array_merge( $where_args, $internal_statuses ); } } $table_name = $this->manager->get_table_name(); $months = $this->manager->db()->get_results( "SELECT DISTINCT YEAR( FROM_UNIXTIME( $timestamp_property ) ) AS year, MONTH( FROM_UNIXTIME( $timestamp_property ) ) AS month FROM %{$table_name}% WHERE 1=1 $where ORDER BY $timestamp_property DESC", $where_args ); $month_count = count( $months ); if ( ! $month_count || ( 1 === $month_count && 0 === (int) $months[0]->month ) ) { return; } $m = isset( $_REQUEST['m'] ) ? (int) $_REQUEST['m'] : 0; echo '<label for="filter-by-date" class="screen-reader-text">' . $this->manager->get_message( 'list_table_filter_by_date_label' ) . '</label>'; echo '<select id="filter-by-date" name="m">'; echo '<option value="0"' . selected( $m, 0, false ) . '>' . $this->manager->get_message( 'list_table_all_dates' ) . '</option>'; foreach ( $months as $row ) { if ( 0 === (int) $row->year ) { continue; } $month = zeroise( $row->month, 2 ); $year = $row->year; printf( '<option value="%1$s" %2$s>%3$s</option>', esc_attr( $year . $month ), selected( $m, $year . $month, false ), sprintf( $this->manager->get_message( 'list_table_month_year' ), $wp_locale->get_month( $month ), $year ) ); } echo '</select>'; }
Changelog
Version | Description |
---|---|
1.0.0 | Introduced. |