WordPress.org

Making WordPress.org


Ignore:
Timestamp:
04/02/2016 03:59:41 PM (5 years ago)
Author:
ocean90
Message:

Translate, Plugin Directory: Switch to using namespaces and an autoloader.

The autoloader is copied from the Plugin Directory plugin: https://meta.trac.wordpress.org/browser/sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/class-autoloader.php

See #1636.

Location:
sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-plugin-directory/inc
Files:
2 added
1 copied

Legend:

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

    r2880 r2881  
    11<?php
    2 /**
    3  * Plugin name: GlotPress: Plugin Directory Bridge
    4  * Description: Clears the content translation cache for plugins (readme/code) hosted on wordpress.org based on actions taken withing translate.wordpress.org.
    5  * Version:     1.1
    6  * Author:      WordPress.org
    7  * Author URI:  http://wordpress.org/
    8  * License:     GPLv2 or later
    9  */
    102
    11 class WPorg_GP_Plugin_Directory {
     3namespace WordPressdotorg\GlotPress\Plugin_Directory\Cache_Purge;
     4
     5use GP;
     6
     7class Cache_Purger {
    128    public $master_project   = 'wp-plugins';
    139    public $i18n_cache_group = 'plugins-i18n';
     
    1511    private $translation_edits_queue = array();
    1612
    17     public function __construct() {
     13    /**
     14     * Registers actions and filters.
     15     */
     16    public function register_events() {
    1817        add_action( 'init', array( $this, 'add_global_cache_group' ) );
    1918        add_action( 'gp_originals_imported', array( $this, 'originals_imported' ) );
     
    2322        // Cache purging is delayed until shutdown to prevent multiple purges for the same project.
    2423        add_action( 'shutdown', array( $this, 'delete_plugin_i18n_cache_on_translation_edits' ) );
    25 
    26         if ( defined( 'WP_CLI' ) && WP_CLI ) {
    27             $this->register_cli_commands();
    28         }
    29     }
    30 
    31     /**
    32      * Registers CLI commands if WP-CLI is loaded.
    33      */
    34     function register_cli_commands() {
    35         require_once __DIR__ . '/cli/import-plugin-translations.php';
    36         require_once __DIR__ . '/cli/set-plugin-project.php';
    37         require_once __DIR__ . '/cli/delete-plugin-project.php';
    38 
    39         WP_CLI::add_command( 'wporg-translate import-plugin-translations', 'WPorg_GP_CLI_Import_Plugin_Translations' );
    40         WP_CLI::add_command( 'wporg-translate set-plugin-project', 'WPorg_GP_CLI_Set_Plugin_Project' );
    41         WP_CLI::add_command( 'wporg-translate delete-plugin-project', 'WPorg_GP_CLI_Delete_Plugin_Project' );
    4224    }
    4325
     
    6749     * or updated.
    6850     *
    69      * @param GP_Translation $translation Created/updated translation.
     51     * @param \GP_Translation $translation Created/updated translation.
    7052     */
    7153    public function queue_translation_for_cache_purge( $translation ) {
     
    7961    /**
    8062     * Deletes the cache on a translation edits.
    81      *
    82      * @param GP_Translation $translation The edited translation.
    8363     */
    8464    public function delete_plugin_i18n_cache_on_translation_edits() {
     
    139119    private function get_plugin_i18n_cache_prefix( $project_id ) {
    140120        $project = GP::$project->get( $project_id );
    141         if ( empty( $project->path ) || !$this->project_is_plugin( $project->path ) ) {
     121        if ( empty( $project->path ) || ! $this->project_is_plugin( $project->path ) ) {
    142122            return '';
    143123        }
     
    204184    }
    205185}
    206 
    207 function wporg_gp_plugin_directory() {
    208     global $wporg_gp_plugin_directory;
    209 
    210     if ( ! isset( $wporg_gp_plugin_directory ) ) {
    211         $wporg_gp_plugin_directory = new WPorg_GP_Plugin_Directory();
    212     }
    213 
    214     return $wporg_gp_plugin_directory;
    215 }
    216 add_action( 'plugins_loaded', 'wporg_gp_plugin_directory' );
Note: See TracChangeset for help on using the changeset viewer.