Ticket #5541: no_db_roles-r6510-2.patch
File no_db_roles-r6510-2.patch, 11.8 KB (added by , 17 years ago) |
---|
-
wordpress/wp-includes/capabilities.php
1 1 <?php 2 2 3 3 class WP_Roles { 4 var $roles;5 4 6 5 var $role_objects = array(); 7 6 var $role_names = array(); 8 var $role_key;9 var $use_db = true;10 7 11 8 function WP_Roles() { 12 9 $this->_init(); 13 10 } 14 11 15 12 function _init () { 16 global $wpdb; 17 global $wp_user_roles; 18 $this->role_key = $wpdb->prefix . 'user_roles'; 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 } 25 26 if ( empty($this->roles) ) 27 return; 28 29 $this->role_objects = array(); 30 $this->role_names = array(); 31 foreach ($this->roles as $role => $data) { 32 $this->role_objects[$role] = new WP_Role($role, $this->roles[$role]['capabilities']); 33 $this->role_names[$role] = $this->roles[$role]['name']; 34 } 13 do_action_ref_array('init_roles', array(&$this)); 35 14 } 36 15 37 16 function add_role($role, $display_name, $capabilities = '') { 38 17 if ( isset($this->roles[$role]) ) 39 18 return; 40 19 41 $this->roles[$role] = array(42 'name' => $display_name,43 'capabilities' => $capabilities);44 if ( $this->use_db )45 update_option($this->role_key, $this->roles);46 20 $this->role_objects[$role] = new WP_Role($role, $capabilities); 47 21 $this->role_names[$role] = $display_name; 48 22 return $this->role_objects[$role]; … … 54 28 55 29 unset($this->role_objects[$role]); 56 30 unset($this->role_names[$role]); 57 unset($this->roles[$role]);58 59 if ( $this->use_db )60 update_option($this->role_key, $this->roles);61 31 } 62 32 63 33 function add_cap($role, $cap, $grant = true) { 64 $this->roles[$role]['capabilities'][$cap] = $grant; 65 if ( $this->use_db ) 66 update_option($this->role_key, $this->roles); 34 if (isset($this->role_objects[$role])) 35 $this->role_objects[$role]->add_cap($cap, $grant); 67 36 } 68 37 69 38 function remove_cap($role, $cap) { 70 unset($this->roles[$role]['capabilities'][$cap]); 71 if ( $this->use_db ) 72 update_option($this->role_key, $this->roles); 39 if (isset($this->role_objects[$role])) 40 $this->role_objects[$role]->remove_cap($cap, $grant); 73 41 } 74 42 75 43 function &get_role($role) { … … 99 67 } 100 68 101 69 function add_cap($cap, $grant = true) { 102 global $wp_roles;103 104 if ( ! isset($wp_roles) )105 $wp_roles = new WP_Roles();106 107 70 $this->capabilities[$cap] = $grant; 108 $wp_roles->add_cap($this->name, $cap, $grant);109 71 } 110 72 111 73 function remove_cap($cap) { 112 global $wp_roles;113 114 if ( ! isset($wp_roles) )115 $wp_roles = new WP_Roles();116 117 74 unset($this->capabilities[$cap]); 118 $wp_roles->remove_cap($this->name, $cap);119 75 } 120 76 121 77 function has_cap($cap) { 122 78 $capabilities = apply_filters('role_has_cap', $this->capabilities, $cap, $this->name); 123 if ( !empty($capabilities[$cap]) ) 124 return $capabilities[$cap]; 125 else 126 return false; 79 $grant = !empty( $capabilities[$cap] ); 80 return apply_filters("{$this->name}_has_cap", $grant); 127 81 } 128 82 129 83 } … … 280 234 281 235 } 282 236 237 // Populate standard role definitions 238 function populate_roles(&$roles) { 239 240 $roles->add_role('administrator', _c('Administrator|User role'), array( 241 'switch_themes' => true, 242 'edit_themes' => true, 243 'activate_plugins' => true, 244 'edit_plugins' => true, 245 'edit_users' => true, 246 'edit_files' => true, 247 'manage_options' => true, 248 'moderate_comments' => true, 249 'manage_categories' => true, 250 'manage_links' => true, 251 'upload_files' => true, 252 'import' => true, 253 'unfiltered_html' => true, 254 'edit_posts' => true, 255 'edit_others_posts' => true, 256 'edit_published_posts' => true, 257 'publish_posts' => true, 258 'edit_pages' => true, 259 'read' => true, 260 'level_10' => true, 261 'level_9' => true, 262 'level_8' => true, 263 'level_7' => true, 264 'level_6' => true, 265 'level_5' => true, 266 'level_4' => true, 267 'level_3' => true, 268 'level_2' => true, 269 'level_1' => true, 270 'level_0' => true, 271 'edit_others_pages' => true, 272 'edit_published_pages' => true, 273 'publish_pages' => true, 274 'delete_pages' => true, 275 'delete_others_pages' => true, 276 'delete_published_pages' => true, 277 'delete_posts' => true, 278 'delete_others_posts' => true, 279 'delete_published_posts' => true, 280 'delete_private_posts' => true, 281 'edit_private_posts' => true, 282 'read_private_posts' => true, 283 'delete_private_pages' => true, 284 'edit_private_pages' => true, 285 'read_private_pages' => true, 286 'delete_users' => true, 287 'create_users' => true, 288 'unfiltered_upload' => true, 289 )); 290 291 $roles->add_role('editor', _c('Editor|User role'), array( 292 'moderate_comments' => true, 293 'manage_categories' => true, 294 'manage_links' => true, 295 'upload_files' => true, 296 'unfiltered_html' => true, 297 'edit_posts' => true, 298 'edit_others_posts' => true, 299 'edit_published_posts' => true, 300 'publish_posts' => true, 301 'edit_pages' => true, 302 'read' => true, 303 'level_7' => true, 304 'level_6' => true, 305 'level_5' => true, 306 'level_4' => true, 307 'level_3' => true, 308 'level_2' => true, 309 'level_1' => true, 310 'level_0' => true, 311 'edit_others_pages' => true, 312 'edit_published_pages' => true, 313 'publish_pages' => true, 314 'delete_pages' => true, 315 'delete_others_pages' => true, 316 'delete_published_pages' => true, 317 'delete_posts' => true, 318 'delete_others_posts' => true, 319 'delete_published_posts' => true, 320 'delete_private_posts' => true, 321 'edit_private_posts' => true, 322 'read_private_posts' => true, 323 'delete_private_pages' => true, 324 'edit_private_pages' => true, 325 'read_private_pages' => true, 326 )); 327 328 $roles->add_role( 'author', _c('Author|User role'), array( 329 'upload_files' => true, 330 'edit_posts' => true, 331 'edit_published_posts' => true, 332 'publish_posts' => true, 333 'read' => true, 334 'level_2' => true, 335 'level_1' => true, 336 'level_0' => true, 337 'delete_posts' => true, 338 'delete_published_posts' => true, 339 ) ); 340 341 $roles->add_role( 'contributor', _c('Contributor|User role'), array( 342 'edit_posts' => true, 343 'read' => true, 344 'level_1' => true, 345 'level_0' => true, 346 'delete_posts' => true, 347 ) ); 348 349 $roles->add_role('subscriber', _c('Editor|User role'), array( 350 'read' => true, 351 'level_0' => true, 352 ) ); 353 } 354 355 add_action('init_roles', 'populate_roles'); 356 283 357 // Map meta capabilities to primitive capabilities. 284 358 function map_meta_cap($cap, $user_id) { 285 359 $args = array_slice(func_get_args(), 2); -
wordpress/wp-admin/includes/schema.php
247 247 endforeach; 248 248 } 249 249 250 function populate_roles() {251 populate_roles_160();252 populate_roles_210();253 populate_roles_230();254 }255 256 function populate_roles_160() {257 // Add roles258 add_role('administrator', _c('Administrator|User role'));259 add_role('editor', _c('Editor|User role'));260 add_role('author', _c('Author|User role'));261 add_role('contributor', _c('Contributor|User role'));262 add_role('subscriber', _c('Subscriber|User role'));263 264 // Add caps for Administrator role265 $role = get_role('administrator');266 $role->add_cap('switch_themes');267 $role->add_cap('edit_themes');268 $role->add_cap('activate_plugins');269 $role->add_cap('edit_plugins');270 $role->add_cap('edit_users');271 $role->add_cap('edit_files');272 $role->add_cap('manage_options');273 $role->add_cap('moderate_comments');274 $role->add_cap('manage_categories');275 $role->add_cap('manage_links');276 $role->add_cap('upload_files');277 $role->add_cap('import');278 $role->add_cap('unfiltered_html');279 $role->add_cap('edit_posts');280 $role->add_cap('edit_others_posts');281 $role->add_cap('edit_published_posts');282 $role->add_cap('publish_posts');283 $role->add_cap('edit_pages');284 $role->add_cap('read');285 $role->add_cap('level_10');286 $role->add_cap('level_9');287 $role->add_cap('level_8');288 $role->add_cap('level_7');289 $role->add_cap('level_6');290 $role->add_cap('level_5');291 $role->add_cap('level_4');292 $role->add_cap('level_3');293 $role->add_cap('level_2');294 $role->add_cap('level_1');295 $role->add_cap('level_0');296 297 // Add caps for Editor role298 $role = get_role('editor');299 $role->add_cap('moderate_comments');300 $role->add_cap('manage_categories');301 $role->add_cap('manage_links');302 $role->add_cap('upload_files');303 $role->add_cap('unfiltered_html');304 $role->add_cap('edit_posts');305 $role->add_cap('edit_others_posts');306 $role->add_cap('edit_published_posts');307 $role->add_cap('publish_posts');308 $role->add_cap('edit_pages');309 $role->add_cap('read');310 $role->add_cap('level_7');311 $role->add_cap('level_6');312 $role->add_cap('level_5');313 $role->add_cap('level_4');314 $role->add_cap('level_3');315 $role->add_cap('level_2');316 $role->add_cap('level_1');317 $role->add_cap('level_0');318 319 // Add caps for Author role320 $role = get_role('author');321 $role->add_cap('upload_files');322 $role->add_cap('edit_posts');323 $role->add_cap('edit_published_posts');324 $role->add_cap('publish_posts');325 $role->add_cap('read');326 $role->add_cap('level_2');327 $role->add_cap('level_1');328 $role->add_cap('level_0');329 330 // Add caps for Contributor role331 $role = get_role('contributor');332 $role->add_cap('edit_posts');333 $role->add_cap('read');334 $role->add_cap('level_1');335 $role->add_cap('level_0');336 337 // Add caps for Subscriber role338 $role = get_role('subscriber');339 $role->add_cap('read');340 $role->add_cap('level_0');341 }342 343 function populate_roles_210() {344 $roles = array('administrator', 'editor');345 foreach ($roles as $role) {346 $role = get_role($role);347 if ( empty($role) )348 continue;349 350 $role->add_cap('edit_others_pages');351 $role->add_cap('edit_published_pages');352 $role->add_cap('publish_pages');353 $role->add_cap('delete_pages');354 $role->add_cap('delete_others_pages');355 $role->add_cap('delete_published_pages');356 $role->add_cap('delete_posts');357 $role->add_cap('delete_others_posts');358 $role->add_cap('delete_published_posts');359 $role->add_cap('delete_private_posts');360 $role->add_cap('edit_private_posts');361 $role->add_cap('read_private_posts');362 $role->add_cap('delete_private_pages');363 $role->add_cap('edit_private_pages');364 $role->add_cap('read_private_pages');365 }366 367 $role = get_role('administrator');368 if ( ! empty($role) ) {369 $role->add_cap('delete_users');370 $role->add_cap('create_users');371 }372 373 $role = get_role('author');374 if ( ! empty($role) ) {375 $role->add_cap('delete_posts');376 $role->add_cap('delete_published_posts');377 }378 379 $role = get_role('contributor');380 if ( ! empty($role) ) {381 $role->add_cap('delete_posts');382 }383 }384 385 function populate_roles_230() {386 $role = get_role( 'administrator' );387 388 if ( !empty( $role ) ) {389 $role->add_cap( 'unfiltered_upload' );390 }391 }392 393 250 ?> -
wordpress/wp-admin/includes/upgrade.php
13 13 wp_cache_flush(); 14 14 make_db_current_silent(); 15 15 populate_options(); 16 populate_roles();17 16 18 17 update_option('blogname', $blog_title); 19 18 update_option('admin_email', $user_email); … … 409 408 function upgrade_160() { 410 409 global $wpdb, $wp_current_db_version; 411 410 412 populate_roles_160();413 414 411 $users = $wpdb->get_results("SELECT * FROM $wpdb->users"); 415 412 foreach ( $users as $user ) : 416 413 if ( !empty( $user->user_firstname ) ) … … 508 505 } 509 506 } 510 507 511 if ( $wp_current_db_version < 3845 ) {512 populate_roles_210();513 }514 515 508 if ( $wp_current_db_version < 3531 ) { 516 509 // Give future posts a post_status of future. 517 510 $now = gmdate('Y-m-d H:i:59'); … … 527 520 function upgrade_230() { 528 521 global $wp_current_db_version, $wpdb; 529 522 530 if ( $wp_current_db_version < 5200 ) {531 populate_roles_230();532 }533 534 523 // Convert categories to terms. 535 524 $tt_ids = array(); 536 525 $have_tags = false;