Making WordPress.org


Ignore:
Timestamp:
09/16/2016 09:17:20 PM (8 years ago)
Author:
ocean90
Message:

Rosetta Roles: Remove handling for custom roles.

This has been migrated to the Rosetta plugin.

See #2003, #1398.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/global.wordpress.org/public_html/wp-content/mu-plugins/roles/rosetta-roles.php

    r2697 r4084  
    6868        $this->gp_locale = $gp_locale;
    6969
    70         add_filter( 'editable_roles', array( $this, 'editable_roles' ) );
    71         add_action( 'admin_init', array( $this, 'role_modifications' ) );
    72         add_action( 'set_user_role', array( $this, 'restore_translation_editor_role' ), 10, 3 );
    73         add_filter( 'gettext_with_context', array( $this, 'rename_user_roles' ), 10, 4 );
    7470        add_action( 'admin_menu', array( $this, 'register_translation_editors_page' ) );
    7571        add_filter( 'set-screen-option', array( $this, 'save_custom_screen_options' ), 10, 3 );
     
    7975
    8076        add_action( 'wp_ajax_rosetta-get-projects', array( $this, 'ajax_rosetta_get_projects' ) );
    81     }
    82 
    83     /**
    84      * Registers "(General) Translation Editor" role and modifies editor role.
    85      */
    86     public function role_modifications() {
    87         if ( ! get_role( self::TRANSLATION_EDITOR_ROLE ) ) {
    88             add_role( self::TRANSLATION_EDITOR_ROLE, __( 'Translation Editor', 'rosetta' ), array( 'read' => true, 'level_0' => true ) );
    89         }
    90 
    91         if ( ! get_role( self::GENERAL_TRANSLATION_EDITOR_ROLE ) ) {
    92             add_role( self::GENERAL_TRANSLATION_EDITOR_ROLE, __( 'General Translation Editor', 'rosetta' ), array( 'read' => true, 'level_0' => true, self::MANAGE_TRANSLATION_EDITORS_CAP => true ) );
    93         }
    94 
    95         $editor_role = get_role( 'editor' );
    96         if ( $editor_role && ! $editor_role->has_cap( 'remove_users' ) ) {
    97             $editor_role->add_cap( 'edit_theme_options' );
    98             $editor_role->add_cap( 'list_users' );
    99             $editor_role->add_cap( 'promote_users' );
    100             $editor_role->add_cap( 'remove_users' );
    101         }
    102     }
    103 
    104     /**
    105      * Restores the "(General) Translation Editor" role if an user is promoted.
    106      *
    107      * @param int    $user_id   The user ID.
    108      * @param string $role      The new role.
    109      * @param array  $old_roles An array of the user's previous roles.
    110      */
    111     public function restore_translation_editor_role( $user_id, $role, $old_roles ) {
    112         if ( self::GENERAL_TRANSLATION_EDITOR_ROLE !== $role && in_array( self::TRANSLATION_EDITOR_ROLE, $old_roles ) ) {
    113             $user = new WP_User( $user_id );
    114             $user->add_role( self::TRANSLATION_EDITOR_ROLE );
    115         }
    116 
    117         if ( self::TRANSLATION_EDITOR_ROLE !== $role && in_array( self::GENERAL_TRANSLATION_EDITOR_ROLE, $old_roles ) ) {
    118             $user = new WP_User( $user_id );
    119             $user->add_role( self::GENERAL_TRANSLATION_EDITOR_ROLE );
    120         }
    121     }
    122 
    123     /**
    124      * Removes "Translation Editor" role and "Administrator" role from
    125      * the list of editable roles.
    126      *
    127      * The list used in wp_dropdown_roles() on users list table.
    128      *
    129      * @param array $roles List of roles.
    130      * @return array Filtered list of editable roles.
    131      */
    132     public function editable_roles( $roles ) {
    133         unset( $roles[ self::TRANSLATION_EDITOR_ROLE ], $roles[ self::GENERAL_TRANSLATION_EDITOR_ROLE ] );
    134 
    135         if ( ! is_super_admin() && ! is_main_site() ) {
    136             unset( $roles['administrator'] );
    137         }
    138 
    139         return $roles;
    140     }
    141 
    142     /**
    143      * Translates the "Translation Editor" role.
    144      *
    145      * @param string $translation Translated text.
    146      * @param string $text        Text to translate.
    147      * @param string $context     Context information for the translators.
    148      * @param string $domain      Text domain.
    149      * @return string Translated user role.
    150      */
    151     public function rename_user_roles( $translation, $text, $context, $domain ) {
    152         if ( $domain !== 'default' || $context !== 'User role' ) {
    153             return $translation;
    154         }
    155 
    156         if ( 'Translation Editor' === $text ) {
    157             return __( 'Translation Editor', 'rosetta' );
    158         } elseif ( 'General Translation Editor' === $text ) {
    159             return __( 'General Translation Editor', 'rosetta' );
    160         }
    161 
    162         return $translation;
    16377    }
    16478
Note: See TracChangeset for help on using the changeset viewer.