WP_MS_Sites_List_Table::prepare_items() – Prepares the list of sites for display.

You appear to be a bot. Output may be restricted

Description

Prepares the list of sites for display.

Usage

WP_MS_Sites_List_Table::prepare_items();

Parameters

Returns

void

Source

File name: wordpress/wp-admin/includes/class-wp-ms-sites-list-table.php
Lines:

1 to 100 of 134
  public function prepare_items() {
    global $mode, $s, $wpdb;

    if ( ! empty( $_REQUEST['mode'] ) ) {
      $mode = 'excerpt' === $_REQUEST['mode'] ? 'excerpt' : 'list';
      set_user_setting( 'sites_list_mode', $mode );
    } else {
      $mode = get_user_setting( 'sites_list_mode', 'list' );
    }

    $per_page = $this->get_items_per_page( 'sites_network_per_page' );

    $pagenum = $this->get_pagenum();

    $s    = isset( $_REQUEST['s'] ) ? wp_unslash( trim( $_REQUEST['s'] ) ) : '';
    $wild = '';
    if ( false !== strpos( $s, '*' ) ) {
      $wild = '*';
      $s    = trim( $s, '*' );
    }

    /*
		 * If the network is large and a search is not being performed, show only
		 * the latest sites with no paging in order to avoid expensive count queries.
		 */
    if ( ! $s && wp_is_large_network() ) {
      if ( ! isset( $_REQUEST['orderby'] ) ) {
        $_GET['orderby']     = '';
        $_REQUEST['orderby'] = '';
      }
      if ( ! isset( $_REQUEST['order'] ) ) {
        $_GET['order']     = 'DESC';
        $_REQUEST['order'] = 'DESC';
      }
    }

    $args = array(
      'number'     => (int) $per_page,
      'offset'     => (int) ( ( $pagenum - 1 ) * $per_page ),
      'network_id' => get_current_network_id(),
    );

    if ( empty( $s ) ) {
      // Nothing to do.
    } elseif ( preg_match( '/^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$/', $s ) ||
          preg_match( '/^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.?$/', $s ) ||
          preg_match( '/^[0-9]{1,3}\.[0-9]{1,3}\.?$/', $s ) ||
          preg_match( '/^[0-9]{1,3}\.$/', $s ) ) {
      // IPv4 address.
      $sql          = $wpdb->prepare( "SELECT blog_id FROM {$wpdb->registration_log} WHERE {$wpdb->registration_log}.IP LIKE %s", $wpdb->esc_like( $s ) . ( ! empty( $wild ) ? '%' : '' ) );
      $reg_blog_ids = $wpdb->get_col( $sql );

      if ( $reg_blog_ids ) {
        $args['site__in'] = $reg_blog_ids;
      }
    } elseif ( is_numeric( $s ) && empty( $wild ) ) {
      $args['ID'] = $s;
    } else {
      $args['search'] = $s;

      if ( ! is_subdomain_install() ) {
        $args['search_columns'] = array( 'path' );
      }
    }

    $order_by = isset( $_REQUEST['orderby'] ) ? $_REQUEST['orderby'] : '';
    if ( 'registered' === $order_by ) {
      // 'registered' is a valid field name.
    } elseif ( 'lastupdated' === $order_by ) {
      $order_by = 'last_updated';
    } elseif ( 'blogname' === $order_by ) {
      if ( is_subdomain_install() ) {
        $order_by = 'domain';
      } else {
        $order_by = 'path';
      }
    } elseif ( 'blog_id' === $order_by ) {
      $order_by = 'id';
    } elseif ( ! $order_by ) {
      $order_by = false;
    }

    $args['orderby'] = $order_by;

    if ( $order_by ) {
      $args['order'] = ( isset( $_REQUEST['order'] ) && 'DESC' === strtoupper( $_REQUEST['order'] ) ) ? 'DESC' : 'ASC';
    }

    if ( wp_is_large_network() ) {
      $args['no_found_rows'] = true;
    } else {
      $args['no_found_rows'] = false;
    }

    // Take into account the role the user has selected.
    $status = isset( $_REQUEST['status'] ) ? wp_unslash( trim( $_REQUEST['status'] ) ) : '';
    if ( in_array( $status, array( 'public', 'archived', 'mature', 'spam', 'deleted' ), true ) ) {
      $args[ $status ] = 1;
    }

 

 View on GitHub View on Trac