Changeset 2110 for sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-rosetta-roles/wporg-gp-rosetta-roles.php
- Timestamp:
- 11/22/2015 09:20:57 PM (9 years ago)
- Location:
- sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-rosetta-roles
- Files:
-
- 2 copied
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-rosetta-roles/wporg-gp-rosetta-roles.php
r2102 r2110 1 1 <?php 2 2 /** 3 * Tie roles on Rosetta sites directly into translate.wordpress.org. 4 * 5 * @author Nacin, ocean90 3 * Plugin name: GlotPress: Tie roles on Rosetta sites directly into translate.wordpress.org. 4 * Plugin author: nacin, ocean90 6 5 */ 7 class GP_WPorg_Rosetta_Roles extends GP_Plugin { 6 7 class WPorg_GP_Rosetta_Roles { 8 8 9 9 /** … … 39 39 */ 40 40 public function __construct() { 41 parent::__construct(); 42 $this->add_filter( 'pre_can_user', array( 'args' => 2, 'priority' => 9 ) ); 43 $this->add_action( 'project_created' ); 44 $this->add_action( 'project_saved' ); 41 add_filter( 'gp_pre_can_user', array( $this, 'pre_can_user' ), 9 , 2 ); 42 add_action( 'gp_project_created', array( $this, 'project_created' ) ); 43 add_action( 'gp_project_saved', array( $this, 'project_saved' ) ); 45 44 } 46 45 … … 127 126 */ 128 127 public function is_global_administrator( $user_id ) { 129 if ( ! class_exists( 'BP_Roles' ) ) { 130 require_once( BACKPRESS_PATH . 'class.bp-roles.php' ); 131 } 132 if ( ! class_exists( 'BP_User' ) ) { 133 require_once( BACKPRESS_PATH . 'class.bp-user.php' ); 134 } 135 136 $user = new BP_User( $user_id ); 128 $user = get_user_by( 'id', $user_id ); 137 129 138 130 // 115 = global.wordpress.org. Administrators on this site are considered global admins in GlotPress. … … 152 144 */ 153 145 public function is_approver_for_locale( $user_id, $locale_slug ) { 154 if ( ! class_exists( 'BP_Roles' ) ) {155 require_once( BACKPRESS_PATH . 'class.bp-roles.php' );156 }157 if ( ! class_exists( 'BP_User' ) ) {158 require_once( BACKPRESS_PATH . 'class.bp-user.php' );159 }160 161 146 // Get blog prefix of the associated Rosetta site. 162 147 if ( ! $blog_prefix = $this->get_blog_prefix( $locale_slug ) ) { … … 164 149 } 165 150 166 $user = new BP_User($user_id );151 $user = get_user_by( 'id', $user_id ); 167 152 168 153 // Check if current user has the approver role. … … 175 160 176 161 return $user->has_cap( $this->approver_role ); 177 178 162 } 179 163 … … 191 175 */ 192 176 public function get_project_id_access_list( $user_id, $locale_slug, $include_children = false ) { 193 if ( ! class_exists( 'BP_Roles' ) ) { 194 require_once( BACKPRESS_PATH . 'class.bp-roles.php' ); 195 } 196 if ( ! class_exists( 'BP_User' ) ) { 197 require_once( BACKPRESS_PATH . 'class.bp-user.php' ); 198 } 199 200 $user = new BP_User( $user_id ); 177 $user = get_user_by( 'id', $user_id ); 201 178 202 179 // Get blog prefix of the associated Rosetta site. … … 242 219 */ 243 220 public function get_all_projects() { 244 global $ gpdb;221 global $wpdb; 245 222 static $projects = null; 246 223 … … 249 226 } 250 227 251 $_projects = $ gpdb->get_results( "228 $_projects = $wpdb->get_results( " 252 229 SELECT 253 230 id, parent_project_id 254 FROM {$ gpdb->projects}231 FROM {$wpdb->gp_projects} 255 232 ORDER BY id 256 233 " ); … … 383 360 */ 384 361 public function get_blog_prefix( $locale_slug ) { 385 global $ gpdb;362 global $wpdb; 386 363 static $ros_blogs, $ros_locale_assoc; 387 364 … … 394 371 395 372 if ( ! isset( $ros_blogs ) ) { 396 $ros_locale_assoc = $ gpdb->get_results( 'SELECT locale, subdomain FROM locales', OBJECT_K );373 $ros_locale_assoc = $wpdb->get_results( 'SELECT locale, subdomain FROM locales', OBJECT_K ); 397 374 // 6 = Rosetta sites 398 $ros_blogs = $ gpdb->get_results( 'SELECT domain, blog_id FROM wporg_blogs WHERE site_id = 6', OBJECT_K );375 $ros_blogs = $wpdb->get_results( "SELECT domain, blog_id FROM $wpdb->blogs WHERE site_id = 6", OBJECT_K ); 399 376 } 400 377 … … 434 411 } 435 412 436 GP::$plugins->wporg_rosetta_roles = new GP_WPorg_Rosetta_Roles; 413 function wporg_gp_rosetta_roles() { 414 global $wporg_gp_rosetta_roles; 415 416 if ( ! isset( $wporg_gp_rosetta_roles ) ) { 417 $wporg_gp_rosetta_roles = new WPorg_GP_Rosetta_Roles(); 418 } 419 420 return $wporg_gp_rosetta_roles; 421 } 422 add_action( 'plugins_loaded', 'wporg_gp_rosetta_roles' );
Note: See TracChangeset
for help on using the changeset viewer.