Making WordPress.org


Ignore:
Timestamp:
09/16/2016 08:56:17 PM (10 years ago)
Author:
ocean90
Message:

Translate, Rosetta Roles: Add support for the new locale manager role.

See #1398.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-rosetta-roles/inc/class-plugin.php

    r3954 r4083  
    2929         */
    3030        const GENERAL_TRANSLATION_EDITOR_ROLE = 'general_translation_editor';
     31
     32        /**
     33         * Role of a locale manager.
     34         */
     35        const LOCALE_MANAGER_ROLE = 'locale_manager';
    3136
    3237        /**
    … …  
    102107
    103108                // Simple check to see if they're an approver or not.
    104                 if ( ! $this->is_approver_for_locale( $args['user_id'], $locale_slug ) ) {
    105                         return false;
     109                $role = $this->is_approver_for_locale( $args['user_id'], $locale_slug );
     110                if ( ! $role ) {
     111                        return false;
     112                }
     113
     114                // Locale managers are allowed to approve all projects.
     115                if ( self::LOCALE_MANAGER_ROLE === $role ) {
     116                        return true;
    106117                }
    107118
    … …  
    170181         * @param int    $user_id     User ID.
    171182         * @param string $locale_slug The Locale for which we are checking.
    172          * @return bool True, if user is an approver, false if not.
     183         * @return false|string Role, if user is an approver, false if not.
    173184         */
    174185        public function is_approver_for_locale( $user_id, $locale_slug ) {
    … …  
    202213
    203214                $capabilities = $user->{$cap_key};
    204                 $is_approver = ! empty( $capabilities[ self::TRANSLATION_EDITOR_ROLE ] ) || ! empty( $capabilities[ self::GENERAL_TRANSLATION_EDITOR_ROLE ] );
    205                 $cache[ $user_id ][ $locale_slug ] = $is_approver;
    206 
    207                 return $is_approver;
     215
     216                if ( ! empty( $capabilities[ self::LOCALE_MANAGER_ROLE ] ) ) {
     217                        $cache[ $user_id ][ $locale_slug ] = self::LOCALE_MANAGER_ROLE;
     218                        return self::LOCALE_MANAGER_ROLE;
     219                } elseif ( ! empty( $capabilities[ self::GENERAL_TRANSLATION_EDITOR_ROLE ] ) ) {
     220                        $cache[ $user_id ][ $locale_slug ] = self::GENERAL_TRANSLATION_EDITOR_ROLE;
     221                        return self::GENERAL_TRANSLATION_EDITOR_ROLE;
     222                } elseif ( ! empty( $capabilities[ self::TRANSLATION_EDITOR_ROLE ] ) ) {
     223                        $cache[ $user_id ][ $locale_slug ] = self::TRANSLATION_EDITOR_ROLE;
     224                        return self::TRANSLATION_EDITOR_ROLE;
     225                } else {
     226                        $cache[ $user_id ][ $locale_slug ] = false;
     227                        return false;
     228                }
    208229        }
    209230
Note: See TracChangeset for help on using the changeset viewer.