Changeset 4080 for sites/trunk/wordpress.org/public_html/wp-content/plugins/rosetta/inc/site/class-locale-main.php
- Timestamp:
- 09/16/2016 03:50:43 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/rosetta/inc/site/class-locale-main.php
r4032 r4080 5 5 use WordPressdotorg\Rosetta\Jetpack; 6 6 use WordPressdotorg\Rosetta\User; 7 use WordPressdotorg\Rosetta\User\Role; 7 8 use WP_Site; 9 use WP_User; 8 10 9 11 class Locale_Main implements Site { … … 49 51 } 50 52 53 $this->initialize_jetpack_customizations(); 54 $this->initialize_user_role_customizations(); 55 } 56 57 /** 58 * Initializes customizations for Jetpack. 59 */ 60 private function initialize_jetpack_customizations() { 51 61 $jetpack_module_manager = new Jetpack\Module_Manager( [ 52 62 'stats', … … 58 68 $jetpack_module_manager->setup(); 59 69 70 // Options for Jetpack's sharing module. 60 71 $options = new Filter\Options(); 61 // Options for Jetpack's sharing module.62 72 $options->add_option( 63 73 ( new Filter\Option() ) … … 87 97 $options->setup(); 88 98 } 99 100 /** 101 * Initializes user role customizations. 102 */ 103 private function initialize_user_role_customizations() { 104 $role_manager = new User\Role_Manager(); 105 $role_manager->add_role( new Role\Locale_Manager() ); 106 $role_manager->add_role( new Role\General_Translation_Editor() ); 107 $role_manager->add_role( new Role\Translation_Editor() ); 108 $role_manager->setup(); 109 110 add_action( 'set_user_role', [ $this, 'restore_translation_editor_role' ], 10, 3 ); 111 add_filter( 'editable_roles', [ $this, 'remove_administrator_from_editable_roles' ] ); 112 } 113 114 /** 115 * Restores the "(General) Translation Editor" role if an user is promoted. 116 * 117 * @param int $user_id The user ID. 118 * @param string $role The new role. 119 * @param array $old_roles An array of the user's previous roles. 120 */ 121 public function restore_translation_editor_role( $user_id, $role, $old_roles ) { 122 if ( 123 Role\General_Translation_Editor::get_name() !== $role && 124 in_array( Role\Translation_Editor::get_name(), $old_roles, true ) 125 ) { 126 $user = new WP_User( $user_id ); 127 $user->add_role( Role\Translation_Editor::get_name() ); 128 } 129 130 if ( 131 Role\Translation_Editor::get_name() !== $role && 132 in_array( Role\General_Translation_Editor::get_name(), $old_roles, true ) 133 ) { 134 $user = new WP_User( $user_id ); 135 $user->add_role( Role\General_Translation_Editor::get_name() ); 136 } 137 } 138 139 /** 140 * Removes "Administrator" role from the list of editable roles. 141 * 142 * @param array $roles List of roles. 143 * @return array Filtered list of editable roles. 144 */ 145 public function remove_administrator_from_editable_roles( $roles ) { 146 if ( ! is_super_admin() && ! is_main_site() ) { 147 unset( $roles['administrator'] ); 148 } 149 150 return $roles; 151 } 89 152 }
Note: See TracChangeset
for help on using the changeset viewer.