Making WordPress.org


Ignore:
Timestamp:
11/22/2015 09:20:57 PM (9 years ago)
Author:
ocean90
Message:

Translate: Convert the GP plugin "wporg-rosetta-roles" to a WP plugin.

See #1352.

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  
    11<?php
    22/**
    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
    65 */
    7 class GP_WPorg_Rosetta_Roles extends GP_Plugin {
     6
     7class WPorg_GP_Rosetta_Roles {
    88
    99    /**
     
    3939     */
    4040    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' ) );
    4544    }
    4645
     
    127126     */
    128127    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 );
    137129
    138130        // 115 = global.wordpress.org. Administrators on this site are considered global admins in GlotPress.
     
    152144     */
    153145    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 
    161146        // Get blog prefix of the associated Rosetta site.
    162147        if ( ! $blog_prefix = $this->get_blog_prefix( $locale_slug ) ) {
     
    164149        }
    165150
    166         $user = new BP_User( $user_id );
     151        $user = get_user_by( 'id', $user_id );
    167152
    168153        // Check if current user has the approver role.
     
    175160
    176161        return $user->has_cap( $this->approver_role );
    177 
    178162    }
    179163
     
    191175     */
    192176    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 );
    201178
    202179        // Get blog prefix of the associated Rosetta site.
     
    242219     */
    243220    public function get_all_projects() {
    244         global $gpdb;
     221        global $wpdb;
    245222        static $projects = null;
    246223
     
    249226        }
    250227
    251         $_projects = $gpdb->get_results( "
     228        $_projects = $wpdb->get_results( "
    252229            SELECT
    253230                id, parent_project_id
    254             FROM {$gpdb->projects}
     231            FROM {$wpdb->gp_projects}
    255232            ORDER BY id
    256233        " );
     
    383360     */
    384361    public function get_blog_prefix( $locale_slug ) {
    385         global $gpdb;
     362        global $wpdb;
    386363        static $ros_blogs, $ros_locale_assoc;
    387364
     
    394371
    395372        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 );
    397374            // 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 );
    399376        }
    400377
     
    434411}
    435412
    436 GP::$plugins->wporg_rosetta_roles = new GP_WPorg_Rosetta_Roles;
     413function 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}
     422add_action( 'plugins_loaded', 'wporg_gp_rosetta_roles' );
Note: See TracChangeset for help on using the changeset viewer.