[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

Search

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


Generated : Fri Mar 29 08:20:02 2024 Cross-referenced by PHPXref