Ticket #35791: 35791.1.patch
File 35791.1.patch, 122.7 KB (added by , 9 years ago) |
---|
-
wp-content/themes/twentyfifteen/header.php
50 50 </div><!-- .sidebar --> 51 51 52 52 <div id="content" class="site-content"> 53 <?php wp_update_network_site_counts(); 54 No newline at end of file -
wp-includes/class-wp-site-query.php
1 <?php 2 3 /** 4 * Site API: WP_Site_Query class 5 * 6 * @package WordPress 7 * @subpackage Sites 8 * @since 4.6.0 9 */ 10 11 /** 12 * Core class used for querying sites. 13 * 14 * @since 4.6.0 15 * 16 * @see WP_Site_Query::__construct() for accepted arguments. 17 */ 18 class WP_Site_Query { 19 20 /** 21 * SQL for database query. 22 * 23 * @since 4.6.0 24 * @access public 25 * @var string 26 */ 27 public $request; 28 29 /** 30 * SQL query clauses. 31 * 32 * @since 4.6.0 33 * @access protected 34 * @var array 35 */ 36 protected $sql_clauses = array( 37 'select' => '', 38 'from' => '', 39 'where' => array(), 40 'groupby' => '', 41 'orderby' => '', 42 'limits' => '', 43 ); 44 45 /** 46 * SQL WHERE clause. 47 * 48 * Stored after the 'sites_clauses' filter is run on the compiled WHERE sub-clauses. 49 * 50 * @since 4.6.0 51 * @access protected 52 * @var string 53 */ 54 protected $filtered_where_clause; 55 56 /** 57 * Date query container 58 * 59 * @since 4.6.0 60 * @access public 61 * @var object WP_Date_Query 62 */ 63 public $date_query = false; 64 65 /** 66 * Query vars set by the user. 67 * 68 * @since 4.6.0 69 * @access public 70 * @var array 71 */ 72 public $query_vars; 73 74 /** 75 * Default values for query vars. 76 * 77 * @since 4.6.0 78 * @access public 79 * @var array 80 */ 81 public $query_var_defaults; 82 83 /** 84 * List of sites located by the query. 85 * 86 * @since 4.6.0 87 * @access public 88 * @var array 89 */ 90 public $sites; 91 92 /** 93 * The amount of found sites for the current query. 94 * 95 * @since 4.6.0 96 * @access public 97 * @var int 98 */ 99 public $found_sites = 0; 100 101 /** 102 * The number of pages. 103 * 104 * @since 4.6.0 105 * @access public 106 * @var int 107 */ 108 public $max_num_pages = 0; 109 110 /** 111 * Make private/protected methods readable for backwards compatibility. 112 * 113 * @since 4.6.0 114 * @access public 115 * 116 * @param callable $name Method to call. 117 * @param array $arguments Arguments to pass when calling. 118 * 119 * @return mixed|false Return value of the callback, false otherwise. 120 */ 121 public function __call( $name, $arguments ) { 122 if ( 'get_search_sql' === $name ) { 123 return call_user_func_array( array( $this, $name ), $arguments ); 124 } 125 126 return false; 127 } 128 129 /** 130 * Constructor. 131 * 132 * Sets up the site query, based on the query vars passed. 133 * 134 * @since 4.6.0 135 * @access public 136 * 137 * @param string|array $query { 138 * Optional. Array or query string of site query parameters. Default empty. 139 * 140 * @type array $site__in Array of site IDs to include. Default empty. 141 * @type array $site__not_in Array of site IDs to exclude. Default empty. 142 * @type bool $count Whether to return a site count (true) or array of 143 * site objects (false). Default false. 144 * @type array $date_query Date query clauses to limit sites by. See WP_Date_Query. 145 * Default null. 146 * @type string $fields Site fields to return. Accepts 'ids' for site IDs 147 * only or empty for all fields. Default empty. 148 * @type int $ID Currently unused. 149 * @type int $number Maximum number of sites to retrieve. 150 * Default null (no limit). 151 * @type int $offset Number of sites to offset the query. Used to build 152 * LIMIT clause. Default 0. 153 * @type bool $no_found_rows Whether to disable the `SQL_CALC_FOUND_ROWS` query. 154 * Default: true. 155 * @type string|array $orderby Site status or array of statuses. To use 'meta_value' 156 * or 'meta_value_num', `$meta_key` must also be defined. 157 * To sort by a specific `$meta_query` clause, use that 158 * clause's array key. Accepts 'site_agent', 159 * 'site_approved', 'site_author', 160 * 'site_author_email', 'site_author_IP', 161 * 'site_author_url', 'site_content', 'site_date', 162 * 'site_date_gmt', 'blog_id', 'site_karma', 163 * 'site_parent', 'site_id', 'site_type', 164 * 'user_id', 'site__in', 'meta_value', 'meta_value_num', 165 * the value of $meta_key, and the array keys of 166 * `$meta_query`. Also accepts false, an empty array, or 167 * 'none' to disable `ORDER BY` clause. 168 * Default: 'site_date_gmt'. 169 * @type string $order How to order retrieved sites. Accepts 'ASC', 'DESC'. 170 * Default: 'DESC'. 171 * @type string $domain Limit results to those affiliated with a given network ID. 172 * Default current network id. 173 * @type array $domain__in Array of domains to include affiliated sites for. 174 * Default empty. 175 * @type array $domain__not_in Array of domains to exclude affiliated sites for. 176 * Default empty. 177 * @type string $path Limit results to those affiliated with a given network ID. 178 * Default current network id. 179 * @type array $path__in Array of paths to include affiliated sites for. 180 * Default empty. 181 * @type array $path__not_in Array of paths to exclude affiliated sites for. 182 * Default empty. 183 * @type int $network_id Limit results to those affiliated with a given network ID. 184 * Default current network id. 185 * @type array $network__in Array of network IDs to include affiliated sites for. 186 * Default empty. 187 * @type array $network__not_in Array of network IDs to exclude affiliated sites for. 188 * Default empty. 189 * @type string $search Search term(s) to retrieve matching sites for. 190 * Default empty. 191 * @type bool $update_site_cache Whether to prime the cache for site networks. 192 * Default false. 193 * } 194 */ 195 public function __construct( $query = '' ) { 196 $this->query_var_defaults = array( 197 'fields' => '', 198 'ID' => '', 199 'site__in' => '', 200 'site__not_in' => '', 201 'number' => '', 202 'offset' => '', 203 'no_found_rows' => true, 204 'orderby' => '', 205 'order' => 'DESC', 206 'network_id' => 0, 207 'network__in' => '', 208 'network__not_in' => '', 209 'domain' => '', 210 'domain__in' => '', 211 'domain__not_in' => '', 212 'path' => '', 213 'path__in' => '', 214 'path__not_in' => '', 215 'public' => 'all', 216 'archived' => 'all', 217 'mature' => 'all', 218 'spam' => 'all', 219 'deleted' => 'all', 220 'search' => '', 221 'count' => false, 222 'date_query' => null, // See WP_Date_Query 223 'update_site_cache' => true, 224 ); 225 226 if ( ! empty( $query ) ) { 227 $this->query( $query ); 228 } 229 } 230 231 /** 232 * Parse arguments passed to the site query with default query parameters. 233 * 234 * @since 4.6.0 Extracted from WP_Site_Query::query(). 235 * 236 * @access public 237 * 238 * @param string|array $query WP_Site_Query arguments. See WP_Site_Query::__construct() 239 */ 240 public function parse_query( $query = '' ) { 241 if ( empty( $query ) ) { 242 $query = $this->query_vars; 243 } 244 245 $this->query_vars = wp_parse_args( $query, $this->query_var_defaults ); 246 do_action_ref_array( 'parse_site_query', array( &$this ) ); 247 } 248 249 /** 250 * Sets up the WordPress query for retrieving sites. 251 * 252 * @since 4.6.0 253 * @access public 254 * 255 * @param string|array $query Array or URL query string of parameters. 256 * 257 * @return array|int List of sites, or number of sites when 'count' is passed as a query var. 258 */ 259 public function query( $query ) { 260 $this->query_vars = wp_parse_args( $query ); 261 262 return $this->get_sites(); 263 } 264 265 /** 266 * Get a list of sites matching the query vars. 267 * 268 * @since 4.6.0 269 * @access public 270 * 271 * @global wpdb $wpdb WordPress database abstraction object. 272 * 273 * @return int|array The list of sites. 274 */ 275 public function get_sites() { 276 global $wpdb; 277 278 $this->parse_query(); 279 280 281 /** 282 * Fires before sites are retrieved. 283 * 284 * @since 4.6.0 285 * 286 * @param WP_Site_Query &$this Current instance of WP_Site_Query, passed by reference. 287 */ 288 do_action_ref_array( 'pre_get_sites', array( &$this ) ); 289 290 // $args can include anything. Only use the args defined in the query_var_defaults to compute the key. 291 $key = md5( serialize( wp_array_slice_assoc( $this->query_vars, array_keys( $this->query_var_defaults ) ) ) ); 292 $last_changed = wp_cache_get( 'last_changed', 'site' ); 293 if ( ! $last_changed ) { 294 $last_changed = microtime(); 295 wp_cache_set( 'last_changed', $last_changed, 'site' ); 296 } 297 $cache_key = "get_site_ids:$key:$last_changed"; 298 299 $site_ids = wp_cache_get( $cache_key, 'site' ); 300 if ( false === $site_ids ) { 301 $site_ids = $this->get_site_ids(); 302 wp_cache_add( $cache_key, $site_ids, 'site' ); 303 } 304 305 // If querying for a count only, there's nothing more to do. 306 if ( $this->query_vars['count'] ) { 307 // $site_ids is actually a count in this case. 308 return intval( $site_ids ); 309 } 310 311 $site_ids = array_map( 'intval', $site_ids ); 312 313 $this->site_count = count( $this->sites ); 314 315 if ( $site_ids && $this->query_vars['number'] && ! $this->query_vars['no_found_rows'] ) { 316 /** 317 * Filter the query used to retrieve found site count. 318 * 319 * @since 4.6.0 320 * 321 * @param string $found_sites_query SQL query. Default 'SELECT FOUND_ROWS()'. 322 * @param WP_Site_Query $site_query The `WP_Site_Query` instance. 323 */ 324 $found_sites_query = apply_filters( 'found_sites_query', 'SELECT FOUND_ROWS()', $this ); 325 $this->found_sites = (int) $wpdb->get_var( $found_sites_query ); 326 327 $this->max_num_pages = ceil( $this->found_sites / $this->query_vars['number'] ); 328 } 329 330 if ( 'ids' == $this->query_vars['fields'] ) { 331 $this->sites = $site_ids; 332 333 return $this->sites; 334 } 335 336 // Fetch full site objects from the primed cache. 337 $_sites = array(); 338 foreach ( $site_ids as $site_id ) { 339 if ( $_site = get_site( $site_id ) ) { 340 $_sites[] = $_site; 341 } 342 } 343 344 // Prime site network caches. 345 if ( $this->query_vars['update_site_cache'] ) { 346 $site_ids = array(); 347 foreach ( $_sites as $_site ) { 348 $site_ids[] = $_site->site_id; 349 } 350 _prime_site_caches( $site_ids ); 351 } 352 353 /** 354 * Filter the site query results. 355 * 356 * @since 4.6.0 357 * 358 * @param array $results An array of sites. 359 * @param WP_Site_Query &$this Current instance of WP_Site_Query, passed by reference. 360 */ 361 $_sites = apply_filters_ref_array( 'the_sites', array( $_sites, &$this ) ); 362 363 // Convert to WP_Site instances 364 $sites = array_map( 'get_site', $_sites ); 365 366 $this->sites = $sites; 367 368 return $this->sites; 369 } 370 371 /** 372 * Used internally to get a list of site IDs matching the query vars. 373 * 374 * @since 4.6.0 375 * @access protected 376 * 377 * @global wpdb $wpdb WordPress database abstraction object. 378 */ 379 protected function get_site_ids() { 380 global $wpdb; 381 382 $order = ( 'ASC' == strtoupper( $this->query_vars['order'] ) ) ? 'ASC' : 'DESC'; 383 384 // Disable ORDER BY with 'none', an empty array, or boolean false. 385 if ( in_array( $this->query_vars['orderby'], array( 'none', array(), false ), true ) ) { 386 $orderby = ''; 387 } elseif ( ! empty( $this->query_vars['orderby'] ) ) { 388 $ordersby = is_array( $this->query_vars['orderby'] ) ? 389 $this->query_vars['orderby'] : 390 preg_split( '/[,\s]/', $this->query_vars['orderby'] ); 391 392 $orderby_array = array(); 393 $found_orderby_blog_id = false; 394 foreach ( $ordersby as $_key => $_value ) { 395 if ( ! $_value ) { 396 continue; 397 } 398 399 if ( is_int( $_key ) ) { 400 $_orderby = $_value; 401 $_order = $order; 402 } else { 403 $_orderby = $_key; 404 $_order = $_value; 405 } 406 407 if ( ! $found_orderby_blog_id && in_array( $_orderby, array( 'blog_id', 'site__in' ) ) ) { 408 $found_orderby_blog_id = true; 409 } 410 411 $parsed = $this->parse_orderby( $_orderby ); 412 413 if ( ! $parsed ) { 414 continue; 415 } 416 417 if ( 'site__in' === $_orderby ) { 418 $orderby_array[] = $parsed; 419 continue; 420 } 421 422 $orderby_array[] = $parsed . ' ' . $this->parse_order( $_order ); 423 } 424 425 $orderby = implode( ', ', $orderby_array ); 426 } else { 427 $orderby = "blog_id $order"; 428 } 429 430 $number = absint( $this->query_vars['number'] ); 431 $offset = absint( $this->query_vars['offset'] ); 432 433 if ( ! empty( $number ) ) { 434 if ( $offset ) { 435 $limits = 'LIMIT ' . $offset . ',' . $number; 436 } else { 437 $limits = 'LIMIT ' . $number; 438 } 439 } 440 441 if ( $this->query_vars['count'] ) { 442 $fields = 'COUNT(*)'; 443 } else { 444 $fields = "blog_id"; 445 } 446 447 // Parse site IDs for an IN clause. 448 $site_id = absint( $this->query_vars['ID'] ); 449 if ( ! empty( $site_id ) ) { 450 $this->sql_clauses['where']['ID'] = $wpdb->prepare( 'blog_id = %d', $site_id ); 451 } 452 453 // Parse site IDs for an IN clause. 454 if ( ! empty( $this->query_vars['site__in'] ) ) { 455 $this->sql_clauses['where']['site__in'] = "blog_id IN ( " . implode( ',', wp_parse_id_list( $this->query_vars['site__in'] ) ) . ' )'; 456 } 457 458 // Parse site IDs for a NOT IN clause. 459 if ( ! empty( $this->query_vars['site__not_in'] ) ) { 460 $this->sql_clauses['where']['site__not_in'] = "blog_id NOT IN ( " . implode( ',', wp_parse_id_list( $this->query_vars['site__not_in'] ) ) . ' )'; 461 } 462 463 $network_id = absint( $this->query_vars['network_id'] ); 464 if ( ! empty( $network_id ) ) { 465 $this->sql_clauses['where']['network_id'] = $wpdb->prepare( 'site_id = %d', $network_id ); 466 } 467 468 // Parse site network IDs for an IN clause. 469 if ( ! empty( $this->query_vars['network__in'] ) ) { 470 $this->sql_clauses['where']['network__in'] = 'site_id IN ( ' . implode( ',', wp_parse_id_list( $this->query_vars['network__in'] ) ) . ' )'; 471 } 472 473 // Parse site network IDs for a NOT IN clause. 474 if ( ! empty( $this->query_vars['network__not_in'] ) ) { 475 $this->sql_clauses['where']['network__not_in'] = 'site_id NOT IN ( ' . implode( ',', wp_parse_id_list( $this->query_vars['network__not_in'] ) ) . ' )'; 476 } 477 478 479 if ( ! empty( $this->query_vars['domain'] ) ) { 480 $this->sql_clauses['where']['domain'] = $wpdb->prepare( 'domain = %s', $this->query_vars['domain'] ); 481 } 482 483 // Parse site domain for an IN clause. 484 if ( is_array( $this->query_vars['domain__in'] ) ) { 485 $this->sql_clauses['where']['domain__in'] = "domain IN ( '" . implode( "', '", $wpdb->_escape( $this->query_vars['domain__in'] ) ) . "' )"; 486 } 487 488 // Parse site domain for a NOT IN clause. 489 if ( is_array( $this->query_vars['domain__not_in'] ) ) { 490 $this->sql_clauses['where']['domain__not_in'] = "domain NOT IN ( '" . implode( "', '", $wpdb->_escape( $this->query_vars['domain__not_in'] ) ) . "' )"; 491 } 492 493 494 if ( ! empty( $this->query_vars['path'] ) ) { 495 $this->sql_clauses['where']['path'] = $wpdb->prepare( 'path = %s', $this->query_vars['path'] ); 496 } 497 498 // Parse site path for an IN clause. 499 if ( is_array( $this->query_vars['path__in'] ) ) { 500 $this->sql_clauses['where']['path__in'] = "path IN ( '" . implode( "', '", $wpdb->_escape( $this->query_vars['path__in'] ) ) . "' )"; 501 } 502 503 // Parse site path for a NOT IN clause. 504 if ( is_array( $this->query_vars['path__not_in'] ) ) { 505 $this->sql_clauses['where']['path__not_in'] = "path NOT IN ( '" . implode( "', '", $wpdb->_escape( $this->query_vars['path__not_in'] ) ) . "' )"; 506 } 507 508 509 if ( is_numeric( $this->query_vars['archived'] ) ) { 510 $archived = absint( $this->query_vars['archived'] ); 511 $this->sql_clauses['where']['archived'] = $wpdb->prepare( "archived = %d ", $archived ); 512 } 513 514 if ( is_numeric( $this->query_vars['mature'] ) ) { 515 $mature = absint( $this->query_vars['mature'] ); 516 $this->sql_clauses['where']['mature'] = $wpdb->prepare( "mature = %d ", $mature ); 517 } 518 519 if ( is_numeric( $this->query_vars['spam'] ) ) { 520 $spam = absint( $this->query_vars['spam'] ); 521 $this->sql_clauses['where']['spam'] = $wpdb->prepare( "spam = %d ", $spam ); 522 } 523 524 if ( is_numeric( $this->query_vars['deleted'] ) ) { 525 $deleted = absint( $this->query_vars['deleted'] ); 526 $this->sql_clauses['where']['deleted'] = $wpdb->prepare( "deleted = %d ", $deleted ); 527 } 528 529 // Falsy search strings are ignored. 530 if ( strlen( $this->query_vars['search'] ) ) { 531 $search_sql = $this->get_search_sql( 532 $this->query_vars['search'], 533 array( 'domain', 'path' ) 534 ); 535 536 // Strip leading 'AND'. 537 $this->sql_clauses['where']['search'] = preg_replace( '/^\s*AND\s*/', '', $search_sql ); 538 } 539 540 $date_query = $this->query_vars['date_query']; 541 if ( ! empty( $date_query ) && is_array( $date_query ) ) { 542 $date_query_object = new WP_Date_Query( $date_query, 'registered' ); 543 $this->sql_clauses['where']['date_query'] = preg_replace( '/^\s*AND\s*/', '', $date_query_object->get_sql() ); 544 } 545 546 $where = implode( ' AND ', $this->sql_clauses['where'] ); 547 548 $pieces = array( 'fields', 'join', 'where', 'orderby', 'limits', 'groupby' ); 549 /** 550 * Filter the site query clauses. 551 * 552 * @since 4.6.0 553 * 554 * @param array $pieces A compacted array of site query clauses. 555 * @param WP_Site_Query &$this Current instance of WP_Site_Query, passed by reference. 556 */ 557 $clauses = apply_filters_ref_array( 'sites_clauses', array( compact( $pieces ), &$this ) ); 558 $fields = isset( $clauses['fields'] ) ? $clauses['fields'] : ''; 559 $join = isset( $clauses['join'] ) ? $clauses['join'] : ''; 560 $where = isset( $clauses['where'] ) ? $clauses['where'] : ''; 561 $orderby = isset( $clauses['orderby'] ) ? $clauses['orderby'] : ''; 562 $limits = isset( $clauses['limits'] ) ? $clauses['limits'] : ''; 563 $groupby = isset( $clauses['groupby'] ) ? $clauses['groupby'] : ''; 564 565 $this->filtered_where_clause = $where; 566 567 if ( $where ) { 568 $where = 'WHERE ' . $where; 569 } 570 571 if ( $groupby ) { 572 $groupby = 'GROUP BY ' . $groupby; 573 } 574 575 if ( $orderby ) { 576 $orderby = "ORDER BY $orderby"; 577 } 578 579 $found_rows = ''; 580 if ( ! $this->query_vars['no_found_rows'] ) { 581 $found_rows = 'SQL_CALC_FOUND_ROWS'; 582 } 583 584 $this->sql_clauses['select'] = "SELECT $found_rows $fields"; 585 $this->sql_clauses['from'] = "FROM $wpdb->blogs $join"; 586 $this->sql_clauses['groupby'] = $groupby; 587 $this->sql_clauses['orderby'] = $orderby; 588 $this->sql_clauses['limits'] = $limits; 589 590 $this->request = "{$this->sql_clauses['select']} {$this->sql_clauses['from']} {$where} {$this->sql_clauses['groupby']} {$this->sql_clauses['orderby']} {$this->sql_clauses['limits']}"; 591 592 if ( $this->query_vars['count'] ) { 593 return intval( $wpdb->get_var( $this->request ) ); 594 } else { 595 $site_ids = $wpdb->get_col( $this->request ); 596 597 return array_map( 'intval', $site_ids ); 598 } 599 } 600 601 /** 602 * Used internally to generate an SQL string for searching across multiple columns 603 * 604 * @since 4.6.0 605 * @access protected 606 * 607 * @global wpdb $wpdb WordPress database abstraction object. 608 * 609 * @param string $string 610 * @param array $cols 611 * 612 * @return string 613 */ 614 protected function get_search_sql( $string, $cols ) { 615 global $wpdb; 616 617 $like = '%' . $wpdb->esc_like( $string ) . '%'; 618 619 $searches = array(); 620 foreach ( $cols as $col ) { 621 $searches[] = $wpdb->prepare( "$col LIKE %s", $like ); 622 } 623 624 return ' AND (' . implode( ' OR ', $searches ) . ')'; 625 } 626 627 /** 628 * Parse and sanitize 'orderby' keys passed to the site query. 629 * 630 * @since 4.6.0 631 * @access protected 632 * 633 * @global wpdb $wpdb WordPress database abstraction object. 634 * 635 * @param string $orderby Alias for the field to order by. 636 * 637 * @return string|false Value to used in the ORDER clause. False otherwise. 638 */ 639 protected function parse_orderby( $orderby ) { 640 global $wpdb; 641 642 switch ( $orderby ) { 643 case 'domain': 644 case 'last_updated': 645 case 'path': 646 case 'registered': 647 $_orderby = $orderby; 648 break; 649 case 'network_id': 650 $_orderby = "site_id"; 651 break; 652 case 'ids': 653 default: 654 $_orderby = "blog_id"; 655 break; 656 } 657 658 $parsed = "$_orderby"; 659 660 661 return $parsed; 662 } 663 664 /** 665 * Parse an 'order' query variable and cast it to ASC or DESC as necessary. 666 * 667 * @since 4.6.0 668 * @access protected 669 * 670 * @param string $order The 'order' query variable. 671 * 672 * @return string The sanitized 'order' query variable. 673 */ 674 protected function parse_order( $order ) { 675 if ( ! is_string( $order ) || empty( $order ) ) { 676 return 'DESC'; 677 } 678 679 if ( 'ASC' === strtoupper( $order ) ) { 680 return 'ASC'; 681 } else { 682 return 'DESC'; 683 } 684 } 685 } -
wp-includes/date.php
Property changes on: wp-includes/class-wp-site-query.php ___________________________________________________________________ Added: svn:executable ## -0,0 +1 ## +* \ No newline at end of property
489 489 global $wpdb; 490 490 491 491 $valid_columns = array( 492 'post_date', 'post_date_gmt', 'post_modified', 493 'post_modified_gmt', 'comment_date', 'comment_date_gmt', 492 'post_date', 493 'post_date_gmt', 494 'post_modified', 495 'post_modified_gmt', 496 'comment_date', 497 'comment_date_gmt', 494 498 'user_registered', 499 'registered', 500 'last_updated', 495 501 ); 496 502 497 503 // Attempt to detect a table prefix. … … 525 531 $wpdb->users => array( 526 532 'user_registered', 527 533 ), 534 $wpdb->blogs => array( 535 'registered', 536 'last_updated', 537 ), 528 538 ); 529 539 530 540 // If it's a known column name, add the appropriate table prefix. -
wp-includes/http.php
607 607 * @return bool 608 608 */ 609 609 function ms_allowed_http_request_hosts( $is_external, $host ) { 610 global $wpdb;611 610 static $queried = array(); 612 if ( $is_external ) 611 if ( $is_external ) { 613 612 return $is_external; 614 if ( $host === get_current_site()->domain ) 613 } 614 if ( $host === get_current_site()->domain ) { 615 615 return true; 616 if ( isset( $queried[ $host ] ) ) 616 } 617 if ( isset( $queried[ $host ] ) ) { 617 618 return $queried[ $host ]; 618 $queried[ $host ] = (bool) $wpdb->get_var( $wpdb->prepare( "SELECT domain FROM $wpdb->blogs WHERE domain = %s LIMIT 1", $host ) ); 619 } 620 $query = new WP_Site_Query(); 621 $result = $query->query( array( 'domain' => $host, 'count' => true ) ); 622 $queried[ $host ] = (bool) $result; 623 619 624 return $queried[ $host ]; 620 625 } 621 626 -
wp-includes/ms-blogs.php
99 99 $path = $current_site->path . $slug . '/'; 100 100 } 101 101 102 $blog_id = $wpdb->get_var( $wpdb->prepare("SELECT blog_id FROM {$wpdb->blogs} WHERE domain = %s AND path = %s", $domain, $path) ); 102 $query = new WP_Site_Query(); 103 $result = $query->query( array( 'domain' => $domain, 'path' => $path, 'fields' => 'ids' ) ); 104 $blog_id = array_shift( $result ); 105 103 106 wp_cache_set( 'get_id_from_blogname_' . $slug, $blog_id, 'blog-details' ); 107 104 108 return $blog_id; 105 109 } 106 110 … … 126 130 } elseif ( isset($fields['domain']) && isset($fields['path']) ) { 127 131 $key = md5( $fields['domain'] . $fields['path'] ); 128 132 $blog = wp_cache_get($key, 'blog-lookup'); 129 if ( false !== $blog ) 133 if ( false !== $blog ) { 130 134 return $blog; 135 } 136 137 $domains = array( $fields['domain'] ); 131 138 if ( substr( $fields['domain'], 0, 4 ) == 'www.' ) { 132 $nowww = substr( $fields['domain'], 4 ); 133 $blog = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->blogs WHERE domain IN (%s,%s) AND path = %s ORDER BY CHAR_LENGTH(domain) DESC", $nowww, $fields['domain'], $fields['path'] ) ); 134 } else { 135 $blog = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->blogs WHERE domain = %s AND path = %s", $fields['domain'], $fields['path'] ) ); 139 $domains[] = substr( $fields['domain'], 4 ); 136 140 } 141 142 $query = new WP_Site_Query(); 143 $args = array( 'domain__in' => $domains, 'path' => $fields['path'], 'number' => 1 ); 144 $result = $query->query( $args ); 145 $blog = array_shift( $result ); 146 137 147 if ( $blog ) { 138 148 wp_cache_set($blog->blog_id . 'short', $blog, 'blog-details'); 139 149 $blog_id = $blog->blog_id; … … 143 153 } elseif ( isset($fields['domain']) && is_subdomain_install() ) { 144 154 $key = md5( $fields['domain'] ); 145 155 $blog = wp_cache_get($key, 'blog-lookup'); 146 if ( false !== $blog ) 156 if ( false !== $blog ) { 147 157 return $blog; 158 } 159 $domains = array($fields['domain']); 148 160 if ( substr( $fields['domain'], 0, 4 ) == 'www.' ) { 149 $nowww = substr( $fields['domain'], 4 ); 150 $blog = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->blogs WHERE domain IN (%s,%s) ORDER BY CHAR_LENGTH(domain) DESC", $nowww, $fields['domain'] ) ); 151 } else { 152 $blog = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->blogs WHERE domain = %s", $fields['domain'] ) ); 161 $domains[] = substr( $fields['domain'], 4 ); 153 162 } 163 164 $query = new WP_Site_Query(); 165 $args = array( 'domain__in' => $domains, 'number' => 1 ); 166 $result = $query->query( $args ); 167 $blog = array_shift( $result ); 168 154 169 if ( $blog ) { 155 170 wp_cache_set($blog->blog_id . 'short', $blog, 'blog-details'); 156 171 $blog_id = $blog->blog_id; … … 457 472 } 458 473 459 474 /** 475 * Retrieves site data given a site ID or site object. 476 * 477 * If an object is passed then the site data will be cached and then returned 478 * after being passed through a filter. If the site is empty, then the global 479 * site variable will be used, if it is set. 480 * 481 * @since 4.6.0 482 * 483 * @global WP_Site $site 484 * 485 * @param WP_Site|string|int $site Site to retrieve. 486 * @param string $output Optional. OBJECT or ARRAY_A or ARRAY_N constants. 487 * 488 * @return WP_Site|array|null Depends on $output value. 489 */ 490 function get_site( &$site = null, $output = OBJECT ) { 491 global $current_blog; 492 if ( empty( $site ) && isset( $current_blog ) ) { 493 $site = $current_blog; 494 } 495 496 if ( $site instanceof WP_Site ) { 497 $_site = $site; 498 } elseif ( is_object( $site ) ) { 499 $_site = new WP_Site( $site ); 500 } else { 501 $_site = WP_Site::get_instance( $site ); 502 } 503 504 if ( ! $_site ) { 505 return null; 506 } 507 508 /** 509 * Fires after a site is retrieved. 510 * 511 * @since 4.6.0 512 * 513 * @param mixed $_site Site data. 514 */ 515 $_site = apply_filters( 'get_site', $_site ); 516 517 if ( $output == OBJECT ) { 518 return $_site; 519 } elseif ( $output == ARRAY_A ) { 520 return $_site->to_array(); 521 } elseif ( $output == ARRAY_N ) { 522 return array_values( $_site->to_array() ); 523 } 524 525 return $_site; 526 } 527 528 /** 529 * Adds any sites from the given ids to the cache that do not already exist in cache 530 * 531 * @since 4.6.0 532 * @access private 533 * 534 * @see update_site_cache() 535 * 536 * @global wpdb $wpdb WordPress database abstraction object. 537 * 538 * @param array $ids ID list. 539 */ 540 function _prime_site_caches( $ids ) { 541 global $wpdb; 542 543 $non_cached_ids = _get_non_cached_ids( $ids, 'sites' ); 544 if ( ! empty( $non_cached_ids ) ) { 545 $fresh_sites = $wpdb->get_results( sprintf( "SELECT * FROM $wpdb->blogs WHERE blog_id IN (%s)", join( ",", $non_cached_ids ) ) ); 546 547 update_site_cache( $fresh_sites ); 548 } 549 } 550 551 /** 552 * Updates sites in cache. 553 * 554 * @since 4.6.0 555 * 556 * @param array $sites Array of site objects, passed by reference. 557 */ 558 function update_site_cache( &$sites ) { 559 if ( ! $sites ) { 560 return; 561 } 562 563 foreach ( $sites as $site ) { 564 wp_cache_add( $site->blog_id, $site, 'sites' ); 565 } 566 } 567 568 /** 460 569 * Retrieve option value for a given blog id based on name of option. 461 570 * 462 571 * If the option does not exist or does not have a value, then the return value -
wp-includes/ms-functions.php
37 37 * @global wpdb $wpdb WordPress database abstraction object. 38 38 * 39 39 * @param int $user_id The unique ID of the user 40 * 40 41 * @return WP_Site|void The blog object 41 42 */ 42 43 function get_active_blog_for_user( $user_id ) { 43 44 global $wpdb; 44 45 $blogs = get_blogs_of_user( $user_id ); 45 if ( empty( $blogs ) ) 46 if ( empty( $blogs ) ) { 46 47 return; 48 } 47 49 48 if ( !is_multisite() ) 49 return $blogs[$wpdb->blogid]; 50 if ( ! is_multisite() ) { 51 return $blogs[ $wpdb->blogid ]; 52 } 50 53 51 54 $primary_blog = get_user_meta( $user_id, 'primary_blog', true ); 52 $first_blog = current($blogs);55 $first_blog = current( $blogs ); 53 56 if ( false !== $primary_blog ) { 54 57 if ( ! isset( $blogs[ $primary_blog ] ) ) { 55 58 update_user_meta( $user_id, 'primary_blog', $first_blog->userblog_id ); … … 66 69 67 70 if ( ( ! is_object( $primary ) ) || ( $primary->archived == 1 || $primary->spam == 1 || $primary->deleted == 1 ) ) { 68 71 $blogs = get_blogs_of_user( $user_id, true ); // if a user's primary blog is shut down, check their other blogs. 69 $ret = false;72 $ret = false; 70 73 if ( is_array( $blogs ) && count( $blogs ) > 0 ) { 71 74 foreach ( (array) $blogs as $blog_id => $blog ) { 72 if ( $blog->site_id != $wpdb->siteid ) 75 if ( $blog->site_id != $wpdb->siteid ) { 73 76 continue; 77 } 74 78 $details = get_blog_details( $blog_id ); 75 79 if ( is_object( $details ) && $details->archived == 0 && $details->spam == 0 && $details->deleted == 0 ) { 76 80 $ret = $blog; 77 if ( get_user_meta( $user_id , 'primary_blog', true ) != $blog_id )81 if ( get_user_meta( $user_id, 'primary_blog', true ) != $blog_id ) { 78 82 update_user_meta( $user_id, 'primary_blog', $blog_id ); 79 if ( !get_user_meta($user_id , 'source_domain', true) ) 83 } 84 if ( ! get_user_meta( $user_id, 'source_domain', true ) ) { 80 85 update_user_meta( $user_id, 'source_domain', $blog->domain ); 86 } 81 87 break; 82 88 } 83 89 } … … 84 90 } else { 85 91 return; 86 92 } 93 87 94 return $ret; 88 95 } else { 89 96 return $primary; … … 111 118 * @since MU 1.0 112 119 * 113 120 * @param int $network_id Deprecated, not supported. 121 * 114 122 * @return int 115 123 */ 116 124 function get_blog_count( $network_id = 0 ) { 117 if ( func_num_args() ) 125 if ( func_num_args() ) { 118 126 _deprecated_argument( __FUNCTION__, '3.1' ); 127 } 119 128 120 129 return get_site_option( 'blog_count' ); 121 130 } … … 127 136 * 128 137 * @param int $blog_id ID of the blog. 129 138 * @param int $post_id ID of the post you're looking for. 139 * 130 140 * @return WP_Post|null WP_Post on success or null on failure 131 141 */ 132 142 function get_blog_post( $blog_id, $post_id ) { … … 145 155 * 146 156 * @since MU 1.0 147 157 * 148 * @param int $blog_id ID of the blog you're adding the user to. 149 * @param int $user_id ID of the user you're adding. 150 * @param string $role The role you want the user to have 158 * @param int $blog_id ID of the blog you're adding the user to. 159 * @param int $user_id ID of the user you're adding. 160 * @param string $role The role you want the user to have 161 * 151 162 * @return true|WP_Error 152 163 */ 153 164 function add_user_to_blog( $blog_id, $user_id, $role ) { 154 switch_to_blog( $blog_id);165 switch_to_blog( $blog_id ); 155 166 156 167 $user = get_userdata( $user_id ); 157 168 158 169 if ( ! $user ) { 159 170 restore_current_blog(); 171 160 172 return new WP_Error( 'user_does_not_exist', __( 'The requested user does not exist.' ) ); 161 173 } 162 174 163 if ( ! get_user_meta($user_id, 'primary_blog', true) ) {164 update_user_meta( $user_id, 'primary_blog', $blog_id);165 $details = get_blog_details( $blog_id);166 update_user_meta( $user_id, 'source_domain', $details->domain);175 if ( ! get_user_meta( $user_id, 'primary_blog', true ) ) { 176 update_user_meta( $user_id, 'primary_blog', $blog_id ); 177 $details = get_blog_details( $blog_id ); 178 update_user_meta( $user_id, 'source_domain', $details->domain ); 167 179 } 168 180 169 $user->set_role( $role);181 $user->set_role( $role ); 170 182 171 183 /** 172 184 * Fires immediately after a user is added to a site. … … 173 185 * 174 186 * @since MU 175 187 * 176 * @param int 177 * @param string $role 178 * @param int 188 * @param int $user_id User ID. 189 * @param string $role User role. 190 * @param int $blog_id Blog ID. 179 191 */ 180 192 do_action( 'add_user_to_blog', $user_id, $role, $blog_id ); 181 193 wp_cache_delete( $user_id, 'users' ); 182 194 wp_cache_delete( $blog_id . '_user_count', 'blog-details' ); 183 195 restore_current_blog(); 196 184 197 return true; 185 198 } 186 199 … … 197 210 * 198 211 * @global wpdb $wpdb WordPress database abstraction object. 199 212 * 200 * @param int $user_idID of the user you're removing.201 * @param int $blog_idID of the blog you're removing the user from.213 * @param int $user_id ID of the user you're removing. 214 * @param int $blog_id ID of the blog you're removing the user from. 202 215 * @param string $reassign Optional. A user to whom to reassign posts. 216 * 203 217 * @return true|WP_Error 204 218 */ 205 function remove_user_from_blog( $user_id, $blog_id = '', $reassign = '') {219 function remove_user_from_blog( $user_id, $blog_id = '', $reassign = '' ) { 206 220 global $wpdb; 207 switch_to_blog( $blog_id);221 switch_to_blog( $blog_id ); 208 222 $user_id = (int) $user_id; 209 223 /** 210 224 * Fires before a user is removed from a site. … … 218 232 219 233 // If being removed from the primary blog, set a new primary if the user is assigned 220 234 // to multiple blogs. 221 $primary_blog = get_user_meta( $user_id, 'primary_blog', true);235 $primary_blog = get_user_meta( $user_id, 'primary_blog', true ); 222 236 if ( $primary_blog == $blog_id ) { 223 $new_id = '';237 $new_id = ''; 224 238 $new_domain = ''; 225 $blogs = get_blogs_of_user($user_id);239 $blogs = get_blogs_of_user( $user_id ); 226 240 foreach ( (array) $blogs as $blog ) { 227 if ( $blog->userblog_id == $blog_id ) 241 if ( $blog->userblog_id == $blog_id ) { 228 242 continue; 229 $new_id = $blog->userblog_id; 243 } 244 $new_id = $blog->userblog_id; 230 245 $new_domain = $blog->domain; 231 246 break; 232 247 } 233 248 234 update_user_meta( $user_id, 'primary_blog', $new_id);235 update_user_meta( $user_id, 'source_domain', $new_domain);249 update_user_meta( $user_id, 'primary_blog', $new_id ); 250 update_user_meta( $user_id, 'source_domain', $new_domain ); 236 251 } 237 252 238 253 // wp_revoke_user($user_id); … … 239 254 $user = get_userdata( $user_id ); 240 255 if ( ! $user ) { 241 256 restore_current_blog(); 242 return new WP_Error('user_does_not_exist', __('That user does not exist.')); 257 258 return new WP_Error( 'user_does_not_exist', __( 'That user does not exist.' ) ); 243 259 } 244 260 245 261 $user->remove_all_caps(); 246 262 247 $blogs = get_blogs_of_user( $user_id);248 if ( count( $blogs) == 0 ) {249 update_user_meta( $user_id, 'primary_blog', '');250 update_user_meta( $user_id, 'source_domain', '');263 $blogs = get_blogs_of_user( $user_id ); 264 if ( count( $blogs ) == 0 ) { 265 update_user_meta( $user_id, 'primary_blog', '' ); 266 update_user_meta( $user_id, 'source_domain', '' ); 251 267 } 252 268 253 269 if ( $reassign != '' ) { … … 278 294 * 279 295 * @param int $blog_id ID of the source blog. 280 296 * @param int $post_id ID of the desired post. 297 * 281 298 * @return string The post's permalink 282 299 */ 283 300 function get_blog_permalink( $blog_id, $post_id ) { … … 301 318 * @global wpdb $wpdb WordPress database abstraction object. 302 319 * 303 320 * @param string $domain 304 * @param string $path Optional. Not required for subdomain installations. 321 * @param string $path Optional. Not required for subdomain installations. 322 * 305 323 * @return int 0 if no blog found, otherwise the ID of the matching blog 306 324 */ 307 325 function get_blog_id_from_url( $domain, $path = '/' ) { … … 308 326 global $wpdb; 309 327 310 328 $domain = strtolower( $domain ); 311 $path = strtolower( $path );312 $id = wp_cache_get( md5( $domain . $path ), 'blog-id-cache' );329 $path = strtolower( $path ); 330 $id = wp_cache_get( md5( $domain . $path ), 'blog-id-cache' ); 313 331 314 if ( $id == -1 ) // blog does not exist 332 if ( $id == - 1 ) // blog does not exist 333 { 315 334 return 0; 316 elseif ( $id )335 } elseif ( $id ) { 317 336 return (int) $id; 337 } 318 338 319 $id = $wpdb->get_var( $wpdb->prepare( "SELECT blog_id FROM $wpdb->blogs WHERE domain = %s and path = %s /* get_blog_id_from_url */", $domain, $path ) ); 339 $query = new WP_Site_Query(); 340 $result = $query->query( array( 'domain' => $domain, 'path' => $path, 'fields' => 'ids' ) ); 341 $id = array_shift( $result ); 342 if ( ! $id ) { 343 wp_cache_set( md5( $domain . $path ), - 1, 'blog-id-cache' ); 320 344 321 if ( ! $id ) {322 wp_cache_set( md5( $domain . $path ), -1, 'blog-id-cache' );323 345 return 0; 324 346 } 325 347 … … 341 363 * @since MU 342 364 * 343 365 * @param string $user_email The email provided by the user at registration. 366 * 344 367 * @return bool Returns true when the email address is banned. 345 368 */ 346 369 function is_email_address_unsafe( $user_email ) { 347 370 $banned_names = get_site_option( 'banned_email_domains' ); 348 if ( $banned_names && ! is_array( $banned_names ) ) 371 if ( $banned_names && ! is_array( $banned_names ) ) { 349 372 $banned_names = explode( "\n", $banned_names ); 373 } 350 374 351 375 $is_email_address_unsafe = false; 352 376 353 377 if ( $banned_names && is_array( $banned_names ) ) { 354 $banned_names = array_map( 'strtolower', $banned_names );378 $banned_names = array_map( 'strtolower', $banned_names ); 355 379 $normalized_email = strtolower( $user_email ); 356 380 357 381 list( $email_local_part, $email_domain ) = explode( '@', $normalized_email ); 358 382 359 383 foreach ( $banned_names as $banned_domain ) { 360 if ( ! $banned_domain ) 384 if ( ! $banned_domain ) { 361 385 continue; 386 } 362 387 363 388 if ( $email_domain == $banned_domain ) { 364 389 $is_email_address_unsafe = true; … … 366 391 } 367 392 368 393 $dotted_domain = ".$banned_domain"; 369 if ( $dotted_domain === substr( $normalized_email, - strlen( $dotted_domain ) ) ) {394 if ( $dotted_domain === substr( $normalized_email, - strlen( $dotted_domain ) ) ) { 370 395 $is_email_address_unsafe = true; 371 396 break; 372 397 } … … 378 403 * 379 404 * @since 3.5.0 380 405 * 381 * @param bool 382 * @param string $user_email 406 * @param bool $is_email_address_unsafe Whether the email address is "unsafe". Default false. 407 * @param string $user_email User email address. 383 408 */ 384 409 return apply_filters( 'is_email_address_unsafe', $is_email_address_unsafe, $user_email ); 385 410 } … … 400 425 * 401 426 * @global wpdb $wpdb WordPress database abstraction object. 402 427 * 403 * @param string $user_name 428 * @param string $user_name The login name provided by the user. 404 429 * @param string $user_email The email provided by the user. 430 * 405 431 * @return array Contains username, email, and error messages. 406 432 */ 407 function wpmu_validate_user_signup( $user_name, $user_email) {433 function wpmu_validate_user_signup( $user_name, $user_email ) { 408 434 global $wpdb; 409 435 410 436 $errors = new WP_Error(); 411 437 412 438 $orig_username = $user_name; 413 $user_name = preg_replace( '/\s+/', '', sanitize_user( $user_name, true ) );439 $user_name = preg_replace( '/\s+/', '', sanitize_user( $user_name, true ) ); 414 440 415 441 if ( $user_name != $orig_username || preg_match( '/[^a-z0-9]/', $user_name ) ) { 416 442 $errors->add( 'user_name', __( 'Usernames can only contain lowercase letters (a-z) and numbers.' ) ); … … 419 445 420 446 $user_email = sanitize_email( $user_email ); 421 447 422 if ( empty( $user_name ) ) 423 $errors->add('user_name', __( 'Please enter a username.' ) ); 448 if ( empty( $user_name ) ) { 449 $errors->add( 'user_name', __( 'Please enter a username.' ) ); 450 } 424 451 425 452 $illegal_names = get_site_option( 'illegal_names' ); 426 453 if ( ! is_array( $illegal_names ) ) { 427 $illegal_names = array( 454 $illegal_names = array( 'www', 'web', 'root', 'admin', 'main', 'invite', 'administrator' ); 428 455 add_site_option( 'illegal_names', $illegal_names ); 429 456 } 430 457 if ( in_array( $user_name, $illegal_names ) ) { 431 $errors->add( 'user_name', 458 $errors->add( 'user_name', __( 'Sorry, that username is not allowed.' ) ); 432 459 } 433 460 434 461 /** This filter is documented in wp-includes/user.php */ … … 435 462 $illegal_logins = (array) apply_filters( 'illegal_user_logins', array() ); 436 463 437 464 if ( in_array( strtolower( $user_name ), array_map( 'strtolower', $illegal_logins ) ) ) { 438 $errors->add( 'user_name', 465 $errors->add( 'user_name', __( 'Sorry, that username is not allowed.' ) ); 439 466 } 440 467 441 if ( is_email_address_unsafe( $user_email ) ) 442 $errors->add('user_email', __('You cannot use that email address to signup. We are having problems with them blocking some of our email. Please use another email provider.')); 468 if ( is_email_address_unsafe( $user_email ) ) { 469 $errors->add( 'user_email', __( 'You cannot use that email address to signup. We are having problems with them blocking some of our email. Please use another email provider.' ) ); 470 } 443 471 444 if ( strlen( $user_name ) < 4 ) 445 $errors->add('user_name', __( 'Username must be at least 4 characters.' ) ); 472 if ( strlen( $user_name ) < 4 ) { 473 $errors->add( 'user_name', __( 'Username must be at least 4 characters.' ) ); 474 } 446 475 447 476 if ( strlen( $user_name ) > 60 ) { 448 477 $errors->add( 'user_name', __( 'Username may not be longer than 60 characters.' ) ); … … 449 478 } 450 479 451 480 // all numeric? 452 if ( preg_match( '/^[0-9]*$/', $user_name ) ) 453 $errors->add('user_name', __('Sorry, usernames must have letters too!')); 481 if ( preg_match( '/^[0-9]*$/', $user_name ) ) { 482 $errors->add( 'user_name', __( 'Sorry, usernames must have letters too!' ) ); 483 } 454 484 455 if ( !is_email( $user_email ) ) 456 $errors->add('user_email', __( 'Please enter a valid email address.' ) ); 485 if ( ! is_email( $user_email ) ) { 486 $errors->add( 'user_email', __( 'Please enter a valid email address.' ) ); 487 } 457 488 458 489 $limited_email_domains = get_site_option( 'limited_email_domains' ); 459 490 if ( is_array( $limited_email_domains ) && ! empty( $limited_email_domains ) ) { 460 491 $emaildomain = substr( $user_email, 1 + strpos( $user_email, '@' ) ); 461 492 if ( ! in_array( $emaildomain, $limited_email_domains ) ) { 462 $errors->add( 'user_email', __('Sorry, that email address is not allowed!'));493 $errors->add( 'user_email', __( 'Sorry, that email address is not allowed!' ) ); 463 494 } 464 495 } 465 496 466 497 // Check if the username has been used already. 467 if ( username_exists( $user_name) )498 if ( username_exists( $user_name ) ) { 468 499 $errors->add( 'user_name', __( 'Sorry, that username already exists!' ) ); 500 } 469 501 470 502 // Check if the email address has been used already. 471 if ( email_exists( $user_email) )503 if ( email_exists( $user_email ) ) { 472 504 $errors->add( 'user_email', __( 'Sorry, that email address is already used!' ) ); 505 } 473 506 474 507 // Has someone already signed up for this username? 475 $signup = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->signups WHERE user_login = %s", $user_name) );508 $signup = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->signups WHERE user_login = %s", $user_name ) ); 476 509 if ( $signup != null ) { 477 $registered_at = mysql2date('U', $signup->registered);478 $now = current_time( 'timestamp', true );479 $diff = $now - $registered_at;510 $registered_at = mysql2date( 'U', $signup->registered ); 511 $now = current_time( 'timestamp', true ); 512 $diff = $now - $registered_at; 480 513 // If registered more than two days ago, cancel registration and let this signup go through. 481 if ( $diff > 2 * DAY_IN_SECONDS ) 514 if ( $diff > 2 * DAY_IN_SECONDS ) { 482 515 $wpdb->delete( $wpdb->signups, array( 'user_login' => $user_name ) ); 483 else 484 $errors->add('user_name', __('That username is currently reserved but may be available in a couple of days.')); 516 } else { 517 $errors->add( 'user_name', __( 'That username is currently reserved but may be available in a couple of days.' ) ); 518 } 485 519 } 486 520 487 $signup = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->signups WHERE user_email = %s", $user_email) );521 $signup = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->signups WHERE user_email = %s", $user_email ) ); 488 522 if ( $signup != null ) { 489 $diff = current_time( 'timestamp', true ) - mysql2date( 'U', $signup->registered);523 $diff = current_time( 'timestamp', true ) - mysql2date( 'U', $signup->registered ); 490 524 // If registered more than two days ago, cancel registration and let this signup go through. 491 if ( $diff > 2 * DAY_IN_SECONDS ) 525 if ( $diff > 2 * DAY_IN_SECONDS ) { 492 526 $wpdb->delete( $wpdb->signups, array( 'user_email' => $user_email ) ); 493 else 494 $errors->add('user_email', __('That email address has already been used. Please check your inbox for an activation email. It will become available in a couple of days if you do nothing.')); 527 } else { 528 $errors->add( 'user_email', __( 'That email address has already been used. Please check your inbox for an activation email. It will become available in a couple of days if you do nothing.' ) ); 529 } 495 530 } 496 531 497 $result = array('user_name' => $user_name, 'orig_username' => $orig_username, 'user_email' => $user_email, 'errors' => $errors); 532 $result = array( 'user_name' => $user_name, 533 'orig_username' => $orig_username, 534 'user_email' => $user_email, 535 'errors' => $errors 536 ); 498 537 499 538 /** 500 539 * Filter the validated user registration details. … … 507 546 * @param array $result { 508 547 * The array of user name, email and the error messages. 509 548 * 510 * @type string $user_nameSanitized and unique username.511 * @type string$orig_username Original username.512 * @type string $user_emailUser email address.513 * @type WP_Error $errorsWP_Error object containing any errors found.549 * @type string $user_name Sanitized and unique username. 550 * @type string $orig_username Original username. 551 * @type string $user_email User email address. 552 * @type WP_Error $errors WP_Error object containing any errors found. 514 553 * } 515 554 */ 516 555 return apply_filters( 'wpmu_validate_user_signup', $result ); … … 532 571 * 533 572 * @since MU 534 573 * 535 * @global wpdb 574 * @global wpdb $wpdb 536 575 * @global string $domain 537 576 * 538 * @param string $blogname The blog name provided by the user. Must be unique. 539 * @param string $blog_title The blog title provided by the user. 540 * @param WP_User|string $user Optional. The user object to check against the new site name. 577 * @param string $blogname The blog name provided by the user. Must be unique. 578 * @param string $blog_title The blog title provided by the user. 579 * @param WP_User|string $user Optional. The user object to check against the new site name. 580 * 541 581 * @return array Contains the new site data and error messages. 542 582 */ 543 583 function wpmu_validate_blog_signup( $blogname, $blog_title, $user = '' ) { … … 544 584 global $wpdb, $domain; 545 585 546 586 $current_site = get_current_site(); 547 $base = $current_site->path;587 $base = $current_site->path; 548 588 549 589 $blog_title = strip_tags( $blog_title ); 550 590 551 $errors = new WP_Error();591 $errors = new WP_Error(); 552 592 $illegal_names = get_site_option( 'illegal_names' ); 553 593 if ( $illegal_names == false ) { 554 594 $illegal_names = array( 'www', 'web', 'root', 'admin', 'main', 'invite', 'administrator' ); … … 563 603 $illegal_names = array_merge( $illegal_names, get_subdirectory_reserved_names() ); 564 604 } 565 605 566 if ( empty( $blogname ) ) 567 $errors->add('blogname', __( 'Please enter a site name.' ) ); 606 if ( empty( $blogname ) ) { 607 $errors->add( 'blogname', __( 'Please enter a site name.' ) ); 608 } 568 609 569 610 if ( preg_match( '/[^a-z0-9]+/', $blogname ) ) { 570 611 $errors->add( 'blogname', __( 'Site names can only contain lowercase letters (a-z) and numbers.' ) ); 571 612 } 572 613 573 if ( in_array( $blogname, $illegal_names ) ) 574 $errors->add('blogname', __( 'That name is not allowed.' ) ); 614 if ( in_array( $blogname, $illegal_names ) ) { 615 $errors->add( 'blogname', __( 'That name is not allowed.' ) ); 616 } 575 617 576 if ( strlen( $blogname ) < 4 && !is_super_admin() ) 577 $errors->add('blogname', __( 'Site name must be at least 4 characters.' ) ); 618 if ( strlen( $blogname ) < 4 && ! is_super_admin() ) { 619 $errors->add( 'blogname', __( 'Site name must be at least 4 characters.' ) ); 620 } 578 621 579 622 // do not allow users to create a blog that conflicts with a page on the main blog. 580 if ( ! is_subdomain_install() && $wpdb->get_var( $wpdb->prepare( "SELECT post_name FROM " . $wpdb->get_blog_prefix( $current_site->blog_id ) . "posts WHERE post_type = 'page' AND post_name = %s", $blogname ) ) )623 if ( ! is_subdomain_install() && $wpdb->get_var( $wpdb->prepare( "SELECT post_name FROM " . $wpdb->get_blog_prefix( $current_site->blog_id ) . "posts WHERE post_type = 'page' AND post_name = %s", $blogname ) ) ) { 581 624 $errors->add( 'blogname', __( 'Sorry, you may not use that site name.' ) ); 625 } 582 626 583 627 // all numeric? 584 if ( preg_match( '/^[0-9]*$/', $blogname ) ) 585 $errors->add('blogname', __('Sorry, site names must have letters too!')); 628 if ( preg_match( '/^[0-9]*$/', $blogname ) ) { 629 $errors->add( 'blogname', __( 'Sorry, site names must have letters too!' ) ); 630 } 586 631 587 632 /** 588 633 * Filter the new site name during registration. … … 596 641 */ 597 642 $blogname = apply_filters( 'newblogname', $blogname ); 598 643 599 $blog_title = wp_unslash( 644 $blog_title = wp_unslash( $blog_title ); 600 645 601 if ( empty( $blog_title ) ) 602 $errors->add('blog_title', __( 'Please enter a site title.' ) ); 646 if ( empty( $blog_title ) ) { 647 $errors->add( 'blog_title', __( 'Please enter a site title.' ) ); 648 } 603 649 604 650 // Check if the domain/path has been used already. 605 651 if ( is_subdomain_install() ) { 606 652 $mydomain = $blogname . '.' . preg_replace( '|^www\.|', '', $domain ); 607 $path = $base;653 $path = $base; 608 654 } else { 609 655 $mydomain = "$domain"; 610 $path = $base.$blogname.'/';656 $path = $base . $blogname . '/'; 611 657 } 612 if ( domain_exists( $mydomain, $path, $current_site->id) )658 if ( domain_exists( $mydomain, $path, $current_site->id ) ) { 613 659 $errors->add( 'blogname', __( 'Sorry, that site already exists!' ) ); 660 } 614 661 615 662 if ( username_exists( $blogname ) ) { 616 if ( ! is_object( $user ) || ( is_object( $user) && ( $user->user_login != $blogname ) ) )663 if ( ! is_object( $user ) || ( is_object( $user ) && ( $user->user_login != $blogname ) ) ) { 617 664 $errors->add( 'blogname', __( 'Sorry, that site is reserved!' ) ); 665 } 618 666 } 619 667 620 668 // Has someone already signed up for this domain? 621 $signup = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->signups WHERE domain = %s AND path = %s", $mydomain, $path) ); // TODO: Check email too?622 if ( ! empty( $signup) ) {623 $diff = current_time( 'timestamp', true ) - mysql2date( 'U', $signup->registered);669 $signup = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->signups WHERE domain = %s AND path = %s", $mydomain, $path ) ); // TODO: Check email too? 670 if ( ! empty( $signup ) ) { 671 $diff = current_time( 'timestamp', true ) - mysql2date( 'U', $signup->registered ); 624 672 // If registered more than two days ago, cancel registration and let this signup go through. 625 if ( $diff > 2 * DAY_IN_SECONDS ) 626 $wpdb->delete( $wpdb->signups, array( 'domain' => $mydomain , 'path' => $path ) ); 627 else 628 $errors->add('blogname', __('That site is currently reserved but may be available in a couple days.')); 673 if ( $diff > 2 * DAY_IN_SECONDS ) { 674 $wpdb->delete( $wpdb->signups, array( 'domain' => $mydomain, 'path' => $path ) ); 675 } else { 676 $errors->add( 'blogname', __( 'That site is currently reserved but may be available in a couple days.' ) ); 677 } 629 678 } 630 679 631 $result = array('domain' => $mydomain, 'path' => $path, 'blogname' => $blogname, 'blog_title' => $blog_title, 'user' => $user, 'errors' => $errors); 680 $result = array( 'domain' => $mydomain, 681 'path' => $path, 682 'blogname' => $blogname, 683 'blog_title' => $blog_title, 684 'user' => $user, 685 'errors' => $errors 686 ); 632 687 633 688 /** 634 689 * Filter site details and error messages following registration. … … 638 693 * @param array $result { 639 694 * Array of domain, path, blog name, blog title, user and error messages. 640 695 * 641 * @type string $domainDomain for the site.642 * @type string $pathPath for the site. Used in subdirectory installs.643 * @type string $blognameThe unique site name (slug).644 * @type string$blog_title Blog title.645 * @type string|WP_User $userBy default, an empty string. A user object if provided.646 * @type WP_Error $errorsWP_Error containing any errors found.696 * @type string $domain Domain for the site. 697 * @type string $path Path for the site. Used in subdirectory installs. 698 * @type string $blogname The unique site name (slug). 699 * @type string $blog_title Blog title. 700 * @type string|WP_User $user By default, an empty string. A user object if provided. 701 * @type WP_Error $errors WP_Error containing any errors found. 647 702 * } 648 703 */ 649 704 return apply_filters( 'wpmu_validate_blog_signup', $result ); … … 656 711 * 657 712 * @global wpdb $wpdb WordPress database abstraction object. 658 713 * 659 * @param string $domain 660 * @param string $path 661 * @param string $title 662 * @param string $user 714 * @param string $domain The requested domain. 715 * @param string $path The requested path. 716 * @param string $title The requested site title. 717 * @param string $user The user's requested login name. 663 718 * @param string $user_email The user's email address. 664 * @param array $metaBy default, contains the requested privacy setting and lang_id.719 * @param array $meta By default, contains the requested privacy setting and lang_id. 665 720 */ 666 function wpmu_signup_blog( $domain, $path, $title, $user, $user_email, $meta = array() ) 721 function wpmu_signup_blog( $domain, $path, $title, $user, $user_email, $meta = array() ) { 667 722 global $wpdb; 668 723 669 $key = substr( md5( time() . rand() . $domain ), 0, 16 );670 $meta = serialize( $meta);724 $key = substr( md5( time() . rand() . $domain ), 0, 16 ); 725 $meta = serialize( $meta ); 671 726 672 727 $wpdb->insert( $wpdb->signups, array( 673 'domain' => $domain,674 'path' => $path,675 'title' => $title,676 'user_login' => $user,677 'user_email' => $user_email,678 'registered' => current_time('mysql', true),728 'domain' => $domain, 729 'path' => $path, 730 'title' => $title, 731 'user_login' => $user, 732 'user_email' => $user_email, 733 'registered' => current_time( 'mysql', true ), 679 734 'activation_key' => $key, 680 'meta' => $meta735 'meta' => $meta 681 736 ) ); 682 737 683 738 /** … … 685 740 * 686 741 * @since 4.4.0 687 742 * 688 * @param string $domain 689 * @param string $path 690 * @param string $title 691 * @param string $user 743 * @param string $domain The requested domain. 744 * @param string $path The requested path. 745 * @param string $title The requested site title. 746 * @param string $user The user's requested login name. 692 747 * @param string $user_email The user's email address. 693 * @param string $key 694 * @param array $metaBy default, contains the requested privacy setting and lang_id.748 * @param string $key The user's activation key 749 * @param array $meta By default, contains the requested privacy setting and lang_id. 695 750 */ 696 751 do_action( 'after_signup_site', $domain, $path, $title, $user, $user_email, $key, $meta ); 697 752 } … … 706 761 * 707 762 * @global wpdb $wpdb WordPress database abstraction object. 708 763 * 709 * @param string $user 764 * @param string $user The user's requested login name. 710 765 * @param string $user_email The user's email address. 711 * @param array $metaBy default, this is an empty array.766 * @param array $meta By default, this is an empty array. 712 767 */ 713 768 function wpmu_signup_user( $user, $user_email, $meta = array() ) { 714 769 global $wpdb; 715 770 716 771 // Format data 717 $user = preg_replace( '/\s+/', '', sanitize_user( $user, true ) );772 $user = preg_replace( '/\s+/', '', sanitize_user( $user, true ) ); 718 773 $user_email = sanitize_email( $user_email ); 719 $key = substr( md5( time() . rand() . $user_email ), 0, 16 );720 $meta = serialize($meta);774 $key = substr( md5( time() . rand() . $user_email ), 0, 16 ); 775 $meta = serialize( $meta ); 721 776 722 777 $wpdb->insert( $wpdb->signups, array( 723 'domain' => '',724 'path' => '',725 'title' => '',726 'user_login' => $user,727 'user_email' => $user_email,728 'registered' => current_time('mysql', true),778 'domain' => '', 779 'path' => '', 780 'title' => '', 781 'user_login' => $user, 782 'user_email' => $user_email, 783 'registered' => current_time( 'mysql', true ), 729 784 'activation_key' => $key, 730 'meta' => $meta785 'meta' => $meta 731 786 ) ); 732 787 733 788 /** … … 735 790 * 736 791 * @since 4.4.0 737 792 * 738 * @param string $user 793 * @param string $user The user's requested login name. 739 794 * @param string $user_email The user's email address. 740 * @param string $key 741 * @param array $metaAdditional signup meta. By default, this is an empty array.795 * @param string $key The user's activation key 796 * @param array $meta Additional signup meta. By default, this is an empty array. 742 797 */ 743 798 do_action( 'after_signup_user', $user, $user_email, $key, $meta ); 744 799 } … … 758 813 * 759 814 * @since MU 760 815 * 761 * @param string $domain 762 * @param string $path 763 * @param string $title 764 * @param string $user 816 * @param string $domain The new blog domain. 817 * @param string $path The new blog path. 818 * @param string $title The site title. 819 * @param string $user The user's login name. 765 820 * @param string $user_email The user's email address. 766 * @param string $key The activation key created in wpmu_signup_blog() 767 * @param array $meta By default, contains the requested privacy setting and lang_id. 821 * @param string $key The activation key created in wpmu_signup_blog() 822 * @param array $meta By default, contains the requested privacy setting and lang_id. 823 * 768 824 * @return bool 769 825 */ 770 826 function wpmu_signup_blog_notification( $domain, $path, $title, $user, $user_email, $key, $meta = array() ) { … … 773 829 * 774 830 * @since MU 775 831 * 776 * @param string|bool $domain 777 * @param string $pathSite path.778 * @param string $titleSite title.779 * @param string $userUser login name.780 * @param string 781 * @param string $keyActivation key created in wpmu_signup_blog().782 * @param array $metaBy default, contains the requested privacy setting and lang_id.832 * @param string|bool $domain Site domain. 833 * @param string $path Site path. 834 * @param string $title Site title. 835 * @param string $user User login name. 836 * @param string $user_email User email address. 837 * @param string $key Activation key created in wpmu_signup_blog(). 838 * @param array $meta By default, contains the requested privacy setting and lang_id. 783 839 */ 784 840 if ( ! apply_filters( 'wpmu_signup_blog_notification', $domain, $path, $title, $user, $user_email, $key, $meta ) ) { 785 841 return false; … … 786 842 } 787 843 788 844 // Send email with activation link. 789 if ( !is_subdomain_install() || get_current_site()->id != 1 ) 790 $activate_url = network_site_url("wp-activate.php?key=$key"); 791 else 792 $activate_url = "http://{$domain}{$path}wp-activate.php?key=$key"; // @todo use *_url() API 845 if ( ! is_subdomain_install() || get_current_site()->id != 1 ) { 846 $activate_url = network_site_url( "wp-activate.php?key=$key" ); 847 } else { 848 $activate_url = "http://{$domain}{$path}wp-activate.php?key=$key"; 849 } // @todo use *_url() API 793 850 794 $activate_url = esc_url( $activate_url);795 $admin_email = get_site_option( 'admin_email' );796 if ( $admin_email == '' ) 851 $activate_url = esc_url( $activate_url ); 852 $admin_email = get_site_option( 'admin_email' ); 853 if ( $admin_email == '' ) { 797 854 $admin_email = 'support@' . $_SERVER['SERVER_NAME']; 798 $from_name = get_site_option( 'site_name' ) == '' ? 'WordPress' : esc_html( get_site_option( 'site_name' ) ); 799 $message_headers = "From: \"{$from_name}\" <{$admin_email}>\n" . "Content-Type: text/plain; charset=\"" . get_option('blog_charset') . "\"\n"; 800 $message = sprintf( 801 /** 802 * Filter the message content of the new blog notification email. 803 * 804 * Content should be formatted for transmission via wp_mail(). 805 * 806 * @since MU 807 * 808 * @param string $content Content of the notification email. 809 * @param string $domain Site domain. 810 * @param string $path Site path. 811 * @param string $title Site title. 812 * @param string $user User login name. 813 * @param string $user_email User email address. 814 * @param string $key Activation key created in wpmu_signup_blog(). 815 * @param array $meta By default, contains the requested privacy setting and lang_id. 816 */ 855 } 856 $from_name = get_site_option( 'site_name' ) == '' ? 'WordPress' : esc_html( get_site_option( 'site_name' ) ); 857 $message_headers = "From: \"{$from_name}\" <{$admin_email}>\n" . "Content-Type: text/plain; charset=\"" . get_option( 'blog_charset' ) . "\"\n"; 858 $message = sprintf( 859 /** 860 * Filter the message content of the new blog notification email. 861 * 862 * Content should be formatted for transmission via wp_mail(). 863 * 864 * @since MU 865 * 866 * @param string $content Content of the notification email. 867 * @param string $domain Site domain. 868 * @param string $path Site path. 869 * @param string $title Site title. 870 * @param string $user User login name. 871 * @param string $user_email User email address. 872 * @param string $key Activation key created in wpmu_signup_blog(). 873 * @param array $meta By default, contains the requested privacy setting and lang_id. 874 */ 817 875 apply_filters( 'wpmu_signup_blog_notification_email', 818 876 __( "To activate your blog, please click the following link:\n\n%s\n\nAfter you activate, you will receive *another email* with your login.\n\nAfter you activate, you can visit your site here:\n\n%s" ), 819 877 $domain, $path, $title, $user, $user_email, $key, $meta … … 824 882 ); 825 883 // TODO: Don't hard code activation link. 826 884 $subject = sprintf( 827 828 829 830 831 832 * @param string $subjectSubject of the notification email.833 * @param string $domainSite domain.834 * @param string $pathSite path.835 * @param string $titleSite title.836 * @param string $userUser login name.837 838 * @param string $keyActivation key created in wpmu_signup_blog().839 * @param array $metaBy default, contains the requested privacy setting and lang_id.840 885 /** 886 * Filter the subject of the new blog notification email. 887 * 888 * @since MU 889 * 890 * @param string $subject Subject of the notification email. 891 * @param string $domain Site domain. 892 * @param string $path Site path. 893 * @param string $title Site title. 894 * @param string $user User login name. 895 * @param string $user_email User email address. 896 * @param string $key Activation key created in wpmu_signup_blog(). 897 * @param array $meta By default, contains the requested privacy setting and lang_id. 898 */ 841 899 apply_filters( 'wpmu_signup_blog_notification_subject', 842 900 __( '[%1$s] Activate %2$s' ), 843 901 $domain, $path, $title, $user, $user_email, $key, $meta … … 846 904 esc_url( 'http://' . $domain . $path ) 847 905 ); 848 906 wp_mail( $user_email, wp_specialchars_decode( $subject ), $message, $message_headers ); 907 849 908 return true; 850 909 } 851 910 … … 864 923 * 865 924 * @since MU 866 925 * 867 * @param string $user 926 * @param string $user The user's login name. 868 927 * @param string $user_email The user's email address. 869 * @param string $key The activation key created in wpmu_signup_user() 870 * @param array $meta By default, an empty array. 928 * @param string $key The activation key created in wpmu_signup_user() 929 * @param array $meta By default, an empty array. 930 * 871 931 * @return bool 872 932 */ 873 933 function wpmu_signup_user_notification( $user, $user_email, $key, $meta = array() ) { … … 876 936 * 877 937 * @since MU 878 938 * 879 * @param string $user 939 * @param string $user User login name. 880 940 * @param string $user_email User email address. 881 * @param string $key 882 * @param array $metaSignup meta data.941 * @param string $key Activation key created in wpmu_signup_user(). 942 * @param array $meta Signup meta data. 883 943 */ 884 if ( ! apply_filters( 'wpmu_signup_user_notification', $user, $user_email, $key, $meta ) ) 944 if ( ! apply_filters( 'wpmu_signup_user_notification', $user, $user_email, $key, $meta ) ) { 885 945 return false; 946 } 886 947 887 948 // Send email with activation link. 888 949 $admin_email = get_site_option( 'admin_email' ); 889 if ( $admin_email == '' ) 950 if ( $admin_email == '' ) { 890 951 $admin_email = 'support@' . $_SERVER['SERVER_NAME']; 891 $from_name = get_site_option( 'site_name' ) == '' ? 'WordPress' : esc_html( get_site_option( 'site_name' ) ); 892 $message_headers = "From: \"{$from_name}\" <{$admin_email}>\n" . "Content-Type: text/plain; charset=\"" . get_option('blog_charset') . "\"\n"; 893 $message = sprintf( 894 /** 895 * Filter the content of the notification email for new user sign-up. 896 * 897 * Content should be formatted for transmission via wp_mail(). 898 * 899 * @since MU 900 * 901 * @param string $content Content of the notification email. 902 * @param string $user User login name. 903 * @param string $user_email User email address. 904 * @param string $key Activation key created in wpmu_signup_user(). 905 * @param array $meta Signup meta data. 906 */ 952 } 953 $from_name = get_site_option( 'site_name' ) == '' ? 'WordPress' : esc_html( get_site_option( 'site_name' ) ); 954 $message_headers = "From: \"{$from_name}\" <{$admin_email}>\n" . "Content-Type: text/plain; charset=\"" . get_option( 'blog_charset' ) . "\"\n"; 955 $message = sprintf( 956 /** 957 * Filter the content of the notification email for new user sign-up. 958 * 959 * Content should be formatted for transmission via wp_mail(). 960 * 961 * @since MU 962 * 963 * @param string $content Content of the notification email. 964 * @param string $user User login name. 965 * @param string $user_email User email address. 966 * @param string $key Activation key created in wpmu_signup_user(). 967 * @param array $meta Signup meta data. 968 */ 907 969 apply_filters( 'wpmu_signup_user_notification_email', 908 970 __( "To activate your user, please click the following link:\n\n%s\n\nAfter you activate, you will receive *another email* with your login." ), 909 971 $user, $user_email, $key, $meta … … 912 974 ); 913 975 // TODO: Don't hard code activation link. 914 976 $subject = sprintf( 915 916 917 918 919 920 * @param string $subjectSubject of the notification email.921 * @param string $userUser login name.922 923 * @param string $keyActivation key created in wpmu_signup_user().924 * @param array $metaSignup meta data.925 977 /** 978 * Filter the subject of the notification email of new user signup. 979 * 980 * @since MU 981 * 982 * @param string $subject Subject of the notification email. 983 * @param string $user User login name. 984 * @param string $user_email User email address. 985 * @param string $key Activation key created in wpmu_signup_user(). 986 * @param array $meta Signup meta data. 987 */ 926 988 apply_filters( 'wpmu_signup_user_notification_subject', 927 989 __( '[%1$s] Activate %2$s' ), 928 990 $user, $user_email, $key, $meta … … 931 993 $user 932 994 ); 933 995 wp_mail( $user_email, wp_specialchars_decode( $subject ), $message, $message_headers ); 996 934 997 return true; 935 998 } 936 999 … … 947 1010 * @global wpdb $wpdb WordPress database abstraction object. 948 1011 * 949 1012 * @param string $key The activation key provided to the user. 1013 * 950 1014 * @return array|WP_Error An array containing information about the activated user and/or blog 951 1015 */ 952 function wpmu_activate_signup( $key) {1016 function wpmu_activate_signup( $key ) { 953 1017 global $wpdb; 954 1018 955 $signup = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->signups WHERE activation_key = %s", $key) );1019 $signup = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->signups WHERE activation_key = %s", $key ) ); 956 1020 957 if ( empty( $signup ) ) 1021 if ( empty( $signup ) ) { 958 1022 return new WP_Error( 'invalid_key', __( 'Invalid activation key.' ) ); 1023 } 959 1024 960 1025 if ( $signup->active ) { 961 if ( empty( $signup->domain ) ) 1026 if ( empty( $signup->domain ) ) { 962 1027 return new WP_Error( 'already_active', __( 'The user is already active.' ), $signup ); 963 else1028 } else { 964 1029 return new WP_Error( 'already_active', __( 'The site is already active.' ), $signup ); 1030 } 965 1031 } 966 1032 967 $meta = maybe_unserialize($signup->meta);1033 $meta = maybe_unserialize( $signup->meta ); 968 1034 $password = wp_generate_password( 12, false ); 969 1035 970 $user_id = username_exists( $signup->user_login);1036 $user_id = username_exists( $signup->user_login ); 971 1037 972 if ( ! $user_id ) 973 $user_id = wpmu_create_user( $signup->user_login, $password, $signup->user_email);974 else1038 if ( ! $user_id ) { 1039 $user_id = wpmu_create_user( $signup->user_login, $password, $signup->user_email ); 1040 } else { 975 1041 $user_already_exists = true; 1042 } 976 1043 977 if ( ! $user_id ) 978 return new WP_Error('create_user', __('Could not create user'), $signup); 1044 if ( ! $user_id ) { 1045 return new WP_Error( 'create_user', __( 'Could not create user' ), $signup ); 1046 } 979 1047 980 $now = current_time( 'mysql', true);1048 $now = current_time( 'mysql', true ); 981 1049 982 if ( empty( $signup->domain) ) {983 $wpdb->update( $wpdb->signups, array( 'active' => 1, 'activated' => $now), array('activation_key' => $key) );1050 if ( empty( $signup->domain ) ) { 1051 $wpdb->update( $wpdb->signups, array( 'active' => 1, 'activated' => $now ), array( 'activation_key' => $key ) ); 984 1052 985 if ( isset( $user_already_exists ) ) 986 return new WP_Error( 'user_already_exists', __( 'That username is already activated.' ), $signup); 1053 if ( isset( $user_already_exists ) ) { 1054 return new WP_Error( 'user_already_exists', __( 'That username is already activated.' ), $signup ); 1055 } 987 1056 988 1057 /** 989 1058 * Fires immediately after a new user is activated. … … 990 1059 * 991 1060 * @since MU 992 1061 * 993 * @param int $user_idUser ID.994 * @param int 995 * @param array $meta 1062 * @param int $user_id User ID. 1063 * @param int $password User password. 1064 * @param array $meta Signup meta data. 996 1065 */ 997 1066 do_action( 'wpmu_activate_user', $user_id, $password, $meta ); 1067 998 1068 return array( 'user_id' => $user_id, 'password' => $password, 'meta' => $meta ); 999 1069 } 1000 1070 … … 1001 1071 $blog_id = wpmu_create_blog( $signup->domain, $signup->path, $signup->title, $user_id, $meta, $wpdb->siteid ); 1002 1072 1003 1073 // TODO: What to do if we create a user but cannot create a blog? 1004 if ( is_wp_error( $blog_id) ) {1074 if ( is_wp_error( $blog_id ) ) { 1005 1075 // If blog is taken, that means a previous attempt to activate this blog failed in between creating the blog and 1006 1076 // setting the activation flag. Let's just set the active flag and instruct the user to reset their password. 1007 1077 if ( 'blog_taken' == $blog_id->get_error_code() ) { 1008 1078 $blog_id->add_data( $signup ); 1009 $wpdb->update( $wpdb->signups, array( 'active' => 1, 'activated' => $now ), array( 'activation_key' => $key ) ); 1079 $wpdb->update( $wpdb->signups, array( 'active' => 1, 1080 'activated' => $now 1081 ), array( 'activation_key' => $key ) ); 1010 1082 } 1083 1011 1084 return $blog_id; 1012 1085 } 1013 1086 1014 $wpdb->update( $wpdb->signups, array( 'active' => 1, 'activated' => $now), array('activation_key' => $key) );1087 $wpdb->update( $wpdb->signups, array( 'active' => 1, 'activated' => $now ), array( 'activation_key' => $key ) ); 1015 1088 /** 1016 1089 * Fires immediately after a site is activated. 1017 1090 * 1018 1091 * @since MU 1019 1092 * 1020 * @param int $blog_idBlog ID.1021 * @param int $user_idUser ID.1022 * @param int $passwordUser password.1023 * @param string $signup_title 1024 * @param array $metaSignup meta data.1093 * @param int $blog_id Blog ID. 1094 * @param int $user_id User ID. 1095 * @param int $password User password. 1096 * @param string $signup_title Site title. 1097 * @param array $meta Signup meta data. 1025 1098 */ 1026 1099 do_action( 'wpmu_activate_blog', $blog_id, $user_id, $password, $signup->title, $meta ); 1027 1100 1028 return array('blog_id' => $blog_id, 'user_id' => $user_id, 'password' => $password, 'title' => $signup->title, 'meta' => $meta); 1101 return array( 'blog_id' => $blog_id, 1102 'user_id' => $user_id, 1103 'password' => $password, 1104 'title' => $signup->title, 1105 'meta' => $meta 1106 ); 1029 1107 } 1030 1108 1031 1109 /** … … 1039 1117 * @since MU 1040 1118 * 1041 1119 * @param string $user_name The new user's login name. 1042 * @param string $password The new user's password. 1043 * @param string $email The new user's email address. 1120 * @param string $password The new user's password. 1121 * @param string $email The new user's email address. 1122 * 1044 1123 * @return int|false Returns false on failure, or int $user_id on success 1045 1124 */ 1046 1125 function wpmu_create_user( $user_name, $password, $email ) { … … 1047 1126 $user_name = preg_replace( '/\s+/', '', sanitize_user( $user_name, true ) ); 1048 1127 1049 1128 $user_id = wp_create_user( $user_name, $password, $email ); 1050 if ( is_wp_error( $user_id ) ) 1129 if ( is_wp_error( $user_id ) ) { 1051 1130 return false; 1131 } 1052 1132 1053 1133 // Newly created users have no roles or caps until they are added to a blog. 1054 1134 delete_user_option( $user_id, 'capabilities' ); … … 1080 1160 * 1081 1161 * @since MU 1082 1162 * 1083 * @param string $domain The new site's domain. 1084 * @param string $path The new site's path. 1085 * @param string $title The new site's title. 1086 * @param int $user_id The user ID of the new site's admin. 1087 * @param array $meta Optional. Used to set initial site options. 1088 * @param int $site_id Optional. Only relevant on multi-network installs. 1163 * @param string $domain The new site's domain. 1164 * @param string $path The new site's path. 1165 * @param string $title The new site's title. 1166 * @param int $user_id The user ID of the new site's admin. 1167 * @param array $meta Optional. Used to set initial site options. 1168 * @param int $site_id Optional. Only relevant on multi-network installs. 1169 * 1089 1170 * @return int|WP_Error Returns WP_Error object on failure, int $blog_id on success 1090 1171 */ 1091 1172 function wpmu_create_blog( $domain, $path, $title, $user_id, $meta = array(), $site_id = 1 ) { 1092 1173 $defaults = array( 'public' => 0 ); 1093 $meta = wp_parse_args( $meta, $defaults );1174 $meta = wp_parse_args( $meta, $defaults ); 1094 1175 1095 1176 $domain = preg_replace( '/\s+/', '', sanitize_user( $domain, true ) ); 1096 1177 1097 if ( is_subdomain_install() ) 1178 if ( is_subdomain_install() ) { 1098 1179 $domain = str_replace( '@', '', $domain ); 1180 } 1099 1181 1100 $title = strip_tags( $title );1182 $title = strip_tags( $title ); 1101 1183 $user_id = (int) $user_id; 1102 1184 1103 if ( empty( $path) )1185 if ( empty( $path ) ) { 1104 1186 $path = '/'; 1187 } 1105 1188 1106 1189 // Check if the domain has been used already. We should return an error message. 1107 if ( domain_exists( $domain, $path, $site_id) )1190 if ( domain_exists( $domain, $path, $site_id ) ) { 1108 1191 return new WP_Error( 'blog_taken', __( 'Sorry, that site already exists!' ) ); 1192 } 1109 1193 1110 1194 if ( ! wp_installing() ) { 1111 1195 wp_installing( true ); 1112 1196 } 1113 1197 1114 if ( ! $blog_id = insert_blog($domain, $path, $site_id) ) 1115 return new WP_Error('insert_blog', __('Could not create site.')); 1198 if ( ! $blog_id = insert_blog( $domain, $path, $site_id ) ) { 1199 return new WP_Error( 'insert_blog', __( 'Could not create site.' ) ); 1200 } 1116 1201 1117 switch_to_blog( $blog_id);1118 install_blog( $blog_id, $title);1119 wp_install_defaults( $user_id);1202 switch_to_blog( $blog_id ); 1203 install_blog( $blog_id, $title ); 1204 wp_install_defaults( $user_id ); 1120 1205 1121 add_user_to_blog( $blog_id, $user_id, 'administrator');1206 add_user_to_blog( $blog_id, $user_id, 'administrator' ); 1122 1207 1123 1208 foreach ( $meta as $key => $value ) { 1124 if ( in_array( $key, array( 'public', 'archived', 'mature', 'spam', 'deleted', 'lang_id' ) ) ) 1209 if ( in_array( $key, array( 'public', 'archived', 'mature', 'spam', 'deleted', 'lang_id' ) ) ) { 1125 1210 update_blog_status( $blog_id, $key, $value ); 1126 else1211 } else { 1127 1212 update_option( $key, $value ); 1213 } 1128 1214 } 1129 1215 1130 1216 add_option( 'WPLANG', get_site_option( 'WPLANG' ) ); 1131 1217 update_option( 'blog_public', (int) $meta['public'] ); 1132 1218 1133 if ( ! is_super_admin( $user_id ) && ! get_user_meta( $user_id, 'primary_blog', true ) ) 1219 if ( ! is_super_admin( $user_id ) && ! get_user_meta( $user_id, 'primary_blog', true ) ) { 1134 1220 update_user_meta( $user_id, 'primary_blog', $blog_id ); 1221 } 1135 1222 1136 1223 restore_current_blog(); 1137 1224 /** … … 1139 1226 * 1140 1227 * @since MU 1141 1228 * 1142 * @param int 1143 * @param int 1144 * @param string $domain 1145 * @param string $path 1146 * @param int 1147 * @param array $metaMeta data. Used to set initial site options.1229 * @param int $blog_id Blog ID. 1230 * @param int $user_id User ID. 1231 * @param string $domain Site domain. 1232 * @param string $path Site path. 1233 * @param int $site_id Site ID. Only relevant on multi-network installs. 1234 * @param array $meta Meta data. Used to set initial site options. 1148 1235 */ 1149 1236 do_action( 'wpmu_new_blog', $blog_id, $user_id, $domain, $path, $site_id, $meta ); 1150 1237 … … 1159 1246 * 1160 1247 * @since MU 1161 1248 * 1162 * @param int $blog_idThe new site's ID.1249 * @param int $blog_id The new site's ID. 1163 1250 * @param string $deprecated Not used. 1251 * 1164 1252 * @return bool 1165 1253 */ 1166 1254 function newblog_notify_siteadmin( $blog_id, $deprecated = '' ) { 1167 if ( get_site_option( 'registrationnotification' ) != 'yes' ) 1255 if ( get_site_option( 'registrationnotification' ) != 'yes' ) { 1168 1256 return false; 1257 } 1169 1258 1170 1259 $email = get_site_option( 'admin_email' ); 1171 if ( is_email( $email) == false )1260 if ( is_email( $email ) == false ) { 1172 1261 return false; 1262 } 1173 1263 1174 $options_site_url = esc_url( network_admin_url('settings.php'));1264 $options_site_url = esc_url( network_admin_url( 'settings.php' ) ); 1175 1265 1176 1266 switch_to_blog( $blog_id ); 1177 1267 $blogname = get_option( 'blogname' ); 1178 $siteurl = site_url();1268 $siteurl = site_url(); 1179 1269 restore_current_blog(); 1180 1270 1181 1271 $msg = sprintf( __( 'New Site: %1$s … … 1182 1272 URL: %2$s 1183 1273 Remote IP: %3$s 1184 1274 1185 Disable these notifications: %4$s' ), $blogname, $siteurl, wp_unslash( $_SERVER['REMOTE_ADDR'] ), $options_site_url );1275 Disable these notifications: %4$s' ), $blogname, $siteurl, wp_unslash( $_SERVER['REMOTE_ADDR'] ), $options_site_url ); 1186 1276 /** 1187 1277 * Filter the message body of the new site activation email sent 1188 1278 * to the network administrator. … … 1194 1284 $msg = apply_filters( 'newblog_notify_siteadmin', $msg ); 1195 1285 1196 1286 wp_mail( $email, sprintf( __( 'New Site Registration: %s' ), $siteurl ), $msg ); 1287 1197 1288 return true; 1198 1289 } 1199 1290 … … 1206 1297 * @since MU 1207 1298 * 1208 1299 * @param int $user_id The new user's ID. 1300 * 1209 1301 * @return bool 1210 1302 */ 1211 1303 function newuser_notify_siteadmin( $user_id ) { 1212 if ( get_site_option( 'registrationnotification' ) != 'yes' ) 1304 if ( get_site_option( 'registrationnotification' ) != 'yes' ) { 1213 1305 return false; 1306 } 1214 1307 1215 1308 $email = get_site_option( 'admin_email' ); 1216 1309 1217 if ( is_email( $email) == false )1310 if ( is_email( $email ) == false ) { 1218 1311 return false; 1312 } 1219 1313 1220 1314 $user = get_userdata( $user_id ); 1221 1315 1222 $options_site_url = esc_url( network_admin_url('settings.php'));1223 $msg = sprintf(__('New User: %1$s1316 $options_site_url = esc_url( network_admin_url( 'settings.php' ) ); 1317 $msg = sprintf( __( 'New User: %1$s 1224 1318 Remote IP: %2$s 1225 1319 1226 Disable these notifications: %3$s' ), $user->user_login, wp_unslash( $_SERVER['REMOTE_ADDR'] ), $options_site_url);1320 Disable these notifications: %3$s' ), $user->user_login, wp_unslash( $_SERVER['REMOTE_ADDR'] ), $options_site_url ); 1227 1321 1228 1322 /** 1229 1323 * Filter the message body of the new user activation email sent … … 1231 1325 * 1232 1326 * @since MU 1233 1327 * 1234 * @param string $msgEmail body.1328 * @param string $msg Email body. 1235 1329 * @param WP_User $user WP_User instance of the new user. 1236 1330 */ 1237 1331 $msg = apply_filters( 'newuser_notify_siteadmin', $msg, $user ); 1238 wp_mail( $email, sprintf(__('New User Registration: %s'), $user->user_login), $msg ); 1332 wp_mail( $email, sprintf( __( 'New User Registration: %s' ), $user->user_login ), $msg ); 1333 1239 1334 return true; 1240 1335 } 1241 1336 … … 1249 1344 * 1250 1345 * @global wpdb $wpdb WordPress database abstraction object. 1251 1346 * 1252 * @param string $domain The domain to be checked. 1253 * @param string $path The path to be checked. 1254 * @param int $site_id Optional. Relevant only on multi-network installs. 1347 * @param string $domain The domain to be checked. 1348 * @param string $path The path to be checked. 1349 * @param int $site_id Optional. Relevant only on multi-network installs. 1350 * 1255 1351 * @return int 1256 1352 */ 1257 function domain_exists($domain, $path, $site_id = 1) { 1258 global $wpdb; 1353 function domain_exists( $domain, $path, $site_id = 1 ) { 1259 1354 $path = trailingslashit( $path ); 1260 $result = $wpdb->get_var( $wpdb->prepare("SELECT blog_id FROM $wpdb->blogs WHERE domain = %s AND path = %s AND site_id = %d", $domain, $path, $site_id) );1261 1355 1356 $query = new WP_Site_Query(); 1357 $args = array( 'path' => $path, 'domain' => $domain, 'network' => $site_id, 'number' => 1, 'fields' => 'ids' ); 1358 $result = $query->query( $args ); 1359 $site = array_shift( $result ); 1360 1262 1361 /** 1263 1362 * Filter whether a blogname is taken. 1264 1363 * 1265 1364 * @since 3.5.0 1266 1365 * 1267 * @param int|null $ resultThe blog_id if the blogname exists, null otherwise.1268 * @param string $domainDomain to be checked.1269 * @param string $pathPath to be checked.1270 * @param int 1366 * @param int|null $site The blog_id if the blogname exists, null otherwise. 1367 * @param string $domain Domain to be checked. 1368 * @param string $path Path to be checked. 1369 * @param int $site_id Site ID. Relevant only on multi-network installs. 1271 1370 */ 1272 return apply_filters( 'domain_exists', $ result, $domain, $path, $site_id );1371 return apply_filters( 'domain_exists', $site, $domain, $path, $site_id ); 1273 1372 } 1274 1373 1275 1374 /** … … 1282 1381 * 1283 1382 * @global wpdb $wpdb WordPress database abstraction object. 1284 1383 * 1285 * @param string $domain The domain of the new site. 1286 * @param string $path The path of the new site. 1287 * @param int $site_id Unless you're running a multi-network install, be sure to set this value to 1. 1384 * @param string $domain The domain of the new site. 1385 * @param string $path The path of the new site. 1386 * @param int $site_id Unless you're running a multi-network install, be sure to set this value to 1. 1387 * 1288 1388 * @return int|false The ID of the new row 1289 1389 */ 1290 function insert_blog( $domain, $path, $site_id) {1390 function insert_blog( $domain, $path, $site_id ) { 1291 1391 global $wpdb; 1292 1392 1293 $path = trailingslashit($path);1393 $path = trailingslashit( $path ); 1294 1394 $site_id = (int) $site_id; 1295 1395 1296 $result = $wpdb->insert( $wpdb->blogs, array('site_id' => $site_id, 'domain' => $domain, 'path' => $path, 'registered' => current_time('mysql')) ); 1297 if ( ! $result ) 1396 $result = $wpdb->insert( $wpdb->blogs, array( 'site_id' => $site_id, 1397 'domain' => $domain, 1398 'path' => $path, 1399 'registered' => current_time( 'mysql' ) 1400 ) ); 1401 if ( ! $result ) { 1298 1402 return false; 1403 } 1299 1404 1300 1405 $blog_id = $wpdb->insert_id; 1301 1406 refresh_blog_details( $blog_id ); … … 1314 1419 * 1315 1420 * @since MU 1316 1421 * 1317 * @global wpdb 1422 * @global wpdb $wpdb 1318 1423 * @global WP_Roles $wp_roles 1319 1424 * 1320 * @param int $blog_idThe value returned by insert_blog().1425 * @param int $blog_id The value returned by insert_blog(). 1321 1426 * @param string $blog_title The title of the new site. 1322 1427 */ 1323 1428 function install_blog( $blog_id, $blog_title = '' ) { … … 1329 1434 require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); 1330 1435 1331 1436 $suppress = $wpdb->suppress_errors(); 1332 if ( $wpdb->get_results( "DESCRIBE {$wpdb->posts}" ) ) 1437 if ( $wpdb->get_results( "DESCRIBE {$wpdb->posts}" ) ) { 1333 1438 die( '<h1>' . __( 'Already Installed' ) . '</h1><p>' . __( 'You appear to have already installed WordPress. To reinstall please clear your old database tables first.' ) . '</p></body></html>' ); 1439 } 1334 1440 $wpdb->suppress_errors( $suppress ); 1335 1441 1336 1442 $url = get_blogaddress_by_id( $blog_id ); … … 1347 1453 1348 1454 if ( ! is_subdomain_install() ) { 1349 1455 1350 1351 1352 1353 1354 1355 1456 if ( 'https' === parse_url( get_site_option( 'siteurl' ), PHP_URL_SCHEME ) ) { 1457 $siteurl = set_url_scheme( $siteurl, 'https' ); 1458 } 1459 if ( 'https' === parse_url( get_home_url( $current_site->blog_id ), PHP_URL_SCHEME ) ) { 1460 $home = set_url_scheme( $home, 'https' ); 1461 } 1356 1462 1357 1463 } 1358 1464 … … 1359 1465 update_option( 'siteurl', $siteurl ); 1360 1466 update_option( 'home', $home ); 1361 1467 1362 if ( get_site_option( 'ms_files_rewriting' ) ) 1468 if ( get_site_option( 'ms_files_rewriting' ) ) { 1363 1469 update_option( 'upload_path', UPLOADBLOGSDIR . "/$blog_id/files" ); 1364 else1470 } else { 1365 1471 update_option( 'upload_path', get_blog_option( get_current_site()->blog_id, 'upload_path' ) ); 1472 } 1366 1473 1367 1474 update_option( 'blogname', wp_unslash( $blog_title ) ); 1368 1475 update_option( 'admin_email', '' ); … … 1369 1476 1370 1477 // remove all perms 1371 1478 $table_prefix = $wpdb->get_blog_prefix(); 1372 delete_metadata( 'user', 0, $table_prefix . 'user_level', 1479 delete_metadata( 'user', 0, $table_prefix . 'user_level', null, true ); // delete all 1373 1480 delete_metadata( 'user', 0, $table_prefix . 'capabilities', null, true ); // delete all 1374 1481 } 1375 1482 … … 1387 1494 * @param int $blog_id Ignored in this function. 1388 1495 * @param int $user_id 1389 1496 */ 1390 function install_blog_defaults( $blog_id, $user_id) {1497 function install_blog_defaults( $blog_id, $user_id ) { 1391 1498 global $wpdb; 1392 1499 1393 1500 require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); … … 1394 1501 1395 1502 $suppress = $wpdb->suppress_errors(); 1396 1503 1397 wp_install_defaults( $user_id);1504 wp_install_defaults( $user_id ); 1398 1505 1399 1506 $wpdb->suppress_errors( $suppress ); 1400 1507 } … … 1409 1516 * 1410 1517 * @since MU 1411 1518 * 1412 * @param int 1413 * @param int 1519 * @param int $blog_id 1520 * @param int $user_id 1414 1521 * @param string $password 1415 * @param string $title The new blog's title 1416 * @param array $meta Optional. Not used in the default function, but is passed along to hooks for customization. 1522 * @param string $title The new blog's title 1523 * @param array $meta Optional. Not used in the default function, but is passed along to hooks for customization. 1524 * 1417 1525 * @return bool 1418 1526 */ 1419 1527 function wpmu_welcome_notification( $blog_id, $user_id, $password, $title, $meta = array() ) { … … 1426 1534 * 1427 1535 * @since MU 1428 1536 * 1429 * @param int|bool $blog_id 1430 * @param int $user_idUser ID.1431 * @param string 1432 * @param string $titleSite title.1433 * @param array $metaSignup meta data.1537 * @param int|bool $blog_id Blog ID. 1538 * @param int $user_id User ID. 1539 * @param string $password User password. 1540 * @param string $title Site title. 1541 * @param array $meta Signup meta data. 1434 1542 */ 1435 if ( ! apply_filters( 'wpmu_welcome_notification', $blog_id, $user_id, $password, $title, $meta ) ) 1543 if ( ! apply_filters( 'wpmu_welcome_notification', $blog_id, $user_id, $password, $title, $meta ) ) { 1436 1544 return false; 1545 } 1437 1546 1438 1547 $welcome_email = get_site_option( 'welcome_email' ); 1439 1548 if ( $welcome_email == false ) { … … 1454 1563 --The Team @ SITE_NAME' ); 1455 1564 } 1456 1565 1457 $url = get_blogaddress_by_id($blog_id);1566 $url = get_blogaddress_by_id( $blog_id ); 1458 1567 $user = get_userdata( $user_id ); 1459 1568 1460 1569 $welcome_email = str_replace( 'SITE_NAME', $current_site->site_name, $welcome_email ); … … 1471 1580 * @since MU 1472 1581 * 1473 1582 * @param string $welcome_email Message body of the email. 1474 * @param int $blog_idBlog ID.1475 * @param int $user_idUser ID.1476 * @param string $password 1477 * @param string $title 1478 * @param array $metaSignup meta data.1583 * @param int $blog_id Blog ID. 1584 * @param int $user_id User ID. 1585 * @param string $password User password. 1586 * @param string $title Site title. 1587 * @param array $meta Signup meta data. 1479 1588 */ 1480 1589 $welcome_email = apply_filters( 'update_welcome_email', $welcome_email, $blog_id, $user_id, $password, $title, $meta ); 1481 $admin_email = get_site_option( 'admin_email' );1590 $admin_email = get_site_option( 'admin_email' ); 1482 1591 1483 if ( $admin_email == '' ) 1592 if ( $admin_email == '' ) { 1484 1593 $admin_email = 'support@' . $_SERVER['SERVER_NAME']; 1594 } 1485 1595 1486 $from_name = get_site_option( 'site_name' ) == '' ? 'WordPress' : esc_html( get_site_option( 'site_name' ) );1487 $message_headers = "From: \"{$from_name}\" <{$admin_email}>\n" . "Content-Type: text/plain; charset=\"" . get_option( 'blog_charset') . "\"\n";1488 $message = $welcome_email;1596 $from_name = get_site_option( 'site_name' ) == '' ? 'WordPress' : esc_html( get_site_option( 'site_name' ) ); 1597 $message_headers = "From: \"{$from_name}\" <{$admin_email}>\n" . "Content-Type: text/plain; charset=\"" . get_option( 'blog_charset' ) . "\"\n"; 1598 $message = $welcome_email; 1489 1599 1490 if ( empty( $current_site->site_name ) ) 1600 if ( empty( $current_site->site_name ) ) { 1491 1601 $current_site->site_name = 'WordPress'; 1602 } 1492 1603 1493 1604 /** 1494 1605 * Filter the subject of the welcome email after site activation. … … 1499 1610 */ 1500 1611 $subject = apply_filters( 'update_welcome_subject', sprintf( __( 'New %1$s Site: %2$s' ), $current_site->site_name, wp_unslash( $title ) ) ); 1501 1612 wp_mail( $user->user_email, wp_specialchars_decode( $subject ), $message, $message_headers ); 1613 1502 1614 return true; 1503 1615 } 1504 1616 … … 1512 1624 * 1513 1625 * @since MU 1514 1626 * 1515 * @param int 1627 * @param int $user_id 1516 1628 * @param string $password 1517 * @param array $meta Optional. Not used in the default function, but is passed along to hooks for customization. 1629 * @param array $meta Optional. Not used in the default function, but is passed along to hooks for customization. 1630 * 1518 1631 * @return bool 1519 1632 */ 1520 1633 function wpmu_welcome_user_notification( $user_id, $password, $meta = array() ) { … … 1521 1634 $current_site = get_current_site(); 1522 1635 1523 1636 /** 1524 1637 * Filter whether to bypass the welcome email after user activation. 1525 1638 * 1526 1639 * Returning false disables the welcome email. 1527 1640 * 1528 1641 * @since MU 1529 1642 * 1530 * @param int $user_idUser ID.1643 * @param int $user_id User ID. 1531 1644 * @param string $password User password. 1532 * @param array $metaSignup meta data.1645 * @param array $meta Signup meta data. 1533 1646 */ 1534 if ( ! apply_filters( 'wpmu_welcome_user_notification', $user_id, $password, $meta ) ) 1647 if ( ! apply_filters( 'wpmu_welcome_user_notification', $user_id, $password, $meta ) ) { 1535 1648 return false; 1649 } 1536 1650 1537 1651 $welcome_email = get_site_option( 'welcome_user_email' ); 1538 1652 … … 1546 1660 * @since MU 1547 1661 * 1548 1662 * @param string $welcome_email The message body of the account activation success email. 1549 * @param int $user_idUser ID.1550 * @param string $password 1551 * @param array $metaSignup meta data.1663 * @param int $user_id User ID. 1664 * @param string $password User password. 1665 * @param array $meta Signup meta data. 1552 1666 */ 1553 1667 $welcome_email = apply_filters( 'update_welcome_user_email', $welcome_email, $user_id, $password, $meta ); 1554 1668 $welcome_email = str_replace( 'SITE_NAME', $current_site->site_name, $welcome_email ); … … 1558 1672 1559 1673 $admin_email = get_site_option( 'admin_email' ); 1560 1674 1561 if ( $admin_email == '' ) 1675 if ( $admin_email == '' ) { 1562 1676 $admin_email = 'support@' . $_SERVER['SERVER_NAME']; 1677 } 1563 1678 1564 $from_name = get_site_option( 'site_name' ) == '' ? 'WordPress' : esc_html( get_site_option( 'site_name' ) );1565 $message_headers = "From: \"{$from_name}\" <{$admin_email}>\n" . "Content-Type: text/plain; charset=\"" . get_option( 'blog_charset') . "\"\n";1566 $message = $welcome_email;1679 $from_name = get_site_option( 'site_name' ) == '' ? 'WordPress' : esc_html( get_site_option( 'site_name' ) ); 1680 $message_headers = "From: \"{$from_name}\" <{$admin_email}>\n" . "Content-Type: text/plain; charset=\"" . get_option( 'blog_charset' ) . "\"\n"; 1681 $message = $welcome_email; 1567 1682 1568 if ( empty( $current_site->site_name ) ) 1683 if ( empty( $current_site->site_name ) ) { 1569 1684 $current_site->site_name = 'WordPress'; 1685 } 1570 1686 1571 1687 /** 1572 1688 * Filter the subject of the welcome email after user activation. … … 1575 1691 * 1576 1692 * @param string $subject Subject of the email. 1577 1693 */ 1578 $subject = apply_filters( 'update_welcome_user_subject', sprintf( __( 'New %1$s User: %2$s' ), $current_site->site_name, $user->user_login ) );1694 $subject = apply_filters( 'update_welcome_user_subject', sprintf( __( 'New %1$s User: %2$s' ), $current_site->site_name, $user->user_login ) ); 1579 1695 wp_mail( $user->user_email, wp_specialchars_decode( $subject ), $message, $message_headers ); 1696 1580 1697 return true; 1581 1698 } 1582 1699 … … 1596 1713 */ 1597 1714 function get_current_site() { 1598 1715 global $current_site; 1716 1599 1717 return $current_site; 1600 1718 } 1601 1719 … … 1610 1728 * @global wpdb $wpdb WordPress database abstraction object. 1611 1729 * 1612 1730 * @param int $user_id 1731 * 1613 1732 * @return array Contains the blog_id, post_id, post_date_gmt, and post_gmt_ts 1614 1733 */ 1615 1734 function get_most_recent_post_of_user( $user_id ) { 1616 1735 global $wpdb; 1617 1736 1618 $user_blogs = get_blogs_of_user( (int) $user_id );1737 $user_blogs = get_blogs_of_user( (int) $user_id ); 1619 1738 $most_recent_post = array(); 1620 1739 1621 1740 // Walk through each blog and get the most recent post 1622 1741 // published by $user_id 1623 1742 foreach ( (array) $user_blogs as $blog ) { 1624 $prefix = $wpdb->get_blog_prefix( $blog->userblog_id );1625 $recent_post = $wpdb->get_row( $wpdb->prepare( "SELECT ID, post_date_gmt FROM {$prefix}posts WHERE post_author = %d AND post_type = 'post' AND post_status = 'publish' ORDER BY post_date_gmt DESC LIMIT 1", $user_id ), ARRAY_A);1743 $prefix = $wpdb->get_blog_prefix( $blog->userblog_id ); 1744 $recent_post = $wpdb->get_row( $wpdb->prepare( "SELECT ID, post_date_gmt FROM {$prefix}posts WHERE post_author = %d AND post_type = 'post' AND post_status = 'publish' ORDER BY post_date_gmt DESC LIMIT 1", $user_id ), ARRAY_A ); 1626 1745 1627 1746 // Make sure we found a post 1628 if ( isset( $recent_post['ID']) ) {1629 $post_gmt_ts = strtotime( $recent_post['post_date_gmt']);1747 if ( isset( $recent_post['ID'] ) ) { 1748 $post_gmt_ts = strtotime( $recent_post['post_date_gmt'] ); 1630 1749 1631 1750 // If this is the first post checked or if this post is 1632 1751 // newer than the current recent post, make it the new 1633 1752 // most recent post. 1634 if ( ! isset($most_recent_post['post_gmt_ts']) || ( $post_gmt_ts > $most_recent_post['post_gmt_ts'] ) ) {1753 if ( ! isset( $most_recent_post['post_gmt_ts'] ) || ( $post_gmt_ts > $most_recent_post['post_gmt_ts'] ) ) { 1635 1754 $most_recent_post = array( 1636 'blog_id' 1637 'post_id' 1638 'post_date_gmt' 1639 'post_gmt_ts' 1755 'blog_id' => $blog->userblog_id, 1756 'post_id' => $recent_post['ID'], 1757 'post_date_gmt' => $recent_post['post_date_gmt'], 1758 'post_gmt_ts' => $post_gmt_ts 1640 1759 ); 1641 1760 } 1642 1761 } … … 1656 1775 * @since MU 1657 1776 * 1658 1777 * @param string $directory Full path of a directory. 1778 * 1659 1779 * @return int Size of the directory in MB. 1660 1780 */ 1661 1781 function get_dirsize( $directory ) { 1662 1782 $dirsize = get_transient( 'dirsize_cache' ); 1663 if ( is_array( $dirsize ) && isset( $dirsize[ $directory ][ 'size' ] ) ) 1664 return $dirsize[ $directory ][ 'size' ]; 1783 if ( is_array( $dirsize ) && isset( $dirsize[ $directory ]['size'] ) ) { 1784 return $dirsize[ $directory ]['size']; 1785 } 1665 1786 1666 if ( ! is_array( $dirsize ) ) 1787 if ( ! is_array( $dirsize ) ) { 1667 1788 $dirsize = array(); 1789 } 1668 1790 1669 1791 // Exclude individual site directories from the total when checking the main site, 1670 1792 // as they are subdirectories and should not be counted. 1671 1793 if ( is_main_site() ) { 1672 $dirsize[ $directory ][ 'size'] = recurse_dirsize( $directory, $directory . '/sites' );1794 $dirsize[ $directory ]['size'] = recurse_dirsize( $directory, $directory . '/sites' ); 1673 1795 } else { 1674 $dirsize[ $directory ][ 'size'] = recurse_dirsize( $directory );1796 $dirsize[ $directory ]['size'] = recurse_dirsize( $directory ); 1675 1797 } 1676 1798 1677 1799 set_transient( 'dirsize_cache', $dirsize, HOUR_IN_SECONDS ); 1678 return $dirsize[ $directory ][ 'size' ]; 1800 1801 return $dirsize[ $directory ]['size']; 1679 1802 } 1680 1803 1681 1804 /** … … 1688 1811 * @since 4.3.0 $exclude parameter added. 1689 1812 * 1690 1813 * @param string $directory Full path of a directory. 1691 * @param string $exclude Optional. Full path of a subdirectory to exclude from the total. 1814 * @param string $exclude Optional. Full path of a subdirectory to exclude from the total. 1815 * 1692 1816 * @return int|false Size in MB if a valid directory. False if not. 1693 1817 */ 1694 1818 function recurse_dirsize( $directory, $exclude = null ) { … … 1700 1824 return false; 1701 1825 } 1702 1826 1703 if ( $handle = opendir($directory)) {1704 while (($file = readdir($handle)) !== false) {1705 $path = $directory .'/'.$file;1706 if ( $file != '.' && $file != '..') {1707 if ( is_file($path)) {1708 $size += filesize( $path);1709 } elseif ( is_dir($path)) {1827 if ( $handle = opendir( $directory ) ) { 1828 while ( ( $file = readdir( $handle ) ) !== false ) { 1829 $path = $directory . '/' . $file; 1830 if ( $file != '.' && $file != '..' ) { 1831 if ( is_file( $path ) ) { 1832 $size += filesize( $path ); 1833 } elseif ( is_dir( $path ) ) { 1710 1834 $handlesize = recurse_dirsize( $path, $exclude ); 1711 if ( $handlesize > 0)1835 if ( $handlesize > 0 ) { 1712 1836 $size += $handlesize; 1837 } 1713 1838 } 1714 1839 } 1715 1840 } 1716 closedir( $handle);1841 closedir( $handle ); 1717 1842 } 1843 1718 1844 return $size; 1719 1845 } 1720 1846 … … 1730 1856 * @since MU 1731 1857 * 1732 1858 * @param array $mimes 1859 * 1733 1860 * @return array 1734 1861 */ 1735 1862 function check_upload_mimes( $mimes ) { 1736 $site_exts = explode( ' ', get_site_option( 'upload_filetypes', 'jpg jpeg png gif' ) );1863 $site_exts = explode( ' ', get_site_option( 'upload_filetypes', 'jpg jpeg png gif' ) ); 1737 1864 $site_mimes = array(); 1738 1865 foreach ( $site_exts as $ext ) { 1739 1866 foreach ( $mimes as $ext_pattern => $mime ) { 1740 if ( $ext != '' && strpos( $ext_pattern, $ext ) !== false ) 1741 $site_mimes[$ext_pattern] = $mime; 1867 if ( $ext != '' && strpos( $ext_pattern, $ext ) !== false ) { 1868 $site_mimes[ $ext_pattern ] = $mime; 1869 } 1742 1870 } 1743 1871 } 1872 1744 1873 return $site_mimes; 1745 1874 } 1746 1875 … … 1776 1905 function wpmu_log_new_registrations( $blog_id, $user_id ) { 1777 1906 global $wpdb; 1778 1907 $user = get_userdata( (int) $user_id ); 1779 if ( $user ) 1780 $wpdb->insert( $wpdb->registration_log, array('email' => $user->user_email, 'IP' => preg_replace( '/[^0-9., ]/', '', wp_unslash( $_SERVER['REMOTE_ADDR'] ) ), 'blog_id' => $blog_id, 'date_registered' => current_time('mysql')) ); 1908 if ( $user ) { 1909 $wpdb->insert( $wpdb->registration_log, array( 'email' => $user->user_email, 1910 'IP' => preg_replace( '/[^0-9., ]/', '', wp_unslash( $_SERVER['REMOTE_ADDR'] ) ), 1911 'blog_id' => $blog_id, 1912 'date_registered' => current_time( 'mysql' ) 1913 ) ); 1914 } 1781 1915 } 1782 1916 1783 1917 /** … … 1790 1924 * @global wpdb $wpdb WordPress database abstraction object. 1791 1925 * @staticvar int $global_terms_recurse 1792 1926 * 1793 * @param int $term_idAn ID for a term on the current blog.1927 * @param int $term_id An ID for a term on the current blog. 1794 1928 * @param string $deprecated Not used. 1929 * 1795 1930 * @return int An ID from the global terms table mapped from $term_id. 1796 1931 */ 1797 1932 function global_terms( $term_id, $deprecated = '' ) { … … 1798 1933 global $wpdb; 1799 1934 static $global_terms_recurse = null; 1800 1935 1801 if ( ! global_terms_enabled() )1936 if ( ! global_terms_enabled() ) { 1802 1937 return $term_id; 1938 } 1803 1939 1804 1940 // prevent a race condition 1805 1941 $recurse_start = false; 1806 1942 if ( $global_terms_recurse === null ) { 1807 $recurse_start = true;1943 $recurse_start = true; 1808 1944 $global_terms_recurse = 1; 1809 } elseif ( 10 < $global_terms_recurse ++ ) {1945 } elseif ( 10 < $global_terms_recurse ++ ) { 1810 1946 return $term_id; 1811 1947 } 1812 1948 1813 1949 $term_id = intval( $term_id ); 1814 $c = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->terms WHERE term_id = %d", $term_id ) );1950 $c = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->terms WHERE term_id = %d", $term_id ) ); 1815 1951 1816 1952 $global_id = $wpdb->get_var( $wpdb->prepare( "SELECT cat_ID FROM $wpdb->sitecategories WHERE category_nicename = %s", $c->slug ) ); 1817 1953 if ( $global_id == null ) { 1818 1954 $used_global_id = $wpdb->get_var( $wpdb->prepare( "SELECT cat_ID FROM $wpdb->sitecategories WHERE cat_ID = %d", $c->term_id ) ); 1819 1955 if ( null == $used_global_id ) { 1820 $wpdb->insert( $wpdb->sitecategories, array( 'cat_ID' => $term_id, 'cat_name' => $c->name, 'category_nicename' => $c->slug ) ); 1956 $wpdb->insert( $wpdb->sitecategories, array( 'cat_ID' => $term_id, 1957 'cat_name' => $c->name, 1958 'category_nicename' => $c->slug 1959 ) ); 1821 1960 $global_id = $wpdb->insert_id; 1822 if ( empty( $global_id ) ) 1961 if ( empty( $global_id ) ) { 1823 1962 return $term_id; 1963 } 1824 1964 } else { 1825 1965 $max_global_id = $wpdb->get_var( "SELECT MAX(cat_ID) FROM $wpdb->sitecategories" ); 1826 $max_local_id = $wpdb->get_var( "SELECT MAX(term_id) FROM $wpdb->terms" );1966 $max_local_id = $wpdb->get_var( "SELECT MAX(term_id) FROM $wpdb->terms" ); 1827 1967 $new_global_id = max( $max_global_id, $max_local_id ) + mt_rand( 100, 400 ); 1828 $wpdb->insert( $wpdb->sitecategories, array( 'cat_ID' => $new_global_id, 'cat_name' => $c->name, 'category_nicename' => $c->slug ) ); 1968 $wpdb->insert( $wpdb->sitecategories, array( 'cat_ID' => $new_global_id, 1969 'cat_name' => $c->name, 1970 'category_nicename' => $c->slug 1971 ) ); 1829 1972 $global_id = $wpdb->insert_id; 1830 1973 } 1831 1974 } elseif ( $global_id != $term_id ) { … … 1839 1982 } 1840 1983 1841 1984 if ( $global_id != $term_id ) { 1842 if ( get_option( 'default_category' ) == $term_id ) 1985 if ( get_option( 'default_category' ) == $term_id ) { 1843 1986 update_option( 'default_category', $global_id ); 1987 } 1844 1988 1845 $wpdb->update( $wpdb->terms, array( 'term_id' => $global_id), array('term_id' => $term_id) );1846 $wpdb->update( $wpdb->term_taxonomy, array( 'term_id' => $global_id), array('term_id' => $term_id) );1847 $wpdb->update( $wpdb->term_taxonomy, array( 'parent' => $global_id), array('parent' => $term_id) );1989 $wpdb->update( $wpdb->terms, array( 'term_id' => $global_id ), array( 'term_id' => $term_id ) ); 1990 $wpdb->update( $wpdb->term_taxonomy, array( 'term_id' => $global_id ), array( 'term_id' => $term_id ) ); 1991 $wpdb->update( $wpdb->term_taxonomy, array( 'parent' => $global_id ), array( 'parent' => $term_id ) ); 1848 1992 1849 clean_term_cache( $term_id);1993 clean_term_cache( $term_id ); 1850 1994 } 1851 if ( $recurse_start ) 1995 if ( $recurse_start ) { 1852 1996 $global_terms_recurse = null; 1997 } 1853 1998 1854 1999 return $global_id; 1855 2000 } … … 1861 2006 * @since MU 1862 2007 * 1863 2008 * @param array|string $deprecated Not used. 2009 * 1864 2010 * @return array The current site's domain 1865 2011 */ 1866 2012 function redirect_this_site( $deprecated = '' ) { … … 1875 2021 * @blessed 1876 2022 * 1877 2023 * @param array $upload 2024 * 1878 2025 * @return string|array If the upload is under the size limit, $upload is returned. Otherwise returns an error message. 1879 2026 */ 1880 2027 function upload_is_file_too_big( $upload ) { 1881 if ( ! is_array( $upload ) || defined( 'WP_IMPORTING' ) || get_site_option( 'upload_space_check_disabled' ) ) 2028 if ( ! is_array( $upload ) || defined( 'WP_IMPORTING' ) || get_site_option( 'upload_space_check_disabled' ) ) { 1882 2029 return $upload; 2030 } 1883 2031 1884 if ( strlen( $upload['bits'] ) 2032 if ( strlen( $upload['bits'] ) > ( KB_IN_BYTES * get_site_option( 'fileupload_maxk', 1500 ) ) ) { 1885 2033 return sprintf( __( 'This file is too big. Files must be less than %d KB in size.' ) . '<br />', get_site_option( 'fileupload_maxk', 1500 ) ); 1886 2034 } 1887 2035 … … 1896 2044 function signup_nonce_fields() { 1897 2045 $id = mt_rand(); 1898 2046 echo "<input type='hidden' name='signup_form_id' value='{$id}' />"; 1899 wp_nonce_field( 'signup_form_' . $id, '_signup_form', false);2047 wp_nonce_field( 'signup_form_' . $id, '_signup_form', false ); 1900 2048 } 1901 2049 1902 2050 /** … … 1905 2053 * @since MU 1906 2054 * 1907 2055 * @param array $result 2056 * 1908 2057 * @return array 1909 2058 */ 1910 2059 function signup_nonce_check( $result ) { 1911 if ( ! strpos( $_SERVER[ 'PHP_SELF' ], 'wp-signup.php' ) )2060 if ( ! strpos( $_SERVER['PHP_SELF'], 'wp-signup.php' ) ) { 1912 2061 return $result; 2062 } 1913 2063 1914 if ( wp_create_nonce( 'signup_form_' . $_POST[ 'signup_form_id' ]) != $_POST['_signup_form'] )2064 if ( wp_create_nonce( 'signup_form_' . $_POST['signup_form_id'] ) != $_POST['_signup_form'] ) { 1915 2065 wp_die( __( 'Please try again.' ) ); 2066 } 1916 2067 1917 2068 return $result; 1918 2069 } … … 1933 2084 * @param string $no_blog_redirect The redirect URL defined in NOBLOGREDIRECT. 1934 2085 */ 1935 2086 if ( is_main_site() && is_404() && defined( 'NOBLOGREDIRECT' ) && ( $destination = apply_filters( 'blog_redirect_404', NOBLOGREDIRECT ) ) ) { 1936 if ( $destination == '%siteurl%' ) 2087 if ( $destination == '%siteurl%' ) { 1937 2088 $destination = network_home_url(); 2089 } 1938 2090 wp_redirect( $destination ); 1939 2091 exit(); 1940 2092 } … … 1950 2102 * @since MU 1951 2103 */ 1952 2104 function maybe_add_existing_user_to_blog() { 1953 if ( false === strpos( $_SERVER[ 'REQUEST_URI' ], '/newbloguser/' ) )2105 if ( false === strpos( $_SERVER['REQUEST_URI'], '/newbloguser/' ) ) { 1954 2106 return; 2107 } 1955 2108 1956 $parts = explode( '/', $_SERVER[ 'REQUEST_URI'] );1957 $key = array_pop( $parts );2109 $parts = explode( '/', $_SERVER['REQUEST_URI'] ); 2110 $key = array_pop( $parts ); 1958 2111 1959 if ( $key == '' ) 2112 if ( $key == '' ) { 1960 2113 $key = array_pop( $parts ); 2114 } 1961 2115 1962 2116 $details = get_option( 'new_user_' . $key ); 1963 if ( ! empty( $details ) )2117 if ( ! empty( $details ) ) { 1964 2118 delete_option( 'new_user_' . $key ); 2119 } 1965 2120 1966 if ( empty( $details ) || is_wp_error( add_existing_user_to_blog( $details ) ) ) 1967 wp_die( sprintf(__('An error occurred adding you to this site. Back to the <a href="%s">homepage</a>.'), home_url() ) ); 2121 if ( empty( $details ) || is_wp_error( add_existing_user_to_blog( $details ) ) ) { 2122 wp_die( sprintf( __( 'An error occurred adding you to this site. Back to the <a href="%s">homepage</a>.' ), home_url() ) ); 2123 } 1968 2124 1969 2125 wp_die( sprintf( __( 'You have been added to this site. Please visit the <a href="%s">homepage</a> or <a href="%s">log in</a> using your username and password.' ), home_url(), admin_url() ), __( 'WordPress › Success' ), array( 'response' => 200 ) ); 1970 2126 } … … 1977 2133 * @global int $blog_id 1978 2134 * 1979 2135 * @param array $details 2136 * 1980 2137 * @return true|WP_Error|void 1981 2138 */ 1982 2139 function add_existing_user_to_blog( $details = false ) { … … 1983 2140 global $blog_id; 1984 2141 1985 2142 if ( is_array( $details ) ) { 1986 $result = add_user_to_blog( $blog_id, $details[ 'user_id' ], $details[ 'role'] );2143 $result = add_user_to_blog( $blog_id, $details['user_id'], $details['role'] ); 1987 2144 /** 1988 2145 * Fires immediately after an existing user is added to a site. 1989 2146 * 1990 2147 * @since MU 1991 2148 * 1992 * @param int 1993 * @param mixed $result 2149 * @param int $user_id User ID. 2150 * @param mixed $result True on success or a WP_Error object if the user doesn't exist. 1994 2151 */ 1995 2152 do_action( 'added_existing_user', $details['user_id'], $result ); 2153 1996 2154 return $result; 1997 2155 } 1998 2156 } … … 2006 2164 * @since MU 2007 2165 * @see add_user_to_blog() 2008 2166 * 2009 * @param int 2167 * @param int $user_id 2010 2168 * @param mixed $password Ignored. 2011 2169 * @param array $meta 2012 2170 */ 2013 2171 function add_new_user_to_blog( $user_id, $password, $meta ) { 2014 if ( ! empty( $meta[ 'add_to_blog'] ) ) {2015 $blog_id = $meta[ 'add_to_blog'];2016 $role = $meta[ 'new_role'];2017 remove_user_from_blog( $user_id, get_current_site()->blog_id); // remove user from main blog.2172 if ( ! empty( $meta['add_to_blog'] ) ) { 2173 $blog_id = $meta['add_to_blog']; 2174 $role = $meta['new_role']; 2175 remove_user_from_blog( $user_id, get_current_site()->blog_id ); // remove user from main blog. 2018 2176 add_user_to_blog( $blog_id, $user_id, $role ); 2019 2177 update_user_meta( $user_id, 'primary_blog', $blog_id ); 2020 2178 } … … 2037 2195 * @since MU 2038 2196 * 2039 2197 * @param string|WP_User $user Optional. Defaults to current user. WP_User object, 2040 * or user login name as a string. 2198 * or user login name as a string. 2199 * 2041 2200 * @return bool 2042 2201 */ 2043 2202 function is_user_spammy( $user = null ) { 2044 2203 if ( ! ( $user instanceof WP_User ) ) { 2045 2204 if ( $user ) { 2046 2205 $user = get_user_by( 'login', $user ); 2047 2206 } else { … … 2060 2219 * @since MU 2061 2220 * 2062 2221 * @param int $old_value 2063 * @param int $value 2222 * @param int $value The new public value 2064 2223 */ 2065 2224 function update_blog_public( $old_value, $value ) { 2066 2225 update_blog_status( get_current_blog_id(), 'public', (int) $value ); … … 2074 2233 * @global wpdb $wpdb WordPress database abstraction object. 2075 2234 * 2076 2235 * @param string $key 2077 * @param int $user_id Optional. Defaults to current user. 2078 * @param int $blog_id Optional. Defaults to current blog. 2236 * @param int $user_id Optional. Defaults to current user. 2237 * @param int $blog_id Optional. Defaults to current blog. 2238 * 2079 2239 * @return bool 2080 2240 */ 2081 2241 function is_user_option_local( $key, $user_id = 0, $blog_id = 0 ) { … … 2098 2258 * @return bool 2099 2259 */ 2100 2260 function users_can_register_signup_filter() { 2101 $registration = get_site_option('registration'); 2261 $registration = get_site_option( 'registration' ); 2262 2102 2263 return ( $registration == 'all' || $registration == 'user' ); 2103 2264 } 2104 2265 … … 2108 2269 * @since MU 2109 2270 * 2110 2271 * @param string $text 2272 * 2111 2273 * @return string 2112 2274 */ 2113 2275 function welcome_user_msg_filter( $text ) { 2114 if ( ! $text ) {2276 if ( ! $text ) { 2115 2277 remove_filter( 'site_option_welcome_user_email', 'welcome_user_msg_filter' ); 2116 2278 2117 2279 /* translators: Do not translate USERNAME, PASSWORD, LOGINLINK, SITE_NAME: those are placeholders. */ … … 2129 2291 --The Team @ SITE_NAME' ); 2130 2292 update_site_option( 'welcome_user_email', $text ); 2131 2293 } 2294 2132 2295 return $text; 2133 2296 } 2134 2297 … … 2140 2303 * @staticvar bool $forced_content 2141 2304 * 2142 2305 * @param bool $force 2306 * 2143 2307 * @return bool True if forced, false if not forced. 2144 2308 */ 2145 2309 function force_ssl_content( $force = '' ) { … … 2146 2310 static $forced_content = false; 2147 2311 2148 2312 if ( '' != $force ) { 2149 $old_forced = $forced_content;2313 $old_forced = $forced_content; 2150 2314 $forced_content = $force; 2315 2151 2316 return $old_forced; 2152 2317 } 2153 2318 … … 2162 2327 * @since 2.8.5 2163 2328 * 2164 2329 * @param string $url URL 2330 * 2165 2331 * @return string URL with https as the scheme 2166 2332 */ 2167 2333 function filter_SSL( $url ) { 2168 if ( ! is_string( $url ) ) 2169 return get_bloginfo( 'url' ); // Return home blog url with proper scheme 2334 if ( ! is_string( $url ) ) { 2335 return get_bloginfo( 'url' ); 2336 } // Return home blog url with proper scheme 2170 2337 2171 if ( force_ssl_content() && is_ssl() ) 2338 if ( force_ssl_content() && is_ssl() ) { 2172 2339 $url = set_url_scheme( $url, 'https' ); 2340 } 2173 2341 2174 2342 return $url; 2175 2343 } … … 2180 2348 * @since 3.1.0 2181 2349 */ 2182 2350 function wp_schedule_update_network_counts() { 2183 if ( ! is_main_site() )2351 if ( ! is_main_site() ) { 2184 2352 return; 2353 } 2185 2354 2186 if ( ! wp_next_scheduled('update_network_counts') && ! wp_installing() ) 2187 wp_schedule_event(time(), 'twicedaily', 'update_network_counts'); 2355 if ( ! wp_next_scheduled( 'update_network_counts' ) && ! wp_installing() ) { 2356 wp_schedule_event( time(), 'twicedaily', 'update_network_counts' ); 2357 } 2188 2358 } 2189 2359 2190 2360 /** 2191 2361 * Update the network-wide counts for the current network. 2192 2362 * 2193 * 2363 * @since 3.1.0 2194 2364 */ 2195 2365 function wp_update_network_counts() { 2196 2366 wp_update_network_user_counts(); … … 2215 2385 * 2216 2386 * @see wp_is_large_network() 2217 2387 * 2218 * @param bool 2219 * @param string $context 2388 * @param bool $small_network Whether the network is considered small. 2389 * @param string $context Context. Either 'users' or 'sites'. 2220 2390 */ 2221 if ( ! apply_filters( 'enable_live_network_counts', $is_small_network, 'sites' ) ) 2391 if ( ! apply_filters( 'enable_live_network_counts', $is_small_network, 'sites' ) ) { 2222 2392 return; 2393 } 2223 2394 2224 2395 wp_update_network_site_counts(); 2225 2396 } … … 2236 2407 $is_small_network = ! wp_is_large_network( 'users' ); 2237 2408 2238 2409 /** This filter is documented in wp-includes/ms-functions.php */ 2239 if ( ! apply_filters( 'enable_live_network_counts', $is_small_network, 'users' ) ) 2410 if ( ! apply_filters( 'enable_live_network_counts', $is_small_network, 'users' ) ) { 2240 2411 return; 2412 } 2241 2413 2242 2414 wp_update_network_user_counts(); 2243 2415 } … … 2252 2424 function wp_update_network_site_counts() { 2253 2425 global $wpdb; 2254 2426 2255 $count = $wpdb->get_var( $wpdb->prepare("SELECT COUNT(blog_id) as c FROM $wpdb->blogs WHERE site_id = %d AND spam = '0' AND deleted = '0' and archived = '0'", $wpdb->siteid) ); 2427 2428 $query = new WP_Site_Query(); 2429 $args = array( 'network_id' => $wpdb->siteid, 'spam' => 0, 'deleted' => 0, 'archived' => 0, 'count' => true ); 2430 $count = $query->query( $args ); 2431 2256 2432 update_site_option( 'blog_count', $count ); 2257 2433 } 2258 2434 … … 2304 2480 function get_space_allowed() { 2305 2481 $space_allowed = get_option( 'blog_upload_space' ); 2306 2482 2307 if ( ! is_numeric( $space_allowed ) ) 2483 if ( ! is_numeric( $space_allowed ) ) { 2308 2484 $space_allowed = get_site_option( 'blog_upload_space' ); 2485 } 2309 2486 2310 if ( ! is_numeric( $space_allowed ) ) 2487 if ( ! is_numeric( $space_allowed ) ) { 2311 2488 $space_allowed = 100; 2489 } 2312 2490 2313 2491 /** 2314 2492 * Filter the upload quota for the current site. … … 2333 2511 $allowed = 0; 2334 2512 } 2335 2513 $space_allowed = $allowed * MB_IN_BYTES; 2336 if ( get_site_option( 'upload_space_check_disabled' ) ) 2514 if ( get_site_option( 'upload_space_check_disabled' ) ) { 2337 2515 return $space_allowed; 2516 } 2338 2517 2339 2518 $space_used = get_space_used() * MB_IN_BYTES; 2340 2519 2341 if ( ( $space_allowed - $space_used ) <= 0 ) 2520 if ( ( $space_allowed - $space_used ) <= 0 ) { 2342 2521 return 0; 2522 } 2343 2523 2344 2524 return $space_allowed - $space_used; 2345 2525 } … … 2351 2531 * @return bool True if space is available, false otherwise. 2352 2532 */ 2353 2533 function is_upload_space_available() { 2354 if ( get_site_option( 'upload_space_check_disabled' ) ) 2534 if ( get_site_option( 'upload_space_check_disabled' ) ) { 2355 2535 return true; 2536 } 2356 2537 2357 2538 return (bool) get_upload_space_available(); 2358 2539 } … … 2363 2544 * @since 3.0.0 2364 2545 * 2365 2546 * @param int $size Upload size limit in bytes. 2547 * 2366 2548 * @return int Upload size limit in bytes. 2367 2549 */ 2368 2550 function upload_size_limit_filter( $size ) { 2369 2551 $fileupload_maxk = KB_IN_BYTES * get_site_option( 'fileupload_maxk', 1500 ); 2370 if ( get_site_option( 'upload_space_check_disabled' ) ) 2552 if ( get_site_option( 'upload_space_check_disabled' ) ) { 2371 2553 return min( $size, $fileupload_maxk ); 2554 } 2372 2555 2373 2556 return min( $size, $fileupload_maxk, get_upload_space_available() ); 2374 2557 } … … 2380 2563 * Plugins can alter this criteria using the 'wp_is_large_network' filter. 2381 2564 * 2382 2565 * @since 3.3.0 2566 * 2383 2567 * @param string $using 'sites or 'users'. Default is 'sites'. 2568 * 2384 2569 * @return bool True if the network meets the criteria for large. False otherwise. 2385 2570 */ 2386 2571 function wp_is_large_network( $using = 'sites' ) { 2387 2572 if ( 'users' == $using ) { 2388 2573 $count = get_user_count(); 2574 2389 2575 /** 2390 2576 * Filter whether the network is considered large. 2391 2577 * 2392 2578 * @since 3.3.0 2393 2579 * 2394 * @param bool 2395 * @param string $component 2396 * @param int $countThe count of items for the component.2580 * @param bool $is_large_network Whether the network has more than 10000 users or sites. 2581 * @param string $component The component to count. Accepts 'users', or 'sites'. 2582 * @param int $count The count of items for the component. 2397 2583 */ 2398 2584 return apply_filters( 'wp_is_large_network', $count > 10000, 'users', $count ); 2399 2585 } 2400 2586 2401 2587 $count = get_blog_count(); 2588 2402 2589 /** This filter is documented in wp-includes/ms-functions.php */ 2403 2590 return apply_filters( 'wp_is_large_network', $count > 10000, 'sites', $count ); 2404 2591 } … … 2414 2601 * @param array $args { 2415 2602 * Array of default arguments. Optional. 2416 2603 * 2417 * 2604 * @type int|array $network_id A network ID or array of network IDs. Set to null to retrieve sites 2418 2605 * from all networks. Defaults to current network ID. 2419 * @type int $publicRetrieve public or non-public sites. Default null, for any.2420 * @type int $archivedRetrieve archived or non-archived sites. Default null, for any.2421 * @type int $matureRetrieve mature or non-mature sites. Default null, for any.2422 * @type int $spamRetrieve spam or non-spam sites. Default null, for any.2423 * @type int $deletedRetrieve deleted or non-deleted sites. Default null, for any.2424 * @type int $limitNumber of sites to limit the query to. Default 100.2425 * @type int $offsetExclude the first x sites. Used in combination with the $limit parameter. Default 0.2606 * @type int $public Retrieve public or non-public sites. Default null, for any. 2607 * @type int $archived Retrieve archived or non-archived sites. Default null, for any. 2608 * @type int $mature Retrieve mature or non-mature sites. Default null, for any. 2609 * @type int $spam Retrieve spam or non-spam sites. Default null, for any. 2610 * @type int $deleted Retrieve deleted or non-deleted sites. Default null, for any. 2611 * @type int $limit Number of sites to limit the query to. Default 100. 2612 * @type int $offset Exclude the first x sites. Used in combination with the $limit parameter. Default 0. 2426 2613 * } 2427 2614 * @return array An empty array if the install is considered "large" via wp_is_large_network(). Otherwise, 2428 2615 * an associative array of site data arrays, each containing the site (network) ID, blog ID, … … 2432 2619 function wp_get_sites( $args = array() ) { 2433 2620 global $wpdb; 2434 2621 2435 if ( wp_is_large_network() )2436 return array();2437 2438 2622 $defaults = array( 2439 2623 'network_id' => $wpdb->siteid, 2440 'public' => null,2441 'archived' => null,2442 'mature' => null,2443 'spam' => null,2444 'deleted' => null,2445 2624 'limit' => 100, 2446 2625 'offset' => 0, 2447 2626 ); … … 2448 2627 2449 2628 $args = wp_parse_args( $args, $defaults ); 2450 2629 2451 $query = "SELECT * FROM $wpdb->blogs WHERE 1=1 ";2630 $query = new WP_Site_Query(); 2452 2631 2453 if ( isset( $args['network_id'] ) && ( is_array( $args['network_id'] ) || is_numeric( $args['network_id'] ) ) ) { 2454 $network_ids = implode( ',', wp_parse_id_list( $args['network_id'] ) ); 2455 $query .= "AND site_id IN ($network_ids) "; 2456 } 2457 2458 if ( isset( $args['public'] ) ) 2459 $query .= $wpdb->prepare( "AND public = %d ", $args['public'] ); 2460 2461 if ( isset( $args['archived'] ) ) 2462 $query .= $wpdb->prepare( "AND archived = %d ", $args['archived'] ); 2463 2464 if ( isset( $args['mature'] ) ) 2465 $query .= $wpdb->prepare( "AND mature = %d ", $args['mature'] ); 2466 2467 if ( isset( $args['spam'] ) ) 2468 $query .= $wpdb->prepare( "AND spam = %d ", $args['spam'] ); 2469 2470 if ( isset( $args['deleted'] ) ) 2471 $query .= $wpdb->prepare( "AND deleted = %d ", $args['deleted'] ); 2472 2473 if ( isset( $args['limit'] ) && $args['limit'] ) { 2474 if ( isset( $args['offset'] ) && $args['offset'] ) 2475 $query .= $wpdb->prepare( "LIMIT %d , %d ", $args['offset'], $args['limit'] ); 2476 else 2477 $query .= $wpdb->prepare( "LIMIT %d ", $args['limit'] ); 2478 } 2479 2480 $site_results = $wpdb->get_results( $query, ARRAY_A ); 2481 2482 return $site_results; 2632 return $query->query( $args ); 2483 2633 } 2484 2634 2485 2635 /** … … 2491 2641 */ 2492 2642 function get_subdirectory_reserved_names() { 2493 2643 $names = array( 2494 'page', 'comments', 'blog', 'files', 'feed', 'wp-admin', 2495 'wp-content', 'wp-includes', 'wp-json', 'embed' 2644 'page', 2645 'comments', 2646 'blog', 2647 'files', 2648 'feed', 2649 'wp-admin', 2650 'wp-content', 2651 'wp-includes', 2652 'wp-json', 2653 'embed' 2496 2654 ); 2497 2655 2498 2656 /** -
wp-includes/ms-load.php
231 231 $domains = array( $domain ); 232 232 if ( 'www.' === substr( $domain, 0, 4 ) ) { 233 233 $domains[] = substr( $domain, 4 ); 234 $search_domains = "'" . implode( "', '", $wpdb->_escape( $domains ) ) . "'";235 234 } 236 235 237 if ( count( $paths ) > 1 ) { 238 $search_paths = "'" . implode( "', '", $wpdb->_escape( $paths ) ) . "'"; 239 } 240 241 if ( count( $domains ) > 1 && count( $paths ) > 1 ) { 242 $site = $wpdb->get_row( "SELECT * FROM $wpdb->blogs WHERE domain IN ($search_domains) AND path IN ($search_paths) ORDER BY CHAR_LENGTH(domain) DESC, CHAR_LENGTH(path) DESC LIMIT 1" ); 243 } elseif ( count( $domains ) > 1 ) { 244 $sql = $wpdb->prepare( "SELECT * FROM $wpdb->blogs WHERE path = %s", $paths[0] ); 245 $sql .= " AND domain IN ($search_domains) ORDER BY CHAR_LENGTH(domain) DESC LIMIT 1"; 246 $site = $wpdb->get_row( $sql ); 247 } elseif ( count( $paths ) > 1 ) { 248 $sql = $wpdb->prepare( "SELECT * FROM $wpdb->blogs WHERE domain = %s", $domains[0] ); 249 $sql .= " AND path IN ($search_paths) ORDER BY CHAR_LENGTH(path) DESC LIMIT 1"; 250 $site = $wpdb->get_row( $sql ); 251 } else { 252 $site = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->blogs WHERE domain = %s AND path = %s", $domains[0], $paths[0] ) ); 253 } 254 236 $query = new WP_Site_Query(); 237 $args = array( 'path__in' => $path, 'domain__in' => $domains, 'number' => 1 ); 238 $result = $query->query( $args ); 239 $site = array_shift( $result ); 255 240 if ( $site ) { 256 241 // @todo get_blog_details() 257 242 return $site; -
wp-settings.php
99 99 100 100 // Initialize multisite if enabled. 101 101 if ( is_multisite() ) { 102 require( ABSPATH . WPINC . '/class-wp-site-query.php' ); 102 103 require( ABSPATH . WPINC . '/ms-blogs.php' ); 103 104 require( ABSPATH . WPINC . '/ms-settings.php' ); 104 105 } elseif ( ! defined( 'MULTISITE' ) ) {