[wp-trac] [WordPress Trac] #57596: Categories/Tags: Quick Edit contents should only be rendered if quick edit is in actions after filtering.
WordPress Trac
noreply at wordpress.org
Wed Feb 1 06:35:21 UTC 2023
#57596: Categories/Tags: Quick Edit contents should only be rendered if quick edit
is in actions after filtering.
-------------------------------------------------+-------------------------
Reporter: costdev | Owner: (none)
Type: enhancement | Status: new
Priority: normal | Milestone: Awaiting
| Review
Component: Quick/Bulk Edit | Version: 3.0.4
Severity: normal | Resolution:
Keywords: needs-patch has-testing-info needs- | Focuses:
testing 2nd-opinion |
-------------------------------------------------+-------------------------
Description changed by costdev:
Old description:
> This is a follow-up to #16502.
>
> == Overview
>
> Despite Quick Edit being removed from the available actions, a
> `class="inline_<id>"` div is still rendered on the `Posts > Categories`
> and `Posts > Tags` screens.
>
> To prevent the div from rendering, [https://github.com/wordpress
> /wordpress-develop/blob/6.1/src/wp-admin/includes/class-wp-terms-list-
> table.php#L421-L426 this code] **(Ref 1)** must be rendered only if the
> `$actions` array includes the `inline hide-if-no-js` key.
>
> -----
>
> == The Problem
>
> The `$actions` array is currently created in the `::handle_row_actions()`
> method of `WP_Terms_List_Table`. This method returns an HTML string, not
> an array.
>
> -----
>
> == Possible Solution 1
> We could check the return value of `::handle_row_actions()` to see if it
> includes a substring, such as `editinline`, using `str_contains()`.
> However, this isn't a particularly clean solution, and is easily prone to
> regressions.
>
> == Possible Solution 2
> We could abstract [https://github.com/wordpress/wordpress-
> develop/blob/6.1/src/wp-admin/includes/class-wp-terms-list-
> table.php#L460-L537 this entire portion] **(Ref 2)** of the
> `::handle_row_actions()` method to a new method that returns `array
> $actions`.
>
> This new method would be called in `::handle_row_actions()` to retain
> existing functionality, as well as in `::column_name`:
>
> {{{#!php
> $actions = $this->get_row_actions();
> if ( isset( $actions['inline hide-if-no-js'] ) ) {
> // The code from (Ref 1)
> }
> }}}
>
> I'm adding `2nd-opinion` to gather thoughts on these possible solutions,
> and to explore other solutions you may have.
>
> -----
>
> == Reproduction/Testing Instructions
>
> === Steps to Reproduce or Test
> 1. Create a new file `wp-content/plugins/test-quick-edit-removal.php`
> with the following contents:
> {{{#!php
> <?php
> /**
> * Plugin Name: Test Quick Edit Removal
> * Description: Tests the removal of Quick Edit Contents.
> * Author: WordPress Core Contributors
> * Author URI: https://make.wordpress.org/core
> * License: GPLv2 or later
> * Version: 1.0.0
> */
>
> add_action( 'admin_bar_menu', 'test_qer_adminbar', 999 );
> add_filter( 'tag_row_actions', 'test_qer_hide_quick_edit', 10, 1 );
>
> function test_qer_adminbar( $wp_admin_bar ) {
> global $pagenow;
> $action = empty( $_GET['hide_quick_edit'] ) ? '1' : '0';
> $url = add_query_arg( array_merge( $_GET, array(
> 'hide_quick_edit' => $action ) ), admin_url( $pagenow ) );
> $wp_admin_bar->add_node( array( 'id' => 'test-qer', 'title' =>
> $action ? 'Remove Quick Edit' : 'Add Quick Edit', 'href' => $url ) );
> }
>
> function test_qer_hide_quick_edit( $actions ) {
> if ( isset( $_GET['hide_quick_edit'] ) && '1' ===
> $_GET['hide_quick_edit'] ) unset( $actions['inline hide-if-no-js'] );
> return $actions;
> }
> }}}
> 2. Navigate to `Plugins > Installed Plugins` and activate **Test Quick
> Edit Removal**.
> 3. Navigate to `Posts > Categories`.
> 4. Open DevTools and inspect a category's title.
> 5. Below the category's title `<strong>` markup, there will be `<div
> class="hidden" id="inline_XXXX">` element.
> 6. In the admin bar, click "Remove Quick Edit".
> 7. 🐞 Repeat steps 4-5.
> 8. Click "Add Quick Edit".
> 9. Apply a patch.
> 10. ✅ Repeat steps 3-7.
> 11. Repeat steps 3-10 for `Posts > Tags`.
>
> === Expected Results
> When reproducing a bug:
> - ❌ The hidden "inline_XXXX" element should exist even though "Quick
> Edit" is removed.
>
> When testing a patch to validate it works as expected:
> - ✅ Posts (and other screens): The element should no longer exist when
> "Quick Edit" is removed.
New description:
This is a follow-up to #16502.
== Overview
Despite Quick Edit being removed from the available actions, a
`class="inline_<id>"` div is still rendered on the `Posts > Categories`
and `Posts > Tags` screens.
To prevent the div from rendering, [https://github.com/wordpress
/wordpress-develop/blob/6.1/src/wp-admin/includes/class-wp-terms-list-
table.php#L421-L426 this code] **(Ref 1)** must be rendered only if the
`$actions` array includes the `inline hide-if-no-js` key.
-----
== The Problem
The `$actions` array is currently created in the `::handle_row_actions()`
method of `WP_Terms_List_Table`. This method returns an HTML string, not
an array.
-----
== Possible Solution 1
We could check the return value of `::handle_row_actions()` to see if it
includes a substring, such as `editinline`, using `str_contains()`.
However, this isn't a particularly clean solution, and is easily prone to
regressions.
== Possible Solution 2
We could abstract [https://github.com/wordpress/wordpress-
develop/blob/6.1/src/wp-admin/includes/class-wp-terms-list-
table.php#L460-L537 this entire portion] **(Ref 2)** of the
`::handle_row_actions()` method to a new method that returns `array
$actions`.
This new method would be called in `::handle_row_actions()` to retain
existing functionality, as well as in `::column_name`:
{{{#!php
$actions = $this->get_row_actions();
if ( isset( $actions['inline hide-if-no-js'] ) ) {
// The code from (Ref 1)
}
}}}
I'm adding `2nd-opinion` to gather thoughts on these possible solutions,
and to explore other solutions you may have.
-----
== Reproduction/Testing Instructions
=== Steps to Reproduce or Test
1. Create a new file `wp-content/plugins/test-quick-edit-removal.php` with
the following contents:
{{{#!php
<?php
/**
* Plugin Name: Test Quick Edit Removal
* Description: Tests the removal of Quick Edit Contents.
* Author: WordPress Core Contributors
* Author URI: https://make.wordpress.org/core
* License: GPLv2 or later
* Version: 1.0.0
*/
add_action( 'admin_bar_menu', 'test_qer_adminbar', 999 );
add_filter( 'tag_row_actions', 'test_qer_hide_quick_edit', 10, 1 );
function test_qer_adminbar( $wp_admin_bar ) {
global $pagenow;
$action = empty( $_GET['hide_quick_edit'] ) ? '1' : '0';
$url = add_query_arg( array_merge( $_GET, array(
'hide_quick_edit' => $action ) ), admin_url( $pagenow ) );
$wp_admin_bar->add_node( array( 'id' => 'test-qer', 'title' =>
$action ? 'Remove Quick Edit' : 'Add Quick Edit', 'href' => $url ) );
}
function test_qer_hide_quick_edit( $actions ) {
if ( isset( $_GET['hide_quick_edit'] ) && '1' ===
$_GET['hide_quick_edit'] ) unset( $actions['inline hide-if-no-js'] );
return $actions;
}
}}}
2. Navigate to `Plugins > Installed Plugins` and activate **Test Quick
Edit Removal**.
3. Navigate to `Posts > Categories`.
4. Open DevTools and inspect a category's title.
5. Below the category's title `<strong>` markup, there will be `<div
class="hidden" id="inline_XXXX">` element.
6. In the admin bar, click "Remove Quick Edit".
7. 🐞 Repeat steps 4-5.
8. Click "Add Quick Edit".
9. Apply a patch.
10. ✅ Repeat steps 3-7.
11. Repeat steps 3-10 for `Posts > Tags`.
=== Expected Results
When reproducing a bug:
- ❌ The hidden "inline_XXXX" element should exist even though "Quick
Edit" is removed.
When testing a patch to validate it works as expected:
- ✅ The element should no longer exist when "Quick Edit" is removed.
--
--
Ticket URL: <https://core.trac.wordpress.org/ticket/57596#comment:1>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list