wppaste
WordPress

bulk_edit_posts( array|null $post_data = null ): array

Since
2.7.0
Source
wp-admin/includes/post.php:500
Processes the post data for the bulk editing of posts.

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 $_POST superglobal.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

Reaches the database via ->get_results().

Scaling
Scales with input

The body loops, so the work grows with what you pass in.

Instructions
57–81

Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 404.

Plugin surface
1 hook

Third-party callbacks on 'bulk_edit_posts' run inside this call, and their cost is not bounded by anything here.

Called by
0

Nothing in core calls this; the cost is only what you spend yourself.

What it touches

  • querycontent queryget_post()called directly
  • hookthird-party callbacksdo_action()called directly
  • sqldatabase query->get_results()called directly
  • optionoption read or writeget_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.

WhenInstructionsCalls it makes
!isset($post_data) && current_user_can()57–65get_post_type_object(), current_user_can(), array_map(), do_action()
current_user_can()75–81get_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

PHPCompiledExecutedBranchesNotes
8.6-dev40457–8155
8.540457–8155
8.440457–815512 fewer instructions than PHP 8.3
8.341657–8155
8.241657–8155
8.141657–8155
7.441657–8155

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:

  1. do_action( bulk_edit_posts )actionline 726 (+226 into the body)

    Fires after processing the post data for bulk edit.

Uses · 25

Show all 25

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.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 7.1.0

Signature, return type and hooks compared across 5 parsed releases.

About this page

Parsed data
Generated from the wordpress-develop 7.0.4 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.