wp_admin_css( string $file = 'wp-admin', bool $force_echo = false )
- Since
- 2.3.0
- Source
wp-includes/general-template.php:5282
Description
"Intelligently" decides to enqueue or to print the CSS file. If the 'wp_print_styles' action has not yet been called, the CSS file will be enqueued. If the 'wp_print_styles' action has been called, the CSS link will be printed. Printing may be forced by passing true as the $force_echo (second) parameter.
For backward compatibility with WordPress 2.3 calling method: If the $file (first) parameter does not correspond to a registered CSS file, we assume $file is a file relative to wp-admin/ without its ".css" extension. A stylesheet link to that generated URL is printed.
Compatibility
- WordPress
- since 2.3.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
$filestringoptional- Style handle name or file name (without ".css" extension) relative to wp-admin/. Defaults to 'wp-admin'.Default:
'wp-admin' $force_echobooloptional- Force the stylesheet link to be printed rather than enqueued.Default:
false
Performance profile
How much work a call to wp_admin_css() 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
- Constant
- Instructions
- 17–53
- Plugin surface
- 1 hook
- Called by
- 2
Reaches the database via ->query().
No loop in the body: the same number of instructions runs whatever you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 67.
Third-party callbacks on 'wp_admin_css' run inside this call, and their cost is not bounded by anything here.
2 places 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 - sqldatabase query
->query()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 · 6 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost wp_admin_css() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
->query() | 17–18 | wp_styles(), ->query(), wp_print_styles() |
->query() && !did_action() | 21–22 | wp_styles(), ->query(), did_action(), wp_enqueue_style() |
->query() && did_action() | 21–22 | wp_styles(), ->query(), did_action(), wp_print_styles() |
!->query() && !function_exists() | 32–33 | wp_styles(), ->query(), wp_admin_css_uri(), esc_url(), apply_filters(), function_exists() |
!->query() && function_exists() && !is_rtl() | 35–36 | wp_styles(), ->query(), wp_admin_css_uri(), esc_url(), apply_filters(), function_exists(), is_rtl() |
!->query() && function_exists() && is_rtl() | 52–53 | wp_styles(), ->query(), wp_admin_css_uri(), esc_url(), apply_filters(), function_exists(), is_rtl(), wp_admin_css_uri(), esc_url(), apply_filters() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 67 | 17–53 | 6 | |
| 8.5 | 67 | 17–53 | 6 | |
| 8.4 | 67 | 17–53 | 6 | 11 fewer instructions than PHP 8.3 |
| 8.3 | 78 | 20–64 | 6 | |
| 8.2 | 78 | 20–64 | 6 | |
| 8.1 | 78 | 20–64 | 6 | |
| 7.4 | 78 | 20–64 | 6 |
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 · 2
2 hooks fire while wp_admin_css() runs, in this order:
- apply_filters( wp_admin_css )filterline 5313 (+31 into the body)
Filters the stylesheet link to the specified CSS file.
- apply_filters( wp_admin_css )filterline 5322 (+40 into the body)
Filters the stylesheet link to the specified CSS file.
Uses · 10
- str_starts_with()Polyfill for `str_starts_with()` function added in PHP 8.0.
- wp_styles()Initializes $wp_styles if it has not been set.
- did_action()Retrieves the number of times an action has been fired during the current request.
- wp_print_styles()Displays styles that are in the $handles queue.
- wp_enqueue_style()Enqueues a CSS stylesheet.
- esc_url()Checks and cleans a URL.
- wp_admin_css_uri()Displays the URL of a WordPress admin CSS file.
- apply_filters()Calls the callback functions that have been added to a filter hook.
- is_rtl()Determines whether the current locale is right-to-left (RTL).
- wp_styles()::query()
Used by · 2
- display_header()Display installation header.
- setup_config_display_header()Display setup wp-config.php file header.
Source code
function wp_admin_css( $file = 'wp-admin', $force_echo = false ) { // For backward compatibility. $handle = str_starts_with( $file, 'css/' ) ? substr( $file, 4 ) : $file; if ( wp_styles()->query( $handle ) ) { if ( $force_echo || did_action( 'wp_print_styles' ) ) { // We already printed the style queue. Print this one immediately. wp_print_styles( $handle ); } else { // Add to style queue. wp_enqueue_style( $handle ); } return; } $stylesheet_link = sprintf( "<link rel='stylesheet' href='%s' />\n", esc_url( wp_admin_css_uri( $file ) ) ); /** * Filters the stylesheet link to the specified CSS file. * * If the site is set to display right-to-left, the RTL stylesheet link * will be used instead. * * @since 2.3.0 * @param string $stylesheet_link HTML link element for the stylesheet. * @param string $file Style handle name or filename (without ".css" extension) * relative to wp-admin/. Defaults to 'wp-admin'. */ echo apply_filters( 'wp_admin_css', $stylesheet_link, $file ); if ( function_exists( 'is_rtl' ) && is_rtl() ) { $rtl_stylesheet_link = sprintf( "<link rel='stylesheet' href='%s' />\n", esc_url( wp_admin_css_uri( "$file-rtl" ) ) ); /** This filter is documented in wp-includes/general-template.php */ echo apply_filters( 'wp_admin_css', $rtl_stylesheet_link, "$file-rtl" ); }}Changelog
Introduced in 2.3.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-includes/general-template.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.