Make WordPress Core

Changeset 56091


Ignore:
Timestamp:
06/28/2023 01:17:49 PM (17 months ago)
Author:
SergeyBiryukov
Message:

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.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/post.php

    r56022 r56091  
    681681        }
    682682    }
     683
     684    /**
     685     * Fires after processing the post data for bulk edit.
     686     *
     687     * @since 6.3.0
     688     *
     689     * @param int[] $updated          An array of updated post IDs.
     690     * @param array $shared_post_data Associative array containing the post data.
     691     */
     692    do_action( 'bulk_edit_posts', $updated, $shared_post_data );
    683693
    684694    return array(
  • trunk/tests/phpunit/tests/admin/includesPost.php

    r55673 r56091  
    317317            $this->assertSame( 'aside', get_post_format( $post_id ) );
    318318        }
     319    }
     320
     321    /**
     322     * Tests that `bulk_edit_posts()` fires the 'bulk_edit_posts' action.
     323     *
     324     * @ticket 28112
     325     *
     326     * @covers ::bulk_edit_posts
     327     */
     328    public function test_bulk_edit_posts_should_fire_bulk_edit_posts_action() {
     329        wp_set_current_user( self::$admin_id );
     330
     331        $action = new MockAction();
     332        add_action( 'bulk_edit_posts', array( $action, 'action' ) );
     333
     334        bulk_edit_posts(
     335            array(
     336                'post'      => self::$post_id,
     337                'post_type' => 'post',
     338                '_status'   => 1,
     339
     340            )
     341        );
     342
     343        $this->assertSame( 1, $action->get_call_count() );
    319344    }
    320345
Note: See TracChangeset for help on using the changeset viewer.