From a63be5a89018825d1ce56de7cfa65b90161c1bde Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Wed, 28 Jun 2023 13:17:49 +0000 Subject: [PATCH] Quick/Bulk Edit: Add an action hook to `bulk_edit_posts()` function. This changeset introduces the `bulk_edit_posts` action hook, triggered after processing the post data for bulk edit and before the function returns its results. For example, it allows developers to save additional data without having to perform any `.ajax()` calls. Follow-up to [8973]. Props helgatheviking, helen, Mte90, afercia, mrasharirfan, desrosj, itowhid06, pento, mensmaximus, audrasjb, costdev, webcommsat, marybaum, oglekler, mukesh27, SergeyBiryukov. Fixes #28112. git-svn-id: https://develop.svn.wordpress.org/trunk@56091 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-admin/includes/post.php | 10 +++++++++ tests/phpunit/tests/admin/includesPost.php | 25 ++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/src/wp-admin/includes/post.php b/src/wp-admin/includes/post.php index 4036b2bbce..37ab30721d 100644 --- a/src/wp-admin/includes/post.php +++ b/src/wp-admin/includes/post.php @@ -681,6 +681,16 @@ function bulk_edit_posts( $post_data = null ) { } } + /** + * Fires after processing the post data for bulk edit. + * + * @since 6.3.0 + * + * @param int[] $updated An array of updated post IDs. + * @param array $shared_post_data Associative array containing the post data. + */ + do_action( 'bulk_edit_posts', $updated, $shared_post_data ); + return array( 'updated' => $updated, 'skipped' => $skipped, diff --git a/tests/phpunit/tests/admin/includesPost.php b/tests/phpunit/tests/admin/includesPost.php index 07660e6f30..ec72c68f6d 100644 --- a/tests/phpunit/tests/admin/includesPost.php +++ b/tests/phpunit/tests/admin/includesPost.php @@ -318,6 +318,31 @@ class Tests_Admin_IncludesPost extends WP_UnitTestCase { } } + /** + * Tests that `bulk_edit_posts()` fires the 'bulk_edit_posts' action. + * + * @ticket 28112 + * + * @covers ::bulk_edit_posts + */ + public function test_bulk_edit_posts_should_fire_bulk_edit_posts_action() { + wp_set_current_user( self::$admin_id ); + + $action = new MockAction(); + add_action( 'bulk_edit_posts', array( $action, 'action' ) ); + + bulk_edit_posts( + array( + 'post' => self::$post_id, + 'post_type' => 'post', + '_status' => 1, + + ) + ); + + $this->assertSame( 1, $action->get_call_count() ); + } + /** * @ticket 38293 */