diff -r 3d4e9c994f10 -r a86126ab1dd4 wp/wp-admin/includes/class-wp-plugins-list-table.php --- a/wp/wp-admin/includes/class-wp-plugins-list-table.php Tue Oct 22 16:11:46 2019 +0200 +++ b/wp/wp-admin/includes/class-wp-plugins-list-table.php Tue Dec 15 13:49:49 2020 +0100 @@ -16,6 +16,14 @@ * @see WP_List_Table */ class WP_Plugins_List_Table extends WP_List_Table { + /** + * Whether to show the auto-updates UI. + * + * @since 5.5.0 + * + * @var bool True if auto-updates UI is to be shown, false otherwise. + */ + protected $show_autoupdates = true; /** * Constructor. @@ -39,8 +47,10 @@ ) ); + $allowed_statuses = array( 'active', 'inactive', 'recently_activated', 'upgrade', 'mustuse', 'dropins', 'search', 'paused', 'auto-update-enabled', 'auto-update-disabled' ); + $status = 'all'; - if ( isset( $_REQUEST['plugin_status'] ) && in_array( $_REQUEST['plugin_status'], array( 'active', 'inactive', 'recently_activated', 'upgrade', 'mustuse', 'dropins', 'search', 'paused' ) ) ) { + if ( isset( $_REQUEST['plugin_status'] ) && in_array( $_REQUEST['plugin_status'], $allowed_statuses, true ) ) { $status = $_REQUEST['plugin_status']; } @@ -49,6 +59,11 @@ } $page = $this->get_pagenum(); + + $this->show_autoupdates = wp_is_auto_update_enabled_for_type( 'plugin' ) + && current_user_can( 'update_plugins' ) + && ( ! is_multisite() || $this->screen->in_admin( 'network' ) ) + && ! in_array( $status, array( 'mustuse', 'dropins' ), true ); } /** @@ -101,6 +116,12 @@ 'dropins' => array(), 'paused' => array(), ); + if ( $this->show_autoupdates ) { + $auto_updates = (array) get_site_option( 'auto_update_plugins', array() ); + + $plugins['auto-update-enabled'] = array(); + $plugins['auto-update-disabled'] = array(); + } $screen = $this->screen; @@ -159,8 +180,6 @@ $show_network_active = apply_filters( 'show_network_active_plugins', $show ); } - set_transient( 'plugin_slugs', array_keys( $plugins['all'] ), DAY_IN_SECONDS ); - if ( $screen->in_admin( 'network' ) ) { $recently_activated = get_site_option( 'recently_activated', array() ); } else { @@ -184,42 +203,69 @@ foreach ( (array) $plugins['all'] as $plugin_file => $plugin_data ) { // Extra info if known. array_merge() ensures $plugin_data has precedence if keys collide. if ( isset( $plugin_info->response[ $plugin_file ] ) ) { - $plugin_data = array_merge( (array) $plugin_info->response[ $plugin_file ], $plugin_data ); - $plugins['all'][ $plugin_file ] = $plugin_data; - // Make sure that $plugins['upgrade'] also receives the extra info since it is used on ?plugin_status=upgrade - if ( isset( $plugins['upgrade'][ $plugin_file ] ) ) { - $plugins['upgrade'][ $plugin_file ] = $plugin_data; - } + $plugin_data = array_merge( (array) $plugin_info->response[ $plugin_file ], array( 'update-supported' => true ), $plugin_data ); } elseif ( isset( $plugin_info->no_update[ $plugin_file ] ) ) { - $plugin_data = array_merge( (array) $plugin_info->no_update[ $plugin_file ], $plugin_data ); - $plugins['all'][ $plugin_file ] = $plugin_data; - // Make sure that $plugins['upgrade'] also receives the extra info since it is used on ?plugin_status=upgrade - if ( isset( $plugins['upgrade'][ $plugin_file ] ) ) { - $plugins['upgrade'][ $plugin_file ] = $plugin_data; - } + $plugin_data = array_merge( (array) $plugin_info->no_update[ $plugin_file ], array( 'update-supported' => true ), $plugin_data ); + } elseif ( empty( $plugin_data['update-supported'] ) ) { + $plugin_data['update-supported'] = false; } - // Filter into individual sections + /* + * Create the payload that's used for the auto_update_plugin filter. + * This is the same data contained within $plugin_info->(response|no_update) however + * not all plugins will be contained in those keys, this avoids unexpected warnings. + */ + $filter_payload = array( + 'id' => $plugin_file, + 'slug' => '', + 'plugin' => $plugin_file, + 'new_version' => '', + 'url' => '', + 'package' => '', + 'icons' => array(), + 'banners' => array(), + 'banners_rtl' => array(), + 'tested' => '', + 'requires_php' => '', + 'compatibility' => new stdClass(), + ); + $filter_payload = (object) array_merge( $filter_payload, array_intersect_key( $plugin_data, $filter_payload ) ); + + $type = 'plugin'; + /** This filter is documented in wp-admin/includes/class-wp-automatic-updater.php */ + $auto_update_forced = apply_filters( "auto_update_{$type}", null, $filter_payload ); + + if ( ! is_null( $auto_update_forced ) ) { + $plugin_data['auto-update-forced'] = $auto_update_forced; + } + + $plugins['all'][ $plugin_file ] = $plugin_data; + // Make sure that $plugins['upgrade'] also receives the extra info since it is used on ?plugin_status=upgrade. + if ( isset( $plugins['upgrade'][ $plugin_file ] ) ) { + $plugins['upgrade'][ $plugin_file ] = $plugin_data; + } + + // Filter into individual sections. if ( is_multisite() && ! $screen->in_admin( 'network' ) && is_network_only_plugin( $plugin_file ) && ! is_plugin_active( $plugin_file ) ) { if ( $show_network_active ) { - // On the non-network screen, show inactive network-only plugins if allowed + // On the non-network screen, show inactive network-only plugins if allowed. $plugins['inactive'][ $plugin_file ] = $plugin_data; } else { - // On the non-network screen, filter out network-only plugins as long as they're not individually active + // On the non-network screen, filter out network-only plugins as long as they're not individually active. unset( $plugins['all'][ $plugin_file ] ); } } elseif ( ! $screen->in_admin( 'network' ) && is_plugin_active_for_network( $plugin_file ) ) { if ( $show_network_active ) { - // On the non-network screen, show network-active plugins if allowed + // On the non-network screen, show network-active plugins if allowed. $plugins['active'][ $plugin_file ] = $plugin_data; } else { - // On the non-network screen, filter out network-active plugins + // On the non-network screen, filter out network-active plugins. unset( $plugins['all'][ $plugin_file ] ); } } elseif ( ( ! $screen->in_admin( 'network' ) && is_plugin_active( $plugin_file ) ) || ( $screen->in_admin( 'network' ) && is_plugin_active_for_network( $plugin_file ) ) ) { - // On the non-network screen, populate the active list with plugins that are individually activated - // On the network-admin screen, populate the active list with plugins that are network activated + // On the non-network screen, populate the active list with plugins that are individually activated. + // On the network admin screen, populate the active list with plugins that are network-activated. $plugins['active'][ $plugin_file ] = $plugin_data; if ( ! $screen->in_admin( 'network' ) && is_plugin_paused( $plugin_file ) ) { @@ -227,12 +273,25 @@ } } else { if ( isset( $recently_activated[ $plugin_file ] ) ) { - // Populate the recently activated list with plugins that have been recently activated + // Populate the recently activated list with plugins that have been recently activated. $plugins['recently_activated'][ $plugin_file ] = $plugin_data; } - // Populate the inactive list with plugins that aren't activated + // Populate the inactive list with plugins that aren't activated. $plugins['inactive'][ $plugin_file ] = $plugin_data; } + + if ( $this->show_autoupdates ) { + $enabled = in_array( $plugin_file, $auto_updates, true ) && $plugin_data['update-supported']; + if ( isset( $plugin_data['auto-update-forced'] ) ) { + $enabled = (bool) $plugin_data['auto-update-forced']; + } + + if ( $enabled ) { + $plugins['auto-update-enabled'][ $plugin_file ] = $plugin_data; + } else { + $plugins['auto-update-disabled'][ $plugin_file ] = $plugin_data; + } + } } if ( strlen( $s ) ) { @@ -245,13 +304,13 @@ $totals[ $type ] = count( $list ); } - if ( empty( $plugins[ $status ] ) && ! in_array( $status, array( 'all', 'search' ) ) ) { + if ( empty( $plugins[ $status ] ) && ! in_array( $status, array( 'all', 'search' ), true ) ) { $status = 'all'; } $this->items = array(); foreach ( $plugins[ $status ] as $plugin_file => $plugin_data ) { - // Translate, Don't Apply Markup, Sanitize HTML + // Translate, don't apply markup, sanitize HTML. $this->items[ $plugin_file ] = _get_plugin_data_markup_translate( $plugin_file, $plugin_data, false, true ); } @@ -348,7 +407,7 @@ if ( ! empty( $_REQUEST['s'] ) ) { $s = esc_html( wp_unslash( $_REQUEST['s'] ) ); - /* translators: %s: plugin search term */ + /* translators: %s: Plugin search term. */ printf( __( 'No plugins found for “%s”.' ), $s ); // We assume that somebody who can install plugins in multisite is experienced enough to not need this helper link. @@ -358,7 +417,7 @@ } elseif ( ! empty( $plugins['all'] ) ) { _e( 'No plugins found.' ); } else { - _e( 'You do not appear to have any plugins available at this time.' ); + _e( 'No plugins are currently available.' ); } } @@ -399,11 +458,17 @@ public function get_columns() { global $status; - return array( - 'cb' => ! in_array( $status, array( 'mustuse', 'dropins' ) ) ? '' : '', + $columns = array( + 'cb' => ! in_array( $status, array( 'mustuse', 'dropins' ), true ) ? '' : '', 'name' => __( 'Plugin' ), 'description' => __( 'Description' ), ); + + if ( $this->show_autoupdates ) { + $columns['auto-updates'] = __( 'Automatic Updates' ); + } + + return $columns; } /** @@ -429,36 +494,85 @@ switch ( $type ) { case 'all': - /* translators: %s: plugin count */ - $text = _nx( 'All (%s)', 'All (%s)', $count, 'plugins' ); + /* translators: %s: Number of plugins. */ + $text = _nx( + 'All (%s)', + 'All (%s)', + $count, + 'plugins' + ); break; case 'active': - /* translators: %s: plugin count */ - $text = _n( 'Active (%s)', 'Active (%s)', $count ); + /* translators: %s: Number of plugins. */ + $text = _n( + 'Active (%s)', + 'Active (%s)', + $count + ); break; case 'recently_activated': - /* translators: %s: plugin count */ - $text = _n( 'Recently Active (%s)', 'Recently Active (%s)', $count ); + /* translators: %s: Number of plugins. */ + $text = _n( + 'Recently Active (%s)', + 'Recently Active (%s)', + $count + ); break; case 'inactive': - /* translators: %s: plugin count */ - $text = _n( 'Inactive (%s)', 'Inactive (%s)', $count ); + /* translators: %s: Number of plugins. */ + $text = _n( + 'Inactive (%s)', + 'Inactive (%s)', + $count + ); break; case 'mustuse': - /* translators: %s: plugin count */ - $text = _n( 'Must-Use (%s)', 'Must-Use (%s)', $count ); + /* translators: %s: Number of plugins. */ + $text = _n( + 'Must-Use (%s)', + 'Must-Use (%s)', + $count + ); break; case 'dropins': - /* translators: %s: plugin count */ - $text = _n( 'Drop-in (%s)', 'Drop-ins (%s)', $count ); + /* translators: %s: Number of plugins. */ + $text = _n( + 'Drop-in (%s)', + 'Drop-ins (%s)', + $count + ); break; case 'paused': - /* translators: %s: plugin count */ - $text = _n( 'Paused (%s)', 'Paused (%s)', $count ); + /* translators: %s: Number of plugins. */ + $text = _n( + 'Paused (%s)', + 'Paused (%s)', + $count + ); break; case 'upgrade': - /* translators: %s: plugin count */ - $text = _n( 'Update Available (%s)', 'Update Available (%s)', $count ); + /* translators: %s: Number of plugins. */ + $text = _n( + 'Update Available (%s)', + 'Update Available (%s)', + $count + ); + break; + case 'auto-update-enabled': + /* translators: %s: Number of plugins. */ + $text = _n( + 'Auto-updates Enabled (%s)', + 'Auto-updates Enabled (%s)', + $count + ); + break; + case 'auto-update-disabled': + /* translators: %s: Number of plugins. */ + $text = _n( + 'Auto-updates Disabled (%s)', + 'Auto-updates Disabled (%s)', + $count + ); break; } @@ -484,11 +598,11 @@ $actions = array(); - if ( 'active' != $status ) { + if ( 'active' !== $status ) { $actions['activate-selected'] = $this->screen->in_admin( 'network' ) ? __( 'Network Activate' ) : __( 'Activate' ); } - if ( 'inactive' != $status && 'recent' != $status ) { + if ( 'inactive' !== $status && 'recent' !== $status ) { $actions['deactivate-selected'] = $this->screen->in_admin( 'network' ) ? __( 'Network Deactivate' ) : __( 'Deactivate' ); } @@ -496,9 +610,19 @@ if ( current_user_can( 'update_plugins' ) ) { $actions['update-selected'] = __( 'Update' ); } - if ( current_user_can( 'delete_plugins' ) && ( 'active' != $status ) ) { + + if ( current_user_can( 'delete_plugins' ) && ( 'active' !== $status ) ) { $actions['delete-selected'] = __( 'Delete' ); } + + if ( $this->show_autoupdates ) { + if ( 'auto-update-enabled' !== $status ) { + $actions['enable-auto-update-selected'] = __( 'Enable Auto-updates' ); + } + if ( 'auto-update-disabled' !== $status ) { + $actions['disable-auto-update-selected'] = __( 'Disable Auto-updates' ); + } + } } return $actions; @@ -511,7 +635,7 @@ public function bulk_actions( $which = '' ) { global $status; - if ( in_array( $status, array( 'mustuse', 'dropins' ) ) ) { + if ( in_array( $status, array( 'mustuse', 'dropins' ), true ) ) { return; } @@ -525,24 +649,24 @@ protected function extra_tablenav( $which ) { global $status; - if ( ! in_array( $status, array( 'recently_activated', 'mustuse', 'dropins' ) ) ) { + if ( ! in_array( $status, array( 'recently_activated', 'mustuse', 'dropins' ), true ) ) { return; } echo '
' . sprintf(
- /* translators: %s: mu-plugins directory name */
+ /* translators: %s: mu-plugins directory name. */
__( 'Files in the %s directory are executed automatically.' ),
'' . str_replace( ABSPATH, '/', WPMU_PLUGIN_DIR ) . '
'
) . '
' . sprintf(
- /* translators: %s: wp-content directory name */
- __( 'Drop-ins are advanced plugins in the %s directory that replace WordPress functionality when present.' ),
+ /* translators: %s: wp-content directory name. */
+ __( 'Drop-ins are single files, found in the %s directory, that replace or enhance WordPress features in ways that are not possible for traditional plugins.' ),
'' . str_replace( ABSPATH, '', WP_CONTENT_DIR ) . '
'
) . '
' . $dropins[ $plugin_file ][0] . '
'; - } elseif ( defined( $dropins[ $plugin_file ][1] ) && constant( $dropins[ $plugin_file ][1] ) ) { // Constant is true + } elseif ( defined( $dropins[ $plugin_file ][1] ) && constant( $dropins[ $plugin_file ][1] ) ) { // Constant is true. $is_active = true; $description = '' . $dropins[ $plugin_file ][0] . '
'; } else { $is_active = false; $description = '' . $dropins[ $plugin_file ][0] . ' define('" . $dropins[ $plugin_file ][1] . "', true);
",
'wp-config.php
'
@@ -641,17 +779,36 @@
if ( $screen->in_admin( 'network' ) ) {
if ( $is_active ) {
if ( current_user_can( 'manage_network_plugins' ) ) {
- /* translators: %s: plugin name */
- $actions['deactivate'] = '' . __( 'Network Deactivate' ) . '';
+ $actions['deactivate'] = sprintf(
+ '%s',
+ wp_nonce_url( 'plugins.php?action=deactivate&plugin=' . urlencode( $plugin_file ) . '&plugin_status=' . $context . '&paged=' . $page . '&s=' . $s, 'deactivate-plugin_' . $plugin_file ),
+ esc_attr( $plugin_id_attr ),
+ /* translators: %s: Plugin name. */
+ esc_attr( sprintf( _x( 'Network Deactivate %s', 'plugin' ), $plugin_data['Name'] ) ),
+ __( 'Network Deactivate' )
+ );
}
} else {
if ( current_user_can( 'manage_network_plugins' ) ) {
- /* translators: %s: plugin name */
- $actions['activate'] = '' . __( 'Network Activate' ) . '';
+ $actions['activate'] = sprintf(
+ '%s',
+ wp_nonce_url( 'plugins.php?action=activate&plugin=' . urlencode( $plugin_file ) . '&plugin_status=' . $context . '&paged=' . $page . '&s=' . $s, 'activate-plugin_' . $plugin_file ),
+ esc_attr( $plugin_id_attr ),
+ /* translators: %s: Plugin name. */
+ esc_attr( sprintf( _x( 'Network Activate %s', 'plugin' ), $plugin_data['Name'] ) ),
+ __( 'Network Activate' )
+ );
}
+
if ( current_user_can( 'delete_plugins' ) && ! is_plugin_active( $plugin_file ) ) {
- /* translators: %s: plugin name */
- $actions['delete'] = '' . __( 'Delete' ) . '';
+ $actions['delete'] = sprintf(
+ '%s',
+ wp_nonce_url( 'plugins.php?action=delete-selected&checked[]=' . urlencode( $plugin_file ) . '&plugin_status=' . $context . '&paged=' . $page . '&s=' . $s, 'bulk-plugins' ),
+ esc_attr( $plugin_id_attr ),
+ /* translators: %s: Plugin name. */
+ esc_attr( sprintf( _x( 'Delete %s', 'plugin' ), $plugin_data['Name'] ) ),
+ __( 'Delete' )
+ );
}
}
} else {
@@ -665,26 +822,51 @@
);
} elseif ( $is_active ) {
if ( current_user_can( 'deactivate_plugin', $plugin_file ) ) {
- /* translators: %s: plugin name */
- $actions['deactivate'] = '' . __( 'Deactivate' ) . '';
+ $actions['deactivate'] = sprintf(
+ '%s',
+ wp_nonce_url( 'plugins.php?action=deactivate&plugin=' . urlencode( $plugin_file ) . '&plugin_status=' . $context . '&paged=' . $page . '&s=' . $s, 'deactivate-plugin_' . $plugin_file ),
+ esc_attr( $plugin_id_attr ),
+ /* translators: %s: Plugin name. */
+ esc_attr( sprintf( _x( 'Deactivate %s', 'plugin' ), $plugin_data['Name'] ) ),
+ __( 'Deactivate' )
+ );
}
+
if ( current_user_can( 'resume_plugin', $plugin_file ) && is_plugin_paused( $plugin_file ) ) {
- /* translators: %s: plugin name */
- $actions['resume'] = '' . __( 'Resume' ) . '';
+ $actions['resume'] = sprintf(
+ '%s',
+ wp_nonce_url( 'plugins.php?action=resume&plugin=' . urlencode( $plugin_file ) . '&plugin_status=' . $context . '&paged=' . $page . '&s=' . $s, 'resume-plugin_' . $plugin_file ),
+ esc_attr( $plugin_id_attr ),
+ /* translators: %s: Plugin name. */
+ esc_attr( sprintf( _x( 'Resume %s', 'plugin' ), $plugin_data['Name'] ) ),
+ __( 'Resume' )
+ );
}
} else {
if ( current_user_can( 'activate_plugin', $plugin_file ) ) {
- /* translators: %s: plugin name */
- $actions['activate'] = '' . __( 'Activate' ) . '';
+ $actions['activate'] = sprintf(
+ '%s',
+ wp_nonce_url( 'plugins.php?action=activate&plugin=' . urlencode( $plugin_file ) . '&plugin_status=' . $context . '&paged=' . $page . '&s=' . $s, 'activate-plugin_' . $plugin_file ),
+ esc_attr( $plugin_id_attr ),
+ /* translators: %s: Plugin name. */
+ esc_attr( sprintf( _x( 'Activate %s', 'plugin' ), $plugin_data['Name'] ) ),
+ __( 'Activate' )
+ );
}
if ( ! is_multisite() && current_user_can( 'delete_plugins' ) ) {
- /* translators: %s: plugin name */
- $actions['delete'] = '' . __( 'Delete' ) . '';
+ $actions['delete'] = sprintf(
+ '%s',
+ wp_nonce_url( 'plugins.php?action=delete-selected&checked[]=' . urlencode( $plugin_file ) . '&plugin_status=' . $context . '&paged=' . $page . '&s=' . $s, 'bulk-plugins' ),
+ esc_attr( $plugin_id_attr ),
+ /* translators: %s: Plugin name. */
+ esc_attr( sprintf( _x( 'Delete %s', 'plugin' ), $plugin_data['Name'] ) ),
+ __( 'Delete' )
+ );
}
- } // end if $is_active
- } // end if $screen->in_admin( 'network' )
- } // end if $context
+ } // End if $is_active.
+ } // End if $screen->in_admin( 'network' ).
+ } // End if $context.
$actions = array_filter( $actions );
@@ -765,14 +947,19 @@
$compatible_php = is_php_version_compatible( $requires_php );
$class = $is_active ? 'active' : 'inactive';
$checkbox_id = 'checkbox_' . md5( $plugin_data['Name'] );
- if ( $restrict_network_active || $restrict_network_only || in_array( $status, array( 'mustuse', 'dropins' ) ) || ! $compatible_php ) {
+ if ( $restrict_network_active || $restrict_network_only || in_array( $status, array( 'mustuse', 'dropins' ), true ) || ! $compatible_php ) {
$checkbox = '';
} else {
- /* translators: %s: plugin name */
- $checkbox = "'
- . "";
+ $checkbox = sprintf(
+ '' .
+ '',
+ $checkbox_id,
+ /* translators: %s: Plugin name. */
+ sprintf( __( 'Select %s' ), $plugin_data['Name'] ),
+ esc_attr( $plugin_file )
+ );
}
- if ( 'dropins' != $context ) {
+ if ( 'dropins' !== $context ) {
$description = '
' . ( $plugin_data['Description'] ? $plugin_data['Description'] : ' ' ) . '
'; $plugin_name = $plugin_data['Name']; } @@ -787,7 +974,10 @@ $class .= ' paused'; } - $plugin_slug = isset( $plugin_data['slug'] ) ? $plugin_data['slug'] : sanitize_title( $plugin_name ); + if ( is_uninstallable_plugin( $plugin_file ) ) { + $class .= ' is-uninstallable'; + } + printf( '