wp_dashboard_quick_press( string|false $error_msg = false )
- Since
- 3.8.0
- Source
wp-admin/includes/dashboard.php:542
Compatibility
- WordPress
- since 3.8.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
$error_msgstring|falseoptional- Error message. Default false.Default:
false
Performance profile
How much work a call to wp_dashboard_quick_press() 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
- 7–93
- Plugin surface
- 1 hook
- Called by
- 1
Reaches the database via get_post().
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 121.
Third-party callbacks on 'enter_title_here' 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
- querycontent query
get_post()called directly - hookthird-party callbacks
apply_filters()called directly - optionoption read or write
get_option()one call below wp_dashboard_quick_press()
Further down the call graph this can also reach 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 · 9 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost wp_dashboard_quick_press() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
!current_user_can() | 7 | current_user_can() |
current_user_can() && !empty($post) | 75 | current_user_can(), get_user_option(), get_post(), admin_url(), esc_url(), __(), apply_filters(), _e(), esc_attr_e(), wp_nonce_field(), __(), submit_button(), wp_dashboard_recent_drafts() |
current_user_can() && !empty($post) | 79 | current_user_can(), get_user_option(), get_post(), admin_url(), esc_url(), wp_admin_notice(), __(), apply_filters(), _e(), esc_attr_e(), wp_nonce_field(), __(), submit_button(), wp_dashboard_recent_drafts() |
current_user_can() | 82 | current_user_can(), get_user_option(), get_default_post_to_edit(), get_current_user_id(), get_current_blog_id(), get_blogs_of_user(), array_keys(), admin_url(), esc_url(), __(), apply_filters(), _e(), esc_attr_e(), wp_nonce_field(), __(), submit_button(), wp_dashboard_recent_drafts() |
current_user_can() | 84–87 | current_user_can(), get_user_option(), get_post(), get_default_post_to_edit(), get_current_user_id(), update_user_option(), admin_url(), esc_url(), __(), apply_filters(), _e(), esc_attr_e(), wp_nonce_field(), __(), submit_button(), wp_dashboard_recent_drafts() |
current_user_can() | 86 | current_user_can(), get_user_option(), get_default_post_to_edit(), get_current_user_id(), get_current_blog_id(), get_blogs_of_user(), array_keys(), admin_url(), esc_url(), wp_admin_notice(), __(), apply_filters(), _e(), esc_attr_e(), wp_nonce_field(), __(), submit_button(), wp_dashboard_recent_drafts() |
current_user_can() | 88–91 | current_user_can(), get_user_option(), get_post(), get_default_post_to_edit(), get_current_user_id(), update_user_option(), admin_url(), esc_url(), wp_admin_notice(), __(), apply_filters(), _e(), esc_attr_e(), wp_nonce_field(), __(), submit_button(), wp_dashboard_recent_drafts() |
current_user_can() | 89 | current_user_can(), get_user_option(), get_default_post_to_edit(), get_current_user_id(), get_current_blog_id(), get_blogs_of_user(), array_keys(), update_user_option(), admin_url(), esc_url(), __(), apply_filters(), _e(), esc_attr_e(), wp_nonce_field(), __(), submit_button(), wp_dashboard_recent_drafts() |
current_user_can() | 93 | current_user_can(), get_user_option(), get_default_post_to_edit(), get_current_user_id(), get_current_blog_id(), get_blogs_of_user(), array_keys(), update_user_option(), admin_url(), esc_url(), wp_admin_notice(), __(), apply_filters(), _e(), esc_attr_e(), wp_nonce_field(), __(), submit_button(), wp_dashboard_recent_drafts() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 121 | 7–93 | 6 | |
| 8.5 | 121 | 7–93 | 6 | |
| 8.4 | 121 | 7–93 | 6 | 3 fewer instructions than PHP 8.3 |
| 8.3 | 124 | 7–96 | 6 | |
| 8.2 | 124 | 7–96 | 6 | |
| 8.1 | 124 | 7–96 | 6 | |
| 7.4 | 124 | 7–96 | 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 · 1
One hook fires while wp_dashboard_quick_press() runs, in this order:
- apply_filters( enter_title_here )filterline 591 (+49 into the body)
Filters the title field placeholder text.
Uses · 18
- current_user_can()Returns whether the current user has the specified capability.
- get_user_option()Retrieves user option that can be either per Site or per Network.
- get_post()Retrieves post data given a post ID or post object.
- get_default_post_to_edit()Returns default post information to use when populating the "Write Post" form.
- update_user_option()Updates user option with global blog capability.
- get_current_user_id()Gets the current user's ID.
- get_current_blog_id()Retrieves the current site ID.
- get_blogs_of_user()Gets the sites a user belongs to.
- esc_url()Checks and cleans a URL.
- admin_url()Retrieves the URL to the admin area for the current site.
- wp_admin_notice()Outputs an admin notice.
- apply_filters()Calls the callback functions that have been added to a filter hook.
Show all 18
- __()Retrieves the translation of $text.
- _e()Displays translated text.
- esc_attr_e()Displays translated text that has been escaped for safe use in an attribute.
- wp_nonce_field()Retrieves or display nonce hidden field for forms.
- submit_button()Echoes a submit button, with provided text and appropriate class(es).
- wp_dashboard_recent_drafts()Show recent drafts of the user on the dashboard.
Used by · 1
- wp_dashboard_quick_press_output()Output the QuickPress dashboard widget.
Source code
function wp_dashboard_quick_press( $error_msg = false ) { global $post_ID; if ( ! current_user_can( 'edit_posts' ) ) { return; } // Check if a new auto-draft (= no new post_ID) is needed or if the old can be used. $last_post_id = (int) get_user_option( 'dashboard_quick_press_last_post_id' ); // Get the last post_ID. if ( $last_post_id ) { $post = get_post( $last_post_id ); if ( empty( $post ) || 'auto-draft' !== $post->post_status ) { // auto-draft doesn't exist anymore. $post = get_default_post_to_edit( 'post', true ); update_user_option( get_current_user_id(), 'dashboard_quick_press_last_post_id', (int) $post->ID ); // Save post_ID. } else { $post->post_title = ''; // Remove the auto draft title. } } else { $post = get_default_post_to_edit( 'post', true ); $user_id = get_current_user_id(); // Don't create an option if this is a super admin who does not belong to this site. if ( in_array( get_current_blog_id(), array_keys( get_blogs_of_user( $user_id ) ), true ) ) { update_user_option( $user_id, 'dashboard_quick_press_last_post_id', (int) $post->ID ); // Save post_ID. } } $post_ID = (int) $post->ID; ?> <form name="post" action="<?php echo esc_url( admin_url( 'post.php' ) ); ?>" method="post" id="quick-press" class="initial-form hide-if-no-js"> <?php if ( $error_msg ) { wp_admin_notice( $error_msg, array( 'additional_classes' => array( 'error' ), ) ); } ?> <div class="input-text-wrap" id="title-wrap"> <label for="title"> <?php /** This filter is documented in wp-admin/edit-form-advanced.php */ echo apply_filters( 'enter_title_here', __( 'Title' ), $post ); ?> </label> <input type="text" name="post_title" id="title" autocomplete="off" /> </div> <div class="textarea-wrap" id="description-wrap"> <label for="content"><?php _e( 'Content' ); ?></label> <textarea name="content" id="content" placeholder="<?php esc_attr_e( 'What’s on your mind?' ); ?>" class="mceEditor" rows="3" cols="15" autocomplete="off"></textarea> </div> <p class="submit"> <input type="hidden" name="action" id="quickpost-action" value="post-quickdraft-save" /> <input type="hidden" name="post_ID" value="<?php echo $post_ID; ?>" /> <input type="hidden" name="post_type" value="post" /> <?php wp_nonce_field( 'add-post' ); ?> <?php submit_button( __( 'Save Draft' ), 'primary', 'save', false, array( 'id' => 'save-post' ) ); ?> <br class="clear" /> </p> </form> <?php wp_dashboard_recent_drafts();}Changelog
Introduced in 3.8.0. 3 changes between 6.7.7 and 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
$message added.verified against source$notice_type added.verified against source$error_msg removed.verified against sourceAbout this page
- Parsed data
- Generated from the wordpress-develop 6.8.8 tag, from
src/wp-admin/includes/dashboard.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.