-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcrouton.php
173 lines (131 loc) · 3.75 KB
/
crouton.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
<?php
/**
* Plugin Name: Crouton
* Plugin URI: http://chefduweb.nl/cuisine
* Description: Starting canvas for Cuisine plugins
* Version: 1.2.2
* Author: Luc Princen
* Author URI: http://www.chefduweb.nl/
* License: GPLv2
*
* @package Cuisine
* @category Core
* @author Chef du Web
*/
//change this namespace
namespace Crouton;
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
// The directory separator.
defined('DS') ? DS : define('DS', DIRECTORY_SEPARATOR);
/**
* Main class that bootstraps the plugin.
*/
if (!class_exists('PluginIgniter')) {
class PluginIgniter {
/**
* Plugin bootstrap instance.
*
* @var \Crouton\PluginIgniter
*/
private static $instance = null;
/**
* Plugin version.
*
* @var float
*/
const VERSION = '1.1';
/**
* Plugin directory name.
*
* @var string
*/
private static $dirName = '';
private function __construct(){
static::$dirName = static::setDirName(__DIR__);
// Load plugin.
$this->load();
}
/**
* Load the framework classes.
*
* @return void
*/
private function load(){
//require the language domain:
$path = __DIR__ . DS . '/Languages/';
load_plugin_textdomain( 'crouton', false, $path );
//require the autoloader:
require( __DIR__ . DS . 'autoloader.php');
//initiate the autoloader:
( new \Crouton\Autoloader() )->register()->load();
//give off the loaded hook
do_action( 'crouton_loaded' );
}
/*=============================================================*/
/** Getters & Setters */
/*=============================================================*/
/**
* Init the plugin classes
*
* @return \Crouton\PluginIgniter
*/
public static function getInstance(){
if ( is_null( static::$instance ) ){
static::$instance = new static();
}
return static::$instance;
}
/**
* Set the plugin directory property. This property
* is used as 'key' in order to retrieve the plugins
* informations.
*
* @param string
* @return string
*/
private static function setDirName($path) {
$parent = static::getParentDirectoryName(dirname($path));
$dirName = explode($parent, $path);
$dirName = substr($dirName[1], 1);
return $dirName;
}
/**
* Check if the plugin is inside the 'mu-plugins'
* or 'plugin' directory.
*
* @param string $path
* @return string
*/
private static function getParentDirectoryName($path) {
// Check if in the 'mu-plugins' directory.
if (WPMU_PLUGIN_DIR === $path) {
return 'mu-plugins';
}
// Install as a classic plugin.
return 'plugins';
}
/**
* Get the plugin path
*
* @return string
*/
public static function getPluginPath(){
return __DIR__.DS;
}
/**
* Returns the directory name.
*
* @return string
*/
public static function getDirName(){
return static::$dirName;
}
}
}
/**
* Load the main class, when Cuisine is loaded
*
*/
add_action('cuisine_loaded', function(){
\Crouton\PluginIgniter::getInstance();
});