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


Generated : Thu Nov 21 08:20:01 2024 Cross-referenced by PHPXref