WP_List_Table::months_dropdown( string $post_type )
- Since
- 3.1.0
- Source
wp-admin/includes/class-wp-list-table.php:712
Compatibility
- WordPress
- since 3.1.0
- PHP
- 7.4–8.6-dev
- 6.7.7
- 6.8.8
- 6.9.7
- 7.0.4
- 7.1.0
Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.
Parameters
$post_typestring- The post type.
Performance profile
How much work a call to WP_List_Table::months_dropdown() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.
- Cost class
- Heavy
- Scaling
- Scales with input
- Instructions
- 10–95
- Plugin surface
- 3 hooks
- Called by
- 0
Reaches the database via ->get_results().
The body loops, so the work grows with what you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 144.
Third-party callbacks on 'disable_months_dropdown', 'pre_months_dropdown_query', 'months_dropdown_results' run inside this call, and their cost is not bounded by anything here.
Nothing in core calls this; the cost is only what you spend yourself.
What it touches
- hookthird-party callbacks
apply_filters()called directly - sqldatabase query
->get_results()called directly
Further down the call graph this can also reach option, cache, serialize, query and transient. Those are the worst case, several calls deep and usually down an error path, not what a normal call pays.
What one call costs · 7 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost WP_List_Table::months_dropdown() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
apply_filters() | 10 | apply_filters() |
!apply_filters() && is_array($months) | 26–33 | apply_filters(), apply_filters(), apply_filters() |
!apply_filters() && !is_array($months) | 46–58 | apply_filters(), apply_filters(), ->prepare(), ->get_results(), apply_filters() |
!apply_filters() && is_array($months) && $months | 53–62 | apply_filters(), apply_filters(), apply_filters(), get_post_type_object(), selected(), _e() |
!apply_filters() && !is_array($months) && isset($value) | 59–66 | apply_filters(), apply_filters(), ->prepare(), ->prepare(), ->get_results(), apply_filters() |
!apply_filters() && !is_array($months) && $months | 73–87 | apply_filters(), apply_filters(), ->prepare(), ->get_results(), apply_filters(), get_post_type_object(), selected(), _e() |
!apply_filters() && !is_array($months) && isset($value) && $months | 86–95 | apply_filters(), apply_filters(), ->prepare(), ->prepare(), ->get_results(), apply_filters(), get_post_type_object(), selected(), _e() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 146 | 10–95 | 12 | 2 more instructions than PHP 8.5 |
| 8.5 | 144 | 10–95 | 12 | |
| 8.4 | 144 | 10–95 | 12 | |
| 8.3 | 144 | 10–95 | 12 | |
| 8.2 | 144 | 10–95 | 12 | |
| 8.1 | 144 | 10–95 | 12 | 1 fewer instruction than PHP 7.4 |
| 7.4 | 145 | 10–96 | 12 |
An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.
Hooks and filters fired · 3
3 hooks fire while WP_List_Table::months_dropdown() runs, in this order:
- apply_filters( disable_months_dropdown )filterline 723 (+11 into the body)
Filters whether to remove the 'Months' drop-down from the post list table.
- apply_filters( pre_months_dropdown_query )filterline 735 (+23 into the body)
Filters whether to short-circuit performing the months dropdown query.
- apply_filters( months_dropdown_results )filterline 765 (+53 into the body)
Filters the 'Months' drop-down results.
Uses · 8
- apply_filters()Calls the callback functions that have been added to a filter hook.
- get_post_type_object()Retrieves a post type object by name.
- selected()Outputs the HTML selected attribute.
- _e()Displays translated text.
- zeroise()Add leading zeros when necessary.
- esc_attr()Escaping for HTML attributes.
- esc_html()Escaping for HTML blocks.
- __()Retrieves the translation of $text.
Source code
protected function months_dropdown( $post_type ) { global $wpdb, $wp_locale; /** * Filters whether to remove the 'Months' drop-down from the post list table. * * @since 4.2.0 * * @param bool $disable Whether to disable the drop-down. Default false. * @param string $post_type The post type. */ if ( apply_filters( 'disable_months_dropdown', false, $post_type ) ) { return; } /** * Filters whether to short-circuit performing the months dropdown query. * * @since 5.7.0 * * @param object[]|false $months 'Months' drop-down results. Default false. * @param string $post_type The post type. */ $months = apply_filters( 'pre_months_dropdown_query', false, $post_type ); if ( ! is_array( $months ) ) { $extra_checks = "AND post_status != 'auto-draft'"; if ( ! isset( $_GET['post_status'] ) || 'trash' !== $_GET['post_status'] ) { $extra_checks .= " AND post_status != 'trash'"; } elseif ( isset( $_GET['post_status'] ) ) { $extra_checks = $wpdb->prepare( ' AND post_status = %s', $_GET['post_status'] ); } $months = $wpdb->get_results( $wpdb->prepare( "SELECT DISTINCT YEAR( post_date ) AS year, MONTH( post_date ) AS month FROM $wpdb->posts WHERE post_type = %s $extra_checks ORDER BY post_date DESC", $post_type ) ); } /** * Filters the 'Months' drop-down results. * * @since 3.7.0 * * @param object[] $months Array of the months drop-down query results. * @param string $post_type The post type. */ $months = apply_filters( 'months_dropdown_results', $months, $post_type ); $month_count = count( $months ); if ( ! $month_count || ( 1 === $month_count && 0 === (int) $months[0]->month ) ) { return; } $selected_month = isset( $_GET['m'] ) ? (int) $_GET['m'] : 0; ?> <label for="filter-by-date" class="screen-reader-text"><?php echo get_post_type_object( $post_type )->labels->filter_by_date; ?></label> <select name="m" id="filter-by-date"> <option<?php selected( $selected_month, 0 ); ?> value="0"><?php _e( 'All dates' ); ?></option> <?php foreach ( $months as $arc_row ) { if ( 0 === (int) $arc_row->year ) { continue; } $month = zeroise( $arc_row->month, 2 ); $year = $arc_row->year; printf( "<option %s value='%s'>%s</option>\n", selected( $selected_month, $year . $month, false ), esc_attr( $year . $month ), /* translators: 1: Month name, 2: 4-digit year. */Changelog
Introduced in 3.1.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 7.1.0 tag, from
src/wp-admin/includes/class-wp-list-table.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it. - Corrections
- Something wrong on this page? Report it and it gets fixed in the next regeneration.