WordPress.org

Making WordPress.org

Changeset 4108


Ignore:
Timestamp:
09/20/2016 11:42:24 AM (4 years ago)
Author:
ocean90
Message:

Rosetta: Extend editor's capabilities to be able to change theme settings and manage users on team sites.

See #2003.

Location:
sites/trunk/wordpress.org/public_html/wp-content/plugins/rosetta/inc/site
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/rosetta/inc/site/class-locale-main.php

    r4082 r4108  
    157157     */
    158158    public function remove_administrator_from_editable_roles( $roles ) {
    159         if ( ! is_super_admin() && ! is_main_site() ) {
     159        if ( ! is_super_admin() ) {
    160160            unset( $roles['administrator'] );
    161161        }
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/rosetta/inc/site/class-locale-team.php

    r4031 r4108  
    4040     */
    4141    public function register_events() {
     42        $this->initialize_jetpack_customizations();
     43        $this->initialize_user_role_customizations();
     44    }
     45
     46    /**
     47     * Initializes customizations for Jetpack.
     48     */
     49    private function initialize_jetpack_customizations() {
    4250        $jetpack_module_manager = new Jetpack\Module_Manager( [
    4351            'stats',
     
    4654        $jetpack_module_manager->setup();
    4755    }
     56
     57    /**
     58     * Initializes user role customizations.
     59     */
     60    private function initialize_user_role_customizations() {
     61        add_filter( 'user_has_cap', [ $this, 'extend_editors_capabilities' ], 10, 4 );
     62        add_filter( 'editable_roles', [ $this, 'remove_administrator_from_editable_roles' ] );
     63    }
     64
     65    /**
     66     * Extends editor's capabilities to be able to change theme settings
     67     * and manage users.
     68     *
     69     * @param array   $allcaps An array of all the user's capabilities.
     70     * @param array   $caps    Actual capabilities for meta capability.
     71     * @param array   $args    Optional parameters passed to has_cap(), typically object ID.
     72     * @param WP_User $user    The user object.
     73     * @return array An array of user's capabilities.
     74     */
     75    public function extend_editors_capabilities( $allcaps, $caps, $args, $user ) {
     76        if ( ! in_array( 'editor', $user->roles ) ) {
     77            return $allcaps;
     78        }
     79
     80        $allcaps['edit_theme_options'] = true;
     81        $allcaps['list_users']         = true;
     82        $allcaps['promote_users']      = true;
     83        $allcaps['remove_users']       = true;
     84
     85        return $allcaps;
     86    }
     87
     88    /**
     89     * Removes "Administrator" role from the list of editable roles.
     90     *
     91     * @param array $roles List of roles.
     92     * @return array Filtered list of editable roles.
     93     */
     94    public function remove_administrator_from_editable_roles( $roles ) {
     95        if ( ! is_super_admin() ) {
     96            unset( $roles['administrator'] );
     97        }
     98
     99        return $roles;
     100    }
    48101}
Note: See TracChangeset for help on using the changeset viewer.