Ticket #14953: 14953-3.diff
File 14953-3.diff, 26.3 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 * @uses get_site_option() 485 * 486 * @param string $user_email The email provided by the user at registration. 487 * @return bool Returns true when the email address is banned. 488 */ 450 489 function is_email_address_unsafe( $user_email ) { 451 490 $banned_names = get_site_option( 'banned_email_domains' ); 452 491 if ($banned_names && !is_array( $banned_names )) … … 470 509 return false; 471 510 } 472 511 512 /** 513 * Processes new user registrations. 514 * 515 * Checks the data provided by the user during signup. Verifies 516 * the validity and uniqueness of user names and user email addresses, 517 * and checks email addresses against admin-provided domain 518 * whitelists and blacklists. 519 * 520 * The hook 'wpmu_validate_user_signup' provides an easy way 521 * to modify the signup process. The value $result, which is passed 522 * to the hook, contains both the user-provided info and the error 523 * messages created by the function. 'wpmu_validate_user_signup' allows 524 * you to process the data in any way you'd like, and unset the 525 * relevant errors if necessary. 526 * 527 * @since MU 528 * @uses sanitize_user() 529 * @uses sanitize_email() 530 * @uses get_site_option() 531 * @uses is_email_address_unsafe() 532 * @uses username_exists() 533 * @uses email_exists() 534 * @uses $wpdb 535 * 536 * @param string $user_name The login name provided by the user. 537 * @param string $user_email The email provided by the user. 538 * @return array $result Contains username, email, and error messages. 539 */ 473 540 function wpmu_validate_user_signup($user_name, $user_email) { 474 541 global $wpdb; 475 542 … … 562 629 return apply_filters('wpmu_validate_user_signup', $result); 563 630 } 564 631 632 /** 633 * Processes new site registrations. 634 * 635 * Checks the data provided by the user during blog signup. Verifies 636 * the validity and uniqueness of blog paths and domains. 637 * 638 * This function prevents the current user from registering a new site 639 * with a blogname equivalent to another user's login name. Passing the 640 * $user parameter to the function, where $user is the other user, is 641 * effectively an override of this limitation. 642 * 643 * Filter 'wpmu_validate_blog_signup' if you want to modify 644 * the way that WordPress validates new site signups. 645 * 646 * @since MU 647 * @uses is_subdomain_install() 648 * @uses add_site_option() 649 * @uses get_site_option() 650 * @uses domain_exists() 651 * @uses username_exists() 652 * @uses $wpdb 653 * 654 * @param string $blogname The blog name provided by the user. Must be unique. 655 * @param string $blog_title The blog title provided by the user. 656 * @return array $result Contains the new site data and error messages. 657 */ 565 658 function wpmu_validate_blog_signup($blogname, $blog_title, $user = '') { 566 659 global $wpdb, $domain, $base, $current_site; 567 660 … … 645 738 return apply_filters('wpmu_validate_blog_signup', $result); 646 739 } 647 740 648 // Record signup information for future activation. wpmu_validate_signup() should be run 649 // on the inputs before calling wpmu_signup(). 741 /** 742 * Record site signup information for future activation. 743 * 744 * @since MU 745 * @uses wpmu_signup_blog_notification() 746 * @uses $wpdb 747 * 748 * @param string $domain The requested domain. 749 * @param string $path The requested path. 750 * @param string $title The requested site title. 751 * @param string $user The user's requested login name. 752 * @param string $user_email The user's email address. 753 * @param array $meta By default, contains the requested privacy setting and lang_id. 754 * @return none 755 */ 650 756 function wpmu_signup_blog($domain, $path, $title, $user, $user_email, $meta = '') { 651 757 global $wpdb; 652 758 … … 670 776 wpmu_signup_blog_notification($domain, $path, $title, $user, $user_email, $key, $meta); 671 777 } 672 778 779 /** 780 * Record user signup information for future activation. 781 * 782 * This function is used when user registration is open but 783 * new site registration is not. 784 * 785 * @since MU 786 * @uses wpmu_signup_user_notification() 787 * @uses $wpdb 788 * 789 * @param string $user The user's requested login name. 790 * @param string $user_email The user's email address. 791 * @param array $meta By default, this is an empty array. 792 * @return none 793 */ 673 794 function wpmu_signup_user($user, $user_email, $meta = '') { 674 795 global $wpdb; 675 796 … … 693 814 wpmu_signup_user_notification($user, $user_email, $key, $meta); 694 815 } 695 816 696 // Notify user of signup success. 817 /** 818 * Notify user of signup success. 819 * 820 * This is the notification function used when site registration 821 * is enabled. 822 * 823 * Filter 'wpmu_signup_blog_notification' to bypass this function or 824 * replace it with your own notification behavior. 825 * 826 * Filter 'wpmu_signup_blog_notification_email' and 827 * 'wpmu_signup_blog_notification_email' to change the content 828 * and subject line of the email sent to newly registered users. 829 * 830 * @since MU 831 * @uses is_subdomain_install() 832 * @uses get_site_option() 833 * @uses wp_mail() 834 * 835 * @param string $domain The new blog domain. 836 * @param string $path The new blog path. 837 * @param string $title The site title. 838 * @param string $user The user's login name. 839 * @param string $user_email The user's email address. 840 * @param array $meta By default, contains the requested privacy setting and lang_id. 841 * @param string $key The activation key created in wpmu_signup_blog() 842 * @return bool 843 */ 697 844 function wpmu_signup_blog_notification($domain, $path, $title, $user, $user_email, $key, $meta = '') { 698 845 global $current_site; 699 846 … … 734 881 return true; 735 882 } 736 883 884 /** 885 * Notify user of signup success. 886 * 887 * This is the notification function used when no new site has 888 * been requested. 889 * 890 * Filter 'wpmu_signup_user_notification' to bypass this function or 891 * replace it with your own notification behavior. 892 * 893 * Filter 'wpmu_signup_user_notification_email' and 894 * 'wpmu_signup_user_notification_subject' to change the content 895 * and subject line of the email sent to newly registered users. 896 * 897 * @since MU 898 * @uses get_site_option() 899 * @uses site_url() 900 * @uses wp_mail() 901 * 902 * @param string $user The user's login name. 903 * @param string $user_email The user's email address. 904 * @param array $meta By default, an empty array. 905 * @param string $key The activation key created in wpmu_signup_user() 906 * @return bool 907 */ 737 908 function wpmu_signup_user_notification($user, $user_email, $key, $meta = '') { 738 909 if ( !apply_filters('wpmu_signup_user_notification', $user, $user_email, $key, $meta) ) 739 910 return false; … … 765 936 return true; 766 937 } 767 938 939 /** 940 * Activate a signup. 941 * 942 * Hook to 'wpmu_activate_user' or 'wpmu_activate_blog' for events 943 * that should happen only when users or sites are self-created (since 944 * those actions are not called when users and sites are created 945 * by a Super Admin). 946 * 947 * @since MU 948 * @uses $wpdb 949 * @uses wp_generate_password() 950 * @uses wpmu_welcome_user_notification() 951 * @uses get_site_option() 952 * @uses add_user_to_blog() 953 * @uses add_new_user_to_blog() 954 * @uses wpmu_create_user() 955 * @uses wpmu_create_blog() 956 * @uses is_wp_error() 957 * @uses wpmu_welcome_notification() 958 * 959 * @param string $key The activation key provided to the user. 960 * @return array An array containing information about the activated user and/or blog 961 */ 768 962 function wpmu_activate_signup($key) { 769 963 global $wpdb, $current_site; 770 964 … … 830 1024 return array('blog_id' => $blog_id, 'user_id' => $user_id, 'password' => $password, 'title' => $signup->title, 'meta' => $meta); 831 1025 } 832 1026 1027 /** 1028 * Create a user. 1029 * 1030 * This function runs when a user self-registers as well as when 1031 * a Super Admin creates a new user. Hook to 'wpmu_new_user' for events 1032 * that should affect all new users, but only on Multisite (otherwise 1033 * use 'user_register'). 1034 * 1035 * @since MU 1036 * @uses wp_create_user() 1037 * @uses is_wp_error() 1038 * @uses delete_user_option() 1039 * 1040 * @param string $user_name The new user's login name. 1041 * @param string $password The new user's password. 1042 * @param string $email The new user's email address. 1043 * @return mixed Returns false on failure, or int $user_id on success 1044 */ 833 1045 function wpmu_create_user( $user_name, $password, $email) { 834 1046 $user_name = preg_replace( '/\s+/', '', sanitize_user( $user_name, true ) ); 835 1047 … … 846 1058 return $user_id; 847 1059 } 848 1060 1061 /** 1062 * Create a site. 1063 * 1064 * This function runs when a user self-registers a new site as well 1065 * as when a Super Admin creates a new site. Hook to 'wpmu_new_blog' 1066 * for events that should affect all new sites. 1067 * 1068 * On subdirectory installs, $domain is the same as the main site's 1069 * domain, and the path is the subdirectory name (eg 'example.com' 1070 * and '/blog1/'). On subdomain installs, $domain is the new subdomain + 1071 * root domain (eg 'blog1.example.com'), and $path is '/'. 1072 * 1073 * @since MU 1074 * @uses is_subdomain_install() 1075 * @uses domain_exists() 1076 * @uses insert_blog() 1077 * @uses switch_to_blog() 1078 * @uses wp_install_defaults() 1079 * @uses add_user_to_blog() 1080 * @uses update_blog_status() 1081 * @uses restore_current_blog() 1082 * 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. 1089 * @return mixed Returns WP_Error object on failure, int $blog_id on success 1090 */ 849 1091 function wpmu_create_blog($domain, $path, $title, $user_id, $meta = '', $site_id = 1) { 850 1092 $domain = preg_replace( '/\s+/', '', sanitize_user( $domain, true ) ); 851 1093 … … 893 1135 return $blog_id; 894 1136 } 895 1137 1138 /** 1139 * Notifies the network admin that a new site has been activated. 1140 * 1141 * Filter 'newblog_notify_siteadmin' to change the content of 1142 * the notification email. 1143 * 1144 * @since MU 1145 * @uses switch_to_blog() 1146 * @uses site_url() 1147 * @uses get_site_option() 1148 * @uses network_admin_url() 1149 * @uses restore_current_blog() 1150 * @uses wp_mail() 1151 * 1152 * @param int $blog_id The new site's ID. 1153 * @return bool 1154 */ 896 1155 function newblog_notify_siteadmin( $blog_id, $deprecated = '' ) { 897 1156 if ( get_site_option( 'registrationnotification' ) != 'yes' ) 898 1157 return false; … … 919 1178 return true; 920 1179 } 921 1180 1181 /** 1182 * Notifies the network admin that a new user has been activated. 1183 * 1184 * Filter 'newuser_notify_siteadmin' to change the content of 1185 * the notification email. 1186 * 1187 * @since MU 1188 * @uses get_site_option() 1189 * @uses network_admin_url() 1190 * @uses wp_mail() 1191 * 1192 * @param int $user_id The new user's ID. 1193 * @return bool 1194 */ 922 1195 function newuser_notify_siteadmin( $user_id ) { 923 1196 if ( get_site_option( 'registrationnotification' ) != 'yes' ) 924 1197 return false; … … 941 1214 return true; 942 1215 } 943 1216 1217 /** 1218 * Check whether a blogname is already taken. 1219 * 1220 * Used during the new site registration process to ensure 1221 * that each blogname is unique. 1222 * 1223 * @since MU 1224 * @uses $wpdb 1225 * 1226 * @param string $domain The domain to be checked. 1227 * @param string $path The path to be checked. 1228 * @param int $site_id Optional. Relevant only on multi-network installs. 1229 * @return int $blog_id 1230 */ 944 1231 function domain_exists($domain, $path, $site_id = 1) { 945 1232 global $wpdb; 946 1233 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 1234 } 948 1235 1236 /** 1237 * Store basic site info in the blogs table. 1238 * 1239 * This function creates a row in the wp_blogs table and returns 1240 * the new blog's ID. It is the first step in creating a new blog. 1241 * 1242 * @since MU 1243 * @uses $wpdb 1244 * @uses trailingslashit() 1245 * @uses refresh_blog_details() 1246 * 1247 * @param string $domain The domain of the new site. 1248 * @param string $path The path of the new site. 1249 * @param int $site_id Unless you're running a multi-network install, be sure to set this value to 1. 1250 * @return int $blog_id The ID of the new row 1251 */ 949 1252 function insert_blog($domain, $path, $site_id) { 950 1253 global $wpdb; 951 1254 … … 960 1263 return $wpdb->insert_id; 961 1264 } 962 1265 963 // Install an empty blog. wpdb should already be switched. 1266 /** 1267 * Install an empty blog. 1268 * 1269 * Creates the new blog tables and options. If calling this function 1270 * directly, be sure to use switch_to_blog() first, so that $wpdb 1271 * points to the new blog. 1272 * 1273 * @since MU 1274 * @uses $wpdb 1275 * @uses get_blogaddress_by_id() 1276 * @uses make_db_current_silent() 1277 * @uses populate_roles() 1278 * @uses update_option() 1279 * 1280 * @param int $blog_id The value returned by insert_blog(). 1281 * @param string $blog_title The title of the new site. 1282 * @return none 1283 */ 964 1284 function install_blog($blog_id, $blog_title = '') { 965 1285 global $wpdb, $table_prefix, $wp_roles; 966 1286 $wpdb->suppress_errors(); … … 999 1319 $wpdb->suppress_errors( false ); 1000 1320 } 1001 1321 1002 // Deprecated, use wp_install_defaults() 1003 // should be switched already as $blog_id is ignored. 1322 /** 1323 * Set blog defaults. 1324 * 1325 * This function creates a row in the wp_blogs table. 1326 * 1327 * @since MU 1328 * @deprecated MU 1329 * @deprecated Use wp_install_defaults() 1330 * @uses wp_install_defaults() 1331 * 1332 * @param int $blog_id Ignored in this function. 1333 * @param int $user_id 1334 * @return none 1335 */ 1004 1336 function install_blog_defaults($blog_id, $user_id) { 1005 1337 global $wpdb; 1006 1338 … … 1013 1345 $wpdb->suppress_errors( false ); 1014 1346 } 1015 1347 1348 /** 1349 * Notify a user that her blog activation has been successful. 1350 * 1351 * Filter 'wpmu_welcome_notification' to disable or bypass. 1352 * 1353 * Filter 'update_welcome_email' and 'update_welcome_subject' to 1354 * modify the content and subject line of the notification email. 1355 * 1356 * @since MU 1357 * @uses get_site_option() 1358 * @uses get_blogaddress_by_id() 1359 * @uses wp_mail() 1360 * 1361 * @param int $blog_id 1362 * @param int $user_id 1363 * @param string $password 1364 * @param string $title The new blog's title 1365 * @param array $meta Optional. Not used in the default function, but is passed along to hooks for customization. 1366 * @return bool 1367 */ 1016 1368 function wpmu_welcome_notification($blog_id, $user_id, $password, $title, $meta = '') { 1017 1369 global $current_site; 1018 1370 … … 1063 1415 return true; 1064 1416 } 1065 1417 1418 /** 1419 * Notify a user that her account activation has been successful. 1420 * 1421 * Filter 'wpmu_welcome_user_notification' to disable or bypass. 1422 * 1423 * Filter 'update_welcome_user_email' and 'update_welcome_user_subject' to 1424 * modify the content and subject line of the notification email. 1425 * 1426 * @since MU 1427 * @uses get_site_option() 1428 * @uses wp_mail() 1429 * 1430 * @param int $user_id 1431 * @param string $password 1432 * @param array $meta Optional. Not used in the default function, but is passed along to hooks for customization. 1433 * @return bool 1434 */ 1066 1435 function wpmu_welcome_user_notification($user_id, $password, $meta = '') { 1067 1436 global $current_site; 1068 1437 … … 1096 1465 return true; 1097 1466 } 1098 1467 1468 /** 1469 * Get the current site info. 1470 * 1471 * Returns an object containing the ID, domain, path, and site_name 1472 * of the site being viewed. 1473 * 1474 * @since MU 1475 * 1476 * @return object $current_site 1477 */ 1099 1478 function get_current_site() { 1100 1479 global $current_site; 1101 1480 return $current_site; 1102 1481 } 1103 1482 1483 /** 1484 * Get a numeric user ID from either an email address or a login. 1485 * 1486 * @since MU 1487 * @uses is_email() 1488 * @uses get_user_by() 1489 * 1490 * @param string $string 1491 * @return int $user_id 1492 */ 1104 1493 function get_user_id_from_string( $string ) { 1105 1494 $user_id = 0; 1106 1495 if ( is_email( $string ) ) { … … 1118 1507 return $user_id; 1119 1508 } 1120 1509 1510 /** 1511 * Get a user's most recent post. 1512 * 1513 * Walks through each of a user's blogs to find the post with 1514 * the most recent post_date_gmt. 1515 * 1516 * @since MU 1517 * @uses $wpdb 1518 * @uses get_blogs_of_user() 1519 * 1520 * @param int $user_id 1521 * @return array $most_recent_post Contains the blog_id, post_id, post_date_gmt, and post_gmt_ts 1522 */ 1121 1523 function get_most_recent_post_of_user( $user_id ) { 1122 1524 global $wpdb; 1123 1525 … … 1150 1552 return $most_recent_post; 1151 1553 } 1152 1554 1153 /* Misc functions */ 1555 // Misc functions 1556 1557 /** 1558 * Get the size of a directory. 1559 * 1560 * A helper function that is used primarily to check whether 1561 * a blog has exceeded its allowed upload space. 1562 * 1563 * @since MU 1564 * @uses $wpdb 1565 * @uses get_transient() 1566 * @uses recurse_dirsize() 1567 * @uses set_transient() 1568 * 1569 * @param string $directory 1570 * @return int 1571 */ 1154 1572 function get_dirsize( $directory ) { 1155 1573 $dirsize = get_transient( 'dirsize_cache' ); 1156 1574 if ( is_array( $dirsize ) && isset( $dirsize[ $directory ][ 'size' ] ) ) … … 1165 1583 return $dirsize[ $directory ][ 'size' ]; 1166 1584 } 1167 1585 1586 /** 1587 * Get the size of a directory recursively. 1588 * 1589 * Used by get_dirsize() to get a directory's size when it contains 1590 * other directories. 1591 * 1592 * @since MU 1593 * 1594 * @param string $directory 1595 * @return int $size 1596 */ 1168 1597 function recurse_dirsize( $directory ) { 1169 1598 $size = 0; 1170 1599 … … 1192 1621 return $size; 1193 1622 } 1194 1623 1624 /** 1625 * Check whether a blog has used its allotted upload space. 1626 * 1627 * Used by get_dirsize() to get a directory's size when it contains 1628 * other directories. 1629 * 1630 * @since MU 1631 * @uses get_site_option() 1632 * @uses get_dirsize() 1633 * 1634 * @param bool $echo Optional. If $echo is set and the quota is exceeded, a warning message is echoed. Default is true. 1635 * @return int $size 1636 */ 1195 1637 function upload_is_user_over_quota( $echo = true ) { 1196 1638 if ( get_site_option( 'upload_space_check_disabled' ) ) 1197 1639 return false; … … 1212 1654 } 1213 1655 } 1214 1656 1657 /** 1658 * Check an array of MIME types against a whitelist. 1659 * 1660 * WordPress ships with a set of allowed upload filetypes, 1661 * which is defined in wp-includes/functions.php in 1662 * get_allowed_mime_types(). This function is used to filter 1663 * that list against the filetype whitelist provided by Multisite 1664 * Super Admins at wp-admin/network/settings.php. 1665 * 1666 * @since MU 1667 * @uses get_site_option() 1668 * 1669 * @param array $mimes 1670 * @return array $site_mimes 1671 */ 1215 1672 function check_upload_mimes( $mimes ) { 1216 1673 $site_exts = explode( ' ', get_site_option( 'upload_filetypes' ) ); 1217 1674 foreach ( $site_exts as $ext ) { … … 1223 1680 return $site_mimes; 1224 1681 } 1225 1682 1683 /** 1684 * Update a blog's post count. 1685 * 1686 * WordPress MS stores a blog's post count as an option so as 1687 * to avoid extraneous COUNTs when a blog's details are fetched 1688 * with get_blog_details(). This function is called when posts 1689 * are published to make sure the count stays current. 1690 * 1691 * @since MU 1692 * @uses $wpdb 1693 * @uses update_option() 1694 * 1695 * @return none 1696 */ 1226 1697 function update_posts_count( $deprecated = '' ) { 1227 1698 global $wpdb; 1228 1699 update_option( 'post_count', (int) $wpdb->get_var( "SELECT COUNT(ID) FROM {$wpdb->posts} WHERE post_status = 'publish' and post_type = 'post'" ) ); 1229 1700 } 1230 1701 1702 /** 1703 * Logs user registrations. 1704 * 1705 * @since MU 1706 * @uses $wpdb 1707 * 1708 * @param int $blog_id 1709 * @param int $user_id 1710 * @return none 1711 */ 1231 1712 function wpmu_log_new_registrations( $blog_id, $user_id ) { 1232 1713 global $wpdb; 1233 1714 $user = new WP_User( (int) $user_id ); 1234 1715 $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 1716 } 1236 1717 1718 /** 1719 * Get the remaining upload space for this blog. 1720 * 1721 * @since MU 1722 * @uses upload_is_user_over_quota() 1723 * @uses get_space_allowed() 1724 * @uses get_dirsize() 1725 * 1726 * @param int $size 1727 * @return int $size 1728 */ 1237 1729 function fix_import_form_size( $size ) { 1238 1730 if ( upload_is_user_over_quota( false ) == true ) 1239 1731 return 0; … … 1315 1807 return $global_id; 1316 1808 } 1317 1809 1810 /** 1811 * Ensure that the current site's domain is listed in the allowed redirect host list. 1812 * 1813 * @see wp_validate_redirect() 1814 * 1815 * @since MU 1816 * 1817 * @return array The current site's domain 1818 */ 1318 1819 function redirect_this_site( $deprecated = '' ) { 1319 1820 global $current_site; 1320 1821 return array( $current_site->domain ); 1321 1822 } 1322 1823 1824 /** 1825 * Check whether an upload is too big. 1826 * 1827 * @since MU 1828 * @uses get_site_option() 1829 * 1830 * @param array $upload 1831 * @return mixed If the upload is under the size limit, $upload is returned. Otherwise returns an error message. 1832 */ 1323 1833 function upload_is_file_too_big( $upload ) { 1324 1834 if ( is_array( $upload ) == false || defined( 'WP_IMPORTING' ) ) 1325 1835 return $upload; … … 1330 1840 return $upload; 1331 1841 } 1332 1842 1843 /** 1844 * Add a nonce field to the signup page. 1845 * 1846 * @since MU 1847 * @uses wp_nonce_field() 1848 * 1849 * @return none 1850 */ 1333 1851 function signup_nonce_fields() { 1334 1852 $id = mt_rand(); 1335 1853 echo "<input type='hidden' name='signup_form_id' value='{$id}' />"; 1336 1854 wp_nonce_field('signup_form_' . $id, '_signup_form', false); 1337 1855 } 1338 1856 1857 /** 1858 * Process the signup nonce created in signup_nonce_fields(). 1859 * 1860 * @since MU 1861 * @uses wp_create_nonce() 1862 * 1863 * @param array $result 1864 * @return array $result 1865 */ 1339 1866 function signup_nonce_check( $result ) { 1340 1867 if ( !strpos( $_SERVER[ 'PHP_SELF' ], 'wp-signup.php' ) ) 1341 1868 return $result; … … 1346 1873 return $result; 1347 1874 } 1348 1875 1876 /** 1877 * Correct 404 redirects when NOBLOGREDIRECT is defined. 1878 * 1879 * @since MU 1880 * @uses is_main_site() 1881 * @uses is_404() 1882 * @uses network_home_url() 1883 * @uses wp_redirect() 1884 * 1885 * @return none 1886 */ 1349 1887 function maybe_redirect_404() { 1350 1888 global $current_site; 1351 1889 if ( is_main_site() && is_404() && defined( 'NOBLOGREDIRECT' ) && ( $destination = apply_filters( 'blog_redirect_404', NOBLOGREDIRECT ) ) ) { … … 1356 1894 } 1357 1895 } 1358 1896 1897 /** 1898 * Add a new user to a blog by visiting /newbloguser/username/. 1899 * 1900 * This will only work when the user's details are saved as an option 1901 * keyed as 'new_user_x', where 'x' is the username of the user to be 1902 * added, as when a user is invited through the regular WP Add User interface. 1903 * 1904 * @since MU 1905 * @uses get_option() 1906 * @uses add_existing_user_to_blog() 1907 * @uses is_wp_error() 1908 * @uses wp_die() 1909 * 1910 * @return none 1911 */ 1359 1912 function maybe_add_existing_user_to_blog() { 1360 1913 if ( false === strpos( $_SERVER[ 'REQUEST_URI' ], '/newbloguser/' ) ) 1361 1914 return false; … … 1376 1929 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 1930 } 1378 1931 1932 /** 1933 * Add a user to a blog based on details from maybe_add_existing_user_to_blog(). 1934 * 1935 * @since MU 1936 * @uses add_user_to_blog() 1937 * 1938 * @param array $details 1939 * @return none 1940 */ 1379 1941 function add_existing_user_to_blog( $details = false ) { 1380 1942 global $blog_id; 1381 1943 … … 1386 1948 return $result; 1387 1949 } 1388 1950 1951 /** 1952 * Add a newly created user to the appropriate blog 1953 * 1954 * @since MU 1955 * @uses remove_user_from_blog() 1956 * @uses add_user_to_blog() 1957 * @uses update_user_meta() 1958 * 1959 * @param int $user_id 1960 * @param string $email 1961 * @param array $meta 1962 * @return none 1963 */ 1389 1964 function add_new_user_to_blog( $user_id, $email, $meta ) { 1390 1965 global $current_site; 1391 1966 if ( $meta[ 'add_to_blog' ] ) { … … 1397 1972 } 1398 1973 } 1399 1974 1975 /** 1976 * Correct From host on outgoing mail to match the site domain 1977 * 1978 * @since MU 1979 * 1980 * @return none 1981 */ 1400 1982 function fix_phpmailer_messageid( $phpmailer ) { 1401 1983 global $current_site; 1402 1984 $phpmailer->Hostname = $current_site->domain; 1403 1985 } 1404 1986 1987 /** 1988 * Check to see whether a user is marked as a spammer, based on username 1989 * 1990 * @since MU 1991 * @uses get_current_user_id() 1992 * @uses get_user_id_from_string() 1993 * 1994 * @param string $username 1995 * @return bool 1996 */ 1405 1997 function is_user_spammy( $username = 0 ) { 1406 1998 if ( $username == 0 ) { 1407 1999 $user_id = get_current_user_id(); … … 1413 2005 return ( isset( $u->spam ) && $u->spam == 1 ); 1414 2006 } 1415 2007 2008 /** 2009 * Update this blog's 'public' setting in the global blogs table. 2010 * 2011 * Public blogs have a setting of 1, private blogs are 0. 2012 * 2013 * @since MU 2014 * @uses update_blog_status() 2015 * 2016 * @param int $old_value 2017 * @param int $value The new public value 2018 * @return bool 2019 */ 1416 2020 function update_blog_public( $old_value, $value ) { 1417 2021 global $wpdb; 1418 2022 do_action('update_blog_public'); … … 1420 2024 } 1421 2025 add_action('update_option_blog_public', 'update_blog_public', 10, 2); 1422 2026 2027 /** 2028 * Get the "dashboard blog", the blog where users without a blog edit their profile data. 2029 * 2030 * @since MU 2031 * @uses get_site_option() 2032 * @uses get_blog_details() 2033 * 2034 * @return int 2035 */ 1423 2036 function get_dashboard_blog() { 1424 2037 if ( $blog = get_site_option( 'dashboard_blog' ) ) 1425 2038 return get_blog_details( $blog ); … … 1427 2040 return get_blog_details( $GLOBALS['current_site']->blog_id ); 1428 2041 } 1429 2042 2043 /** 2044 * Check whether a usermeta key has to do with the current blog. 2045 * 2046 * @since MU 2047 * @uses wp_get_current_user() 2048 * 2049 * @param string $key 2050 * @param int $user_id Optional. Defaults to current user. 2051 * @param int $blog_id Optional. Defaults to current blog. 2052 * @return bool 2053 */ 1430 2054 function is_user_option_local( $key, $user_id = 0, $blog_id = 0 ) { 1431 2055 global $wpdb; 1432 2056 … … 1444 2068 return false; 1445 2069 } 1446 2070 2071 /** 2072 * Check whether users can self-register, based on Network settings. 2073 * 2074 * @since MU 2075 * @uses get_site_option() 2076 * 2077 * @return bool 2078 */ 1447 2079 function users_can_register_signup_filter() { 1448 2080 $registration = get_site_option('registration'); 1449 2081 if ( $registration == 'all' || $registration == 'user' ) … … 1453 2085 } 1454 2086 add_filter('option_users_can_register', 'users_can_register_signup_filter'); 1455 2087 2088 /** 2089 * Ensure that the welcome message is not empty. Currently unused. 2090 * 2091 * @since MU 2092 * 2093 * @param string $text 2094 * @return string $text 2095 */ 1456 2096 function welcome_user_msg_filter( $text ) { 1457 2097 if ( !$text ) { 1458 2098 return __( 'Dear User,