-
Notifications
You must be signed in to change notification settings - Fork 5
/
bootstrap.php
81 lines (68 loc) · 2.45 KB
/
bootstrap.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
<?php
/*
Plugin Name: Quick Navigation Interface
Plugin URI: https://wordpress.org/plugins/quick-navigation-interface
Description: Quickly access screens and content within wp-admin just by typing the first few letters of the name.
Version: 1.0.1
Author: Ian Dunn
Author URI: https://iandunn.name
*/
defined( 'WPINC' ) || die;
define( 'QNI_VERSION', '1.0.1' );
define( 'QNI_REQUIRED_PHP_VERSION', '5.6' ); // Because of WordPress minimum requirements.
define( 'QNI_REQUIRED_WP_VERSION', '5.2' ); // Because of React Context.
/**
* Checks if the system requirements are met
*
* @return bool True if system requirements are met, false if not
*/
function qni_requirements_met() {
global $wp_version;
if ( version_compare( PHP_VERSION, QNI_REQUIRED_PHP_VERSION, '<' ) ) {
return false;
}
if ( version_compare( $wp_version, QNI_REQUIRED_WP_VERSION, '<' ) ) {
return false;
}
return true;
}
/**
* Prints an error that the system requirements weren't met.
*/
function qni_requirements_error() {
global $wp_version;
require_once( dirname( __FILE__ ) . '/requirements-error.php' );
}
/**
* Detect if the current screen is the login screen.
*
* @see https://wordpress.stackexchange.com/questions/12863/check-if-wp-login-is-current-page#comment506953_225298
*
* @todo Remove this if https://core.trac.wordpress.org/ticket/19898 provides a canonical solution.
*
* @return bool
*/
function qni_is_login_screen() {
return false !== stripos( wp_login_url(), $_SERVER['SCRIPT_NAME'] );
}
/*
* Check requirements and load the main class
*
* The main program needs to be in a separate file that only gets loaded if the plugin requirements are met. Otherwise older PHP installations could crash when trying to parse it.
*/
if ( qni_requirements_met() ) {
/*
* This isn't really what `wp_is_json_request()` is meant for, but it's the best option until
* https://core.trac.wordpress.org/ticket/42061 is resolved.
*
* @todo Replace with `wp_doing_rest()` (or whatever) once that's available on minimum required WP version.
*/
if ( is_admin() || wp_is_json_request() || qni_is_login_screen() ) {
require_once( dirname( __FILE__ ) . '/components/main/controller.php' );
}
add_action( 'customize_preview_init', function() {
require_once( dirname( __FILE__ ) . '/components/main/previewer.php' );
}, 9 ); // Before the `customize_preview_init` callback in `previewer.php`.
} else {
add_action( 'admin_notices', 'qni_requirements_error' );
}