wp_get_admin_notice( string $message, array $args = array() ): string
- Since
- 6.4.0
- Source
wp-includes/functions.php:9196
Compatibility
- WordPress
- since 6.4.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
$messagestring- The message.
$argsarrayoptional- An array of arguments for the admin notice. Default empty array.Default:
array()$typestringdefault: empty stringOptional. The type of admin notice. For example, 'error', 'success', 'warning', 'info'.$dismissiblebooldefault: falseOptional. Whether the admin notice is dismissible.$idstringdefault: empty stringOptional. The value of the admin notice's ID attribute.$additional_classesstring[]default: empty arrayOptional. A string array of class names.$attributesstring[]default: empty arrayOptional. Additional attributes for the notice div.$paragraph_wrapbooldefault: trueOptional. Whether to wrap the message in paragraph tags.
Return value
string- The markup for an admin notice.
Performance profile
How much work a call to wp_get_admin_notice() 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
- Light
- Scaling
- Scales with input
- Instructions
- 50–95
- Plugin surface
- 2 hooks
- Called by
- 7
Touches nothing outside its own arguments.
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 124.
Third-party callbacks on 'wp_admin_notice_args', 'wp_admin_notice_markup' run inside this call, and their cost is not bounded by anything here.
7 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
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 · 2 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost wp_get_admin_notice() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
| always | 50–83 | wp_parse_args(), apply_filters(), sprintf(), apply_filters() |
$type | 68–95 | wp_parse_args(), apply_filters(), __(), sprintf(), _doing_it_wrong(), sprintf(), apply_filters() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 124 | 50–95 | 17 | |
| 8.5 | 124 | 50–95 | 17 | |
| 8.4 | 124 | 50–95 | 17 | 16 fewer instructions than PHP 8.3 |
| 8.3 | 140 | 50–107 | 17 | |
| 8.2 | 140 | 50–107 | 17 | |
| 8.1 | 140 | 50–107 | 17 | 1 fewer instruction than PHP 7.4 |
| 7.4 | 141 | 50–107 | 17 |
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_get_admin_notice() runs, in this order:
- apply_filters( wp_admin_notice_args )filterline 9216 (+20 into the body)
Filters the arguments for an admin notice.
- apply_filters( wp_admin_notice_markup )filterline 9285 (+89 into the body)
Filters the markup for an admin notice.
Uses · 6
- wp_parse_args()Merges user defined arguments into defaults array.
- apply_filters()Calls the callback functions that have been added to a filter hook.
- str_contains()Polyfill for `str_contains()` function added in PHP 8.0.
- _doing_it_wrong()Marks something as being incorrectly called.
- __()Retrieves the translation of $text.
- esc_attr()Escaping for HTML attributes.
Used by · 7
- WP_Plugins_List_Table::add_dependencies_to_dependent_plugin_row()Prints a list of other plugins that the plugin depends on.
- WP_Privacy_Policy_Content::privacy_policy_guide()Outputs the privacy policy guide together with content from the theme and plugins.
- wp_admin_notice()Outputs an admin notice.
- wp_dashboard_cached_rss_widget()Checks to see if all of the feed url in $check_urls are cached.
- wp_get_nav_menu_to_edit()Returns the menu formatted to edit.
- wp_nav_menu_update_menu_items()Saves nav menu items.
- wp_theme_auto_update_setting_template()Returns the JavaScript template used to display the auto-update setting for a theme.
Source code
function wp_get_admin_notice( $message, $args = array() ) { $defaults = array( 'type' => '', 'dismissible' => false, 'id' => '', 'additional_classes' => array(), 'attributes' => array(), 'paragraph_wrap' => true, ); $args = wp_parse_args( $args, $defaults ); /** * Filters the arguments for an admin notice. * * @since 6.4.0 * * @param array $args The arguments for the admin notice. * @param string $message The message for the admin notice. */ $args = apply_filters( 'wp_admin_notice_args', $args, $message ); $id = ''; $classes = 'notice'; $attributes = ''; if ( is_string( $args['id'] ) ) { $trimmed_id = trim( $args['id'] ); if ( '' !== $trimmed_id ) { $id = 'id="' . $trimmed_id . '" '; } } if ( is_string( $args['type'] ) ) { $type = trim( $args['type'] ); if ( str_contains( $type, ' ' ) ) { _doing_it_wrong( __FUNCTION__, sprintf( /* translators: %s: The "type" key. */ __( 'The %s key must be a string without spaces.' ), '<code>type</code>' ), '6.4.0' ); } if ( '' !== $type ) { $classes .= ' notice-' . $type; } } if ( true === $args['dismissible'] ) { $classes .= ' is-dismissible'; } if ( is_array( $args['additional_classes'] ) && ! empty( $args['additional_classes'] ) ) { $classes .= ' ' . implode( ' ', $args['additional_classes'] ); } if ( is_array( $args['attributes'] ) && ! empty( $args['attributes'] ) ) { $attributes = ''; foreach ( $args['attributes'] as $attr => $val ) { if ( is_bool( $val ) ) { $attributes .= $val ? ' ' . $attr : ''; } elseif ( is_int( $attr ) ) { $attributes .= ' ' . esc_attr( trim( $val ) ); } elseif ( $val ) { $attributes .= ' ' . $attr . '="' . esc_attr( trim( $val ) ) . '"'; } } } if ( false !== $args['paragraph_wrap'] ) { $message = "<p>$message</p>"; } $markup = sprintf( '<div %1$sclass="%2$s"%3$s>%4$s</div>', $id, $classes, $attributes, $message );Changelog
Introduced in 6.4.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/functions.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.