-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathwp-steroids.php
executable file
·142 lines (102 loc) · 3.13 KB
/
wp-steroids.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
<?php
/**
* Plugin Name: WordPress on Steroids
* Description: Configure WordPress using yml and add amazing features
* Version: 1.5.3
* Author: Metabolism
*/
use Dflydev\DotAccessData\Data;
if ( ! defined( 'ABSPATH' ) )
exit; // Exit if accessed directly
class WPS{
function __construct() {
// Do nothing.
}
private function loadAll($folder, $instantiate=false){
$folder = __DIR__.'/includes/'.$folder;
$files = scandir($folder);
foreach($files as $file){
if( !in_array($file, ['.','..']) )
{
$classname = 'WPS_'.str_replace(' ', '_', ucwords(str_replace('-', ' ', str_replace('class-', '', str_replace('.php', '', $file)))));
$this->load($folder.'/'.$file, $classname, $instantiate);
}
}
}
/**
* @param $file
* @param $classname
* @param bool $instantiate
*/
private function load($file, $classname, bool $instantiate=false){
if( !file_exists($file) )
return;
include_once $file;
if( $instantiate )
new $classname();
}
/**
* @param $resource
* @return void
*/
private function importConfig($resource){
/**
* Wordpress configuration file
*/
global $_config;
$config = WPS_Yaml::load('wp_steroid', $resource);
$_config = new Data($config['wordpress']??$config);
/**
* Define constants
*/
foreach ((array)$_config->get('define', []) as $constant=>$value){
if( !defined(strtoupper($constant)) ){
if( substr($value, 0, 4) === 'env(' ){
$value = substr($value, 4, strlen($value)-6);
define( strtoupper($constant), $_ENV[$value]??false);
}
else{
define( strtoupper($constant), $value);
}
}
}
if( !defined('HEADLESS') )
define('HEADLESS', $_config->get('headless', false) );
if( !defined('URL_MAPPING') )
define('URL_MAPPING', $_config->get('headless.mapping', false) );
}
/**
* initialize
*
* Sets up the Meta Steroids
*
* @return void
*/
function initialize() {
if( !defined('WPS_YAML_FILE') )
die('WPS_YAML_FILE is not defined');
if( !defined('WPS_YAML_TRANSLATION_FILES') )
define('WPS_YAML_TRANSLATION_FILES', WP_LANG_DIR);
define('WPS_PATH', __DIR__);
define('WPS_PLUGIN_URL', plugin_dir_url(__FILE__));
define('WPS_VERSION', '1.5.3');
require __DIR__ . '/includes/vendor/autoload.php';
$this->loadAll('lib');
$this->importConfig(WPS_YAML_FILE);
$this->loadAll('extensions', true);
$this->loadAll('plugins', true);
}
}
function wps() {
global $wps;
// Instantiate only once.
if ( ! isset( $wps ) ) {
$wps = new WPS();
$wps->initialize();
}
return $wps;
}
if( ( defined('WP_INSTALLING') && WP_INSTALLING ) || !defined('WPINC') )
return;
// Instantiate.
wps();