This repository has been archived by the owner on Oct 24, 2020. It is now read-only.
forked from roots/soil
-
Notifications
You must be signed in to change notification settings - Fork 0
/
soil.php
71 lines (59 loc) · 1.74 KB
/
soil.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: Soil
Plugin URI: https://roots.io/plugins/soil/
Description: A collection of modules to apply theme-agnostic front-end modifications to WordPress.
Version: 3.7.3
Author: Roots
Author URI: https://roots.io/
License: MIT License
License URI: http://opensource.org/licenses/MIT
*/
namespace Roots\Soil;
class Options {
protected static $modules = [];
protected $options = [];
public static function init($module, $options = []) {
if (!isset(self::$modules[$module])) {
self::$modules[$module] = new static((array) $options);
}
return self::$modules[$module];
}
public static function getByFile($file) {
if (file_exists($file) || file_exists(__DIR__ . '/modules/' . $file)) {
return self::get('soil-' . basename($file, '.php'));
}
return [];
}
public static function get($module) {
if (isset(self::$modules[$module])) {
return self::$modules[$module]->options;
}
if (substr($module, 0, 5) !== 'soil-') {
return self::get('soil-' . $module);
}
return [];
}
protected function __construct($options) {
$this->set($options);
}
public function set($options) {
$this->options = $options;
}
}
require_once __DIR__ . '/lib/utils.php';
function load_modules() {
global $_wp_theme_features;
// Skip loading modules in the admin.
if (is_admin()) {
return;
}
foreach (glob(__DIR__ . '/modules/*.php') as $file) {
$feature = 'soil-' . basename($file, '.php');
if (isset($_wp_theme_features[$feature])) {
Options::init($feature, $_wp_theme_features[$feature]);
require_once $file;
}
}
}
add_action('after_setup_theme', __NAMESPACE__ . '\\load_modules', 100);