|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Bootstrap class |
|
4
|
|
|
* |
|
5
|
|
|
* Add required Hooks and Filters to provide: |
|
6
|
|
|
* - Theme required implementation |
|
7
|
|
|
* - Implementation registration |
|
8
|
|
|
* - Implementation ready status |
|
9
|
|
|
* - Translations |
|
10
|
|
|
* |
|
11
|
|
|
* @package Stencil |
|
12
|
|
|
*/ |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Class Bootstrap |
|
16
|
|
|
*/ |
|
17
|
|
|
class Stencil_Bootstrap { |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* Bootstrap constructor. |
|
21
|
|
|
*/ |
|
22
|
|
|
public function __construct() { |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* Initialize the plugin to check for registered addons |
|
26
|
|
|
* |
|
27
|
|
|
* Checking if a plugin is active with the "stencil-" prefix is not enough |
|
28
|
|
|
* The plugin could have not implemented the proper hook and could not be usable in the theme |
|
29
|
|
|
*/ |
|
30
|
|
|
add_action( 'after_setup_theme', array( __CLASS__, 'boot' ) ); |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* Allow implementation to be filtered |
|
34
|
|
|
*/ |
|
35
|
|
|
add_filter( Stencil_Environment::format_filter( 'implementation' ), array( __CLASS__, 'implementation' ) ); |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* Boot Stencil when an engine is ready |
|
39
|
|
|
*/ |
|
40
|
|
|
add_action( Stencil_Environment::format_hook( 'engine_ready' ), array( 'Stencil', 'boot' ) ); |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* Load plugin textdomain |
|
44
|
|
|
*/ |
|
45
|
|
|
add_action( 'plugins_loaded', array( __CLASS__, 'load_textdomain' ) ); |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* Boot up config if we are in the CMS. |
|
49
|
|
|
*/ |
|
50
|
|
|
if ( is_admin() ) { |
|
51
|
|
|
new Stencil_Config(); |
|
52
|
|
|
} |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* Get the classname of the required Implementation |
|
57
|
|
|
*/ |
|
58
|
|
|
public static function boot() { |
|
59
|
|
|
$implementation = Stencil_Environment::filter( 'implementation', false ); |
|
60
|
|
|
$required = Stencil_Environment::filter( 'require', false ); |
|
61
|
|
|
|
|
62
|
|
|
if ( $implementation !== $required ) { |
|
63
|
|
|
$message = __( '<em>Theme Addon conflict</em>. The active theme requires the Stencil Implementation: <em>%s</em> to be active.', 'stencil' ); |
|
64
|
|
|
$message = sprintf( $message, $required ); |
|
65
|
|
|
|
|
66
|
|
|
Stencil_Feedback::notification( 'error', $message ); |
|
67
|
|
|
|
|
68
|
|
|
return null; |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
// Tell the implementation to active itself. |
|
72
|
|
|
Stencil_Environment::trigger( 'activate-' . $required ); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* Get the required implementation if found, otherwise first in list. |
|
77
|
|
|
* |
|
78
|
|
|
* @return bool |
|
79
|
|
|
*/ |
|
80
|
|
|
public static function implementation() { |
|
|
|
|
|
|
81
|
|
|
$engines = Stencil_Environment::filter( 'register-engine', array() ); |
|
82
|
|
|
if ( ! is_array( $engines ) || array() === $engines ) { |
|
83
|
|
|
return false; |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* Get theme required addon information |
|
88
|
|
|
* |
|
89
|
|
|
* If the addon that the theme needs is registered, return it |
|
90
|
|
|
*/ |
|
91
|
|
|
$required = Stencil_Environment::filter( 'require', false ); |
|
92
|
|
|
if ( in_array( $required, $engines, true ) ) { |
|
93
|
|
|
return $required; |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
/** |
|
97
|
|
|
* Otherwise return first registered one |
|
98
|
|
|
*/ |
|
99
|
|
|
return false; |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
/** |
|
103
|
|
|
* Load translations for Stencil |
|
104
|
|
|
*/ |
|
105
|
|
|
public static function load_textdomain() { |
|
106
|
|
|
load_plugin_textdomain( 'stencil', false, STENCIL_PATH . '/languages' ); |
|
107
|
|
|
} |
|
108
|
|
|
} |
|
109
|
|
|
|
This check examines a number of code elements and verifies that they conform to the given naming conventions.
You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.