bulk_edit_posts( array|null $post_data = null ): array
- Since
- 2.7.0
- Source
wp-admin/includes/post.php:504
Description
Updates all bulk edited posts/pages, adding (but not removing) tags and categories. Skips pages when they would be their own parent or child.
Compatibility
- WordPress
- since 2.7.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_dataarray|nulloptional- The array of post data to process.
Defaults to the$_POSTsuperglobal.Default:null
Return value
array- An array of updated, skipped, and locked post IDs.
$updatedint[]An array of updated post IDs.$skippedint[]An array of skipped post IDs.$lockedint[]An array of locked post IDs.
Performance profile
How much work a call to bulk_edit_posts() 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
- 57–81
- Plugin surface
- 1 hook
- Called by
- 0
Reaches the database via ->get_results().
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 404.
Third-party callbacks on 'bulk_edit_posts' run inside this call, and their cost is not bounded by anything here.
Nothing in core calls this; the cost is only what you spend yourself.
What it touches
- querycontent query
get_post()called directly - hookthird-party callbacks
do_action()called directly - sqldatabase query
->get_results()called directly - optionoption read or write
get_option()one call below bulk_edit_posts()
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 · 2 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost bulk_edit_posts() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
!isset($post_data) && current_user_can() | 57–65 | get_post_type_object(), current_user_can(), array_map(), do_action() |
current_user_can() | 75–81 | get_post_type_object(), current_user_can(), array_map(), ->get_results(), do_action() |
This body has more branch combinations than are worth enumerating, so the table covers the outcomes found first rather than every one that exists.
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 404 | 57–81 | 55 | |
| 8.5 | 404 | 57–81 | 55 | |
| 8.4 | 404 | 57–81 | 55 | 12 fewer instructions than PHP 8.3 |
| 8.3 | 416 | 57–81 | 55 | |
| 8.2 | 416 | 57–81 | 55 | |
| 8.1 | 416 | 57–81 | 55 | |
| 7.4 | 416 | 57–81 | 55 |
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 bulk_edit_posts() runs, in this order:
- do_action( bulk_edit_posts )actionline 730 (+226 into the body)
Fires after processing the post data for bulk edit.
Uses · 25
- get_post_type_object()Retrieves a post type object by name.
- current_user_can()Returns whether the current user has the specified capability.
- wp_die()Kills WordPress execution and displays HTML page with an error message.
- __()Retrieves the translation of $text.
- sanitize_key()Sanitizes a string key.
- is_taxonomy_hierarchical()Determines whether the taxonomy object is hierarchical.
- _x()Retrieves translated string with gettext context.
- get_post_type()Retrieves the post type of the current post or of a given post.
- wp_check_post_lock()Determines whether the post is currently being edited by another user.
- get_post()Retrieves post data given a post ID or post object.
- get_object_taxonomies()Returns the names or objects of the taxonomies which are registered for the requested object or object type, such as a post object or post type name.
- get_taxonomy()Retrieves the taxonomy object of $taxonomy.
Show all 25
- wp_get_object_terms()Retrieves the terms associated with the given object(s), in the supplied taxonomies.
- wp_get_post_categories()Retrieves the list of categories for a post.
- _wp_translate_postdata()Renames `$_POST` data from form names to DB post columns.
- is_wp_error()Checks whether the given variable is a WordPress Error.
- _wp_get_allowed_postdata()Returns only allowed post data fields.
- set_post_format()Assign a format to a post
- current_time()Retrieves the current time based on specified type.
- wp_update_post()Updates a post with new post data.
- update_post_meta()Updates a post meta field based on the given post ID.
- get_current_user_id()Gets the current user's ID.
- stick_post()Makes a post sticky.
- unstick_post()Un-sticks a post.
- do_action()Calls the callback functions that have been added to an action hook.
Source code
function bulk_edit_posts( $post_data = null ) { global $wpdb; if ( empty( $post_data ) ) { $post_data = &$_POST; } if ( isset( $post_data['post_type'] ) ) { $ptype = get_post_type_object( $post_data['post_type'] ); } else { $ptype = get_post_type_object( 'post' ); } if ( ! current_user_can( $ptype->cap->edit_posts ) ) { if ( 'page' === $ptype->name ) { wp_die( __( 'Sorry, you are not allowed to edit pages.' ) ); } else { wp_die( __( 'Sorry, you are not allowed to edit posts.' ) ); } } if ( '-1' === $post_data['_status'] ) { $post_data['post_status'] = null; unset( $post_data['post_status'] ); } else { $post_data['post_status'] = $post_data['_status']; } unset( $post_data['_status'] ); if ( ! empty( $post_data['post_status'] ) ) { $post_data['post_status'] = sanitize_key( $post_data['post_status'] ); if ( 'inherit' === $post_data['post_status'] ) { unset( $post_data['post_status'] ); } } $post_ids = array_map( 'intval', (array) $post_data['post'] ); $reset = array( 'post_author', 'post_status', 'post_password', 'post_parent', 'page_template', 'comment_status', 'ping_status', 'keep_private', 'tax_input', 'post_category', 'sticky', 'post_format', ); foreach ( $reset as $field ) { if ( isset( $post_data[ $field ] ) && ( '' === $post_data[ $field ] || '-1' === $post_data[ $field ] ) ) { unset( $post_data[ $field ] ); } } if ( isset( $post_data['post_category'] ) ) { if ( is_array( $post_data['post_category'] ) && ! empty( $post_data['post_category'] ) ) { $new_cats = array_map( 'absint', $post_data['post_category'] ); } else { unset( $post_data['post_category'] ); } } $tax_input = array(); if ( isset( $post_data['tax_input'] ) ) { foreach ( $post_data['tax_input'] as $tax_name => $terms ) { if ( empty( $terms ) ) { continue; } if ( is_taxonomy_hierarchical( $tax_name ) ) { $tax_input[ $tax_name ] = array_map( 'absint', $terms ); } else { $comma = _x( ',', 'tag delimiter' ); if ( ',' !== $comma ) {Changelog
Introduced in 2.7.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.8.8 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.