-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrewrite-bases-internationalization.php
54 lines (44 loc) · 2.01 KB
/
rewrite-bases-internationalization.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
<?php
/**
* Plugin Name: Rewrite Bases Internationalization
* Plugin URI: https://github.com/timohubois/rewrite-bases-internationalization/
* Description: Internationalization of rewrite bases for author, search, comments and page slugs.
* Version: 1.0
* Requires at least: 6.0
* Requires PHP: 8.0
* Author: Timo Hubois
* Author URI: https://pixelsaft.wtf
* Text Domain: rewrite-bases-internationalization
* Domain Path: /languages
* License: GPLv3 or later
* License URI: https://www.gnu.org/licenses/gpl-3.0.html
*/
namespace RewriteBasesI18n;
defined('ABSPATH') || exit;
if (!defined('REWRITE_BASES_INTERNATIONALIZATION_PLUGIN_FILE')) {
define('REWRITE_BASES_INTERNATIONALIZATION_PLUGIN_FILE', __FILE__);
}
// Autoloader via Composer if available.
if (file_exists(plugin_dir_path(REWRITE_BASES_INTERNATIONALIZATION_PLUGIN_FILE) . 'vendor/autoload.php')) {
require plugin_dir_path(REWRITE_BASES_INTERNATIONALIZATION_PLUGIN_FILE) . 'vendor/autoload.php';
}
// Custom autoloader if Composer is not available.
if (!file_exists(plugin_dir_path(REWRITE_BASES_INTERNATIONALIZATION_PLUGIN_FILE) . 'vendor/autoload.php')) {
spl_autoload_register(static function ($className): void {
$prefix = 'RewriteBasesI18n\\';
$baseDir = plugin_dir_path(REWRITE_BASES_INTERNATIONALIZATION_PLUGIN_FILE) . 'classes/';
$length = strlen($prefix);
if (strncmp($prefix, $className, $length) !== 0) {
return;
}
$relativeClass = substr($className, $length);
$file = $baseDir . str_replace('\\', '/', $relativeClass) . '.php';
if (file_exists($file)) {
require $file;
}
});
}
load_plugin_textdomain(REWRITE_BASES_INTERNATIONALIZATION_PLUGIN_FILE);
register_activation_hook(REWRITE_BASES_INTERNATIONALIZATION_PLUGIN_FILE, [Plugin::class, 'activate']);
register_deactivation_hook(REWRITE_BASES_INTERNATIONALIZATION_PLUGIN_FILE, [Plugin::class, 'deactivate']);
Plugin::init();