balmet.com

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

class-wp-ms-themes-list-table.php (27380B)


      1 <?php
      2 /**
      3  * List Table API: WP_MS_Themes_List_Table class
      4  *
      5  * @package WordPress
      6  * @subpackage Administration
      7  * @since 3.1.0
      8  */
      9 
     10 /**
     11  * Core class used to implement displaying themes in a list table for the network admin.
     12  *
     13  * @since 3.1.0
     14  * @access private
     15  *
     16  * @see WP_List_Table
     17  */
     18 class WP_MS_Themes_List_Table extends WP_List_Table {
     19 
     20 	public $site_id;
     21 	public $is_site_themes;
     22 
     23 	private $has_items;
     24 
     25 	/**
     26 	 * Whether to show the auto-updates UI.
     27 	 *
     28 	 * @since 5.5.0
     29 	 *
     30 	 * @var bool True if auto-updates UI is to be shown, false otherwise.
     31 	 */
     32 	protected $show_autoupdates = true;
     33 
     34 	/**
     35 	 * Constructor.
     36 	 *
     37 	 * @since 3.1.0
     38 	 *
     39 	 * @see WP_List_Table::__construct() for more information on default arguments.
     40 	 *
     41 	 * @global string $status
     42 	 * @global int    $page
     43 	 *
     44 	 * @param array $args An associative array of arguments.
     45 	 */
     46 	public function __construct( $args = array() ) {
     47 		global $status, $page;
     48 
     49 		parent::__construct(
     50 			array(
     51 				'plural' => 'themes',
     52 				'screen' => isset( $args['screen'] ) ? $args['screen'] : null,
     53 			)
     54 		);
     55 
     56 		$status = isset( $_REQUEST['theme_status'] ) ? $_REQUEST['theme_status'] : 'all';
     57 		if ( ! in_array( $status, array( 'all', 'enabled', 'disabled', 'upgrade', 'search', 'broken', 'auto-update-enabled', 'auto-update-disabled' ), true ) ) {
     58 			$status = 'all';
     59 		}
     60 
     61 		$page = $this->get_pagenum();
     62 
     63 		$this->is_site_themes = ( 'site-themes-network' === $this->screen->id ) ? true : false;
     64 
     65 		if ( $this->is_site_themes ) {
     66 			$this->site_id = isset( $_REQUEST['id'] ) ? (int) $_REQUEST['id'] : 0;
     67 		}
     68 
     69 		$this->show_autoupdates = wp_is_auto_update_enabled_for_type( 'theme' ) &&
     70 			! $this->is_site_themes && current_user_can( 'update_themes' );
     71 	}
     72 
     73 	/**
     74 	 * @return array
     75 	 */
     76 	protected function get_table_classes() {
     77 		// @todo Remove and add CSS for .themes.
     78 		return array( 'widefat', 'plugins' );
     79 	}
     80 
     81 	/**
     82 	 * @return bool
     83 	 */
     84 	public function ajax_user_can() {
     85 		if ( $this->is_site_themes ) {
     86 			return current_user_can( 'manage_sites' );
     87 		} else {
     88 			return current_user_can( 'manage_network_themes' );
     89 		}
     90 	}
     91 
     92 	/**
     93 	 * @global string $status
     94 	 * @global array $totals
     95 	 * @global int $page
     96 	 * @global string $orderby
     97 	 * @global string $order
     98 	 * @global string $s
     99 	 */
    100 	public function prepare_items() {
    101 		global $status, $totals, $page, $orderby, $order, $s;
    102 
    103 		wp_reset_vars( array( 'orderby', 'order', 's' ) );
    104 
    105 		$themes = array(
    106 			/**
    107 			 * Filters the full array of WP_Theme objects to list in the Multisite
    108 			 * themes list table.
    109 			 *
    110 			 * @since 3.1.0
    111 			 *
    112 			 * @param WP_Theme[] $all Array of WP_Theme objects to display in the list table.
    113 			 */
    114 			'all'      => apply_filters( 'all_themes', wp_get_themes() ),
    115 			'search'   => array(),
    116 			'enabled'  => array(),
    117 			'disabled' => array(),
    118 			'upgrade'  => array(),
    119 			'broken'   => $this->is_site_themes ? array() : wp_get_themes( array( 'errors' => true ) ),
    120 		);
    121 
    122 		if ( $this->show_autoupdates ) {
    123 			$auto_updates = (array) get_site_option( 'auto_update_themes', array() );
    124 
    125 			$themes['auto-update-enabled']  = array();
    126 			$themes['auto-update-disabled'] = array();
    127 		}
    128 
    129 		if ( $this->is_site_themes ) {
    130 			$themes_per_page = $this->get_items_per_page( 'site_themes_network_per_page' );
    131 			$allowed_where   = 'site';
    132 		} else {
    133 			$themes_per_page = $this->get_items_per_page( 'themes_network_per_page' );
    134 			$allowed_where   = 'network';
    135 		}
    136 
    137 		$current      = get_site_transient( 'update_themes' );
    138 		$maybe_update = current_user_can( 'update_themes' ) && ! $this->is_site_themes && $current;
    139 
    140 		foreach ( (array) $themes['all'] as $key => $theme ) {
    141 			if ( $this->is_site_themes && $theme->is_allowed( 'network' ) ) {
    142 				unset( $themes['all'][ $key ] );
    143 				continue;
    144 			}
    145 
    146 			if ( $maybe_update && isset( $current->response[ $key ] ) ) {
    147 				$themes['all'][ $key ]->update = true;
    148 				$themes['upgrade'][ $key ]     = $themes['all'][ $key ];
    149 			}
    150 
    151 			$filter                    = $theme->is_allowed( $allowed_where, $this->site_id ) ? 'enabled' : 'disabled';
    152 			$themes[ $filter ][ $key ] = $themes['all'][ $key ];
    153 
    154 			$theme_data = array(
    155 				'update_supported' => isset( $theme->update_supported ) ? $theme->update_supported : true,
    156 			);
    157 
    158 			// Extra info if known. array_merge() ensures $theme_data has precedence if keys collide.
    159 			if ( isset( $current->response[ $key ] ) ) {
    160 				$theme_data = array_merge( (array) $current->response[ $key ], $theme_data );
    161 			} elseif ( isset( $current->no_update[ $key ] ) ) {
    162 				$theme_data = array_merge( (array) $current->no_update[ $key ], $theme_data );
    163 			} else {
    164 				$theme_data['update_supported'] = false;
    165 			}
    166 
    167 			$theme->update_supported = $theme_data['update_supported'];
    168 
    169 			/*
    170 			 * Create the expected payload for the auto_update_theme filter, this is the same data
    171 			 * as contained within $updates or $no_updates but used when the Theme is not known.
    172 			 */
    173 			$filter_payload = array(
    174 				'theme'        => $key,
    175 				'new_version'  => '',
    176 				'url'          => '',
    177 				'package'      => '',
    178 				'requires'     => '',
    179 				'requires_php' => '',
    180 			);
    181 
    182 			$filter_payload = (object) array_merge( $filter_payload, array_intersect_key( $theme_data, $filter_payload ) );
    183 
    184 			$auto_update_forced = wp_is_auto_update_forced_for_item( 'theme', null, $filter_payload );
    185 
    186 			if ( ! is_null( $auto_update_forced ) ) {
    187 				$theme->auto_update_forced = $auto_update_forced;
    188 			}
    189 
    190 			if ( $this->show_autoupdates ) {
    191 				$enabled = in_array( $key, $auto_updates, true ) && $theme->update_supported;
    192 				if ( isset( $theme->auto_update_forced ) ) {
    193 					$enabled = (bool) $theme->auto_update_forced;
    194 				}
    195 
    196 				if ( $enabled ) {
    197 					$themes['auto-update-enabled'][ $key ] = $theme;
    198 				} else {
    199 					$themes['auto-update-disabled'][ $key ] = $theme;
    200 				}
    201 			}
    202 		}
    203 
    204 		if ( $s ) {
    205 			$status           = 'search';
    206 			$themes['search'] = array_filter( array_merge( $themes['all'], $themes['broken'] ), array( $this, '_search_callback' ) );
    207 		}
    208 
    209 		$totals    = array();
    210 		$js_themes = array();
    211 		foreach ( $themes as $type => $list ) {
    212 			$totals[ $type ]    = count( $list );
    213 			$js_themes[ $type ] = array_keys( $list );
    214 		}
    215 
    216 		if ( empty( $themes[ $status ] ) && ! in_array( $status, array( 'all', 'search' ), true ) ) {
    217 			$status = 'all';
    218 		}
    219 
    220 		$this->items = $themes[ $status ];
    221 		WP_Theme::sort_by_name( $this->items );
    222 
    223 		$this->has_items = ! empty( $themes['all'] );
    224 		$total_this_page = $totals[ $status ];
    225 
    226 		wp_localize_script(
    227 			'updates',
    228 			'_wpUpdatesItemCounts',
    229 			array(
    230 				'themes' => $js_themes,
    231 				'totals' => wp_get_update_data(),
    232 			)
    233 		);
    234 
    235 		if ( $orderby ) {
    236 			$orderby = ucfirst( $orderby );
    237 			$order   = strtoupper( $order );
    238 
    239 			if ( 'Name' === $orderby ) {
    240 				if ( 'ASC' === $order ) {
    241 					$this->items = array_reverse( $this->items );
    242 				}
    243 			} else {
    244 				uasort( $this->items, array( $this, '_order_callback' ) );
    245 			}
    246 		}
    247 
    248 		$start = ( $page - 1 ) * $themes_per_page;
    249 
    250 		if ( $total_this_page > $themes_per_page ) {
    251 			$this->items = array_slice( $this->items, $start, $themes_per_page, true );
    252 		}
    253 
    254 		$this->set_pagination_args(
    255 			array(
    256 				'total_items' => $total_this_page,
    257 				'per_page'    => $themes_per_page,
    258 			)
    259 		);
    260 	}
    261 
    262 	/**
    263 	 * @param WP_Theme $theme
    264 	 * @return bool
    265 	 */
    266 	public function _search_callback( $theme ) {
    267 		static $term = null;
    268 		if ( is_null( $term ) ) {
    269 			$term = wp_unslash( $_REQUEST['s'] );
    270 		}
    271 
    272 		foreach ( array( 'Name', 'Description', 'Author', 'Author', 'AuthorURI' ) as $field ) {
    273 			// Don't mark up; Do translate.
    274 			if ( false !== stripos( $theme->display( $field, false, true ), $term ) ) {
    275 				return true;
    276 			}
    277 		}
    278 
    279 		if ( false !== stripos( $theme->get_stylesheet(), $term ) ) {
    280 			return true;
    281 		}
    282 
    283 		if ( false !== stripos( $theme->get_template(), $term ) ) {
    284 			return true;
    285 		}
    286 
    287 		return false;
    288 	}
    289 
    290 	// Not used by any core columns.
    291 	/**
    292 	 * @global string $orderby
    293 	 * @global string $order
    294 	 * @param array $theme_a
    295 	 * @param array $theme_b
    296 	 * @return int
    297 	 */
    298 	public function _order_callback( $theme_a, $theme_b ) {
    299 		global $orderby, $order;
    300 
    301 		$a = $theme_a[ $orderby ];
    302 		$b = $theme_b[ $orderby ];
    303 
    304 		if ( $a === $b ) {
    305 			return 0;
    306 		}
    307 
    308 		if ( 'DESC' === $order ) {
    309 			return ( $a < $b ) ? 1 : -1;
    310 		} else {
    311 			return ( $a < $b ) ? -1 : 1;
    312 		}
    313 	}
    314 
    315 	/**
    316 	 */
    317 	public function no_items() {
    318 		if ( $this->has_items ) {
    319 			_e( 'No themes found.' );
    320 		} else {
    321 			_e( 'No themes are currently available.' );
    322 		}
    323 	}
    324 
    325 	/**
    326 	 * @return array
    327 	 */
    328 	public function get_columns() {
    329 		$columns = array(
    330 			'cb'          => '<input type="checkbox" />',
    331 			'name'        => __( 'Theme' ),
    332 			'description' => __( 'Description' ),
    333 		);
    334 
    335 		if ( $this->show_autoupdates ) {
    336 			$columns['auto-updates'] = __( 'Automatic Updates' );
    337 		}
    338 
    339 		return $columns;
    340 	}
    341 
    342 	/**
    343 	 * @return array
    344 	 */
    345 	protected function get_sortable_columns() {
    346 		return array(
    347 			'name' => 'name',
    348 		);
    349 	}
    350 
    351 	/**
    352 	 * Gets the name of the primary column.
    353 	 *
    354 	 * @since 4.3.0
    355 	 *
    356 	 * @return string Unalterable name of the primary column name, in this case, 'name'.
    357 	 */
    358 	protected function get_primary_column_name() {
    359 		return 'name';
    360 	}
    361 
    362 	/**
    363 	 * @global array $totals
    364 	 * @global string $status
    365 	 * @return array
    366 	 */
    367 	protected function get_views() {
    368 		global $totals, $status;
    369 
    370 		$status_links = array();
    371 		foreach ( $totals as $type => $count ) {
    372 			if ( ! $count ) {
    373 				continue;
    374 			}
    375 
    376 			switch ( $type ) {
    377 				case 'all':
    378 					/* translators: %s: Number of themes. */
    379 					$text = _nx(
    380 						'All <span class="count">(%s)</span>',
    381 						'All <span class="count">(%s)</span>',
    382 						$count,
    383 						'themes'
    384 					);
    385 					break;
    386 				case 'enabled':
    387 					/* translators: %s: Number of themes. */
    388 					$text = _nx(
    389 						'Enabled <span class="count">(%s)</span>',
    390 						'Enabled <span class="count">(%s)</span>',
    391 						$count,
    392 						'themes'
    393 					);
    394 					break;
    395 				case 'disabled':
    396 					/* translators: %s: Number of themes. */
    397 					$text = _nx(
    398 						'Disabled <span class="count">(%s)</span>',
    399 						'Disabled <span class="count">(%s)</span>',
    400 						$count,
    401 						'themes'
    402 					);
    403 					break;
    404 				case 'upgrade':
    405 					/* translators: %s: Number of themes. */
    406 					$text = _nx(
    407 						'Update Available <span class="count">(%s)</span>',
    408 						'Update Available <span class="count">(%s)</span>',
    409 						$count,
    410 						'themes'
    411 					);
    412 					break;
    413 				case 'broken':
    414 					/* translators: %s: Number of themes. */
    415 					$text = _nx(
    416 						'Broken <span class="count">(%s)</span>',
    417 						'Broken <span class="count">(%s)</span>',
    418 						$count,
    419 						'themes'
    420 					);
    421 					break;
    422 				case 'auto-update-enabled':
    423 					/* translators: %s: Number of themes. */
    424 					$text = _n(
    425 						'Auto-updates Enabled <span class="count">(%s)</span>',
    426 						'Auto-updates Enabled <span class="count">(%s)</span>',
    427 						$count
    428 					);
    429 					break;
    430 				case 'auto-update-disabled':
    431 					/* translators: %s: Number of themes. */
    432 					$text = _n(
    433 						'Auto-updates Disabled <span class="count">(%s)</span>',
    434 						'Auto-updates Disabled <span class="count">(%s)</span>',
    435 						$count
    436 					);
    437 					break;
    438 			}
    439 
    440 			if ( $this->is_site_themes ) {
    441 				$url = 'site-themes.php?id=' . $this->site_id;
    442 			} else {
    443 				$url = 'themes.php';
    444 			}
    445 
    446 			if ( 'search' !== $type ) {
    447 				$status_links[ $type ] = sprintf(
    448 					"<a href='%s'%s>%s</a>",
    449 					esc_url( add_query_arg( 'theme_status', $type, $url ) ),
    450 					( $type === $status ) ? ' class="current" aria-current="page"' : '',
    451 					sprintf( $text, number_format_i18n( $count ) )
    452 				);
    453 			}
    454 		}
    455 
    456 		return $status_links;
    457 	}
    458 
    459 	/**
    460 	 * @global string $status
    461 	 *
    462 	 * @return array
    463 	 */
    464 	protected function get_bulk_actions() {
    465 		global $status;
    466 
    467 		$actions = array();
    468 		if ( 'enabled' !== $status ) {
    469 			$actions['enable-selected'] = $this->is_site_themes ? __( 'Enable' ) : __( 'Network Enable' );
    470 		}
    471 		if ( 'disabled' !== $status ) {
    472 			$actions['disable-selected'] = $this->is_site_themes ? __( 'Disable' ) : __( 'Network Disable' );
    473 		}
    474 		if ( ! $this->is_site_themes ) {
    475 			if ( current_user_can( 'update_themes' ) ) {
    476 				$actions['update-selected'] = __( 'Update' );
    477 			}
    478 			if ( current_user_can( 'delete_themes' ) ) {
    479 				$actions['delete-selected'] = __( 'Delete' );
    480 			}
    481 		}
    482 
    483 		if ( $this->show_autoupdates ) {
    484 			if ( 'auto-update-enabled' !== $status ) {
    485 				$actions['enable-auto-update-selected'] = __( 'Enable Auto-updates' );
    486 			}
    487 
    488 			if ( 'auto-update-disabled' !== $status ) {
    489 				$actions['disable-auto-update-selected'] = __( 'Disable Auto-updates' );
    490 			}
    491 		}
    492 
    493 		return $actions;
    494 	}
    495 
    496 	/**
    497 	 */
    498 	public function display_rows() {
    499 		foreach ( $this->items as $theme ) {
    500 			$this->single_row( $theme );
    501 		}
    502 	}
    503 
    504 	/**
    505 	 * Handles the checkbox column output.
    506 	 *
    507 	 * @since 4.3.0
    508 	 *
    509 	 * @param WP_Theme $theme The current WP_Theme object.
    510 	 */
    511 	public function column_cb( $theme ) {
    512 		$checkbox_id = 'checkbox_' . md5( $theme->get( 'Name' ) );
    513 		?>
    514 		<input type="checkbox" name="checked[]" value="<?php echo esc_attr( $theme->get_stylesheet() ); ?>" id="<?php echo $checkbox_id; ?>" />
    515 		<label class="screen-reader-text" for="<?php echo $checkbox_id; ?>" ><?php _e( 'Select' ); ?>  <?php echo $theme->display( 'Name' ); ?></label>
    516 		<?php
    517 	}
    518 
    519 	/**
    520 	 * Handles the name column output.
    521 	 *
    522 	 * @since 4.3.0
    523 	 *
    524 	 * @global string $status
    525 	 * @global int    $page
    526 	 * @global string $s
    527 	 *
    528 	 * @param WP_Theme $theme The current WP_Theme object.
    529 	 */
    530 	public function column_name( $theme ) {
    531 		global $status, $page, $s;
    532 
    533 		$context = $status;
    534 
    535 		if ( $this->is_site_themes ) {
    536 			$url     = "site-themes.php?id={$this->site_id}&amp;";
    537 			$allowed = $theme->is_allowed( 'site', $this->site_id );
    538 		} else {
    539 			$url     = 'themes.php?';
    540 			$allowed = $theme->is_allowed( 'network' );
    541 		}
    542 
    543 		// Pre-order.
    544 		$actions = array(
    545 			'enable'  => '',
    546 			'disable' => '',
    547 			'delete'  => '',
    548 		);
    549 
    550 		$stylesheet = $theme->get_stylesheet();
    551 		$theme_key  = urlencode( $stylesheet );
    552 
    553 		if ( ! $allowed ) {
    554 			if ( ! $theme->errors() ) {
    555 				$url = add_query_arg(
    556 					array(
    557 						'action' => 'enable',
    558 						'theme'  => $theme_key,
    559 						'paged'  => $page,
    560 						's'      => $s,
    561 					),
    562 					$url
    563 				);
    564 
    565 				if ( $this->is_site_themes ) {
    566 					/* translators: %s: Theme name. */
    567 					$aria_label = sprintf( __( 'Enable %s' ), $theme->display( 'Name' ) );
    568 				} else {
    569 					/* translators: %s: Theme name. */
    570 					$aria_label = sprintf( __( 'Network Enable %s' ), $theme->display( 'Name' ) );
    571 				}
    572 
    573 				$actions['enable'] = sprintf(
    574 					'<a href="%s" class="edit" aria-label="%s">%s</a>',
    575 					esc_url( wp_nonce_url( $url, 'enable-theme_' . $stylesheet ) ),
    576 					esc_attr( $aria_label ),
    577 					( $this->is_site_themes ? __( 'Enable' ) : __( 'Network Enable' ) )
    578 				);
    579 			}
    580 		} else {
    581 			$url = add_query_arg(
    582 				array(
    583 					'action' => 'disable',
    584 					'theme'  => $theme_key,
    585 					'paged'  => $page,
    586 					's'      => $s,
    587 				),
    588 				$url
    589 			);
    590 
    591 			if ( $this->is_site_themes ) {
    592 				/* translators: %s: Theme name. */
    593 				$aria_label = sprintf( __( 'Disable %s' ), $theme->display( 'Name' ) );
    594 			} else {
    595 				/* translators: %s: Theme name. */
    596 				$aria_label = sprintf( __( 'Network Disable %s' ), $theme->display( 'Name' ) );
    597 			}
    598 
    599 			$actions['disable'] = sprintf(
    600 				'<a href="%s" aria-label="%s">%s</a>',
    601 				esc_url( wp_nonce_url( $url, 'disable-theme_' . $stylesheet ) ),
    602 				esc_attr( $aria_label ),
    603 				( $this->is_site_themes ? __( 'Disable' ) : __( 'Network Disable' ) )
    604 			);
    605 		}
    606 
    607 		if ( ! $allowed && ! $this->is_site_themes
    608 			&& current_user_can( 'delete_themes' )
    609 			&& get_option( 'stylesheet' ) !== $stylesheet
    610 			&& get_option( 'template' ) !== $stylesheet
    611 		) {
    612 			$url = add_query_arg(
    613 				array(
    614 					'action'       => 'delete-selected',
    615 					'checked[]'    => $theme_key,
    616 					'theme_status' => $context,
    617 					'paged'        => $page,
    618 					's'            => $s,
    619 				),
    620 				'themes.php'
    621 			);
    622 
    623 			/* translators: %s: Theme name. */
    624 			$aria_label = sprintf( _x( 'Delete %s', 'theme' ), $theme->display( 'Name' ) );
    625 
    626 			$actions['delete'] = sprintf(
    627 				'<a href="%s" class="delete" aria-label="%s">%s</a>',
    628 				esc_url( wp_nonce_url( $url, 'bulk-themes' ) ),
    629 				esc_attr( $aria_label ),
    630 				__( 'Delete' )
    631 			);
    632 		}
    633 		/**
    634 		 * Filters the action links displayed for each theme in the Multisite
    635 		 * themes list table.
    636 		 *
    637 		 * The action links displayed are determined by the theme's status, and
    638 		 * which Multisite themes list table is being displayed - the Network
    639 		 * themes list table (themes.php), which displays all installed themes,
    640 		 * or the Site themes list table (site-themes.php), which displays the
    641 		 * non-network enabled themes when editing a site in the Network admin.
    642 		 *
    643 		 * The default action links for the Network themes list table include
    644 		 * 'Network Enable', 'Network Disable', and 'Delete'.
    645 		 *
    646 		 * The default action links for the Site themes list table include
    647 		 * 'Enable', and 'Disable'.
    648 		 *
    649 		 * @since 2.8.0
    650 		 *
    651 		 * @param string[] $actions An array of action links.
    652 		 * @param WP_Theme $theme   The current WP_Theme object.
    653 		 * @param string   $context Status of the theme, one of 'all', 'enabled', or 'disabled'.
    654 		 */
    655 		$actions = apply_filters( 'theme_action_links', array_filter( $actions ), $theme, $context );
    656 
    657 		/**
    658 		 * Filters the action links of a specific theme in the Multisite themes
    659 		 * list table.
    660 		 *
    661 		 * The dynamic portion of the hook name, `$stylesheet`, refers to the
    662 		 * directory name of the theme, which in most cases is synonymous
    663 		 * with the template name.
    664 		 *
    665 		 * @since 3.1.0
    666 		 *
    667 		 * @param string[] $actions An array of action links.
    668 		 * @param WP_Theme $theme   The current WP_Theme object.
    669 		 * @param string   $context Status of the theme, one of 'all', 'enabled', or 'disabled'.
    670 		 */
    671 		$actions = apply_filters( "theme_action_links_{$stylesheet}", $actions, $theme, $context );
    672 
    673 		echo $this->row_actions( $actions, true );
    674 	}
    675 
    676 	/**
    677 	 * Handles the description column output.
    678 	 *
    679 	 * @since 4.3.0
    680 	 *
    681 	 * @global string $status
    682 	 * @global array  $totals
    683 	 *
    684 	 * @param WP_Theme $theme The current WP_Theme object.
    685 	 */
    686 	public function column_description( $theme ) {
    687 		global $status, $totals;
    688 
    689 		if ( $theme->errors() ) {
    690 			$pre = 'broken' === $status ? __( 'Broken Theme:' ) . ' ' : '';
    691 			echo '<p><strong class="error-message">' . $pre . $theme->errors()->get_error_message() . '</strong></p>';
    692 		}
    693 
    694 		if ( $this->is_site_themes ) {
    695 			$allowed = $theme->is_allowed( 'site', $this->site_id );
    696 		} else {
    697 			$allowed = $theme->is_allowed( 'network' );
    698 		}
    699 
    700 		$class = ! $allowed ? 'inactive' : 'active';
    701 		if ( ! empty( $totals['upgrade'] ) && ! empty( $theme->update ) ) {
    702 			$class .= ' update';
    703 		}
    704 
    705 		echo "<div class='theme-description'><p>" . $theme->display( 'Description' ) . "</p></div>
    706 			<div class='$class second theme-version-author-uri'>";
    707 
    708 		$stylesheet = $theme->get_stylesheet();
    709 		$theme_meta = array();
    710 
    711 		if ( $theme->get( 'Version' ) ) {
    712 			/* translators: %s: Theme version. */
    713 			$theme_meta[] = sprintf( __( 'Version %s' ), $theme->display( 'Version' ) );
    714 		}
    715 
    716 		/* translators: %s: Theme author. */
    717 		$theme_meta[] = sprintf( __( 'By %s' ), $theme->display( 'Author' ) );
    718 
    719 		if ( $theme->get( 'ThemeURI' ) ) {
    720 			/* translators: %s: Theme name. */
    721 			$aria_label = sprintf( __( 'Visit %s homepage' ), $theme->display( 'Name' ) );
    722 
    723 			$theme_meta[] = sprintf(
    724 				'<a href="%s" aria-label="%s">%s</a>',
    725 				$theme->display( 'ThemeURI' ),
    726 				esc_attr( $aria_label ),
    727 				__( 'Visit Theme Site' )
    728 			);
    729 		}
    730 
    731 		if ( $theme->parent() ) {
    732 			$theme_meta[] = sprintf(
    733 				/* translators: %s: Theme name. */
    734 				__( 'Child theme of %s' ),
    735 				'<strong>' . $theme->parent()->display( 'Name' ) . '</strong>'
    736 			);
    737 		}
    738 
    739 		/**
    740 		 * Filters the array of row meta for each theme in the Multisite themes
    741 		 * list table.
    742 		 *
    743 		 * @since 3.1.0
    744 		 *
    745 		 * @param string[] $theme_meta An array of the theme's metadata, including
    746 		 *                             the version, author, and theme URI.
    747 		 * @param string   $stylesheet Directory name of the theme.
    748 		 * @param WP_Theme $theme      WP_Theme object.
    749 		 * @param string   $status     Status of the theme.
    750 		 */
    751 		$theme_meta = apply_filters( 'theme_row_meta', $theme_meta, $stylesheet, $theme, $status );
    752 
    753 		echo implode( ' | ', $theme_meta );
    754 
    755 		echo '</div>';
    756 	}
    757 
    758 	/**
    759 	 * Handles the auto-updates column output.
    760 	 *
    761 	 * @since 5.5.0
    762 	 *
    763 	 * @global string $status
    764 	 * @global int  $page
    765 	 *
    766 	 * @param WP_Theme $theme The current WP_Theme object.
    767 	 */
    768 	public function column_autoupdates( $theme ) {
    769 		global $status, $page;
    770 
    771 		static $auto_updates, $available_updates;
    772 
    773 		if ( ! $auto_updates ) {
    774 			$auto_updates = (array) get_site_option( 'auto_update_themes', array() );
    775 		}
    776 		if ( ! $available_updates ) {
    777 			$available_updates = get_site_transient( 'update_themes' );
    778 		}
    779 
    780 		$stylesheet = $theme->get_stylesheet();
    781 
    782 		if ( isset( $theme->auto_update_forced ) ) {
    783 			if ( $theme->auto_update_forced ) {
    784 				// Forced on.
    785 				$text = __( 'Auto-updates enabled' );
    786 			} else {
    787 				$text = __( 'Auto-updates disabled' );
    788 			}
    789 			$action     = 'unavailable';
    790 			$time_class = ' hidden';
    791 		} elseif ( empty( $theme->update_supported ) ) {
    792 			$text       = '';
    793 			$action     = 'unavailable';
    794 			$time_class = ' hidden';
    795 		} elseif ( in_array( $stylesheet, $auto_updates, true ) ) {
    796 			$text       = __( 'Disable auto-updates' );
    797 			$action     = 'disable';
    798 			$time_class = '';
    799 		} else {
    800 			$text       = __( 'Enable auto-updates' );
    801 			$action     = 'enable';
    802 			$time_class = ' hidden';
    803 		}
    804 
    805 		$query_args = array(
    806 			'action'       => "{$action}-auto-update",
    807 			'theme'        => $stylesheet,
    808 			'paged'        => $page,
    809 			'theme_status' => $status,
    810 		);
    811 
    812 		$url = add_query_arg( $query_args, 'themes.php' );
    813 
    814 		if ( 'unavailable' === $action ) {
    815 			$html[] = '<span class="label">' . $text . '</span>';
    816 		} else {
    817 			$html[] = sprintf(
    818 				'<a href="%s" class="toggle-auto-update aria-button-if-js" data-wp-action="%s">',
    819 				wp_nonce_url( $url, 'updates' ),
    820 				$action
    821 			);
    822 
    823 			$html[] = '<span class="dashicons dashicons-update spin hidden" aria-hidden="true"></span>';
    824 			$html[] = '<span class="label">' . $text . '</span>';
    825 			$html[] = '</a>';
    826 
    827 		}
    828 
    829 		if ( isset( $available_updates->response[ $stylesheet ] ) ) {
    830 			$html[] = sprintf(
    831 				'<div class="auto-update-time%s">%s</div>',
    832 				$time_class,
    833 				wp_get_auto_update_message()
    834 			);
    835 		}
    836 
    837 		$html = implode( '', $html );
    838 
    839 		/**
    840 		 * Filters the HTML of the auto-updates setting for each theme in the Themes list table.
    841 		 *
    842 		 * @since 5.5.0
    843 		 *
    844 		 * @param string   $html       The HTML for theme's auto-update setting, including
    845 		 *                             toggle auto-update action link and time to next update.
    846 		 * @param string   $stylesheet Directory name of the theme.
    847 		 * @param WP_Theme $theme      WP_Theme object.
    848 		 */
    849 		echo apply_filters( 'theme_auto_update_setting_html', $html, $stylesheet, $theme );
    850 
    851 		echo '<div class="notice notice-error notice-alt inline hidden"><p></p></div>';
    852 	}
    853 
    854 	/**
    855 	 * Handles default column output.
    856 	 *
    857 	 * @since 4.3.0
    858 	 *
    859 	 * @param WP_Theme $theme       The current WP_Theme object.
    860 	 * @param string   $column_name The current column name.
    861 	 */
    862 	public function column_default( $theme, $column_name ) {
    863 		$stylesheet = $theme->get_stylesheet();
    864 
    865 		/**
    866 		 * Fires inside each custom column of the Multisite themes list table.
    867 		 *
    868 		 * @since 3.1.0
    869 		 *
    870 		 * @param string   $column_name Name of the column.
    871 		 * @param string   $stylesheet  Directory name of the theme.
    872 		 * @param WP_Theme $theme       Current WP_Theme object.
    873 		 */
    874 		do_action( 'manage_themes_custom_column', $column_name, $stylesheet, $theme );
    875 	}
    876 
    877 	/**
    878 	 * Handles the output for a single table row.
    879 	 *
    880 	 * @since 4.3.0
    881 	 *
    882 	 * @param WP_Theme $item The current WP_Theme object.
    883 	 */
    884 	public function single_row_columns( $item ) {
    885 		list( $columns, $hidden, $sortable, $primary ) = $this->get_column_info();
    886 
    887 		foreach ( $columns as $column_name => $column_display_name ) {
    888 			$extra_classes = '';
    889 			if ( in_array( $column_name, $hidden, true ) ) {
    890 				$extra_classes .= ' hidden';
    891 			}
    892 
    893 			switch ( $column_name ) {
    894 				case 'cb':
    895 					echo '<th scope="row" class="check-column">';
    896 
    897 					$this->column_cb( $item );
    898 
    899 					echo '</th>';
    900 					break;
    901 
    902 				case 'name':
    903 					$active_theme_label = '';
    904 
    905 					/* The presence of the site_id property means that this is a subsite view and a label for the active theme needs to be added */
    906 					if ( ! empty( $this->site_id ) ) {
    907 						$stylesheet = get_blog_option( $this->site_id, 'stylesheet' );
    908 						$template   = get_blog_option( $this->site_id, 'template' );
    909 
    910 						/* Add a label for the active template */
    911 						if ( $item->get_template() === $template ) {
    912 							$active_theme_label = ' &mdash; ' . __( 'Active Theme' );
    913 						}
    914 
    915 						/* In case this is a child theme, label it properly */
    916 						if ( $stylesheet !== $template && $item->get_stylesheet() === $stylesheet ) {
    917 							$active_theme_label = ' &mdash; ' . __( 'Active Child Theme' );
    918 						}
    919 					}
    920 
    921 					echo "<td class='theme-title column-primary{$extra_classes}'><strong>" . $item->display( 'Name' ) . $active_theme_label . '</strong>';
    922 
    923 					$this->column_name( $item );
    924 
    925 					echo '</td>';
    926 					break;
    927 
    928 				case 'description':
    929 					echo "<td class='column-description desc{$extra_classes}'>";
    930 
    931 					$this->column_description( $item );
    932 
    933 					echo '</td>';
    934 					break;
    935 
    936 				case 'auto-updates':
    937 					echo "<td class='column-auto-updates{$extra_classes}'>";
    938 
    939 					$this->column_autoupdates( $item );
    940 
    941 					echo '</td>';
    942 					break;
    943 				default:
    944 					echo "<td class='$column_name column-$column_name{$extra_classes}'>";
    945 
    946 					$this->column_default( $item, $column_name );
    947 
    948 					echo '</td>';
    949 					break;
    950 			}
    951 		}
    952 	}
    953 
    954 	/**
    955 	 * @global string $status
    956 	 * @global array  $totals
    957 	 *
    958 	 * @param WP_Theme $theme
    959 	 */
    960 	public function single_row( $theme ) {
    961 		global $status, $totals;
    962 
    963 		if ( $this->is_site_themes ) {
    964 			$allowed = $theme->is_allowed( 'site', $this->site_id );
    965 		} else {
    966 			$allowed = $theme->is_allowed( 'network' );
    967 		}
    968 
    969 		$stylesheet = $theme->get_stylesheet();
    970 
    971 		$class = ! $allowed ? 'inactive' : 'active';
    972 		if ( ! empty( $totals['upgrade'] ) && ! empty( $theme->update ) ) {
    973 			$class .= ' update';
    974 		}
    975 
    976 		printf(
    977 			'<tr class="%s" data-slug="%s">',
    978 			esc_attr( $class ),
    979 			esc_attr( $stylesheet )
    980 		);
    981 
    982 		$this->single_row_columns( $theme );
    983 
    984 		echo '</tr>';
    985 
    986 		if ( $this->is_site_themes ) {
    987 			remove_action( "after_theme_row_$stylesheet", 'wp_theme_update_row' );
    988 		}
    989 
    990 		/**
    991 		 * Fires after each row in the Multisite themes list table.
    992 		 *
    993 		 * @since 3.1.0
    994 		 *
    995 		 * @param string   $stylesheet Directory name of the theme.
    996 		 * @param WP_Theme $theme      Current WP_Theme object.
    997 		 * @param string   $status     Status of the theme.
    998 		 */
    999 		do_action( 'after_theme_row', $stylesheet, $theme, $status );
   1000 
   1001 		/**
   1002 		 * Fires after each specific row in the Multisite themes list table.
   1003 		 *
   1004 		 * The dynamic portion of the hook name, `$stylesheet`, refers to the
   1005 		 * directory name of the theme, most often synonymous with the template
   1006 		 * name of the theme.
   1007 		 *
   1008 		 * @since 3.5.0
   1009 		 *
   1010 		 * @param string   $stylesheet Directory name of the theme.
   1011 		 * @param WP_Theme $theme      Current WP_Theme object.
   1012 		 * @param string   $status     Status of the theme.
   1013 		 */
   1014 		do_action( "after_theme_row_{$stylesheet}", $stylesheet, $theme, $status );
   1015 	}
   1016 }