WordPress.org

Making WordPress.org

Changeset 2123


Ignore:
Timestamp:
11/23/2015 10:45:21 PM (4 years ago)
Author:
ocean90
Message:

Translate: Convert the GP plugin "client-side JS translation validation" to a WP plugin.

See #1352.

Location:
sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-js-warnings
Files:
3 copied

Legend:

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

    r2115 r2123  
    11<?php
     2/**
     3 * Plugin name: GlotPress: Client-side JS translation validation
     4 * Plugin author: dd32
     5 */
     6
    27/**
    38 * Adds client-side JS translation validation warning warnings.
     
    1217 * @author dd32
    1318 */
    14 class WPORG_JS_Translation_Warnings {
     19class WPorg_GP_JS_Translation_Warnings {
     20
    1521    function __construct() {
    1622        add_action( 'wp_print_scripts', array( $this, 'replace_editor_with_our_own' ), 100 );
    1723    }
    1824
    19     // Replace the GlotPress editor script with our own (which depends on the editor-core GlotPress variant) this allows us to be output whenever `editor` is.
    20     function replace_editor_with_our_own( $scripts ) {
    21         global $wp_scripts;
    22 
    23         $query = $wp_scripts->query( 'editor', 'registered' );
     25    /**
     26     * Replace the GlotPress editor script with our own which depends on the wporg-gp-editor GlotPress variant.
     27     *
     28     * This allows us to be output whenever `gp-editor` is.
     29     */
     30    function replace_editor_with_our_own() {
     31        $query = wp_scripts()->query( 'gp-editor', 'registered' );
    2432        if ( ! $query ) {
    2533            return;
    2634        }
    2735
    28         wp_register_script( 'editor-core', $query->src, $query->deps, $query->ver );
     36        wp_register_script( 'wporg-gp-editor', $query->src, $query->deps, $query->ver );
    2937        if ( isset( $query->extra['l10n'] ) ) {
    30             wp_localize_script( 'editor-core', $query->extra['l10n'][0], $query->extra['l10n'][1] );
     38            wp_localize_script( 'wporg-gp-editor', $query->extra['l10n'][0], $query->extra['l10n'][1] );
    3139        }
    3240
    33         wp_deregister_script( 'editor' );
    34         wp_register_script( 'editor', gp_url_public_root() . 'gp-plugins/wporg-js-warnings/wporg-js-warnings.js', array( 'editor-core', 'jquery' ), '2015-11-14' );
    35 
     41        wp_deregister_script( 'gp-editor' );
     42        wp_register_script( 'gp-editor', plugins_url( '/wporg-gp-js-warnings.js', __FILE__ ), array( 'wporg-gp-editor', 'jquery' ), '2015-11-14' );
    3643    }
    3744
    3845}
    39 new WPORG_JS_Translation_Warnings();
    4046
     47function wporg_gp_js_translation_warnings() {
     48    global $wporg_gp_js_translation_warnings;
     49
     50    if ( ! isset( $wporg_gp_js_translation_warnings ) ) {
     51        $wporg_gp_js_translation_warnings = new WPorg_GP_JS_Translation_Warnings();
     52    }
     53
     54    return $wporg_gp_js_translation_warnings;
     55}
     56add_action( 'plugins_loaded', 'wporg_gp_js_translation_warnings' );
Note: See TracChangeset for help on using the changeset viewer.