Changeset 4510 for sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-rosetta-roles/inc/class-plugin.php
- Timestamp:
- 12/11/2016 08:34:14 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-rosetta-roles/inc/class-plugin.php
r4395 r4510 100 100 101 101 // No permissions for unknown object types. 102 if ( ! in_array( $args['object_type'], array( 'project|locale|set-slug', 'translation-set' ) ) ) { 103 return false; 102 if ( ! in_array( $args['object_type'], array( 'project|locale|set-slug', 'translation-set', 'translation' ), true ) ) { 103 return false; 104 } 105 106 // Allow logged in users to submit translations. 107 if ( 'edit' == $args['action'] && 'translation-set' === $args['object_type'] ) { 108 return is_user_logged_in(); 104 109 } 105 110 106 111 // Get locale and current project ID. 107 $locale_and_project_id = (object) $this->get_locale_and_project_id( $args['object_type'], $args['object_id'] );112 $locale_and_project_id = (object) $this->get_locale_and_project_id( $args['object_type'], $args['object_id'], $args ); 108 113 if ( ! $locale_and_project_id ) { 109 114 return false; … … 482 487 * @param string $object_type Current object type. 483 488 * @param string $object_id Current object ID. 489 * @param array $args Optional. Array of additional arguments. 484 490 * @return array|false Locale and project ID, false on failure. 485 491 */ 486 public function get_locale_and_project_id( $object_type, $object_id ) { 492 public function get_locale_and_project_id( $object_type, $object_id, $args = array() ) { 493 static $set_cache = array(); 494 487 495 switch ( $object_type ) { 496 case 'translation' : 497 if ( empty( $args['extra']['translation']->translation_set_id ) ) { 498 break; 499 } 500 501 $translation_set_id = $args['extra']['translation']->translation_set_id; 502 if ( isset( $set_cache[ $translation_set_id ] ) ) { 503 $set = $set_cache[ $translation_set_id ]; 504 } else { 505 $set = GP::$translation_set->get( $args['extra']['translation']->translation_set_id ); 506 $set_cache[ $translation_set_id ] = $set; 507 } 508 509 return array( 'locale' => $set->locale, 'project_id' => (int) $set->project_id ); 510 488 511 case 'translation-set' : 489 $set = GP::$translation_set->get( $object_id ); 512 if ( isset( $set_cache[ $object_id ] ) ) { 513 $set = $set_cache[ $object_id ]; 514 } else { 515 $set = GP::$translation_set->get( $object_id ); 516 $set_cache[ $object_id ] = $set; 517 } 518 490 519 return array( 'locale' => $set->locale, 'project_id' => (int) $set->project_id ); 491 520 … … 494 523 return array( 'locale' => $locale, 'project_id' => (int) $project_id ); 495 524 } 525 496 526 return false; 497 527 }
Note: See TracChangeset
for help on using the changeset viewer.