Changeset 4377
- Timestamp:
- 11/19/2016 01:51:52 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
r4183 r4377 143 143 144 144 // If current project is a parent ID. 145 if ( in_array( $locale_and_project_id->project_id, $project_access_list ) ) {145 if ( in_array( $locale_and_project_id->project_id, $project_access_list, true ) ) { 146 146 return true; 147 147 } 148 148 149 149 // A user is allowed to approve sub projects as well. 150 $p roject_access_list = $this->get_project_id_access_list( $args['user_id'], $locale_and_project_id->locale, /* $include_children = */ true);151 if ( in_array( $locale_and_project_id->project_id, $project_access_list) ) {150 $parent_project_ids = $this->get_parent_project_ids( $locale_and_project_id->project_id ); 151 if ( array_intersect( $project_access_list, $parent_project_ids ) ) { 152 152 return true; 153 153 } 154 154 155 155 return false; 156 } 157 158 /** 159 * Retrieves all parent project IDs of a project. 160 * 161 * @param int $project_id ID of a project. 162 * @return array List of project IDs that are parents of a project. 163 */ 164 private function get_parent_project_ids( $project_id ) { 165 $last_changed = wp_cache_get_last_changed( self::$cache_group ); 166 167 $cache_key = 'project:' . $project_id . ':parents:' . $last_changed; 168 $cache = wp_cache_get( $cache_key, self::$cache_group ); 169 if ( false !== $cache ) { 170 return $cache; 171 } 172 173 $parent_project_ids = []; 174 175 $parent_project = GP::$project->get( $project_id ); 176 $parent_project_id = $parent_project->parent_project_id; 177 while ( $parent_project_id ) { 178 $parent_project_ids[] = $parent_project_id; 179 180 $parent_project = GP::$project->get( $parent_project_id ); 181 $parent_project_id = $parent_project->parent_project_id; 182 } 183 184 wp_cache_set( $cache_key, $parent_project_ids, self::$cache_group ); 185 186 return $parent_project_ids; 156 187 } 157 188 … … 436 467 */ 437 468 public function clear_project_cache() { 469 wp_cache_set( 'last_changed', microtime(), self::$cache_group ); 470 438 471 $projects = $this->get_all_projects(); 439 472
Note: See TracChangeset
for help on using the changeset viewer.