get_default_post_to_edit( string $post_type = 'post', bool $create_in_db = false ): WP_Post
- Since
- 2.0.0
- Source
wp-admin/includes/post.php:742
Compatibility
- WordPress
- since 2.0.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_typestringoptional- A post type string. Default 'post'.Default:
'post' $create_in_dbbooloptional- Whether to insert the post into database. Default false.Default:
false
Return value
WP_Post- Post object containing all the default post data as attributes
Performance profile
How much work a call to get_default_post_to_edit() 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
- 69–125
- Plugin surface
- 3 hooks
- Called by
- 5
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 179.
Third-party callbacks on 'default_content', 'default_title', 'default_excerpt' run inside this call, and their cost is not bounded by anything here.
5 places 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 - optionoption read or write
get_option()called directly - hookthird-party callbacks
apply_filters()called directly - cacheobject cache
wp_cache_get()one call below get_default_post_to_edit() - serializeserialisation
maybe_unserialize()one call below get_default_post_to_edit()
Further down the call graph this can also reach transient. That is the worst case, several calls deep and usually down an error path, not what a normal call pays.
What one call costs · 36 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost get_default_post_to_edit() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
empty($value) && !current_theme_supports() && wp_next_scheduled() | 69 | __(), post_title(), get_post(), current_theme_supports(), wp_after_insert_post(), wp_next_scheduled(), apply_filters(), apply_filters(), apply_filters() |
empty($value) && current_theme_supports() && !post_type_supports() && wp_next_scheduled() | 76 | __(), post_title(), get_post(), current_theme_supports(), post_type_supports(), wp_after_insert_post(), wp_next_scheduled(), apply_filters(), apply_filters(), apply_filters() |
empty($value) && !current_theme_supports() && !wp_next_scheduled() | 77 | __(), post_title(), get_post(), current_theme_supports(), wp_after_insert_post(), wp_next_scheduled(), time(), wp_schedule_event(), apply_filters(), apply_filters(), apply_filters() |
!current_theme_supports() && wp_next_scheduled() | 79 | wp_unslash(), esc_html(), __(), post_title(), get_post(), current_theme_supports(), wp_after_insert_post(), wp_next_scheduled(), apply_filters(), apply_filters(), apply_filters() |
empty($value) && current_theme_supports() && post_type_supports() && !get_option() && wp_next_scheduled() | 80 | __(), post_title(), get_post(), current_theme_supports(), post_type_supports(), get_option(), wp_after_insert_post(), wp_next_scheduled(), apply_filters(), apply_filters(), apply_filters() |
empty($value) && current_theme_supports() && !post_type_supports() && !wp_next_scheduled() | 84 | __(), post_title(), get_post(), current_theme_supports(), post_type_supports(), wp_after_insert_post(), wp_next_scheduled(), time(), wp_schedule_event(), apply_filters(), apply_filters(), apply_filters() |
current_theme_supports() && !post_type_supports() && wp_next_scheduled() | 86 | wp_unslash(), esc_html(), __(), post_title(), get_post(), current_theme_supports(), post_type_supports(), wp_after_insert_post(), wp_next_scheduled(), apply_filters(), apply_filters(), apply_filters() |
empty($value) && current_theme_supports() && post_type_supports() && get_option() && wp_next_scheduled() | 87 | __(), post_title(), get_post(), current_theme_supports(), post_type_supports(), get_option(), get_option(), set_post_format(), wp_after_insert_post(), wp_next_scheduled(), apply_filters(), apply_filters(), apply_filters() |
!current_theme_supports() && !wp_next_scheduled() | 87 | wp_unslash(), esc_html(), __(), post_title(), get_post(), current_theme_supports(), wp_after_insert_post(), wp_next_scheduled(), time(), wp_schedule_event(), apply_filters(), apply_filters(), apply_filters() |
empty($value) && current_theme_supports() && post_type_supports() && !get_option() && !wp_next_scheduled() | 88 | __(), post_title(), get_post(), current_theme_supports(), post_type_supports(), get_option(), wp_after_insert_post(), wp_next_scheduled(), time(), wp_schedule_event(), apply_filters(), apply_filters(), apply_filters() |
!current_theme_supports() && wp_next_scheduled() | 89 | wp_unslash(), esc_html(), wp_unslash(), esc_html(), __(), post_title(), get_post(), current_theme_supports(), wp_after_insert_post(), wp_next_scheduled(), apply_filters(), apply_filters(), apply_filters() |
current_theme_supports() && post_type_supports() && !get_option() && wp_next_scheduled() | 90 | wp_unslash(), esc_html(), __(), post_title(), get_post(), current_theme_supports(), post_type_supports(), get_option(), wp_after_insert_post(), wp_next_scheduled(), apply_filters(), apply_filters(), apply_filters() |
24 further outcomes, up to 125 instructions
empty($value) | 94 | wp_insert_post(), get_default_comment_status(), get_default_comment_status(), get_option(), get_option(), apply_filters(), apply_filters(), apply_filters() |
current_theme_supports() && !post_type_supports() && !wp_next_scheduled() | 94 | wp_unslash(), esc_html(), __(), post_title(), get_post(), current_theme_supports(), post_type_supports(), wp_after_insert_post(), wp_next_scheduled(), time(), wp_schedule_event(), apply_filters(), apply_filters(), apply_filters() |
empty($value) && current_theme_supports() && post_type_supports() && get_option() && !wp_next_scheduled() | 95 | __(), post_title(), get_post(), current_theme_supports(), post_type_supports(), get_option(), get_option(), set_post_format(), wp_after_insert_post(), wp_next_scheduled(), time(), wp_schedule_event(), apply_filters(), apply_filters(), apply_filters() |
current_theme_supports() && !post_type_supports() && wp_next_scheduled() | 96 | wp_unslash(), esc_html(), wp_unslash(), esc_html(), __(), post_title(), get_post(), current_theme_supports(), post_type_supports(), wp_after_insert_post(), wp_next_scheduled(), apply_filters(), apply_filters(), apply_filters() |
current_theme_supports() && post_type_supports() && get_option() && wp_next_scheduled() | 97 | wp_unslash(), esc_html(), __(), post_title(), get_post(), current_theme_supports(), post_type_supports(), get_option(), get_option(), set_post_format(), wp_after_insert_post(), wp_next_scheduled(), apply_filters(), apply_filters(), apply_filters() |
!current_theme_supports() && !wp_next_scheduled() | 97 | wp_unslash(), esc_html(), wp_unslash(), esc_html(), __(), post_title(), get_post(), current_theme_supports(), wp_after_insert_post(), wp_next_scheduled(), time(), wp_schedule_event(), apply_filters(), apply_filters(), apply_filters() |
current_theme_supports() && post_type_supports() && !get_option() && !wp_next_scheduled() | 98 | wp_unslash(), esc_html(), __(), post_title(), get_post(), current_theme_supports(), post_type_supports(), get_option(), wp_after_insert_post(), wp_next_scheduled(), time(), wp_schedule_event(), apply_filters(), apply_filters(), apply_filters() |
!empty($value) && !current_theme_supports() && wp_next_scheduled() | 99 | wp_unslash(), esc_html(), wp_unslash(), esc_html(), wp_unslash(), esc_html(), __(), post_title(), get_post(), current_theme_supports(), wp_after_insert_post(), wp_next_scheduled(), apply_filters(), apply_filters(), apply_filters() |
current_theme_supports() && post_type_supports() && !get_option() && wp_next_scheduled() | 100 | wp_unslash(), esc_html(), wp_unslash(), esc_html(), __(), post_title(), get_post(), current_theme_supports(), post_type_supports(), get_option(), wp_after_insert_post(), wp_next_scheduled(), apply_filters(), apply_filters(), apply_filters() |
| always | 104 | wp_unslash(), esc_html(), wp_insert_post(), get_default_comment_status(), get_default_comment_status(), get_option(), get_option(), apply_filters(), apply_filters(), apply_filters() |
current_theme_supports() && !post_type_supports() && !wp_next_scheduled() | 104 | wp_unslash(), esc_html(), wp_unslash(), esc_html(), __(), post_title(), get_post(), current_theme_supports(), post_type_supports(), wp_after_insert_post(), wp_next_scheduled(), time(), wp_schedule_event(), apply_filters(), apply_filters(), apply_filters() |
current_theme_supports() && post_type_supports() && get_option() && !wp_next_scheduled() | 105 | wp_unslash(), esc_html(), __(), post_title(), get_post(), current_theme_supports(), post_type_supports(), get_option(), get_option(), set_post_format(), wp_after_insert_post(), wp_next_scheduled(), time(), wp_schedule_event(), apply_filters(), apply_filters(), apply_filters() |
!empty($value) && current_theme_supports() && !post_type_supports() && wp_next_scheduled() | 106 | wp_unslash(), esc_html(), wp_unslash(), esc_html(), wp_unslash(), esc_html(), __(), post_title(), get_post(), current_theme_supports(), post_type_supports(), wp_after_insert_post(), wp_next_scheduled(), apply_filters(), apply_filters(), apply_filters() |
current_theme_supports() && post_type_supports() && get_option() && wp_next_scheduled() | 107 | wp_unslash(), esc_html(), wp_unslash(), esc_html(), __(), post_title(), get_post(), current_theme_supports(), post_type_supports(), get_option(), get_option(), set_post_format(), wp_after_insert_post(), wp_next_scheduled(), apply_filters(), apply_filters(), apply_filters() |
!empty($value) && !current_theme_supports() && !wp_next_scheduled() | 107 | wp_unslash(), esc_html(), wp_unslash(), esc_html(), wp_unslash(), esc_html(), __(), post_title(), get_post(), current_theme_supports(), wp_after_insert_post(), wp_next_scheduled(), time(), wp_schedule_event(), apply_filters(), apply_filters(), apply_filters() |
current_theme_supports() && post_type_supports() && !get_option() && !wp_next_scheduled() | 108 | wp_unslash(), esc_html(), wp_unslash(), esc_html(), __(), post_title(), get_post(), current_theme_supports(), post_type_supports(), get_option(), wp_after_insert_post(), wp_next_scheduled(), time(), wp_schedule_event(), apply_filters(), apply_filters(), apply_filters() |
!empty($value) && current_theme_supports() && post_type_supports() && !get_option() && wp_next_scheduled() | 110 | wp_unslash(), esc_html(), wp_unslash(), esc_html(), wp_unslash(), esc_html(), __(), post_title(), get_post(), current_theme_supports(), post_type_supports(), get_option(), wp_after_insert_post(), wp_next_scheduled(), apply_filters(), apply_filters(), apply_filters() |
| always | 114 | wp_unslash(), esc_html(), wp_unslash(), esc_html(), wp_insert_post(), get_default_comment_status(), get_default_comment_status(), get_option(), get_option(), apply_filters(), apply_filters(), apply_filters() |
!empty($value) && current_theme_supports() && !post_type_supports() && !wp_next_scheduled() | 114 | wp_unslash(), esc_html(), wp_unslash(), esc_html(), wp_unslash(), esc_html(), __(), post_title(), get_post(), current_theme_supports(), post_type_supports(), wp_after_insert_post(), wp_next_scheduled(), time(), wp_schedule_event(), apply_filters(), apply_filters(), apply_filters() |
current_theme_supports() && post_type_supports() && get_option() && !wp_next_scheduled() | 115 | wp_unslash(), esc_html(), wp_unslash(), esc_html(), __(), post_title(), get_post(), current_theme_supports(), post_type_supports(), get_option(), get_option(), set_post_format(), wp_after_insert_post(), wp_next_scheduled(), time(), wp_schedule_event(), apply_filters(), apply_filters(), apply_filters() |
!empty($value) && current_theme_supports() && post_type_supports() && get_option() && wp_next_scheduled() | 117 | wp_unslash(), esc_html(), wp_unslash(), esc_html(), wp_unslash(), esc_html(), __(), post_title(), get_post(), current_theme_supports(), post_type_supports(), get_option(), get_option(), set_post_format(), wp_after_insert_post(), wp_next_scheduled(), apply_filters(), apply_filters(), apply_filters() |
!empty($value) && current_theme_supports() && post_type_supports() && !get_option() && !wp_next_scheduled() | 118 | wp_unslash(), esc_html(), wp_unslash(), esc_html(), wp_unslash(), esc_html(), __(), post_title(), get_post(), current_theme_supports(), post_type_supports(), get_option(), wp_after_insert_post(), wp_next_scheduled(), time(), wp_schedule_event(), apply_filters(), apply_filters(), apply_filters() |
!empty($value) | 124 | wp_unslash(), esc_html(), wp_unslash(), esc_html(), wp_unslash(), esc_html(), wp_insert_post(), get_default_comment_status(), get_default_comment_status(), get_option(), get_option(), apply_filters(), apply_filters(), apply_filters() |
!empty($value) && current_theme_supports() && post_type_supports() && get_option() && !wp_next_scheduled() | 125 | wp_unslash(), esc_html(), wp_unslash(), esc_html(), wp_unslash(), esc_html(), __(), post_title(), get_post(), current_theme_supports(), post_type_supports(), get_option(), get_option(), set_post_format(), wp_after_insert_post(), wp_next_scheduled(), time(), wp_schedule_event(), apply_filters(), apply_filters(), apply_filters() |
Across PHP versions
Compiles the same on PHP 7.4, 8.1, 8.2, 8.3, 8.4, 8.5 and 8.6-dev: 179 instructions, 69–125 executed per call, 8 branches. The work does not change between versions.
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 get_default_post_to_edit() runs, in this order:
- apply_filters( default_content )filterline 808 (+66 into the body)
Filters the default post content initially used in the "Write Post" form.
- apply_filters( default_title )filterline 818 (+76 into the body)
Filters the default post title initially used in the "Write Post" form.
- apply_filters( default_excerpt )filterline 828 (+86 into the body)
Filters the default post excerpt initially used in the "Write Post" form.
Uses · 16
- esc_html()Escaping for HTML blocks.
- wp_unslash()Removes slashes from a string or recursively removes slashes from strings within an array.
- wp_insert_post()Inserts or update a post.
- __()Retrieves the translation of $text.
- get_post()Retrieves post data given a post ID or post object.
- current_theme_supports()Checks a theme's support for a given feature.
- post_type_supports()Checks a post type's support for a given feature.
- get_option()Retrieves an option value based on an option name.
- set_post_format()Assign a format to a post
- wp_after_insert_post()Fires actions after a post, its terms and meta data has been saved.
- wp_next_scheduled()Retrieves the next timestamp for an event.
- wp_schedule_event()Schedules a recurring event.
Show all 16
- get_default_comment_status()Gets the default comment status for a post type.
- apply_filters()Calls the callback functions that have been added to a filter hook.
- stdClass::__construct()
- WP_Post::__construct()Constructor.
Used by · 5
- WP_Posts_List_Table::inline_edit()Outputs the hidden row displayed when inline editing
- get_default_page_to_edit()Gets the default page information to use.
- wp_dashboard_quick_press()Displays the Quick Draft widget.
- wp_xmlrpc_server::_insert_post()Helper method for wp_newPost() and wp_editPost(), containing shared logic.
- wp_xmlrpc_server::mw_newPost()Creates a new post.
Source code
function get_default_post_to_edit( $post_type = 'post', $create_in_db = false ) { $post_title = ''; if ( ! empty( $_REQUEST['post_title'] ) ) { $post_title = esc_html( wp_unslash( $_REQUEST['post_title'] ) ); } $post_content = ''; if ( ! empty( $_REQUEST['content'] ) ) { $post_content = esc_html( wp_unslash( $_REQUEST['content'] ) ); } $post_excerpt = ''; if ( ! empty( $_REQUEST['excerpt'] ) ) { $post_excerpt = esc_html( wp_unslash( $_REQUEST['excerpt'] ) ); } if ( $create_in_db ) { $post_id = wp_insert_post( array( 'post_title' => __( 'Auto Draft' ), 'post_type' => $post_type, 'post_status' => 'auto-draft', ), false, false ); $post = get_post( $post_id ); if ( current_theme_supports( 'post-formats' ) && post_type_supports( $post->post_type, 'post-formats' ) && get_option( 'default_post_format' ) ) { set_post_format( $post, get_option( 'default_post_format' ) ); } wp_after_insert_post( $post, false, null ); // Schedule auto-draft cleanup. if ( ! wp_next_scheduled( 'wp_scheduled_auto_draft_delete' ) ) { wp_schedule_event( time(), 'daily', 'wp_scheduled_auto_draft_delete' ); } } else { $post = new stdClass(); $post->ID = 0; $post->post_author = ''; $post->post_date = ''; $post->post_date_gmt = ''; $post->post_password = ''; $post->post_name = ''; $post->post_type = $post_type; $post->post_status = 'draft'; $post->to_ping = ''; $post->pinged = ''; $post->comment_status = get_default_comment_status( $post_type ); $post->ping_status = get_default_comment_status( $post_type, 'pingback' ); $post->post_pingback = get_option( 'default_pingback_flag' ); $post->post_category = get_option( 'default_category' ); $post->page_template = 'default'; $post->post_parent = 0; $post->menu_order = 0; $post = new WP_Post( $post ); } /** * Filters the default post content initially used in the "Write Post" form. * * @since 1.5.0 * * @param string $post_content Default post content. * @param WP_Post $post Post object. */ $post->post_content = (string) apply_filters( 'default_content', $post_content, $post ); /** * Filters the default post title initially used in the "Write Post" form. * * @since 1.5.0 * * @param string $post_title Default post title. * @param WP_Post $post Post object. */ $post->post_title = (string) apply_filters( 'default_title', $post_title, $post ); /** * Filters the default post excerpt initially used in the "Write Post" form.Changelog
Introduced in 2.0.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 6.7.7 tag, from
src/wp-admin/includes/post.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.