-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoik-load.php
175 lines (157 loc) · 5.4 KB
/
oik-load.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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
<?php // (C) Copyright Bobbing Wide 2014
/**
* Return a full file name for the given $plugin
*
* Note: $dirname of '.' is converted to null
* Missing $extension treated as "php"
* Doesn't support "wordpress" files or "themes"
*
* $dirname $filename result
* -------- --------- ----------
* set set Use the given value
* set null Use the $dirname for the file name. e.g. oik/oik.php
* null set use the $filename for the directory.
* null null
*
* @param string $plugin in format dirname/filename.extension
* @return string full file name
*
*
*/
function bw_full_file( $plugin ) {
$dirname = pathinfo( $plugin, PATHINFO_DIRNAME );
$dirname = str_replace( ".", null, $dirname );
$filename = pathinfo( $plugin, PATHINFO_FILENAME );
$extension = pathinfo( $plugin, PATHINFO_EXTENSION );
if ( !$extension ) {
$extension = "php";
}
//echo "Dirname: $dirname:" ;
//echo "Filename: $filename:" ;
if ( $dirname ) {
if ( $filename ) {
//$plugin = "$filename/$filename.$extension";
// whatever they said
} else {
$plugin = "$dirname/$dirname.php";
}
} else {
if ( $filename ) {
$plugin = "$filename/$filename.$extension";
} else {
$plugin = "oik/oik.php"; // Error really!
}
}
$plugin = WP_PLUGIN_DIR . "/" . $plugin;
return( $plugin );
}
/**
* Write paragraph then flush
* @param string $text - text to write
*/
function pf( $text ) {
p( $text );
bw_flush();
}
/**
* Load WordPress pre-requisite files in order to load a plugin
*
* This function was created by trial and error while attempting to load "easy-digital-downloads"
* WooCommerce was an easier plugin to load.
*
* Counted things oik-batch oik-load | woocommerce | EDD | jetpack |
* -------------- --------- -------- | ----------- | ---- | ------- |
* User functions 625 775 | 1006 | 1337 | 784 |
* Classes 151 155 | 182 | 174 | 171 |
* Included files 21 28 | 69 | 84 | 51 |
* User constants 13 43 | 50 | 48 | 52 |
*
* The initial User functions and Classes count varies depending on the version of PHP
* With PHP 5.3.5 it's a much lower value than PHP 5.5.7
* PHP version:5.5.7,Internal: 2115,User: 0,Classes: 170
* PHP version:5.3.5,Internal: 1570,User: 0,Classes: 138
*
* @TODO Can we convert backticks to <pre> after esc_html() ?
*
*/
function oik_load_wordpress_prerequisites() {
//pf( "Loading WordPress prerequisites ");
require( ABSPATH . WPINC . "/default-constants.php" );
/*
* These can't be directly globalized in version.php. When updating,
* we're including version.php from another install and don't want
* these values to be overridden if already set.
*/
global $wp_version, $wp_db_version, $tinymce_version, $required_php_version, $required_mysql_version;
require( ABSPATH . WPINC . '/version.php' );
//pf( "Running wp_initial_constants" );
wp_initial_constants();
//pf( "Running require_wp_db" );
oikai_api_status_timer( false, "wp_initial_constants" );
require_wp_db();
oikai_api_status_timer( false, "after require_wp_db" );
//pf( "Running wp_set_wpdb_vars" );
wp_set_wpdb_vars();
oikai_api_status_timer( false, "after wp_set_wpdb_vars" );
//pf( "Running wp_start_object_cache" );
//require( ABSPATH . WPINC . "/cache.php" );
wp_start_object_cache();
//pf( "Running wp_plugin_directory_constants" );
wp_plugin_directory_constants();
require( ABSPATH . WPINC . "/link-template.php" );
oikai_api_status_timer( false, "after link-template.php" );
require( ABSPATH . WPINC . "/shortcodes.php" );
require( ABSPATH . WPINC . "/widgets.php" );
// pf( "Running wp_set_lang_dir" );
wp_set_lang_dir();
}
/**
* Load a plugin's file and report how many files were loaded and how many new functions were defined
*
* This function may not be successful if the plugin does not load its own pre-requisite files.
* See oik_load_wordpress_prerequisites() for the current minimum set.
*
*/
function oik_load_loaded( $argc, $argv ) {
$plugin_file = bw_array_get( $argv, 1, "oik/oik.php" );
oik_batch_trace( false );
timer_start();
oik_require( "bobbfunc.inc" );
//oik_require( "shortcodes/oik-api-status.php", "oik-shortcodes" );
oikai_api_status( false, "oik-batch" );
bw_flush();
oik_load_wordpress_prerequisites();
oikai_api_status( true, "WordPress subset" );
bw_flush();
$plugin_files = bw_as_array( $plugin_file );
foreach ( $plugin_files as $plugin_file ) {
$plugin_file = bw_full_file( $plugin_file );
//timer_start();
$rc = include( $plugin_file );
$elapsed = timer_stop( false, 6 );
//h3( "$plugin_file:$rc" );
//p( "Load time (secs): $elapsed " );
oikai_api_status( false, $plugin_file );
bw_flush();
}
}
/**
* Let this routine be invoked by the web or PHP CLI
*
* When invoked in PHP CLI
*
* @TODO Check security considerations.
*
*/
if ( isset( $_SERVER['argc'] ) ) {
oik_load_loaded( $_SERVER['argc'], $_SERVER['argv'] );
} else {
require( dirname( __FILE__ ) . "/oik-batch.php" );
oik_batch_define_constants();
oik_batch_load_oik_boot();
oik_batch_simulate_wp_settings();
oik_batch_load_wordpress_files();
echo "done" ;
$plugin = bw_array_get( $_REQUEST, "plugin", "oik" );
oik_load_loaded( 2, array( null, $plugin ) );
}