[ Index ]

PHP Cross Reference of WordPress

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://wordpress.org/support/article/network-admin-sites-screen/">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 ( get_network()->site_id == $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 && get_network()->site_id != $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 ( get_network()->site_id == $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 $key => $val ) {
 185                      if ( '0' != $val && get_network()->site_id != $val ) {
 186                          switch ( $doaction ) {
 187                              case 'delete':
 188                                  require_once ABSPATH . 'wp-admin/admin-header.php';
 189                                  ?>
 190                                  <div class="wrap">
 191                                      <h1><?php _e( 'Confirm your action' ); ?></h1>
 192                                      <form action="sites.php?action=delete_sites" method="post">
 193                                          <input type="hidden" name="action" value="delete_sites" />
 194                                          <input type="hidden" name="_wp_http_referer" value="<?php echo esc_attr( wp_get_referer() ); ?>" />
 195                                          <?php wp_nonce_field( 'ms-delete-sites', '_wpnonce', false ); ?>
 196                                          <p><?php _e( 'You are about to delete the following sites:' ); ?></p>
 197                                          <ul class="ul-disc">
 198                                              <?php
 199                                              foreach ( $_POST['allblogs'] as $site_id ) :
 200                                                  $site         = get_site( $site_id );
 201                                                  $site_address = untrailingslashit( $site->domain . $site->path );
 202                                                  ?>
 203                                                  <li>
 204                                                      <?php echo $site_address; ?>
 205                                                      <input type="hidden" name="site_ids[]" value="<?php echo (int) $site_id; ?>" />
 206                                                  </li>
 207                                              <?php endforeach; ?>
 208                                          </ul>
 209                                          <?php submit_button( __( 'Confirm' ), 'primary' ); ?>
 210                                      </form>
 211                                  </div>
 212                                  <?php
 213                                  require_once ABSPATH . 'wp-admin/admin-footer.php';
 214                                  exit;
 215                              break;
 216  
 217                              case 'spam':
 218                              case 'notspam':
 219                                  $updated_action = ( 'spam' === $doaction ) ? 'all_spam' : 'all_notspam';
 220                                  update_blog_status( $val, 'spam', ( 'spam' === $doaction ) ? '1' : '0' );
 221                                  break;
 222                          }
 223                      } else {
 224                          wp_die( __( 'Sorry, you are not allowed to change the current site.' ) );
 225                      }
 226                  }
 227  
 228                  if ( ! in_array( $doaction, array( 'delete', 'spam', 'notspam' ), true ) ) {
 229                      $redirect_to = wp_get_referer();
 230                      $blogs       = (array) $_POST['allblogs'];
 231  
 232                      /** This action is documented in wp-admin/network/site-themes.php */
 233                      $redirect_to = apply_filters( 'handle_network_bulk_actions-' . get_current_screen()->id, $redirect_to, $doaction, $blogs, $id ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
 234  
 235                      wp_safe_redirect( $redirect_to );
 236                      exit;
 237                  }
 238              } else {
 239                  // Process query defined by WP_MS_Site_List_Table::extra_table_nav().
 240                  $location = remove_query_arg(
 241                      array( '_wp_http_referer', '_wpnonce' ),
 242                      add_query_arg( $_POST, network_admin_url( 'sites.php' ) )
 243                  );
 244  
 245                  wp_redirect( $location );
 246                  exit;
 247              }
 248  
 249              break;
 250  
 251          case 'archiveblog':
 252          case 'unarchiveblog':
 253              update_blog_status( $id, 'archived', ( 'archiveblog' === $_GET['action'] ) ? '1' : '0' );
 254              break;
 255  
 256          case 'activateblog':
 257              update_blog_status( $id, 'deleted', '0' );
 258  
 259              /**
 260               * Fires after a network site is activated.
 261               *
 262               * @since MU (3.0.0)
 263               *
 264               * @param int $id The ID of the activated site.
 265               */
 266              do_action( 'activate_blog', $id );
 267              break;
 268  
 269          case 'deactivateblog':
 270              /**
 271               * Fires before a network site is deactivated.
 272               *
 273               * @since MU (3.0.0)
 274               *
 275               * @param int $id The ID of the site being deactivated.
 276               */
 277              do_action( 'deactivate_blog', $id );
 278  
 279              update_blog_status( $id, 'deleted', '1' );
 280              break;
 281  
 282          case 'unspamblog':
 283          case 'spamblog':
 284              update_blog_status( $id, 'spam', ( 'spamblog' === $_GET['action'] ) ? '1' : '0' );
 285              break;
 286  
 287          case 'unmatureblog':
 288          case 'matureblog':
 289              update_blog_status( $id, 'mature', ( 'matureblog' === $_GET['action'] ) ? '1' : '0' );
 290              break;
 291      }
 292  
 293      if ( empty( $updated_action ) && array_key_exists( $_GET['action'], $manage_actions ) ) {
 294          $updated_action = $_GET['action'];
 295      }
 296  
 297      if ( ! empty( $updated_action ) ) {
 298          wp_safe_redirect( add_query_arg( array( 'updated' => $updated_action ), wp_get_referer() ) );
 299          exit;
 300      }
 301  }
 302  
 303  $msg = '';
 304  if ( isset( $_GET['updated'] ) ) {
 305      $action = $_GET['updated'];
 306  
 307      switch ( $action ) {
 308          case 'all_notspam':
 309              $msg = __( 'Sites removed from spam.' );
 310              break;
 311          case 'all_spam':
 312              $msg = __( 'Sites marked as spam.' );
 313              break;
 314          case 'all_delete':
 315              $msg = __( 'Sites deleted.' );
 316              break;
 317          case 'delete':
 318              $msg = __( 'Site deleted.' );
 319              break;
 320          case 'not_deleted':
 321              $msg = __( 'Sorry, you are not allowed to delete that site.' );
 322              break;
 323          case 'archiveblog':
 324              $msg = __( 'Site archived.' );
 325              break;
 326          case 'unarchiveblog':
 327              $msg = __( 'Site unarchived.' );
 328              break;
 329          case 'activateblog':
 330              $msg = __( 'Site activated.' );
 331              break;
 332          case 'deactivateblog':
 333              $msg = __( 'Site deactivated.' );
 334              break;
 335          case 'unspamblog':
 336              $msg = __( 'Site removed from spam.' );
 337              break;
 338          case 'spamblog':
 339              $msg = __( 'Site marked as spam.' );
 340              break;
 341          default:
 342              /**
 343               * Filters a specific, non-default, site-updated message in the Network admin.
 344               *
 345               * The dynamic portion of the hook name, `$action`, refers to the non-default
 346               * site update action.
 347               *
 348               * @since 3.1.0
 349               *
 350               * @param string $msg The update message. Default 'Settings saved'.
 351               */
 352              $msg = apply_filters( "network_sites_updated_message_{$action}", __( 'Settings saved.' ) );
 353              break;
 354      }
 355  
 356      if ( ! empty( $msg ) ) {
 357          $msg = '<div id="message" class="updated notice is-dismissible"><p>' . $msg . '</p></div>';
 358      }
 359  }
 360  
 361  $wp_list_table->prepare_items();
 362  
 363  require_once ABSPATH . 'wp-admin/admin-header.php';
 364  ?>
 365  
 366  <div class="wrap">
 367  <h1 class="wp-heading-inline"><?php _e( 'Sites' ); ?></h1>
 368  
 369  <?php if ( current_user_can( 'create_sites' ) ) : ?>
 370      <a href="<?php echo esc_url( network_admin_url( 'site-new.php' ) ); ?>" class="page-title-action"><?php echo esc_html_x( 'Add New', 'site' ); ?></a>
 371  <?php endif; ?>
 372  
 373  <?php
 374  if ( isset( $_REQUEST['s'] ) && strlen( $_REQUEST['s'] ) ) {
 375      echo '<span class="subtitle">';
 376      printf(
 377          /* translators: %s: Search query. */
 378          __( 'Search results for: %s' ),
 379          '<strong>' . esc_html( $s ) . '</strong>'
 380      );
 381      echo '</span>';
 382  }
 383  ?>
 384  
 385  <hr class="wp-header-end">
 386  
 387  <?php $wp_list_table->views(); ?>
 388  
 389  <?php echo $msg; ?>
 390  
 391  <form method="get" id="ms-search" class="wp-clearfix">
 392  <?php $wp_list_table->search_box( __( 'Search Sites' ), 'site' ); ?>
 393  <input type="hidden" name="action" value="blogs" />
 394  </form>
 395  
 396  <form id="form-site-list" action="sites.php?action=allblogs" method="post">
 397      <?php $wp_list_table->display(); ?>
 398  </form>
 399  </div>
 400  <?php
 401  
 402  require_once ABSPATH . 'wp-admin/admin-footer.php'; ?>


Generated: Thu Apr 18 01:00:02 2024 Cross-referenced by PHPXref 0.7.1