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 f3ef1d8e3102..dd8bb3ca4129 100644 --- a/src/wp-admin/includes/class-wp-posts-list-table.php +++ b/src/wp-admin/includes/class-wp-posts-list-table.php @@ -1166,8 +1166,6 @@ public function column_title( $post ) { echo esc_html( get_the_excerpt() ); } } - - get_inline_data( $post ); } /** @@ -1578,6 +1576,10 @@ protected function handle_row_actions( $item, $column_name, $primary ) { $actions = apply_filters( 'post_row_actions', $actions, $post ); } + if ( isset( $actions['inline hide-if-no-js'] ) ) { + get_inline_data( $post ); + } + return $this->row_actions( $actions ); } diff --git a/tests/phpunit/tests/admin/wpPostsListTable.php b/tests/phpunit/tests/admin/wpPostsListTable.php index 4b2dfe6e0a6a..6eb1dbaa8792 100644 --- a/tests/phpunit/tests/admin/wpPostsListTable.php +++ b/tests/phpunit/tests/admin/wpPostsListTable.php @@ -331,4 +331,121 @@ public function test_get_views_should_return_views_by_default() { $this->assertSame( $expected, $actual ); } + /** + * Tests that `WP_Posts_List_Table::handle_row_actions()` conditionally renders + * Quick Edit markup depending on the presence of the 'inline hide-if-no-js' action. + * + * @ticket 16502 + * + * @covers WP_Posts_List_Table::handle_row_actions + * + * @dataProvider data_post_types + * + * @param bool $has_inline_action Whether the 'inline hide-if-no-js' should be present. + * @param bool $expected Whether the Quick Edit markup should be present. + * @param string $post_type The post type to test. + * @param bool $hierarchical Optional. Whether the post type is hierarchical. + * For custom post types only. + * If hierarchical, the 'page_row_actions' hook is used, + * otherwise 'post_row_actions'. + * Default false. + */ + public function test_handle_row_actions_should_conditionally_render_quick_edit_markup( $has_inline_action, $expected, $post_type, $hierarchical = false ) { + $hook = 'page' === $post_type || $hierarchical ? 'page_row_actions' : 'post_row_actions'; + add_filter( + $hook, + static function( $actions ) use ( $has_inline_action ) { + if ( $has_inline_action ) { + $actions['inline hide-if-no-js'] = 'Should render'; + } else { + unset( $actions['inline hide-if-no-js'] ); + } + return $actions; + } + ); + + if ( str_contains( $post_type, 'cpt' ) ) { + register_post_type( + $post_type, + array( + 'labels' => array( 'name' => $post_type ), + 'hierarchical' => $hierarchical, + ) + ); + } + + $post = self::factory()->post->create_and_get( + array( + 'post_title' => 'Post Title', + 'post_type' => $post_type, + ) + ); + + $handle_row_actions = new ReflectionMethod( $this->table, 'handle_row_actions' ); + + $handle_row_actions->setAccessible( true ); + $actual = $handle_row_actions->invokeArgs( $this->table, array( $post, 'primary', 'primary' ) ); + $handle_row_actions->setAccessible( false ); + + if ( $expected ) { + $this->assertStringContainsString( 'inline hide-if-no-js', $actual ); + } else { + $this->assertStringNotContainsString( 'inline hide-if-no-js', $actual ); + } + } + + /** + * Data provider. + * + * @return array[] + */ + public function data_post_types() { + return array( + 'a post with the "inline hide-if-no-js" action' => array( + 'has_inline_action' => true, + 'expected' => true, + 'post_type' => 'post', + ), + 'a page with the "inline hide-if-no-js" action' => array( + 'has_inline_action' => true, + 'expected' => true, + 'post_type' => 'page', + ), + 'a hierarchical custom post type with the "inline hide-if-no-js" action' => array( + 'has_inline_action' => true, + 'expected' => true, + 'post_type' => 'my_cpt', + 'hierarchical' => true, + ), + 'a non-hierarchical custom post type with the "inline hide-if-no-js" action' => array( + 'has_inline_action' => true, + 'expected' => true, + 'post_type' => 'my_cpt', + 'hierarchical' => false, + ), + 'a post without the "inline hide-if-no-js" action' => array( + 'has_inline_action' => false, + 'expected' => false, + 'post_type' => 'post', + ), + 'a page without the "inline hide-if-no-js" action' => array( + 'has_inline_action' => false, + 'expected' => false, + 'post_type' => 'page', + ), + 'a hierarchical custom post type without the "inline hide-if-no-js" action' => array( + 'has_inline_action' => false, + 'expected' => false, + 'post_type' => 'my_cpt', + 'hierarchical' => true, + ), + 'a non-hierarchical custom post type without the "inline hide-if-no-js" action' => array( + 'has_inline_action' => false, + 'expected' => false, + 'post_type' => 'my_cpt', + 'hierarchical' => false, + ), + ); + } + }