Completed
Push — develop ( 691768...c5c7b0 )
by Aristeides
03:22
created

l10n.php ➔ kirki_override_load_textdomain()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 21
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 9
nc 3
nop 2
dl 0
loc 21
rs 9.3142
c 0
b 0
f 0
1
<?php
2
/**
3
 * Allows overriding the "kirki" textdomain from a theme.
4
 *
5
 * @package     Kirki
6
 * @category    Core
7
 * @author      Aristeides Stathopoulos
8
 * @copyright   Copyright (c) 2017, Aristeides Stathopoulos
9
 * @license     http://opensource.org/licenses/https://opensource.org/licenses/MIT
10
 * @since       3.0.0
11
 */
12
13
// if ( ! isset( ))
14
// If kirki is a plugin and not inside a theme,
15
// then there's no need to proceed any further.
16
if ( Kirki_Init::is_plugin() ) {
17
	return;
18
}
19
20
if ( ! function_exists( 'kirki_override_load_textdomain' ) ) {
21
	/**
22
	 * Allows overriding the "kirki" textdomain from a theme.
23
	 *
24
	 * @since 3.0.0
25
	 * @param bool   $override Whether to override the text domain. Default false.
26
	 * @param string $domain   Text domain. Unique identifier for retrieving translated strings.
27
	 * @return bool
28
	 */
29
	function kirki_override_load_textdomain( $override, $domain ) {
30
31
		// Check if the domain is "kirki".
32
		if ( 'kirki' === $domain ) {
33
			global $l10n;
34
35
			// Get the theme's textdomain.
36
			$theme = wp_get_theme();
37
			$theme_textdomain = $theme->get( 'TextDomain' );
38
39
			// If the theme's textdomain is loaded, assign the theme's translations
40
			// to the "kirki" textdomain.
41
			if ( isset( $l10n[ $theme_textdomain ] ) ) {
42
				$l10n[ $domain ] = $l10n[ $theme_textdomain ];
43
			}
44
45
			// Always override.  We only want the theme to handle translations.
46
			$override = true;
47
		}
48
		return $override;
49
	}
50
}
51
add_filter( 'override_load_textdomain', 'kirki_override_load_textdomain', 10, 2 );
52