Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions src/js/_enqueues/admin/inline-edit-post.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
},
Expand Down
1 change: 1 addition & 0 deletions src/wp-admin/admin-ajax.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
'sample-permalink',
'inline-save',
'inline-save-tax',
'inline-edit-custom-box',
'find_posts',
'widgets-order',
'save-widget',
Expand Down
28 changes: 28 additions & 0 deletions src/wp-admin/includes/ajax-actions.php
Original file line number Diff line number Diff line change
Expand Up @@ -2198,6 +2198,34 @@
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 );

Check warning on line 2224 in src/wp-admin/includes/ajax-actions.php

View workflow job for this annotation

GitHub Actions / PHP static analysis / Run PHP static analysis

Cannot call method get_inline_edit_custom_box() on WP_List_Table|false.

wp_die();
}

/**
* Handles Quick Edit saving for a term via AJAX.
*
Expand Down
58 changes: 47 additions & 11 deletions src/wp-admin/includes/class-wp-posts-list-table.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 '<div class="inline-edit-custom-boxes"></div>';
}
}
?>
Expand Down Expand Up @@ -2249,4 +2239,50 @@ public function inline_edit() {
</form>
<?php
}

/**
* Returns the custom fields displayed in Quick Edit mode.
*
* @since 7.2.0
*
* @param WP_Post $post The post being edited.
* @return string The custom Quick Edit fields.
*/
public function get_inline_edit_custom_box( $post ) {
$screen = $this->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();
}
}
34 changes: 34 additions & 0 deletions tests/phpunit/tests/admin/wpPostsListTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
Loading