Ticket #741: 741-muplugin.patch
File 741-muplugin.patch, 26.3 KB (added by , 10 years ago) |
---|
-
trunk/global.wordpress.org/public_html/wp-content/mu-plugins/roles/class-translation-editors-list-table.php
1 <?php 2 3 if ( ! class_exists( 'WP_List_Table' ) ) { 4 require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php'; 5 } 6 7 class Rosetta_Translation_Editors_List_Table extends WP_List_Table { 8 9 public $role; 10 11 public $user_can_promote; 12 13 /** 14 * Constructor. 15 * 16 * @param array $args An associative array of arguments. 17 */ 18 public function __construct( $args = array() ) { 19 parent::__construct( array( 20 'singular' => 'translation-editor', 21 'plural' => 'translation-editors', 22 'screen' => isset( $args['screen'] ) ? $args['screen'] : null, 23 ) ); 24 25 $this->role = $args['role']; 26 $this->user_can_promote = current_user_can( 'promote_users' ); 27 } 28 29 /** 30 * Prepare the list for display. 31 */ 32 public function prepare_items() { 33 $search = isset( $_REQUEST['s'] ) ? wp_unslash( trim( $_REQUEST['s'] ) ) : ''; 34 $per_page = 20; 35 $paged = $this->get_pagenum(); 36 37 $args = array( 38 'number' => $per_page, 39 'offset' => ( $paged - 1 ) * $per_page, 40 'role' => $this->role, 41 'search' => $search, 42 'fields' => 'all_with_meta' 43 ); 44 45 if ( '' !== $args['search'] ) { 46 $args['search'] = '*' . $args['search'] . '*'; 47 } 48 49 if ( isset( $_REQUEST['orderby'] ) ) { 50 $args['orderby'] = $_REQUEST['orderby']; 51 } 52 53 if ( isset( $_REQUEST['order'] ) ) { 54 $args['order'] = $_REQUEST['order']; 55 } 56 57 $user_query = new WP_User_Query( $args ); 58 $this->items = $user_query->get_results(); 59 60 $columns = $this->get_columns(); 61 $hidden = array(); 62 $sortable = $this->get_sortable_columns(); 63 $this->_column_headers = array( $columns, $hidden, $sortable ); 64 65 $this->set_pagination_args( array( 66 'total_items' => $user_query->get_total(), 67 'per_page' => $per_page, 68 ) ); 69 } 70 71 /** 72 * Output 'no users' message. 73 */ 74 public function no_items() { 75 _e( 'No users were found.', 'rosetta' ); 76 } 77 78 /** 79 * Get a list of columns for the list table. 80 * 81 * @return array Array in which the key is the ID of the column, 82 * and the value is the description. 83 */ 84 public function get_columns() { 85 return array( 86 'cb' => '<input type="checkbox" />', 87 'username' => __( 'Username', 'rosetta' ), 88 'name' => __( 'Name', 'rosetta' ), 89 'email' => __( 'E-mail', 'rosetta' ), 90 ); 91 } 92 93 /** 94 * Get a list of sortable columns for the list table. 95 * 96 * @return array Array of sortable columns. 97 */ 98 protected function get_sortable_columns() { 99 return array( 100 'username' => 'login', 101 'name' => 'name', 102 'email' => 'email', 103 ); 104 } 105 106 /** 107 * Return a list of bulk actions available on this table. 108 * 109 * @return array Array of bulk actions. 110 */ 111 protected function get_bulk_actions() { 112 return array( 113 'remove' => _x( 'Remove', 'user', 'rosetta' ), 114 ); 115 } 116 117 /** 118 * Generates content for a single row of the table. 119 * 120 * @param WP_User $user The current user. 121 */ 122 public function single_row( $user ) { 123 $user->filter = 'display'; 124 parent::single_row( $user ); 125 } 126 127 /** 128 * Prints the checkbox column. 129 * 130 * @param WP_User $user The current user. 131 */ 132 public function column_cb( $user ) { 133 if ( $this->user_can_promote ) { 134 ?> 135 <label class="screen-reader-text" for="cb-select-<?php echo $user->ID; ?>"><?php _e( 'Select user', 'rosetta' ); ?></label> 136 <input id="cb-select-<?php echo $user->ID; ?>" type="checkbox" name="translation-editors[]" value="<?php echo $user->ID; ?>" /> 137 <?php 138 } 139 } 140 141 /** 142 * Prints the username column. 143 * 144 * @param WP_User $user The current user. 145 */ 146 public function column_username( $user ) { 147 $avatar = get_avatar( $user->ID, 32 ); 148 149 if ( $this->user_can_promote ) { 150 $page_url = menu_page_url( 'translation-editors', false ); 151 $edit_link = esc_url( add_query_arg( 'user_id', $user->ID, $page_url ) ); 152 $edit = "<strong><a href=\"$edit_link\">$user->user_login</a></strong>"; 153 154 $actions = array(); 155 $actions['edit'] = '<a href="' . $edit_link . '">' . __( 'Edit', 'rosetta' ) . '</a>'; 156 $actions['remove'] = '<a class="submitdelete" href="' . wp_nonce_url( $page_url . "&action=remove-translation-editor&translation-editor=$user->ID", 'remove-translation-editor' ) . '">' . __( 'Remove', 'rosetta' ) . '</a>'; 157 $edit .= $this->row_actions( $actions ); 158 } else { 159 $edit = "<strong>$user->user_login</strong>"; 160 } 161 162 echo "$avatar $edit"; 163 } 164 165 /** 166 * Prints the name column. 167 * 168 * @param WP_User $user The current user. 169 */ 170 public function column_name( $user ) { 171 echo "$user->first_name $user->last_name"; 172 } 173 174 /** 175 * Prints the email column. 176 * 177 * @param WP_User $user The current user. 178 */ 179 public function column_email( $user ) { 180 echo "<a href='mailto:$user->user_email'>$user->user_email</a>"; 181 } 182 } -
trunk/global.wordpress.org/public_html/wp-content/mu-plugins/roles/js/rosetta-roles.js
1 ( function( $ ) { 2 3 $(function() { 4 var $projects = $( 'input.project' ); 5 6 if ( $projects.length ) { 7 var $allProjects = $( '#project-all' ), 8 checked = []; 9 10 // Uncheck "All" if a project is checked. 11 $projects.on( 'change', function() { 12 $allProjects.prop( 'checked', false ); 13 checked = []; 14 } ); 15 16 // (Un)check projects if "All" is (un)checked. 17 $allProjects.on( 'change', function() { 18 if ( this.checked ) { 19 $projects.each( function( index, checkbox ) { 20 var $cb = $( checkbox ); 21 if ( $cb.prop( 'checked' ) ) { 22 checked.push( $cb.attr( 'id' ) ); 23 $cb.prop( 'checked', false ); 24 } 25 } ); 26 } else { 27 for ( i = 0; i < checked.length; i++ ) { 28 $( '#' + checked[ i ] ).prop( 'checked', true ); 29 } 30 checked = []; 31 } 32 } ); 33 34 // Uncheck all checkboxes. 35 $( '#clear-all' ).on( 'click', function( event ) { 36 event.preventDefault(); 37 38 checked = []; 39 $allProjects.prop( 'checked', false ); 40 $projects.prop( 'checked', false ); 41 } ); 42 } 43 } ); 44 } )( jQuery ); -
trunk/global.wordpress.org/public_html/wp-content/mu-plugins/roles/rosetta-roles.php
1 1 <?php 2 /** 3 * Plugin Name: Rosetta Roles 4 * Plugin URI: https://wordpress.org/ 5 * Description: WordPress interface for managing roles. 6 * Author: Dominik Schilling 7 * Version: 1.0 8 */ 2 9 3 add_filter( 'gettext_with_context', 'ros_rename_user_roles', 10, 4 ); 4 function ros_rename_user_roles( $translated, $text, $context, $domain ) { 5 if ( $domain !== 'default' || $context !== 'User role' ) { 6 return $translated; 10 class Rosetta_Roles { 11 12 /** 13 * Holds the role of a Translation Editor. 14 * 15 * @var string 16 */ 17 public $translation_editor_role = 'translation_editor'; 18 19 /** 20 * Attaches hooks once plugins are loaded. 21 */ 22 public function plugins_loaded() { 23 add_filter( 'editable_roles', array( $this, 'editable_roles' ) ); 24 add_filter( 'manage_users_columns', array( $this, 'add_roles_column' ) ); 25 add_filter( 'manage_users_custom_column', array( $this, 'display_user_roles' ), 10, 3 ); 26 add_action( 'admin_init', array( $this, 'role_modifications' ) ); 27 add_action( 'set_user_role', array( $this, 'restore_translation_editor_role' ), 10, 3 ); 28 add_filter( 'gettext_with_context', array( $this, 'rename_user_roles' ), 10, 4 ); 29 add_action( 'user_row_actions', array( $this, 'user_row_action_role_editor' ), 10, 2 ); 30 add_action( 'admin_menu', array( $this, 'register_translation_editors_page' ) ); 7 31 } 8 if ( 'Validator' === $text ) { 9 return __( 'Validator', 'rosetta' ); 32 33 /** 34 * Registers "Translation Editor" role and modifies editor role. 35 */ 36 public function role_modifications() { 37 if ( ! get_role( $this->translation_editor_role ) ) { 38 add_role( $this->translation_editor_role, __( 'Translation Editor', 'rosetta' ), array( 'read' => true, 'level_0' => true ) ); 39 } 40 41 $editor_role = get_role( 'editor' ); 42 if ( $editor_role && ! $editor_role->has_cap( 'remove_users' ) ) { 43 $editor_role->add_cap( 'edit_theme_options' ); 44 $editor_role->add_cap( 'list_users' ); 45 $editor_role->add_cap( 'promote_users' ); 46 $editor_role->add_cap( 'remove_users' ); 47 } 48 49 // Remove deprecated validator role. 50 /*$validator_role = get_role( 'validator' ); 51 if ( $validator_role ) { 52 remove_role( 'validator' ); 53 }*/ 10 54 } 11 return $translated;12 }13 55 14 add_action( 'admin_menu', 'ros_remove_widgets_menu' ); 15 function ros_remove_widgets_menu() { 16 remove_submenu_page( 'themes.php', 'themes.php' ); 17 remove_submenu_page( 'themes.php', 'widgets.php' ); 18 } 56 /** 57 * Restores the "Translation Editor" role if an user is promoted. 58 * 59 * @param int $user_id The user ID. 60 * @param string $role The new role. 61 * @param array $old_roles An array of the user's previous roles. 62 */ 63 public function restore_translation_editor_role( $user_id, $role, $old_roles ) { 64 if ( ! in_array( $this->translation_editor_role, $old_roles ) ) { 65 return; 66 } 19 67 20 add_filter( 'editable_roles', 'ros_editable_roles' ); 21 function ros_editable_roles( $roles ) { 22 $subscriber = $roles['subscriber']; 23 unset( $roles['subscriber'] ); 24 reset( $roles ); 25 $roles['subscriber'] = $subscriber; 26 if ( ! is_super_admin() && ! is_main_site() ) { 27 unset( $roles['administrator'] ); 68 $user = new WP_User( $user_id ); 69 $user->add_role( $this->translation_editor_role ); 28 70 } 29 return $roles;30 }31 71 32 add_filter( 'admin_init', 'ros_role_modifications' ); 33 function ros_role_modifications() { 34 if ( ! get_role( 'validator' ) ) { 35 add_role( 'validator', __( 'Validator', 'rosetta' ), array( 'read' => true, 'level_0' => true ) ); 72 /** 73 * Removes "Translation Editor" role and "Administrator" role from 74 * the list of editable roles. 75 * 76 * The list used in wp_dropdown_roles() on users list table. 77 * 78 * @param array $all_roles List of roles. 79 * @return array Filtered list of editable roles. 80 */ 81 public function editable_roles( $roles ) { 82 unset( $roles[ $this->translation_editor_role ] ); 83 84 if ( ! is_super_admin() && ! is_main_site() ) { 85 unset( $roles['administrator'] ); 86 } 87 88 return $roles; 36 89 } 37 $editor_role = get_role( 'editor' ); 38 if ( $editor_role && ! $editor_role->has_cap( 'remove_users' ) ) { 39 $editor_role->add_cap( 'edit_theme_options' ); 40 $editor_role->add_cap( 'list_users' ); 41 $editor_role->add_cap( 'promote_users' ); 42 $editor_role->add_cap( 'remove_users' ); 90 91 /** 92 * Translates the "Translation Editor" role. 93 * 94 * @param string $translation Translated text. 95 * @param string $text Text to translate. 96 * @param string $context Context information for the translators. 97 * @param string $domain Text domain. 98 * @return string Translated user role. 99 */ 100 public function rename_user_roles( $translation, $text, $context, $domain ) { 101 if ( $domain !== 'default' || $context !== 'User role' ) { 102 return $translation; 103 } 104 105 if ( 'Translation Editor' === $text ) { 106 return __( 'Translation Editor', 'rosetta' ); 107 } 108 109 return $translation; 43 110 } 111 112 /** 113 * Replaces the "Role" column with a "Roles" column. 114 * 115 * @param array $columns An array of column headers. 116 * @return array An array of column headers. 117 */ 118 public function add_roles_column( $columns ) { 119 $posts = $columns['posts']; 120 unset( $columns['role'], $columns['posts'] ); 121 reset( $columns ); 122 $columns['roles'] = __( 'Roles', 'rosetta' ); 123 $columns['posts'] = $posts; 124 125 return $columns; 126 } 127 128 /** 129 * Displays a comma separated list of user's roles. 130 * 131 * @param string $output Custom column output. 132 * @param string $column_name Column name. 133 * @param int $user_id ID of the currently-listed user. 134 * @return string Comma separated list of user's roles. 135 */ 136 public function display_user_roles( $output, $column_name, $user_id ) { 137 global $wp_roles; 138 139 if ( 'roles' == $column_name ) { 140 $user_roles = array(); 141 $user = new WP_User( $user_id ); 142 foreach ( $user->roles as $role ) { 143 $role_name = $wp_roles->role_names[ $role ]; 144 $role_name = translate_user_role( $role_name ); 145 $user_roles[] = $role_name; 146 } 147 148 return implode( ', ', $user_roles ); 149 } 150 151 return $output; 152 } 153 154 /** 155 * Registers page for managing translation editors. 156 */ 157 public function register_translation_editors_page() { 158 $this->translation_editors_page = add_users_page( 159 __( 'Translation Editors', 'rosetta' ), 160 __( 'Translation Editors', 'rosetta' ), 161 'list_users', 162 'translation-editors', 163 array( $this, 'render_translation_editors_page' ) 164 ); 165 166 add_action( 'load-' . $this->translation_editors_page, array( $this, 'load_translation_editors_page' ) ); 167 add_action( 'admin_print_scripts-' . $this->translation_editors_page, array( $this, 'enqueue_scripts' ) ); 168 } 169 170 /** 171 * Enqueues scripts. 172 */ 173 public function enqueue_scripts() { 174 wp_enqueue_script( 'rosetta-roles', plugins_url( '/js/rosetta-roles.js', __FILE__ ), array( 'jquery' ), '1', true ); 175 } 176 177 /** 178 * Loads either the overview or the edit handler. 179 */ 180 public function load_translation_editors_page() { 181 if ( ! empty( $_REQUEST['user_id'] ) ) { 182 $this->load_edit_translation_editor( $_REQUEST['user_id'] ); 183 } else { 184 $this->load_translation_editors(); 185 } 186 } 187 188 /** 189 * Renders either the overview or the edit view. 190 */ 191 public function render_translation_editors_page() { 192 if ( ! empty( $_REQUEST['user_id'] ) ) { 193 $this->render_edit_translation_editor( $_REQUEST['user_id'] ); 194 } else { 195 $this->render_translation_editors(); 196 } 197 } 198 199 /** 200 * Handler for overview page. 201 */ 202 private function load_translation_editors() { 203 global $wpdb; 204 205 $list_table = $this->get_translation_editors_list_table(); 206 $action = $list_table->current_action(); 207 $redirect = menu_page_url( 'translation-editors', false ); 208 209 if ( $action ) { 210 switch ( $action ) { 211 case 'add-translation-editor': 212 check_admin_referer( 'add-translation-editor', '_nonce_add-translation-editor' ); 213 214 if ( ! current_user_can( 'promote_users' ) ) { 215 wp_redirect( $redirect ); 216 exit; 217 } 218 219 $user_details = null; 220 $user = wp_unslash( $_REQUEST['user'] ); 221 if ( false !== strpos( $user_email, '@' ) ) { 222 $user_details = get_user_by( 'email', $user ); 223 } else { 224 $user_details = get_user_by( 'login', $user ); 225 } 226 227 if ( ! $user_details ) { 228 wp_redirect( add_query_arg( array( 'error' => 'no-user-found' ), $redirect ) ); 229 exit; 230 } 231 232 if ( ! is_user_member_of_blog( $user_details->ID ) ) { 233 wp_redirect( add_query_arg( array( 'error' => 'not-a-member' ), $redirect ) ); 234 exit; 235 } 236 237 if ( user_can( $user_details, $this->translation_editor_role ) ) { 238 wp_redirect( add_query_arg( array( 'error' => 'user-exists' ), $redirect ) ); 239 exit; 240 } 241 242 $user_details->add_role( $this->translation_editor_role ); 243 244 wp_redirect( add_query_arg( array( 'update' => 'user-added' ), $redirect ) ); 245 exit; 246 case 'remove-translation-editors': 247 check_admin_referer( 'bulk-translation-editors' ); 248 249 if ( ! current_user_can( 'promote_users' ) ) { 250 wp_redirect( $redirect ); 251 exit; 252 } 253 254 if ( empty( $_REQUEST['translation-editors'] ) ) { 255 wp_redirect( $redirect ); 256 exit; 257 } 258 259 $count = 0; 260 $meta_key = $wpdb->get_blog_prefix() . 'allowed_translate_projects'; 261 $user_ids = array_map( 'intval', (array) $_REQUEST['translation-editors'] ); 262 foreach ( $user_ids as $user_id ) { 263 $user = get_user_by( 'id', $user_id ); 264 $user->remove_role( $this->translation_editor_role ); 265 delete_user_meta( $user_id, $meta_key ); 266 $count++; 267 } 268 269 wp_redirect( add_query_arg( array( 'update' => 'user-removed', 'count' => $count ), $redirect ) ); 270 exit; 271 case 'remove-translation-editor': 272 check_admin_referer( 'remove-translation-editor' ); 273 274 if ( ! current_user_can( 'promote_users' ) ) { 275 wp_redirect( $redirect ); 276 exit; 277 } 278 279 if ( empty( $_REQUEST['translation-editor'] ) ) { 280 wp_redirect( $redirect ); 281 exit; 282 } 283 284 $user_id = (int) $_REQUEST['translation-editor']; 285 $user = get_user_by( 'id', $user_id ); 286 $user->remove_role( $this->translation_editor_role ); 287 $meta_key = $wpdb->get_blog_prefix() . 'allowed_translate_projects'; 288 delete_user_meta( $user_id, $meta_key ); 289 290 wp_redirect( add_query_arg( array( 'update' => 'user-removed' ), $redirect ) ); 291 exit; 292 } 293 } 294 } 295 296 /** 297 * Handler for editing a translation editor. 298 * 299 * @param int $user_id User ID of a translation editor. 300 */ 301 private function load_edit_translation_editor( $user_id ) { 302 global $wpdb; 303 304 $redirect = menu_page_url( 'translation-editors', false ); 305 $user_details = get_user_by( 'id', $user_id ); 306 307 if ( ! $user_details ) { 308 wp_redirect( add_query_arg( array( 'error' => 'no-user-found' ), $redirect ) ); 309 exit; 310 } 311 312 if ( ! is_user_member_of_blog( $user_details->ID ) ) { 313 wp_redirect( add_query_arg( array( 'error' => 'not-a-member' ), $redirect ) ); 314 exit; 315 } 316 317 if ( ! user_can( $user_details, $this->translation_editor_role ) ) { 318 wp_redirect( add_query_arg( array( 'error' => 'user-cannot' ), $redirect ) ); 319 exit; 320 } 321 322 $action = $_REQUEST['action']; 323 switch ( $action ) { 324 case 'update-translation-editor': 325 check_admin_referer( 'update-translation-editor_' . $user_details->ID ); 326 327 $redirect = add_query_arg( 'user_id', $user_details->ID, $redirect ); 328 329 $projects = $this->get_translate_top_level_projects(); 330 $projects = wp_list_pluck( $projects, 'id' ); 331 $projects = array_map( 'intval', $projects ); 332 333 $allowed_projects = (array) $_REQUEST['projects']; 334 $allow_all_projects = in_array( 'all', $allowed_projects ); 335 336 if ( $allow_all_projects ) { 337 $allowed_projects = array( 'all' ); 338 } else { 339 $allowed_projects = array_map( 'intval', $allowed_projects ); 340 $allowed_projects = array_values( array_intersect( $projects, $allowed_projects ) ); 341 } 342 343 $meta_key = $wpdb->get_blog_prefix() . 'allowed_translate_projects'; 344 update_user_meta( $user_details->ID, $meta_key, $allowed_projects ); 345 346 wp_redirect( add_query_arg( array( 'update' => 'user-updated' ), $redirect ) ); 347 exit; 348 } 349 } 350 351 /** 352 * Renders the overview page. 353 */ 354 private function render_translation_editors() { 355 $list_table = $this->get_translation_editors_list_table(); 356 $list_table->prepare_items(); 357 358 $feedback_message = $this->get_feedback_message(); 359 360 require __DIR__ . '/views/translation-editors.php'; 361 } 362 363 /** 364 * Renders the edit page. 365 */ 366 private function render_edit_translation_editor( $user_id ) { 367 global $wpdb; 368 369 $projects = $this->get_translate_top_level_projects(); 370 371 $meta_key = $wpdb->get_blog_prefix() . 'allowed_translate_projects'; 372 $allowed_projects = get_user_meta( $user_id, $meta_key, true ); 373 if ( ! $allowed_projects ) { 374 $allowed_projects = array(); 375 } 376 377 $feedback_message = $this->get_feedback_message(); 378 379 require __DIR__ . '/views/edit-translation-editor.php'; 380 } 381 382 /** 383 * Returns a feedback message based on the current request. 384 * 385 * @return string HTML formatted message. 386 */ 387 private function get_feedback_message() { 388 $message = ''; 389 if ( ! empty( $_REQUEST['update'] ) && ! empty( $_REQUEST['error'] ) ) { 390 return $message; 391 } 392 393 $count = empty( $_REQUEST['count'] ) ? 1 : (int) $_REQUEST['count']; 394 395 $messages = array( 396 'update' => array( 397 'user-updated' => __( 'Translation Editor updated.', 'rosetta' ), 398 'user-added' => __( 'New Translation Editor added.', 'rosetta' ), 399 'user-removed' => sprintf( _n( '%s Translation Editor removed.', '%s Translation Editors removed.', $count, 'rosetta' ), number_format_i18n( $count ) ), 400 ), 401 402 'error' => array( 403 'no-user-found' => __( 'The user couldn’t be found.', 'rosetta' ), 404 'not-a-member' => __( 'The user is not a member of this site.', 'rosetta' ), 405 'user-cannot' => __( 'The user is not a Translation Editor.', 'rosetta' ), 406 'user-exists' => __( 'The user is already a Translation Editor.', 'rosetta' ), 407 ), 408 ); 409 410 if ( isset( $_REQUEST['error'], $messages['error'][ $_REQUEST['error'] ] ) ) { 411 $message = sprintf( 412 '<div class="notice notice-error"><p>%s</p></div>', 413 $messages['error'][ $_REQUEST['error'] ] 414 ); 415 } elseif( isset( $_REQUEST['update'], $messages['update'][ $_REQUEST['update'] ] ) ) { 416 $message = sprintf( 417 '<div class="notice notice-success"><p>%s</p></div>', 418 $messages['update'][ $_REQUEST['update'] ] 419 ); 420 } 421 422 return $message; 423 } 424 425 /** 426 * Wrapper for the custom list table which lists translation editors. 427 * 428 * @return Rosetta_Translation_Editors_List_Table The list table. 429 */ 430 private function get_translation_editors_list_table() { 431 static $list_table; 432 433 require_once __DIR__ . '/class-translation-editors-list-table.php'; 434 435 if ( null !== $list_table ) { 436 return $list_table; 437 } 438 439 $args = array( 440 'role' => $this->translation_editor_role, 441 ); 442 $list_table = new Rosetta_Translation_Editors_List_Table( $args ); 443 444 return $list_table; 445 } 446 447 /** 448 * Fetches all top level projects from translate.wordpress.org. 449 * 450 * @return array List of projects. 451 */ 452 private function get_translate_top_level_projects() { 453 global $wpdb; 454 455 $cache = get_site_transient( 'translate-top-level-projects' ); 456 if ( false !== $cache ) { 457 return $cache; 458 } 459 460 $projects = $wpdb->get_results( " 461 SELECT id, name 462 FROM translate_projects 463 WHERE parent_project_id IS NULL 464 ORDER BY name ASC 465 " ); 466 467 set_site_transient( 'translate-top-level-projects', $projects, DAY_IN_SECONDS ); 468 469 return $projects; 470 } 44 471 } 472 473 $GLOBALS['rosetta_roles'] = new Rosetta_Roles(); -
trunk/global.wordpress.org/public_html/wp-content/mu-plugins/roles/views/edit-translation-editor.php
1 <div class="wrap"> 2 <h2><?php _e( 'Edit Translation Editor', 'rosetta' ); ?></h2> 3 4 <?php echo $feedback_message; ?> 5 6 <form method="post"> 7 <table class="form-table"> 8 <tbody> 9 <tr> 10 <th scope="row"> 11 <?php _e( 'Allowed Projects', 'rosetta' ); ?><br> 12 <small style="font-weight:normal"><a href="#clear-all" id="clear-all"><?php _ex( 'Clear All', 'projects', 'rosetta' ); ?></a></small> 13 </th> 14 <td> 15 <fieldset> 16 <legend class="screen-reader-text"><span><?php _e( 'Allowed Projects', 'rosetta' ); ?></span></legend> 17 <p> 18 <label for="project-all"> 19 <input name="projects[]" id="project-all" value="all" type="checkbox"<?php checked( in_array( 'all', $allowed_projects ) ); ?>> <?php _ex( 'All', 'projects', 'rosetta' ); ?> 20 </label> 21 </p> 22 <?php 23 foreach ( $projects as $project ) { 24 printf( 25 '<p><label for="project-%d"><input name="projects[]" id="project-%d" class="project" value="%d" type="checkbox"%s> %s</label></p>', 26 $project->id, 27 $project->id, 28 $project->id, 29 checked( in_array( $project->id, $allowed_projects ), true, false ), 30 $project->name 31 ); 32 } 33 ?> 34 </fieldset> 35 </td> 36 </tr> 37 </tbody> 38 </table> 39 40 <input type="hidden" name="action" value="update-translation-editor"> 41 <input type="hidden" name="user_id" value="<?php echo esc_attr( $user_id ); ?>"> 42 <?php 43 wp_nonce_field( 'update-translation-editor_' . $user_id ); 44 submit_button( _x( 'Update', 'user', 'rosetta' ) ); 45 ?> 46 </form> 47 </div> -
trunk/global.wordpress.org/public_html/wp-content/mu-plugins/roles/views/translation-editors.php
1 <div class="wrap"> 2 <h2> 3 <?php 4 _e( 'Translation Editors', 'rosetta' ); 5 6 if ( ! empty( $_REQUEST['s'] ) ) { 7 echo '<span class="subtitle">' . sprintf( __( 'Search results for “%s”', 'rosetta' ), wp_html_excerpt( esc_html( wp_unslash( $_REQUEST['s'] ) ), 50, '…' ) ) . '</span>'; 8 } 9 ?> 10 </h2> 11 12 <?php echo $feedback_message; ?> 13 14 <form method="get"> 15 <input type="hidden" name="page" value="translation-editors"> 16 <?php $list_table->search_box( __( 'Search Translation Editors', 'rosetta' ), 'rosetta' ); ?> 17 </form> 18 19 <form method="post"> 20 <?php $list_table->display(); ?> 21 </form> 22 23 <?php if ( current_user_can( 'promote_users' ) ) : ?> 24 <h3><?php _e( 'Add Translation Editor', 'rosetta' ); ?></h3> 25 <p><?php _e( 'Enter the email address or username of an existing user on this site.' ); ?></p> 26 <form action="" method="post"> 27 <input type="hidden" name="action" value="add-translation-editor"> 28 <table class="form-table"> 29 <tr> 30 <th scope="row"><label for="user"><?php _e( 'E-mail or Username', 'rosetta' ); ?></label></th> 31 <td><input type="text" class="regular-text" name="user" id="user"></td> 32 </tr> 33 </table> 34 <?php wp_nonce_field( 'add-translation-editor', '_nonce_add-translation-editor' ) ?> 35 <?php submit_button( __( 'Add Translation Editor', 'rosetta' ) ); ?> 36 </form> 37 <?php endif; ?> 38 </div>