[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

Search

title

Body

[close]

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

   1  <?php
   2  /**
   3   * List Table API: WP_MS_Sites_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 sites 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_Sites_List_Table extends WP_List_Table {
  18  
  19      /**
  20       * Site status list.
  21       *
  22       * @since 4.3.0
  23       * @var array
  24       */
  25      public $status_list;
  26  
  27      /**
  28       * Constructor.
  29       *
  30       * @since 3.1.0
  31       *
  32       * @see WP_List_Table::__construct() for more information on default arguments.
  33       *
  34       * @param array $args An associative array of arguments.
  35       */
  36  	public function __construct( $args = array() ) {
  37          $this->status_list = array(
  38              'archived' => array( 'site-archived', __( 'Archived' ) ),
  39              'spam'     => array( 'site-spammed', _x( 'Spam', 'site' ) ),
  40              'deleted'  => array( 'site-deleted', __( 'Deleted' ) ),
  41              'mature'   => array( 'site-mature', __( 'Mature' ) ),
  42          );
  43  
  44          parent::__construct(
  45              array(
  46                  'plural' => 'sites',
  47                  'screen' => isset( $args['screen'] ) ? $args['screen'] : null,
  48              )
  49          );
  50      }
  51  
  52      /**
  53       * @return bool
  54       */
  55  	public function ajax_user_can() {
  56          return current_user_can( 'manage_sites' );
  57      }
  58  
  59      /**
  60       * Prepares the list of sites for display.
  61       *
  62       * @since 3.1.0
  63       *
  64       * @global string $mode List table view mode.
  65       * @global string $s
  66       * @global wpdb   $wpdb WordPress database abstraction object.
  67       */
  68  	public function prepare_items() {
  69          global $mode, $s, $wpdb;
  70  
  71          if ( ! empty( $_REQUEST['mode'] ) ) {
  72              $mode = 'excerpt' === $_REQUEST['mode'] ? 'excerpt' : 'list';
  73              set_user_setting( 'sites_list_mode', $mode );
  74          } else {
  75              $mode = get_user_setting( 'sites_list_mode', 'list' );
  76          }
  77  
  78          $per_page = $this->get_items_per_page( 'sites_network_per_page' );
  79  
  80          $pagenum = $this->get_pagenum();
  81  
  82          $s    = isset( $_REQUEST['s'] ) ? wp_unslash( trim( $_REQUEST['s'] ) ) : '';
  83          $wild = '';
  84          if ( str_contains( $s, '*' ) ) {
  85              $wild = '*';
  86              $s    = trim( $s, '*' );
  87          }
  88  
  89          /*
  90           * If the network is large and a search is not being performed, show only
  91           * the latest sites with no paging in order to avoid expensive count queries.
  92           */
  93          if ( ! $s && wp_is_large_network() ) {
  94              if ( ! isset( $_REQUEST['orderby'] ) ) {
  95                  $_GET['orderby']     = '';
  96                  $_REQUEST['orderby'] = '';
  97              }
  98              if ( ! isset( $_REQUEST['order'] ) ) {
  99                  $_GET['order']     = 'DESC';
 100                  $_REQUEST['order'] = 'DESC';
 101              }
 102          }
 103  
 104          $args = array(
 105              'number'     => (int) $per_page,
 106              'offset'     => (int) ( ( $pagenum - 1 ) * $per_page ),
 107              'network_id' => get_current_network_id(),
 108          );
 109  
 110          if ( empty( $s ) ) {
 111              // Nothing to do.
 112          } elseif ( preg_match( '/^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$/', $s )
 113              || preg_match( '/^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.?$/', $s )
 114              || preg_match( '/^[0-9]{1,3}\.[0-9]{1,3}\.?$/', $s )
 115              || preg_match( '/^[0-9]{1,3}\.$/', $s )
 116          ) {
 117              // IPv4 address.
 118              $sql = $wpdb->prepare(
 119                  "SELECT blog_id FROM {$wpdb->registration_log} WHERE {$wpdb->registration_log}.IP LIKE %s",
 120                  $wpdb->esc_like( $s ) . ( ! empty( $wild ) ? '%' : '' )
 121              );
 122  
 123              $reg_blog_ids = $wpdb->get_col( $sql );
 124  
 125              if ( $reg_blog_ids ) {
 126                  $args['site__in'] = $reg_blog_ids;
 127              }
 128          } elseif ( is_numeric( $s ) && empty( $wild ) ) {
 129              $args['ID'] = $s;
 130          } else {
 131              $args['search'] = $s;
 132  
 133              if ( ! is_subdomain_install() ) {
 134                  $args['search_columns'] = array( 'path' );
 135              }
 136          }
 137  
 138          $order_by = isset( $_REQUEST['orderby'] ) ? $_REQUEST['orderby'] : '';
 139          if ( 'registered' === $order_by ) {
 140              // 'registered' is a valid field name.
 141          } elseif ( 'lastupdated' === $order_by ) {
 142              $order_by = 'last_updated';
 143          } elseif ( 'blogname' === $order_by ) {
 144              if ( is_subdomain_install() ) {
 145                  $order_by = 'domain';
 146              } else {
 147                  $order_by = 'path';
 148              }
 149          } elseif ( 'blog_id' === $order_by ) {
 150              $order_by = 'id';
 151          } elseif ( ! $order_by ) {
 152              $order_by = false;
 153          }
 154  
 155          $args['orderby'] = $order_by;
 156  
 157          if ( $order_by ) {
 158              $args['order'] = ( isset( $_REQUEST['order'] ) && 'DESC' === strtoupper( $_REQUEST['order'] ) ) ? 'DESC' : 'ASC';
 159          }
 160  
 161          if ( wp_is_large_network() ) {
 162              $args['no_found_rows'] = true;
 163          } else {
 164              $args['no_found_rows'] = false;
 165          }
 166  
 167          // Take into account the role the user has selected.
 168          $status = isset( $_REQUEST['status'] ) ? wp_unslash( trim( $_REQUEST['status'] ) ) : '';
 169          if ( in_array( $status, array( 'public', 'archived', 'mature', 'spam', 'deleted' ), true ) ) {
 170              $args[ $status ] = 1;
 171          }
 172  
 173          /**
 174           * Filters the arguments for the site query in the sites list table.
 175           *
 176           * @since 4.6.0
 177           *
 178           * @param array $args An array of get_sites() arguments.
 179           */
 180          $args = apply_filters( 'ms_sites_list_table_query_args', $args );
 181  
 182          $_sites = get_sites( $args );
 183          if ( is_array( $_sites ) ) {
 184              update_site_cache( $_sites );
 185  
 186              $this->items = array_slice( $_sites, 0, $per_page );
 187          }
 188  
 189          $total_sites = get_sites(
 190              array_merge(
 191                  $args,
 192                  array(
 193                      'count'  => true,
 194                      'offset' => 0,
 195                      'number' => 0,
 196                  )
 197              )
 198          );
 199  
 200          $this->set_pagination_args(
 201              array(
 202                  'total_items' => $total_sites,
 203                  'per_page'    => $per_page,
 204              )
 205          );
 206      }
 207  
 208      /**
 209       */
 210  	public function no_items() {
 211          _e( 'No sites found.' );
 212      }
 213  
 214      /**
 215       * Gets links to filter sites by status.
 216       *
 217       * @since 5.3.0
 218       *
 219       * @return array
 220       */
 221  	protected function get_views() {
 222          $counts = wp_count_sites();
 223  
 224          $statuses = array(
 225              /* translators: %s: Number of sites. */
 226              'all'      => _nx_noop(
 227                  'All <span class="count">(%s)</span>',
 228                  'All <span class="count">(%s)</span>',
 229                  'sites'
 230              ),
 231  
 232              /* translators: %s: Number of sites. */
 233              'public'   => _n_noop(
 234                  'Public <span class="count">(%s)</span>',
 235                  'Public <span class="count">(%s)</span>'
 236              ),
 237  
 238              /* translators: %s: Number of sites. */
 239              'archived' => _n_noop(
 240                  'Archived <span class="count">(%s)</span>',
 241                  'Archived <span class="count">(%s)</span>'
 242              ),
 243  
 244              /* translators: %s: Number of sites. */
 245              'mature'   => _n_noop(
 246                  'Mature <span class="count">(%s)</span>',
 247                  'Mature <span class="count">(%s)</span>'
 248              ),
 249  
 250              /* translators: %s: Number of sites. */
 251              'spam'     => _nx_noop(
 252                  'Spam <span class="count">(%s)</span>',
 253                  'Spam <span class="count">(%s)</span>',
 254                  'sites'
 255              ),
 256  
 257              /* translators: %s: Number of sites. */
 258              'deleted'  => _n_noop(
 259                  'Deleted <span class="count">(%s)</span>',
 260                  'Deleted <span class="count">(%s)</span>'
 261              ),
 262          );
 263  
 264          $view_links       = array();
 265          $requested_status = isset( $_REQUEST['status'] ) ? wp_unslash( trim( $_REQUEST['status'] ) ) : '';
 266          $url              = 'sites.php';
 267  
 268          foreach ( $statuses as $status => $label_count ) {
 269              if ( (int) $counts[ $status ] > 0 ) {
 270                  $label = sprintf(
 271                      translate_nooped_plural( $label_count, $counts[ $status ] ),
 272                      number_format_i18n( $counts[ $status ] )
 273                  );
 274  
 275                  $full_url = 'all' === $status ? $url : add_query_arg( 'status', $status, $url );
 276  
 277                  $view_links[ $status ] = array(
 278                      'url'     => esc_url( $full_url ),
 279                      'label'   => $label,
 280                      'current' => $requested_status === $status || ( '' === $requested_status && 'all' === $status ),
 281                  );
 282              }
 283          }
 284  
 285          return $this->get_views_links( $view_links );
 286      }
 287  
 288      /**
 289       * @return array
 290       */
 291  	protected function get_bulk_actions() {
 292          $actions = array();
 293          if ( current_user_can( 'delete_sites' ) ) {
 294              $actions['delete'] = __( 'Delete' );
 295          }
 296          $actions['spam']    = _x( 'Mark as spam', 'site' );
 297          $actions['notspam'] = _x( 'Not spam', 'site' );
 298  
 299          return $actions;
 300      }
 301  
 302      /**
 303       * @global string $mode List table view mode.
 304       *
 305       * @param string $which The location of the pagination nav markup: Either 'top' or 'bottom'.
 306       */
 307  	protected function pagination( $which ) {
 308          global $mode;
 309  
 310          parent::pagination( $which );
 311  
 312          if ( 'top' === $which ) {
 313              $this->view_switcher( $mode );
 314          }
 315      }
 316  
 317      /**
 318       * Displays extra controls between bulk actions and pagination.
 319       *
 320       * @since 5.3.0
 321       *
 322       * @param string $which The location of the extra table nav markup: Either 'top' or 'bottom'.
 323       */
 324  	protected function extra_tablenav( $which ) {
 325          ?>
 326          <div class="alignleft actions">
 327          <?php
 328          if ( 'top' === $which ) {
 329              ob_start();
 330  
 331              /**
 332               * Fires before the Filter button on the MS sites list table.
 333               *
 334               * @since 5.3.0
 335               *
 336               * @param string $which The location of the extra table nav markup: Either 'top' or 'bottom'.
 337               */
 338              do_action( 'restrict_manage_sites', $which );
 339  
 340              $output = ob_get_clean();
 341  
 342              if ( ! empty( $output ) ) {
 343                  echo $output;
 344                  submit_button( __( 'Filter' ), '', 'filter_action', false, array( 'id' => 'site-query-submit' ) );
 345              }
 346          }
 347          ?>
 348          </div>
 349          <?php
 350          /**
 351           * Fires immediately following the closing "actions" div in the tablenav for the
 352           * MS sites list table.
 353           *
 354           * @since 5.3.0
 355           *
 356           * @param string $which The location of the extra table nav markup: Either 'top' or 'bottom'.
 357           */
 358          do_action( 'manage_sites_extra_tablenav', $which );
 359      }
 360  
 361      /**
 362       * @return string[] Array of column titles keyed by their column name.
 363       */
 364  	public function get_columns() {
 365          $sites_columns = array(
 366              'cb'          => '<input type="checkbox" />',
 367              'blogname'    => __( 'URL' ),
 368              'lastupdated' => __( 'Last Updated' ),
 369              'registered'  => _x( 'Registered', 'site' ),
 370              'users'       => __( 'Users' ),
 371          );
 372  
 373          if ( has_filter( 'wpmublogsaction' ) ) {
 374              $sites_columns['plugins'] = __( 'Actions' );
 375          }
 376  
 377          /**
 378           * Filters the displayed site columns in Sites list table.
 379           *
 380           * @since MU (3.0.0)
 381           *
 382           * @param string[] $sites_columns An array of displayed site columns. Default 'cb',
 383           *                               'blogname', 'lastupdated', 'registered', 'users'.
 384           */
 385          return apply_filters( 'wpmu_blogs_columns', $sites_columns );
 386      }
 387  
 388      /**
 389       * @return array
 390       */
 391  	protected function get_sortable_columns() {
 392  
 393          if ( is_subdomain_install() ) {
 394              $blogname_abbr         = __( 'Domain' );
 395              $blogname_orderby_text = __( 'Table ordered by Site Domain Name.' );
 396          } else {
 397              $blogname_abbr         = __( 'Path' );
 398              $blogname_orderby_text = __( 'Table ordered by Site Path.' );
 399          }
 400  
 401          return array(
 402              'blogname'    => array( 'blogname', false, $blogname_abbr, $blogname_orderby_text ),
 403              'lastupdated' => array( 'lastupdated', true, __( 'Last Updated' ), __( 'Table ordered by Last Updated.' ) ),
 404              'registered'  => array( 'blog_id', true, _x( 'Registered', 'site' ), __( 'Table ordered by Site Registered Date.' ), 'desc' ),
 405          );
 406      }
 407  
 408      /**
 409       * Handles the checkbox column output.
 410       *
 411       * @since 4.3.0
 412       * @since 5.9.0 Renamed `$blog` to `$item` to match parent class for PHP 8 named parameter support.
 413       *
 414       * @param array $item Current site.
 415       */
 416  	public function column_cb( $item ) {
 417          // Restores the more descriptive, specific name for use within this method.
 418          $blog = $item;
 419  
 420          if ( ! is_main_site( $blog['blog_id'] ) ) :
 421              $blogname = untrailingslashit( $blog['domain'] . $blog['path'] );
 422              ?>
 423              <input type="checkbox" id="blog_<?php echo $blog['blog_id']; ?>" name="allblogs[]" value="<?php echo esc_attr( $blog['blog_id'] ); ?>" />
 424              <label for="blog_<?php echo $blog['blog_id']; ?>">
 425                  <span class="screen-reader-text">
 426                  <?php
 427                  /* translators: %s: Site URL. */
 428                  printf( __( 'Select %s' ), $blogname );
 429                  ?>
 430                  </span>
 431              </label>
 432              <?php
 433          endif;
 434      }
 435  
 436      /**
 437       * Handles the ID column output.
 438       *
 439       * @since 4.4.0
 440       *
 441       * @param array $blog Current site.
 442       */
 443  	public function column_id( $blog ) {
 444          echo $blog['blog_id'];
 445      }
 446  
 447      /**
 448       * Handles the site name column output.
 449       *
 450       * @since 4.3.0
 451       *
 452       * @global string $mode List table view mode.
 453       *
 454       * @param array $blog Current site.
 455       */
 456  	public function column_blogname( $blog ) {
 457          global $mode;
 458  
 459          $blogname = untrailingslashit( $blog['domain'] . $blog['path'] );
 460  
 461          ?>
 462          <strong>
 463              <?php
 464              printf(
 465                  '<a href="%1$s" class="edit">%2$s</a>',
 466                  esc_url( network_admin_url( 'site-info.php?id=' . $blog['blog_id'] ) ),
 467                  $blogname
 468              );
 469  
 470              $this->site_states( $blog );
 471              ?>
 472          </strong>
 473          <?php
 474          if ( 'list' !== $mode ) {
 475              switch_to_blog( $blog['blog_id'] );
 476              echo '<p>';
 477              printf(
 478                  /* translators: 1: Site title, 2: Site tagline. */
 479                  __( '%1$s &#8211; %2$s' ),
 480                  get_option( 'blogname' ),
 481                  '<em>' . get_option( 'blogdescription' ) . '</em>'
 482              );
 483              echo '</p>';
 484              restore_current_blog();
 485          }
 486      }
 487  
 488      /**
 489       * Handles the lastupdated column output.
 490       *
 491       * @since 4.3.0
 492       *
 493       * @global string $mode List table view mode.
 494       *
 495       * @param array $blog Current site.
 496       */
 497  	public function column_lastupdated( $blog ) {
 498          global $mode;
 499  
 500          if ( 'list' === $mode ) {
 501              $date = __( 'Y/m/d' );
 502          } else {
 503              $date = __( 'Y/m/d g:i:s a' );
 504          }
 505  
 506          if ( '0000-00-00 00:00:00' === $blog['last_updated'] ) {
 507              _e( 'Never' );
 508          } else {
 509              echo mysql2date( $date, $blog['last_updated'] );
 510          }
 511      }
 512  
 513      /**
 514       * Handles the registered column output.
 515       *
 516       * @since 4.3.0
 517       *
 518       * @global string $mode List table view mode.
 519       *
 520       * @param array $blog Current site.
 521       */
 522  	public function column_registered( $blog ) {
 523          global $mode;
 524  
 525          if ( 'list' === $mode ) {
 526              $date = __( 'Y/m/d' );
 527          } else {
 528              $date = __( 'Y/m/d g:i:s a' );
 529          }
 530  
 531          if ( '0000-00-00 00:00:00' === $blog['registered'] ) {
 532              echo '&#x2014;';
 533          } else {
 534              echo mysql2date( $date, $blog['registered'] );
 535          }
 536      }
 537  
 538      /**
 539       * Handles the users column output.
 540       *
 541       * @since 4.3.0
 542       *
 543       * @param array $blog Current site.
 544       */
 545  	public function column_users( $blog ) {
 546          $user_count = wp_cache_get( $blog['blog_id'] . '_user_count', 'blog-details' );
 547          if ( ! $user_count ) {
 548              $blog_users = new WP_User_Query(
 549                  array(
 550                      'blog_id'     => $blog['blog_id'],
 551                      'fields'      => 'ID',
 552                      'number'      => 1,
 553                      'count_total' => true,
 554                  )
 555              );
 556              $user_count = $blog_users->get_total();
 557              wp_cache_set( $blog['blog_id'] . '_user_count', $user_count, 'blog-details', 12 * HOUR_IN_SECONDS );
 558          }
 559  
 560          printf(
 561              '<a href="%1$s">%2$s</a>',
 562              esc_url( network_admin_url( 'site-users.php?id=' . $blog['blog_id'] ) ),
 563              number_format_i18n( $user_count )
 564          );
 565      }
 566  
 567      /**
 568       * Handles the plugins column output.
 569       *
 570       * @since 4.3.0
 571       *
 572       * @param array $blog Current site.
 573       */
 574  	public function column_plugins( $blog ) {
 575          if ( has_filter( 'wpmublogsaction' ) ) {
 576              /**
 577               * Fires inside the auxiliary 'Actions' column of the Sites list table.
 578               *
 579               * By default this column is hidden unless something is hooked to the action.
 580               *
 581               * @since MU (3.0.0)
 582               *
 583               * @param int $blog_id The site ID.
 584               */
 585              do_action( 'wpmublogsaction', $blog['blog_id'] );
 586          }
 587      }
 588  
 589      /**
 590       * Handles output for the default column.
 591       *
 592       * @since 4.3.0
 593       * @since 5.9.0 Renamed `$blog` to `$item` to match parent class for PHP 8 named parameter support.
 594       *
 595       * @param array  $item        Current site.
 596       * @param string $column_name Current column name.
 597       */
 598  	public function column_default( $item, $column_name ) {
 599          // Restores the more descriptive, specific name for use within this method.
 600          $blog = $item;
 601  
 602          /**
 603           * Fires for each registered custom column in the Sites list table.
 604           *
 605           * @since 3.1.0
 606           *
 607           * @param string $column_name The name of the column to display.
 608           * @param int    $blog_id     The site ID.
 609           */
 610          do_action( 'manage_sites_custom_column', $column_name, $blog['blog_id'] );
 611      }
 612  
 613      /**
 614       * @global string $mode List table view mode.
 615       */
 616  	public function display_rows() {
 617          foreach ( $this->items as $blog ) {
 618              $blog  = $blog->to_array();
 619              $class = '';
 620              reset( $this->status_list );
 621  
 622              foreach ( $this->status_list as $status => $col ) {
 623                  if ( '1' === $blog[ $status ] ) {
 624                      $class = " class='{$col[0]}'";
 625                  }
 626              }
 627  
 628              echo "<tr{$class}>";
 629  
 630              $this->single_row_columns( $blog );
 631  
 632              echo '</tr>';
 633          }
 634      }
 635  
 636      /**
 637       * Determines whether to output comma-separated site states.
 638       *
 639       * @since 5.3.0
 640       *
 641       * @param array $site
 642       */
 643  	protected function site_states( $site ) {
 644          $site_states = array();
 645  
 646          // $site is still an array, so get the object.
 647          $_site = WP_Site::get_instance( $site['blog_id'] );
 648  
 649          if ( is_main_site( $_site->id ) ) {
 650              $site_states['main'] = __( 'Main' );
 651          }
 652  
 653          reset( $this->status_list );
 654  
 655          $site_status = isset( $_REQUEST['status'] ) ? wp_unslash( trim( $_REQUEST['status'] ) ) : '';
 656          foreach ( $this->status_list as $status => $col ) {
 657              if ( '1' === $_site->{$status} && $site_status !== $status ) {
 658                  $site_states[ $col[0] ] = $col[1];
 659              }
 660          }
 661  
 662          /**
 663           * Filters the default site display states for items in the Sites list table.
 664           *
 665           * @since 5.3.0
 666           *
 667           * @param string[] $site_states An array of site states. Default 'Main',
 668           *                              'Archived', 'Mature', 'Spam', 'Deleted'.
 669           * @param WP_Site  $site        The current site object.
 670           */
 671          $site_states = apply_filters( 'display_site_states', $site_states, $_site );
 672  
 673          if ( ! empty( $site_states ) ) {
 674              $state_count = count( $site_states );
 675  
 676              $i = 0;
 677  
 678              echo ' &mdash; ';
 679  
 680              foreach ( $site_states as $state ) {
 681                  ++$i;
 682  
 683                  $separator = ( $i < $state_count ) ? ', ' : '';
 684  
 685                  echo "<span class='post-state'>{$state}{$separator}</span>";
 686              }
 687          }
 688      }
 689  
 690      /**
 691       * Gets the name of the default primary column.
 692       *
 693       * @since 4.3.0
 694       *
 695       * @return string Name of the default primary column, in this case, 'blogname'.
 696       */
 697  	protected function get_default_primary_column_name() {
 698          return 'blogname';
 699      }
 700  
 701      /**
 702       * Generates and displays row action links.
 703       *
 704       * @since 4.3.0
 705       * @since 5.9.0 Renamed `$blog` to `$item` to match parent class for PHP 8 named parameter support.
 706       *
 707       * @param array  $item        Site being acted upon.
 708       * @param string $column_name Current column name.
 709       * @param string $primary     Primary column name.
 710       * @return string Row actions output for sites in Multisite, or an empty string
 711       *                if the current column is not the primary column.
 712       */
 713  	protected function handle_row_actions( $item, $column_name, $primary ) {
 714          if ( $primary !== $column_name ) {
 715              return '';
 716          }
 717  
 718          // Restores the more descriptive, specific name for use within this method.
 719          $blog = $item;
 720  
 721          $blogname = untrailingslashit( $blog['domain'] . $blog['path'] );
 722  
 723          // Preordered.
 724          $actions = array(
 725              'edit'       => '',
 726              'backend'    => '',
 727              'activate'   => '',
 728              'deactivate' => '',
 729              'archive'    => '',
 730              'unarchive'  => '',
 731              'spam'       => '',
 732              'unspam'     => '',
 733              'delete'     => '',
 734              'visit'      => '',
 735          );
 736  
 737          $actions['edit'] = sprintf(
 738              '<a href="%1$s">%2$s</a>',
 739              esc_url( network_admin_url( 'site-info.php?id=' . $blog['blog_id'] ) ),
 740              __( 'Edit' )
 741          );
 742  
 743          $actions['backend'] = sprintf(
 744              '<a href="%1$s" class="edit">%2$s</a>',
 745              esc_url( get_admin_url( $blog['blog_id'] ) ),
 746              __( 'Dashboard' )
 747          );
 748  
 749          if ( ! is_main_site( $blog['blog_id'] ) ) {
 750              if ( '1' === $blog['deleted'] ) {
 751                  $actions['activate'] = sprintf(
 752                      '<a href="%1$s">%2$s</a>',
 753                      esc_url(
 754                          wp_nonce_url(
 755                              network_admin_url( 'sites.php?action=confirm&amp;action2=activateblog&amp;id=' . $blog['blog_id'] ),
 756                              'activateblog_' . $blog['blog_id']
 757                          )
 758                      ),
 759                      _x( 'Activate', 'site' )
 760                  );
 761              } else {
 762                  $actions['deactivate'] = sprintf(
 763                      '<a href="%1$s">%2$s</a>',
 764                      esc_url(
 765                          wp_nonce_url(
 766                              network_admin_url( 'sites.php?action=confirm&amp;action2=deactivateblog&amp;id=' . $blog['blog_id'] ),
 767                              'deactivateblog_' . $blog['blog_id']
 768                          )
 769                      ),
 770                      __( 'Deactivate' )
 771                  );
 772              }
 773  
 774              if ( '1' === $blog['archived'] ) {
 775                  $actions['unarchive'] = sprintf(
 776                      '<a href="%1$s">%2$s</a>',
 777                      esc_url(
 778                          wp_nonce_url(
 779                              network_admin_url( 'sites.php?action=confirm&amp;action2=unarchiveblog&amp;id=' . $blog['blog_id'] ),
 780                              'unarchiveblog_' . $blog['blog_id']
 781                          )
 782                      ),
 783                      __( 'Unarchive' )
 784                  );
 785              } else {
 786                  $actions['archive'] = sprintf(
 787                      '<a href="%1$s">%2$s</a>',
 788                      esc_url(
 789                          wp_nonce_url(
 790                              network_admin_url( 'sites.php?action=confirm&amp;action2=archiveblog&amp;id=' . $blog['blog_id'] ),
 791                              'archiveblog_' . $blog['blog_id']
 792                          )
 793                      ),
 794                      _x( 'Archive', 'verb; site' )
 795                  );
 796              }
 797  
 798              if ( '1' === $blog['spam'] ) {
 799                  $actions['unspam'] = sprintf(
 800                      '<a href="%1$s">%2$s</a>',
 801                      esc_url(
 802                          wp_nonce_url(
 803                              network_admin_url( 'sites.php?action=confirm&amp;action2=unspamblog&amp;id=' . $blog['blog_id'] ),
 804                              'unspamblog_' . $blog['blog_id']
 805                          )
 806                      ),
 807                      _x( 'Not Spam', 'site' )
 808                  );
 809              } else {
 810                  $actions['spam'] = sprintf(
 811                      '<a href="%1$s">%2$s</a>',
 812                      esc_url(
 813                          wp_nonce_url(
 814                              network_admin_url( 'sites.php?action=confirm&amp;action2=spamblog&amp;id=' . $blog['blog_id'] ),
 815                              'spamblog_' . $blog['blog_id']
 816                          )
 817                      ),
 818                      _x( 'Spam', 'site' )
 819                  );
 820              }
 821  
 822              if ( current_user_can( 'delete_site', $blog['blog_id'] ) ) {
 823                  $actions['delete'] = sprintf(
 824                      '<a href="%1$s">%2$s</a>',
 825                      esc_url(
 826                          wp_nonce_url(
 827                              network_admin_url( 'sites.php?action=confirm&amp;action2=deleteblog&amp;id=' . $blog['blog_id'] ),
 828                              'deleteblog_' . $blog['blog_id']
 829                          )
 830                      ),
 831                      __( 'Delete' )
 832                  );
 833              }
 834          }
 835  
 836          $actions['visit'] = sprintf(
 837              '<a href="%1$s" rel="bookmark">%2$s</a>',
 838              esc_url( get_home_url( $blog['blog_id'], '/' ) ),
 839              __( 'Visit' )
 840          );
 841  
 842          /**
 843           * Filters the action links displayed for each site in the Sites list table.
 844           *
 845           * The 'Edit', 'Dashboard', 'Delete', and 'Visit' links are displayed by
 846           * default for each site. The site's status determines whether to show the
 847           * 'Activate' or 'Deactivate' link, 'Unarchive' or 'Archive' links, and
 848           * 'Not Spam' or 'Spam' link for each site.
 849           *
 850           * @since 3.1.0
 851           *
 852           * @param string[] $actions  An array of action links to be displayed.
 853           * @param int      $blog_id  The site ID.
 854           * @param string   $blogname Site path, formatted depending on whether it is a sub-domain
 855           *                           or subdirectory multisite installation.
 856           */
 857          $actions = apply_filters( 'manage_sites_action_links', array_filter( $actions ), $blog['blog_id'], $blogname );
 858  
 859          return $this->row_actions( $actions );
 860      }
 861  }


Generated : Tue Mar 19 08:20:01 2024 Cross-referenced by PHPXref