1 | <?php |
---|
2 | /***** |
---|
3 | * WordPress Abstraction |
---|
4 | * |
---|
5 | * The functions within this file will detect the version of WordPress you are running |
---|
6 | * and will alter the environment so BuddyPress can run regardless. |
---|
7 | * |
---|
8 | * The code below mostly contains function mappings. This code is subject to change once |
---|
9 | * the 3.0 WordPress version merge takes place. |
---|
10 | */ |
---|
11 | |
---|
12 | if ( !bp_core_is_multisite() ) { |
---|
13 | $wpdb->base_prefix = $wpdb->prefix; |
---|
14 | $wpdb->blogid = 1; |
---|
15 | } |
---|
16 | |
---|
17 | function bp_core_is_multisite() { |
---|
18 | if ( function_exists( 'is_multisite' ) ) |
---|
19 | return is_multisite(); |
---|
20 | |
---|
21 | if ( !function_exists( 'wpmu_signup_blog' ) ) |
---|
22 | return false; |
---|
23 | |
---|
24 | return true; |
---|
25 | } |
---|
26 | |
---|
27 | function bp_core_get_status_sql( $prefix = false ) { |
---|
28 | if ( !bp_core_is_multisite() ) |
---|
29 | return "{$prefix}user_status = 0"; |
---|
30 | else |
---|
31 | return "{$prefix}spam = 0 AND {$prefix}deleted = 0 AND {$prefix}user_status = 0"; |
---|
32 | } |
---|
33 | |
---|
34 | if ( !function_exists( 'get_blog_option' ) ) { |
---|
35 | function get_blog_option( $blog_id, $option_name, $default = false ) { |
---|
36 | return get_option( $option_name, $default ); |
---|
37 | } |
---|
38 | } |
---|
39 | |
---|
40 | if ( !function_exists( 'add_blog_option' ) ) { |
---|
41 | function add_blog_option( $blog_id, $option_name, $option_value ) { |
---|
42 | return add_option( $option_name, $option_value ); |
---|
43 | } |
---|
44 | } |
---|
45 | |
---|
46 | if ( !function_exists( 'update_blog_option' ) ) { |
---|
47 | function update_blog_option( $blog_id, $option_name, $option_value ) { |
---|
48 | return update_option( $option_name, $option_value ); |
---|
49 | } |
---|
50 | } |
---|
51 | |
---|
52 | if ( !function_exists( 'switch_to_blog' ) ) { |
---|
53 | function switch_to_blog() { |
---|
54 | return 1; |
---|
55 | } |
---|
56 | } |
---|
57 | |
---|
58 | if ( !function_exists( 'restore_current_blog' ) ) { |
---|
59 | function restore_current_blog() { |
---|
60 | return 1; |
---|
61 | } |
---|
62 | } |
---|
63 | |
---|
64 | if ( !function_exists( 'get_blogs_of_user' ) ) { |
---|
65 | function get_blogs_of_user() { |
---|
66 | return false; |
---|
67 | } |
---|
68 | } |
---|
69 | |
---|
70 | if ( !function_exists( 'is_site_admin' ) ) { |
---|
71 | function is_site_admin() { |
---|
72 | if ( current_user_can( 'manage_options' ) ) |
---|
73 | return true; |
---|
74 | |
---|
75 | return false; |
---|
76 | } |
---|
77 | } |
---|
78 | |
---|
79 | if ( !function_exists( 'get_current_user_id' ) ) { |
---|
80 | function get_current_user_id() { |
---|
81 | global $current_user; |
---|
82 | get_currentuserinfo(); |
---|
83 | return $current_user->data->ID; |
---|
84 | } |
---|
85 | } |
---|
86 | |
---|
87 | if ( !function_exists( 'update_blog_status' ) ) { |
---|
88 | function update_blog_status() { |
---|
89 | return true; |
---|
90 | } |
---|
91 | } |
---|
92 | |
---|
93 | if ( !function_exists( 'wpmu_validate_user_signup' ) ) { |
---|
94 | function wpmu_validate_user_signup( $user_name, $user_email ) { |
---|
95 | global $wpdb; |
---|
96 | |
---|
97 | $errors = new WP_Error(); |
---|
98 | |
---|
99 | $user_name = preg_replace( "/\s+/", '', sanitize_user( $user_name, true ) ); |
---|
100 | $user_email = sanitize_email( $user_email ); |
---|
101 | |
---|
102 | if ( empty( $user_name ) ) |
---|
103 | $errors->add('user_name', __("Please enter a username")); |
---|
104 | |
---|
105 | $maybe = array(); |
---|
106 | preg_match( "/[a-z0-9]+/", $user_name, $maybe ); |
---|
107 | |
---|
108 | if( $user_name != $maybe[0] ) { |
---|
109 | $errors->add('user_name', __("Only lowercase letters and numbers allowed")); |
---|
110 | } |
---|
111 | |
---|
112 | $illegal_names = get_site_option( "illegal_names" ); |
---|
113 | if( is_array( $illegal_names ) == false ) { |
---|
114 | $illegal_names = array( "www", "web", "root", "admin", "main", "invite", "administrator" ); |
---|
115 | add_site_option( "illegal_names", $illegal_names ); |
---|
116 | } |
---|
117 | if( in_array( $user_name, $illegal_names ) == true ) { |
---|
118 | $errors->add('user_name', __("That username is not allowed")); |
---|
119 | } |
---|
120 | |
---|
121 | if( strlen( $user_name ) < 4 ) { |
---|
122 | $errors->add('user_name', __("Username must be at least 4 characters")); |
---|
123 | } |
---|
124 | |
---|
125 | if ( strpos( " " . $user_name, "_" ) != false ) |
---|
126 | $errors->add('user_name', __("Sorry, usernames may not contain the character '_'!")); |
---|
127 | |
---|
128 | // all numeric? |
---|
129 | $match = array(); |
---|
130 | preg_match( '/[0-9]*/', $user_name, $match ); |
---|
131 | if ( $match[0] == $user_name ) |
---|
132 | $errors->add('user_name', __("Sorry, usernames must have letters too!")); |
---|
133 | |
---|
134 | if ( !is_email( $user_email ) ) |
---|
135 | $errors->add('user_email', __("Please check your email address.")); |
---|
136 | |
---|
137 | $limited_email_domains = get_site_option( 'limited_email_domains' ); |
---|
138 | if ( is_array( $limited_email_domains ) && empty( $limited_email_domains ) == false ) { |
---|
139 | $emaildomain = substr( $user_email, 1 + strpos( $user_email, '@' ) ); |
---|
140 | if( in_array( $emaildomain, $limited_email_domains ) == false ) { |
---|
141 | $errors->add('user_email', __("Sorry, that email address is not allowed!")); |
---|
142 | } |
---|
143 | } |
---|
144 | |
---|
145 | // Check if the username has been used already. |
---|
146 | if ( username_exists($user_name) ) |
---|
147 | $errors->add('user_name', __("Sorry, that username already exists!")); |
---|
148 | |
---|
149 | // Check if the email address has been used already. |
---|
150 | if ( email_exists($user_email) ) |
---|
151 | $errors->add('user_email', __("Sorry, that email address is already used!")); |
---|
152 | |
---|
153 | $result = array('user_name' => $user_name, 'user_email' => $user_email, 'errors' => $errors); |
---|
154 | |
---|
155 | return apply_filters('wpmu_validate_user_signup', $result); |
---|
156 | } |
---|
157 | } |
---|