[ 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       */
 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       * @since 5.9.0 Renamed `$theme` to `$item` to match parent class for PHP 8 named parameter support.
 509       *
 510       * @param WP_Theme $item The current WP_Theme object.
 511       */
 512  	public function column_cb( $item ) {
 513          // Restores the more descriptive, specific name for use within this method.
 514          $theme = $item;
 515  
 516          $checkbox_id = 'checkbox_' . md5( $theme->get( 'Name' ) );
 517          ?>
 518          <input type="checkbox" name="checked[]" value="<?php echo esc_attr( $theme->get_stylesheet() ); ?>" id="<?php echo $checkbox_id; ?>" />
 519          <label for="<?php echo $checkbox_id; ?>" >
 520              <span class="screen-reader-text">
 521              <?php
 522              printf(
 523                  /* translators: Hidden accessibility text. %s: Theme name */
 524                  __( 'Select %s' ),
 525                  $theme->display( 'Name' )
 526              );
 527              ?>
 528              </span>
 529          </label>
 530          <?php
 531      }
 532  
 533      /**
 534       * Handles the name column output.
 535       *
 536       * @since 4.3.0
 537       *
 538       * @global string $status
 539       * @global int    $page
 540       * @global string $s
 541       *
 542       * @param WP_Theme $theme The current WP_Theme object.
 543       */
 544  	public function column_name( $theme ) {
 545          global $status, $page, $s;
 546  
 547          $context = $status;
 548  
 549          if ( $this->is_site_themes ) {
 550              $url     = "site-themes.php?id={$this->site_id}&amp;";
 551              $allowed = $theme->is_allowed( 'site', $this->site_id );
 552          } else {
 553              $url     = 'themes.php?';
 554              $allowed = $theme->is_allowed( 'network' );
 555          }
 556  
 557          // Pre-order.
 558          $actions = array(
 559              'enable'  => '',
 560              'disable' => '',
 561              'delete'  => '',
 562          );
 563  
 564          $stylesheet = $theme->get_stylesheet();
 565          $theme_key  = urlencode( $stylesheet );
 566  
 567          if ( ! $allowed ) {
 568              if ( ! $theme->errors() ) {
 569                  $url = add_query_arg(
 570                      array(
 571                          'action' => 'enable',
 572                          'theme'  => $theme_key,
 573                          'paged'  => $page,
 574                          's'      => $s,
 575                      ),
 576                      $url
 577                  );
 578  
 579                  if ( $this->is_site_themes ) {
 580                      /* translators: %s: Theme name. */
 581                      $aria_label = sprintf( __( 'Enable %s' ), $theme->display( 'Name' ) );
 582                  } else {
 583                      /* translators: %s: Theme name. */
 584                      $aria_label = sprintf( __( 'Network Enable %s' ), $theme->display( 'Name' ) );
 585                  }
 586  
 587                  $actions['enable'] = sprintf(
 588                      '<a href="%s" class="edit" aria-label="%s">%s</a>',
 589                      esc_url( wp_nonce_url( $url, 'enable-theme_' . $stylesheet ) ),
 590                      esc_attr( $aria_label ),
 591                      ( $this->is_site_themes ? __( 'Enable' ) : __( 'Network Enable' ) )
 592                  );
 593              }
 594          } else {
 595              $url = add_query_arg(
 596                  array(
 597                      'action' => 'disable',
 598                      'theme'  => $theme_key,
 599                      'paged'  => $page,
 600                      's'      => $s,
 601                  ),
 602                  $url
 603              );
 604  
 605              if ( $this->is_site_themes ) {
 606                  /* translators: %s: Theme name. */
 607                  $aria_label = sprintf( __( 'Disable %s' ), $theme->display( 'Name' ) );
 608              } else {
 609                  /* translators: %s: Theme name. */
 610                  $aria_label = sprintf( __( 'Network Disable %s' ), $theme->display( 'Name' ) );
 611              }
 612  
 613              $actions['disable'] = sprintf(
 614                  '<a href="%s" aria-label="%s">%s</a>',
 615                  esc_url( wp_nonce_url( $url, 'disable-theme_' . $stylesheet ) ),
 616                  esc_attr( $aria_label ),
 617                  ( $this->is_site_themes ? __( 'Disable' ) : __( 'Network Disable' ) )
 618              );
 619          }
 620  
 621          if ( ! $allowed && ! $this->is_site_themes
 622              && current_user_can( 'delete_themes' )
 623              && get_option( 'stylesheet' ) !== $stylesheet
 624              && get_option( 'template' ) !== $stylesheet
 625          ) {
 626              $url = add_query_arg(
 627                  array(
 628                      'action'       => 'delete-selected',
 629                      'checked[]'    => $theme_key,
 630                      'theme_status' => $context,
 631                      'paged'        => $page,
 632                      's'            => $s,
 633                  ),
 634                  'themes.php'
 635              );
 636  
 637              /* translators: %s: Theme name. */
 638              $aria_label = sprintf( _x( 'Delete %s', 'theme' ), $theme->display( 'Name' ) );
 639  
 640              $actions['delete'] = sprintf(
 641                  '<a href="%s" class="delete" aria-label="%s">%s</a>',
 642                  esc_url( wp_nonce_url( $url, 'bulk-themes' ) ),
 643                  esc_attr( $aria_label ),
 644                  __( 'Delete' )
 645              );
 646          }
 647          /**
 648           * Filters the action links displayed for each theme in the Multisite
 649           * themes list table.
 650           *
 651           * The action links displayed are determined by the theme's status, and
 652           * which Multisite themes list table is being displayed - the Network
 653           * themes list table (themes.php), which displays all installed themes,
 654           * or the Site themes list table (site-themes.php), which displays the
 655           * non-network enabled themes when editing a site in the Network admin.
 656           *
 657           * The default action links for the Network themes list table include
 658           * 'Network Enable', 'Network Disable', and 'Delete'.
 659           *
 660           * The default action links for the Site themes list table include
 661           * 'Enable', and 'Disable'.
 662           *
 663           * @since 2.8.0
 664           *
 665           * @param string[] $actions An array of action links.
 666           * @param WP_Theme $theme   The current WP_Theme object.
 667           * @param string   $context Status of the theme, one of 'all', 'enabled', or 'disabled'.
 668           */
 669          $actions = apply_filters( 'theme_action_links', array_filter( $actions ), $theme, $context );
 670  
 671          /**
 672           * Filters the action links of a specific theme in the Multisite themes
 673           * list table.
 674           *
 675           * The dynamic portion of the hook name, `$stylesheet`, refers to the
 676           * directory name of the theme, which in most cases is synonymous
 677           * with the template name.
 678           *
 679           * @since 3.1.0
 680           *
 681           * @param string[] $actions An array of action links.
 682           * @param WP_Theme $theme   The current WP_Theme object.
 683           * @param string   $context Status of the theme, one of 'all', 'enabled', or 'disabled'.
 684           */
 685          $actions = apply_filters( "theme_action_links_{$stylesheet}", $actions, $theme, $context );
 686  
 687          echo $this->row_actions( $actions, true );
 688      }
 689  
 690      /**
 691       * Handles the description column output.
 692       *
 693       * @since 4.3.0
 694       *
 695       * @global string $status
 696       * @global array  $totals
 697       *
 698       * @param WP_Theme $theme The current WP_Theme object.
 699       */
 700  	public function column_description( $theme ) {
 701          global $status, $totals;
 702  
 703          if ( $theme->errors() ) {
 704              $pre = 'broken' === $status ? __( 'Broken Theme:' ) . ' ' : '';
 705              echo '<p><strong class="error-message">' . $pre . $theme->errors()->get_error_message() . '</strong></p>';
 706          }
 707  
 708          if ( $this->is_site_themes ) {
 709              $allowed = $theme->is_allowed( 'site', $this->site_id );
 710          } else {
 711              $allowed = $theme->is_allowed( 'network' );
 712          }
 713  
 714          $class = ! $allowed ? 'inactive' : 'active';
 715          if ( ! empty( $totals['upgrade'] ) && ! empty( $theme->update ) ) {
 716              $class .= ' update';
 717          }
 718  
 719          echo "<div class='theme-description'><p>" . $theme->display( 'Description' ) . "</p></div>
 720              <div class='$class second theme-version-author-uri'>";
 721  
 722          $stylesheet = $theme->get_stylesheet();
 723          $theme_meta = array();
 724  
 725          if ( $theme->get( 'Version' ) ) {
 726              /* translators: %s: Theme version. */
 727              $theme_meta[] = sprintf( __( 'Version %s' ), $theme->display( 'Version' ) );
 728          }
 729  
 730          /* translators: %s: Theme author. */
 731          $theme_meta[] = sprintf( __( 'By %s' ), $theme->display( 'Author' ) );
 732  
 733          if ( $theme->get( 'ThemeURI' ) ) {
 734              /* translators: %s: Theme name. */
 735              $aria_label = sprintf( __( 'Visit theme site for %s' ), $theme->display( 'Name' ) );
 736  
 737              $theme_meta[] = sprintf(
 738                  '<a href="%s" aria-label="%s">%s</a>',
 739                  $theme->display( 'ThemeURI' ),
 740                  esc_attr( $aria_label ),
 741                  __( 'Visit Theme Site' )
 742              );
 743          }
 744  
 745          if ( $theme->parent() ) {
 746              $theme_meta[] = sprintf(
 747                  /* translators: %s: Theme name. */
 748                  __( 'Child theme of %s' ),
 749                  '<strong>' . $theme->parent()->display( 'Name' ) . '</strong>'
 750              );
 751          }
 752  
 753          /**
 754           * Filters the array of row meta for each theme in the Multisite themes
 755           * list table.
 756           *
 757           * @since 3.1.0
 758           *
 759           * @param string[] $theme_meta An array of the theme's metadata, including
 760           *                             the version, author, and theme URI.
 761           * @param string   $stylesheet Directory name of the theme.
 762           * @param WP_Theme $theme      WP_Theme object.
 763           * @param string   $status     Status of the theme.
 764           */
 765          $theme_meta = apply_filters( 'theme_row_meta', $theme_meta, $stylesheet, $theme, $status );
 766  
 767          echo implode( ' | ', $theme_meta );
 768  
 769          echo '</div>';
 770      }
 771  
 772      /**
 773       * Handles the auto-updates column output.
 774       *
 775       * @since 5.5.0
 776       *
 777       * @global string $status
 778       * @global int  $page
 779       *
 780       * @param WP_Theme $theme The current WP_Theme object.
 781       */
 782  	public function column_autoupdates( $theme ) {
 783          global $status, $page;
 784  
 785          static $auto_updates, $available_updates;
 786  
 787          if ( ! $auto_updates ) {
 788              $auto_updates = (array) get_site_option( 'auto_update_themes', array() );
 789          }
 790          if ( ! $available_updates ) {
 791              $available_updates = get_site_transient( 'update_themes' );
 792          }
 793  
 794          $stylesheet = $theme->get_stylesheet();
 795  
 796          if ( isset( $theme->auto_update_forced ) ) {
 797              if ( $theme->auto_update_forced ) {
 798                  // Forced on.
 799                  $text = __( 'Auto-updates enabled' );
 800              } else {
 801                  $text = __( 'Auto-updates disabled' );
 802              }
 803              $action     = 'unavailable';
 804              $time_class = ' hidden';
 805          } elseif ( empty( $theme->update_supported ) ) {
 806              $text       = '';
 807              $action     = 'unavailable';
 808              $time_class = ' hidden';
 809          } elseif ( in_array( $stylesheet, $auto_updates, true ) ) {
 810              $text       = __( 'Disable auto-updates' );
 811              $action     = 'disable';
 812              $time_class = '';
 813          } else {
 814              $text       = __( 'Enable auto-updates' );
 815              $action     = 'enable';
 816              $time_class = ' hidden';
 817          }
 818  
 819          $query_args = array(
 820              'action'       => "{$action}-auto-update",
 821              'theme'        => $stylesheet,
 822              'paged'        => $page,
 823              'theme_status' => $status,
 824          );
 825  
 826          $url = add_query_arg( $query_args, 'themes.php' );
 827  
 828          if ( 'unavailable' === $action ) {
 829              $html[] = '<span class="label">' . $text . '</span>';
 830          } else {
 831              $html[] = sprintf(
 832                  '<a href="%s" class="toggle-auto-update aria-button-if-js" data-wp-action="%s">',
 833                  wp_nonce_url( $url, 'updates' ),
 834                  $action
 835              );
 836  
 837              $html[] = '<span class="dashicons dashicons-update spin hidden" aria-hidden="true"></span>';
 838              $html[] = '<span class="label">' . $text . '</span>';
 839              $html[] = '</a>';
 840  
 841          }
 842  
 843          if ( isset( $available_updates->response[ $stylesheet ] ) ) {
 844              $html[] = sprintf(
 845                  '<div class="auto-update-time%s">%s</div>',
 846                  $time_class,
 847                  wp_get_auto_update_message()
 848              );
 849          }
 850  
 851          $html = implode( '', $html );
 852  
 853          /**
 854           * Filters the HTML of the auto-updates setting for each theme in the Themes list table.
 855           *
 856           * @since 5.5.0
 857           *
 858           * @param string   $html       The HTML for theme's auto-update setting, including
 859           *                             toggle auto-update action link and time to next update.
 860           * @param string   $stylesheet Directory name of the theme.
 861           * @param WP_Theme $theme      WP_Theme object.
 862           */
 863          echo apply_filters( 'theme_auto_update_setting_html', $html, $stylesheet, $theme );
 864  
 865          wp_admin_notice(
 866              '',
 867              array(
 868                  'type'               => 'error',
 869                  'additional_classes' => array( 'notice-alt', 'inline', 'hidden' ),
 870              )
 871          );
 872      }
 873  
 874      /**
 875       * Handles default column output.
 876       *
 877       * @since 4.3.0
 878       * @since 5.9.0 Renamed `$theme` to `$item` to match parent class for PHP 8 named parameter support.
 879       *
 880       * @param WP_Theme $item        The current WP_Theme object.
 881       * @param string   $column_name The current column name.
 882       */
 883  	public function column_default( $item, $column_name ) {
 884          // Restores the more descriptive, specific name for use within this method.
 885          $theme = $item;
 886  
 887          $stylesheet = $theme->get_stylesheet();
 888  
 889          /**
 890           * Fires inside each custom column of the Multisite themes list table.
 891           *
 892           * @since 3.1.0
 893           *
 894           * @param string   $column_name Name of the column.
 895           * @param string   $stylesheet  Directory name of the theme.
 896           * @param WP_Theme $theme       Current WP_Theme object.
 897           */
 898          do_action( 'manage_themes_custom_column', $column_name, $stylesheet, $theme );
 899      }
 900  
 901      /**
 902       * Handles the output for a single table row.
 903       *
 904       * @since 4.3.0
 905       *
 906       * @param WP_Theme $item The current WP_Theme object.
 907       */
 908  	public function single_row_columns( $item ) {
 909          list( $columns, $hidden, $sortable, $primary ) = $this->get_column_info();
 910  
 911          foreach ( $columns as $column_name => $column_display_name ) {
 912              $extra_classes = '';
 913              if ( in_array( $column_name, $hidden, true ) ) {
 914                  $extra_classes .= ' hidden';
 915              }
 916  
 917              switch ( $column_name ) {
 918                  case 'cb':
 919                      echo '<th scope="row" class="check-column">';
 920  
 921                      $this->column_cb( $item );
 922  
 923                      echo '</th>';
 924                      break;
 925  
 926                  case 'name':
 927                      $active_theme_label = '';
 928  
 929                      /* 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 */
 930                      if ( ! empty( $this->site_id ) ) {
 931                          $stylesheet = get_blog_option( $this->site_id, 'stylesheet' );
 932                          $template   = get_blog_option( $this->site_id, 'template' );
 933  
 934                          /* Add a label for the active template */
 935                          if ( $item->get_template() === $template ) {
 936                              $active_theme_label = ' &mdash; ' . __( 'Active Theme' );
 937                          }
 938  
 939                          /* In case this is a child theme, label it properly */
 940                          if ( $stylesheet !== $template && $item->get_stylesheet() === $stylesheet ) {
 941                              $active_theme_label = ' &mdash; ' . __( 'Active Child Theme' );
 942                          }
 943                      }
 944  
 945                      echo "<td class='theme-title column-primary{$extra_classes}'><strong>" . $item->display( 'Name' ) . $active_theme_label . '</strong>';
 946  
 947                      $this->column_name( $item );
 948  
 949                      echo '</td>';
 950                      break;
 951  
 952                  case 'description':
 953                      echo "<td class='column-description desc{$extra_classes}'>";
 954  
 955                      $this->column_description( $item );
 956  
 957                      echo '</td>';
 958                      break;
 959  
 960                  case 'auto-updates':
 961                      echo "<td class='column-auto-updates{$extra_classes}'>";
 962  
 963                      $this->column_autoupdates( $item );
 964  
 965                      echo '</td>';
 966                      break;
 967                  default:
 968                      echo "<td class='$column_name column-$column_name{$extra_classes}'>";
 969  
 970                      $this->column_default( $item, $column_name );
 971  
 972                      echo '</td>';
 973                      break;
 974              }
 975          }
 976      }
 977  
 978      /**
 979       * @global string $status
 980       * @global array  $totals
 981       *
 982       * @param WP_Theme $theme
 983       */
 984  	public function single_row( $theme ) {
 985          global $status, $totals;
 986  
 987          if ( $this->is_site_themes ) {
 988              $allowed = $theme->is_allowed( 'site', $this->site_id );
 989          } else {
 990              $allowed = $theme->is_allowed( 'network' );
 991          }
 992  
 993          $stylesheet = $theme->get_stylesheet();
 994  
 995          $class = ! $allowed ? 'inactive' : 'active';
 996          if ( ! empty( $totals['upgrade'] ) && ! empty( $theme->update ) ) {
 997              $class .= ' update';
 998          }
 999  
1000          printf(
1001              '<tr class="%s" data-slug="%s">',
1002              esc_attr( $class ),
1003              esc_attr( $stylesheet )
1004          );
1005  
1006          $this->single_row_columns( $theme );
1007  
1008          echo '</tr>';
1009  
1010          if ( $this->is_site_themes ) {
1011              remove_action( "after_theme_row_$stylesheet", 'wp_theme_update_row' );
1012          }
1013  
1014          /**
1015           * Fires after each row in the Multisite themes list table.
1016           *
1017           * @since 3.1.0
1018           *
1019           * @param string   $stylesheet Directory name of the theme.
1020           * @param WP_Theme $theme      Current WP_Theme object.
1021           * @param string   $status     Status of the theme.
1022           */
1023          do_action( 'after_theme_row', $stylesheet, $theme, $status );
1024  
1025          /**
1026           * Fires after each specific row in the Multisite themes list table.
1027           *
1028           * The dynamic portion of the hook name, `$stylesheet`, refers to the
1029           * directory name of the theme, most often synonymous with the template
1030           * name of the theme.
1031           *
1032           * @since 3.5.0
1033           *
1034           * @param string   $stylesheet Directory name of the theme.
1035           * @param WP_Theme $theme      Current WP_Theme object.
1036           * @param string   $status     Status of the theme.
1037           */
1038          do_action( "after_theme_row_{$stylesheet}", $stylesheet, $theme, $status );
1039      }
1040  }


Generated : Fri May 10 08:20:01 2024 Cross-referenced by PHPXref