/var/www/wordpress/wp-admin/includes/admin.php
/var/www/wordpress/wp-admin/includes/bookmark.php
/var/www/wordpress/wp-admin/includes/class-ftp-pure.php
/var/www/wordpress/wp-admin/includes/class-ftp-sockets.php
/var/www/wordpress/wp-admin/includes/class-ftp.php
/var/www/wordpress/wp-admin/includes/class-pclzip.php
/var/www/wordpress/wp-admin/includes/class-wp-filesystem-base.php
/var/www/wordpress/wp-admin/includes/class-wp-filesystem-direct.php
/var/www/wordpress/wp-admin/includes/class-wp-filesystem-ftpext.php
/var/www/wordpress/wp-admin/includes/class-wp-filesystem-ftpsockets.php
/var/www/wordpress/wp-admin/includes/class-wp-filesystem-ssh2.php
/var/www/wordpress/wp-admin/includes/class-wp-importer.php
/var/www/wordpress/wp-admin/includes/class-wp-upgrader.php
/var/www/wordpress/wp-admin/includes/comment.php
/var/www/wordpress/wp-admin/includes/continents-cities.php
/var/www/wordpress/wp-admin/includes/dashboard.php
/var/www/wordpress/wp-admin/includes/deprecated.php
/var/www/wordpress/wp-admin/includes/export.php
/var/www/wordpress/wp-admin/includes/file.php
/var/www/wordpress/wp-admin/includes/image-edit.php
/var/www/wordpress/wp-admin/includes/image.php
/var/www/wordpress/wp-admin/includes/import.php
/var/www/wordpress/wp-admin/includes/manifest.php
/var/www/wordpress/wp-admin/includes/media.php
/var/www/wordpress/wp-admin/includes/meta-boxes.php
/var/www/wordpress/wp-admin/includes/misc.php
/var/www/wordpress/wp-admin/includes/ms-deprecated.php
/var/www/wordpress/wp-admin/includes/ms.php
/var/www/wordpress/wp-admin/includes/nav-menu.php
/var/www/wordpress/wp-admin/includes/plugin-install.php
/var/www/wordpress/wp-admin/includes/plugin.php
/var/www/wordpress/wp-admin/includes/post.php
/var/www/wordpress/wp-admin/includes/schema.php
/var/www/wordpress/wp-admin/includes/taxonomy.php
/var/www/wordpress/wp-admin/includes/template.php
/var/www/wordpress/wp-admin/includes/theme-install.php
/var/www/wordpress/wp-admin/includes/theme.php
/var/www/wordpress/wp-admin/includes/update-core.php
/var/www/wordpress/wp-admin/includes/update.php
/var/www/wordpress/wp-admin/includes/upgrade.php
/var/www/wordpress/wp-admin/includes/user.php
/var/www/wordpress/wp-admin/includes/widgets.php
/var/www/wordpress/wp-admin/js/revisions-js.php
/var/www/wordpress/wp-admin/maint/repair.php
/var/www/wordpress/wp-admin/admin-ajax.php
/var/www/wordpress/wp-admin/admin-footer.php
/var/www/wordpress/wp-admin/admin-functions.php
/var/www/wordpress/wp-admin/admin-header.php
/var/www/wordpress/wp-admin/admin-post.php
/var/www/wordpress/wp-admin/admin.php
/var/www/wordpress/wp-admin/async-upload.php
/var/www/wordpress/wp-admin/comment.php
/var/www/wordpress/wp-admin/custom-background.php
/var/www/wordpress/wp-admin/custom-header.php
/var/www/wordpress/wp-admin/edit-attachment-rows.php
/var/www/wordpress/wp-admin/edit-comments.php
/var/www/wordpress/wp-admin/edit-form-advanced.php
/var/www/wordpress/wp-admin/edit-form-comment.php
/var/www/wordpress/wp-admin/edit-link-categories.php
/var/www/wordpress/wp-admin/edit-link-category-form.php
/var/www/wordpress/wp-admin/edit-link-form.php
/var/www/wordpress/wp-admin/edit-post-rows.php
/var/www/wordpress/wp-admin/edit-tag-form.php
/var/www/wordpress/wp-admin/edit-tags.php
/var/www/wordpress/wp-admin/edit.php
/var/www/wordpress/wp-admin/export.php
/var/www/wordpress/wp-admin/gears-manifest.php
/var/www/wordpress/wp-admin/import.php
/var/www/wordpress/wp-admin/index-extra.php
/var/www/wordpress/wp-admin/index.php
/var/www/wordpress/wp-admin/install-helper.php
/var/www/wordpress/wp-admin/install.php
/var/www/wordpress/wp-admin/link-add.php
/var/www/wordpress/wp-admin/link-category.php
/var/www/wordpress/wp-admin/link-manager.php
/var/www/wordpress/wp-admin/link-parse-opml.php
/var/www/wordpress/wp-admin/link.php
/var/www/wordpress/wp-admin/load-scripts.php
/var/www/wordpress/wp-admin/load-styles.php
/var/www/wordpress/wp-admin/media-new.php
/var/www/wordpress/wp-admin/media-upload.php
/var/www/wordpress/wp-admin/media.php
/var/www/wordpress/wp-admin/menu-header.php
/var/www/wordpress/wp-admin/menu.php
/var/www/wordpress/wp-admin/moderation.php
/var/www/wordpress/wp-admin/ms-admin.php
/var/www/wordpress/wp-admin/ms-delete-site.php
/var/www/wordpress/wp-admin/ms-edit.php
/var/www/wordpress/wp-admin/ms-options.php
/var/www/wordpress/wp-admin/ms-sites.php
/var/www/wordpress/wp-admin/ms-themes.php
/var/www/wordpress/wp-admin/ms-upgrade-network.php
/var/www/wordpress/wp-admin/ms-users.php
/var/www/wordpress/wp-admin/my-sites.php
/var/www/wordpress/wp-admin/nav-menus.php
/var/www/wordpress/wp-admin/network.php
/var/www/wordpress/wp-admin/options-discussion.php
/var/www/wordpress/wp-admin/options-general.php
/var/www/wordpress/wp-admin/options-head.php
/var/www/wordpress/wp-admin/options-media.php
/var/www/wordpress/wp-admin/options-permalink.php
/var/www/wordpress/wp-admin/options-privacy.php
/var/www/wordpress/wp-admin/options-reading.php
/var/www/wordpress/wp-admin/options-writing.php
/var/www/wordpress/wp-admin/options.php
/var/www/wordpress/wp-admin/plugin-editor.php
/var/www/wordpress/wp-admin/plugin-install.php
/var/www/wordpress/wp-admin/plugins.php
/var/www/wordpress/wp-admin/post-new.php
/var/www/wordpress/wp-admin/post.php
/var/www/wordpress/wp-admin/press-this.php
/var/www/wordpress/wp-admin/profile.php
/var/www/wordpress/wp-admin/revision.php
/var/www/wordpress/wp-admin/setup-config.php
/var/www/wordpress/wp-admin/sidebar.php
/var/www/wordpress/wp-admin/theme-editor.php
/var/www/wordpress/wp-admin/theme-install.php
/var/www/wordpress/wp-admin/themes.php
/var/www/wordpress/wp-admin/tools.php
/var/www/wordpress/wp-admin/update-core.php
/var/www/wordpress/wp-admin/update.php
/var/www/wordpress/wp-admin/upgrade-functions.php
/var/www/wordpress/wp-admin/upgrade.php
/var/www/wordpress/wp-admin/upload.php
/var/www/wordpress/wp-admin/user-edit.php
/var/www/wordpress/wp-admin/user-new.php
/var/www/wordpress/wp-admin/users.php
/var/www/wordpress/wp-admin/widgets.php
/var/www/wordpress/wp-content/languages/ru_RU.php
/var/www/wordpress/wp-content/plugins/akismet/akismet.php
/var/www/wordpress/wp-content/plugins/rh/rh.php
/var/www/wordpress/wp-content/plugins/hello.php
/var/www/wordpress/wp-content/plugins/index.php
/var/www/wordpress/wp-content/themes/twentyten/404.php
/var/www/wordpress/wp-content/themes/twentyten/archive.php
/var/www/wordpress/wp-content/themes/twentyten/attachment.php
/var/www/wordpress/wp-content/themes/twentyten/author.php
/var/www/wordpress/wp-content/themes/twentyten/category.php
/var/www/wordpress/wp-content/themes/twentyten/comments.php
/var/www/wordpress/wp-content/themes/twentyten/footer.php
/var/www/wordpress/wp-content/themes/twentyten/functions.php
/var/www/wordpress/wp-content/themes/twentyten/header.php
/var/www/wordpress/wp-content/themes/twentyten/index.php
/var/www/wordpress/wp-content/themes/twentyten/loop.php
/var/www/wordpress/wp-content/themes/twentyten/onecolumn-page.php
/var/www/wordpress/wp-content/themes/twentyten/page.php
/var/www/wordpress/wp-content/themes/twentyten/search.php
/var/www/wordpress/wp-content/themes/twentyten/sidebar-footer.php
/var/www/wordpress/wp-content/themes/twentyten/sidebar.php
/var/www/wordpress/wp-content/themes/twentyten/single.php
/var/www/wordpress/wp-content/themes/twentyten/tag.php
/var/www/wordpress/wp-content/themes/index.php
/var/www/wordpress/wp-content/index.php
/var/www/wordpress/wp-includes/js/tinymce/langs/wp-langs.php
/var/www/wordpress/wp-includes/js/tinymce/plugins/spellchecker/classes/utils/JSON.php
/var/www/wordpress/wp-includes/js/tinymce/plugins/spellchecker/classes/utils/Logger.php
/var/www/wordpress/wp-includes/js/tinymce/plugins/spellchecker/classes/EnchantSpell.php
/var/www/wordpress/wp-includes/js/tinymce/plugins/spellchecker/classes/GoogleSpell.php
/var/www/wordpress/wp-includes/js/tinymce/plugins/spellchecker/classes/PSpell.php
/var/www/wordpress/wp-includes/js/tinymce/plugins/spellchecker/classes/PSpellShell.php
/var/www/wordpress/wp-includes/js/tinymce/plugins/spellchecker/classes/SpellChecker.php
/var/www/wordpress/wp-includes/js/tinymce/plugins/spellchecker/includes/general.php
/var/www/wordpress/wp-includes/js/tinymce/plugins/spellchecker/config.php
/var/www/wordpress/wp-includes/js/tinymce/plugins/spellchecker/rpc.php
/var/www/wordpress/wp-includes/js/tinymce/wp-mce-help.php
/var/www/wordpress/wp-includes/js/tinymce/wp-tinymce.php
/var/www/wordpress/wp-includes/pomo/entry.php
/var/www/wordpress/wp-includes/pomo/mo.php
/var/www/wordpress/wp-includes/pomo/po.php
/var/www/wordpress/wp-includes/pomo/streams.php
/var/www/wordpress/wp-includes/pomo/translations.php
/var/www/wordpress/wp-includes/Text/Diff/Engine/native.php
/var/www/wordpress/wp-includes/Text/Diff/Engine/shell.php
/var/www/wordpress/wp-includes/Text/Diff/Engine/string.php
/var/www/wordpress/wp-includes/Text/Diff/Engine/xdiff.php
/var/www/wordpress/wp-includes/Text/Diff/Renderer/inline.php
/var/www/wordpress/wp-includes/Text/Diff/Renderer.php
/var/www/wordpress/wp-includes/Text/Diff.php
/var/www/wordpress/wp-includes/theme-compat/comments-popup.php
/var/www/wordpress/wp-includes/theme-compat/comments.php
/var/www/wordpress/wp-includes/theme-compat/footer.php
/var/www/wordpress/wp-includes/theme-compat/header.php
/var/www/wordpress/wp-includes/theme-compat/sidebar.php
/var/www/wordpress/wp-includes/atomlib.php
/var/www/wordpress/wp-includes/author-template.php
/var/www/wordpress/wp-includes/bookmark-template.php
/var/www/wordpress/wp-includes/bookmark.php
/var/www/wordpress/wp-includes/cache.php
/var/www/wordpress/wp-includes/canonical.php
/var/www/wordpress/wp-includes/capabilities.php
/var/www/wordpress/wp-includes/category-template.php
/var/www/wordpress/wp-includes/category.php
/var/www/wordpress/wp-includes/class-feed.php
/var/www/wordpress/wp-includes/class-http.php
/var/www/wordpress/wp-includes/class-IXR.php
/var/www/wordpress/wp-includes/class-json.php
/var/www/wordpress/wp-includes/class-oembed.php
/var/www/wordpress/wp-includes/class-phpass.php
/var/www/wordpress/wp-includes/class-phpmailer.php
/var/www/wordpress/wp-includes/class-pop3.php
/var/www/wordpress/wp-includes/class-simplepie.php
/var/www/wordpress/wp-includes/class-smtp.php
/var/www/wordpress/wp-includes/class-snoopy.php
/var/www/wordpress/wp-includes/class.wp-dependencies.php
/var/www/wordpress/wp-includes/class.wp-scripts.php
/var/www/wordpress/wp-includes/class.wp-styles.php
/var/www/wordpress/wp-includes/classes.php
/var/www/wordpress/wp-includes/comment-template.php
/var/www/wordpress/wp-includes/comment.php
/var/www/wordpress/wp-includes/compat.php
/var/www/wordpress/wp-includes/cron.php
/var/www/wordpress/wp-includes/default-constants.php
/var/www/wordpress/wp-includes/default-embeds.php
/var/www/wordpress/wp-includes/default-filters.php
/var/www/wordpress/wp-includes/default-widgets.php
/var/www/wordpress/wp-includes/deprecated.php
/var/www/wordpress/wp-includes/feed-atom-comments.php
/var/www/wordpress/wp-includes/feed-atom.php
/var/www/wordpress/wp-includes/feed-rdf.php
/var/www/wordpress/wp-includes/feed-rss.php
/var/www/wordpress/wp-includes/feed-rss2-comments.php
/var/www/wordpress/wp-includes/feed-rss2.php
/var/www/wordpress/wp-includes/feed.php
/var/www/wordpress/wp-includes/formatting.php
/var/www/wordpress/wp-includes/functions.php
/var/www/wordpress/wp-includes/functions.wp-scripts.php
/var/www/wordpress/wp-includes/functions.wp-styles.php
/var/www/wordpress/wp-includes/general-template.php
/var/www/wordpress/wp-includes/http.php
/var/www/wordpress/wp-includes/kses.php
/var/www/wordpress/wp-includes/l10n.php
/var/www/wordpress/wp-includes/link-template.php
/var/www/wordpress/wp-includes/load.php
/var/www/wordpress/wp-includes/locale.php
/var/www/wordpress/wp-includes/media.php
/var/www/wordpress/wp-includes/meta.php
/var/www/wordpress/wp-includes/ms-blogs.php
/var/www/wordpress/wp-includes/ms-default-constants.php
/var/www/wordpress/wp-includes/ms-default-filters.php
/var/www/wordpress/wp-includes/ms-deprecated.php
/var/www/wordpress/wp-includes/ms-files.php
/var/www/wordpress/wp-includes/ms-functions.php
#CodeDescriptions
1<?php
2/**
3 * Multi-site WordPress API
4 *
5 * @package WordPress
6 * @subpackage Multisite
7 * @since 3.0.0
8 */
9
10function get_sitestats() {
11 global $wpdb;
12
13 $stats['blogs'] = get_blog_count();
14
15 $count_ts = get_site_option( 'user_count_ts' );
16 if ( time() - $count_ts > 3600 ) {
17 $count = $wpdb->get_var( "SELECT COUNT(ID) FROM $wpdb->users" );
18 update_site_option( 'user_count', $count );
19 update_site_option( 'user_count_ts', time() );
20 } else {
21 $count = get_site_option( 'user_count' );
22 }
23 $stats['users'] = $count;
24 return $stats;
25}
26
27function get_admin_users_for_domain( $sitedomain = '', $path = '' ) {
28 global $wpdb;
29
30 if ( ! $sitedomain )
31 $site_id = $wpdb->siteid;
32 else
33 $site_id = $wpdb->get_var( $wpdb->prepare( "SELECT id FROM $wpdb->site WHERE domain = %s AND path = %s", $sitedomain, $path ) );
34
35 if ( $site_id )
36 return $wpdb->get_results( $wpdb->prepare( "SELECT u.ID, u.user_login, u.user_pass FROM $wpdb->users AS u, $wpdb->sitemeta AS sm WHERE sm.meta_key = 'admin_user_id' AND u.ID = sm.meta_value AND sm.site_id = %d", $site_id ), ARRAY_A );
37
38 return false;
39}
40
41function get_blogs_of_user( $id, $all = false ) {
42 global $wpdb;
43
44 $cache_suffix = $all ? '_all' : '_short';
45 $return = wp_cache_get( 'blogs_of_user_' . $id . $cache_suffix, 'users' );
46 if ( $return )
47 return apply_filters( 'get_blogs_of_user', $return, $id, $all );
48
49 $user = get_userdata( (int) $id );
50 if ( !$user )
51 return false;
52
53 $blogs = $match = array();
54 $prefix_length = strlen($wpdb->base_prefix);
55 foreach ( (array) $user as $key => $value ) {
56 if ( $prefix_length && substr($key, 0, $prefix_length) != $wpdb->base_prefix )
57 continue;
58 if ( substr($key, -12, 12) != 'capabilities' )
59 continue;
60 if ( preg_match( '/^' . $wpdb->base_prefix . '((\d+)_)?capabilities$/', $key, $match ) ) {
61 if ( count( $match ) > 2 )
62 $blog_id = $match[ 2 ];
63 else
64 $blog_id = 1;
65 $blog = get_blog_details( $blog_id );
66 if ( $blog && isset( $blog->domain ) && ( $all == true || $all == false && ( $blog->archived == 0 && $blog->spam == 0 && $blog->deleted == 0 ) ) ) {
67 $blogs[ $blog_id ]->userblog_id = $blog_id;
68 $blogs[ $blog_id ]->blogname = $blog->blogname;
69 $blogs[ $blog_id ]->domain = $blog->domain;
70 $blogs[ $blog_id ]->path = $blog->path;
71 $blogs[ $blog_id ]->site_id = $blog->site_id;
72 $blogs[ $blog_id ]->siteurl = $blog->siteurl;
73 }
74 }
75 }
76
77 wp_cache_add( 'blogs_of_user_' . $id . $cache_suffix, $blogs, 'users', 5 );
78 return apply_filters( 'get_blogs_of_user', $blogs, $id, $all );
79}
80
81function get_active_blog_for_user( $user_id ) { // get an active blog for user - either primary blog or from blogs list
82 global $wpdb;
83 $blogs = get_blogs_of_user( $user_id );
84 if ( empty( $blogs ) ) {
85 $details = get_dashboard_blog();
86 add_user_to_blog( $details->blog_id, $user_id, 'subscriber' );
87 update_user_meta( $user_id, 'primary_blog', $details->blog_id );
88 wp_cache_delete( $user_id, 'users' );
89 return $details;
90 }
91
92 $primary_blog = get_user_meta( $user_id, 'primary_blog', true );
93 $details = get_dashboard_blog();
94 if ( $primary_blog ) {
95 $blogs = get_blogs_of_user( $user_id );
96 if ( isset( $blogs[ $primary_blog ] ) == false ) {
97 add_user_to_blog( $details->blog_id, $user_id, 'subscriber' );
98 update_user_meta( $user_id, 'primary_blog', $details->blog_id );
99 wp_cache_delete( $user_id, 'users' );
100 } else {
101 $details = get_blog_details( $primary_blog );
102 }
103 } else {
104 add_user_to_blog( $details->blog_id, $user_id, 'subscriber' ); // Add subscriber permission for dashboard blog
105 update_user_meta( $user_id, 'primary_blog', $details->blog_id );
106 }
107
108 if ( ( is_object( $details ) == false ) || ( is_object( $details ) && $details->archived == 1 || $details->spam == 1 || $details->deleted == 1 ) ) {
109 $blogs = get_blogs_of_user( $user_id, true ); // if a user's primary blog is shut down, check their other blogs.
110 $ret = false;
111 if ( is_array( $blogs ) && count( $blogs ) > 0 ) {
112 foreach ( (array) $blogs as $blog_id => $blog ) {
113 if ( $blog->site_id != $wpdb->siteid )
114 continue;
115 $details = get_blog_details( $blog_id );
116 if ( is_object( $details ) && $details->archived == 0 && $details->spam == 0 && $details->deleted == 0 ) {
117 $ret = $blog;
118 $changed = false;
119 if ( get_user_meta( $user_id , 'primary_blog', true ) != $blog_id ) {
120 update_user_meta( $user_id, 'primary_blog', $blog_id );
121 $changed = true;
122 }
123 if ( !get_user_meta($user_id , 'source_domain', true) ) {
124 update_user_meta( $user_id, 'source_domain', $blog->domain );
125 $changed = true;
126 }
127 if ( $changed )
128 wp_cache_delete( $user_id, 'users' );
129 break;
130 }
131 }
132 } else {
133 // Should never get here
134 $dashboard_blog = get_dashboard_blog();
135 add_user_to_blog( $dashboard_blog->blog_id, $user_id, 'subscriber' ); // Add subscriber permission for dashboard blog
136 update_user_meta( $user_id, 'primary_blog', $dashboard_blog->blog_id );
137 return $dashboard_blog;
138 }
139 return $ret;
140 } else {
141 return $details;
142 }
143}
144
145function is_user_member_of_blog( $user_id, $blog_id = 0 ) {
146 $user_id = (int) $user_id;
147 $blog_id = (int) $blog_id;
148
149 if ( $blog_id == 0 ) {
150 global $wpdb;
151 $blog_id = $wpdb->blogid;
152 }
153
154 $blogs = get_blogs_of_user( $user_id );
155 if ( is_array( $blogs ) )
156 return array_key_exists( $blog_id, $blogs );
157 else
158 return false;
159}
160
161function get_user_count() {
162 global $wpdb;
163
164 $count_ts = get_site_option( 'user_count_ts' );
165 if ( time() - $count_ts > 3600 ) {
166 $count = $wpdb->get_var( $wpdb->prepare("SELECT COUNT(ID) as c FROM $wpdb->users WHERE spam = '0' AND deleted = '0'") );
167 update_site_option( 'user_count', $count );
168 update_site_option( 'user_count_ts', time() );
169 }
170
171 $count = get_site_option( 'user_count' );
172
173 return $count;
174}
175
176function get_blog_count( $id = 0 ) {
177 global $wpdb;
178
179 if ( $id == 0 )
180 $id = $wpdb->siteid;
181
182 $count_ts = get_site_option( 'blog_count_ts' );
183 if ( time() - $count_ts > 3600 ) {
184 $count = $wpdb->get_var( $wpdb->prepare("SELECT COUNT(blog_id) as c FROM $wpdb->blogs WHERE site_id = %d AND spam = '0' AND deleted = '0' and archived = '0'", $id) );
185 update_site_option( 'blog_count', $count );
186 update_site_option( 'blog_count_ts', time() );
187 }
188
189 $count = get_site_option( 'blog_count' );
190
191 return $count;
192}
193
194function get_blog_post( $blog_id, $post_id ) {
195 global $wpdb;
196
197 $key = $blog_id . '-' . $post_id;
198 $post = wp_cache_get( $key, 'global-posts' );
199 if ( $post == false ) {
200 $post = $wpdb->get_row( $wpdb->prepare( 'SELECT * FROM ' . $wpdb->get_blog_prefix( $blog_id ) . 'posts WHERE ID = %d', $post_id ) );
201 wp_cache_add( $key, $post, 'global-posts' );
202 }
203
204 return $post;
205}
206
207function add_user_to_blog( $blog_id, $user_id, $role ) {
208 switch_to_blog($blog_id);
209
210 $user = new WP_User($user_id);
211
212 if ( empty( $user->ID ) )
213 return new WP_Error('user_does_not_exist', __('That user does not exist.'));
214
215 if ( !get_user_meta($user_id, 'primary_blog', true) ) {
216 update_user_meta($user_id, 'primary_blog', $blog_id);
217 $details = get_blog_details($blog_id);
218 update_user_meta($user_id, 'source_domain', $details->domain);
219 }
220
221 $user->set_role($role);
222
223 do_action('add_user_to_blog', $user_id, $role, $blog_id);
224 wp_cache_delete( $user_id, 'users' );
225 restore_current_blog();
226 return true;
227}
228
229function remove_user_from_blog($user_id, $blog_id = '', $reassign = '') {
230 global $wpdb;
231 switch_to_blog($blog_id);
232 $user_id = (int) $user_id;
233 do_action('remove_user_from_blog', $user_id, $blog_id);
234
235 // If being removed from the primary blog, set a new primary if the user is assigned
236 // to multiple blogs.
237 $primary_blog = get_user_meta($user_id, 'primary_blog', true);
238 if ( $primary_blog == $blog_id ) {
239 $new_id = '';
240 $new_domain = '';
241 $blogs = get_blogs_of_user($user_id);
242 foreach ( (array) $blogs as $blog ) {
243 if ( $blog->userblog_id == $blog_id )
244 continue;
245 $new_id = $blog->userblog_id;
246 $new_domain = $blog->domain;
247 break;
248 }
249
250 update_user_meta($user_id, 'primary_blog', $new_id);
251 update_user_meta($user_id, 'source_domain', $new_domain);
252 }
253
254 // wp_revoke_user($user_id);
255 $user = new WP_User($user_id);
256 if ( empty( $user->ID ) )
257 return new WP_Error('user_does_not_exist', __('That user does not exist.'));
258
259 $user->remove_all_caps();
260
261 $blogs = get_blogs_of_user($user_id);
262 if ( count($blogs) == 0 ) {
263 update_user_meta($user_id, 'primary_blog', '');
264 update_user_meta($user_id, 'source_domain', '');
265 }
266
267 if ( $reassign != '' ) {
268 $reassign = (int) $reassign;
269 $wpdb->query( $wpdb->prepare("UPDATE $wpdb->posts SET post_author = %d WHERE post_author = %d", $reassign, $user_id) );
270 $wpdb->query( $wpdb->prepare("UPDATE $wpdb->links SET link_owner = %d WHERE link_owner = %d", $reassign, $user_id) );
271 }
272
273 restore_current_blog();
274}
275
276function create_empty_blog( $domain, $path, $weblog_title, $site_id = 1 ) {
277 $domain = addslashes( $domain );
278 $weblog_title = addslashes( $weblog_title );
279
280 if ( empty($path) )
281 $path = '/';
282
283 // Check if the domain has been used already. We should return an error message.
284 if ( domain_exists($domain, $path, $site_id) )
285 return __( 'Error: Site URL already taken.' );
286
287 // Need to backup wpdb table names, and create a new wp_blogs entry for new blog.
288 // Need to get blog_id from wp_blogs, and create new table names.
289 // Must restore table names at the end of function.
290
291 if ( ! $blog_id = insert_blog($domain, $path, $site_id) )
292 return __( 'Error: problem creating site entry.' );
293
294 switch_to_blog($blog_id);
295 install_blog($blog_id);
296 restore_current_blog();
297
298 return $blog_id;
299}
300
301function get_blog_permalink( $_blog_id, $post_id ) {
302 $key = "{$_blog_id}-{$post_id}-blog_permalink";
303 $link = wp_cache_get( $key, 'site-options' );
304 if ( $link == false ) {
305 switch_to_blog( $_blog_id );
306 $link = get_permalink( $post_id );
307 restore_current_blog();
308 wp_cache_add( $key, $link, 'site-options', 360 );
309 }
310 return $link;
311}
312
313function get_blog_id_from_url( $domain, $path = '/' ) {
314 global $wpdb;
315
316 $domain = strtolower( $wpdb->escape( $domain ) );
317 $path = strtolower( $wpdb->escape( $path ) );
318 $id = wp_cache_get( md5( $domain . $path ), 'blog-id-cache' );
319
320 if ( $id == -1 ) { // blog does not exist
321 return 0;
322 } elseif ( $id ) {
323 return (int)$id;
324 }
325
326 $id = $wpdb->get_var( "SELECT blog_id FROM $wpdb->blogs WHERE domain = '$domain' and path = '$path' /* get_blog_id_from_url */" );
327
328 if ( !$id ) {
329 wp_cache_set( md5( $domain . $path ), -1, 'blog-id-cache' );
330 return false;
331 }
332 wp_cache_set( md5( $domain . $path ), $id, 'blog-id-cache' );
333
334 return $id;
335}
336
337// wpmu admin functions
338
339function wpmu_admin_do_redirect( $url = '' ) {
340 $ref = '';
341 if ( isset( $_GET['ref'] ) )
342 $ref = $_GET['ref'];
343 if ( isset( $_POST['ref'] ) )
344 $ref = $_POST['ref'];
345
346 if ( $ref ) {
347 $ref = wpmu_admin_redirect_add_updated_param( $ref );
348 wp_redirect( $ref );
349 exit();
350 }
351 if ( empty( $_SERVER['HTTP_REFERER'] ) == false ) {
352 wp_redirect( $_SERVER['HTTP_REFERER'] );
353 exit();
354 }
355
356 $url = wpmu_admin_redirect_add_updated_param( $url );
357 if ( isset( $_GET['redirect'] ) ) {
358 if ( substr( $_GET['redirect'], 0, 2 ) == 's_' )
359 $url .= '&action=blogs&s='. esc_html( substr( $_GET['redirect'], 2 ) );
360 } elseif ( isset( $_POST['redirect'] ) ) {
361 $url = wpmu_admin_redirect_add_updated_param( $_POST['redirect'] );
362 }
363 wp_redirect( $url );
364 exit();
365}
366
367function wpmu_admin_redirect_add_updated_param( $url = '' ) {
368 if ( strpos( $url, 'updated=true' ) === false ) {
369 if ( strpos( $url, '?' ) === false )
370 return $url . '?updated=true';
371 else
372 return $url . '&updated=true';
373 }
374 return $url;
375}
376
377function is_blog_user( $blog_id = 0 ) {
378 global $wpdb;
379
380 $current_user = wp_get_current_user();
381 if ( !$blog_id )
382 $blog_id = $wpdb->blogid;
383
384 $cap_key = $wpdb->base_prefix . $blog_id . '_capabilities';
385
386 if ( is_array($current_user->$cap_key) && in_array(1, $current_user->$cap_key) )
387 return true;
388
389 return false;
390}
391
392function is_email_address_unsafe( $user_email ) {
393 $banned_names = get_site_option( 'banned_email_domains' );
394 if ($banned_names && !is_array( $banned_names ))
395 $banned_names = explode( "\n", $banned_names);
396
397 if ( is_array( $banned_names ) && empty( $banned_names ) == false ) {
398 $email_domain = strtolower( substr( $user_email, 1 + strpos( $user_email, '@' ) ) );
399 foreach ( (array) $banned_names as $banned_domain ) {
400 if ( $banned_domain == '' )
401 continue;
402 if (
403 strstr( $email_domain, $banned_domain ) ||
404 (
405 strstr( $banned_domain, '/' ) &&
406 preg_match( $banned_domain, $email_domain )
407 )
408 )
409 return true;
410 }
411 }
412 return false;
413}
414
415function wpmu_validate_user_signup($user_name, $user_email) {
416 global $wpdb;
417
418 $errors = new WP_Error();
419
420 $orig_username = $user_name;
421 $user_name = preg_replace( '/\s+/', '', sanitize_user( $user_name, true ) );
422 $maybe = array();
423 preg_match( '/[a-z0-9]+/', $user_name, $maybe );
424
425 if ( $user_name != $orig_username || $user_name != $maybe[0] ) {
426 $errors->add( 'user_name', __( "Only the lowercase letters a-z and numbers allowed" ) );
427 $user_name = $orig_username;
428 }
429
430 $user_email = sanitize_email( $user_email );//Connection Handling
431
432 if ( empty( $user_name ) )
433 $errors->add('user_name', __('Please enter a username'));
434
435 $illegal_names = get_site_option( 'illegal_names' );
436 if ( is_array( $illegal_names ) == false ) {
437 $illegal_names = array( 'www', 'web', 'root', 'admin', 'main', 'invite', 'administrator' );
438 add_site_option( 'illegal_names', $illegal_names );
439 }
440 if ( in_array( $user_name, $illegal_names ) == true )
441 $errors->add('user_name', __('That username is not allowed'));
442
443 if ( is_email_address_unsafe( $user_email ) )
444 $errors->add('user_email', __('You cannot use that email address to signup. We are having problems with them blocking some of our email. Please use another email provider.'));
445
446 if ( strlen( $user_name ) < 4 )
447 $errors->add('user_name', __('Username must be at least 4 characters'));
448
449 if ( strpos( ' ' . $user_name, '_' ) != false )
450 $errors->add( 'user_name', __( 'Sorry, usernames may not contain the character “_”!' ) );
451
452 // all numeric?
453 $match = array();
454 preg_match( '/[0-9]*/', $user_name, $match );
455 if ( $match[0] == $user_name )
456 $errors->add('user_name', __('Sorry, usernames must have letters too!'));
457
458 if ( !is_email( $user_email ) )
459 $errors->add('user_email', __('Please enter a correct email address'));
460
461 $limited_email_domains = get_site_option( 'limited_email_domains' );
462 if ( is_array( $limited_email_domains ) && empty( $limited_email_domains ) == false ) {
463 $emaildomain = substr( $user_email, 1 + strpos( $user_email, '@' ) );
464 if ( in_array( $emaildomain, $limited_email_domains ) == false )
465 $errors->add('user_email', __('Sorry, that email address is not allowed!'));
466 }
467
468 // Check if the username has been used already.
469 if ( username_exists($user_name) )
470 $errors->add('user_name', __('Sorry, that username already exists!'));
471
472 // Check if the email address has been used already.
473 if ( email_exists($user_email) )
474 $errors->add('user_email', __('Sorry, that email address is already used!'));
475
476 // Has someone already signed up for this username?
477 $signup = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->signups WHERE user_login = %s", $user_name) );
478 if ( $signup != null ) {
479 $registered_at = mysql2date('U', $signup->registered);
480 $now = current_time( 'timestamp', true );
481 $diff = $now - $registered_at;
482 // If registered more than two days ago, cancel registration and let this signup go through.
483 if ( $diff > 172800 )
484 $wpdb->query( $wpdb->prepare("DELETE FROM $wpdb->signups WHERE user_login = %s", $user_name) );
485 else
486 $errors->add('user_name', __('That username is currently reserved but may be available in a couple of days.'));
487
488 if ( $signup->active == 0 && $signup->user_email == $user_email )
489 $errors->add('user_email_used', __('username and email used'));
490 }
491
492 $signup = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->signups WHERE user_email = %s", $user_email) );
493 if ( $signup != null ) {
494 $diff = current_time( 'timestamp', true ) - mysql2date('U', $signup->registered);
495 // If registered more than two days ago, cancel registration and let this signup go through.
496 if ( $diff > 172800 )
497 $wpdb->query( $wpdb->prepare("DELETE FROM $wpdb->signups WHERE user_email = %s", $user_email) );
498 else
499 $errors->add('user_email', __('That email address has already been used. Please check your inbox for an activation email. It will become available in a couple of days if you do nothing.'));
500 }
501
502 $result = array('user_name' => $user_name, 'orig_username' => $orig_username, 'user_email' => $user_email, 'errors' => $errors);//Connection Handling
503
504 return apply_filters('wpmu_validate_user_signup', $result);
505}
506
507function wpmu_validate_blog_signup($blogname, $blog_title, $user = '') {
508 global $wpdb, $domain, $base, $current_site;
509
510 $blog_title = strip_tags( $blog_title );
511 $blog_title = substr( $blog_title, 0, 50 );
512
513 $errors = new WP_Error();
514 $illegal_names = get_site_option( 'illegal_names' );
515 if ( $illegal_names == false ) {
516 $illegal_names = array( 'www', 'web', 'root', 'admin', 'main', 'invite', 'administrator' );
517 add_site_option( 'illegal_names', $illegal_names );
518 }
519
520 // On sub dir installs, Some names are so illegal, only a filter can spring them from jail
521 if (! is_subdomain_install() )
522 $illegal_names = array_merge($illegal_names, apply_filters( 'subdirectory_reserved_names', array( 'page', 'comments', 'blog', 'files', 'feed' ) ) );
523
524
525 if ( empty( $blogname ) )
526 $errors->add('blogname', __('Please enter a site name'));
527
528 $maybe = array();
529 preg_match( '/[a-z0-9]+/', $blogname, $maybe );
530 if ( $blogname != $maybe[0] )
531 $errors->add('blogname', __('Only lowercase letters and numbers allowed'));
532
533 if ( in_array( $blogname, $illegal_names ) == true )
534 $errors->add('blogname', __('That name is not allowed'));
535
536 if ( strlen( $blogname ) < 4 && !is_super_admin() )
537 $errors->add('blogname', __('Site name must be at least 4 characters'));
538
539 if ( strpos( ' ' . $blogname, '_' ) != false )
540 $errors->add( 'blogname', __( 'Sorry, site names may not contain the character “_”!' ) );
541
542 // do not allow users to create a blog that conflicts with a page on the main blog.
543 if ( !is_subdomain_install() && $wpdb->get_var( $wpdb->prepare( "SELECT post_name FROM " . $wpdb->get_blog_prefix( $current_site->blog_id ) . "posts WHERE post_type = 'page' AND post_name = %s", $blogname ) ) )
544 $errors->add( 'blogname', __( 'Sorry, you may not use that site name.' ) );
545
546 // all numeric?
547 $match = array();
548 preg_match( '/[0-9]*/', $blogname, $match );
549 if ( $match[0] == $blogname )
550 $errors->add('blogname', __('Sorry, site names must have letters too!'));
551
552 $blogname = apply_filters( 'newblogname', $blogname );
553
554 $blog_title = stripslashes( $blog_title );
555
556 if ( empty( $blog_title ) )
557 $errors->add('blog_title', __('Please enter a site title'));
558
559 // Check if the domain/path has been used already.
560 if ( is_subdomain_install() ) {
561 $mydomain = $blogname . '.' . preg_replace( '|^www\.|', '', $domain );
562 $path = $base;
563 } else {
564 $mydomain = "$domain";
565 $path = $base.$blogname.'/';
566 }
567 if ( domain_exists($mydomain, $path) )
568 $errors->add('blogname', __('Sorry, that site already exists!'));
569
570 if ( username_exists( $blogname ) ) {
571 if ( is_object( $user ) == false || ( is_object($user) && ( $user->user_login != $blogname ) ) )
572 $errors->add( 'blogname', __( 'Sorry, that site is reserved!' ) );
573 }
574
575 // Has someone already signed up for this domain?
576 $signup = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->signups WHERE domain = %s AND path = %s", $mydomain, $path) ); // TODO: Check email too?
577 if ( ! empty($signup) ) {
578 $diff = current_time( 'timestamp', true ) - mysql2date('U', $signup->registered);
579 // If registered more than two days ago, cancel registration and let this signup go through.
580 if ( $diff > 172800 )
581 $wpdb->query( $wpdb->prepare("DELETE FROM $wpdb->signups WHERE domain = %s AND path = %s", $mydomain, $path) );
582 else
583 $errors->add('blogname', __('That site is currently reserved but may be available in a couple days.'));
584 }
585
586 $result = array('domain' => $mydomain, 'path' => $path, 'blogname' => $blogname, 'blog_title' => $blog_title, 'errors' => $errors);
587 return apply_filters('wpmu_validate_blog_signup', $result);
588}
589
590// Record signup information for future activation. wpmu_validate_signup() should be run
591// on the inputs before calling wpmu_signup().
592function wpmu_signup_blog($domain, $path, $title, $user, $user_email, $meta = '') {
593 global $wpdb;
594
595 $key = substr( md5( time() . rand() . $domain ), 0, 16 );
596 $meta = serialize($meta);
597 $domain = $wpdb->escape($domain);
598 $path = $wpdb->escape($path);
599 $title = $wpdb->escape($title);
600
601 $wpdb->insert( $wpdb->signups, array(
602 'domain' => $domain,
603 'path' => $path,
604 'title' => $title,
605 'user_login' => $user,
606 'user_email' => $user_email,
607 'registered' => current_time('mysql', true),
608 'activation_key' => $key,
609 'meta' => $meta
610 ) );
611
612 wpmu_signup_blog_notification($domain, $path, $title, $user, $user_email, $key, $meta);//Connection Handling
613}
614
615function wpmu_signup_user($user, $user_email, $meta = '') {
616 global $wpdb;
617
618 // Format data
619 $user = preg_replace( '/\s+/', '', sanitize_user( $user, true ) );
620 $user_email = sanitize_email( $user_email );//Connection Handling
621 $key = substr( md5( time() . rand() . $user_email ), 0, 16 );
622 $meta = serialize($meta);
623
624 $wpdb->insert( $wpdb->signups, array(
625 'domain' => '',
626 'path' => '',
627 'title' => '',
628 'user_login' => $user,
629 'user_email' => $user_email,
630 'registered' => current_time('mysql', true),
631 'activation_key' => $key,
632 'meta' => $meta
633 ) );
634
635 wpmu_signup_user_notification($user, $user_email, $key, $meta);//Connection Handling
636}
637
638// Notify user of signup success.
639function wpmu_signup_blog_notification($domain, $path, $title, $user, $user_email, $key, $meta = '') {
640 global $current_site;
641
642 if ( !apply_filters('wpmu_signup_blog_notification', $domain, $path, $title, $user, $user_email, $key, $meta) )
643 return false;
644
645 // Send email with activation link.
646 if ( !is_subdomain_install() || $current_site->id != 1 )
647 $activate_url = network_site_url("wp-activate.php?key=$key");
648 else
649 $activate_url = "http://{$domain}{$path}wp-activate.php?key=$key"; // @todo use *_url() API
650
651 $activate_url = esc_url($activate_url);
652 $admin_email = get_site_option( 'admin_email' );
653 if ( $admin_email == '' )
654 $admin_email = 'support@' . $_SERVER['SERVER_NAME'];
655 $from_name = get_site_option( 'site_name' ) == '' ? 'WordPress' : esc_html( get_site_option( 'site_name' ) );
656 $message_headers = "From: \"{$from_name}\" <{$admin_email}>\n" . "Content-Type: text/plain; charset=\"" . get_option('blog_charset') . "\"\n";
657 $message = sprintf( apply_filters( 'wpmu_signup_blog_notification_email', __( "To activate your blog, please click the following link:\n\n%s\n\nAfter you activate, you will receive *another email* with your login.\n\nAfter you activate, you can visit your site here:\n\n%s" ) ), $activate_url, esc_url( "http://{$domain}{$path}" ), $key );
658 // TODO: Don't hard code activation link.
659 $subject = sprintf( apply_filters( 'wpmu_signup_blog_notification_subject', __( '[%1$s] Activate %2$s' ) ), $from_name, esc_url( 'http://' . $domain . $path ) );
660 wp_mail($user_email, $subject, $message, $message_headers);//Connection Handling
661 return true;
662}
663
664function wpmu_signup_user_notification($user, $user_email, $key, $meta = '') {
665 if ( !apply_filters('wpmu_signup_user_notification', $user, $user_email, $key, $meta) )
666 return false;
667
668 // Send email with activation link.
669 $admin_email = get_site_option( 'admin_email' );
670 if ( $admin_email == '' )
671 $admin_email = 'support@' . $_SERVER['SERVER_NAME'];
672 $from_name = get_site_option( 'site_name' ) == '' ? 'WordPress' : esc_html( get_site_option( 'site_name' ) );
673 $message_headers = "From: \"{$from_name}\" <{$admin_email}>\n" . "Content-Type: text/plain; charset=\"" . get_option('blog_charset') . "\"\n";
674 $message = sprintf( apply_filters( 'wpmu_signup_user_notification_email', __( "To activate your user, please click the following link:\n\n%s\n\nAfter you activate, you will receive *another email* with your login.\n\n" ) ), site_url( "wp-activate.php?key=$key" ), $key );
675 // TODO: Don't hard code activation link.
676 $subject = sprintf( __( apply_filters( 'wpmu_signup_user_notification_subject', '[%1$s] Activate %2$s' ) ), $from_name, $user);
677 wp_mail($user_email, $subject, $message, $message_headers);//Connection Handling
678 return true;
679}
680
681function wpmu_activate_signup($key) {
682 global $wpdb, $current_site;
683
684 $signup = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->signups WHERE activation_key = %s", $key) );
685
686 if ( empty($signup) )
687 return new WP_Error('invalid_key', __('Invalid activation key.'));
688
689 if ( $signup->active )
690 return new WP_Error('already_active', __('The site is already active.'), $signup);
691
692 $meta = unserialize($signup->meta);//Possible Control Flow
693 $user_login = $wpdb->escape($signup->user_login);
694 $user_email = $wpdb->escape($signup->user_email);//Connection Handling
695 $password = wp_generate_password();
696
697 $user_id = username_exists($user_login);
698
699 if ( ! $user_id )
700 $user_id = wpmu_create_user($user_login, $password, $user_email);
701 else
702 $user_already_exists = true;
703
704 if ( ! $user_id )
705 return new WP_Error('create_user', __('Could not create user'), $signup);
706
707 $now = current_time('mysql', true);
708
709 if ( empty($signup->domain) ) {
710 $wpdb->update( $wpdb->signups, array('active' => 1, 'activated' => $now), array('activation_key' => $key) );
711
712 if ( isset( $user_already_exists ) )
713 return new WP_Error( 'user_already_exists', __( 'That username is already activated.' ), $signup);
714
715 wpmu_welcome_user_notification($user_id, $password, $meta);
716 $user_site = get_site_option( 'dashboard_blog', $current_site->blog_id );
717
718 if ( $user_site == false )
719 add_user_to_blog( '1', $user_id, get_site_option( 'default_user_role', 'subscriber' ) );
720 else
721 add_user_to_blog( $user_site, $user_id, get_site_option( 'default_user_role', 'subscriber' ) );
722
723 add_new_user_to_blog( $user_id, $user_email, $meta );//Connection Handling
724 do_action('wpmu_activate_user', $user_id, $password, $meta);
725 return array('user_id' => $user_id, 'password' => $password, 'meta' => $meta);
726 }
727
728 $blog_id = wpmu_create_blog( $signup->domain, $signup->path, $signup->title, $user_id, $meta, $wpdb->siteid );
729
730 // TODO: What to do if we create a user but cannot create a blog?
731 if ( is_wp_error($blog_id) ) {
732 // If blog is taken, that means a previous attempt to activate this blog failed in between creating the blog and
733 // setting the activation flag. Let's just set the active flag and instruct the user to reset their password.
734 if ( 'blog_taken' == $blog_id->get_error_code() ) {
735 $blog_id->add_data( $signup );
736 $wpdb->update( $wpdb->signups, array( 'active' => 1, 'activated' => $now ), array( 'activation_key' => $key ) );
737 }
738 return $blog_id;
739 }
740
741 $wpdb->update( $wpdb->signups, array('active' => 1, 'activated' => $now), array('activation_key' => $key) );
742 wpmu_welcome_notification($blog_id, $user_id, $password, $signup->title, $meta);
743 do_action('wpmu_activate_blog', $blog_id, $user_id, $password, $signup->title, $meta);
744
745 return array('blog_id' => $blog_id, 'user_id' => $user_id, 'password' => $password, 'title' => $signup->title, 'meta' => $meta);
746}
747
748function wpmu_create_user( $user_name, $password, $email) {
749 $user_name = preg_replace( '/\s+/', '', sanitize_user( $user_name, true ) );
750
751 $user_id = wp_create_user( $user_name, $password, $email );
752 if ( is_wp_error($user_id) )
753 return false;
754
755 // Newly created users have no roles or caps until they are added to a blog.
756 delete_user_option( $user_id, 'capabilities' );
757 delete_user_option( $user_id, 'user_level' );
758
759 do_action( 'wpmu_new_user', $user_id );
760
761 return $user_id;
762}
763
764function wpmu_create_blog($domain, $path, $title, $user_id, $meta = '', $site_id = 1) {
765 $domain = preg_replace( '/\s+/', '', sanitize_user( $domain, true ) );
766
767 if ( is_subdomain_install() )
768 $domain = str_replace( '@', '', $domain );
769
770 $title = strip_tags( $title );
771 $user_id = (int) $user_id;
772
773 if ( empty($path) )
774 $path = '/';
775
776 // Check if the domain has been used already. We should return an error message.
777 if ( domain_exists($domain, $path, $site_id) )
778 return new WP_Error('blog_taken', __('Site already exists.'));
779
780 if ( !defined('WP_INSTALLING') )
781 define( 'WP_INSTALLING', true );
782
783 if ( ! $blog_id = insert_blog($domain, $path, $site_id) )
784 return new WP_Error('insert_blog', __('Could not create site.'));
785
786 switch_to_blog($blog_id);
787 install_blog($blog_id, $title);
788 wp_install_defaults($user_id);
789
790 add_user_to_blog($blog_id, $user_id, 'administrator');
791
792 if ( is_array($meta) ) foreach ($meta as $key => $value) {
793 if ( $key == 'public' || $key == 'archived' || $key == 'mature' || $key == 'spam' || $key == 'deleted' || $key == 'lang_id' )
794 update_blog_status( $blog_id, $key, $value );
795 else
796 update_option( $key, $value );
797 }
798
799 add_option( 'WPLANG', get_site_option( 'WPLANG' ) );
800 update_option( 'blog_public', (int)$meta['public'] );
801
802 if ( !is_super_admin() && get_user_meta( $user_id, 'primary_blog', true ) == get_site_option( 'dashboard_blog', 1 ) )
803 update_user_meta( $user_id, 'primary_blog', $blog_id );
804
805 restore_current_blog();
806 do_action( 'wpmu_new_blog', $blog_id, $user_id, $domain, $path, $site_id, $meta );
807
808 return $blog_id;
809}
810
811function newblog_notify_siteadmin( $blog_id, $deprecated = '' ) {
812 if ( get_site_option( 'registrationnotification' ) != 'yes' )
813 return false;
814
815 $email = get_site_option( 'admin_email' );
816 if ( is_email($email) == false )
817 return false;
818
819 $options_site_url = esc_url(network_admin_url('ms-options.php'));
820
821 switch_to_blog( $blog_id );
822 $blogname = get_option( 'blogname' );
823 $siteurl = site_url();
824 restore_current_blog();
825
826 $msg = sprintf( __( 'New Site: %1s
827URL: %2s
828Remote IP: %3s
829
830Disable these notifications: %4s' ), $blogname, $siteurl, $_SERVER['REMOTE_ADDR'], $options_site_url);
831 $msg = apply_filters( 'newblog_notify_siteadmin', $msg );
832
833 wp_mail( $email, sprintf( __( 'New Site Registration: %s' ), $siteurl ), $msg );//Connection Handling
834 return true;
835}
836
837function newuser_notify_siteadmin( $user_id ) {
838 if ( get_site_option( 'registrationnotification' ) != 'yes' )
839 return false;
840
841 $email = get_site_option( 'admin_email' );
842
843 if ( is_email($email) == false )
844 return false;
845
846 $user = new WP_User($user_id);
847
848 $options_site_url = esc_url(network_admin_url('ms-options.php'));
849 $msg = sprintf(__('New User: %1s
850Remote IP: %2s
851
852Disable these notifications: %3s'), $user->user_login, $_SERVER['REMOTE_ADDR'], $options_site_url);
853
854 $msg = apply_filters( 'newuser_notify_siteadmin', $msg );
855 wp_mail( $email, sprintf(__('New User Registration: %s'), $user->user_login), $msg );//Connection Handling
856 return true;
857}
858
859function domain_exists($domain, $path, $site_id = 1) {
860 global $wpdb;
861 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) );
862}
863
864function insert_blog($domain, $path, $site_id) {
865 global $wpdb;
866
867 $path = trailingslashit($path);
868 $site_id = (int) $site_id;
869
870 $result = $wpdb->insert( $wpdb->blogs, array('site_id' => $site_id, 'domain' => $domain, 'path' => $path, 'registered' => current_time('mysql')) );
871 if ( ! $result )
872 return false;
873
874 refresh_blog_details($wpdb->insert_id);
875 return $wpdb->insert_id;
876}
877
878// Install an empty blog. wpdb should already be switched.
879function install_blog($blog_id, $blog_title = '') {
880 global $wpdb, $table_prefix, $wp_roles;
881 $wpdb->suppress_errors();
882
883 // Cast for security
884 $blog_id = (int) $blog_id;
885
886 require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
887
888 if ( $wpdb->get_results("SELECT ID FROM $wpdb->posts") )
889 die(__('<h1>Already Installed</h1><p>You appear to have already installed WordPress. To reinstall please clear your old database tables first.</p>') . '</body></html>');
890
891 $wpdb->suppress_errors(false);
892
893 $url = get_blogaddress_by_id($blog_id);
894
895 // Set everything up
896 make_db_current_silent();
897 populate_options();
898 populate_roles();
899 $wp_roles->_init();
900
901 // fix url.
902 update_option('siteurl', $url);
903 update_option('home', $url);
904 update_option('fileupload_url', $url . "files" );
905 update_option('upload_path', "wp-content/blogs.dir/" . $blog_id . "/files");
906 update_option('blogname', stripslashes( $blog_title ) );
907 update_option('admin_email', '');
908 $wpdb->update( $wpdb->options, array('option_value' => ''), array('option_name' => 'admin_email') );
909
910 // remove all perms
911 $wpdb->query( $wpdb->prepare("DELETE FROM $wpdb->usermeta WHERE meta_key = %s", $table_prefix.'user_level') );
912 $wpdb->query( $wpdb->prepare("DELETE FROM $wpdb->usermeta WHERE meta_key = %s", $table_prefix.'capabilities') );
913
914 $wpdb->suppress_errors( false );
915}
916
917// Deprecated, use wp_install_defaults()
918// should be switched already as $blog_id is ignored.
919function install_blog_defaults($blog_id, $user_id) {
920 global $wpdb;
921
922 require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
923
924 $wpdb->suppress_errors();
925
926 wp_install_defaults($user_id);
927
928 $wpdb->suppress_errors( false );
929}
930
931function wpmu_welcome_notification($blog_id, $user_id, $password, $title, $meta = '') {
932 global $current_site;
933
934 if ( !apply_filters('wpmu_welcome_notification', $blog_id, $user_id, $password, $title, $meta) )
935 return false;
936
937 $welcome_email = stripslashes( get_site_option( 'welcome_email' ) );
938 if ( $welcome_email == false )
939 $welcome_email = stripslashes( __( 'Dear User,
940
941Your new SITE_NAME site has been successfully set up at:
942BLOG_URL
943
944You can log in to the administrator account with the following information:
945Username: USERNAME
946Password: PASSWORD
947Login Here: BLOG_URLwp-login.php
948
949We hope you enjoy your new site.
950Thanks!
951
952--The Team @ SITE_NAME' ) );
953
954 $url = get_blogaddress_by_id($blog_id);
955 $user = new WP_User($user_id);
956
957 $welcome_email = str_replace( 'SITE_NAME', $current_site->site_name, $welcome_email );
958 $welcome_email = str_replace( 'BLOG_TITLE', $title, $welcome_email );
959 $welcome_email = str_replace( 'BLOG_URL', $url, $welcome_email );
960 $welcome_email = str_replace( 'USERNAME', $user->user_login, $welcome_email );
961 $welcome_email = str_replace( 'PASSWORD', $password, $welcome_email );
962
963 $welcome_email = apply_filters( 'update_welcome_email', $welcome_email, $blog_id, $user_id, $password, $title, $meta);//Connection Handling
964 $admin_email = get_site_option( 'admin_email' );
965
966 if ( $admin_email == '' )
967 $admin_email = 'support@' . $_SERVER['SERVER_NAME'];
968
969 $from_name = get_site_option( 'site_name' ) == '' ? 'WordPress' : esc_html( get_site_option( 'site_name' ) );
970 $message_headers = "From: \"{$from_name}\" <{$admin_email}>\n" . "Content-Type: text/plain; charset=\"" . get_option('blog_charset') . "\"\n";
971 $message = $welcome_email;
972
973 if ( empty( $current_site->site_name ) )
974 $current_site->site_name = 'WordPress MU';
975
976 $subject = apply_filters( 'update_welcome_subject', sprintf(__('New %1$s Site: %2$s'), $current_site->site_name, stripslashes( $title ) ) );
977 wp_mail($user->user_email, $subject, $message, $message_headers);//Connection Handling
978 return true;
979}
980
981function wpmu_welcome_user_notification($user_id, $password, $meta = '') {
982 global $current_site;
983
984 if ( !apply_filters('wpmu_welcome_user_notification', $user_id, $password, $meta) )
985 return false;
986
987 $welcome_email = get_site_option( 'welcome_user_email' );
988
989 $user = new WP_User($user_id);
990
991 $welcome_email = apply_filters( 'update_welcome_user_email', $welcome_email, $user_id, $password, $meta);//Connection Handling
992 $welcome_email = str_replace( 'SITE_NAME', $current_site->site_name, $welcome_email );
993 $welcome_email = str_replace( 'USERNAME', $user->user_login, $welcome_email );
994 $welcome_email = str_replace( 'PASSWORD', $password, $welcome_email );
995 $welcome_email = str_replace( 'LOGINLINK', wp_login_url(), $welcome_email );
996
997 $admin_email = get_site_option( 'admin_email' );
998
999 if ( $admin_email == '' )
1000 $admin_email = 'support@' . $_SERVER['SERVER_NAME'];
/var/www/wordpress/wp-includes/ms-load.php
/var/www/wordpress/wp-includes/ms-settings.php
/var/www/wordpress/wp-includes/nav-menu-template.php
/var/www/wordpress/wp-includes/nav-menu.php
/var/www/wordpress/wp-includes/pluggable-deprecated.php
/var/www/wordpress/wp-includes/pluggable.php
/var/www/wordpress/wp-includes/plugin.php
/var/www/wordpress/wp-includes/post-template.php
/var/www/wordpress/wp-includes/post-thumbnail-template.php
/var/www/wordpress/wp-includes/post.php
/var/www/wordpress/wp-includes/query.php
/var/www/wordpress/wp-includes/registration-functions.php
/var/www/wordpress/wp-includes/registration.php
/var/www/wordpress/wp-includes/rewrite.php
/var/www/wordpress/wp-includes/rss-functions.php
/var/www/wordpress/wp-includes/rss.php
/var/www/wordpress/wp-includes/script-loader.php
/var/www/wordpress/wp-includes/shortcodes.php
/var/www/wordpress/wp-includes/taxonomy.php
/var/www/wordpress/wp-includes/template-loader.php
/var/www/wordpress/wp-includes/theme.php
/var/www/wordpress/wp-includes/update.php
/var/www/wordpress/wp-includes/user.php
/var/www/wordpress/wp-includes/vars.php
/var/www/wordpress/wp-includes/version.php
/var/www/wordpress/wp-includes/widgets.php
/var/www/wordpress/wp-includes/wp-db.php
/var/www/wordpress/wp-includes/wp-diff.php
/var/www/wordpress/index.php
/var/www/wordpress/wp-activate.php
/var/www/wordpress/wp-app.php
/var/www/wordpress/wp-atom.php
/var/www/wordpress/wp-blog-header.php
/var/www/wordpress/wp-comments-post.php
/var/www/wordpress/wp-commentsrss2.php
/var/www/wordpress/wp-config-sample.php
/var/www/wordpress/wp-cron.php
/var/www/wordpress/wp-feed.php
/var/www/wordpress/wp-links-opml.php
/var/www/wordpress/wp-load.php
/var/www/wordpress/wp-login.php
/var/www/wordpress/wp-mail.php
/var/www/wordpress/wp-pass.php
/var/www/wordpress/wp-rdf.php
/var/www/wordpress/wp-register.php
/var/www/wordpress/wp-rss.php
/var/www/wordpress/wp-rss2.php
/var/www/wordpress/wp-settings.php
/var/www/wordpress/wp-signup.php
/var/www/wordpress/wp-trackback.php
/var/www/wordpress/xmlrpc.php