Ticket #14953: 14953-4.diff
File 14953-4.diff, 25.5 KB (added by , 15 years ago) |
---|
-
wp-includes/ms-functions.php
407 407 return $id; 408 408 } 409 409 410 // wpmu admin functions410 // Admin functions 411 411 412 /** 413 * Redirect a user based on $_GET or $_POST arguments. 414 * 415 * The function looks for redirect arguments in the following order: 416 * 1) $_GET['ref'] 417 * 2) $_POST['ref'] 418 * 3) $_SERVER['HTTP_REFERER'] 419 * 4) $_GET['redirect'] 420 * 5) $_POST['redirect'] 421 * 6) $url 422 * 423 * @since MU 424 * @uses wpmu_admin_redirect_add_updated_param() 425 * 426 * @param string $url 427 * @return none 428 */ 412 429 function wpmu_admin_do_redirect( $url = '' ) { 413 430 $ref = ''; 414 431 if ( isset( $_GET['ref'] ) ) … … 437 454 exit(); 438 455 } 439 456 457 /** 458 * Adds an 'updated=true' argument to a URL. 459 * 460 * @since MU 461 * 462 * @param string $url 463 * @return string $url 464 */ 440 465 function wpmu_admin_redirect_add_updated_param( $url = '' ) { 441 466 if ( strpos( $url, 'updated=true' ) === false ) { 442 467 if ( strpos( $url, '?' ) === false ) … … 447 472 return $url; 448 473 } 449 474 475 /** 476 * Checks an email address against a list of banned domains. 477 * 478 * This function checks against the Banned Email Domains list 479 * at wp-admin/network/settings.php. The check is only run on 480 * self-registrations; user creation at wp-admin/network/users.php 481 * bypasses this check. 482 * 483 * @since MU 484 * 485 * @param string $user_email The email provided by the user at registration. 486 * @return bool Returns true when the email address is banned. 487 */ 450 488 function is_email_address_unsafe( $user_email ) { 451 489 $banned_names = get_site_option( 'banned_email_domains' ); 452 490 if ($banned_names && !is_array( $banned_names )) … … 470 508 return false; 471 509 } 472 510 511 /** 512 * Processes new user registrations. 513 * 514 * Checks the data provided by the user during signup. Verifies 515 * the validity and uniqueness of user names and user email addresses, 516 * and checks email addresses against admin-provided domain 517 * whitelists and blacklists. 518 * 519 * The hook 'wpmu_validate_user_signup' provides an easy way 520 * to modify the signup process. The value $result, which is passed 521 * to the hook, contains both the user-provided info and the error 522 * messages created by the function. 'wpmu_validate_user_signup' allows 523 * you to process the data in any way you'd like, and unset the 524 * relevant errors if necessary. 525 * 526 * @since MU 527 * @uses sanitize_user() 528 * @uses sanitize_email() 529 * @uses is_email_address_unsafe() 530 * @uses username_exists() 531 * @uses email_exists() 532 * @uses $wpdb 533 * 534 * @param string $user_name The login name provided by the user. 535 * @param string $user_email The email provided by the user. 536 * @return array $result Contains username, email, and error messages. 537 */ 473 538 function wpmu_validate_user_signup($user_name, $user_email) { 474 539 global $wpdb; 475 540 … … 562 627 return apply_filters('wpmu_validate_user_signup', $result); 563 628 } 564 629 630 /** 631 * Processes new site registrations. 632 * 633 * Checks the data provided by the user during blog signup. Verifies 634 * the validity and uniqueness of blog paths and domains. 635 * 636 * This function prevents the current user from registering a new site 637 * with a blogname equivalent to another user's login name. Passing the 638 * $user parameter to the function, where $user is the other user, is 639 * effectively an override of this limitation. 640 * 641 * Filter 'wpmu_validate_blog_signup' if you want to modify 642 * the way that WordPress validates new site signups. 643 * 644 * @since MU 645 * @uses is_subdomain_install() 646 * @uses domain_exists() 647 * @uses username_exists() 648 * @uses $wpdb 649 * 650 * @param string $blogname The blog name provided by the user. Must be unique. 651 * @param string $blog_title The blog title provided by the user. 652 * @return array $result Contains the new site data and error messages. 653 */ 565 654 function wpmu_validate_blog_signup($blogname, $blog_title, $user = '') { 566 655 global $wpdb, $domain, $base, $current_site; 567 656 … … 645 734 return apply_filters('wpmu_validate_blog_signup', $result); 646 735 } 647 736 648 // Record signup information for future activation. wpmu_validate_signup() should be run 649 // on the inputs before calling wpmu_signup(). 737 /** 738 * Record site signup information for future activation. 739 * 740 * @since MU 741 * @uses wpmu_signup_blog_notification() 742 * @uses $wpdb 743 * 744 * @param string $domain The requested domain. 745 * @param string $path The requested path. 746 * @param string $title The requested site title. 747 * @param string $user The user's requested login name. 748 * @param string $user_email The user's email address. 749 * @param array $meta By default, contains the requested privacy setting and lang_id. 750 * @return none 751 */ 650 752 function wpmu_signup_blog($domain, $path, $title, $user, $user_email, $meta = '') { 651 753 global $wpdb; 652 754 … … 670 772 wpmu_signup_blog_notification($domain, $path, $title, $user, $user_email, $key, $meta); 671 773 } 672 774 775 /** 776 * Record user signup information for future activation. 777 * 778 * This function is used when user registration is open but 779 * new site registration is not. 780 * 781 * @since MU 782 * @uses wpmu_signup_user_notification() 783 * @uses $wpdb 784 * 785 * @param string $user The user's requested login name. 786 * @param string $user_email The user's email address. 787 * @param array $meta By default, this is an empty array. 788 * @return none 789 */ 673 790 function wpmu_signup_user($user, $user_email, $meta = '') { 674 791 global $wpdb; 675 792 … … 693 810 wpmu_signup_user_notification($user, $user_email, $key, $meta); 694 811 } 695 812 696 // Notify user of signup success. 813 /** 814 * Notify user of signup success. 815 * 816 * This is the notification function used when site registration 817 * is enabled. 818 * 819 * Filter 'wpmu_signup_blog_notification' to bypass this function or 820 * replace it with your own notification behavior. 821 * 822 * Filter 'wpmu_signup_blog_notification_email' and 823 * 'wpmu_signup_blog_notification_email' to change the content 824 * and subject line of the email sent to newly registered users. 825 * 826 * @since MU 827 * @uses is_subdomain_install() 828 * @uses wp_mail() 829 * 830 * @param string $domain The new blog domain. 831 * @param string $path The new blog path. 832 * @param string $title The site title. 833 * @param string $user The user's login name. 834 * @param string $user_email The user's email address. 835 * @param array $meta By default, contains the requested privacy setting and lang_id. 836 * @param string $key The activation key created in wpmu_signup_blog() 837 * @return bool 838 */ 697 839 function wpmu_signup_blog_notification($domain, $path, $title, $user, $user_email, $key, $meta = '') { 698 840 global $current_site; 699 841 … … 734 876 return true; 735 877 } 736 878 879 /** 880 * Notify user of signup success. 881 * 882 * This is the notification function used when no new site has 883 * been requested. 884 * 885 * Filter 'wpmu_signup_user_notification' to bypass this function or 886 * replace it with your own notification behavior. 887 * 888 * Filter 'wpmu_signup_user_notification_email' and 889 * 'wpmu_signup_user_notification_subject' to change the content 890 * and subject line of the email sent to newly registered users. 891 * 892 * @since MU 893 * @uses wp_mail() 894 * 895 * @param string $user The user's login name. 896 * @param string $user_email The user's email address. 897 * @param array $meta By default, an empty array. 898 * @param string $key The activation key created in wpmu_signup_user() 899 * @return bool 900 */ 737 901 function wpmu_signup_user_notification($user, $user_email, $key, $meta = '') { 738 902 if ( !apply_filters('wpmu_signup_user_notification', $user, $user_email, $key, $meta) ) 739 903 return false; … … 765 929 return true; 766 930 } 767 931 932 /** 933 * Activate a signup. 934 * 935 * Hook to 'wpmu_activate_user' or 'wpmu_activate_blog' for events 936 * that should happen only when users or sites are self-created (since 937 * those actions are not called when users and sites are created 938 * by a Super Admin). 939 * 940 * @since MU 941 * @uses $wpdb 942 * @uses wp_generate_password() 943 * @uses wpmu_welcome_user_notification() 944 * @uses add_user_to_blog() 945 * @uses add_new_user_to_blog() 946 * @uses wpmu_create_user() 947 * @uses wpmu_create_blog() 948 * @uses wpmu_welcome_notification() 949 * 950 * @param string $key The activation key provided to the user. 951 * @return array An array containing information about the activated user and/or blog 952 */ 768 953 function wpmu_activate_signup($key) { 769 954 global $wpdb, $current_site; 770 955 … … 830 1015 return array('blog_id' => $blog_id, 'user_id' => $user_id, 'password' => $password, 'title' => $signup->title, 'meta' => $meta); 831 1016 } 832 1017 1018 /** 1019 * Create a user. 1020 * 1021 * This function runs when a user self-registers as well as when 1022 * a Super Admin creates a new user. Hook to 'wpmu_new_user' for events 1023 * that should affect all new users, but only on Multisite (otherwise 1024 * use 'user_register'). 1025 * 1026 * @since MU 1027 * @uses wp_create_user() 1028 * @uses delete_user_option() 1029 * 1030 * @param string $user_name The new user's login name. 1031 * @param string $password The new user's password. 1032 * @param string $email The new user's email address. 1033 * @return mixed Returns false on failure, or int $user_id on success 1034 */ 833 1035 function wpmu_create_user( $user_name, $password, $email) { 834 1036 $user_name = preg_replace( '/\s+/', '', sanitize_user( $user_name, true ) ); 835 1037 … … 846 1048 return $user_id; 847 1049 } 848 1050 1051 /** 1052 * Create a site. 1053 * 1054 * This function runs when a user self-registers a new site as well 1055 * as when a Super Admin creates a new site. Hook to 'wpmu_new_blog' 1056 * for events that should affect all new sites. 1057 * 1058 * On subdirectory installs, $domain is the same as the main site's 1059 * domain, and the path is the subdirectory name (eg 'example.com' 1060 * and '/blog1/'). On subdomain installs, $domain is the new subdomain + 1061 * root domain (eg 'blog1.example.com'), and $path is '/'. 1062 * 1063 * @since MU 1064 * @uses is_subdomain_install() 1065 * @uses domain_exists() 1066 * @uses insert_blog() 1067 * @uses switch_to_blog() 1068 * @uses wp_install_defaults() 1069 * @uses add_user_to_blog() 1070 * @uses update_blog_status() 1071 * @uses restore_current_blog() 1072 * 1073 * @param string $domain The new site's domain. 1074 * @param string $path The new site's path. 1075 * @param string $title The new site's title. 1076 * @param int $user_id The user ID of the new site's admin. 1077 * @param array $meta Optional. Used to set initial site options. 1078 * @param int $site_id Optional. Only relevant on multi-network installs. 1079 * @return mixed Returns WP_Error object on failure, int $blog_id on success 1080 */ 849 1081 function wpmu_create_blog($domain, $path, $title, $user_id, $meta = '', $site_id = 1) { 850 1082 $domain = preg_replace( '/\s+/', '', sanitize_user( $domain, true ) ); 851 1083 … … 893 1125 return $blog_id; 894 1126 } 895 1127 1128 /** 1129 * Notifies the network admin that a new site has been activated. 1130 * 1131 * Filter 'newblog_notify_siteadmin' to change the content of 1132 * the notification email. 1133 * 1134 * @since MU 1135 * @uses switch_to_blog() 1136 * @uses restore_current_blog() 1137 * @uses wp_mail() 1138 * 1139 * @param int $blog_id The new site's ID. 1140 * @return bool 1141 */ 896 1142 function newblog_notify_siteadmin( $blog_id, $deprecated = '' ) { 897 1143 if ( get_site_option( 'registrationnotification' ) != 'yes' ) 898 1144 return false; … … 919 1165 return true; 920 1166 } 921 1167 1168 /** 1169 * Notifies the network admin that a new user has been activated. 1170 * 1171 * Filter 'newuser_notify_siteadmin' to change the content of 1172 * the notification email. 1173 * 1174 * @since MU 1175 * @uses wp_mail() 1176 * 1177 * @param int $user_id The new user's ID. 1178 * @return bool 1179 */ 922 1180 function newuser_notify_siteadmin( $user_id ) { 923 1181 if ( get_site_option( 'registrationnotification' ) != 'yes' ) 924 1182 return false; … … 941 1199 return true; 942 1200 } 943 1201 1202 /** 1203 * Check whether a blogname is already taken. 1204 * 1205 * Used during the new site registration process to ensure 1206 * that each blogname is unique. 1207 * 1208 * @since MU 1209 * @uses $wpdb 1210 * 1211 * @param string $domain The domain to be checked. 1212 * @param string $path The path to be checked. 1213 * @param int $site_id Optional. Relevant only on multi-network installs. 1214 * @return int $blog_id 1215 */ 944 1216 function domain_exists($domain, $path, $site_id = 1) { 945 1217 global $wpdb; 946 1218 return $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) ); 947 1219 } 948 1220 1221 /** 1222 * Store basic site info in the blogs table. 1223 * 1224 * This function creates a row in the wp_blogs table and returns 1225 * the new blog's ID. It is the first step in creating a new blog. 1226 * 1227 * @since MU 1228 * @uses $wpdb 1229 * @uses refresh_blog_details() 1230 * 1231 * @param string $domain The domain of the new site. 1232 * @param string $path The path of the new site. 1233 * @param int $site_id Unless you're running a multi-network install, be sure to set this value to 1. 1234 * @return int $blog_id The ID of the new row 1235 */ 949 1236 function insert_blog($domain, $path, $site_id) { 950 1237 global $wpdb; 951 1238 … … 960 1247 return $wpdb->insert_id; 961 1248 } 962 1249 963 // Install an empty blog. wpdb should already be switched. 1250 /** 1251 * Install an empty blog. 1252 * 1253 * Creates the new blog tables and options. If calling this function 1254 * directly, be sure to use switch_to_blog() first, so that $wpdb 1255 * points to the new blog. 1256 * 1257 * @since MU 1258 * @uses $wpdb 1259 * @uses make_db_current_silent() 1260 * @uses populate_roles() 1261 * 1262 * @param int $blog_id The value returned by insert_blog(). 1263 * @param string $blog_title The title of the new site. 1264 * @return none 1265 */ 964 1266 function install_blog($blog_id, $blog_title = '') { 965 1267 global $wpdb, $table_prefix, $wp_roles; 966 1268 $wpdb->suppress_errors(); … … 999 1301 $wpdb->suppress_errors( false ); 1000 1302 } 1001 1303 1002 // Deprecated, use wp_install_defaults() 1003 // should be switched already as $blog_id is ignored. 1304 /** 1305 * Set blog defaults. 1306 * 1307 * This function creates a row in the wp_blogs table. 1308 * 1309 * @since MU 1310 * @deprecated MU 1311 * @deprecated Use wp_install_defaults() 1312 * @uses wp_install_defaults() 1313 * 1314 * @param int $blog_id Ignored in this function. 1315 * @param int $user_id 1316 * @return none 1317 */ 1004 1318 function install_blog_defaults($blog_id, $user_id) { 1005 1319 global $wpdb; 1006 1320 … … 1013 1327 $wpdb->suppress_errors( false ); 1014 1328 } 1015 1329 1330 /** 1331 * Notify a user that her blog activation has been successful. 1332 * 1333 * Filter 'wpmu_welcome_notification' to disable or bypass. 1334 * 1335 * Filter 'update_welcome_email' and 'update_welcome_subject' to 1336 * modify the content and subject line of the notification email. 1337 * 1338 * @since MU 1339 * @uses wp_mail() 1340 * 1341 * @param int $blog_id 1342 * @param int $user_id 1343 * @param string $password 1344 * @param string $title The new blog's title 1345 * @param array $meta Optional. Not used in the default function, but is passed along to hooks for customization. 1346 * @return bool 1347 */ 1016 1348 function wpmu_welcome_notification($blog_id, $user_id, $password, $title, $meta = '') { 1017 1349 global $current_site; 1018 1350 … … 1063 1395 return true; 1064 1396 } 1065 1397 1398 /** 1399 * Notify a user that her account activation has been successful. 1400 * 1401 * Filter 'wpmu_welcome_user_notification' to disable or bypass. 1402 * 1403 * Filter 'update_welcome_user_email' and 'update_welcome_user_subject' to 1404 * modify the content and subject line of the notification email. 1405 * 1406 * @since MU 1407 * @uses wp_mail() 1408 * 1409 * @param int $user_id 1410 * @param string $password 1411 * @param array $meta Optional. Not used in the default function, but is passed along to hooks for customization. 1412 * @return bool 1413 */ 1066 1414 function wpmu_welcome_user_notification($user_id, $password, $meta = '') { 1067 1415 global $current_site; 1068 1416 … … 1096 1444 return true; 1097 1445 } 1098 1446 1447 /** 1448 * Get the current site info. 1449 * 1450 * Returns an object containing the ID, domain, path, and site_name 1451 * of the site being viewed. 1452 * 1453 * @since MU 1454 * 1455 * @return object $current_site 1456 */ 1099 1457 function get_current_site() { 1100 1458 global $current_site; 1101 1459 return $current_site; 1102 1460 } 1103 1461 1462 /** 1463 * Get a numeric user ID from either an email address or a login. 1464 * 1465 * @since MU 1466 * @uses is_email() 1467 * @uses get_user_by() 1468 * 1469 * @param string $string 1470 * @return int $user_id 1471 */ 1104 1472 function get_user_id_from_string( $string ) { 1105 1473 $user_id = 0; 1106 1474 if ( is_email( $string ) ) { … … 1118 1486 return $user_id; 1119 1487 } 1120 1488 1489 /** 1490 * Get a user's most recent post. 1491 * 1492 * Walks through each of a user's blogs to find the post with 1493 * the most recent post_date_gmt. 1494 * 1495 * @since MU 1496 * @uses $wpdb 1497 * @uses get_blogs_of_user() 1498 * 1499 * @param int $user_id 1500 * @return array $most_recent_post Contains the blog_id, post_id, post_date_gmt, and post_gmt_ts 1501 */ 1121 1502 function get_most_recent_post_of_user( $user_id ) { 1122 1503 global $wpdb; 1123 1504 … … 1150 1531 return $most_recent_post; 1151 1532 } 1152 1533 1153 /* Misc functions */ 1534 // Misc functions 1535 1536 /** 1537 * Get the size of a directory. 1538 * 1539 * A helper function that is used primarily to check whether 1540 * a blog has exceeded its allowed upload space. 1541 * 1542 * @since MU 1543 * @uses $wpdb 1544 * @uses recurse_dirsize() 1545 * 1546 * @param string $directory 1547 * @return int 1548 */ 1154 1549 function get_dirsize( $directory ) { 1155 1550 $dirsize = get_transient( 'dirsize_cache' ); 1156 1551 if ( is_array( $dirsize ) && isset( $dirsize[ $directory ][ 'size' ] ) ) … … 1165 1560 return $dirsize[ $directory ][ 'size' ]; 1166 1561 } 1167 1562 1563 /** 1564 * Get the size of a directory recursively. 1565 * 1566 * Used by get_dirsize() to get a directory's size when it contains 1567 * other directories. 1568 * 1569 * @since MU 1570 * 1571 * @param string $directory 1572 * @return int $size 1573 */ 1168 1574 function recurse_dirsize( $directory ) { 1169 1575 $size = 0; 1170 1576 … … 1192 1598 return $size; 1193 1599 } 1194 1600 1601 /** 1602 * Check whether a blog has used its allotted upload space. 1603 * 1604 * Used by get_dirsize() to get a directory's size when it contains 1605 * other directories. 1606 * 1607 * @since MU 1608 * @uses get_dirsize() 1609 * 1610 * @param bool $echo Optional. If $echo is set and the quota is exceeded, a warning message is echoed. Default is true. 1611 * @return int $size 1612 */ 1195 1613 function upload_is_user_over_quota( $echo = true ) { 1196 1614 if ( get_site_option( 'upload_space_check_disabled' ) ) 1197 1615 return false; … … 1212 1630 } 1213 1631 } 1214 1632 1633 /** 1634 * Check an array of MIME types against a whitelist. 1635 * 1636 * WordPress ships with a set of allowed upload filetypes, 1637 * which is defined in wp-includes/functions.php in 1638 * get_allowed_mime_types(). This function is used to filter 1639 * that list against the filetype whitelist provided by Multisite 1640 * Super Admins at wp-admin/network/settings.php. 1641 * 1642 * @since MU 1643 * @uses get_site_option() 1644 * 1645 * @param array $mimes 1646 * @return array $site_mimes 1647 */ 1215 1648 function check_upload_mimes( $mimes ) { 1216 1649 $site_exts = explode( ' ', get_site_option( 'upload_filetypes' ) ); 1217 1650 foreach ( $site_exts as $ext ) { … … 1223 1656 return $site_mimes; 1224 1657 } 1225 1658 1659 /** 1660 * Update a blog's post count. 1661 * 1662 * WordPress MS stores a blog's post count as an option so as 1663 * to avoid extraneous COUNTs when a blog's details are fetched 1664 * with get_blog_details(). This function is called when posts 1665 * are published to make sure the count stays current. 1666 * 1667 * @since MU 1668 * @uses $wpdb 1669 * 1670 * @return none 1671 */ 1226 1672 function update_posts_count( $deprecated = '' ) { 1227 1673 global $wpdb; 1228 1674 update_option( 'post_count', (int) $wpdb->get_var( "SELECT COUNT(ID) FROM {$wpdb->posts} WHERE post_status = 'publish' and post_type = 'post'" ) ); 1229 1675 } 1230 1676 1677 /** 1678 * Logs user registrations. 1679 * 1680 * @since MU 1681 * @uses $wpdb 1682 * 1683 * @param int $blog_id 1684 * @param int $user_id 1685 * @return none 1686 */ 1231 1687 function wpmu_log_new_registrations( $blog_id, $user_id ) { 1232 1688 global $wpdb; 1233 1689 $user = new WP_User( (int) $user_id ); 1234 1690 $wpdb->insert( $wpdb->registration_log, array('email' => $user->user_email, 'IP' => preg_replace( '/[^0-9., ]/', '',$_SERVER['REMOTE_ADDR'] ), 'blog_id' => $blog_id, 'date_registered' => current_time('mysql')) ); 1235 1691 } 1236 1692 1693 /** 1694 * Get the remaining upload space for this blog. 1695 * 1696 * @since MU 1697 * @uses upload_is_user_over_quota() 1698 * @uses get_space_allowed() 1699 * @uses get_dirsize() 1700 * 1701 * @param int $size 1702 * @return int $size 1703 */ 1237 1704 function fix_import_form_size( $size ) { 1238 1705 if ( upload_is_user_over_quota( false ) == true ) 1239 1706 return 0; … … 1315 1782 return $global_id; 1316 1783 } 1317 1784 1785 /** 1786 * Ensure that the current site's domain is listed in the allowed redirect host list. 1787 * 1788 * @see wp_validate_redirect() 1789 * 1790 * @since MU 1791 * 1792 * @return array The current site's domain 1793 */ 1318 1794 function redirect_this_site( $deprecated = '' ) { 1319 1795 global $current_site; 1320 1796 return array( $current_site->domain ); 1321 1797 } 1322 1798 1799 /** 1800 * Check whether an upload is too big. 1801 * 1802 * @since MU 1803 * 1804 * @param array $upload 1805 * @return mixed If the upload is under the size limit, $upload is returned. Otherwise returns an error message. 1806 */ 1323 1807 function upload_is_file_too_big( $upload ) { 1324 1808 if ( is_array( $upload ) == false || defined( 'WP_IMPORTING' ) ) 1325 1809 return $upload; … … 1330 1814 return $upload; 1331 1815 } 1332 1816 1817 /** 1818 * Add a nonce field to the signup page. 1819 * 1820 * @since MU 1821 * @uses wp_nonce_field() 1822 * 1823 * @return none 1824 */ 1333 1825 function signup_nonce_fields() { 1334 1826 $id = mt_rand(); 1335 1827 echo "<input type='hidden' name='signup_form_id' value='{$id}' />"; 1336 1828 wp_nonce_field('signup_form_' . $id, '_signup_form', false); 1337 1829 } 1338 1830 1831 /** 1832 * Process the signup nonce created in signup_nonce_fields(). 1833 * 1834 * @since MU 1835 * @uses wp_create_nonce() 1836 * 1837 * @param array $result 1838 * @return array $result 1839 */ 1339 1840 function signup_nonce_check( $result ) { 1340 1841 if ( !strpos( $_SERVER[ 'PHP_SELF' ], 'wp-signup.php' ) ) 1341 1842 return $result; … … 1346 1847 return $result; 1347 1848 } 1348 1849 1850 /** 1851 * Correct 404 redirects when NOBLOGREDIRECT is defined. 1852 * 1853 * @since MU 1854 * @uses is_main_site() 1855 * @uses is_404() 1856 * @uses network_home_url() 1857 * @uses wp_redirect() 1858 * 1859 * @return none 1860 */ 1349 1861 function maybe_redirect_404() { 1350 1862 global $current_site; 1351 1863 if ( is_main_site() && is_404() && defined( 'NOBLOGREDIRECT' ) && ( $destination = apply_filters( 'blog_redirect_404', NOBLOGREDIRECT ) ) ) { … … 1356 1868 } 1357 1869 } 1358 1870 1871 /** 1872 * Add a new user to a blog by visiting /newbloguser/username/. 1873 * 1874 * This will only work when the user's details are saved as an option 1875 * keyed as 'new_user_x', where 'x' is the username of the user to be 1876 * added, as when a user is invited through the regular WP Add User interface. 1877 * 1878 * @since MU 1879 * @uses add_existing_user_to_blog() 1880 * 1881 * @return none 1882 */ 1359 1883 function maybe_add_existing_user_to_blog() { 1360 1884 if ( false === strpos( $_SERVER[ 'REQUEST_URI' ], '/newbloguser/' ) ) 1361 1885 return false; … … 1376 1900 wp_die( sprintf(__('You have been added to this site. Please visit the <a href="%s">homepage</a> or <a href="%s">login</a> using your username and password.'), site_url(), admin_url() ), __('Success') ); 1377 1901 } 1378 1902 1903 /** 1904 * Add a user to a blog based on details from maybe_add_existing_user_to_blog(). 1905 * 1906 * @since MU 1907 * @uses add_user_to_blog() 1908 * 1909 * @param array $details 1910 * @return none 1911 */ 1379 1912 function add_existing_user_to_blog( $details = false ) { 1380 1913 global $blog_id; 1381 1914 … … 1386 1919 return $result; 1387 1920 } 1388 1921 1922 /** 1923 * Add a newly created user to the appropriate blog 1924 * 1925 * @since MU 1926 * @uses remove_user_from_blog() 1927 * @uses add_user_to_blog() 1928 * @uses update_user_meta() 1929 * 1930 * @param int $user_id 1931 * @param string $email 1932 * @param array $meta 1933 * @return none 1934 */ 1389 1935 function add_new_user_to_blog( $user_id, $email, $meta ) { 1390 1936 global $current_site; 1391 1937 if ( $meta[ 'add_to_blog' ] ) { … … 1397 1943 } 1398 1944 } 1399 1945 1946 /** 1947 * Correct From host on outgoing mail to match the site domain 1948 * 1949 * @since MU 1950 * 1951 * @return none 1952 */ 1400 1953 function fix_phpmailer_messageid( $phpmailer ) { 1401 1954 global $current_site; 1402 1955 $phpmailer->Hostname = $current_site->domain; 1403 1956 } 1404 1957 1958 /** 1959 * Check to see whether a user is marked as a spammer, based on username 1960 * 1961 * @since MU 1962 * @uses get_current_user_id() 1963 * @uses get_user_id_from_string() 1964 * 1965 * @param string $username 1966 * @return bool 1967 */ 1405 1968 function is_user_spammy( $username = 0 ) { 1406 1969 if ( $username == 0 ) { 1407 1970 $user_id = get_current_user_id(); … … 1413 1976 return ( isset( $u->spam ) && $u->spam == 1 ); 1414 1977 } 1415 1978 1979 /** 1980 * Update this blog's 'public' setting in the global blogs table. 1981 * 1982 * Public blogs have a setting of 1, private blogs are 0. 1983 * 1984 * @since MU 1985 * @uses update_blog_status() 1986 * 1987 * @param int $old_value 1988 * @param int $value The new public value 1989 * @return bool 1990 */ 1416 1991 function update_blog_public( $old_value, $value ) { 1417 1992 global $wpdb; 1418 1993 do_action('update_blog_public'); … … 1420 1995 } 1421 1996 add_action('update_option_blog_public', 'update_blog_public', 10, 2); 1422 1997 1998 /** 1999 * Get the "dashboard blog", the blog where users without a blog edit their profile data. 2000 * 2001 * @since MU 2002 * @uses get_blog_details() 2003 * 2004 * @return int 2005 */ 1423 2006 function get_dashboard_blog() { 1424 2007 if ( $blog = get_site_option( 'dashboard_blog' ) ) 1425 2008 return get_blog_details( $blog ); … … 1427 2010 return get_blog_details( $GLOBALS['current_site']->blog_id ); 1428 2011 } 1429 2012 2013 /** 2014 * Check whether a usermeta key has to do with the current blog. 2015 * 2016 * @since MU 2017 * @uses wp_get_current_user() 2018 * 2019 * @param string $key 2020 * @param int $user_id Optional. Defaults to current user. 2021 * @param int $blog_id Optional. Defaults to current blog. 2022 * @return bool 2023 */ 1430 2024 function is_user_option_local( $key, $user_id = 0, $blog_id = 0 ) { 1431 2025 global $wpdb; 1432 2026 … … 1444 2038 return false; 1445 2039 } 1446 2040 2041 /** 2042 * Check whether users can self-register, based on Network settings. 2043 * 2044 * @since MU 2045 * 2046 * @return bool 2047 */ 1447 2048 function users_can_register_signup_filter() { 1448 2049 $registration = get_site_option('registration'); 1449 2050 if ( $registration == 'all' || $registration == 'user' ) … … 1453 2054 } 1454 2055 add_filter('option_users_can_register', 'users_can_register_signup_filter'); 1455 2056 2057 /** 2058 * Ensure that the welcome message is not empty. Currently unused. 2059 * 2060 * @since MU 2061 * 2062 * @param string $text 2063 * @return string $text 2064 */ 1456 2065 function welcome_user_msg_filter( $text ) { 1457 2066 if ( !$text ) { 1458 2067 return __( 'Dear User, … … 1540 2149 update_site_option( 'user_count', $count ); 1541 2150 } 1542 2151 1543 ?> 2152 ?> 2153 No newline at end of file