Making WordPress.org

Changeset 3056


Ignore:
Timestamp:
05/02/2016 09:14:37 AM (10 years ago)
Author:
ocean90
Message:

Translate: Refactor the Theme Directory Bridge plugin to use an autoloader.

Location:
sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-theme-directory
Files:
4 added
1 deleted
1 edited
2 copied
1 moved

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-theme-directory/inc/class-plugin.php

    r3051 r3056  
    11<?php
    2 /**
    3  * Plugin name: GlotPress: Theme Directory Bridge
    4  * Description: Provides CLI commands to import themes into translate.wordpress.org or to mark themes as inactive.
    5  * Version:     1.0
    6  * Author:      WordPress.org
    7  * Author URI:  http://wordpress.org/
    8  * License:     GPLv2 or later
    9  */
    102
    11 class WPorg_GP_Theme_Directory {
    12     public $master_project   = 'wp-themes';
     3namespace WordPressdotorg\GlotPress\Theme_Directory;
    134
    14     public function __construct() {
     5use WP_CLI;
    156
     7class Plugin {
     8
     9    /**
     10     * @var Plugin The singleton instance.
     11     */
     12    private static $instance;
     13
     14    /**
     15     *
     16     * @var Sync\Translation_Sync
     17     */
     18    public $translation_sync = null;
     19
     20    /**
     21     * Returns always the same instance of this plugin.
     22     *
     23     * @return Plugin
     24     */
     25    public static function get_instance() {
     26        if ( ! ( self::$instance instanceof Plugin ) ) {
     27            self::$instance = new Plugin();
     28        }
     29        return self::$instance;
     30    }
     31
     32    /**
     33     * Instantiates a new Plugin object.
     34     */
     35    private function __construct() {
     36        add_action( 'plugins_loaded', array( $this, 'plugins_loaded' ) );
     37    }
     38
     39    /**
     40     * Initializes the plugin.
     41     */
     42    public function plugins_loaded() {
    1643        if ( defined( 'WP_CLI' ) && WP_CLI ) {
    1744            $this->register_cli_commands();
     
    2350     */
    2451    function register_cli_commands() {
    25         require_once __DIR__ . '/cli/set-theme-project.php';
    26 
    27         WP_CLI::add_command( 'wporg-translate set-theme-project', 'WPorg_GP_CLI_Set_Theme_Project' );
     52        WP_CLI::add_command( 'wporg-translate set-theme-project', __NAMESPACE__ . '\CLI\Set_Theme_Project' );
    2853    }
    2954}
    30 
    31 function wporg_gp_theme_directory() {
    32     global $wporg_gp_theme_directory;
    33 
    34     if ( ! isset( $wporg_gp_theme_directory ) ) {
    35         $wporg_gp_theme_directory = new WPorg_GP_Theme_Directory();
    36     }
    37 
    38     return $wporg_gp_theme_directory;
    39 }
    40 add_action( 'plugins_loaded', 'wporg_gp_theme_directory' );
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-theme-directory/inc/cli/class-set-theme-project.php

    r3051 r3056  
    11<?php
    22
    3 class WPorg_GP_CLI_Set_Theme_Project extends WP_CLI_Command {
     3namespace WordPressdotorg\GlotPress\Theme_Directory\CLI;
     4
     5use GP;
     6use MakePOT;
     7use WP_CLI;
     8use WP_CLI_Command;
     9
     10class Set_Theme_Project extends WP_CLI_Command {
    411
    512    /**
     
    165172     * @param string $theme_slug The theme slug to generate the project from.
    166173     * @param array  $theme_data The theme data (headers + screenshot) from get_theme_data().
     174     * @return \GP_Project|false GP project on success, false on failure.
    167175     */
    168176    private function find_create_update_glotpress_project( $theme_slug, $theme_data ) {
     
    176184            'parent_project_id'   => $parent_project->id,
    177185            'source_url_template' => "https://themes.trac.wordpress.org/browser/$theme_slug/{$theme_data['version']}/%file%#L%line%",
    178             'active'              => 1
     186            'active'              => 1,
    179187        );
    180188
     
    216224        if ( $project ) {
    217225            $project->save( array(
    218                 'active' => 0
     226                'active' => 0,
    219227            ) );
    220228        }
     
    240248            }
    241249
    242             WP_CLI::line( sprintf( "Creating translation set %s (%s)", $set->name, $set->locale . ( $set->slug != 'default' ? '/' . $set->slug : '' ) ) );
     250            WP_CLI::line( sprintf( 'Creating translation set %s (%s)', $set->name, $set->locale . ( $set->slug != 'default' ? '/' . $set->slug : '' ) ) );
    243251
    244252            GP::$translation_set->create( array(
     
    255263     *
    256264     * @param string     $pot_file The themes pot file to import.
    257      * @param GP_Project $project  The theme project to import into.
     265     * @param \GP_Project $project  The theme project to import into.
    258266     */
    259267    private function import_pot_to_glotpress( $pot_file, $project ) {
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-theme-directory/wporg-gp-theme-directory.php

    r2367 r3056  
    33 * Plugin name: GlotPress: Theme Directory Bridge
    44 * Description: Provides CLI commands to import themes into translate.wordpress.org or to mark themes as inactive.
    5  * Version:     1.0
     5 * Version:     2.0
    66 * Author:      WordPress.org
    77 * Author URI:  http://wordpress.org/
     
    99 */
    1010
    11 class WPorg_GP_Theme_Directory {
    12     public $master_project   = 'wp-themes';
     11namespace WordPressdotorg\GlotPress\Theme_Directory;
    1312
    14     public function __construct() {
     13use WordPressdotorg\Autoload;
    1514
    16         if ( defined( 'WP_CLI' ) && WP_CLI ) {
    17             $this->register_cli_commands();
    18         }
    19     }
     15// Store the root plugin file for usage with functions which use the plugin basename.
     16define( __NAMESPACE__ . '\PLUGIN_FILE', __FILE__ );
    2017
    21     /**
    22      * Registers CLI commands if WP-CLI is loaded.
    23      */
    24     function register_cli_commands() {
    25         require_once __DIR__ . '/cli/set-theme-project.php';
    26 
    27         WP_CLI::add_command( 'wporg-translate set-theme-project', 'WPorg_GP_CLI_Set_Theme_Project' );
    28     }
     18if ( ! class_exists( '\WordPressdotorg\Autoload\Autoloader', false ) ) {
     19    include __DIR__ . '/vendor/wordpressdotorg/class-autoloader.php';
    2920}
    3021
    31 function wporg_gp_theme_directory() {
    32     global $wporg_gp_theme_directory;
     22// Register an Autoloader for all files.
     23Autoload\register_class_path( __NAMESPACE__, __DIR__ . '/inc' );
    3324
    34     if ( ! isset( $wporg_gp_theme_directory ) ) {
    35         $wporg_gp_theme_directory = new WPorg_GP_Theme_Directory();
    36     }
    37 
    38     return $wporg_gp_theme_directory;
    39 }
    40 add_action( 'plugins_loaded', 'wporg_gp_theme_directory' );
     25// Instantiate the Plugin.
     26Plugin::get_instance();
Note: See TracChangeset for help on using the changeset viewer.