[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

title

Body

[close]

/wp-admin/network/ -> sites.php (source)

   1  <?php
   2  /**
   3   * Multisite sites administration panel.
   4   *
   5   * @package WordPress
   6   * @subpackage Multisite
   7   * @since 3.0.0
   8   */
   9  
  10  /** Load WordPress Administration Bootstrap */
  11  require_once( dirname( __FILE__ ) . '/admin.php' );
  12  
  13  if ( ! current_user_can( 'manage_sites' ) ) {
  14      wp_die( __( 'Sorry, you are not allowed to access this page.' ), 403 );
  15  }
  16  
  17  $wp_list_table = _get_list_table( 'WP_MS_Sites_List_Table' );
  18  $pagenum       = $wp_list_table->get_pagenum();
  19  
  20  $title       = __( 'Sites' );
  21  $parent_file = 'sites.php';
  22  
  23  add_screen_option( 'per_page' );
  24  
  25  get_current_screen()->add_help_tab(
  26      array(
  27          'id'      => 'overview',
  28          'title'   => __( 'Overview' ),
  29          'content' =>
  30              '<p>' . __( 'Add New takes you to the Add New Site screen. You can search for a site by Name, ID number, or IP address. Screen Options allows you to choose how many sites to display on one page.' ) . '</p>' .
  31              '<p>' . __( 'This is the main table of all sites on this network. Switch between list and excerpt views by using the icons above the right side of the table.' ) . '</p>' .
  32              '<p>' . __( 'Hovering over each site reveals seven options (three for the primary site):' ) . '</p>' .
  33              '<ul><li>' . __( 'An Edit link to a separate Edit Site screen.' ) . '</li>' .
  34              '<li>' . __( 'Dashboard leads to the Dashboard for that site.' ) . '</li>' .
  35              '<li>' . __( 'Deactivate, Archive, and Spam which lead to confirmation screens. These actions can be reversed later.' ) . '</li>' .
  36              '<li>' . __( 'Delete which is a permanent action after the confirmation screens.' ) . '</li>' .
  37              '<li>' . __( 'Visit to go to the front-end site live.' ) . '</li></ul>' .
  38              '<p>' . __( 'The site ID is used internally, and is not shown on the front end of the site or to users/viewers.' ) . '</p>' .
  39              '<p>' . __( 'Clicking on bold headings can re-sort this table.' ) . '</p>',
  40      )
  41  );
  42  
  43  get_current_screen()->set_help_sidebar(
  44      '<p><strong>' . __( 'For more information:' ) . '</strong></p>' .
  45      '<p>' . __( '<a href="https://wordpress.org/support/article/network-admin-sites-screen/">Documentation on Site Management</a>' ) . '</p>' .
  46      '<p>' . __( '<a href="https://wordpress.org/support/forum/multisite/">Support Forums</a>' ) . '</p>'
  47  );
  48  
  49  get_current_screen()->set_screen_reader_content(
  50      array(
  51          'heading_pagination' => __( 'Sites list navigation' ),
  52          'heading_list'       => __( 'Sites list' ),
  53      )
  54  );
  55  
  56  $id = isset( $_REQUEST['id'] ) ? intval( $_REQUEST['id'] ) : 0;
  57  
  58  if ( isset( $_GET['action'] ) ) {
  59      /** This action is documented in wp-admin/network/edit.php */
  60      do_action( 'wpmuadminedit' );
  61  
  62      // A list of valid actions and their associated messaging for confirmation output.
  63      $manage_actions = array(
  64          /* translators: %s: Site URL. */
  65          'activateblog'   => __( 'You are about to activate the site %s.' ),
  66          /* translators: %s: Site URL. */
  67          'deactivateblog' => __( 'You are about to deactivate the site %s.' ),
  68          /* translators: %s: Site URL. */
  69          'unarchiveblog'  => __( 'You are about to unarchive the site %s.' ),
  70          /* translators: %s: Site URL. */
  71          'archiveblog'    => __( 'You are about to archive the site %s.' ),
  72          /* translators: %s: Site URL. */
  73          'unspamblog'     => __( 'You are about to unspam the site %s.' ),
  74          /* translators: %s: Site URL. */
  75          'spamblog'       => __( 'You are about to mark the site %s as spam.' ),
  76          /* translators: %s: Site URL. */
  77          'deleteblog'     => __( 'You are about to delete the site %s.' ),
  78          /* translators: %s: Site URL. */
  79          'unmatureblog'   => __( 'You are about to mark the site %s as mature.' ),
  80          /* translators: %s: Site URL. */
  81          'matureblog'     => __( 'You are about to mark the site %s as not mature.' ),
  82      );
  83  
  84      if ( 'confirm' === $_GET['action'] ) {
  85          // The action2 parameter contains the action being taken on the site.
  86          $site_action = $_GET['action2'];
  87  
  88          if ( ! array_key_exists( $site_action, $manage_actions ) ) {
  89              wp_die( __( 'The requested action is not valid.' ) );
  90          }
  91  
  92          // The mature/unmature UI exists only as external code. Check the "confirm" nonce for backward compatibility.
  93          if ( 'matureblog' === $site_action || 'unmatureblog' === $site_action ) {
  94              check_admin_referer( 'confirm' );
  95          } else {
  96              check_admin_referer( $site_action . '_' . $id );
  97          }
  98  
  99          if ( ! headers_sent() ) {
 100              nocache_headers();
 101              header( 'Content-Type: text/html; charset=utf-8' );
 102          }
 103  
 104          if ( get_network()->site_id == $id ) {
 105              wp_die( __( 'Sorry, you are not allowed to change the current site.' ) );
 106          }
 107  
 108          $site_details = get_site( $id );
 109          $site_address = untrailingslashit( $site_details->domain . $site_details->path );
 110  
 111          require_once ( ABSPATH . 'wp-admin/admin-header.php' );
 112          ?>
 113              <div class="wrap">
 114                  <h1><?php _e( 'Confirm your action' ); ?></h1>
 115                  <form action="sites.php?action=<?php echo esc_attr( $site_action ); ?>" method="post">
 116                      <input type="hidden" name="action" value="<?php echo esc_attr( $site_action ); ?>" />
 117                      <input type="hidden" name="id" value="<?php echo esc_attr( $id ); ?>" />
 118                      <input type="hidden" name="_wp_http_referer" value="<?php echo esc_attr( wp_get_referer() ); ?>" />
 119                      <?php wp_nonce_field( $site_action . '_' . $id, '_wpnonce', false ); ?>
 120                      <p><?php echo sprintf( $manage_actions[ $site_action ], $site_address ); ?></p>
 121                      <?php submit_button( __( 'Confirm' ), 'primary' ); ?>
 122                  </form>
 123              </div>
 124          <?php
 125          require_once ( ABSPATH . 'wp-admin/admin-footer.php' );
 126          exit();
 127      } elseif ( array_key_exists( $_GET['action'], $manage_actions ) ) {
 128          $action = $_GET['action'];
 129          check_admin_referer( $action . '_' . $id );
 130      } elseif ( 'allblogs' === $_GET['action'] ) {
 131          check_admin_referer( 'bulk-sites' );
 132      }
 133  
 134      $updated_action = '';
 135  
 136      switch ( $_GET['action'] ) {
 137  
 138          case 'deleteblog':
 139              if ( ! current_user_can( 'delete_sites' ) ) {
 140                  wp_die( __( 'Sorry, you are not allowed to access this page.' ), '', array( 'response' => 403 ) );
 141              }
 142  
 143              $updated_action = 'not_deleted';
 144              if ( $id != '0' && $id != get_network()->site_id && current_user_can( 'delete_site', $id ) ) {
 145                  wpmu_delete_blog( $id, true );
 146                  $updated_action = 'delete';
 147              }
 148              break;
 149  
 150          case 'delete_sites':
 151              check_admin_referer( 'ms-delete-sites' );
 152  
 153              foreach ( (array) $_POST['site_ids'] as $site_id ) {
 154                  $site_id = (int) $site_id;
 155  
 156                  if ( $site_id == get_network()->site_id ) {
 157                      continue;
 158                  }
 159  
 160                  if ( ! current_user_can( 'delete_site', $site_id ) ) {
 161                      $site         = get_site( $site_id );
 162                      $site_address = untrailingslashit( $site->domain . $site->path );
 163  
 164                      wp_die(
 165                          sprintf(
 166                              /* translators: %s: Site URL. */
 167                              __( 'Sorry, you are not allowed to delete the site %s.' ),
 168                              $site_address
 169                          ),
 170                          403
 171                      );
 172                  }
 173  
 174                  $updated_action = 'all_delete';
 175                  wpmu_delete_blog( $site_id, true );
 176              }
 177              break;
 178  
 179          case 'allblogs':
 180              if ( ( isset( $_POST['action'] ) || isset( $_POST['action2'] ) ) && isset( $_POST['allblogs'] ) ) {
 181                  $doaction = $_POST['action'] != -1 ? $_POST['action'] : $_POST['action2'];
 182  
 183                  foreach ( (array) $_POST['allblogs'] as $key => $val ) {
 184                      if ( $val != '0' && $val != get_network()->site_id ) {
 185                          switch ( $doaction ) {
 186                              case 'delete':
 187                                  require_once ( ABSPATH . 'wp-admin/admin-header.php' );
 188                                  ?>
 189                                  <div class="wrap">
 190                                      <h1><?php _e( 'Confirm your action' ); ?></h1>
 191                                      <form action="sites.php?action=delete_sites" method="post">
 192                                          <input type="hidden" name="action" value="delete_sites" />
 193                                          <input type="hidden" name="_wp_http_referer" value="<?php echo esc_attr( wp_get_referer() ); ?>" />
 194                                          <?php wp_nonce_field( 'ms-delete-sites', '_wpnonce', false ); ?>
 195                                          <p><?php _e( 'You are about to delete the following sites:' ); ?></p>
 196                                          <ul class="ul-disc">
 197                                              <?php
 198                                              foreach ( $_POST['allblogs'] as $site_id ) :
 199                                                  $site         = get_site( $site_id );
 200                                                  $site_address = untrailingslashit( $site->domain . $site->path );
 201                                                  ?>
 202                                                  <li>
 203                                                      <?php echo $site_address; ?>
 204                                                      <input type="hidden" name="site_ids[]" value="<?php echo (int) $site_id; ?>" />
 205                                                  </li>
 206                                              <?php endforeach; ?>
 207                                          </ul>
 208                                          <?php submit_button( __( 'Confirm' ), 'primary' ); ?>
 209                                      </form>
 210                                  </div>
 211                                  <?php
 212                                  require_once ( ABSPATH . 'wp-admin/admin-footer.php' );
 213                                  exit();
 214                              break;
 215  
 216                              case 'spam':
 217                              case 'notspam':
 218                                  $updated_action = ( 'spam' === $doaction ) ? 'all_spam' : 'all_notspam';
 219                                  update_blog_status( $val, 'spam', ( 'spam' === $doaction ) ? '1' : '0' );
 220                                  break;
 221                          }
 222                      } else {
 223                          wp_die( __( 'Sorry, you are not allowed to change the current site.' ) );
 224                      }
 225                  }
 226                  if ( ! in_array( $doaction, array( 'delete', 'spam', 'notspam' ), true ) ) {
 227                      $redirect_to = wp_get_referer();
 228                      $blogs       = (array) $_POST['allblogs'];
 229                      /** This action is documented in wp-admin/network/site-themes.php */
 230                      $redirect_to = apply_filters( 'handle_network_bulk_actions-' . get_current_screen()->id, $redirect_to, $doaction, $blogs, $id ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
 231                      wp_safe_redirect( $redirect_to );
 232                      exit();
 233                  }
 234              } else {
 235                  // Process query defined by WP_MS_Site_List_Table::extra_table_nav().
 236                  $location = remove_query_arg(
 237                      array( '_wp_http_referer', '_wpnonce' ),
 238                      add_query_arg( $_POST, network_admin_url( 'sites.php' ) )
 239                  );
 240                  wp_redirect( $location );
 241                  exit;
 242              }
 243  
 244              break;
 245  
 246          case 'archiveblog':
 247          case 'unarchiveblog':
 248              update_blog_status( $id, 'archived', ( 'archiveblog' === $_GET['action'] ) ? '1' : '0' );
 249              break;
 250  
 251          case 'activateblog':
 252              update_blog_status( $id, 'deleted', '0' );
 253  
 254              /**
 255               * Fires after a network site is activated.
 256               *
 257               * @since MU (3.0.0)
 258               *
 259               * @param string $id The ID of the activated site.
 260               */
 261              do_action( 'activate_blog', $id );
 262              break;
 263  
 264          case 'deactivateblog':
 265              /**
 266               * Fires before a network site is deactivated.
 267               *
 268               * @since MU (3.0.0)
 269               *
 270               * @param string $id The ID of the site being deactivated.
 271               */
 272              do_action( 'deactivate_blog', $id );
 273              update_blog_status( $id, 'deleted', '1' );
 274              break;
 275  
 276          case 'unspamblog':
 277          case 'spamblog':
 278              update_blog_status( $id, 'spam', ( 'spamblog' === $_GET['action'] ) ? '1' : '0' );
 279              break;
 280  
 281          case 'unmatureblog':
 282          case 'matureblog':
 283              update_blog_status( $id, 'mature', ( 'matureblog' === $_GET['action'] ) ? '1' : '0' );
 284              break;
 285      }
 286  
 287      if ( empty( $updated_action ) && array_key_exists( $_GET['action'], $manage_actions ) ) {
 288          $updated_action = $_GET['action'];
 289      }
 290  
 291      if ( ! empty( $updated_action ) ) {
 292          wp_safe_redirect( add_query_arg( array( 'updated' => $updated_action ), wp_get_referer() ) );
 293          exit();
 294      }
 295  }
 296  
 297  $msg = '';
 298  if ( isset( $_GET['updated'] ) ) {
 299      $action = $_GET['updated'];
 300  
 301      switch ( $action ) {
 302          case 'all_notspam':
 303              $msg = __( 'Sites removed from spam.' );
 304              break;
 305          case 'all_spam':
 306              $msg = __( 'Sites marked as spam.' );
 307              break;
 308          case 'all_delete':
 309              $msg = __( 'Sites deleted.' );
 310              break;
 311          case 'delete':
 312              $msg = __( 'Site deleted.' );
 313              break;
 314          case 'not_deleted':
 315              $msg = __( 'Sorry, you are not allowed to delete that site.' );
 316              break;
 317          case 'archiveblog':
 318              $msg = __( 'Site archived.' );
 319              break;
 320          case 'unarchiveblog':
 321              $msg = __( 'Site unarchived.' );
 322              break;
 323          case 'activateblog':
 324              $msg = __( 'Site activated.' );
 325              break;
 326          case 'deactivateblog':
 327              $msg = __( 'Site deactivated.' );
 328              break;
 329          case 'unspamblog':
 330              $msg = __( 'Site removed from spam.' );
 331              break;
 332          case 'spamblog':
 333              $msg = __( 'Site marked as spam.' );
 334              break;
 335          default:
 336              /**
 337               * Filters a specific, non-default, site-updated message in the Network admin.
 338               *
 339               * The dynamic portion of the hook name, `$action`, refers to the non-default
 340               * site update action.
 341               *
 342               * @since 3.1.0
 343               *
 344               * @param string $msg The update message. Default 'Settings saved'.
 345               */
 346              $msg = apply_filters( "network_sites_updated_message_{$action}", __( 'Settings saved.' ) );
 347              break;
 348      }
 349  
 350      if ( ! empty( $msg ) ) {
 351          $msg = '<div id="message" class="updated notice is-dismissible"><p>' . $msg . '</p></div>';
 352      }
 353  }
 354  
 355  $wp_list_table->prepare_items();
 356  
 357  require_once ( ABSPATH . 'wp-admin/admin-header.php' );
 358  ?>
 359  
 360  <div class="wrap">
 361  <h1 class="wp-heading-inline"><?php _e( 'Sites' ); ?></h1>
 362  
 363  <?php if ( current_user_can( 'create_sites' ) ) : ?>
 364      <a href="<?php echo network_admin_url( 'site-new.php' ); ?>" class="page-title-action"><?php echo esc_html_x( 'Add New', 'site' ); ?></a>
 365  <?php endif; ?>
 366  
 367  <?php
 368  if ( isset( $_REQUEST['s'] ) && strlen( $_REQUEST['s'] ) ) {
 369      /* translators: %s: Search query. */
 370      printf( '<span class="subtitle">' . __( 'Search results for &#8220;%s&#8221;' ) . '</span>', esc_html( $s ) );
 371  }
 372  ?>
 373  
 374  <hr class="wp-header-end">
 375  
 376  <?php $wp_list_table->views(); ?>
 377  
 378  <?php echo $msg; ?>
 379  
 380  <form method="get" id="ms-search" class="wp-clearfix">
 381  <?php $wp_list_table->search_box( __( 'Search Sites' ), 'site' ); ?>
 382  <input type="hidden" name="action" value="blogs" />
 383  </form>
 384  
 385  <form id="form-site-list" action="sites.php?action=allblogs" method="post">
 386      <?php $wp_list_table->display(); ?>
 387  </form>
 388  </div>
 389  <?php
 390  
 391  require_once ( ABSPATH . 'wp-admin/admin-footer.php' ); ?>


Generated: Wed Oct 23 08:20:01 2019 Cross-referenced by PHPXref 0.7