[ 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( dirname( __FILE__ ) . '/admin.php' );
  12  
  13  if ( ! is_multisite() )
  14      wp_die( __( 'Multisite support is not enabled.' ) );
  15  
  16  if ( ! current_user_can( 'manage_sites' ) )
  17      wp_die( __( 'You do not have permission to access this page.' ), 403 );
  18  
  19  $wp_list_table = _get_list_table( 'WP_MS_Sites_List_Table' );
  20  $pagenum = $wp_list_table->get_pagenum();
  21  
  22  $title = __( 'Sites' );
  23  $parent_file = 'sites.php';
  24  
  25  add_screen_option( 'per_page' );
  26  
  27  get_current_screen()->add_help_tab( 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 frontend 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  get_current_screen()->set_help_sidebar(
  44      '<p><strong>' . __('For more information:') . '</strong></p>' .
  45      '<p>' . __('<a href="https://codex.wordpress.org/Network_Admin_Sites_Screen" target="_blank">Documentation on Site Management</a>') . '</p>' .
  46      '<p>' . __('<a href="https://wordpress.org/support/forum/multisite/" target="_blank">Support Forums</a>') . '</p>'
  47  );
  48  
  49  get_current_screen()->set_screen_reader_content( array(
  50      'heading_pagination' => __( 'Sites list navigation' ),
  51      'heading_list'       => __( 'Sites list' ),
  52  ) );
  53  
  54  $id = isset( $_REQUEST['id'] ) ? intval( $_REQUEST['id'] ) : 0;
  55  
  56  if ( isset( $_GET['action'] ) ) {
  57      /** This action is documented in wp-admin/network/edit.php */
  58      do_action( 'wpmuadminedit' );
  59  
  60      // A list of valid actions and their associated messaging for confirmation output.
  61      $manage_actions = array(
  62          'activateblog'   => __( 'You are about to activate the site %s' ),
  63          'deactivateblog' => __( 'You are about to deactivate the site %s' ),
  64          'unarchiveblog'  => __( 'You are about to unarchive the site %s.' ),
  65          'archiveblog'    => __( 'You are about to archive the site %s.' ),
  66          'unspamblog'     => __( 'You are about to unspam the site %s.' ),
  67          'spamblog'       => __( 'You are about to mark the site %s as spam.' ),
  68          'deleteblog'     => __( 'You are about to delete the site %s.' ),
  69          'unmatureblog'   => __( 'You are about to mark the site %s as mature.' ),
  70          'matureblog'     => __( 'You are about to mark the site %s as not mature.' ),
  71      );
  72  
  73      if ( 'confirm' === $_GET['action'] ) {
  74          // The action2 parameter contains the action being taken on the site.
  75          $site_action = $_GET['action2'];
  76  
  77          if ( ! array_key_exists( $site_action, $manage_actions ) ) {
  78              wp_die( __( 'The requested action is not valid.' ) );
  79          }
  80  
  81          // The mature/unmature UI exists only as external code. Check the "confirm" nonce for backward compatibility.
  82          if ( 'matureblog' === $site_action || 'unmatureblog' === $site_action ) {
  83              check_admin_referer( 'confirm' );
  84          } else {
  85              check_admin_referer( $site_action . '_' . $id );
  86          }
  87  
  88          if ( ! headers_sent() ) {
  89              nocache_headers();
  90              header( 'Content-Type: text/html; charset=utf-8' );
  91          }
  92  
  93          if ( $current_site->blog_id == $id ) {
  94              wp_die( __( 'You are not allowed to change the current site.' ) );
  95          }
  96  
  97          $site_details = get_blog_details( $id );
  98          $site_address = untrailingslashit( $site_details->domain . $site_details->path );
  99  
 100          require_once ( ABSPATH . 'wp-admin/admin-header.php' );
 101          ?>
 102              <div class="wrap">
 103                  <h1><?php _e( 'Confirm your action' ); ?></h1>
 104                  <form action="sites.php?action=<?php echo esc_attr( $site_action ); ?>" method="post">
 105                      <input type="hidden" name="action" value="<?php echo esc_attr( $site_action ); ?>" />
 106                      <input type="hidden" name="id" value="<?php echo esc_attr( $id ); ?>" />
 107                      <input type="hidden" name="_wp_http_referer" value="<?php echo esc_attr( wp_get_referer() ); ?>" />
 108                      <?php wp_nonce_field( $site_action . '_' . $id, '_wpnonce', false ); ?>
 109                      <p><?php echo sprintf( $manage_actions[ $site_action ], $site_address ); ?></p>
 110                      <?php submit_button( __( 'Confirm' ), 'primary' ); ?>
 111                  </form>
 112              </div>
 113          <?php
 114          require_once ( ABSPATH . 'wp-admin/admin-footer.php' );
 115          exit();
 116      } elseif ( array_key_exists( $_GET['action'], $manage_actions ) ) {
 117          $action = $_GET['action'];
 118          check_admin_referer( $action . '_' . $id );
 119      } elseif ( 'allblogs' === $_GET['action'] ) {
 120          check_admin_referer( 'bulk-sites' );
 121      }
 122  
 123      $updated_action = '';
 124  
 125      switch ( $_GET['action'] ) {
 126  
 127          case 'deleteblog':
 128              if ( ! current_user_can( 'delete_sites' ) )
 129                  wp_die( __( 'You do not have permission to access this page.' ), '', array( 'response' => 403 ) );
 130  
 131              $updated_action = 'not_deleted';
 132              if ( $id != '0' && $id != $current_site->blog_id && current_user_can( 'delete_site', $id ) ) {
 133                  wpmu_delete_blog( $id, true );
 134                  $updated_action = 'delete';
 135              }
 136          break;
 137  
 138          case 'allblogs':
 139              if ( ( isset( $_POST['action'] ) || isset( $_POST['action2'] ) ) && isset( $_POST['allblogs'] ) ) {
 140                  $doaction = $_POST['action'] != -1 ? $_POST['action'] : $_POST['action2'];
 141  
 142                  foreach ( (array) $_POST['allblogs'] as $key => $val ) {
 143                      if ( $val != '0' && $val != $current_site->blog_id ) {
 144                          switch ( $doaction ) {
 145                              case 'delete':
 146                                  if ( ! current_user_can( 'delete_site', $val ) )
 147                                      wp_die( __( 'You are not allowed to delete the site.' ) );
 148  
 149                                  $updated_action = 'all_delete';
 150                                  wpmu_delete_blog( $val, true );
 151                              break;
 152  
 153                              case 'spam':
 154                              case 'notspam':
 155                                  $updated_action = ( 'spam' === $doaction ) ? 'all_spam' : 'all_notspam';
 156                                  update_blog_status( $val, 'spam', ( 'spam' === $doaction ) ? '1' : '0' );
 157                              break;
 158                          }
 159                      } else {
 160                          wp_die( __( 'You are not allowed to change the current site.' ) );
 161                      }
 162                  }
 163              } else {
 164                  $location = network_admin_url( 'sites.php' );
 165                  if ( ! empty( $_REQUEST['paged'] ) ) {
 166                      $location = add_query_arg( 'paged', (int) $_REQUEST['paged'], $location );
 167                  }
 168                  wp_redirect( $location );
 169                  exit();
 170              }
 171          break;
 172  
 173          case 'archiveblog':
 174          case 'unarchiveblog':
 175              update_blog_status( $id, 'archived', ( 'archiveblog' === $_GET['action'] ) ? '1' : '0' );
 176          break;
 177  
 178          case 'activateblog':
 179              update_blog_status( $id, 'deleted', '0' );
 180  
 181              /**
 182               * Fires after a network site is activated.
 183               *
 184               * @since MU
 185               *
 186               * @param string $id The ID of the activated site.
 187               */
 188              do_action( 'activate_blog', $id );
 189          break;
 190  
 191          case 'deactivateblog':
 192              /**
 193               * Fires before a network site is deactivated.
 194               *
 195               * @since MU
 196               *
 197               * @param string $id The ID of the site being deactivated.
 198               */
 199              do_action( 'deactivate_blog', $id );
 200              update_blog_status( $id, 'deleted', '1' );
 201          break;
 202  
 203          case 'unspamblog':
 204          case 'spamblog':
 205              update_blog_status( $id, 'spam', ( 'spamblog' === $_GET['action'] ) ? '1' : '0' );
 206          break;
 207  
 208          case 'unmatureblog':
 209          case 'matureblog':
 210              update_blog_status( $id, 'mature', ( 'matureblog' === $_GET['action'] ) ? '1' : '0' );
 211          break;
 212      }
 213  
 214      if ( empty( $updated_action ) && array_key_exists( $_GET['action'], $manage_actions ) ) {
 215          $updated_action = $_GET['action'];
 216      }
 217  
 218      if ( ! empty( $updated_action ) ) {
 219          wp_safe_redirect( add_query_arg( array( 'updated' => $updated_action ), wp_get_referer() ) );
 220          exit();
 221      }
 222  }
 223  
 224  $msg = '';
 225  if ( isset( $_GET['updated'] ) ) {
 226      switch ( $_GET['updated'] ) {
 227          case 'all_notspam':
 228              $msg = __( 'Sites removed from spam.' );
 229          break;
 230          case 'all_spam':
 231              $msg = __( 'Sites marked as spam.' );
 232          break;
 233          case 'all_delete':
 234              $msg = __( 'Sites deleted.' );
 235          break;
 236          case 'delete':
 237              $msg = __( 'Site deleted.' );
 238          break;
 239          case 'not_deleted':
 240              $msg = __( 'You do not have permission to delete that site.' );
 241          break;
 242          case 'archiveblog':
 243              $msg = __( 'Site archived.' );
 244          break;
 245          case 'unarchiveblog':
 246              $msg = __( 'Site unarchived.' );
 247          break;
 248          case 'activateblog':
 249              $msg = __( 'Site activated.' );
 250          break;
 251          case 'deactivateblog':
 252              $msg = __( 'Site deactivated.' );
 253          break;
 254          case 'unspamblog':
 255              $msg = __( 'Site removed from spam.' );
 256          break;
 257          case 'spamblog':
 258              $msg = __( 'Site marked as spam.' );
 259          break;
 260          default:
 261              /**
 262               * Filter a specific, non-default site-updated message in the Network admin.
 263               *
 264               * The dynamic portion of the hook name, `$_GET['updated']`, refers to the
 265               * non-default site update action.
 266               *
 267               * @since 3.1.0
 268               *
 269               * @param string $msg The update message. Default 'Settings saved'.
 270               */
 271              $msg = apply_filters( 'network_sites_updated_message_' . $_GET['updated'], __( 'Settings saved.' ) );
 272          break;
 273      }
 274  
 275      if ( ! empty( $msg ) )
 276          $msg = '<div class="updated" id="message notice is-dismissible"><p>' . $msg . '</p></div>';
 277  }
 278  
 279  $wp_list_table->prepare_items();
 280  
 281  require_once ( ABSPATH . 'wp-admin/admin-header.php' );
 282  ?>
 283  
 284  <div class="wrap">
 285  <h1><?php _e( 'Sites' ); ?>
 286  
 287  <?php if ( current_user_can( 'create_sites') ) : ?>
 288      <a href="<?php echo network_admin_url('site-new.php'); ?>" class="page-title-action"><?php echo esc_html_x( 'Add New', 'site' ); ?></a>
 289  <?php endif; ?>
 290  
 291  <?php
 292  if ( isset( $_REQUEST['s'] ) && strlen( $_REQUEST['s'] ) ) {
 293      /* translators: %s: search keywords */
 294      printf( '<span class="subtitle">' . __( 'Search results for &#8220;%s&#8221;' ) . '</span>', esc_html( $s ) );
 295  } ?>
 296  </h1>
 297  
 298  <?php echo $msg; ?>
 299  
 300  <form method="get" id="ms-search">
 301  <?php $wp_list_table->search_box( __( 'Search Sites' ), 'site' ); ?>
 302  <input type="hidden" name="action" value="blogs" />
 303  </form>
 304  
 305  <form id="form-site-list" action="sites.php?action=allblogs" method="post">
 306      <?php $wp_list_table->display(); ?>
 307  </form>
 308  </div>
 309  <?php
 310  
 311  require_once ( ABSPATH . 'wp-admin/admin-footer.php' ); ?>


Generated: Sun Feb 14 03:55:51 2016 Hosted by follow the white rabbit.