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


Generated : Sat Nov 23 08:20:01 2024 Cross-referenced by PHPXref