[ Index ]

PHP Cross Reference of WordPress

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


Generated: Sat Jul 4 01:00:03 2020 Cross-referenced by PHPXref 0.7.1