-
Notifications
You must be signed in to change notification settings - Fork 53
/
Copy pathautoload.php
96 lines (73 loc) · 2 KB
/
autoload.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<?php
/**
* Ensure this is only ran once.
*/
if (defined('HERBERT_AUTOLOAD'))
{
return;
}
define('HERBERT_AUTOLOAD', microtime(true));
@require 'helpers.php';
/**
* Load the WP plugin system.
*/
if (array_search(ABSPATH . 'wp-admin/includes/plugin.php', get_included_files()) === false)
{
require_once ABSPATH . 'wp-admin/includes/plugin.php';
}
/**
* Get Herbert.
*/
$herbert = Herbert\Framework\Application::getInstance();
/**
* Load all herbert.php files in plugin roots.
*/
$iterator = new DirectoryIterator(plugin_directory());
foreach ($iterator as $directory)
{
if ( ! $directory->valid() || $directory->isDot() || ! $directory->isDir())
{
continue;
}
$root = $directory->getPath() . '/' . $directory->getFilename();
if ( ! file_exists($root . '/herbert.config.php'))
{
continue;
}
$config = $herbert->getPluginConfig($root);
$plugin = substr($root . '/plugin.php', strlen(plugin_directory()));
$plugin = ltrim($plugin, '/');
register_activation_hook($plugin, function () use ($herbert, $config, $root)
{
if ( ! $herbert->pluginMatches($config))
{
$herbert->pluginMismatched($root);
}
$herbert->pluginMatched($root);
$herbert->loadPlugin($config);
$herbert->activatePlugin($root);
});
register_deactivation_hook($plugin, function () use ($herbert, $root)
{
$herbert->deactivatePlugin($root);
});
// Ugly hack to make the install hook work correctly
// as WP doesn't allow closures to be passed here
register_uninstall_hook($plugin, create_function('', 'herbert()->deletePlugin(\'' . $root . '\');'));
if ( ! is_plugin_active($plugin))
{
continue;
}
if ( ! $herbert->pluginMatches($config))
{
$herbert->pluginMismatched($root);
continue;
}
$herbert->pluginMatched($root);
@require_once $root.'/plugin.php';
$herbert->loadPlugin($config);
}
/**
* Boot Herbert.
*/
$herbert->boot();