[wp-trac] [WordPress Trac] #59587: Pass column count to "after_plugin_row" action hooks in WP_Plugins_List_Table
WordPress Trac
noreply at wordpress.org
Tue Oct 10 20:24:57 UTC 2023
#59587: Pass column count to "after_plugin_row" action hooks in
WP_Plugins_List_Table
------------------------------------+---------------------
Reporter: TobiasBg | Owner: (none)
Type: enhancement | Status: new
Priority: normal | Milestone: 6.5
Component: Administration | Version:
Severity: normal | Resolution:
Keywords: has-patch dev-feedback | Focuses:
------------------------------------+---------------------
Changes (by TobiasBg):
* keywords: has-patch reporter-feedback dev-feedback => has-patch dev-
feedback
Comment:
@afragen: Sure, I'll try to explain a bit more!
Basically, the `after_plugin_row` hook can only really be used to echo
another `<tr>` in the WP_Plugins_List_Table (the action hook runs inside
the `<tbody>`, after each plugin's `<tr>`).
For adding that `<tr>`, the action hook handler needs to know the number
of visible columns (no matter if it prints a `<td>` for each column or if
it prints one `<td colspan=...>` (probably the more common case)).
I noticed this when trying to replicate something like from the attached
screenshot 59587-example.png (which shows that the code that adds that red
notice likely uses a hard-coded number for that `colspan` -- resulting in
a row that is too "short").
Some code for this could be
{{{
add_action( 'after_plugin_row', 'my_custom_plugin_row', 10, 3 );
function my_custom_plugin_row( $plugin_file, $plugin_data, $status ) {
echo
'<tr class="plugin-update-tr">' .
'<td colspan="4" class="plugin-update colspanchange">' .
'<div class="update-message notice inline notice-error
notice-alt"><p>' .
'Your custom message goes here.' .
'</p></div></td></tr>';
}
}}}
Note how the `colspan` is hard-coded to `4`, as the function can't know
the correct value, which depends on things like the user's capabilities,
etc.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/59587#comment:2>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list