Ticket #20152: user-roles-option-plus-regeneration.diff
File user-roles-option-plus-regeneration.diff, 15.4 KB (added by , 12 years ago) |
---|
-
wp-includes/user.php
865 865 foreach ( $avail_roles as $this_role => $name ) { 866 866 $select_count[] = "COUNT(NULLIF(`meta_value` LIKE '%\"" . like_escape( $this_role ) . "\"%', false))"; 867 867 } 868 $select_count = implode(', ', $select_count); 869 868 869 if ( ! empty( $select_count ) ) 870 $select_count = implode(', ', $select_count) . ','; 871 else 872 $select_count = ''; 873 870 874 // Add the meta_value index to the selection list, then run the query. 871 $row = $wpdb->get_row( "SELECT $select_count ,COUNT(*) FROM $wpdb->usermeta WHERE meta_key = '{$blog_prefix}capabilities'", ARRAY_N );875 $row = $wpdb->get_row( "SELECT $select_count COUNT(*) FROM $wpdb->usermeta WHERE meta_key = '{$blog_prefix}capabilities'", ARRAY_N ); 872 876 873 877 // Run the previous loop again to associate results with role names. 874 878 $col = 0; -
wp-includes/capabilities.php
61 61 * @access public 62 62 * @var string 63 63 */ 64 var $role_key ;64 var $role_key = 'user_roles'; 65 65 66 66 /** 67 67 * Whether to use the database for retrieval and storage. … … 84 84 /** 85 85 * Set up the object properties. 86 86 * 87 * The role key is set to the current prefix for the $wpdb object with 88 * 'user_roles' appended. If the $wp_user_roles global is set, then it will 87 * If the $wp_user_roles global is set, then it will 89 88 * be used and the role option will not be updated or used. 90 89 * 91 90 * @since 2.1.0 … … 94 93 * @global array $wp_user_roles Used to set the 'roles' property value. 95 94 */ 96 95 function _init () { 97 global $wp db, $wp_user_roles;98 $this->role_key = $wpdb->prefix . 'user_roles'; 96 global $wp_user_roles; 97 99 98 if ( ! empty( $wp_user_roles ) ) { 100 99 $this->roles = $wp_user_roles; 101 100 $this->use_db = false; 102 101 } else { 103 102 $this->roles = get_option( $this->role_key ); 103 if ( empty( $this->roles ) ) 104 $this->roles = _WP_User_Roles::init(); 104 105 } 105 106 106 107 if ( empty( $this->roles ) ) … … 128 129 if ( ! $this->use_db ) 129 130 return; 130 131 131 global $wpdb, $wp_user_roles;132 133 132 // Duplicated from _init() to avoid an extra function call. 134 $this->role_key = $wpdb->prefix . 'user_roles';135 133 $this->roles = get_option( $this->role_key ); 136 134 if ( empty( $this->roles ) ) 135 $this->roles = _WP_User_Roles::init(); 136 137 if ( empty( $this->roles ) ) 137 138 return; 138 139 139 140 $this->role_objects = array(); … … 1444 1445 1445 1446 return false; 1446 1447 } 1448 1449 /** 1450 * WordPress Default User Roles. 1451 * 1452 * Allows regeneration of the required 'user_roles' option 1453 * 1454 * @acccess private 1455 * 1456 * @since 3.5.0 1457 * @package WordPress 1458 * @subpackage User 1459 */ 1460 class _WP_User_Roles { 1461 static $instance; 1462 private $roles = array(); 1463 1464 private function __construct() { 1465 if ( empty( $this->roles ) ) 1466 $this->populate(); 1467 } 1468 1469 static function init() { 1470 if ( ! isset( self::$instance ) ) 1471 self::$instance = new _WP_User_Roles; 1472 1473 return self::$instance->roles; 1474 } 1475 1476 private function populate() { 1477 $roles = array(); 1478 1479 /** 1480 * @since 2.1.0 1481 */ 1482 $caps_210 = array( 1483 'edit_others_pages' => 1, 1484 'edit_published_pages' => 1, 1485 'publish_pages' => 1, 1486 'delete_pages' => 1, 1487 'delete_others_pages' => 1, 1488 'delete_published_pages' => 1, 1489 'delete_posts' => 1, 1490 'delete_others_posts' => 1, 1491 'delete_published_posts' => 1, 1492 'delete_private_posts' => 1, 1493 'edit_private_posts' => 1, 1494 'read_private_posts' => 1, 1495 'delete_private_pages' => 1, 1496 'edit_private_pages' => 1, 1497 'read_private_pages' => 1 1498 ); 1499 1500 $admin_caps = array( 1501 /** 1502 * @since 1.6.0 1503 */ 1504 'switch_themes' => 1, 1505 'edit_themes' => 1, 1506 'activate_plugins' => 1, 1507 'edit_plugins' => 1, 1508 'edit_users' => 1, 1509 'edit_files' => 1, 1510 'manage_options' => 1, 1511 'moderate_comments' => 1, 1512 'manage_categories' => 1, 1513 'manage_links' => 1, 1514 'upload_files' => 1, 1515 'import', 1516 'unfiltered_html' => 1, 1517 'edit_posts' => 1, 1518 'edit_others_posts' => 1, 1519 'edit_published_posts' => 1, 1520 'publish_posts' => 1, 1521 'edit_pages' => 1, 1522 'read' => 1, 1523 /** 1524 * @since 2.1.0 1525 */ 1526 'delete_users' => 1, 1527 'create_users' => 1, 1528 /** 1529 * @since 2.3.0 1530 */ 1531 'unfiltered_upload' => 1, 1532 /** 1533 * @since 2.5.0 1534 */ 1535 'edit_dashboard' => 1, 1536 /** 1537 * @since 2.6.0 1538 */ 1539 'update_plugins' => 1, 1540 'delete_plugins' => 1, 1541 /** 1542 * @since 2.7.0 1543 */ 1544 'install_plugins' => 1, 1545 'update_themes' => 1, 1546 /** 1547 * @since 2.8.0 1548 */ 1549 'install_themes' => 1, 1550 /** 1551 * @since 3.0.0 1552 */ 1553 'update_core' => 1, 1554 'list_users' => 1, 1555 'remove_users' => 1, 1556 'add_users' => 1, 1557 'promote_users' => 1, 1558 'edit_theme_options' => 1, 1559 'delete_themes' => 1, 1560 'export' => 1, 1561 ); 1562 1563 /** 1564 * @since 1.6.0 1565 */ 1566 for ( $i = 0; $i <= 10; $i++ ) 1567 $admin_caps['level_' . $i] = 1; 1568 1569 /** 1570 * @since 2.1.0 1571 */ 1572 $admin_caps = array_merge( $admin_caps, $caps_210 ); 1573 1574 $roles[] = array( 1575 'administrator', 1576 /* translators: user role */ 1577 _x( 'Administrator', 'User role' ), 1578 $admin_caps 1579 ); 1580 1581 $editor_caps = array( 1582 /** 1583 * @since 1.6.0 1584 */ 1585 'moderate_comments' => 1, 1586 'manage_categories' => 1, 1587 'manage_links' => 1, 1588 'upload_files' => 1, 1589 'import' => 1, 1590 'unfiltered_html' => 1, 1591 'edit_posts' => 1, 1592 'edit_others_posts' => 1, 1593 'edit_published_posts' => 1, 1594 'publish_posts' => 1, 1595 'edit_pages' => 1, 1596 'read' => 1, 1597 ); 1598 /** 1599 * @since 1.6.0 1600 */ 1601 for ( $i = 0; $i <= 7; $i++ ) 1602 $editor_caps['level_' . $i] = 1; 1603 1604 /** 1605 * @since 2.1.0 1606 */ 1607 $editor_caps = array_merge( $editor_caps, $caps_210 ); 1608 1609 $roles[] = array( 1610 'editor', 1611 /* translators: user role */ 1612 _x( 'Editor', 'User role' ), 1613 $editor_caps 1614 ); 1615 1616 $author_caps = array( 1617 /** 1618 * @since 1.6.0 1619 */ 1620 'upload_files' => 1, 1621 'edit_posts' => 1, 1622 'edit_published_posts' => 1, 1623 'publish_posts' => 1, 1624 'read' => 1, 1625 /** 1626 * @since 2.1.0 1627 */ 1628 'delete_posts' => 1, 1629 'delete_published_posts' => 1 1630 ); 1631 /** 1632 * @since 1.6.0 1633 */ 1634 for ( $i = 0; $i <= 2; $i++ ) 1635 $author_caps['level_' . $i] = 1; 1636 1637 $roles[] = array( 1638 'author', 1639 /* translators: user role */ 1640 _x( 'Author', 'User role' ), 1641 $author_caps 1642 ); 1643 1644 $contributor_caps = array( 1645 /** 1646 * @since 1.6.0 1647 */ 1648 'edit_posts' => 1, 1649 'read' => 1, 1650 'level_0' => 1, 1651 'level_1' => 1, 1652 /** 1653 * @since 2.1.0 1654 */ 1655 'delete_posts' => 1, 1656 ); 1657 1658 $roles[] = array( 1659 'contributor', 1660 /* translators: user role */ 1661 _x( 'Contributor', 'User role' ), 1662 $contributor_caps 1663 ); 1664 1665 $subscriber_caps = array( 1666 /** 1667 * @since 1.6.0 1668 */ 1669 'read' => 1, 1670 'level_0' => 1 1671 ); 1672 1673 $roles[] = array( 1674 'subscriber', 1675 /* translators: user role */ 1676 _x( 'Subscriber', 'User role' ), 1677 $subscriber_caps 1678 ); 1679 1680 foreach ( $roles as $role ) { 1681 list( $slug, $name, $caps ) = $role; 1682 1683 $this->roles[$slug] = array( 1684 'name' => $name, 1685 'capabilities' => $caps 1686 ); 1687 } 1688 1689 update_option( 'user_roles', $this->roles ); 1690 } 1691 } 1692 No newline at end of file -
wp-admin/includes/schema.php
556 556 * @since 2.0.0 557 557 */ 558 558 function populate_roles() { 559 populate_roles_160(); 560 populate_roles_210(); 561 populate_roles_230(); 562 populate_roles_250(); 563 populate_roles_260(); 564 populate_roles_270(); 565 populate_roles_280(); 566 populate_roles_300(); 559 /** 560 * @since 3.5.0 561 * 562 */ 563 _WP_User_Roles::init(); 564 565 if ( is_multisite() ) { 566 global $wpdb; 567 $blog_ids = $wpdb->get_col( "SELECT blog_id FROM {$wpdb->blogs}" ); 568 foreach ( $blog_ids as $blog_id ) { 569 if ( 1 === (int) $blog_id ) 570 delete_option( 'wp_user_roles' ); 571 else 572 delete_option( "wp_{$blog_id}_user_roles" ); 573 } 574 } 567 575 } 568 576 569 577 /** 570 * Create the roles for WordPress 2.0571 *572 * @since 2.0.0573 */574 function populate_roles_160() {575 // Add roles576 577 // Dummy gettext calls to get strings in the catalog.578 /* translators: user role */579 _x('Administrator', 'User role');580 /* translators: user role */581 _x('Editor', 'User role');582 /* translators: user role */583 _x('Author', 'User role');584 /* translators: user role */585 _x('Contributor', 'User role');586 /* translators: user role */587 _x('Subscriber', 'User role');588 589 add_role('administrator', 'Administrator');590 add_role('editor', 'Editor');591 add_role('author', 'Author');592 add_role('contributor', 'Contributor');593 add_role('subscriber', 'Subscriber');594 595 // Add caps for Administrator role596 $role =& get_role('administrator');597 $role->add_cap('switch_themes');598 $role->add_cap('edit_themes');599 $role->add_cap('activate_plugins');600 $role->add_cap('edit_plugins');601 $role->add_cap('edit_users');602 $role->add_cap('edit_files');603 $role->add_cap('manage_options');604 $role->add_cap('moderate_comments');605 $role->add_cap('manage_categories');606 $role->add_cap('manage_links');607 $role->add_cap('upload_files');608 $role->add_cap('import');609 $role->add_cap('unfiltered_html');610 $role->add_cap('edit_posts');611 $role->add_cap('edit_others_posts');612 $role->add_cap('edit_published_posts');613 $role->add_cap('publish_posts');614 $role->add_cap('edit_pages');615 $role->add_cap('read');616 $role->add_cap('level_10');617 $role->add_cap('level_9');618 $role->add_cap('level_8');619 $role->add_cap('level_7');620 $role->add_cap('level_6');621 $role->add_cap('level_5');622 $role->add_cap('level_4');623 $role->add_cap('level_3');624 $role->add_cap('level_2');625 $role->add_cap('level_1');626 $role->add_cap('level_0');627 628 // Add caps for Editor role629 $role =& get_role('editor');630 $role->add_cap('moderate_comments');631 $role->add_cap('manage_categories');632 $role->add_cap('manage_links');633 $role->add_cap('upload_files');634 $role->add_cap('unfiltered_html');635 $role->add_cap('edit_posts');636 $role->add_cap('edit_others_posts');637 $role->add_cap('edit_published_posts');638 $role->add_cap('publish_posts');639 $role->add_cap('edit_pages');640 $role->add_cap('read');641 $role->add_cap('level_7');642 $role->add_cap('level_6');643 $role->add_cap('level_5');644 $role->add_cap('level_4');645 $role->add_cap('level_3');646 $role->add_cap('level_2');647 $role->add_cap('level_1');648 $role->add_cap('level_0');649 650 // Add caps for Author role651 $role =& get_role('author');652 $role->add_cap('upload_files');653 $role->add_cap('edit_posts');654 $role->add_cap('edit_published_posts');655 $role->add_cap('publish_posts');656 $role->add_cap('read');657 $role->add_cap('level_2');658 $role->add_cap('level_1');659 $role->add_cap('level_0');660 661 // Add caps for Contributor role662 $role =& get_role('contributor');663 $role->add_cap('edit_posts');664 $role->add_cap('read');665 $role->add_cap('level_1');666 $role->add_cap('level_0');667 668 // Add caps for Subscriber role669 $role =& get_role('subscriber');670 $role->add_cap('read');671 $role->add_cap('level_0');672 }673 674 /**675 * Create and modify WordPress roles for WordPress 2.1.676 *677 * @since 2.1.0678 */679 function populate_roles_210() {680 $roles = array('administrator', 'editor');681 foreach ($roles as $role) {682 $role =& get_role($role);683 if ( empty($role) )684 continue;685 686 $role->add_cap('edit_others_pages');687 $role->add_cap('edit_published_pages');688 $role->add_cap('publish_pages');689 $role->add_cap('delete_pages');690 $role->add_cap('delete_others_pages');691 $role->add_cap('delete_published_pages');692 $role->add_cap('delete_posts');693 $role->add_cap('delete_others_posts');694 $role->add_cap('delete_published_posts');695 $role->add_cap('delete_private_posts');696 $role->add_cap('edit_private_posts');697 $role->add_cap('read_private_posts');698 $role->add_cap('delete_private_pages');699 $role->add_cap('edit_private_pages');700 $role->add_cap('read_private_pages');701 }702 703 $role =& get_role('administrator');704 if ( ! empty($role) ) {705 $role->add_cap('delete_users');706 $role->add_cap('create_users');707 }708 709 $role =& get_role('author');710 if ( ! empty($role) ) {711 $role->add_cap('delete_posts');712 $role->add_cap('delete_published_posts');713 }714 715 $role =& get_role('contributor');716 if ( ! empty($role) ) {717 $role->add_cap('delete_posts');718 }719 }720 721 /**722 * Create and modify WordPress roles for WordPress 2.3.723 *724 * @since 2.3.0725 */726 function populate_roles_230() {727 $role =& get_role( 'administrator' );728 729 if ( !empty( $role ) ) {730 $role->add_cap( 'unfiltered_upload' );731 }732 }733 734 /**735 * Create and modify WordPress roles for WordPress 2.5.736 *737 * @since 2.5.0738 */739 function populate_roles_250() {740 $role =& get_role( 'administrator' );741 742 if ( !empty( $role ) ) {743 $role->add_cap( 'edit_dashboard' );744 }745 }746 747 /**748 * Create and modify WordPress roles for WordPress 2.6.749 *750 * @since 2.6.0751 */752 function populate_roles_260() {753 $role =& get_role( 'administrator' );754 755 if ( !empty( $role ) ) {756 $role->add_cap( 'update_plugins' );757 $role->add_cap( 'delete_plugins' );758 }759 }760 761 /**762 * Create and modify WordPress roles for WordPress 2.7.763 *764 * @since 2.7.0765 */766 function populate_roles_270() {767 $role =& get_role( 'administrator' );768 769 if ( !empty( $role ) ) {770 $role->add_cap( 'install_plugins' );771 $role->add_cap( 'update_themes' );772 }773 }774 775 /**776 * Create and modify WordPress roles for WordPress 2.8.777 *778 * @since 2.8.0779 */780 function populate_roles_280() {781 $role =& get_role( 'administrator' );782 783 if ( !empty( $role ) ) {784 $role->add_cap( 'install_themes' );785 }786 }787 788 /**789 * Create and modify WordPress roles for WordPress 3.0.790 *791 * @since 3.0.0792 */793 function populate_roles_300() {794 $role =& get_role( 'administrator' );795 796 if ( !empty( $role ) ) {797 $role->add_cap( 'update_core' );798 $role->add_cap( 'list_users' );799 $role->add_cap( 'remove_users' );800 $role->add_cap( 'add_users' );801 $role->add_cap( 'promote_users' );802 $role->add_cap( 'edit_theme_options' );803 $role->add_cap( 'delete_themes' );804 $role->add_cap( 'export' );805 }806 }807 808 /**809 578 * Install Network. 810 579 * 811 580 * @since 3.0.0 -
wp-admin/includes/template.php
759 759 760 760 $editable_roles = get_editable_roles(); 761 761 762 if ( empty( $editable_roles ) ) 763 return; 764 762 765 foreach ( $editable_roles as $role => $details ) { 763 766 $name = translate_user_role($details['name'] ); 764 767 if ( $selected == $role ) // preselect specified role -
wp-admin/network/site-settings.php
113 113 <table class="form-table"> 114 114 <?php 115 115 $blog_prefix = $wpdb->get_blog_prefix( $id ); 116 $options = $wpdb->get_results( "SELECT * FROM {$blog_prefix}options WHERE option_name NOT LIKE '\_%' AND option_name NOT LIKE '%user_roles'" );116 $options = $wpdb->get_results( "SELECT * FROM {$blog_prefix}options WHERE option_name NOT LIKE '\_%' AND option_name != 'user_roles'" ); 117 117 foreach ( $options as $option ) { 118 118 if ( $option->option_name == 'default_role' ) 119 119 $editblog_default_role = $option->option_value;