From e919eff796c965d161cb1650c082d5a100682070 Mon Sep 17 00:00:00 2001 From: ArkaPrabhaChowdhury Date: Fri, 11 Sep 2026 13:18:43 +0530 Subject: [PATCH] Quick/Bulk Edit: Pass post to quick edit custom hook --- src/js/_enqueues/admin/inline-edit-post.js | 14 ++++- src/wp-admin/admin-ajax.php | 1 + src/wp-admin/includes/ajax-actions.php | 28 +++++++++ .../includes/class-wp-posts-list-table.php | 58 +++++++++++++++---- .../phpunit/tests/admin/wpPostsListTable.php | 34 +++++++++++ 5 files changed, 122 insertions(+), 13 deletions(-) diff --git a/src/js/_enqueues/admin/inline-edit-post.js b/src/js/_enqueues/admin/inline-edit-post.js index 7f469137fc1bd..2a694ff768b14 100644 --- a/src/js/_enqueues/admin/inline-edit-post.js +++ b/src/js/_enqueues/admin/inline-edit-post.js @@ -479,8 +479,18 @@ window.wp = window.wp || {}; pageOpt.remove(); } - $(editRow).attr('id', 'edit-'+id).addClass('inline-editor').show(); - $('.ptitle', editRow).trigger( 'focus' ); + $(editRow).attr('id', 'edit-'+id).addClass('inline-editor'); + + $.post( ajaxurl, { + action: 'inline-edit-custom-box', + post_ID: id, + _inline_edit: $( ':input[name="_inline_edit"]', editRow ).val() + } ).done( function( response ) { + $( '.inline-edit-custom-boxes', editRow ).html( response ); + } ).always( function() { + $( editRow ).show(); + $( '.ptitle', editRow ).trigger( 'focus' ); + } ); return false; }, diff --git a/src/wp-admin/admin-ajax.php b/src/wp-admin/admin-ajax.php index 3ad60f95766e3..f601def92cead 100644 --- a/src/wp-admin/admin-ajax.php +++ b/src/wp-admin/admin-ajax.php @@ -89,6 +89,7 @@ 'sample-permalink', 'inline-save', 'inline-save-tax', + 'inline-edit-custom-box', 'find_posts', 'widgets-order', 'save-widget', diff --git a/src/wp-admin/includes/ajax-actions.php b/src/wp-admin/includes/ajax-actions.php index 747bcc75e53eb..1bb29ec53d754 100644 --- a/src/wp-admin/includes/ajax-actions.php +++ b/src/wp-admin/includes/ajax-actions.php @@ -2198,6 +2198,34 @@ function wp_ajax_inline_save() { wp_die(); } +/** + * Ajax handler for returning the custom Quick Edit fields for a post. + * + * @since 7.2.0 + */ +function wp_ajax_inline_edit_custom_box() { + check_ajax_referer( 'inlineeditnonce', '_inline_edit' ); + + $post_id = isset( $_POST['post_ID'] ) ? absint( $_POST['post_ID'] ) : 0; + $post = get_post( $post_id ); + + if ( ! $post || ! current_user_can( 'edit_post', $post_id ) ) { + wp_die( -1, 403 ); + } + + $screen_id = 'edit-' . $post->post_type; + $screen = get_current_screen(); + if ( ! $screen || $screen_id !== $screen->id ) { + set_current_screen( $screen_id ); + } + + $list_table = _get_list_table( 'WP_Posts_List_Table', array( 'screen' => get_current_screen() ) ); + + echo $list_table->get_inline_edit_custom_box( $post ); + + wp_die(); +} + /** * Handles Quick Edit saving for a term via AJAX. * diff --git a/src/wp-admin/includes/class-wp-posts-list-table.php b/src/wp-admin/includes/class-wp-posts-list-table.php index d3d631b9b4467..0b9afe8144c52 100644 --- a/src/wp-admin/includes/class-wp-posts-list-table.php +++ b/src/wp-admin/includes/class-wp-posts-list-table.php @@ -2191,17 +2191,7 @@ public function inline_edit() { */ do_action( 'bulk_edit_custom_box', $column_name, $screen->post_type ); } else { - - /** - * Fires once for each column in Quick Edit mode. - * - * @since 2.7.0 - * - * @param string $column_name Name of the column to edit. - * @param string $post_type The post type slug, or current screen name if this is a taxonomy list table. - * @param string $taxonomy The taxonomy name, if any. - */ - do_action( 'quick_edit_custom_box', $column_name, $screen->post_type, '' ); + echo '
'; } } ?> @@ -2249,4 +2239,50 @@ public function inline_edit() { screen; + + $core_columns = array( + 'cb' => true, + 'date' => true, + 'title' => true, + 'categories' => true, + 'tags' => true, + 'comments' => true, + 'author' => true, + ); + + list( $columns ) = $this->get_column_info(); + + ob_start(); + + foreach ( $columns as $column_name => $column_display_name ) { + if ( isset( $core_columns[ $column_name ] ) ) { + continue; + } + + /** + * Fires once for each column in Quick Edit mode. + * + * @since 2.7.0 + * + * @param string $column_name Name of the column to edit. + * @param string $post_type The post type slug. + * @param string $taxonomy The taxonomy name, if any. + * @param WP_Post $post The post being edited. + */ + do_action( 'quick_edit_custom_box', $column_name, $screen->post_type, '', $post ); + } + + return ob_get_clean(); + } } diff --git a/tests/phpunit/tests/admin/wpPostsListTable.php b/tests/phpunit/tests/admin/wpPostsListTable.php index 25324dcb4cb7f..ffadfa5125801 100644 --- a/tests/phpunit/tests/admin/wpPostsListTable.php +++ b/tests/phpunit/tests/admin/wpPostsListTable.php @@ -92,6 +92,40 @@ public function test_list_hierarchical_pages_first_page() { ); } + /** + * Tests that the post object is passed to the quick_edit_custom_box action. + * + * @ticket 53195 + */ + public function test_quick_edit_custom_box_receives_post_object() { + $received_post = null; + + add_action( + 'quick_edit_custom_box', + static function ( $column_name, $post_type, $taxonomy, $post ) use ( &$received_post ) { + if ( 'custom' === $column_name ) { + $received_post = $post; + } + }, + 10, + 4 + ); + + $table = new class( array( 'screen' => 'edit-page' ) ) extends WP_Posts_List_Table { + protected function get_column_info() { + $column_info = parent::get_column_info(); + $column_info[0]['custom'] = 'Custom'; + return $column_info; + } + }; + + $table->get_inline_edit_custom_box( self::$top[1] ); + + $this->assertInstanceOf( 'WP_Post', $received_post ); + $this->assertSame( 'page', $received_post->post_type ); + $this->assertSame( self::$top[1]->ID, $received_post->ID ); + } + /** * @ticket 15459 *