Ejemplo n.º 1
0
/**
 * Populate the BP blogs table with existing blogs.
 *
 * @since BuddyPress (1.0.0)
 *
 * @global object $wpdb WordPress database object.
 * @uses get_users()
 * @uses bp_blogs_record_blog()
 *
 * @return bool
 */
function bp_blogs_record_existing_blogs()
{
    global $wpdb;
    // Query for all sites in network
    if (is_multisite()) {
        // Get blog ID's if not a large network
        if (!wp_is_large_network()) {
            $blog_ids = $wpdb->get_col($wpdb->prepare("SELECT blog_id FROM {$wpdb->base_prefix}blogs WHERE mature = 0 AND spam = 0 AND deleted = 0 AND site_id = %d", $wpdb->siteid));
            // If error running this query, set blog ID's to false
            if (is_wp_error($blog_ids)) {
                $blog_ids = false;
            }
            // Large networks are not currently supported
        } else {
            $blog_ids = false;
        }
        // Record a single site
    } else {
        $blog_ids = $wpdb->blogid;
    }
    // Bail if there are no blogs in the network
    if (empty($blog_ids)) {
        return false;
    }
    // Get BuddyPress
    $bp = buddypress();
    // Truncate user blogs table
    $truncate = $wpdb->query("TRUNCATE {$bp->blogs->table_name}");
    if (is_wp_error($truncate)) {
        return false;
    }
    // Truncate user blogsmeta table
    $truncate = $wpdb->query("TRUNCATE {$bp->blogs->table_name_blogmeta}");
    if (is_wp_error($truncate)) {
        return false;
    }
    // Loop through users of blogs and record the relationship
    foreach ((array) $blog_ids as $blog_id) {
        // Ensure that the cache is clear after the table TRUNCATE above
        wp_cache_delete($blog_id, 'blog_meta');
        // Get all users
        $users = get_users(array('blog_id' => $blog_id));
        // Continue on if no users exist for this site (how did this happen?)
        if (empty($users)) {
            continue;
        }
        // Loop through users and record their relationship to this blog
        foreach ((array) $users as $user) {
            bp_blogs_add_user_to_blog($user->ID, false, $blog_id);
        }
    }
    /**
     * Fires after the BP blogs tables have been populated with existing blogs.
     *
     * @since BuddyPress (2.4.0)
     */
    do_action('bp_blogs_recorded_existing_blogs');
    // No errors
    return true;
}
	/**
	 *
	 * @global string $usersearch
	 * @global string $role
	 * @global wpdb   $wpdb
	 * @global string $mode
	 */
	public function prepare_items() {
		global $usersearch, $role, $wpdb, $mode;

		$usersearch = isset( $_REQUEST['s'] ) ? wp_unslash( trim( $_REQUEST['s'] ) ) : '';

		$users_per_page = $this->get_items_per_page( 'users_network_per_page' );

		$role = isset( $_REQUEST['role'] ) ? $_REQUEST['role'] : '';

		$paged = $this->get_pagenum();

		$args = array(
			'number' => $users_per_page,
			'offset' => ( $paged-1 ) * $users_per_page,
			'search' => $usersearch,
			'blog_id' => 0,
			'fields' => 'all_with_meta'
		);

		if ( wp_is_large_network( 'users' ) )
			$args['search'] = ltrim( $args['search'], '*' );

		if ( $role == 'super' ) {
			$logins = implode( "', '", get_super_admins() );
			$args['include'] = $wpdb->get_col( "SELECT ID FROM $wpdb->users WHERE user_login IN ('$logins')" );
		}

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

		if ( isset( $_REQUEST['orderby'] ) )
			$args['orderby'] = $_REQUEST['orderby'];

		if ( isset( $_REQUEST['order'] ) )
			$args['order'] = $_REQUEST['order'];

		$mode = empty( $_REQUEST['mode'] ) ? 'list' : $_REQUEST['mode'];

		// Query the user IDs for this page
		$wp_user_search = new WP_User_Query( $args );

		$this->items = $wp_user_search->get_results();

		$this->set_pagination_args( array(
			'total_items' => $wp_user_search->get_total(),
			'per_page' => $users_per_page,
		) );
	}
 /**
  *
  * @global string $usersearch
  * @global string $role
  * @global wpdb   $wpdb
  * @global string $mode
  */
 public function prepare_items()
 {
     global $usersearch, $role, $wpdb, $mode;
     $usersearch = isset($_REQUEST['s']) ? wp_unslash(trim($_REQUEST['s'])) : '';
     $users_per_page = $this->get_items_per_page('users_network_per_page');
     $role = isset($_REQUEST['role']) ? $_REQUEST['role'] : '';
     $paged = $this->get_pagenum();
     $args = array('number' => $users_per_page, 'offset' => ($paged - 1) * $users_per_page, 'search' => $usersearch, 'blog_id' => 0, 'fields' => 'all_with_meta');
     if (wp_is_large_network('users')) {
         $args['search'] = ltrim($args['search'], '*');
     } else {
         if ('' !== $args['search']) {
             $args['search'] = trim($args['search'], '*');
             $args['search'] = '*' . $args['search'] . '*';
         }
     }
     if ($role === 'super') {
         $logins = implode("', '", get_super_admins());
         $args['include'] = $wpdb->get_col("SELECT ID FROM {$wpdb->users} WHERE user_login IN ('{$logins}')");
     }
     /*
      * If the network is large and a search is not being performed,
      * show only the latest users with no paging in order to avoid
      * expensive count queries.
      */
     if (!$usersearch && wp_is_large_network('users')) {
         if (!isset($_REQUEST['orderby'])) {
             $_GET['orderby'] = $_REQUEST['orderby'] = 'id';
         }
         if (!isset($_REQUEST['order'])) {
             $_GET['order'] = $_REQUEST['order'] = 'DESC';
         }
         $args['count_total'] = false;
     }
     if (isset($_REQUEST['orderby'])) {
         $args['orderby'] = $_REQUEST['orderby'];
     }
     if (isset($_REQUEST['order'])) {
         $args['order'] = $_REQUEST['order'];
     }
     if (!empty($_REQUEST['mode'])) {
         $mode = $_REQUEST['mode'] === 'excerpt' ? 'excerpt' : 'list';
         set_user_setting('network_users_list_mode', $mode);
     } else {
         $mode = get_user_setting('network_users_list_mode', 'list');
     }
     /** This filter is documented in wp-admin/includes/class-wp-users-list-table.php */
     $args = apply_filters('users_list_table_query_args', $args);
     // Query the user IDs for this page
     $wp_user_search = new WP_User_Query($args);
     $this->items = $wp_user_search->get_results();
     $this->set_pagination_args(array('total_items' => $wp_user_search->get_total(), 'per_page' => $users_per_page));
 }
Ejemplo n.º 4
0
 /**
  * Return translated context labels
  *
  * @return array Context label translations
  */
 public static function get_context_labels()
 {
     $labels = array();
     if (is_multisite() && !wp_is_large_network()) {
         $blogs = wp_get_sites();
         foreach ($blogs as $blog) {
             $blog_details = get_blog_details($blog['blog_id']);
             $key = sanitize_key($blog_details->blogname);
             $labels[$key] = $blog_details->blogname;
         }
     }
     return $labels;
 }
Ejemplo n.º 5
0
 /**
  * Run the deactivation script on every blog for a multisite install
  *
  * @return void
  */
 protected function multisite_deactivate()
 {
     /** @var wpdb $wpdb */
     global $wpdb;
     $site = get_current_site();
     $blog_ids = $wpdb->get_col($wpdb->prepare("SELECT blog_id FROM {$wpdb->blogs} WHERE site_id=%d", $site->id));
     $large = wp_is_large_network();
     foreach ($blog_ids as $blog) {
         set_time_limit(30);
         switch_to_blog($blog);
         $large ? $this->short_blog_deactivate() : $this->blog_deactivate();
         restore_current_blog();
     }
 }
 /**
  * Thanks to Jeremy Felt.
  *
  * Source: https://jeremyfelt.com/2015/07/17/flushing-rewrite-rules-in-wordpress-multisite-for-fun-and-profit/
  */
 public function flush_rules()
 {
     if (wp_is_large_network()) {
         return;
     }
     if (isset($_GET['action']) && $_GET['action'] == 'flush-rules') {
         $sites = wp_get_sites(array('network' => 1, 'limit' => 1000));
         foreach ($sites as $site) {
             switch_to_blog($site['blog_id']);
             delete_option('rewrite_rules');
             restore_current_blog();
         }
     }
 }
 public function update_options_callback()
 {
     check_ajax_referer($_POST['referer'], 'nonce');
     if (isset($_POST['multisite'])) {
         $this->multisite = TRUE;
     }
     $this->update_option_boolean('display_deprecated');
     $this->update_option_boolean('remove_nonstandard_capabilities_restore');
     $this->update_option_boolean('override_edit_permissions');
     $this->update_option_boolean('disable_navigation_menu_permissions');
     if ($this->multisite && wp_is_large_network()) {
         $this->update_option_boolean('enable_large_network_functionalities');
     }
     if ($this->main->enable_multisite_only_options($this->multisite)) {
         $this->update_option_boolean('remove_data_on_uninstall', TRUE);
     }
     if (isset($_POST['custom-post-types'])) {
         $custom_post_types = $_POST['custom-post-types'];
         if (is_array($custom_post_types)) {
             $post_type_values = $this->customize_permission_custom_post_types();
             foreach ($custom_post_types as $key => $value) {
                 if ($value === 'true') {
                     if (!in_array($key, $post_type_values)) {
                         $post_type_values[] = $key;
                     }
                 } else {
                     if (in_array($key, $post_type_values)) {
                         $post_type_values = array_diff($post_type_values, array($key));
                     }
                 }
             }
             do_action('wpfront_ure_update_customize_permission_custom_post_types', $post_type_values, $this->customize_permission_custom_post_types());
             $this->update_option('customize_permission_custom_post_types', implode(',', $post_type_values));
         }
     }
     if ($this->multisite) {
         echo network_admin_url('admin.php?page=' . self::MENU_SLUG . '&settings-updated=true');
     } else {
         echo admin_url('admin.php?page=' . self::MENU_SLUG . '&settings-updated=true');
     }
     die;
 }
/**
 * Populate the $wpmdbpro_multisite_tools global with an instance of the WPMDBPro_Multisite_Tools class and return it.
 *
 * @param bool $cli
 *
 * @return WPMDBPro_Multisite_Tools The one true global instance of the WPMDBPro_Multisite_Tools class.
 */
function wp_migrate_db_pro_multisite_tools($cli = false)
{
    global $wpmdbpro_multisite_tools;
    if (!class_exists('WPMDBPro_Addon')) {
        return false;
    }
    // Allows hooks to bypass the regular admin / ajax checks to force load the addon (required for the CLI addon).
    $force_load = apply_filters('wp_migrate_db_pro_multisite_tools_force_load', false);
    if (false === $force_load && !is_null($wpmdbpro_multisite_tools)) {
        return $wpmdbpro_multisite_tools;
    }
    if (false === $force_load && (!function_exists('wp_migrate_db_pro_loaded') || !wp_migrate_db_pro_loaded() || is_multisite() && wp_is_large_network())) {
        return false;
    }
    load_plugin_textdomain('wp-migrate-db-pro-multisite-tools', false, dirname(plugin_basename(__FILE__)) . '/languages/');
    require_once dirname(__FILE__) . '/class/wpmdbpro-multisite-tools.php';
    if ($cli) {
        require_once dirname(__FILE__) . '/class/cli/wpmdbpro-multisite-tools-cli.php';
        $wpmdbpro_multisite_tools = new WPMDBPro_Multisite_Tools_CLI(__FILE__);
    } else {
        $wpmdbpro_multisite_tools = new WPMDBPro_Multisite_Tools(__FILE__);
    }
    return $wpmdbpro_multisite_tools;
}
Ejemplo n.º 9
0
 /**
  * Checks if a blog exists and is not marked as deleted.
  *
  * @link   http://wordpress.stackexchange.com/q/138300/73
  * @param  int $blog_id
  * @param  int $site_id
  * @return bool
  */
 function blog_exists($blog_id, $site_id = 0)
 {
     global $wpdb;
     static $cache = array();
     $site_id = (int) $site_id;
     if (!function_exists('get_current_site')) {
         return false;
     }
     if (0 === $site_id) {
         $current_site = get_current_site();
         $site_id = $current_site->id;
     }
     if (empty($cache) or empty($cache[$site_id])) {
         if (wp_is_large_network()) {
             // we do not test large sites.
             return TRUE;
         }
         $query = "SELECT `blog_id` FROM {$wpdb->blogs}\n                    WHERE site_id = {$site_id} AND deleted = 0";
         $result = $wpdb->get_col($query);
         // Make sure the array is always filled with something.
         if (empty($result)) {
             $cache[$site_id] = array('do not check again');
         } else {
             $cache[$site_id] = $result;
         }
     }
     return in_array($blog_id, $cache[$site_id]);
 }
Ejemplo n.º 10
0
/**
 * Return an array of sites for a network or networks.
 *
 * @since 3.7.0
 *
 * @global wpdb $wpdb
 *
 * @param array $args {
 *     Array of default arguments. Optional.
 *
 *     @type int|array $network_id A network ID or array of network IDs. Set to null to retrieve sites
 *                                 from all networks. Defaults to current network ID.
 *     @type int       $public     Retrieve public or non-public sites. Default null, for any.
 *     @type int       $archived   Retrieve archived or non-archived sites. Default null, for any.
 *     @type int       $mature     Retrieve mature or non-mature sites. Default null, for any.
 *     @type int       $spam       Retrieve spam or non-spam sites. Default null, for any.
 *     @type int       $deleted    Retrieve deleted or non-deleted sites. Default null, for any.
 *     @type int       $limit      Number of sites to limit the query to. Default 100.
 *     @type int       $offset     Exclude the first x sites. Used in combination with the $limit parameter. Default 0.
 * }
 * @return array An empty array if the install is considered "large" via wp_is_large_network(). Otherwise,
 *               an associative array of site data arrays, each containing the site (network) ID, blog ID,
 *               site domain and path, dates registered and modified, and the language ID. Also, boolean
 *               values for whether the site is public, archived, mature, spam, and/or deleted.
 */
function wp_get_sites($args = array())
{
    global $wpdb;
    if (wp_is_large_network()) {
        return array();
    }
    $defaults = array('network_id' => $wpdb->siteid, 'public' => null, 'archived' => null, 'mature' => null, 'spam' => null, 'deleted' => null, 'limit' => 100, 'offset' => 0);
    $args = wp_parse_args($args, $defaults);
    $query = "SELECT * FROM {$wpdb->blogs} WHERE 1=1 ";
    if (isset($args['network_id']) && (is_array($args['network_id']) || is_numeric($args['network_id']))) {
        $network_ids = implode(',', wp_parse_id_list($args['network_id']));
        $query .= "AND site_id IN ({$network_ids}) ";
    }
    if (isset($args['public'])) {
        $query .= $wpdb->prepare("AND public = %d ", $args['public']);
    }
    if (isset($args['archived'])) {
        $query .= $wpdb->prepare("AND archived = %d ", $args['archived']);
    }
    if (isset($args['mature'])) {
        $query .= $wpdb->prepare("AND mature = %d ", $args['mature']);
    }
    if (isset($args['spam'])) {
        $query .= $wpdb->prepare("AND spam = %d ", $args['spam']);
    }
    if (isset($args['deleted'])) {
        $query .= $wpdb->prepare("AND deleted = %d ", $args['deleted']);
    }
    if (isset($args['limit']) && $args['limit']) {
        if (isset($args['offset']) && $args['offset']) {
            $query .= $wpdb->prepare("LIMIT %d , %d ", $args['offset'], $args['limit']);
        } else {
            $query .= $wpdb->prepare("LIMIT %d ", $args['limit']);
        }
    }
    $site_results = $wpdb->get_results($query, ARRAY_A);
    return $site_results;
}
Ejemplo n.º 11
0
/**
 * Wrapper for wp_is_large_network() that supports non-MS.
 *
 * @since 1.1.2
 */
function invite_anyone_is_large_network()
{
    if (function_exists('wp_is_large_network')) {
        $is_large_network = wp_is_large_network('users');
        $count = get_user_count();
    } else {
        global $wpdb;
        $count = get_transient('ia_user_count');
        if (false === $count) {
            $count = $wpdb->get_var("SELECT COUNT(ID) FROM {$wpdb->users} WHERE user_status = '0'");
            set_transient('ia_user_count', $count, 60 * 60 * 24);
        }
        $is_large_network = $count > 10000;
        return apply_filters('invite_anyone_is_large_network', $count > 10000, $count);
    }
    return apply_filters('invite_anyone_is_large_network', $is_large_network, $count);
}
Ejemplo n.º 12
0
 /**
  * Prepare the query variables.
  *
  * @since 3.1.0
  *
  * @param string|array $args Optional. The query variables.
  */
 function prepare_query($query = array())
 {
     global $wpdb;
     if (empty($this->query_vars) || !empty($query)) {
         $this->query_limit = null;
         $this->query_vars = wp_parse_args($query, array('blog_id' => $GLOBALS['blog_id'], 'role' => '', 'meta_key' => '', 'meta_value' => '', 'meta_compare' => '', 'include' => array(), 'exclude' => array(), 'search' => '', 'search_columns' => array(), 'orderby' => 'login', 'order' => 'ASC', 'offset' => '', 'number' => '', 'count_total' => true, 'fields' => 'all', 'who' => ''));
     }
     $qv =& $this->query_vars;
     if (is_array($qv['fields'])) {
         $qv['fields'] = array_unique($qv['fields']);
         $this->query_fields = array();
         foreach ($qv['fields'] as $field) {
             $field = 'ID' === $field ? 'ID' : sanitize_key($field);
             $this->query_fields[] = "{$wpdb->users}.{$field}";
         }
         $this->query_fields = implode(',', $this->query_fields);
     } elseif ('all' == $qv['fields']) {
         $this->query_fields = "{$wpdb->users}.*";
     } else {
         $this->query_fields = "{$wpdb->users}.ID";
     }
     if (isset($qv['count_total']) && $qv['count_total']) {
         $this->query_fields = 'SQL_CALC_FOUND_ROWS ' . $this->query_fields;
     }
     $this->query_from = "FROM {$wpdb->users}";
     $this->query_where = "WHERE 1=1";
     // sorting
     if (isset($qv['orderby'])) {
         if (in_array($qv['orderby'], array('nicename', 'email', 'url', 'registered'))) {
             $orderby = 'user_' . $qv['orderby'];
         } elseif (in_array($qv['orderby'], array('user_nicename', 'user_email', 'user_url', 'user_registered'))) {
             $orderby = $qv['orderby'];
         } elseif ('name' == $qv['orderby'] || 'display_name' == $qv['orderby']) {
             $orderby = 'display_name';
         } elseif ('post_count' == $qv['orderby']) {
             // todo: avoid the JOIN
             $where = get_posts_by_author_sql('post');
             $this->query_from .= " LEFT OUTER JOIN (\r\n\t\t\t\t\tSELECT post_author, COUNT(*) as post_count\r\n\t\t\t\t\tFROM {$wpdb->posts}\r\n\t\t\t\t\t{$where}\r\n\t\t\t\t\tGROUP BY post_author\r\n\t\t\t\t) p ON ({$wpdb->users}.ID = p.post_author)\r\n\t\t\t\t";
             $orderby = 'post_count';
         } elseif ('ID' == $qv['orderby'] || 'id' == $qv['orderby']) {
             $orderby = 'ID';
         } elseif ('meta_value' == $qv['orderby']) {
             $orderby = "{$wpdb->usermeta}.meta_value";
         } else {
             $orderby = 'user_login';
         }
     }
     if (empty($orderby)) {
         $orderby = 'user_login';
     }
     $qv['order'] = isset($qv['order']) ? strtoupper($qv['order']) : '';
     if ('ASC' == $qv['order']) {
         $order = 'ASC';
     } else {
         $order = 'DESC';
     }
     $this->query_orderby = "ORDER BY {$orderby} {$order}";
     // limit
     if (isset($qv['number']) && $qv['number']) {
         if ($qv['offset']) {
             $this->query_limit = $wpdb->prepare("LIMIT %d, %d", $qv['offset'], $qv['number']);
         } else {
             $this->query_limit = $wpdb->prepare("LIMIT %d", $qv['number']);
         }
     }
     $search = '';
     if (isset($qv['search'])) {
         $search = trim($qv['search']);
     }
     if ($search) {
         $leading_wild = ltrim($search, '*') != $search;
         $trailing_wild = rtrim($search, '*') != $search;
         if ($leading_wild && $trailing_wild) {
             $wild = 'both';
         } elseif ($leading_wild) {
             $wild = 'leading';
         } elseif ($trailing_wild) {
             $wild = 'trailing';
         } else {
             $wild = false;
         }
         if ($wild) {
             $search = trim($search, '*');
         }
         $search_columns = array();
         if ($qv['search_columns']) {
             $search_columns = array_intersect($qv['search_columns'], array('ID', 'user_login', 'user_email', 'user_url', 'user_nicename'));
         }
         if (!$search_columns) {
             if (false !== strpos($search, '@')) {
                 $search_columns = array('user_email');
             } elseif (is_numeric($search)) {
                 $search_columns = array('user_login', 'ID');
             } elseif (preg_match('|^https?://|', $search) && !(is_multisite() && wp_is_large_network('users'))) {
                 $search_columns = array('user_url');
             } else {
                 $search_columns = array('user_login', 'user_nicename');
             }
         }
         /**
          * Filter the columns to search in a WP_User_Query search.
          *
          * The default columns depend on the search term, and include 'user_email',
          * 'user_login', 'ID', 'user_url', and 'user_nicename'.
          *
          * @since 3.6.0
          *
          * @param array         $search_columns Array of column names to be searched.
          * @param string        $search         Text being searched.
          * @param WP_User_Query $this           The current WP_User_Query instance.
          */
         $search_columns = apply_filters('user_search_columns', $search_columns, $search, $this);
         $this->query_where .= $this->get_search_sql($search, $search_columns, $wild);
     }
     $blog_id = 0;
     if (isset($qv['blog_id'])) {
         $blog_id = absint($qv['blog_id']);
     }
     if (isset($qv['who']) && 'authors' == $qv['who'] && $blog_id) {
         $qv['meta_key'] = $wpdb->get_blog_prefix($blog_id) . 'user_level';
         $qv['meta_value'] = 0;
         $qv['meta_compare'] = '!=';
         $qv['blog_id'] = $blog_id = 0;
         // Prevent extra meta query
     }
     $role = '';
     if (isset($qv['role'])) {
         $role = trim($qv['role']);
     }
     if ($blog_id && ($role || is_multisite())) {
         $cap_meta_query = array();
         $cap_meta_query['key'] = $wpdb->get_blog_prefix($blog_id) . 'capabilities';
         if ($role) {
             $cap_meta_query['value'] = '"' . $role . '"';
             $cap_meta_query['compare'] = 'like';
         }
         if (empty($qv['meta_query']) || !in_array($cap_meta_query, $qv['meta_query'], true)) {
             $qv['meta_query'][] = $cap_meta_query;
         }
     }
     $meta_query = new WP_Meta_Query();
     $meta_query->parse_query_vars($qv);
     if (!empty($meta_query->queries)) {
         $clauses = $meta_query->get_sql('user', $wpdb->users, 'ID', $this);
         $this->query_from .= $clauses['join'];
         $this->query_where .= $clauses['where'];
         if ('OR' == $meta_query->relation) {
             $this->query_fields = 'DISTINCT ' . $this->query_fields;
         }
     }
     if (!empty($qv['include'])) {
         $ids = implode(',', wp_parse_id_list($qv['include']));
         $this->query_where .= " AND {$wpdb->users}.ID IN ({$ids})";
     } elseif (!empty($qv['exclude'])) {
         $ids = implode(',', wp_parse_id_list($qv['exclude']));
         $this->query_where .= " AND {$wpdb->users}.ID NOT IN ({$ids})";
     }
     /**
      * Fires after the WP_User_Query has been parsed, and before
      * the query is executed.
      *
      * The passed WP_User_Query object contains SQL parts formed
      * from parsing the given query.
      *
      * @since 3.1.0
      *
      * @param WP_User_Query $this The current WP_User_Query instance,
      *                            passed by reference.
      */
     do_action_ref_array('pre_user_query', array(&$this));
 }
Ejemplo n.º 13
0
_e('Network|Multisite Sitewide Login Security Settings', 'bulletproof-security');
?>
</label></strong><br />  
<input type="submit" name="Submit-Net-LSM" class="button bps-button" style="margin:10px 0px 20px 0px;" value="<?php 
esc_attr_e('Save Network LSM Options Sitewide', 'bulletproof-security');
?>
" />
</div>
</form>

<?php 
// Network|Multisite: update/save Login Security DB option settings for all sites
if (isset($_POST['Submit-Net-LSM']) && current_user_can('manage_options')) {
    check_admin_referer('bulletproof_security_net_lsm');
    if (is_multisite()) {
        if (wp_is_large_network()) {
            echo '<div id="message" class="updated" style="border:1px solid #999999;margin-left:70px;background-color:#ffffe0;"><p>';
            $text = '<font color="red"><strong>' . __('Error: Your Network site exceeds the default WP criteria for a large network site. Either you have more than 10,000 users or more than 10,000 sites. Please post a new forum thread in the BPS plugin support forum on wordpress.org for assistance.', 'bulletproof-security') . '</strong></font>';
            echo $text;
            echo '</p></div>';
            return;
        }
        $successMessage = __(' LSM DB Options created or updated Successfully!', 'bulletproof-security');
        $successTextBegin = '<font color="green"><strong>';
        $successTextEnd = '</strong></font><br>';
        $network_ids = wp_get_sites();
        foreach ($network_ids as $key => $value) {
            $net_id = $value['blog_id'];
            $bps_Net_lsm = 'bulletproof_security_options_login_security';
            $BPS_Net_LSM_Options = array('bps_max_logins' => '3', 'bps_lockout_duration' => '60', 'bps_manual_lockout_duration' => '60', 'bps_max_db_rows_display' => '', 'bps_login_security_OnOff' => 'On', 'bps_login_security_logging' => 'logLockouts', 'bps_login_security_errors' => 'wpErrors', 'bps_login_security_remaining' => 'On', 'bps_login_security_pw_reset' => 'enable', 'bps_login_security_sort' => 'ascending');
            if (!get_blog_option($net_id, $bps_Net_lsm)) {
Ejemplo n.º 14
0
    $help .= '<p>' . __('You must assign a password to the new user, which they can change after logging in. The username, however, cannot be changed.') . '</p>' . '<p>' . __('New users will receive an email letting them know they&#8217;ve been added as a user for your site. By default, this email will also contain their password. Uncheck the box if you don&#8217;t want the password to be included in the welcome email.') . '</p>';
}
$help .= '<p>' . __('Remember to click the Add New User button at the bottom of this screen when you are finished.') . '</p>';
get_current_screen()->add_help_tab(array('id' => 'overview', 'title' => __('Overview'), 'content' => $help));
get_current_screen()->add_help_tab(array('id' => 'user-roles', 'title' => __('User Roles'), 'content' => '<p>' . __('Here is a basic overview of the different user roles and the permissions associated with each one:') . '</p>' . '<ul>' . '<li>' . __('Administrators have access to all the administration features.') . '</li>' . '<li>' . __('Editors can publish posts, manage posts as well as manage other people&#8217;s posts, etc.') . '</li>' . '<li>' . __('Authors can publish and manage their own posts, and are able to upload files.') . '</li>' . '<li>' . __('Contributors can write and manage their posts but not publish posts or upload media files.') . '</li>' . '<li>' . __('Subscribers can read comments/comment/receive newsletters, etc. but cannot create regular site content.') . '</li>' . '</ul>'));
get_current_screen()->set_help_sidebar('<p><strong>' . __('For more information:') . '</strong></p>' . '<p>' . __('<a href="http://codex.wordpress.org/Users_Add_New_Screen" target="_blank">Documentation on Adding New Users</a>') . '</p>' . '<p>' . __('<a href="http://wordpress.org/support/" target="_blank">Support Forums</a>') . '</p>');
wp_enqueue_script('wp-ajax-response');
wp_enqueue_script('user-profile');
/**
 * Filter whether to enable user auto-complete for non-super admins in Multisite.
 *
 * @since 3.4.0
 *
 * @param bool $enable Whether to enable auto-complete for non-super admins. Default false.
 */
if (is_multisite() && current_user_can('promote_users') && !wp_is_large_network('users') && (is_super_admin() || apply_filters('autocomplete_users_for_site_admins', false))) {
    wp_enqueue_script('user-suggest');
}
require_once ABSPATH . 'wp-admin/admin-header.php';
if (isset($_GET['update'])) {
    $messages = array();
    if (is_multisite()) {
        switch ($_GET['update']) {
            case "newuserconfirmation":
                $messages[] = __('Invitation email sent to new user. A confirmation link must be clicked before their account is created.');
                break;
            case "add":
                $messages[] = __('Invitation email sent to user. A confirmation link must be clicked for them to be added to your site.');
                break;
            case "addnoconfirmation":
                $messages[] = __('User has been added to your site.');
Ejemplo n.º 15
0
 /**
  * Upgrades the settings.
  * 
  * ## OPTIONS
  * 
  * [--network-wide]
  * : Perform the settings upgrade on all blogs of the network.
  * 
  * ## EXAMPLES
  * 
  *     wp amt upgrade
  *     wp amt upgrade --network-wide
  *
  * @synopsis [--network-wide]
  */
 function upgrade($args, $assoc_args)
 {
     // Multisite
     if ($assoc_args['network-wide']) {
         if (is_multisite()) {
             // Check for large network
             if (wp_is_large_network($using = 'sites')) {
                 WP_CLI::error('Too large network. Aborting...');
             }
             $blog_list = wp_get_sites();
             //var_dump($blog_list);
             if (empty($blog_list)) {
                 WP_CLI::error('No blogs could be found.');
                 // Check for large network is done above
             }
             foreach ($blog_list as $blog) {
                 switch_to_blog($blog['blog_id']);
                 $plugin_info = get_plugin_data(plugin_dir_path(__FILE__) . 'add-meta-tags.php', $markup = true, $translate = true);
                 WP_CLI::line('Upgrading settings of: ' . get_bloginfo('name') . ' - (ID: ' . $blog['blog_id'] . ')');
                 amt_plugin_upgrade();
                 restore_current_blog();
             }
             WP_CLI::success('Add-Meta-Tags settings have been upgraded network wide.');
         } else {
             WP_CLI::warning('No network detected. Reverting to single site mode.');
         }
     }
     if (!is_multisite()) {
         // Single site installation
         amt_plugin_upgrade();
         WP_CLI::success('Add-Meta-Tags settings have been upgraded.');
     }
     /*
             if ( is_multisite() ) {
                 $blog_list = get_blog_list( 0, 'all' );
             } else {
                 $blog_list   = array();
                 $blog_list[] = array( 'blog_id' => 1 );
             }
     
             foreach ( $blog_list as $blog ) {
                 if ( is_multisite() ) {
                     switch_to_blog( $blog['blog_id'] );
                 }
                 $plugin_info = get_plugin_data( plugin_dir_path( __FILE__ ) . 'add-meta-tags.php', $markup = true, $translate = true );
                 WP_CLI::line( 'Upgrading settings of: ' . get_bloginfo('name') . ' - (ID: ' . $blog['blog_id'] . ')' );
                 amt_plugin_upgrade();
                 if ( is_multisite() ) {
                     restore_current_blog();
                 }
             }
     */
     // get_plugin_data( $plugin_file, $markup = true, $translate = true )
     //$plugin info = get_plugin_data( AMT_PLUGIN_DIR . 'add-meta-tags.php', $markup = true, $translate = true );
     // WP_CLI::line( ' ' );
     // WP_CLI::line( count( $field_groups ) . ' field groups found for blog_id ' . $blog['blog_id'] );
     // Print a success message
     //WP_CLI::success( "Operation complete." );
 }
Ejemplo n.º 16
0
    }
    restore_current_blog();
    wp_safe_redirect(add_query_arg('update', $update, $referer));
    exit;
}
if (isset($_GET['action']) && 'update-site' == $_GET['action']) {
    wp_safe_redirect($referer);
    exit;
}
add_screen_option('per_page', array('label' => _x('Users', 'users per page (screen options)')));
$site_url_no_http = preg_replace('#^http(s)?://#', '', get_blogaddress_by_id($id));
$title_site_url_linked = sprintf(__('Edit Site: <a href="%1$s">%2$s</a>'), get_blogaddress_by_id($id), $site_url_no_http);
$title = sprintf(__('Edit Site: %s'), $site_url_no_http);
$parent_file = 'sites.php';
$submenu_file = 'sites.php';
if (current_user_can('promote_users') && apply_filters('show_network_site_users_add_existing_form', true) && !wp_is_large_network('users')) {
    wp_enqueue_script('user-search');
}
require '../admin-header.php';
?>

<script type='text/javascript'>
/* <![CDATA[ */
var current_site_id = <?php 
echo $id;
?>
;
/* ]]> */
</script>

Ejemplo n.º 17
0
        case 'unspam':
            $msg = __('Site removed from spam.');
            break;
        case 'spam':
            $msg = __('Site marked as spam.');
            break;
        default:
            $msg = apply_filters('network_sites_updated_message_' . $_REQUEST['action'], __('Settings saved.'));
            break;
    }
    if ($msg) {
        $msg = '<div class="updated" id="message"><p>' . $msg . '</p></div>';
    }
}
$wp_list_table->prepare_items();
if (!wp_is_large_network('sites')) {
    wp_enqueue_script('site-search');
}
require_once '../admin-header.php';
?>

<div class="wrap">
<?php 
screen_icon('ms-admin');
?>
<h2><?php 
_e('Sites');
echo $msg;
if (current_user_can('create_sites')) {
    ?>
        <a href="<?php 
Ejemplo n.º 18
0
 /**
  * Return an array of sites on the specified network. If no network is specified,
  * return all sites, regardless of network.
  *
  * @todo REMOVE THIS FUNCTION! This function is moving to core. Use that one in favor of this. WordPress::wp_get_sites(). http://codex.wordpress.org/Function_Reference/wp_get_sites NOTE, This returns an array instead of stdClass. Be sure to update class.network-sites-list-table.php
  * @since 2.9
  * @deprecated 2.4.5
  *
  * @param array|string $args Optional. Specify the status of the sites to return.
  *
  * @return array An array of site data
  */
 public function wp_get_sites($args = array())
 {
     global $wpdb;
     if (wp_is_large_network()) {
         return;
     }
     $defaults = array('network_id' => $wpdb->siteid);
     $args = wp_parse_args($args, $defaults);
     $query = "SELECT * FROM {$wpdb->blogs} WHERE 1=1 ";
     if (isset($args['network_id']) && (is_array($args['network_id']) || is_numeric($args['network_id']))) {
         $network_ids = array_map('intval', (array) $args['network_id']);
         $network_ids = implode(',', $network_ids);
         $query .= "AND site_id IN ({$network_ids}) ";
     }
     if (isset($args['public'])) {
         $query .= $wpdb->prepare("AND public = %s ", $args['public']);
     }
     if (isset($args['archived'])) {
         $query .= $wpdb->prepare("AND archived = %s ", $args['archived']);
     }
     if (isset($args['mature'])) {
         $query .= $wpdb->prepare("AND mature = %s ", $args['mature']);
     }
     if (isset($args['spam'])) {
         $query .= $wpdb->prepare("AND spam = %s ", $args['spam']);
     }
     if (isset($args['deleted'])) {
         $query .= $wpdb->prepare("AND deleted = %s ", $args['deleted']);
     }
     if (isset($args['exclude_blogs'])) {
         $query .= "AND blog_id NOT IN (" . implode(',', $args['exclude_blogs']) . ")";
     }
     $key = 'wp_get_sites:' . md5($query);
     if (!($site_results = wp_cache_get($key, 'site-id-cache'))) {
         $site_results = (array) $wpdb->get_results($query);
         wp_cache_set($key, $site_results, 'site-id-cache');
     }
     return $site_results;
 }
Ejemplo n.º 19
0
/**
 * Ajax handler for user autocomplete.
 *
 * @since 3.4.0
 */
function wp_ajax_autocomplete_user()
{
    if (!is_multisite() || !current_user_can('promote_users') || wp_is_large_network('users')) {
        wp_die(-1);
    }
    /** This filter is documented in wp-admin/user-new.php */
    if (!is_super_admin() && !apply_filters('autocomplete_users_for_site_admins', false)) {
        wp_die(-1);
    }
    $return = array();
    // Check the type of request
    // Current allowed values are `add` and `search`
    if (isset($_REQUEST['autocomplete_type']) && 'search' === $_REQUEST['autocomplete_type']) {
        $type = $_REQUEST['autocomplete_type'];
    } else {
        $type = 'add';
    }
    // Check the desired field for value
    // Current allowed values are `user_email` and `user_login`
    if (isset($_REQUEST['autocomplete_field']) && 'user_email' === $_REQUEST['autocomplete_field']) {
        $field = $_REQUEST['autocomplete_field'];
    } else {
        $field = 'user_login';
    }
    // Exclude current users of this blog
    if (isset($_REQUEST['site_id'])) {
        $id = absint($_REQUEST['site_id']);
    } else {
        $id = get_current_blog_id();
    }
    $include_blog_users = $type == 'search' ? get_users(array('blog_id' => $id, 'fields' => 'ID')) : array();
    $exclude_blog_users = $type == 'add' ? get_users(array('blog_id' => $id, 'fields' => 'ID')) : array();
    $users = get_users(array('blog_id' => false, 'search' => '*' . $_REQUEST['term'] . '*', 'include' => $include_blog_users, 'exclude' => $exclude_blog_users, 'search_columns' => array('user_login', 'user_nicename', 'user_email')));
    foreach ($users as $user) {
        $return[] = array('label' => sprintf(__('%1$s (%2$s)'), $user->user_login, $user->user_email), 'value' => $user->{$field});
    }
    wp_die(wp_json_encode($return));
}
Ejemplo n.º 20
0
 /**
  * Prepare the query variables
  *
  * @since 3.1.0
  * @access private
  */
 function prepare_query()
 {
     global $wpdb;
     $qv =& $this->query_vars;
     if (is_array($qv['fields'])) {
         $qv['fields'] = array_unique($qv['fields']);
         $this->query_fields = array();
         foreach ($qv['fields'] as $field) {
             $this->query_fields[] = $wpdb->users . '.' . esc_sql($field);
         }
         $this->query_fields = implode(',', $this->query_fields);
     } elseif ('all' == $qv['fields']) {
         $this->query_fields = "{$wpdb->users}.*";
     } else {
         $this->query_fields = "{$wpdb->users}.ID";
     }
     if ($qv['count_total']) {
         $this->query_fields = 'SQL_CALC_FOUND_ROWS ' . $this->query_fields;
     }
     $this->query_from = "FROM {$wpdb->users}";
     $this->query_where = "WHERE 1=1";
     // sorting
     if (in_array($qv['orderby'], array('nicename', 'email', 'url', 'registered'))) {
         $orderby = 'user_' . $qv['orderby'];
     } elseif (in_array($qv['orderby'], array('user_nicename', 'user_email', 'user_url', 'user_registered'))) {
         $orderby = $qv['orderby'];
     } elseif ('name' == $qv['orderby'] || 'display_name' == $qv['orderby']) {
         $orderby = 'display_name';
     } elseif ('post_count' == $qv['orderby']) {
         // todo: avoid the JOIN
         $where = get_posts_by_author_sql('post');
         $this->query_from .= " LEFT OUTER JOIN (\n\t\t\t\tSELECT post_author, COUNT(*) as post_count\n\t\t\t\tFROM {$wpdb->posts}\n\t\t\t\t{$where}\n\t\t\t\tGROUP BY post_author\n\t\t\t) p ON ({$wpdb->users}.ID = p.post_author)\n\t\t\t";
         $orderby = 'post_count';
     } elseif ('ID' == $qv['orderby'] || 'id' == $qv['orderby']) {
         $orderby = 'ID';
     } else {
         $orderby = 'user_login';
     }
     $qv['order'] = strtoupper($qv['order']);
     if ('ASC' == $qv['order']) {
         $order = 'ASC';
     } else {
         $order = 'DESC';
     }
     $this->query_orderby = "ORDER BY {$orderby} {$order}";
     // limit
     if ($qv['number']) {
         if ($qv['offset']) {
             $this->query_limit = $wpdb->prepare("LIMIT %d, %d", $qv['offset'], $qv['number']);
         } else {
             $this->query_limit = $wpdb->prepare("LIMIT %d", $qv['number']);
         }
     }
     $search = trim($qv['search']);
     if ($search) {
         $leading_wild = ltrim($search, '*') != $search;
         $trailing_wild = rtrim($search, '*') != $search;
         if ($leading_wild && $trailing_wild) {
             $wild = 'both';
         } elseif ($leading_wild) {
             $wild = 'leading';
         } elseif ($trailing_wild) {
             $wild = 'trailing';
         } else {
             $wild = false;
         }
         if ($wild) {
             $search = trim($search, '*');
         }
         $search_columns = array();
         if ($qv['search_columns']) {
             $search_columns = array_intersect($qv['search_columns'], array('ID', 'user_login', 'user_email', 'user_url', 'user_nicename'));
         }
         if (!$search_columns) {
             if (false !== strpos($search, '@')) {
                 $search_columns = array('user_email');
             } elseif (is_numeric($search)) {
                 $search_columns = array('user_login', 'ID');
             } elseif (preg_match('|^https?://|', $search) && !(is_multisite() && function_exists('wp_is_large_network') && wp_is_large_network('users'))) {
                 $search_columns = array('user_url');
             } else {
                 $search_columns = array('user_login', 'user_nicename');
             }
         }
         $this->query_where .= $this->get_search_sql($search, $search_columns, $wild);
     }
     $blog_id = absint($qv['blog_id']);
     if ('authors' == $qv['who'] && $blog_id) {
         $qv['meta_key'] = $wpdb->get_blog_prefix($blog_id) . 'user_level';
         $qv['meta_value'] = 0;
         $qv['meta_compare'] = '!=';
         $qv['blog_id'] = $blog_id = 0;
         // Prevent extra meta query
     }
     $role = trim($qv['role']);
     if ($blog_id && ($role || is_multisite())) {
         $cap_meta_query = array();
         $cap_meta_query['key'] = $wpdb->get_blog_prefix($blog_id) . 'capabilities';
         if ($role) {
             $cap_meta_query['value'] = '"' . $role . '"';
             $cap_meta_query['compare'] = 'like';
         }
         $qv['meta_query'][] = $cap_meta_query;
     }
     $meta_query = new WP_Meta_Query();
     $meta_query->parse_query_vars($qv);
     if (!empty($meta_query->queries)) {
         $clauses = $meta_query->get_sql('user', $wpdb->users, 'ID', $this);
         $this->query_from .= $clauses['join'];
         $this->query_where .= $clauses['where'];
         if ('OR' == $meta_query->relation) {
             $this->query_fields = 'DISTINCT ' . $this->query_fields;
         }
     }
     if (!empty($qv['include'])) {
         $ids = implode(',', wp_parse_id_list($qv['include']));
         $this->query_where .= " AND {$wpdb->users}.ID IN ({$ids})";
     } elseif (!empty($qv['exclude'])) {
         $ids = implode(',', wp_parse_id_list($qv['exclude']));
         $this->query_where .= " AND {$wpdb->users}.ID NOT IN ({$ids})";
     }
     do_action_ref_array('pre_user_query', array(&$this));
 }
Ejemplo n.º 21
0
/**
 * Update the network-wide users count.
 *
 * If enabled through the {@see 'enable_live_network_counts'} filter, update the users count
 * on a network when a user is created or its status is updated.
 *
 * @since 3.7.0
 */
function wp_maybe_update_network_user_counts()
{
    $is_small_network = !wp_is_large_network('users');
    /** This filter is documented in wp-includes/ms-functions.php */
    if (!apply_filters('enable_live_network_counts', $is_small_network, 'users')) {
        return;
    }
    wp_update_network_user_counts();
}
 /**
  * Prepares the list of sites for display.
  *
  * @since 3.1.0
  * @since 4.6.0 Converted to use get_sites()
  *
  * @global string $s
  * @global string $mode
  * @global wpdb   $wpdb
  */
 public function prepare_items()
 {
     global $s, $mode, $wpdb;
     if (!empty($_REQUEST['mode'])) {
         $mode = $_REQUEST['mode'] === 'excerpt' ? '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'] = $_REQUEST['order'] = 'DESC';
         }
     }
     $args = array('number' => intval($per_page), 'offset' => intval(($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;
     }
     /**
      * Filters the arguments for the site query in the sites list table.
      *
      * @since 4.6.0
      *
      * @param array $args An array of get_sites() arguments.
      */
     $args = apply_filters('ms_sites_list_table_query_args', $args);
     $_sites = get_sites($args);
     if (is_array($_sites)) {
         update_site_cache($_sites);
         $this->items = array_slice($_sites, 0, $per_page);
     }
     $total_sites = get_sites(array_merge($args, array('count' => true, 'offset' => 0, 'number' => 0)));
     $this->set_pagination_args(array('total_items' => $total_sites, 'per_page' => $per_page));
 }
/**
 * Return an array of sites for a network or networks.
 *
 * @since 3.7.0
 * @deprecated 4.6.0
 * @see get_sites()
 *
 * @global wpdb $wpdb WordPress database abstraction object.
 *
 * @param array $args {
 *     Array of default arguments. Optional.
 *
 *     @type int|array $network_id A network ID or array of network IDs. Set to null to retrieve sites
 *                                 from all networks. Defaults to current network ID.
 *     @type int       $public     Retrieve public or non-public sites. Default null, for any.
 *     @type int       $archived   Retrieve archived or non-archived sites. Default null, for any.
 *     @type int       $mature     Retrieve mature or non-mature sites. Default null, for any.
 *     @type int       $spam       Retrieve spam or non-spam sites. Default null, for any.
 *     @type int       $deleted    Retrieve deleted or non-deleted sites. Default null, for any.
 *     @type int       $limit      Number of sites to limit the query to. Default 100.
 *     @type int       $offset     Exclude the first x sites. Used in combination with the $limit parameter. Default 0.
 * }
 * @return array An empty array if the install is considered "large" via wp_is_large_network(). Otherwise,
 *               an associative array of site data arrays, each containing the site (network) ID, blog ID,
 *               site domain and path, dates registered and modified, and the language ID. Also, boolean
 *               values for whether the site is public, archived, mature, spam, and/or deleted.
 */
function wp_get_sites($args = array())
{
    global $wpdb;
    _deprecated_function(__FUNCTION__, '4.6.0', 'get_sites()');
    if (wp_is_large_network()) {
        return array();
    }
    $defaults = array('network_id' => $wpdb->siteid, 'public' => null, 'archived' => null, 'mature' => null, 'spam' => null, 'deleted' => null, 'limit' => 100, 'offset' => 0);
    $args = wp_parse_args($args, $defaults);
    // Backwards compatibility
    if (is_array($args['network_id'])) {
        $args['network__in'] = $args['network_id'];
        $args['network_id'] = null;
    }
    if (is_numeric($args['limit'])) {
        $args['number'] = $args['limit'];
        $args['limit'] = null;
    }
    // Make sure count is disabled.
    $args['count'] = false;
    $_sites = get_sites($args);
    $results = array();
    foreach ($_sites as $_site) {
        $_site = get_site($_site);
        $results[] = $_site->to_array();
    }
    return $results;
}
Ejemplo n.º 24
0
function wp_network_dashboard_right_now()
{
    $actions = array();
    if (current_user_can('create_sites')) {
        $actions['create-site'] = '<a href="' . network_admin_url('site-new.php') . '">' . __('Create a New Site') . '</a>';
    }
    if (current_user_can('create_users')) {
        $actions['create-user'] = '******' . network_admin_url('user-new.php') . '">' . __('Create a New User') . '</a>';
    }
    if (!wp_is_large_network('users')) {
        wp_enqueue_script('user-search');
    }
    if (!wp_is_large_network('sites')) {
        wp_enqueue_script('site-search');
    }
    $c_users = get_user_count();
    $c_blogs = get_blog_count();
    $user_text = sprintf(_n('%s user', '%s users', $c_users), number_format_i18n($c_users));
    $blog_text = sprintf(_n('%s site', '%s sites', $c_blogs), number_format_i18n($c_blogs));
    $sentence = sprintf(__('You have %1$s and %2$s.'), $blog_text, $user_text);
    if ($actions) {
        echo '<ul class="subsubsub">';
        foreach ($actions as $class => $action) {
            $actions[$class] = "\t<li class='{$class}'>{$action}";
        }
        echo implode(" |</li>\n", $actions) . "</li>\n";
        echo '</ul>';
    }
    ?>
	<br class="clear" />

	<p class="youhave"><?php 
    echo $sentence;
    ?>
</p>
	<?php 
    do_action('wpmuadminresult', '');
    ?>

	<form name="searchform" action="<?php 
    echo network_admin_url('users.php');
    ?>
" method="get">
		<p>
			<input type="search" name="s" value="" size="17" id="all-user-search-input" />
			<?php 
    submit_button(__('Search Users'), 'button', 'submit', false, array('id' => 'submit_users'));
    ?>
		</p>
	</form>

	<form name="searchform" action="<?php 
    echo network_admin_url('sites.php');
    ?>
" method="get">
		<p>
			<input type="search" name="s" value="" size="17" id="site-search-input" />
			<?php 
    submit_button(__('Search Sites'), 'button', 'submit', false, array('id' => 'submit_sites'));
    ?>
		</p>
	</form>
<?php 
    do_action('mu_rightnow_end');
    do_action('mu_activity_box_end');
}
 public function prepare_items()
 {
     global $s, $mode, $wpdb;
     $current_site = get_current_site();
     $mode = empty($_REQUEST['mode']) ? 'list' : $_REQUEST['mode'];
     $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 blogs 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'] = $_REQUEST['order'] = 'DESC';
         }
     }
     $query = "SELECT * FROM {$wpdb->blogs} WHERE site_id = '{$wpdb->siteid}' ";
     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) . $wild);
         $reg_blog_ids = $wpdb->get_col($sql);
         if (!$reg_blog_ids) {
             $reg_blog_ids = array(0);
         }
         $query = "SELECT *\r\n\t\t\t\tFROM {$wpdb->blogs}\r\n\t\t\t\tWHERE site_id = '{$wpdb->siteid}'\r\n\t\t\t\tAND {$wpdb->blogs}.blog_id IN (" . implode(', ', $reg_blog_ids) . ")";
     } else {
         if (is_numeric($s) && empty($wild)) {
             $query .= $wpdb->prepare(" AND ( {$wpdb->blogs}.blog_id = %s )", $s);
         } elseif (is_subdomain_install()) {
             $blog_s = str_replace('.' . $current_site->domain, '', $s);
             $blog_s = $wpdb->esc_like($blog_s) . $wild . $wpdb->esc_like('.' . $current_site->domain);
             $query .= $wpdb->prepare(" AND ( {$wpdb->blogs}.domain LIKE %s ) ", $blog_s);
         } else {
             if ($s != trim('/', $current_site->path)) {
                 $blog_s = $wpdb->esc_like($current_site->path . $s) . $wild . $wpdb->esc_like('/');
             } else {
                 $blog_s = $wpdb->esc_like($s);
             }
             $query .= $wpdb->prepare(" AND  ( {$wpdb->blogs}.path LIKE %s )", $blog_s);
         }
     }
     $order_by = isset($_REQUEST['orderby']) ? $_REQUEST['orderby'] : '';
     if ($order_by == 'registered') {
         $query .= ' ORDER BY registered ';
     } elseif ($order_by == 'lastupdated') {
         $query .= ' ORDER BY last_updated ';
     } elseif ($order_by == 'blogname') {
         if (is_subdomain_install()) {
             $query .= ' ORDER BY domain ';
         } else {
             $query .= ' ORDER BY path ';
         }
     } elseif ($order_by == 'blog_id') {
         $query .= ' ORDER BY blog_id ';
     } else {
         $order_by = null;
     }
     if (isset($order_by)) {
         $order = isset($_REQUEST['order']) && 'DESC' == strtoupper($_REQUEST['order']) ? "DESC" : "ASC";
         $query .= $order;
     }
     // Don't do an unbounded count on large networks
     if (!wp_is_large_network()) {
         $total = $wpdb->get_var(str_replace('SELECT *', 'SELECT COUNT( blog_id )', $query));
     }
     $query .= " LIMIT " . intval(($pagenum - 1) * $per_page) . ", " . intval($per_page);
     $this->items = $wpdb->get_results($query, ARRAY_A);
     if (wp_is_large_network()) {
         $total = count($this->items);
     }
     $this->set_pagination_args(array('total_items' => $total, 'per_page' => $per_page));
 }
Ejemplo n.º 26
0
    }
    wp_safe_redirect(add_query_arg('update', $update, $referer));
    exit;
}
restore_current_blog();
if (isset($_GET['action']) && 'update-site' == $_GET['action']) {
    wp_safe_redirect($referer);
    exit;
}
add_screen_option('per_page', array('label' => _x('Users', 'users per page (screen options)')));
$site_url_no_http = preg_replace('#^http(s)?://#', '', get_blogaddress_by_id($id));
$title_site_url_linked = sprintf(__('Edit Site: <a href="%1$s">%2$s</a>'), get_blogaddress_by_id($id), $site_url_no_http);
$title = sprintf(__('Edit Site: %s'), $site_url_no_http);
$parent_file = 'sites.php';
$submenu_file = 'sites.php';
if (!wp_is_large_network('users') && apply_filters('show_network_site_users_add_existing_form', true)) {
    wp_enqueue_script('user-suggest');
}
require '../admin-header.php';
?>

<script type='text/javascript'>
/* <![CDATA[ */
var current_site_id = <?php 
echo $id;
?>
;
/* ]]> */
</script>

Ejemplo n.º 27
0
 /**
  * Prepare the query variables.
  *
  * @since 3.1.0
  * @since 4.1.0 Added the ability to order by the `include` value.
  * @since 4.2.0 Added 'meta_value_num' support for `$orderby` parameter. Added multi-dimensional array syntax
  *              for `$orderby` parameter.
  * @since 4.3.0 Added 'has_published_posts' parameter.
  * @since 4.4.0 Added 'paged', 'role__in', and 'role__not_in' parameters. The 'role' parameter was updated to
  *              permit an array or comma-separated list of values. The 'number' parameter was updated to support
  *              querying for all users with using -1.
  *
  * @access public
  *
  * @global wpdb $wpdb WordPress database abstraction object.
  * @global int  $blog_id
  *
  * @param string|array $query {
  *     Optional. Array or string of Query parameters.
  *
  *     @type int          $blog_id             The site ID. Default is the global blog id.
  *     @type string|array $role                An array or a comma-separated list of role names that users must match
  *                                             to be included in results. Note that this is an inclusive list: users
  *                                             must match *each* role. Default empty.
  *     @type array        $role__in            An array of role names. Matched users must have at least one of these
  *                                             roles. Default empty array.
  *     @type array        $role__not_in        An array of role names to exclude. Users matching one or more of these
  *                                             roles will not be included in results. Default empty array.
  *     @type string       $meta_key            User meta key. Default empty.
  *     @type string       $meta_value          User meta value. Default empty.
  *     @type string       $meta_compare        Comparison operator to test the `$meta_value`. Accepts '=', '!=',
  *                                             '>', '>=', '<', '<=', 'LIKE', 'NOT LIKE', 'IN', 'NOT IN',
  *                                             'BETWEEN', 'NOT BETWEEN', 'EXISTS', 'NOT EXISTS', 'REGEXP',
  *                                             'NOT REGEXP', or 'RLIKE'. Default '='.
  *     @type array        $include             An array of user IDs to include. Default empty array.
  *     @type array        $exclude             An array of user IDs to exclude. Default empty array.
  *     @type string       $search              Search keyword. Searches for possible string matches on columns.
  *                                             When `$search_columns` is left empty, it tries to determine which
  *                                             column to search in based on search string. Default empty.
  *     @type array        $search_columns      Array of column names to be searched. Accepts 'ID', 'login',
  *                                             'nicename', 'email', 'url'. Default empty array.
  *     @type string|array $orderby             Field(s) to sort the retrieved users by. May be a single value,
  *                                             an array of values, or a multi-dimensional array with fields as
  *                                             keys and orders ('ASC' or 'DESC') as values. Accepted values are
  *                                             'ID', 'display_name' (or 'name'), 'include', 'user_login'
  *                                             (or 'login'), 'user_nicename' (or 'nicename'), 'user_email'
  *                                             (or 'email'), 'user_url' (or 'url'), 'user_registered'
  *                                             or 'registered'), 'post_count', 'meta_value', 'meta_value_num',
  *                                             the value of `$meta_key`, or an array key of `$meta_query`. To use
  *                                             'meta_value' or 'meta_value_num', `$meta_key` must be also be
  *                                             defined. Default 'user_login'.
  *     @type string       $order               Designates ascending or descending order of users. Order values
  *                                             passed as part of an `$orderby` array take precedence over this
  *                                             parameter. Accepts 'ASC', 'DESC'. Default 'ASC'.
  *     @type int          $offset              Number of users to offset in retrieved results. Can be used in
  *                                             conjunction with pagination. Default 0.
  *     @type int          $number              Number of users to limit the query for. Can be used in
  *                                             conjunction with pagination. Value -1 (all) is supported, but
  *                                             should be used with caution on larger sites.
  *                                             Default empty (all users).
  *     @type int          $paged               When used with number, defines the page of results to return.
  *                                             Default 1.
  *     @type bool         $count_total         Whether to count the total number of users found. If pagination
  *                                             is not needed, setting this to false can improve performance.
  *                                             Default true.
  *     @type string|array $fields              Which fields to return. Single or all fields (string), or array
  *                                             of fields. Accepts 'ID', 'display_name', 'user_login',
  *                                             'user_nicename', 'user_email', 'user_url', 'user_registered'.
  *                                             Use 'all' for all fields and 'all_with_meta' to include
  *                                             meta fields. Default 'all'.
  *     @type string       $who                 Type of users to query. Accepts 'authors'.
  *                                             Default empty (all users).
  *     @type bool|array   $has_published_posts Pass an array of post types to filter results to users who have
  *                                             published posts in those post types. `true` is an alias for all
  *                                             public post types.
  * }
  */
 public function prepare_query($query = array())
 {
     global $wpdb;
     if (empty($this->query_vars) || !empty($query)) {
         $this->query_limit = null;
         $this->query_vars = $this->fill_query_vars($query);
     }
     /**
      * Fires before the WP_User_Query has been parsed.
      *
      * The passed WP_User_Query object contains the query variables, not
      * yet passed into SQL.
      *
      * @since 4.0.0
      *
      * @param WP_User_Query $this The current WP_User_Query instance,
      *                            passed by reference.
      */
     do_action('pre_get_users', $this);
     // Ensure that query vars are filled after 'pre_get_users'.
     $qv =& $this->query_vars;
     $qv = $this->fill_query_vars($qv);
     if (is_array($qv['fields'])) {
         $qv['fields'] = array_unique($qv['fields']);
         $this->query_fields = array();
         foreach ($qv['fields'] as $field) {
             $field = 'ID' === $field ? 'ID' : sanitize_key($field);
             $this->query_fields[] = "{$wpdb->users}.{$field}";
         }
         $this->query_fields = implode(',', $this->query_fields);
     } elseif ('all' == $qv['fields']) {
         $this->query_fields = "{$wpdb->users}.*";
     } else {
         $this->query_fields = "{$wpdb->users}.ID";
     }
     if (isset($qv['count_total']) && $qv['count_total']) {
         $this->query_fields = 'SQL_CALC_FOUND_ROWS ' . $this->query_fields;
     }
     $this->query_from = "FROM {$wpdb->users}";
     $this->query_where = "WHERE 1=1";
     // Parse and sanitize 'include', for use by 'orderby' as well as 'include' below.
     if (!empty($qv['include'])) {
         $include = wp_parse_id_list($qv['include']);
     } else {
         $include = false;
     }
     $blog_id = 0;
     if (isset($qv['blog_id'])) {
         $blog_id = absint($qv['blog_id']);
     }
     if (isset($qv['who']) && 'authors' == $qv['who'] && $blog_id) {
         $qv['meta_key'] = $wpdb->get_blog_prefix($blog_id) . 'user_level';
         $qv['meta_value'] = 0;
         $qv['meta_compare'] = '!=';
         $qv['blog_id'] = $blog_id = 0;
         // Prevent extra meta query
     }
     if ($qv['has_published_posts'] && $blog_id) {
         if (true === $qv['has_published_posts']) {
             $post_types = get_post_types(array('public' => true));
         } else {
             $post_types = (array) $qv['has_published_posts'];
         }
         foreach ($post_types as &$post_type) {
             $post_type = $wpdb->prepare('%s', $post_type);
         }
         $posts_table = $wpdb->get_blog_prefix($blog_id) . 'posts';
         $this->query_where .= " AND {$wpdb->users}.ID IN ( SELECT DISTINCT {$posts_table}.post_author FROM {$posts_table} WHERE {$posts_table}.post_status = 'publish' AND {$posts_table}.post_type IN ( " . join(", ", $post_types) . " ) )";
     }
     // Meta query.
     $this->meta_query = new WP_Meta_Query();
     $this->meta_query->parse_query_vars($qv);
     $roles = array();
     if (isset($qv['role'])) {
         if (is_array($qv['role'])) {
             $roles = $qv['role'];
         } elseif (is_string($qv['role']) && !empty($qv['role'])) {
             $roles = array_map('trim', explode(',', $qv['role']));
         }
     }
     $role__in = array();
     if (isset($qv['role__in'])) {
         $role__in = (array) $qv['role__in'];
     }
     $role__not_in = array();
     if (isset($qv['role__not_in'])) {
         $role__not_in = (array) $qv['role__not_in'];
     }
     if ($blog_id && (!empty($roles) || !empty($role__in) || !empty($role__not_in) || is_multisite())) {
         $role_queries = array();
         $roles_clauses = array('relation' => 'AND');
         if (!empty($roles)) {
             foreach ($roles as $role) {
                 $roles_clauses[] = array('key' => $wpdb->get_blog_prefix($blog_id) . 'capabilities', 'value' => '"' . $role . '"', 'compare' => 'LIKE');
             }
             $role_queries[] = $roles_clauses;
         }
         $role__in_clauses = array('relation' => 'OR');
         if (!empty($role__in)) {
             foreach ($role__in as $role) {
                 $role__in_clauses[] = array('key' => $wpdb->get_blog_prefix($blog_id) . 'capabilities', 'value' => '"' . $role . '"', 'compare' => 'LIKE');
             }
             $role_queries[] = $role__in_clauses;
         }
         $role__not_in_clauses = array('relation' => 'AND');
         if (!empty($role__not_in)) {
             foreach ($role__not_in as $role) {
                 $role__not_in_clauses[] = array('key' => $wpdb->get_blog_prefix($blog_id) . 'capabilities', 'value' => '"' . $role . '"', 'compare' => 'NOT LIKE');
             }
             $role_queries[] = $role__not_in_clauses;
         }
         // If there are no specific roles named, make sure the user is a member of the site.
         if (empty($role_queries)) {
             $role_queries[] = array('key' => $wpdb->get_blog_prefix($blog_id) . 'capabilities', 'compare' => 'EXISTS');
         }
         // Specify that role queries should be joined with AND.
         $role_queries['relation'] = 'AND';
         if (empty($this->meta_query->queries)) {
             $this->meta_query->queries = $role_queries;
         } else {
             // Append the cap query to the original queries and reparse the query.
             $this->meta_query->queries = array('relation' => 'AND', array($this->meta_query->queries, $role_queries));
         }
         $this->meta_query->parse_query_vars($this->meta_query->queries);
     }
     if (!empty($this->meta_query->queries)) {
         $clauses = $this->meta_query->get_sql('user', $wpdb->users, 'ID', $this);
         $this->query_from .= $clauses['join'];
         $this->query_where .= $clauses['where'];
         if ($this->meta_query->has_or_relation()) {
             $this->query_fields = 'DISTINCT ' . $this->query_fields;
         }
     }
     // sorting
     $qv['order'] = isset($qv['order']) ? strtoupper($qv['order']) : '';
     $order = $this->parse_order($qv['order']);
     if (empty($qv['orderby'])) {
         // Default order is by 'user_login'.
         $ordersby = array('user_login' => $order);
     } elseif (is_array($qv['orderby'])) {
         $ordersby = $qv['orderby'];
     } else {
         // 'orderby' values may be a comma- or space-separated list.
         $ordersby = preg_split('/[,\\s]+/', $qv['orderby']);
     }
     $orderby_array = array();
     foreach ($ordersby as $_key => $_value) {
         if (!$_value) {
             continue;
         }
         if (is_int($_key)) {
             // Integer key means this is a flat array of 'orderby' fields.
             $_orderby = $_value;
             $_order = $order;
         } else {
             // Non-integer key means this the key is the field and the value is ASC/DESC.
             $_orderby = $_key;
             $_order = $_value;
         }
         $parsed = $this->parse_orderby($_orderby);
         if (!$parsed) {
             continue;
         }
         $orderby_array[] = $parsed . ' ' . $this->parse_order($_order);
     }
     // If no valid clauses were found, order by user_login.
     if (empty($orderby_array)) {
         $orderby_array[] = "user_login {$order}";
     }
     $this->query_orderby = 'ORDER BY ' . implode(', ', $orderby_array);
     // limit
     if (isset($qv['number']) && $qv['number'] > 0) {
         if ($qv['offset']) {
             $this->query_limit = $wpdb->prepare("LIMIT %d, %d", $qv['offset'], $qv['number']);
         } else {
             $this->query_limit = $wpdb->prepare("LIMIT %d, %d", $qv['number'] * ($qv['paged'] - 1), $qv['number']);
         }
     }
     $search = '';
     if (isset($qv['search'])) {
         $search = trim($qv['search']);
     }
     if ($search) {
         $leading_wild = ltrim($search, '*') != $search;
         $trailing_wild = rtrim($search, '*') != $search;
         if ($leading_wild && $trailing_wild) {
             $wild = 'both';
         } elseif ($leading_wild) {
             $wild = 'leading';
         } elseif ($trailing_wild) {
             $wild = 'trailing';
         } else {
             $wild = false;
         }
         if ($wild) {
             $search = trim($search, '*');
         }
         $search_columns = array();
         if ($qv['search_columns']) {
             $search_columns = array_intersect($qv['search_columns'], array('ID', 'user_login', 'user_email', 'user_url', 'user_nicename'));
         }
         if (!$search_columns) {
             if (false !== strpos($search, '@')) {
                 $search_columns = array('user_email');
             } elseif (is_numeric($search)) {
                 $search_columns = array('user_login', 'ID');
             } elseif (preg_match('|^https?://|', $search) && !(is_multisite() && wp_is_large_network('users'))) {
                 $search_columns = array('user_url');
             } else {
                 $search_columns = array('user_login', 'user_url', 'user_email', 'user_nicename', 'display_name');
             }
         }
         /**
          * Filter the columns to search in a WP_User_Query search.
          *
          * The default columns depend on the search term, and include 'user_email',
          * 'user_login', 'ID', 'user_url', 'display_name', and 'user_nicename'.
          *
          * @since 3.6.0
          *
          * @param array         $search_columns Array of column names to be searched.
          * @param string        $search         Text being searched.
          * @param WP_User_Query $this           The current WP_User_Query instance.
          */
         $search_columns = apply_filters('user_search_columns', $search_columns, $search, $this);
         $this->query_where .= $this->get_search_sql($search, $search_columns, $wild);
     }
     if (!empty($include)) {
         // Sanitized earlier.
         $ids = implode(',', $include);
         $this->query_where .= " AND {$wpdb->users}.ID IN ({$ids})";
     } elseif (!empty($qv['exclude'])) {
         $ids = implode(',', wp_parse_id_list($qv['exclude']));
         $this->query_where .= " AND {$wpdb->users}.ID NOT IN ({$ids})";
     }
     // Date queries are allowed for the user_registered field.
     if (!empty($qv['date_query']) && is_array($qv['date_query'])) {
         $date_query = new WP_Date_Query($qv['date_query'], 'user_registered');
         $this->query_where .= $date_query->get_sql();
     }
     /**
      * Fires after the WP_User_Query has been parsed, and before
      * the query is executed.
      *
      * The passed WP_User_Query object contains SQL parts formed
      * from parsing the given query.
      *
      * @since 3.1.0
      *
      * @param WP_User_Query $this The current WP_User_Query instance,
      *                            passed by reference.
      */
     do_action_ref_array('pre_user_query', array(&$this));
 }
Ejemplo n.º 28
0
 /**
  * Prepare the query variables.
  *
  * @since 3.1.0
  * @since 4.2.0 Added 'meta_value_num' support for `$orderby` parameter. Added multi-dimensional array syntax
  *              for `$orderby` parameter.
  * @access public
  *
  * @param string|array $query {
  *     Optional. Array or string of Query parameters.
  *
  *     @type int          $blog_id         The site ID. Default is the global blog id.
  *     @type string       $role            Role name. Default empty.
  *     @type string       $meta_key        User meta key. Default empty.
  *     @type string       $meta_value      User meta value. Default empty.
  *     @type string       $meta_compare    Comparison operator to test the `$meta_value`. Accepts '=', '!=',
  *                                         '>', '>=', '<', '<=', 'LIKE', 'NOT LIKE', 'IN', 'NOT IN', 'BETWEEN',
  *                                         'NOT BETWEEN', 'EXISTS', 'NOT EXISTS', 'REGEXP', 'NOT REGEXP',
  *                                         or 'RLIKE'. Default '='.
  *     @type array        $include         An array of user IDs to include. Default empty array.
  *     @type array        $exclude         An array of user IDs to exclude. Default empty array.
  *     @type string       $search          Search keyword. Searches for possible string matches on columns.
  *                                         When `$search_columns` is left empty, it tries to determine which
  *                                         column to search in based on search string. Default empty.
  *     @type array        $search_columns  Array of column names to be searched. Accepts 'ID', 'login',
  *                                         'nicename', 'email', 'url'. Default empty array.
  *     @type string|array $orderby         Field(s) to sort the retrieved users by. May be a single value,
  *                                         an array of values, or a multi-dimensional array with fields as keys
  *                                         and orders ('ASC' or 'DESC') as values. Accepted values are'ID',
  *                                         'display_name' (or 'name'), 'user_login' (or 'login'),
  *                                         'user_nicename' (or 'nicename'), 'user_email' (or 'email'),
  *                                         'user_url' (or 'url'), 'user_registered' (or 'registered'),
  *                                         'post_count', 'meta_value', 'meta_value_num', the value of
  *                                         `$meta_key`, or an array key of `$meta_query`. To use 'meta_value'
  *                                         or 'meta_value_num', `$meta_key` must be also be defined.
  *                                         Default 'user_login'.
  *     @type string       $order           Designates ascending or descending order of users. Order values
  *                                         passed as part of an `$orderby` array take precedence over this
  *                                         parameter. Accepts 'ASC', 'DESC'. Default 'ASC'.
  *     @type int          $offset          Number of users to offset in retrieved results. Can be used in
  *                                         conjunction with pagination. Default 0.
  *     @type int          $number          Number of users to limit the query for. Can be used in conjunction
  *                                         with pagination. Value -1 (all) is not supported.
  *                                         Default empty (all users).
  *     @type bool         $count_total     Whether to count the total number of users found. If pagination is not
  *                                         needed, setting this to false can improve performance. Default true.
  *     @type string|array $fields          Which fields to return. Single or all fields (string), or array
  *                                         of fields. Accepts 'ID', 'display_name', 'login', 'nicename', 'email',
  *                                         'url', 'registered'. Use 'all' for all fields and 'all_with_meta' to
  *                                         include meta fields. Default 'all'.
  *     @type string       $who             Type of users to query. Accepts 'authors'. Default empty (all users).
  * }
  */
 public function prepare_query($query = array())
 {
     global $wpdb;
     if (empty($this->query_vars) || !empty($query)) {
         $this->query_limit = null;
         $this->query_vars = wp_parse_args($query, array('blog_id' => $GLOBALS['blog_id'], 'role' => '', 'meta_key' => '', 'meta_value' => '', 'meta_compare' => '', 'include' => array(), 'exclude' => array(), 'search' => '', 'search_columns' => array(), 'orderby' => 'login', 'order' => 'ASC', 'offset' => '', 'number' => '', 'count_total' => true, 'fields' => 'all', 'who' => ''));
     }
     /**
      * Fires before the WP_User_Query has been parsed.
      *
      * The passed WP_User_Query object contains the query variables, not
      * yet passed into SQL.
      *
      * @since 4.0.0
      *
      * @param WP_User_Query $this The current WP_User_Query instance,
      *                            passed by reference.
      */
     do_action('pre_get_users', $this);
     $qv =& $this->query_vars;
     if (is_array($qv['fields'])) {
         $qv['fields'] = array_unique($qv['fields']);
         $this->query_fields = array();
         foreach ($qv['fields'] as $field) {
             $field = 'ID' === $field ? 'ID' : sanitize_key($field);
             $this->query_fields[] = "{$wpdb->users}.{$field}";
         }
         $this->query_fields = implode(',', $this->query_fields);
     } elseif ('all' == $qv['fields']) {
         $this->query_fields = "{$wpdb->users}.*";
     } else {
         $this->query_fields = "{$wpdb->users}.ID";
     }
     $this->query_from = "FROM {$wpdb->users}";
     $this->query_where = "WHERE 1=1";
     // Parse and sanitize 'include', for use by 'orderby' as well as 'include' below.
     if (!empty($qv['include'])) {
         $include = wp_parse_id_list($qv['include']);
     } else {
         $include = false;
     }
     $blog_id = 0;
     if (isset($qv['blog_id'])) {
         $blog_id = absint($qv['blog_id']);
     }
     if (isset($qv['who']) && 'authors' == $qv['who'] && $blog_id) {
         $qv['meta_key'] = $wpdb->get_blog_prefix($blog_id) . 'user_level';
         $qv['meta_value'] = 0;
         $qv['meta_compare'] = '!=';
         $qv['blog_id'] = $blog_id = 0;
         // Prevent extra meta query
     }
     // Meta query.
     $this->meta_query = new WP_Meta_Query();
     $this->meta_query->parse_query_vars($qv);
     $role = '';
     if (isset($qv['role'])) {
         $role = trim($qv['role']);
     }
     if ($blog_id && ($role || is_multisite())) {
         $cap_meta_query = array();
         $cap_meta_query['key'] = $wpdb->get_blog_prefix($blog_id) . 'capabilities';
         if ($role) {
             $cap_meta_query['value'] = '"' . $role . '"';
             $cap_meta_query['compare'] = 'like';
         }
         if (empty($this->meta_query->queries)) {
             $this->meta_query->queries = array($cap_meta_query);
         } elseif (!in_array($cap_meta_query, $this->meta_query->queries, true)) {
             // Append the cap query to the original queries and reparse the query.
             $this->meta_query->queries = array('relation' => 'AND', array($this->meta_query->queries, $cap_meta_query));
         }
         $this->meta_query->parse_query_vars($this->meta_query->queries);
     }
     if (!empty($this->meta_query->queries)) {
         $clauses = $this->meta_query->get_sql('user', $wpdb->users, 'ID', $this);
         $this->query_from .= $clauses['join'];
         $this->query_where .= $clauses['where'];
         if ('OR' == $this->meta_query->relation) {
             $this->query_fields = 'DISTINCT ' . $this->query_fields;
         }
     }
     // sorting
     $qv['order'] = isset($qv['order']) ? strtoupper($qv['order']) : '';
     $order = $this->parse_order($qv['order']);
     if (empty($qv['orderby'])) {
         // Default order is by 'user_login'.
         $ordersby = array('user_login' => $order);
     } else {
         if (is_array($qv['orderby'])) {
             $ordersby = $qv['orderby'];
         } else {
             // 'orderby' values may be a comma- or space-separated list.
             $ordersby = preg_split('/[,\\s]+/', $qv['orderby']);
         }
     }
     $orderby_array = array();
     foreach ($ordersby as $_key => $_value) {
         if (!$_value) {
             continue;
         }
         if (is_int($_key)) {
             // Integer key means this is a flat array of 'orderby' fields.
             $_orderby = $_value;
             $_order = $order;
         } else {
             // Non-integer key means this the key is the field and the value is ASC/DESC.
             $_orderby = $_key;
             $_order = $_value;
         }
         $parsed = $this->parse_orderby($_orderby);
         if (!$parsed) {
             continue;
         }
         $orderby_array[] = $parsed . ' ' . $this->parse_order($_order);
     }
     // If no valid clauses were found, order by user_login.
     if (empty($orderby_array)) {
         $orderby_array[] = "user_login {$order}";
     }
     $this->query_orderby = 'ORDER BY ' . implode(', ', $orderby_array);
     // limit
     if ($qv['number']) {
         if ($qv['offset']) {
             $this->query_limit = $wpdb->prepare("OFFSET %d ROWS FETCH NEXT %d ROWS ONLY", $qv['offset'], $qv['number']);
         } else {
             $this->query_limit = $wpdb->prepare("OFFSET 0 ROWS FETCH NEXT %d ROWS ONLY", $qv['number']);
         }
     }
     $search = '';
     if (isset($qv['search'])) {
         $search = trim($qv['search']);
     }
     if ($search) {
         $leading_wild = ltrim($search, '*') != $search;
         $trailing_wild = rtrim($search, '*') != $search;
         if ($leading_wild && $trailing_wild) {
             $wild = 'both';
         } elseif ($leading_wild) {
             $wild = 'leading';
         } elseif ($trailing_wild) {
             $wild = 'trailing';
         } else {
             $wild = false;
         }
         if ($wild) {
             $search = trim($search, '*');
         }
         $search_columns = array();
         if ($qv['search_columns']) {
             $search_columns = array_intersect($qv['search_columns'], array('ID', 'user_login', 'user_email', 'user_url', 'user_nicename'));
         }
         if (!$search_columns) {
             if (false !== strpos($search, '@')) {
                 $search_columns = array('user_email');
             } elseif (is_numeric($search)) {
                 $search_columns = array('user_login', 'ID');
             } elseif (preg_match('|^https?://|', $search) && !(is_multisite() && wp_is_large_network('users'))) {
                 $search_columns = array('user_url');
             } else {
                 $search_columns = array('user_login', 'user_nicename');
             }
         }
         /**
          * Filter the columns to search in a WP_User_Query search.
          *
          * The default columns depend on the search term, and include 'user_email',
          * 'user_login', 'ID', 'user_url', and 'user_nicename'.
          *
          * @since 3.6.0
          *
          * @param array         $search_columns Array of column names to be searched.
          * @param string        $search         Text being searched.
          * @param WP_User_Query $this           The current WP_User_Query instance.
          */
         $search_columns = apply_filters('user_search_columns', $search_columns, $search, $this);
         $this->query_where .= $this->get_search_sql($search, $search_columns, $wild);
     }
     if (!empty($include)) {
         // Sanitized earlier.
         $ids = implode(',', $include);
         $this->query_where .= " AND {$wpdb->users}.ID IN ({$ids})";
     } elseif (!empty($qv['exclude'])) {
         $ids = implode(',', wp_parse_id_list($qv['exclude']));
         $this->query_where .= " AND {$wpdb->users}.ID NOT IN ({$ids})";
     }
     // Date queries are allowed for the user_registered field.
     if (!empty($qv['date_query']) && is_array($qv['date_query'])) {
         $date_query = new WP_Date_Query($qv['date_query'], 'user_registered');
         $this->query_where .= $date_query->get_sql();
     }
     /**
      * Fires after the WP_User_Query has been parsed, and before
      * the query is executed.
      *
      * The passed WP_User_Query object contains SQL parts formed
      * from parsing the given query.
      *
      * @since 3.1.0
      *
      * @param WP_User_Query $this The current WP_User_Query instance,
      *                            passed by reference.
      */
     do_action_ref_array('pre_user_query', array(&$this));
 }
Ejemplo n.º 29
0
/**
 * AJAX handler for group member autocomplete requests.
 *
 * @since 1.7.0
 */
function bp_groups_admin_autocomplete_handler()
{
    // Bail if user user shouldn't be here, or is a large network
    if (!current_user_can('bp_moderate') || is_multisite() && wp_is_large_network('users')) {
        wp_die(-1);
    }
    $term = isset($_GET['term']) ? sanitize_text_field($_GET['term']) : '';
    $group_id = isset($_GET['group_id']) ? absint($_GET['group_id']) : 0;
    if (!$term || !$group_id) {
        wp_die(-1);
    }
    $suggestions = bp_core_get_suggestions(array('group_id' => -$group_id, 'limit' => 10, 'term' => $term, 'type' => 'members'));
    $matches = array();
    if ($suggestions && !is_wp_error($suggestions)) {
        foreach ($suggestions as $user) {
            $matches[] = array('label' => sprintf(__('%1$s (%2$s)', 'buddypress'), $user->name, $user->ID), 'value' => $user->ID);
        }
    }
    wp_die(json_encode($matches));
}
Ejemplo n.º 30
0
 private static function get_site_user_count()
 {
     global $wpdb;
     if (function_exists('wp_is_large_network')) {
         if (wp_is_large_network('users')) {
             return -1;
             // Not a real value but should tell us that we are dealing with a large network.
         }
     }
     if (false === ($user_count = get_transient('jetpack_site_user_count'))) {
         // It wasn't there, so regenerate the data and save the transient
         $user_count = $wpdb->get_var("SELECT COUNT(*) FROM {$wpdb->usermeta} WHERE meta_key = '{$wpdb->prefix}capabilities'");
         set_transient('jetpack_site_user_count', $user_count, DAY_IN_SECONDS);
     }
     return $user_count;
 }