1 | <?php |
---|
2 | /* |
---|
3 | Plugin name: Separate Blog User Tables |
---|
4 | Plugin URI: http://core.trac.wordpress.org/ticket/15467 |
---|
5 | Description: Configure and implements separate User Tables for each blog in the same Multisite Network. |
---|
6 | Author: lightningspirit |
---|
7 | Author URI: http://vcarvalho.com/ |
---|
8 | Version: 0.1 |
---|
9 | */ |
---|
10 | |
---|
11 | /** |
---|
12 | * This file actually do all do work on creating user tables for the |
---|
13 | * current blog if they are not already created. |
---|
14 | * |
---|
15 | * |
---|
16 | * |
---|
17 | * NOTE: Don't use this file in a production environment. |
---|
18 | * Not stable. Use only for test purposes. |
---|
19 | * |
---|
20 | * |
---|
21 | * |
---|
22 | * Instalation Procedure: |
---|
23 | * ---------------------- |
---|
24 | * 1. Put inside wp-contents/mu-plugins/ |
---|
25 | * |
---|
26 | * |
---|
27 | * @package WordPress |
---|
28 | * @since 3.4 |
---|
29 | */ |
---|
30 | |
---|
31 | |
---|
32 | |
---|
33 | /** |
---|
34 | * Fire on Must use plugins loading process |
---|
35 | */ |
---|
36 | add_action( 'muplugins_loaded', '_separate_blog_user_tables_create' ); |
---|
37 | |
---|
38 | |
---|
39 | /** |
---|
40 | * _separate_blog_user_tables_create |
---|
41 | * |
---|
42 | * This code will create new user tables if they are not present in |
---|
43 | * the DB for the current blog request. |
---|
44 | * TODO: replicate the administrator of the blog in those custom tables |
---|
45 | * or at least hook the authentication process to load the users |
---|
46 | * from the global users table too |
---|
47 | * |
---|
48 | * @since 0.1 |
---|
49 | * @uses dbDelta |
---|
50 | */ |
---|
51 | function _separate_blog_user_tables_create() { |
---|
52 | global $wpdb, $blog_id; |
---|
53 | |
---|
54 | /** Lets set the name of the custom Users tables */ |
---|
55 | $users_table = $wpdb->prefix . 'users'; |
---|
56 | $user_meta_table = $wpdb->prefix . 'usermeta'; |
---|
57 | |
---|
58 | |
---|
59 | /** Check if the tables were already created, if so return and have fun! :) */ |
---|
60 | if ( $wpdb->get_var( "SHOW TABLES LIKE '$users_table'" ) == $users_table ) |
---|
61 | return; |
---|
62 | |
---|
63 | |
---|
64 | /** |
---|
65 | * Hum... it seems that it is the first time that you are running |
---|
66 | * this code in the current blog... |
---|
67 | * We have to create the custom tables, lets do it! |
---|
68 | * |
---|
69 | * Require the dbDelta() function |
---|
70 | */ |
---|
71 | require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); |
---|
72 | |
---|
73 | /** Create user meta table */ |
---|
74 | dbDelta( "CREATE TABLE IF NOT EXISTS `$user_meta_table` ( |
---|
75 | `umeta_id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, |
---|
76 | `user_id` bigint(20) unsigned NOT NULL DEFAULT '0', |
---|
77 | `meta_key` varchar(255) DEFAULT NULL, |
---|
78 | `meta_value` longtext, |
---|
79 | PRIMARY KEY (`umeta_id`), |
---|
80 | KEY `user_id` (`user_id`), |
---|
81 | KEY `meta_key` (`meta_key`) |
---|
82 | );" ); |
---|
83 | |
---|
84 | /** Create users table **/ |
---|
85 | dbDelta( "CREATE TABLE IF NOT EXISTS `$users_table` ( |
---|
86 | `ID` bigint(20) unsigned NOT NULL AUTO_INCREMENT, |
---|
87 | `user_login` varchar(60) NOT NULL DEFAULT '', |
---|
88 | `user_pass` varchar(64) NOT NULL DEFAULT '', |
---|
89 | `user_nicename` varchar(50) NOT NULL DEFAULT '', |
---|
90 | `user_email` varchar(100) NOT NULL DEFAULT '', |
---|
91 | `user_url` varchar(100) NOT NULL DEFAULT '', |
---|
92 | `user_registered` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', |
---|
93 | `user_activation_key` varchar(60) NOT NULL DEFAULT '', |
---|
94 | `user_status` int(11) NOT NULL DEFAULT '0', |
---|
95 | `display_name` varchar(250) NOT NULL DEFAULT '', |
---|
96 | `spam` tinyint(2) NOT NULL DEFAULT '0', |
---|
97 | `deleted` tinyint(2) NOT NULL DEFAULT '0', |
---|
98 | PRIMARY KEY (`ID`), |
---|
99 | KEY `user_login_key` (`user_login`), |
---|
100 | KEY `user_nicename` (`user_nicename`) |
---|
101 | );" ); |
---|
102 | |
---|
103 | /** TODO: Replicate current user on those tables */ |
---|
104 | |
---|
105 | } |
---|