Skip to content

Commit 3afd781

Browse files
committed
PHP-DI added
1 parent 1e5c335 commit 3afd781

5 files changed

Lines changed: 36 additions & 15 deletions

File tree

MultisiteLanguageSwitcher.php

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,6 @@
3535
exit;
3636
}
3737

38-
if ( file_exists( __DIR__ . '/vendor/autoload.php' ) ) {
39-
require __DIR__ . '/vendor/autoload.php';
40-
}
41-
4238
/**
4339
* MultisiteLanguageSwitcher
4440
*
@@ -49,10 +45,23 @@
4945
define( 'MSLS_PLUGIN_PATH', plugin_basename( __FILE__ ) );
5046
define( 'MSLS_PLUGIN__FILE__', __FILE__ );
5147

52-
require_once __DIR__ . '/includes/aliases.php';
53-
require_once __DIR__ . '/includes/deprectated.php';
54-
require_once __DIR__ . '/includes/api.php';
48+
if ( file_exists( __DIR__ . '/vendor/autoload.php' ) ) {
49+
require __DIR__ . '/vendor/autoload.php';
50+
}
51+
52+
add_action(
53+
'plugins_loaded',
54+
function () {
55+
require_once __DIR__ . '/includes/aliases.php';
56+
require_once __DIR__ . '/includes/deprectated.php';
57+
require_once __DIR__ . '/includes/api.php';
58+
59+
$builder = new DI\ContainerBuilder();
60+
$builder->addDefinitions( require __DIR__ . '/config.php' );
61+
$builder->build();
5562

56-
lloc\Msls\Plugin::init();
57-
lloc\Msls\Cli\Cli::init();
63+
lloc\Msls\Plugin::init();
64+
lloc\Msls\Cli\Cli::init();
65+
}
66+
);
5867
}

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"require": {
88
"php": ">=7.4",
99
"composer/installers": "~2.3.0",
10+
"php-di/php-di": "^7.0",
1011
"ext-json": "*"
1112
},
1213
"require-dev": {

config.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<?php declare( strict_types=1 );
2+
3+
return array();

includes/Plugin.php

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,11 @@ class Plugin {
3636

3737
/**
3838
* Injected Options object
39-
*
40-
* @var Options
4139
*/
42-
protected $options;
40+
protected Options $options;
4341

4442
/**
4543
* MslsPlugin constructor.
46-
*
47-
* @param Options $options
4844
*/
4945
public function __construct( Options $options ) {
5046
$this->options = $options;
@@ -56,6 +52,8 @@ public function __construct( Options $options ) {
5652
public static function init(): void {
5753
$obj = new self( msls_options() );
5854

55+
add_action( 'init', array( $obj, 'init_i18n_support' ) );
56+
5957
register_activation_hook( self::file(), array( __CLASS__, 'activate' ) );
6058

6159
if ( function_exists( 'is_multisite' ) && is_multisite() ) {
@@ -196,6 +194,16 @@ public static function path(): string {
196194
return defined( 'MSLS_PLUGIN_PATH' ) ? constant( 'MSLS_PLUGIN_PATH' ) : '';
197195
}
198196

197+
/**
198+
* Loads the translation files for the plugin from the bundled /languages/ directory.
199+
*
200+
* Required because the plugin ships its own .mo files; WordPress only auto-loads
201+
* translations served from wordpress.org's language packs.
202+
*/
203+
public function init_i18n_support(): void {
204+
load_plugin_textdomain( 'multisite-language-switcher', false, self::dirname( '/languages/' ) );
205+
}
206+
199207
/**
200208
* Message handler
201209
*

readme.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Contributors: realloc, lucatume
44
Donate link: https://www.greenpeace.org/international/
55
Tags: multilingual, multisite, language, switcher, localization
66
Requires at least: 6.1
7-
Tested up to: 6.9
7+
Tested up to: 7.0
88
Requires PHP: 7.4
99
Stable tag: 2.10.1
1010
License: GPLv2 or later

0 commit comments

Comments
 (0)