-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathdynamic-mo-loader.php
71 lines (57 loc) · 1.76 KB
/
dynamic-mo-loader.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?php
/*
Plugin Name: Dynamic MO Loader
Plugin URI: https://github.com/aucor/dynamic-mo-loader
Description: Better text domain loading with object cache support
Version: 1.4.1
Author: Aucor Oy
Author URI:
License: GPL3
*/
if(!class_exists('Dynamic_MO_Loader')) {
require_once('inc/mo_dynamic.php');
class Dynamic_MO_Loader {
function __construct() {
add_filter( 'override_load_textdomain', array( $this, 'dynamicmo_load_textdomain_override' ), 0, 3 );
}
function dynamicmo_load_textdomain_override( $retval, $domain, $mofile ) {
global $l10n;
$result = false;
$mo = NULL;
if ( $mo === NULL ) {
do_action( 'load_textdomain', $domain, $mofile );
$mofile = apply_filters( 'load_textdomain_mofile', $mofile, $domain );
if ( isset( $l10n[$domain] ) ) {
if ( $l10n[$domain] instanceof WPPP_MO_dynamic && $l10n[$domain]->Mo_file_loaded( $mofile ) ) {
return true;
}
}
if ( !is_readable( $mofile ) ) {
return false; // return false is important so load_plugin_textdomain/load_theme_textdomain/... can call load_textdomain for different locations
}
$cache = TRUE;
$mo = new WPPP_MO_dynamic ( $domain, $cache );
if ( $mo->import_from_file( $mofile ) ) {
$result = true;
} else {
$mo->unhook_and_close();
$mo = NULL;
}
}
if ( $mo !== NULL ) {
if ( isset( $l10n[$domain] ) ) {
$mo->merge_with( $l10n[$domain] );
if ( $l10n[$domain] instanceof WPPP_MO_dynamic ) {
$l10n[$domain]->unhook_and_close();
}
}
$l10n[$domain] = $mo;
}
return $result;
}
}
}
if(class_exists('Dynamic_MO_Loader')) {
// instantiate the plugin class
$dynamic_mo_loader = new Dynamic_MO_Loader();
}