Index: trunk/src/wp-admin/includes/class-wp-ms-themes-list-table.php =================================================================== --- trunk/src/wp-admin/includes/class-wp-ms-themes-list-table.php (revision 47808) +++ trunk/src/wp-admin/includes/class-wp-ms-themes-list-table.php (revision 47835) @@ -24,4 +24,13 @@ /** + * 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. * @@ -46,5 +55,5 @@ $status = isset( $_REQUEST['theme_status'] ) ? $_REQUEST['theme_status'] : 'all'; - if ( ! in_array( $status, array( 'all', 'enabled', 'disabled', 'upgrade', 'search', 'broken' ), true ) ) { + if ( ! in_array( $status, array( 'all', 'enabled', 'disabled', 'upgrade', 'search', 'broken', 'auto-update-enabled', 'auto-update-disabled' ), true ) ) { $status = 'all'; } @@ -57,4 +66,7 @@ $this->site_id = isset( $_REQUEST['id'] ) ? intval( $_REQUEST['id'] ) : 0; } + + $this->show_autoupdates = wp_is_auto_update_enabled_for_type( 'theme' ) && + ! $this->is_site_themes && current_user_can( 'update_themes' ); } @@ -108,4 +120,11 @@ ); + if ( $this->show_autoupdates ) { + $auto_updates = (array) get_site_option( 'auto_update_themes', array() ); + + $themes['auto-update-enabled'] = array(); + $themes['auto-update-disabled'] = array(); + } + if ( $this->is_site_themes ) { $themes_per_page = $this->get_items_per_page( 'site_themes_network_per_page' ); @@ -132,4 +151,12 @@ $filter = $theme->is_allowed( $allowed_where, $this->site_id ) ? 'enabled' : 'disabled'; $themes[ $filter ][ $key ] = $themes['all'][ $key ]; + + if ( $this->show_autoupdates ) { + if ( in_array( $key, $auto_updates, true ) ) { + $themes['auto-update-enabled'][ $key ] = $themes['all'][ $key ]; + } else { + $themes['auto-update-disabled'][ $key ] = $themes['all'][ $key ]; + } + } } @@ -258,9 +285,15 @@ */ public function get_columns() { - return array( + $columns = array( 'cb' => '', 'name' => __( 'Theme' ), 'description' => __( 'Description' ), ); + + if ( $this->show_autoupdates ) { + $columns['auto-updates'] = __( 'Automatic Updates' ); + } + + return $columns; } @@ -345,4 +378,20 @@ ); break; + case 'auto-update-enabled': + /* translators: %s: Number of themes. */ + $text = _n( + 'Auto-updates Enabled (%s)', + 'Auto-updates Enabled (%s)', + $count + ); + break; + case 'auto-update-disabled': + /* translators: %s: Number of themes. */ + $text = _n( + 'Auto-updates Disabled (%s)', + 'Auto-updates Disabled (%s)', + $count + ); + break; } @@ -389,4 +438,15 @@ } } + + 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; } @@ -641,4 +701,68 @@ /** + * Handles the auto-updates column output. + * + * @since 5.5.0 + * + * @global string $status + * @global int $page + * + * @param WP_Theme $theme The current WP_Theme object. + */ + public function column_autoupdates( $theme ) { + global $status, $page; + + static $auto_updates, $available_updates; + + if ( ! $auto_updates ) { + $auto_updates = (array) get_site_option( 'auto_update_themes', array() ); + } + if ( ! $available_updates ) { + $available_updates = get_site_transient( 'update_themes' ); + } + + $stylesheet = $theme->get_stylesheet(); + + if ( in_array( $stylesheet, $auto_updates, true ) ) { + $text = __( 'Disable auto-updates' ); + $action = 'disable'; + $time_class = ''; + } else { + $text = __( 'Enable auto-updates' ); + $action = 'enable'; + $time_class = ' hidden'; + } + + $query_args = array( + 'action' => "{$action}-auto-update", + 'theme' => $stylesheet, + 'paged' => $page, + 'theme_status' => $status, + ); + + $url = add_query_arg( $query_args, 'themes.php' ); + + printf( + '', + wp_nonce_url( $url, 'updates' ), + $action + ); + + echo ''; + echo '' . $text . ''; + echo ''; + + $available_updates = get_site_transient( 'update_themes' ); + if ( isset( $available_updates->response[ $stylesheet ] ) ) { + printf( + '