Making WordPress.org


Ignore:
Timestamp:
12/17/2015 12:32:48 PM (9 years ago)
Author:
ocean90
Message:

Rosetta: Update roles plugin to use the new translation_editors table.

  • Introduce a new role for General Translation Editors.
  • Introduce a new capability to manage Translation Editors, assigned to General Translation Editors.
  • Fix wrong action name for bulk removal.
  • Remove custom "Role" column, obsolete with WordPress 4.4.
  • Introduce translation_editor_added, translation_editor_updated and translation_editor_removed actions.
  • Make "Translation Editors" a top-level menu.
  • Add views to the "Translation Editors" table.

See #1240.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/global.wordpress.org/public_html/wp-content/mu-plugins/roles/class-translation-editors-list-table.php

    r2001 r2197  
    88
    99    /**
    10      * Holds the role of a translation editor.
    11      *
    12      * @var string
    13      */
    14     public $user_role;
    15 
    16     /**
    17      * Holds the meta key of the project access list.
    18      *
    19      * @var string
    20      */
    21     public $project_access_meta_key;
     10     * Holds the roles for translation editors.
     11     *
     12     * @var arrays
     13     */
     14    public $user_roles;
     15
     16    /**
     17     * Holds the instance of the Rosetta_Roles class.
     18     *
     19     * @var Rosetta_Roles
     20     */
     21    public $rosetta_roles;
    2222
    2323    /**
     
    5656        ) );
    5757
    58         $this->user_role = $args['user_role'];
    59         $this->project_access_meta_key = $args['project_access_meta_key'];
    60         $this->projects = $args['projects'];
    61         $this->project_tree = $args['project_tree'];
    62         $this->user_can_promote = current_user_can( 'promote_users' );
     58        $this->user_roles       = $args['user_roles'];
     59        $this->projects         = $args['projects'];
     60        $this->project_tree     = $args['project_tree'];
     61        $this->rosetta_roles    = $args['rosetta_roles'];
     62        $this->user_can_promote = current_user_can( Rosetta_Roles::MANAGE_TRANSLATION_EDITORS_CAP );
    6363    }
    6464
     
    7171        $paged =    $this->get_pagenum();
    7272
     73        $role__in = $this->user_roles;
     74        if ( isset( $_REQUEST['role'] ) ) {
     75            $role__in = $_REQUEST['role'];
     76        }
     77
    7378        $args = array(
    74             'number' => $per_page,
    75             'offset' => ( $paged - 1 ) * $per_page,
    76             'role'   => $this->user_role,
    77             'search' => $search,
    78             'fields' => 'all_with_meta'
     79            'number'   => $per_page,
     80            'offset'   => ( $paged - 1 ) * $per_page,
     81            'role__in' => $role__in,
     82            'search'   => $search,
     83            'fields'   => 'all_with_meta'
    7984        );
    8085
     
    137142
    138143    /**
     144     * Provides a list of roles and user count for that role for easy
     145     * filtering of the table.
     146     *
     147     * @return array An array of HTML links, one for each view.
     148     */
     149    protected function get_views() {
     150        $class = '';
     151        $view_links = array();
     152
     153        $users_of_blog = count_users();
     154
     155        $count_translation_editors = isset( $users_of_blog['avail_roles'][ Rosetta_Roles::TRANSLATION_EDITOR_ROLE ] ) ? $users_of_blog['avail_roles'][ Rosetta_Roles::TRANSLATION_EDITOR_ROLE ] : 0 ;
     156        $count_general_translation_editors = isset( $users_of_blog['avail_roles'][ Rosetta_Roles::GENERAL_TRANSLATION_EDITOR_ROLE ] ) ? $users_of_blog['avail_roles'][ Rosetta_Roles::GENERAL_TRANSLATION_EDITOR_ROLE ] : 0 ;
     157        $total_translation_editors = $count_translation_editors + $count_general_translation_editors;
     158
     159        $all_inner_html = sprintf(
     160            _nx(
     161                'All <span class="count">(%s)</span>',
     162                'All <span class="count">(%s)</span>',
     163                $total_translation_editors,
     164                'translation editors'
     165            ),
     166            number_format_i18n( $total_translation_editors )
     167        );
     168
     169        if ( ! isset( $_REQUEST['role'] ) ) {
     170            $class = 'current';
     171        }
     172
     173        $view_links['all'] = $this->get_view_link( array(), $all_inner_html, $class );
     174
     175        if ( $count_translation_editors ) {
     176            $class = '';
     177            $translation_editors_inner_html = sprintf(
     178                _n(
     179                    'Translation Editor <span class="count">(%s)</span>',
     180                    'Translation Editor <span class="count">(%s)</span>',
     181                    $count_translation_editors
     182                ),
     183                number_format_i18n( $count_translation_editors )
     184            );
     185
     186            if ( isset( $_REQUEST['role'] ) && Rosetta_Roles::TRANSLATION_EDITOR_ROLE === $_REQUEST['role'] ) {
     187                $class = 'current';
     188            }
     189
     190            $view_links[ Rosetta_Roles::TRANSLATION_EDITOR_ROLE ] = $this->get_view_link( array( 'role' => Rosetta_Roles::TRANSLATION_EDITOR_ROLE ), $translation_editors_inner_html, $class );
     191        }
     192
     193        if ( $count_translation_editors ) {
     194            $class = '';
     195            $general_translation_editors_inner_html = sprintf(
     196                _n(
     197                    'General Translation Editor <span class="count">(%s)</span>',
     198                    'General Translation Editor <span class="count">(%s)</span>',
     199                    $count_general_translation_editors
     200                ),
     201                number_format_i18n( $count_general_translation_editors )
     202            );
     203
     204            if ( isset( $_REQUEST['role'] ) && Rosetta_Roles::GENERAL_TRANSLATION_EDITOR_ROLE === $_REQUEST['role'] ) {
     205                $class = 'current';
     206            }
     207
     208            $view_links[ Rosetta_Roles::GENERAL_TRANSLATION_EDITOR_ROLE ] = $this->get_view_link( array( 'role' => Rosetta_Roles::GENERAL_TRANSLATION_EDITOR_ROLE ), $general_translation_editors_inner_html, $class );
     209        }
     210
     211        return $view_links;
     212    }
     213
     214    /**
     215     * Helper to create view links with params.
     216     *
     217     * @param array  $args  URL parameters for the link.
     218     * @param string $label Link text.
     219     * @param string $class Optional. Class attribute. Default empty string.
     220     * @return string The formatted link string.
     221     */
     222    protected function get_view_link( $args, $label, $class = '' ) {
     223        $page_url = menu_page_url( 'translation-editors', false );
     224        $url = add_query_arg( $args, $page_url );
     225
     226        $class_html = '';
     227        if ( ! empty( $class ) ) {
     228             $class_html = sprintf(
     229                ' class="%s"',
     230                esc_attr( $class )
     231            );
     232        }
     233
     234        return sprintf(
     235            '<a href="%s"%s>%s</a>',
     236            esc_url( $url ),
     237            $class_html,
     238            $label
     239        );
     240    }
     241
     242    /**
    139243     * Return a list of bulk actions available on this table.
    140244     *
     
    143247    protected function get_bulk_actions() {
    144248        return array(
    145             'remove' => _x( 'Remove', 'translation editor', 'rosetta' ),
     249            'remove-translation-editors' => _x( 'Remove', 'translation editor', 'rosetta' ),
    146250        );
    147251    }
     
    210314     */
    211315    public function column_email( $user ) {
    212         echo "<a href='mailto:$user->user_email'>$user->user_email</a>";
     316        echo "<a href='" . esc_url( "mailto:$user->user_email" ) . "'>$user->user_email</a>";
    213317    }
    214318
     
    219323     */
    220324    public function column_projects( $user ) {
    221         $project_access_list = get_user_meta( $user->ID, $this->project_access_meta_key, true );
     325        $project_access_list = $this->rosetta_roles->get_users_projects( $user->ID );
    222326
    223327        if ( empty( $project_access_list ) ) {
     
    226330        }
    227331
    228         if ( in_array( 'all', $project_access_list ) ) {
     332        if ( in_array( 'all', $project_access_list, true ) ) {
    229333            _e( 'All projects', 'rosetta' );
    230334            return;
Note: See TracChangeset for help on using the changeset viewer.