WordPress.org

Making WordPress.org


Ignore:
Timestamp:
11/22/2015 08:01:41 PM (5 years ago)
Author:
ocean90
Message:

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

See #1352.

Location:
sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-routes
Files:
2 copied

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-routes/wporg-gp-routes.php

    r2108 r2109  
    11<?php
    22/**
    3  * Register custom routes for translate.wordpress.org.
    4  *
    5  * @author ocean90, obenland, dd32
     3 * Plugin name: GlotPress: Register custom routes for translate.wordpress.org.
     4 * Plugin author: ocean90, obenland, dd32
    65 */
    76
     
    1211require_once __DIR__ . '/routes/wp-plugins.php';
    1312
    14 class GP_WPorg_Routes extends GP_Plugin {
    15     public $id = 'wporg-routes';
     13class WPorg_GP_Routes {
    1614
    1715    public function __construct() {
    18         parent::__construct();
    19         $this->add_action( 'init' );
     16        add_action( 'init', array( $this, 'register_routes' ) );
    2017    }
    2118
    22     public function init() {
     19    public function register_routes() {
    2320        // Bail for API requests.
    2421        $request_uri = GP::$router->request_uri();
     
    3532
    3633        // Redirect routes.
    37         GP::$router->prepend( '/languages', array( 'GP_WPorg_Route_Redirector', 'redirect_languages' ) );
    38         GP::$router->prepend( "/languages/$path", array( 'GP_WPorg_Route_Redirector', 'redirect_languages' ) );
     34        GP::$router->prepend( '/languages', array( 'WPorg_GP_Route_Redirector', 'redirect_languages' ) );
     35        GP::$router->prepend( "/languages/$path", array( 'WPorg_GP_Route_Redirector', 'redirect_languages' ) );
    3936
    4037        // Register custom routes.
    41         GP::$router->prepend( '/', array( 'GP_WPorg_Route_Index', 'get_locales' ) );
    42         GP::$router->prepend( "/locale/$locale", array( 'GP_WPorg_Route_Locale', 'get_locale_projects' ) );
    43         GP::$router->prepend( "/locale/$locale/$path", array( 'GP_WPorg_Route_Locale', 'get_locale_projects' ) );
    44         GP::$router->prepend( "/locale/$locale/$path/$path", array( 'GP_WPorg_Route_Locale', 'get_locale_projects' ) );
    45         GP::$router->prepend( "/locale/$locale/$path/$path/$path", array( 'GP_WPorg_Route_Locale', 'get_locale_project' ) );
    46         GP::$router->prepend( '/stats/?', array( 'GP_WPorg_Route_Stats', 'get_stats_overview' ) );
     38        GP::$router->prepend( '/', array( 'WPorg_GP_Route_Index', 'get_locales' ) );
     39        GP::$router->prepend( "/locale/$locale", array( 'WPorg_GP_Route_Locale', 'get_locale_projects' ) );
     40        GP::$router->prepend( "/locale/$locale/$path", array( 'WPorg_GP_Route_Locale', 'get_locale_projects' ) );
     41        GP::$router->prepend( "/locale/$locale/$path/$path", array( 'WPorg_GP_Route_Locale', 'get_locale_projects' ) );
     42        GP::$router->prepend( "/locale/$locale/$path/$path/$path", array( 'WPorg_GP_Route_Locale', 'get_locale_project' ) );
     43        GP::$router->prepend( '/stats/?', array( 'WPorg_GP_Route_Stats', 'get_stats_overview' ) );
    4744        $project = '([^/]*)/?';
    48         GP::$router->prepend( "/projects/wp-plugins/$project", array( 'GP_WPorg_Route_WP_Plugins', 'get_plugin_projects' ) );
     45        GP::$router->prepend( "/projects/wp-plugins/$project", array( 'WPorg_GP_Route_WP_Plugins', 'get_plugin_projects' ) );
    4946    }
    5047}
    5148
    52 GP::$plugins->wporg_routes = new GP_WPorg_Routes;
     49function wporg_gp_routes() {
     50    global $wporg_gp_routes;
     51
     52    if ( ! isset( $wporg_gp_routes ) ) {
     53        $wporg_gp_routes = new WPorg_GP_Routes();
     54    }
     55
     56    return $wporg_gp_routes;
     57}
     58add_action( 'plugins_loaded', 'wporg_gp_routes' );
Note: See TracChangeset for help on using the changeset viewer.