diff --git src/wp-includes/class-wp-roles.php src/wp-includes/class-wp-roles.php
index 23e05d7..d9654f6 100644
|
|
|
70 | 70 | public $use_db = true; |
71 | 71 | |
72 | 72 | /** |
| 73 | * What role type to get from the database |
| 74 | * |
| 75 | * @since 4.8.0 |
| 76 | * |
| 77 | * @access public |
| 78 | * @var string |
| 79 | */ |
| 80 | public $role_type = 'user_roles'; |
| 81 | |
| 82 | /** |
73 | 83 | * Constructor |
74 | 84 | * |
75 | 85 | * @since 2.0.0 |
76 | 86 | */ |
77 | | public function __construct() { |
78 | | $this->_init(); |
| 87 | public function __construct( $blog_id = null ) { |
| 88 | $this->use_db = empty( $GLOBALS['wp_user_roles'] ); |
| 89 | |
| 90 | $this->for_blog( $blog_id ); |
79 | 91 | } |
80 | 92 | |
81 | 93 | /** |
… |
… |
|
99 | 111 | * Set up the object properties. |
100 | 112 | * |
101 | 113 | * The role key is set to the current prefix for the $wpdb object with |
102 | | * 'user_roles' appended. If the $wp_user_roles global is set, then it will |
| 114 | * the role_type appended. If the $wp_user_roles global is set, then it will |
103 | 115 | * be used and the role option will not be updated or used. |
104 | 116 | * |
105 | 117 | * @since 2.1.0 |
106 | 118 | * @access protected |
107 | 119 | * |
108 | | * @global array $wp_user_roles Used to set the 'roles' property value. |
| 120 | * @param string $role_key Optional role key. |
109 | 121 | */ |
110 | | protected function _init() { |
111 | | global $wp_user_roles, $wpdb; |
| 122 | protected function _init( $role_key = '' ) { |
| 123 | global $wpdb; |
112 | 124 | |
113 | | $this->role_key = $wpdb->get_blog_prefix() . 'user_roles'; |
114 | | if ( ! empty( $wp_user_roles ) ) { |
115 | | $this->roles = $wp_user_roles; |
116 | | $this->use_db = false; |
| 125 | // Fallback on current site's prefix if no role key was passed |
| 126 | if ( empty( $role_key ) ) { |
| 127 | $this->role_key = $wpdb->get_blog_prefix() . $this->role_type; |
| 128 | } else { |
| 129 | $this->role_key = $role_key; |
| 130 | } |
| 131 | |
| 132 | // Use the $wp_user_roles global if one was set |
| 133 | if ( false === $this->use_db ) { |
| 134 | $this->roles = $GLOBALS['wp_user_roles']; |
117 | 135 | } else { |
118 | 136 | $this->roles = get_option( $this->role_key ); |
119 | 137 | } |
120 | 138 | |
121 | | if ( empty( $this->roles ) ) |
122 | | return; |
| 139 | // Set role names & objects from the roles array |
| 140 | if ( ! empty( $this->roles ) ) { |
| 141 | $this->role_objects = array(); |
| 142 | $this->role_names = array(); |
123 | 143 | |
124 | | $this->role_objects = array(); |
125 | | $this->role_names = array(); |
126 | | foreach ( array_keys( $this->roles ) as $role ) { |
127 | | $this->role_objects[$role] = new WP_Role( $role, $this->roles[$role]['capabilities'] ); |
128 | | $this->role_names[$role] = $this->roles[$role]['name']; |
| 144 | foreach ( array_keys( $this->roles ) as $role ) { |
| 145 | $this->role_objects[ $role ] = new WP_Role( $role, $this->roles[ $role ]['capabilities'] ); |
| 146 | $this->role_names[ $role ] = $this->roles[ $role ]['name']; |
| 147 | } |
129 | 148 | } |
130 | 149 | |
131 | 150 | /** |
… |
… |
|
142 | 161 | * Reinitialize the object |
143 | 162 | * |
144 | 163 | * Recreates the role objects. This is typically called only by switch_to_blog() |
145 | | * after switching wpdb to a new site ID. |
| 164 | * after switching wpdb to a new site ID, and is skipped entirely when the |
| 165 | * $wp_user_roles omega global is used. |
146 | 166 | * |
147 | 167 | * @since 3.5.0 |
148 | | * @deprecated 4.7.0 Use new WP_Roles() |
149 | 168 | * @access public |
150 | 169 | */ |
151 | 170 | public function reinit() { |
152 | | _deprecated_function( __METHOD__, '4.7.0', 'new WP_Roles()' ); |
153 | | $this->_init(); |
| 171 | if ( $this->use_db ) { |
| 172 | $this->_init(); |
| 173 | } |
| 174 | } |
| 175 | |
| 176 | /** |
| 177 | * Set the site to operate on. Defaults to the current site. |
| 178 | * |
| 179 | * @since 4.8.0 |
| 180 | * |
| 181 | * @global WPDB $wpdb |
| 182 | * |
| 183 | * @param int $blog_id Optional. The site ID to initialize for. |
| 184 | */ |
| 185 | public function for_blog( $blog_id = null ) { |
| 186 | global $wpdb; |
| 187 | |
| 188 | // Set the role_key based on the prefix for the blog_id |
| 189 | $role_key = $wpdb->get_blog_prefix( $blog_id ) . $this->role_type; |
| 190 | |
| 191 | // Initialize roles based on key |
| 192 | $this->_init( $role_key ); |
154 | 193 | } |
155 | 194 | |
156 | 195 | /** |
diff --git src/wp-includes/ms-blogs.php src/wp-includes/ms-blogs.php
index 9188750..875a6ce 100644
|
|
|
766 | 766 | * @return true Always returns True. |
767 | 767 | */ |
768 | 768 | function switch_to_blog( $new_blog, $deprecated = null ) { |
769 | | global $wpdb, $wp_roles; |
| 769 | global $wpdb; |
770 | 770 | |
771 | 771 | $blog_id = get_current_blog_id(); |
772 | 772 | if ( empty( $new_blog ) ) { |
… |
… |
|
821 | 821 | } |
822 | 822 | } |
823 | 823 | |
824 | | if ( did_action( 'init' ) ) { |
825 | | $wp_roles = new WP_Roles(); |
826 | | $current_user = wp_get_current_user(); |
827 | | $current_user->for_blog( $new_blog ); |
828 | | } |
829 | | |
830 | 824 | /** This filter is documented in wp-includes/ms-blogs.php */ |
831 | 825 | do_action( 'switch_blog', $new_blog, $prev_blog_id ); |
832 | 826 | $GLOBALS['switched'] = true; |
… |
… |
|
850 | 844 | * @return bool True on success, false if we're already on the current blog |
851 | 845 | */ |
852 | 846 | function restore_current_blog() { |
853 | | global $wpdb, $wp_roles; |
| 847 | global $wpdb; |
854 | 848 | |
855 | 849 | if ( empty( $GLOBALS['_wp_switched_stack'] ) ) { |
856 | 850 | return false; |
… |
… |
|
895 | 889 | } |
896 | 890 | } |
897 | 891 | |
898 | | if ( did_action( 'init' ) ) { |
899 | | $wp_roles = new WP_Roles(); |
900 | | $current_user = wp_get_current_user(); |
901 | | $current_user->for_blog( $blog ); |
902 | | } |
903 | | |
904 | 892 | /** This filter is documented in wp-includes/ms-blogs.php */ |
905 | 893 | do_action( 'switch_blog', $blog, $prev_blog_id ); |
906 | 894 | |
… |
… |
|
911 | 899 | } |
912 | 900 | |
913 | 901 | /** |
| 902 | * Switch WP_Roles & current_user roles & caps, usually when switching sites. |
| 903 | * |
| 904 | * @since 4.8.0 |
| 905 | * |
| 906 | * @param int $new_blog_id |
| 907 | * @param int $old_blog_id |
| 908 | */ |
| 909 | function switch_wp_roles( $new_blog_id = 0, $old_blog_id = 0 ) { |
| 910 | if ( $new_blog_id != $old_blog_id ) { |
| 911 | wp_roles()->for_blog( $new_blog_id ); |
| 912 | wp_get_current_user()->for_blog( $new_blog_id ); |
| 913 | } |
| 914 | } |
| 915 | |
| 916 | /** |
914 | 917 | * Determines if switch_to_blog() is in effect |
915 | 918 | * |
916 | 919 | * @since 3.5.0 |
diff --git src/wp-includes/ms-default-filters.php src/wp-includes/ms-default-filters.php
old mode 100644
new mode 100755
index 08d752a..c3e218b
|
|
|
32 | 32 | add_action( 'network_user_new_created_user', 'wp_send_new_user_notifications' ); |
33 | 33 | add_filter( 'sanitize_user', 'strtolower' ); |
34 | 34 | |
| 35 | // Roles |
| 36 | add_action( 'switch_blog', 'switch_wp_roles', 8, 2 ); |
| 37 | |
35 | 38 | // Blogs |
36 | 39 | add_filter( 'wpmu_validate_blog_signup', 'signup_nonce_check' ); |
37 | 40 | add_action( 'wpmu_new_blog', 'wpmu_log_new_registrations', 10, 2 ); |