Changeset 2880 for sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-plugin-directory/wporg-gp-plugin-directory.php
- Timestamp:
- 04/02/2016 10:24:29 AM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-plugin-directory/wporg-gp-plugin-directory.php
r2690 r2880 3 3 * Plugin name: GlotPress: Plugin Directory Bridge 4 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. 05 * Version: 1.1 6 6 * Author: WordPress.org 7 7 * Author URI: http://wordpress.org/ … … 13 13 public $i18n_cache_group = 'plugins-i18n'; 14 14 15 private $translation_edits_queue = array(); 16 15 17 public function __construct() { 16 18 add_action( 'init', array( $this, 'add_global_cache_group' ) ); 17 19 add_action( 'gp_originals_imported', array( $this, 'originals_imported' ) ); 18 add_action( 'gp_translation_created', array( $this, 'translation_created' ) ); 19 add_action( 'gp_translation_saved', array( $this, 'translation_saved' ) ); 20 add_action( 'gp_translation_created', array( $this, 'queue_translation_for_cache_purge' ) ); 21 add_action( 'gp_translation_saved', array( $this, 'queue_translation_for_cache_purge' ) ); 22 23 // Cache purging is delayed until shutdown to prevent multiple purges for the same project. 24 add_action( 'shutdown', array( $this, 'delete_plugin_i18n_cache_on_translation_edits' ) ); 20 25 21 26 if ( defined( 'WP_CLI' ) && WP_CLI ) { … … 59 64 60 65 /** 61 * Triggers a cache purge when a new translation was created. 62 * 63 * @param GP_Translation $translation Created translation. 64 */ 65 public function translation_created( $translation ) { 66 * Adds a translation to a cache purge queue when a translation was created 67 * or updated. 68 * 69 * @param GP_Translation $translation Created/updated translation. 70 */ 71 public function queue_translation_for_cache_purge( $translation ) { 66 72 if ( ! $this->project_is_plugin( $_SERVER['REQUEST_URI'] ) ) { 67 73 return; 68 74 } 69 75 70 $this->delete_plugin_i18n_cache_on_translation_edit( $translation ); 71 } 72 73 /** 74 * Triggers a cache purge when a translation was updated. 75 * 76 * @param GP_Translation $translation Updated translation. 77 */ 78 public function translation_saved( $translation ) { 79 if ( ! $this->project_is_plugin( $_SERVER['REQUEST_URI'] ) ) { 80 return; 81 } 82 83 $this->delete_plugin_i18n_cache_on_translation_edit( $translation ); 76 $this->translation_edits_queue[ $translation->original_id ][ $translation->translation_set_id ] = true; 77 } 78 79 /** 80 * Deletes the cache on a translation edits. 81 * 82 * @param GP_Translation $translation The edited translation. 83 */ 84 public function delete_plugin_i18n_cache_on_translation_edits() { 85 if ( empty( $this->translation_edits_queue ) ) { 86 return; 87 } 88 89 $purged = array(); 90 foreach ( $this->translation_edits_queue as $original_id => $set_ids ) { 91 $original = GP::$original->get( $original_id ); 92 if ( ! $original ) { 93 return; 94 } 95 96 foreach ( array_keys( $set_ids ) as $set_id ) { 97 if ( in_array( "{$original->project_id}-{$set_id}", $purged ) ) { 98 continue; 99 } 100 101 $translation_set = GP::$translation_set->get( $set_id ); 102 if ( ! $translation_set ) { 103 return; 104 } 105 106 $this->delete_plugin_i18n_cache_keys_for_locale( $original->project_id, $translation_set->locale ); 107 $purged[] = "{$original->project_id}-{$set_id}"; 108 } 109 } 84 110 } 85 111 … … 177 203 $this->delete_plugin_i18n_cache_keys_for( $prefix, $locale ); 178 204 } 179 180 /**181 * Deletes the cache on a translation edit.182 *183 * @param GP_Translation $translation The edited translation.184 */185 private function delete_plugin_i18n_cache_on_translation_edit( $translation ) {186 $original = GP::$original->get( $translation->original_id );187 if ( ! $original ) {188 return;189 }190 191 $translation_set = GP::$translation_set->get( $translation->translation_set_id );192 if ( ! $translation_set ) {193 return;194 }195 196 $this->delete_plugin_i18n_cache_keys_for_locale( $original->project_id, $translation_set->locale );197 }198 205 } 199 206
Note: See TracChangeset
for help on using the changeset viewer.