WP_Posts_List_Table::formats_dropdown( string $post_type )
- Since
- 5.2.0
- Source
wp-admin/includes/class-wp-posts-list-table.php:502
Compatibility
- WordPress
- since 5.2.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- Post type slug.
Performance profile
How much work a call to WP_Posts_List_Table::formats_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
- 8–43
- Plugin surface
- 1 hook
- Called by
- 1
Reaches the database via get_terms().
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 73.
Third-party callbacks on 'disable_formats_dropdown' run inside this call, and their cost is not bounded by anything here.
1 place in core call this, so the cost is paid more often than your own code shows.
What it touches
- hookthird-party callbacks
apply_filters()called directly - querycontent query
get_terms()called directly
Further down the call graph this can also reach option, cache, serialize 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 · 4 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost WP_Posts_List_Table::formats_dropdown() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
apply_filters() | 8 | apply_filters() |
!apply_filters() | 13–15 | apply_filters(), is_object_in_taxonomy() |
!apply_filters() && is_object_in_taxonomy() | 20 | apply_filters(), is_object_in_taxonomy(), get_terms() |
!apply_filters() && is_object_in_taxonomy() | 41–43 | apply_filters(), is_object_in_taxonomy(), get_terms(), _e(), selected(), _e() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 73 | 8–43 | 8 | |
| 8.5 | 73 | 8–43 | 8 | |
| 8.4 | 73 | 8–43 | 8 | 3 fewer instructions than PHP 8.3 |
| 8.3 | 76 | 8–43 | 8 | |
| 8.2 | 76 | 8–43 | 8 | |
| 8.1 | 76 | 8–43 | 8 | |
| 7.4 | 76 | 8–43 | 8 |
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 · 1
One hook fires while WP_Posts_List_Table::formats_dropdown() runs, in this order:
- apply_filters( disable_formats_dropdown )filterline 512 (+10 into the body)
Filters whether to remove the 'Formats' drop-down from the post list table.
Uses · 8
- apply_filters()Calls the callback functions that have been added to a filter hook.
- is_object_in_taxonomy()Determines if the given object type is associated with the given taxonomy.
- get_terms()Retrieves the terms in a given taxonomy or list of taxonomies.
- _e()Displays translated text.
- selected()Outputs the HTML selected attribute.
- get_post_format_string()Returns a pretty, translated version of a post format slug
- esc_attr()Escaping for HTML attributes.
- esc_html()Escaping for HTML blocks.
Used by · 1
Source code
protected function formats_dropdown( $post_type ) { /** * Filters whether to remove the 'Formats' drop-down from the post list table. * * @since 5.2.0 * @since 5.5.0 The `$post_type` parameter was added. * * @param bool $disable Whether to disable the drop-down. Default false. * @param string $post_type Post type slug. */ if ( apply_filters( 'disable_formats_dropdown', false, $post_type ) ) { return; } // Return if the post type doesn't have post formats or if we're in the Trash. if ( ! is_object_in_taxonomy( $post_type, 'post_format' ) || $this->is_trash ) { return; } // Make sure the dropdown shows only formats with a post count greater than 0. $used_post_formats = get_terms( array( 'taxonomy' => 'post_format', 'hide_empty' => true, ) ); // Return if there are no posts using formats. if ( ! $used_post_formats ) { return; } $displayed_post_format = $_GET['post_format'] ?? ''; ?> <label for="filter-by-format" class="screen-reader-text"> <?php /* translators: Hidden accessibility text. */ _e( 'Filter by post format' ); ?> </label> <select name="post_format" id="filter-by-format"> <option<?php selected( $displayed_post_format, '' ); ?> value=""><?php _e( 'All formats' ); ?></option> <?php foreach ( $used_post_formats as $used_post_format ) { // Post format slug. $slug = str_replace( 'post-format-', '', $used_post_format->slug ); // Pretty, translated version of the post format slug. $pretty_name = get_post_format_string( $slug ); // Skip the standard post format. if ( 'standard' === $slug ) { continue; } ?> <option<?php selected( $displayed_post_format, $slug ); ?> value="<?php echo esc_attr( $slug ); ?>"><?php echo esc_html( $pretty_name ); ?></option> <?php } ?> </select> <?php }Changelog
Introduced in 5.2.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-posts-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.