Ticket #14953: 14953-2.diff
File 14953-2.diff, 27.1 KB (added by , 15 years ago) |
---|
-
ms-functions.php
447 447 return $id; 448 448 } 449 449 450 // wpmu admin functions450 // Admin functions 451 451 452 /** 453 * Redirect a user based on $_GET or $_POST arguments. 454 * 455 * The function looks for redirect arguments in the following order: 456 * 1) $_GET['ref'] 457 * 2) $_POST['ref'] 458 * 3) $_SERVER['HTTP_REFERER'] 459 * 4) $_GET['redirect'] 460 * 5) $_POST['redirect'] 461 * 6) $url 462 * 463 * @since MU 464 * @uses wpmu_admin_redirect_add_updated_param() 465 * 466 * @param string $url 467 * @return none 468 */ 452 469 function wpmu_admin_do_redirect( $url = '' ) { 453 470 $ref = ''; 454 471 if ( isset( $_GET['ref'] ) ) … … 477 494 exit(); 478 495 } 479 496 497 /** 498 * Adds an 'updated=true' argument to a URL. 499 * 500 * @since MU 501 * 502 * @param string $url 503 * @return string $url 504 */ 480 505 function wpmu_admin_redirect_add_updated_param( $url = '' ) { 481 506 if ( strpos( $url, 'updated=true' ) === false ) { 482 507 if ( strpos( $url, '?' ) === false ) … … 487 512 return $url; 488 513 } 489 514 515 /** 516 * Checks an email address against a list of banned domains. 517 * 518 * This function checks against the Banned Email Domains list 519 * at wp-admin/network/settings.php. The check is only run on 520 * self-registrations; user creation at wp-admin/network/users.php 521 * bypasses this check. 522 * 523 * @since MU 524 * @uses get_site_option() 525 * 526 * @param string $user_email The email provided by the user at registration. 527 * @return bool Returns true when the email address is banned. 528 */ 490 529 function is_email_address_unsafe( $user_email ) { 491 530 $banned_names = get_site_option( 'banned_email_domains' ); 492 531 if ($banned_names && !is_array( $banned_names )) … … 510 549 return false; 511 550 } 512 551 552 /** 553 * Processes new user registrations. 554 * 555 * Checks the data provided by the user during signup. Verifies 556 * the validity and uniqueness of user names and user email addresses, 557 * and checks email addresses against admin-provided domain 558 * whitelists and blacklists. 559 * 560 * The hook 'wpmu_validate_user_signup' provides an easy way 561 * to modify the signup process. The value $result, which is passed 562 * to the hook, contains both the user-provided info and the error 563 * messages created by the function. 'wpmu_validate_user_signup' allows 564 * you to process the data in any way you'd like, and unset the 565 * relevant errors if necessary. 566 * 567 * @since MU 568 * @uses sanitize_user() 569 * @uses sanitize_email() 570 * @uses get_site_option() 571 * @uses is_email_address_unsafe() 572 * @uses username_exists() 573 * @uses email_exists() 574 * @uses $wpdb 575 * 576 * @param string $user_name The login name provided by the user. 577 * @param string $user_email The email provided by the user. 578 * @return array $result Contains username, email, and error messages. 579 */ 513 580 function wpmu_validate_user_signup($user_name, $user_email) { 514 581 global $wpdb; 515 582 … … 602 669 return apply_filters('wpmu_validate_user_signup', $result); 603 670 } 604 671 672 /** 673 * Processes new site registrations. 674 * 675 * Checks the data provided by the user during blog signup. Verifies 676 * the validity and uniqueness of blog paths and domains. 677 * 678 * This function prevents the current user from registering a new site 679 * with a blogname equivalent to another user's login name. Passing the 680 * $user parameter to the function, where $user is the other user, is 681 * effectively an override of this limitation. 682 * 683 * Filter 'wpmu_validate_blog_signup' if you want to modify 684 * the way that WordPress validates new site signups. 685 * 686 * @since MU 687 * @uses is_subdomain_install() 688 * @uses add_site_option() 689 * @uses get_site_option() 690 * @uses domain_exists() 691 * @uses username_exists() 692 * @uses $wpdb 693 * 694 * @param string $blogname The blog name provided by the user. Must be unique. 695 * @param string $blog_title The blog title provided by the user. 696 * @return array $result Contains the new site data and error messages. 697 */ 605 698 function wpmu_validate_blog_signup($blogname, $blog_title, $user = '') { 606 699 global $wpdb, $domain, $base, $current_site; 607 700 … … 685 778 return apply_filters('wpmu_validate_blog_signup', $result); 686 779 } 687 780 688 // Record signup information for future activation. wpmu_validate_signup() should be run 689 // on the inputs before calling wpmu_signup(). 781 /** 782 * Record site signup information for future activation. 783 * 784 * @since MU 785 * @uses wpmu_signup_blog_notification() 786 * @uses $wpdb 787 * 788 * @param string $domain The requested domain. 789 * @param string $path The requested path. 790 * @param string $title The requested site title. 791 * @param string $user The user's requested login name. 792 * @param string $user_email The user's email address. 793 * @param array $meta By default, contains the requested privacy setting and lang_id. 794 * @return none 795 */ 690 796 function wpmu_signup_blog($domain, $path, $title, $user, $user_email, $meta = '') { 691 797 global $wpdb; 692 798 … … 710 816 wpmu_signup_blog_notification($domain, $path, $title, $user, $user_email, $key, $meta); 711 817 } 712 818 819 /** 820 * Record user signup information for future activation. 821 * 822 * This function is used when user registration is open but 823 * new site registration is not. 824 * 825 * @since MU 826 * @uses wpmu_signup_user_notification() 827 * @uses $wpdb 828 * 829 * @param string $user The user's requested login name. 830 * @param string $user_email The user's email address. 831 * @param array $meta By default, this is an empty array. 832 * @return none 833 */ 713 834 function wpmu_signup_user($user, $user_email, $meta = '') { 714 835 global $wpdb; 715 836 … … 733 854 wpmu_signup_user_notification($user, $user_email, $key, $meta); 734 855 } 735 856 736 // Notify user of signup success. 857 /** 858 * Notify user of signup success. 859 * 860 * This is the notification function used when site registration 861 * is enabled. 862 * 863 * Filter 'wpmu_signup_blog_notification' to bypass this function or 864 * replace it with your own notification behavior. 865 * 866 * Filter 'wpmu_signup_blog_notification_email' and 867 * 'wpmu_signup_blog_notification_email' to change the content 868 * and subject line of the email sent to newly registered users. 869 * 870 * @since MU 871 * @uses is_subdomain_install() 872 * @uses get_site_option() 873 * @uses wp_mail() 874 * 875 * @param string $domain The new blog domain. 876 * @param string $path The new blog path. 877 * @param string $title The site title. 878 * @param string $user The user's login name. 879 * @param string $user_email The user's email address. 880 * @param array $meta By default, contains the requested privacy setting and lang_id. 881 * @param string $key The activation key created in wpmu_signup_blog() 882 * @return bool 883 */ 737 884 function wpmu_signup_blog_notification($domain, $path, $title, $user, $user_email, $key, $meta = '') { 738 885 global $current_site; 739 886 … … 774 921 return true; 775 922 } 776 923 924 /** 925 * Notify user of signup success. 926 * 927 * This is the notification function used when no new site has 928 * been requested. 929 * 930 * Filter 'wpmu_signup_user_notification' to bypass this function or 931 * replace it with your own notification behavior. 932 * 933 * Filter 'wpmu_signup_user_notification_email' and 934 * 'wpmu_signup_user_notification_subject' to change the content 935 * and subject line of the email sent to newly registered users. 936 * 937 * @since MU 938 * @uses get_site_option() 939 * @uses site_url() 940 * @uses wp_mail() 941 * 942 * @param string $user The user's login name. 943 * @param string $user_email The user's email address. 944 * @param array $meta By default, an empty array. 945 * @param string $key The activation key created in wpmu_signup_user() 946 * @return bool 947 */ 777 948 function wpmu_signup_user_notification($user, $user_email, $key, $meta = '') { 778 949 if ( !apply_filters('wpmu_signup_user_notification', $user, $user_email, $key, $meta) ) 779 950 return false; … … 805 976 return true; 806 977 } 807 978 979 /** 980 * Activate a signup. 981 * 982 * Hook to 'wpmu_activate_user' or 'wpmu_activate_blog' for events 983 * that should happen only when users or sites are self-created (since 984 * those actions are not called when users and sites are created 985 * by a Super Admin). 986 * 987 * @since MU 988 * @uses $wpdb 989 * @uses wp_generate_password() 990 * @uses wpmu_welcome_user_notification() 991 * @uses get_site_option() 992 * @uses add_user_to_blog() 993 * @uses add_new_user_to_blog() 994 * @uses wpmu_create_user() 995 * @uses wpmu_create_blog() 996 * @uses is_wp_error() 997 * @uses wpmu_welcome_notification() 998 * 999 * @param string $key The activation key provided to the user. 1000 * @return array An array containing information about the activated user and/or blog 1001 */ 808 1002 function wpmu_activate_signup($key) { 809 1003 global $wpdb, $current_site; 810 1004 … … 872 1066 return array('blog_id' => $blog_id, 'user_id' => $user_id, 'password' => $password, 'title' => $signup->title, 'meta' => $meta); 873 1067 } 874 1068 1069 /** 1070 * Create a user. 1071 * 1072 * This function runs when a user self-registers as well as when 1073 * a Super Admin creates a new user. Hook to 'wpmu_new_user' for events 1074 * that should affect all new users, but only on Multisite (otherwise 1075 * use 'user_register'). 1076 * 1077 * @since MU 1078 * @uses wp_create_user() 1079 * @uses is_wp_error() 1080 * @uses delete_user_option() 1081 * 1082 * @param string $user_name The new user's login name. 1083 * @param string $password The new user's password. 1084 * @param string $email The new user's email address. 1085 * @return mixed Returns false on failure, or int $user_id on success 1086 */ 875 1087 function wpmu_create_user( $user_name, $password, $email) { 876 1088 $user_name = preg_replace( '/\s+/', '', sanitize_user( $user_name, true ) ); 877 1089 … … 888 1100 return $user_id; 889 1101 } 890 1102 1103 /** 1104 * Create a site. 1105 * 1106 * This function runs when a user self-registers a new site as well 1107 * as when a Super Admin creates a new site. Hook to 'wpmu_new_blog' 1108 * for events that should affect all new sites. 1109 * 1110 * On subdirectory installs, $domain is the same as the main site's 1111 * domain, and the path is the subdirectory name (eg 'example.com' 1112 * and '/blog1/'). On subdomain installs, $domain is the new subdomain + 1113 * root domain (eg 'blog1.example.com'), and $path is '/'. 1114 * 1115 * @since MU 1116 * @uses is_subdomain_install() 1117 * @uses domain_exists() 1118 * @uses insert_blog() 1119 * @uses switch_to_blog() 1120 * @uses wp_install_defaults() 1121 * @uses add_user_to_blog() 1122 * @uses update_blog_status() 1123 * @uses restore_current_blog() 1124 * 1125 * @param string $domain The new site's domain. 1126 * @param string $path The new site's path. 1127 * @param string $title The new site's title. 1128 * @param int $user_id The user ID of the new site's admin. 1129 * @param array $meta Optional. Used to set initial site options. 1130 * @param int $site_id Optional. Only relevant on multi-network installs. 1131 * @return mixed Returns WP_Error object on failure, int $blog_id on success 1132 */ 891 1133 function wpmu_create_blog($domain, $path, $title, $user_id, $meta = '', $site_id = 1) { 892 1134 $domain = preg_replace( '/\s+/', '', sanitize_user( $domain, true ) ); 893 1135 … … 935 1177 return $blog_id; 936 1178 } 937 1179 1180 /** 1181 * Notifies the network admin that a new site has been activated. 1182 * 1183 * Filter 'newblog_notify_siteadmin' to change the content of 1184 * the notification email. 1185 * 1186 * @since MU 1187 * @uses switch_to_blog() 1188 * @uses site_url() 1189 * @uses get_site_option() 1190 * @uses network_admin_url() 1191 * @uses restore_current_blog() 1192 * @uses wp_mail() 1193 * 1194 * @param int $blog_id The new site's ID. 1195 * @return bool 1196 */ 938 1197 function newblog_notify_siteadmin( $blog_id, $deprecated = '' ) { 939 1198 if ( get_site_option( 'registrationnotification' ) != 'yes' ) 940 1199 return false; … … 961 1220 return true; 962 1221 } 963 1222 1223 /** 1224 * Notifies the network admin that a new user has been activated. 1225 * 1226 * Filter 'newuser_notify_siteadmin' to change the content of 1227 * the notification email. 1228 * 1229 * @since MU 1230 * @uses get_site_option() 1231 * @uses network_admin_url() 1232 * @uses wp_mail() 1233 * 1234 * @param int $user_id The new user's ID. 1235 * @return bool 1236 */ 964 1237 function newuser_notify_siteadmin( $user_id ) { 965 1238 if ( get_site_option( 'registrationnotification' ) != 'yes' ) 966 1239 return false; … … 983 1256 return true; 984 1257 } 985 1258 1259 /** 1260 * Check whether a blogname is already taken. 1261 * 1262 * Used during the new site registration process to ensure 1263 * that each blogname is unique. 1264 * 1265 * @since MU 1266 * @uses $wpdb 1267 * 1268 * @param string $domain The domain to be checked. 1269 * @param string $path The path to be checked. 1270 * @param int $site_id Optional. Relevant only on multi-network installs. 1271 * @return int $blog_id 1272 */ 986 1273 function domain_exists($domain, $path, $site_id = 1) { 987 1274 global $wpdb; 988 1275 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) ); 989 1276 } 990 1277 1278 /** 1279 * Store basic site info in the blogs table. 1280 * 1281 * This function creates a row in the wp_blogs table and returns 1282 * the new blog's ID. It is the first step in creating a new blog. 1283 * 1284 * @since MU 1285 * @uses $wpdb 1286 * @uses trailingslashit() 1287 * @uses refresh_blog_details() 1288 * 1289 * @param string $domain The domain of the new site. 1290 * @param string $path The path of the new site. 1291 * @param int $site_id Unless you're running a multi-network install, be sure to set this value to 1. 1292 * @return int $blog_id The ID of the new row 1293 */ 991 1294 function insert_blog($domain, $path, $site_id) { 992 1295 global $wpdb; 993 1296 … … 1002 1305 return $wpdb->insert_id; 1003 1306 } 1004 1307 1005 // Install an empty blog. wpdb should already be switched. 1308 /** 1309 * Install an empty blog. 1310 * 1311 * Creates the new blog tables and options. If calling this function 1312 * directly, be sure to use switch_to_blog() first, so that $wpdb 1313 * points to the new blog. 1314 * 1315 * @since MU 1316 * @uses $wpdb 1317 * @uses get_blogaddress_by_id() 1318 * @uses make_db_current_silent() 1319 * @uses populate_roles() 1320 * @uses update_option() 1321 * 1322 * @param int $blog_id The value returned by insert_blog(). 1323 * @param string $blog_title The title of the new site. 1324 * @return none 1325 */ 1006 1326 function install_blog($blog_id, $blog_title = '') { 1007 1327 global $wpdb, $table_prefix, $wp_roles; 1008 1328 $wpdb->suppress_errors(); … … 1041 1361 $wpdb->suppress_errors( false ); 1042 1362 } 1043 1363 1044 // Deprecated, use wp_install_defaults() 1045 // should be switched already as $blog_id is ignored. 1364 /** 1365 * Set blog defaults. 1366 * 1367 * This function creates a row in the wp_blogs table. 1368 * 1369 * @since MU 1370 * @deprecated MU 1371 * @deprecated Use wp_install_defaults() 1372 * @uses wp_install_defaults() 1373 * 1374 * @param int $blog_id Ignored in this function. 1375 * @param int $user_id 1376 * @return none 1377 */ 1046 1378 function install_blog_defaults($blog_id, $user_id) { 1047 1379 global $wpdb; 1048 1380 … … 1055 1387 $wpdb->suppress_errors( false ); 1056 1388 } 1057 1389 1390 /** 1391 * Notify a user that her blog activation has been successful. 1392 * 1393 * Filter 'wpmu_welcome_notification' to disable or bypass. 1394 * 1395 * Filter 'update_welcome_email' and 'update_welcome_subject' to 1396 * modify the content and subject line of the notification email. 1397 * 1398 * @since MU 1399 * @uses get_site_option() 1400 * @uses get_blogaddress_by_id() 1401 * @uses wp_mail() 1402 * 1403 * @param int $blog_id 1404 * @param int $user_id 1405 * @param string $password 1406 * @param string $title The new blog's title 1407 * @param array $meta Optional. Not used in the default function, but is passed along to hooks for customization. 1408 * @return bool 1409 */ 1058 1410 function wpmu_welcome_notification($blog_id, $user_id, $password, $title, $meta = '') { 1059 1411 global $current_site; 1060 1412 … … 1105 1457 return true; 1106 1458 } 1107 1459 1460 /** 1461 * Notify a user that her account activation has been successful. 1462 * 1463 * Filter 'wpmu_welcome_user_notification' to disable or bypass. 1464 * 1465 * Filter 'update_welcome_user_email' and 'update_welcome_user_subject' to 1466 * modify the content and subject line of the notification email. 1467 * 1468 * @since MU 1469 * @uses get_site_option() 1470 * @uses wp_mail() 1471 * 1472 * @param int $user_id 1473 * @param string $password 1474 * @param array $meta Optional. Not used in the default function, but is passed along to hooks for customization. 1475 * @return bool 1476 */ 1108 1477 function wpmu_welcome_user_notification($user_id, $password, $meta = '') { 1109 1478 global $current_site; 1110 1479 … … 1138 1507 return true; 1139 1508 } 1140 1509 1510 /** 1511 * Get the current site info. 1512 * 1513 * Returns an object containing the ID, domain, path, and site_name 1514 * of the site being viewed. 1515 * 1516 * @since MU 1517 * 1518 * @return object $current_site 1519 */ 1141 1520 function get_current_site() { 1142 1521 global $current_site; 1143 1522 return $current_site; 1144 1523 } 1145 1524 1525 /** 1526 * Get a numeric user ID from either an email address or a login. 1527 * 1528 * @since MU 1529 * @uses is_email() 1530 * @uses get_user_by() 1531 * 1532 * @param string $string 1533 * @return int $user_id 1534 */ 1146 1535 function get_user_id_from_string( $string ) { 1147 1536 $user_id = 0; 1148 1537 if ( is_email( $string ) ) { … … 1160 1549 return $user_id; 1161 1550 } 1162 1551 1552 /** 1553 * Get a user's most recent post. 1554 * 1555 * Walks through each of a user's blogs to find the post with 1556 * the most recent post_date_gmt. 1557 * 1558 * @since MU 1559 * @uses $wpdb 1560 * @uses get_blogs_of_user() 1561 * 1562 * @param int $user_id 1563 * @return array $most_recent_post Contains the blog_id, post_id, post_date_gmt, and post_gmt_ts 1564 */ 1163 1565 function get_most_recent_post_of_user( $user_id ) { 1164 1566 global $wpdb; 1165 1567 … … 1192 1594 return $most_recent_post; 1193 1595 } 1194 1596 1195 /* Misc functions */ 1597 // Misc functions 1598 1599 /** 1600 * Get the size of a directory. 1601 * 1602 * A helper function that is used primarily to check whether 1603 * a blog has exceeded its allowed upload space. 1604 * 1605 * @since MU 1606 * @uses $wpdb 1607 * @uses get_transient() 1608 * @uses recurse_dirsize() 1609 * @uses set_transient() 1610 * 1611 * @param string $directory 1612 * @return int 1613 */ 1196 1614 function get_dirsize( $directory ) { 1197 1615 $dirsize = get_transient( 'dirsize_cache' ); 1198 1616 if ( is_array( $dirsize ) && isset( $dirsize[ $directory ][ 'size' ] ) ) … … 1207 1625 return $dirsize[ $directory ][ 'size' ]; 1208 1626 } 1209 1627 1628 /** 1629 * Get the size of a directory recursively. 1630 * 1631 * Used by get_dirsize() to get a directory's size when it contains 1632 * other directories. 1633 * 1634 * @since MU 1635 * 1636 * @param string $directory 1637 * @return int $size 1638 */ 1210 1639 function recurse_dirsize( $directory ) { 1211 1640 $size = 0; 1212 1641 … … 1234 1663 return $size; 1235 1664 } 1236 1665 1666 /** 1667 * Check whether a blog has used its allotted upload space. 1668 * 1669 * Used by get_dirsize() to get a directory's size when it contains 1670 * other directories. 1671 * 1672 * @since MU 1673 * @uses get_site_option() 1674 * @uses get_dirsize() 1675 * 1676 * @param bool $echo Optional. If $echo is set and the quota is exceeded, a warning message is echoed. Default is true. 1677 * @return int $size 1678 */ 1237 1679 function upload_is_user_over_quota( $echo = true ) { 1238 1680 if ( get_site_option( 'upload_space_check_disabled' ) ) 1239 1681 return true; … … 1254 1696 } 1255 1697 } 1256 1698 1699 /** 1700 * Check an array of MIME types against a whitelist. 1701 * 1702 * WordPress ships with a set of allowed upload filetypes, 1703 * which is defined in wp-includes/functions.php in 1704 * get_allowed_mime_types(). This function is used to filter 1705 * that list against the filetype whitelist provided by Multisite 1706 * Super Admins at wp-admin/network/settings.php. 1707 * 1708 * @since MU 1709 * @uses get_site_option() 1710 * 1711 * @param array $mimes 1712 * @return array $site_mimes 1713 */ 1257 1714 function check_upload_mimes( $mimes ) { 1258 1715 $site_exts = explode( ' ', get_site_option( 'upload_filetypes' ) ); 1259 1716 foreach ( $site_exts as $ext ) { … … 1265 1722 return $site_mimes; 1266 1723 } 1267 1724 1725 /** 1726 * Update a blog's post count. 1727 * 1728 * WordPress MS stores a blog's post count as an option so as 1729 * to avoid extraneous COUNTs when a blog's details are fetched 1730 * with get_blog_details(). This function is called when posts 1731 * are published to make sure the count stays current. 1732 * 1733 * @since MU 1734 * @uses $wpdb 1735 * @uses update_option() 1736 * 1737 * @return none 1738 */ 1268 1739 function update_posts_count( $deprecated = '' ) { 1269 1740 global $wpdb; 1270 1741 update_option( 'post_count', (int) $wpdb->get_var( "SELECT COUNT(ID) FROM {$wpdb->posts} WHERE post_status = 'publish' and post_type = 'post'" ) ); 1271 1742 } 1272 1743 1744 /** 1745 * Logs user registrations. 1746 * 1747 * @since MU 1748 * @uses $wpdb 1749 * 1750 * @param int $blog_id 1751 * @param int $user_id 1752 * @return none 1753 */ 1273 1754 function wpmu_log_new_registrations( $blog_id, $user_id ) { 1274 1755 global $wpdb; 1275 1756 $user = new WP_User( (int) $user_id ); 1276 1757 $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')) ); 1277 1758 } 1278 1759 1760 /** 1761 * Get the remaining upload space for this blog. 1762 * 1763 * @since MU 1764 * @uses upload_is_user_over_quota() 1765 * @uses get_space_allowed() 1766 * @uses get_dirsize() 1767 * 1768 * @param int $size 1769 * @return int $size 1770 */ 1279 1771 function fix_import_form_size( $size ) { 1280 1772 if ( upload_is_user_over_quota( false ) == true ) 1281 1773 return 0; … … 1357 1849 return $global_id; 1358 1850 } 1359 1851 1852 /** 1853 * Ensure that the current site's domain is listed in the allowed redirect host list. 1854 * 1855 * @see wp_validate_redirect() 1856 * 1857 * @since MU 1858 * 1859 * @return array The current site's domain 1860 */ 1360 1861 function redirect_this_site( $deprecated = '' ) { 1361 1862 global $current_site; 1362 1863 return array( $current_site->domain ); 1363 1864 } 1364 1865 1866 /** 1867 * Check whether an upload is too big. 1868 * 1869 * @since MU 1870 * @uses get_site_option() 1871 * 1872 * @param array $upload 1873 * @return mixed If the upload is under the size limit, $upload is returned. Otherwise returns an error message. 1874 */ 1365 1875 function upload_is_file_too_big( $upload ) { 1366 1876 if ( is_array( $upload ) == false || defined( 'WP_IMPORTING' ) ) 1367 1877 return $upload; … … 1372 1882 return $upload; 1373 1883 } 1374 1884 1885 /** 1886 * Ensure that the from address on outgoing mail is the blog's correct admin_email. Filters 'wp_mail_from'. 1887 * 1888 * @since MU 1889 * @uses get_option() 1890 * 1891 * @param string $email 1892 * @return string $email 1893 */ 1375 1894 function wordpressmu_wp_mail_from( $email ) { 1376 1895 if ( strpos( $email, 'wordpress@' ) !== false ) 1377 1896 $email = get_option( 'admin_email' ); 1378 1897 return $email; 1379 1898 } 1380 1899 1900 /** 1901 * Add a nonce field to the signup page. 1902 * 1903 * @since MU 1904 * @uses wp_nonce_field() 1905 * 1906 * @return none 1907 */ 1381 1908 function signup_nonce_fields() { 1382 1909 $id = mt_rand(); 1383 1910 echo "<input type='hidden' name='signup_form_id' value='{$id}' />"; 1384 1911 wp_nonce_field('signup_form_' . $id, '_signup_form', false); 1385 1912 } 1386 1913 1914 /** 1915 * Process the signup nonce created in signup_nonce_fields(). 1916 * 1917 * @since MU 1918 * @uses wp_create_nonce() 1919 * 1920 * @param array $result 1921 * @return array $result 1922 */ 1387 1923 function signup_nonce_check( $result ) { 1388 1924 if ( !strpos( $_SERVER[ 'PHP_SELF' ], 'wp-signup.php' ) ) 1389 1925 return $result; … … 1394 1930 return $result; 1395 1931 } 1396 1932 1933 /** 1934 * Correct 404 redirects when NOBLOGREDIRECT is defined. 1935 * 1936 * @since MU 1937 * @uses is_main_site() 1938 * @uses is_404() 1939 * @uses network_home_url() 1940 * @uses wp_redirect() 1941 * 1942 * @return none 1943 */ 1397 1944 function maybe_redirect_404() { 1398 1945 global $current_site; 1399 1946 if ( is_main_site() && is_404() && defined( 'NOBLOGREDIRECT' ) && ( $destination = apply_filters( 'blog_redirect_404', NOBLOGREDIRECT ) ) ) { … … 1404 1951 } 1405 1952 } 1406 1953 1954 /** 1955 * Add a new user to a blog by visiting /newbloguser/username/. 1956 * 1957 * This will only work when the user's details are saved as an option 1958 * keyed as 'new_user_x', where 'x' is the username of the user to be 1959 * added, as when a user is invited through the regular WP Add User interface. 1960 * 1961 * @since MU 1962 * @uses get_option() 1963 * @uses add_existing_user_to_blog() 1964 * @uses is_wp_error() 1965 * @uses wp_die() 1966 * 1967 * @return none 1968 */ 1407 1969 function maybe_add_existing_user_to_blog() { 1408 1970 if ( false === strpos( $_SERVER[ 'REQUEST_URI' ], '/newbloguser/' ) ) 1409 1971 return false; … … 1424 1986 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') ); 1425 1987 } 1426 1988 1989 /** 1990 * Add a user to a blog based on details from maybe_add_existing_user_to_blog(). 1991 * 1992 * @since MU 1993 * @uses add_user_to_blog() 1994 * 1995 * @param array $details 1996 * @return none 1997 */ 1427 1998 function add_existing_user_to_blog( $details = false ) { 1428 1999 if ( is_array( $details ) ) { 1429 2000 $result = add_user_to_blog( '', $details[ 'user_id' ], $details[ 'role' ] ); … … 1432 2003 return $result; 1433 2004 } 1434 2005 2006 /** 2007 * Add a newly created user to the appropriate blog 2008 * 2009 * @since MU 2010 * @uses remove_user_from_blog() 2011 * @uses add_user_to_blog() 2012 * @uses update_user_meta() 2013 * 2014 * @param int $user_id 2015 * @param string $email 2016 * @param array $meta 2017 * @return none 2018 */ 1435 2019 function add_new_user_to_blog( $user_id, $email, $meta ) { 1436 2020 global $current_site; 1437 2021 if ( $meta[ 'add_to_blog' ] ) { … … 1443 2027 } 1444 2028 } 1445 2029 2030 /** 2031 * Correct From host on outgoing mail to match the site domain 2032 * 2033 * @since MU 2034 * 2035 * @return none 2036 */ 1446 2037 function fix_phpmailer_messageid( $phpmailer ) { 1447 2038 global $current_site; 1448 2039 $phpmailer->Hostname = $current_site->domain; 1449 2040 } 1450 2041 2042 /** 2043 * Check to see whether a user is marked as a spammer, based on username 2044 * 2045 * @since MU 2046 * @uses get_current_user_id() 2047 * @uses get_user_id_from_string() 2048 * 2049 * @param string $username 2050 * @return bool 2051 */ 1451 2052 function is_user_spammy( $username = 0 ) { 1452 2053 if ( $username == 0 ) { 1453 2054 $user_id = get_current_user_id(); … … 1459 2060 return ( isset( $u->spam ) && $u->spam == 1 ); 1460 2061 } 1461 2062 2063 /** 2064 * Update this blog's 'public' setting in the global blogs table. 2065 * 2066 * Public blogs have a setting of 1, private blogs are 0. 2067 * 2068 * @since MU 2069 * @uses update_blog_status() 2070 * 2071 * @param int $old_value 2072 * @param int $value The new public value 2073 * @return bool 2074 */ 1462 2075 function update_blog_public( $old_value, $value ) { 1463 2076 global $wpdb; 1464 2077 do_action('update_blog_public'); … … 1466 2079 } 1467 2080 add_action('update_option_blog_public', 'update_blog_public', 10, 2); 1468 2081 1469 /* Redirect all hits to "dashboard" blog to wp-admin/ Dashboard. */ 2082 /** 2083 * Redirect all hits to "dashboard" blog to wp-admin/ Dashboard. 2084 * 2085 * @since MU 2086 * @uses get_dashboard_blog() 2087 * @uses wp_redirect() 2088 * @uses trailingslashit() 2089 * 2090 * @return none 2091 */ 1470 2092 function redirect_mu_dashboard() { 1471 2093 global $current_site, $current_blog; 1472 2094 … … 1479 2101 } 1480 2102 add_action( 'template_redirect', 'redirect_mu_dashboard' ); 1481 2103 2104 /** 2105 * Get the "dashboard blog", the blog where users without a blog edit their profile data. 2106 * 2107 * @since MU 2108 * @uses get_site_option() 2109 * @uses get_blog_details() 2110 * 2111 * @return int 2112 */ 1482 2113 function get_dashboard_blog() { 1483 2114 if ( $blog = get_site_option( 'dashboard_blog' ) ) 1484 2115 return get_blog_details( $blog ); … … 1486 2117 return get_blog_details( $GLOBALS['current_site']->blog_id ); 1487 2118 } 1488 2119 2120 /** 2121 * Check whether a usermeta key has to do with the current blog. 2122 * 2123 * @since MU 2124 * @uses wp_get_current_user() 2125 * 2126 * @param string $key 2127 * @param int $user_id Optional. Defaults to current user. 2128 * @param int $blog_id Optional. Defaults to current blog. 2129 * @return bool 2130 */ 1489 2131 function is_user_option_local( $key, $user_id = 0, $blog_id = 0 ) { 1490 2132 global $wpdb; 1491 2133 … … 1503 2145 return false; 1504 2146 } 1505 2147 2148 /** 2149 * Check whether users can self-register, based on Network settings. 2150 * 2151 * @since MU 2152 * @uses get_site_option() 2153 * 2154 * @return bool 2155 */ 1506 2156 function users_can_register_signup_filter() { 1507 2157 $registration = get_site_option('registration'); 1508 2158 if ( $registration == 'all' || $registration == 'user' ) … … 1512 2162 } 1513 2163 add_filter('option_users_can_register', 'users_can_register_signup_filter'); 1514 2164 2165 /** 2166 * Ensure that the welcome message is not empty. Currently unused. 2167 * 2168 * @since MU 2169 * 2170 * @param string $text 2171 * @return string $text 2172 */ 1515 2173 function welcome_user_msg_filter( $text ) { 1516 2174 if ( !$text ) { 1517 2175 return __( 'Dear User,