Skip to content

Commit

Permalink
Disable checkbox instead of removing it
Browse files Browse the repository at this point in the history
  • Loading branch information
aristath committed Sep 20, 2021
1 parent f2779af commit 209ee36
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 22 deletions.
11 changes: 6 additions & 5 deletions src/wp-admin/includes/class-wp-plugin-dependencies.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public function __construct() {
// Filter available plugin actions.
add_filter( 'plugin_action_links', array( $this, 'plugin_action_links' ), 10, 2 );

add_filter( 'plugin_display_checkbox', array( $this, 'hide_checkbox_for_dependency' ), 10, 2 );
add_filter( 'plugin_checkbox_disabled', array( $this, 'disable_checkbox_for_dependency' ), 10, 2 );
}

/**
Expand Down Expand Up @@ -382,16 +382,17 @@ public function get_parents( $plugin_file ) {
*
* @since 5.9.0
*
* @param bool $display Whether the checkbox should be displayed.
* @param bool $disabled Whether the checkbox should be disabled or not.
* @param string $plugin_file Path to the plugin file relative to the plugins' directory.
*
* @return bool
*/
public function hide_checkbox_for_dependency( $display, $plugin_file ) {
public function disable_checkbox_for_dependency( $disabled, $plugin_file ) {
if ( ! empty( $this->get_parents( $plugin_file ) ) && is_plugin_active( $plugin_file ) ) {
return false;
var_dump( $plugin_file );
return true;
}
return $display;
return $disabled;
}

/**
Expand Down
35 changes: 18 additions & 17 deletions src/wp-admin/includes/class-wp-plugins-list-table.php
Original file line number Diff line number Diff line change
Expand Up @@ -973,9 +973,24 @@ public function single_row( $item ) {
if ( $restrict_network_active || $restrict_network_only || in_array( $status, array( 'mustuse', 'dropins' ), true ) || ! $compatible_php ) {
$checkbox = '';
} else {
/**
* Determines whether the checkbox should be disabled or not.
*
* @since 5.9.0
*
* @param bool $disabled Set to true to disable the checkbox. Defaults to false.
* @param string $plugin_file Path to the plugin file relative to the plugins directory.
*
* @return bool
*/
$checkbox_disabled = apply_filters( 'plugin_checkbox_disabled', false, $plugin_file );

$checkbox_input = '<input type="checkbox" name="checked[]" value="%3$s" id="%1$s" />';
if ( $checkbox_disabled ) {
$checkbox_input = '<input type="checkbox" name="checked[]" value="%3$s" id="%1$s" disabled="disabled" />';
}
$checkbox = sprintf(
'<label class="screen-reader-text" for="%1$s">%2$s</label>' .
'<input type="checkbox" name="checked[]" value="%3$s" id="%1$s" />',
'<label class="screen-reader-text" for="%1$s">%2$s</label>' . $checkbox_input,
$checkbox_id,
/* translators: %s: Plugin name. */
sprintf( __( 'Select %s' ), $plugin_data['Name'] ),
Expand Down Expand Up @@ -1028,21 +1043,7 @@ public function single_row( $item ) {

switch ( $column_name ) {
case 'cb':
echo '<th scope="row" class="check-column">';
/**
* Determines whether the checkbox should be displayed in the plugin row.
*
* @since 5.9.0
*
* @param bool $display True to show the checkblox, false to hide it. Defaults to true.
* @param string $plugin_file Path to the plugin file relative to the plugins directory.
*
* @return bool True if the checkbox should be displayed, false otherwise.
*/
if ( apply_filters( 'plugin_display_checkbox', true, $plugin_file ) ) {
echo $checkbox;
}
echo '</th>';
echo "<th scope='row' class='check-column'>$checkbox</th>";
break;
case 'name':
echo "<td class='plugin-title column-primary'><strong>$plugin_name</strong>";
Expand Down

0 comments on commit 209ee36

Please sign in to comment.