Ticket #20152: 20152.diff
File 20152.diff, 15.5 KB (added by , 11 years ago) |
---|
-
wp-admin/includes/schema.php
diff --git wp-admin/includes/schema.php wp-admin/includes/schema.php index 162651a..5b046a0 100644
function populate_options() { 550 550 * @since 2.0.0 551 551 */ 552 552 function populate_roles() { 553 populate_roles_160(); 554 populate_roles_210(); 555 populate_roles_230(); 556 populate_roles_250(); 557 populate_roles_260(); 558 populate_roles_270(); 559 populate_roles_280(); 560 populate_roles_300(); 561 } 562 563 /** 564 * Create the roles for WordPress 2.0 565 * 566 * @since 2.0.0 567 */ 568 function populate_roles_160() { 569 // Add roles 570 571 // Dummy gettext calls to get strings in the catalog. 572 /* translators: user role */ 573 _x('Administrator', 'User role'); 574 /* translators: user role */ 575 _x('Editor', 'User role'); 576 /* translators: user role */ 577 _x('Author', 'User role'); 578 /* translators: user role */ 579 _x('Contributor', 'User role'); 580 /* translators: user role */ 581 _x('Subscriber', 'User role'); 582 583 add_role('administrator', 'Administrator'); 584 add_role('editor', 'Editor'); 585 add_role('author', 'Author'); 586 add_role('contributor', 'Contributor'); 587 add_role('subscriber', 'Subscriber'); 588 589 // Add caps for Administrator role 590 $role = get_role('administrator'); 591 $role->add_cap('switch_themes'); 592 $role->add_cap('edit_themes'); 593 $role->add_cap('activate_plugins'); 594 $role->add_cap('edit_plugins'); 595 $role->add_cap('edit_users'); 596 $role->add_cap('edit_files'); 597 $role->add_cap('manage_options'); 598 $role->add_cap('moderate_comments'); 599 $role->add_cap('manage_categories'); 600 $role->add_cap('manage_links'); 601 $role->add_cap('upload_files'); 602 $role->add_cap('import'); 603 $role->add_cap('unfiltered_html'); 604 $role->add_cap('edit_posts'); 605 $role->add_cap('edit_others_posts'); 606 $role->add_cap('edit_published_posts'); 607 $role->add_cap('publish_posts'); 608 $role->add_cap('edit_pages'); 609 $role->add_cap('read'); 610 $role->add_cap('level_10'); 611 $role->add_cap('level_9'); 612 $role->add_cap('level_8'); 613 $role->add_cap('level_7'); 614 $role->add_cap('level_6'); 615 $role->add_cap('level_5'); 616 $role->add_cap('level_4'); 617 $role->add_cap('level_3'); 618 $role->add_cap('level_2'); 619 $role->add_cap('level_1'); 620 $role->add_cap('level_0'); 621 622 // Add caps for Editor role 623 $role = get_role('editor'); 624 $role->add_cap('moderate_comments'); 625 $role->add_cap('manage_categories'); 626 $role->add_cap('manage_links'); 627 $role->add_cap('upload_files'); 628 $role->add_cap('unfiltered_html'); 629 $role->add_cap('edit_posts'); 630 $role->add_cap('edit_others_posts'); 631 $role->add_cap('edit_published_posts'); 632 $role->add_cap('publish_posts'); 633 $role->add_cap('edit_pages'); 634 $role->add_cap('read'); 635 $role->add_cap('level_7'); 636 $role->add_cap('level_6'); 637 $role->add_cap('level_5'); 638 $role->add_cap('level_4'); 639 $role->add_cap('level_3'); 640 $role->add_cap('level_2'); 641 $role->add_cap('level_1'); 642 $role->add_cap('level_0'); 643 644 // Add caps for Author role 645 $role = get_role('author'); 646 $role->add_cap('upload_files'); 647 $role->add_cap('edit_posts'); 648 $role->add_cap('edit_published_posts'); 649 $role->add_cap('publish_posts'); 650 $role->add_cap('read'); 651 $role->add_cap('level_2'); 652 $role->add_cap('level_1'); 653 $role->add_cap('level_0'); 654 655 // Add caps for Contributor role 656 $role = get_role('contributor'); 657 $role->add_cap('edit_posts'); 658 $role->add_cap('read'); 659 $role->add_cap('level_1'); 660 $role->add_cap('level_0'); 661 662 // Add caps for Subscriber role 663 $role = get_role('subscriber'); 664 $role->add_cap('read'); 665 $role->add_cap('level_0'); 666 } 667 668 /** 669 * Create and modify WordPress roles for WordPress 2.1. 670 * 671 * @since 2.1.0 672 */ 673 function populate_roles_210() { 674 $roles = array('administrator', 'editor'); 675 foreach ($roles as $role) { 676 $role = get_role($role); 677 if ( empty($role) ) 678 continue; 679 680 $role->add_cap('edit_others_pages'); 681 $role->add_cap('edit_published_pages'); 682 $role->add_cap('publish_pages'); 683 $role->add_cap('delete_pages'); 684 $role->add_cap('delete_others_pages'); 685 $role->add_cap('delete_published_pages'); 686 $role->add_cap('delete_posts'); 687 $role->add_cap('delete_others_posts'); 688 $role->add_cap('delete_published_posts'); 689 $role->add_cap('delete_private_posts'); 690 $role->add_cap('edit_private_posts'); 691 $role->add_cap('read_private_posts'); 692 $role->add_cap('delete_private_pages'); 693 $role->add_cap('edit_private_pages'); 694 $role->add_cap('read_private_pages'); 695 } 696 697 $role = get_role('administrator'); 698 if ( ! empty($role) ) { 699 $role->add_cap('delete_users'); 700 $role->add_cap('create_users'); 701 } 702 703 $role = get_role('author'); 704 if ( ! empty($role) ) { 705 $role->add_cap('delete_posts'); 706 $role->add_cap('delete_published_posts'); 707 } 708 709 $role = get_role('contributor'); 710 if ( ! empty($role) ) { 711 $role->add_cap('delete_posts'); 712 } 713 } 714 715 /** 716 * Create and modify WordPress roles for WordPress 2.3. 717 * 718 * @since 2.3.0 719 */ 720 function populate_roles_230() { 721 $role = get_role( 'administrator' ); 722 723 if ( !empty( $role ) ) { 724 $role->add_cap( 'unfiltered_upload' ); 725 } 726 } 727 728 /** 729 * Create and modify WordPress roles for WordPress 2.5. 730 * 731 * @since 2.5.0 732 */ 733 function populate_roles_250() { 734 $role = get_role( 'administrator' ); 735 736 if ( !empty( $role ) ) { 737 $role->add_cap( 'edit_dashboard' ); 738 } 739 } 740 741 /** 742 * Create and modify WordPress roles for WordPress 2.6. 743 * 744 * @since 2.6.0 745 */ 746 function populate_roles_260() { 747 $role = get_role( 'administrator' ); 553 /** 554 * @since 3.7.0 555 * 556 */ 557 _WP_User_Roles::init(); 748 558 749 if ( !empty( $role ) ) { 750 $role->add_cap( 'update_plugins' ); 751 $role->add_cap( 'delete_plugins' ); 752 } 753 } 754 755 /** 756 * Create and modify WordPress roles for WordPress 2.7. 757 * 758 * @since 2.7.0 759 */ 760 function populate_roles_270() { 761 $role = get_role( 'administrator' ); 762 763 if ( !empty( $role ) ) { 764 $role->add_cap( 'install_plugins' ); 765 $role->add_cap( 'update_themes' ); 766 } 767 } 768 769 /** 770 * Create and modify WordPress roles for WordPress 2.8. 771 * 772 * @since 2.8.0 773 */ 774 function populate_roles_280() { 775 $role = get_role( 'administrator' ); 776 777 if ( !empty( $role ) ) { 778 $role->add_cap( 'install_themes' ); 779 } 780 } 781 782 /** 783 * Create and modify WordPress roles for WordPress 3.0. 784 * 785 * @since 3.0.0 786 */ 787 function populate_roles_300() { 788 $role = get_role( 'administrator' ); 789 790 if ( !empty( $role ) ) { 791 $role->add_cap( 'update_core' ); 792 $role->add_cap( 'list_users' ); 793 $role->add_cap( 'remove_users' ); 794 795 // Never used, will be removed. create_users or 796 // promote_users is the capability you're looking for. 797 $role->add_cap( 'add_users' ); 798 799 $role->add_cap( 'promote_users' ); 800 $role->add_cap( 'edit_theme_options' ); 801 $role->add_cap( 'delete_themes' ); 802 $role->add_cap( 'export' ); 559 if ( is_multisite() ) { 560 global $wpdb; 561 $blog_ids = $wpdb->get_col( "SELECT blog_id FROM {$wpdb->blogs}" ); 562 foreach ( $blog_ids as $blog_id ) { 563 if ( 1 === (int) $blog_id ) 564 delete_option( 'wp_user_roles' ); 565 else 566 delete_option( "wp_{$blog_id}_user_roles" ); 567 } 803 568 } 804 569 } 805 570 -
wp-admin/includes/template.php
diff --git wp-admin/includes/template.php wp-admin/includes/template.php index d426533..289b378 100644
function wp_dropdown_roles( $selected = false ) { 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
diff --git wp-admin/network/site-settings.php wp-admin/network/site-settings.php index c3aec75..70b4122 100644
if ( ! empty( $messages ) ) { 109 109 <table class="form-table"> 110 110 <?php 111 111 $blog_prefix = $wpdb->get_blog_prefix( $id ); 112 $options = $wpdb->get_results( "SELECT * FROM {$blog_prefix}options WHERE option_name NOT LIKE '\_%' AND option_name NOT LIKE '%user_roles'" );112 $options = $wpdb->get_results( "SELECT * FROM {$blog_prefix}options WHERE option_name NOT LIKE '\_%' AND option_name != 'user_roles'" ); 113 113 foreach ( $options as $option ) { 114 114 if ( $option->option_name == 'default_role' ) 115 115 $editblog_default_role = $option->option_value; -
wp-includes/capabilities.php
diff --git wp-includes/capabilities.php wp-includes/capabilities.php index c3bb58f..89b59a3 100644
class WP_Roles { 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. … … class WP_Roles { 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 … … class WP_Roles { 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 ) ) … … class WP_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(); … … function is_super_admin( $user_id = false ) { 1466 1467 1467 1468 return false; 1468 1469 } 1470 1471 /** 1472 * WordPress Default User Roles. 1473 * 1474 * Allows regeneration of the required 'user_roles' option 1475 * 1476 * @acccess private 1477 * 1478 * @since 3.5.0 1479 * @package WordPress 1480 * @subpackage User 1481 */ 1482 class _WP_User_Roles { 1483 static $instance; 1484 private $roles = array(); 1485 1486 private function __construct() { 1487 if ( empty( $this->roles ) ) 1488 $this->populate(); 1489 } 1490 1491 static function init() { 1492 if ( ! isset( self::$instance ) ) 1493 self::$instance = new _WP_User_Roles; 1494 1495 return self::$instance->roles; 1496 } 1497 1498 private function populate() { 1499 $roles = array(); 1500 1501 /** 1502 * @since 2.1.0 1503 */ 1504 $caps_210 = array( 1505 'edit_others_pages' => 1, 1506 'edit_published_pages' => 1, 1507 'publish_pages' => 1, 1508 'delete_pages' => 1, 1509 'delete_others_pages' => 1, 1510 'delete_published_pages' => 1, 1511 'delete_posts' => 1, 1512 'delete_others_posts' => 1, 1513 'delete_published_posts' => 1, 1514 'delete_private_posts' => 1, 1515 'edit_private_posts' => 1, 1516 'read_private_posts' => 1, 1517 'delete_private_pages' => 1, 1518 'edit_private_pages' => 1, 1519 'read_private_pages' => 1 1520 ); 1521 1522 $admin_caps = array( 1523 /** 1524 * @since 1.6.0 1525 */ 1526 'switch_themes' => 1, 1527 'edit_themes' => 1, 1528 'activate_plugins' => 1, 1529 'edit_plugins' => 1, 1530 'edit_users' => 1, 1531 'edit_files' => 1, 1532 'manage_options' => 1, 1533 'moderate_comments' => 1, 1534 'manage_categories' => 1, 1535 'manage_links' => 1, 1536 'upload_files' => 1, 1537 'import', 1538 'unfiltered_html' => 1, 1539 'edit_posts' => 1, 1540 'edit_others_posts' => 1, 1541 'edit_published_posts' => 1, 1542 'publish_posts' => 1, 1543 'edit_pages' => 1, 1544 'read' => 1, 1545 /** 1546 * @since 2.1.0 1547 */ 1548 'delete_users' => 1, 1549 'create_users' => 1, 1550 /** 1551 * @since 2.3.0 1552 */ 1553 'unfiltered_upload' => 1, 1554 /** 1555 * @since 2.5.0 1556 */ 1557 'edit_dashboard' => 1, 1558 /** 1559 * @since 2.6.0 1560 */ 1561 'update_plugins' => 1, 1562 'delete_plugins' => 1, 1563 /** 1564 * @since 2.7.0 1565 */ 1566 'install_plugins' => 1, 1567 'update_themes' => 1, 1568 /** 1569 * @since 2.8.0 1570 */ 1571 'install_themes' => 1, 1572 /** 1573 * @since 3.0.0 1574 */ 1575 'update_core' => 1, 1576 'list_users' => 1, 1577 'remove_users' => 1, 1578 'add_users' => 1, 1579 'promote_users' => 1, 1580 'edit_theme_options' => 1, 1581 'delete_themes' => 1, 1582 'export' => 1, 1583 ); 1584 1585 /** 1586 * @since 1.6.0 1587 */ 1588 for ( $i = 0; $i <= 10; $i++ ) 1589 $admin_caps['level_' . $i] = 1; 1590 1591 /** 1592 * @since 2.1.0 1593 */ 1594 $admin_caps = array_merge( $admin_caps, $caps_210 ); 1595 1596 $roles[] = array( 1597 'administrator', 1598 /* translators: user role */ 1599 _x( 'Administrator', 'User role' ), 1600 $admin_caps 1601 ); 1602 1603 $editor_caps = array( 1604 /** 1605 * @since 1.6.0 1606 */ 1607 'moderate_comments' => 1, 1608 'manage_categories' => 1, 1609 'manage_links' => 1, 1610 'upload_files' => 1, 1611 'import' => 1, 1612 'unfiltered_html' => 1, 1613 'edit_posts' => 1, 1614 'edit_others_posts' => 1, 1615 'edit_published_posts' => 1, 1616 'publish_posts' => 1, 1617 'edit_pages' => 1, 1618 'read' => 1, 1619 ); 1620 /** 1621 * @since 1.6.0 1622 */ 1623 for ( $i = 0; $i <= 7; $i++ ) 1624 $editor_caps['level_' . $i] = 1; 1625 1626 /** 1627 * @since 2.1.0 1628 */ 1629 $editor_caps = array_merge( $editor_caps, $caps_210 ); 1630 1631 $roles[] = array( 1632 'editor', 1633 /* translators: user role */ 1634 _x( 'Editor', 'User role' ), 1635 $editor_caps 1636 ); 1637 1638 $author_caps = array( 1639 /** 1640 * @since 1.6.0 1641 */ 1642 'upload_files' => 1, 1643 'edit_posts' => 1, 1644 'edit_published_posts' => 1, 1645 'publish_posts' => 1, 1646 'read' => 1, 1647 /** 1648 * @since 2.1.0 1649 */ 1650 'delete_posts' => 1, 1651 'delete_published_posts' => 1 1652 ); 1653 /** 1654 * @since 1.6.0 1655 */ 1656 for ( $i = 0; $i <= 2; $i++ ) 1657 $author_caps['level_' . $i] = 1; 1658 1659 $roles[] = array( 1660 'author', 1661 /* translators: user role */ 1662 _x( 'Author', 'User role' ), 1663 $author_caps 1664 ); 1665 1666 $contributor_caps = array( 1667 /** 1668 * @since 1.6.0 1669 */ 1670 'edit_posts' => 1, 1671 'read' => 1, 1672 'level_0' => 1, 1673 'level_1' => 1, 1674 /** 1675 * @since 2.1.0 1676 */ 1677 'delete_posts' => 1, 1678 ); 1679 1680 $roles[] = array( 1681 'contributor', 1682 /* translators: user role */ 1683 _x( 'Contributor', 'User role' ), 1684 $contributor_caps 1685 ); 1686 1687 $subscriber_caps = array( 1688 /** 1689 * @since 1.6.0 1690 */ 1691 'read' => 1, 1692 'level_0' => 1 1693 ); 1694 1695 $roles[] = array( 1696 'subscriber', 1697 /* translators: user role */ 1698 _x( 'Subscriber', 'User role' ), 1699 $subscriber_caps 1700 ); 1701 1702 foreach ( $roles as $role ) { 1703 list( $slug, $name, $caps ) = $role; 1704 1705 $this->roles[$slug] = array( 1706 'name' => $name, 1707 'capabilities' => $caps 1708 ); 1709 } 1710 1711 update_option( 'user_roles', $this->roles ); 1712 } 1713 } 1714 No newline at end of file -
wp-includes/user.php
diff --git wp-includes/user.php wp-includes/user.php index bc583a5..03ef666 100644
function count_users($strategy = 'time') { 891 891 foreach ( $avail_roles as $this_role => $name ) { 892 892 $select_count[] = "COUNT(NULLIF(`meta_value` LIKE '%\"" . like_escape( $this_role ) . "\"%', false))"; 893 893 } 894 $select_count = implode(', ', $select_count); 895 894 895 if ( ! empty( $select_count ) ) 896 $select_count = implode(', ', $select_count) . ','; 897 else 898 $select_count = ''; 899 896 900 // Add the meta_value index to the selection list, then run the query. 897 $row = $wpdb->get_row( "SELECT $select_count ,COUNT(*) FROM $wpdb->usermeta WHERE meta_key = '{$blog_prefix}capabilities'", ARRAY_N );901 $row = $wpdb->get_row( "SELECT $select_count COUNT(*) FROM $wpdb->usermeta WHERE meta_key = '{$blog_prefix}capabilities'", ARRAY_N ); 898 902 899 903 // Run the previous loop again to associate results with role names. 900 904 $col = 0;