Changeset 10575
- Timestamp:
- 01/13/2021 08:24:28 AM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-customizations/inc/class-plugin.php
r10377 r10575 3 3 namespace WordPressdotorg\GlotPress\Customizations; 4 4 5 use GP; 6 use GP_Locales; 5 7 use GP_Translation; 6 8 use WP_CLI; … … 49 51 add_filter( 'wporg_translate_language_pack_theme_args', array( $this, 'set_version_for_default_themes_in_development' ), 10, 2 ); 50 52 53 add_filter( 'gp_translation_prepare_for_save', array( $this, 'auto_reject_already_rejected' ), 100, 2 ); 54 51 55 // Cron. 52 56 add_filter( 'cron_schedules', [ $this, 'register_cron_schedules' ] ); … … 185 189 $args[ "translation_$i" ] = capital_P_dangit( $args[ "translation_$i" ] ); 186 190 } 191 } 192 193 return $args; 194 } 195 196 /** 197 * Rejects translation submissions where the suggested string has already been rejected for the user. 198 * 199 * @param array $args Translation arguments. 200 * @param GP_Translation $translation Translation instance. 201 * @return array Translation arguments. 202 */ 203 public function auto_reject_already_rejected( $args, GP_Translation $translation ) { 204 if ( 205 ! $translation->id && 206 'waiting' === $args['status'] && 207 GP::$current_route->class_name === 'GP_Route_Translation' && 208 GP::$current_route->last_method_called === 'translations_post' 209 ) { 210 // New translation being added. 211 212 $translation_set = GP::$translation_set->get( $args['translation_set_id'] ); 213 $project = GP::$project->get( $translation_set->project_id ); 214 215 // If the current user can approve / write to the project, skip. 216 if ( 217 GP::$permission->current_user_can( 'approve', 'translation-set', $translation_set->id ) 218 || 219 GP::$permission->current_user_can( 'write', 'project', $project->id ) 220 ) { 221 return $args; 222 } 223 224 $existing_rejected_translations = GP::$translation->for_translation( 225 $project, 226 $translation_set, 227 'no-limit', 228 array( 229 'user_login' => get_user_by( 'ID', $args['user_id'] )->user_login, 230 'original_id' => $args['original_id'], 231 'status' => 'rejected', 232 ), 233 array() 234 ); 235 236 if ( $existing_rejected_translations ) { 237 $locale = GP_Locales::by_slug( $translation_set->locale ); 238 239 $translations = []; 240 foreach ( range( 0, GP::$translation->get_static( 'number_of_plural_translations' ) - 1 ) as $i ) { 241 if ( isset( $args[ "translation_$i" ] ) ) { 242 $translations[] = $args[ "translation_$i" ]; 243 } 244 } 245 246 foreach ( $existing_rejected_translations as $e ) { 247 if ( array_pad( $translations, $locale->nplurals, null ) == $e->translations ) { 248 GP::$current_route->die_with_error( __( 'Identical rejected translation already exists.', 'wporg' ), 200 ); 249 } 250 } 251 } 252 187 253 } 188 254
Note: See TracChangeset
for help on using the changeset viewer.