[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

Search

title

Body

[close]

/wp-admin/includes/ -> class-wp-ms-themes-list-table.php (source)

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


Generated : Sun Nov 8 08:20:01 2026 Cross-referenced by PHPXref