@@ -6,16 +6,22 @@ class WP_Roles {
66 var $ role_objects = array ();
77 var $ role_names = array ();
88 var $ role_key ;
9+ var $ use_db = true ;
910
1011 function WP_Roles () {
1112 $ this ->_init ();
1213 }
1314
1415 function _init () {
1516 global $ wpdb ;
17+ global $ wp_user_roles ;
1618 $ this ->role_key = $ wpdb ->prefix . 'user_roles ' ;
17-
18- $ this ->roles = get_option ($ this ->role_key );
19+ if ( ! empty ($ wp_user_roles ) ) {
20+ $ this ->roles = $ wp_user_roles ;
21+ $ this ->use_db = false ;
22+ } else {
23+ $ this ->roles = get_option ($ this ->role_key );
24+ }
1925
2026 if ( empty ($ this ->roles ) )
2127 return ;
@@ -35,7 +41,8 @@ function add_role($role, $display_name, $capabilities = '') {
3541 $ this ->roles [$ role ] = array (
3642 'name ' => $ display_name ,
3743 'capabilities ' => $ capabilities );
38- update_option ($ this ->role_key , $ this ->roles );
44+ if ( $ this ->use_db )
45+ update_option ($ this ->role_key , $ this ->roles );
3946 $ this ->role_objects [$ role ] = new WP_Role ($ role , $ capabilities );
4047 $ this ->role_names [$ role ] = $ display_name ;
4148 return $ this ->role_objects [$ role ];
@@ -48,18 +55,21 @@ function remove_role($role) {
4855 unset($ this ->role_objects [$ role ]);
4956 unset($ this ->role_names [$ role ]);
5057 unset($ this ->roles [$ role ]);
51-
52- update_option ($ this ->role_key , $ this ->roles );
58+
59+ if ( $ this ->use_db )
60+ update_option ($ this ->role_key , $ this ->roles );
5361 }
5462
5563 function add_cap ($ role , $ cap , $ grant = true ) {
5664 $ this ->roles [$ role ]['capabilities ' ][$ cap ] = $ grant ;
57- update_option ($ this ->role_key , $ this ->roles );
65+ if ( $ this ->use_db )
66+ update_option ($ this ->role_key , $ this ->roles );
5867 }
5968
6069 function remove_cap ($ role , $ cap ) {
6170 unset($ this ->roles [$ role ]['capabilities ' ][$ cap ]);
62- update_option ($ this ->role_key , $ this ->roles );
71+ if ( $ this ->use_db )
72+ update_option ($ this ->role_key , $ this ->roles );
6373 }
6474
6575 function &get_role ($ role ) {
0 commit comments