-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathjoaogrilo.php
259 lines (213 loc) · 6.92 KB
/
joaogrilo.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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
<?php
/**
* João Grilo Plugin
*
* João Grilo is a tool to WordPress developers. It comes with several options intended to be used in the customization of your project.
*
* @package JoaoGrilo
*
*/
/*
Plugin Name: João Grilo
Plugin URI: https://github.com/wordpressceara/joaogrilo
Description: João Grilo is a tool to WordPress developers. It comes with several options intended to be used in the customization of your project.
Version: 1.0
Author: Comunidade Wordpress Ceará
Author URI: https://www.facebook.com/groups/wordpressceara
Text Domain: joao-grilo
Domain Path: /jg-languages/
License: GPLv2 or later
Copyright 2014 COMUNIDADE WORDPRESS CEARÁ (email : [email protected])
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License, version 2, as
published by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
// Exit if accessed directly
defined( 'ABSPATH' ) || exit;
/**
* Main JoaoGrilo Class
*
* @since JoaoGrilo (1.0)
*
*/
if ( ! class_exists('JoaoGrilo') ) :
/**
* Plugin Class Constructor
*
* @since JoaoGrilo (1.0)
*
*/
class JoaoGrilo {
/**
* Main JoaoGrilo Instance.
*
* Insures that only one instance of JoaoGrilo Class exists in memory at any
* one time. Also prevents needing to define globals all over the place.
*
* @since JoaoGrilo (1.0)
*
*/
public static function instance() {
// Store the instance locally to avoid private static replication
static $instance = null;
// Only run these methods if they haven't been run previously
if ( null === $instance ) {
$instance = new JoaoGrilo;
$instance->constants();
$instance->setup_globals();
$instance->setup_hooks();
$instance->includes();
}
// Always return the instance
return $instance;
}
/** Magic Methods *********************************************************/
/**
* A dummy constructor to prevent JoaoGrilo from being loaded more than once.
*
* @since JoaoGrilo (1.0)
* @access private
* @see JoaoGrilo::instance()
*/
private function __construct() { /* Do nothing here */ }
/**
* A dummy magic method to prevent JoaoGrilo from being cloned.
*
* @since JoaoGrilo (1.0)
*/
public function __clone() { _doing_it_wrong( __FUNCTION__, __( 'Cheatin’ huh?', 'joao-grilo' ), '1.0' ); }
/**
* A dummy magic method to prevent JoaoGrilo from being unserialized.
*
* @since JoaoGrilo (1.0)
*/
public function __wakeup() { _doing_it_wrong( __FUNCTION__, __( 'Cheatin’ huh?', 'joao-grilo' ), '1.0' ); }
/** Private Methods *******************************************************/
/**
* Bootstrap constants.
*
* @since JoaoGrilo (1.0)
* @access private
*
*/
private function constants() {
// Path and URL
if ( ! defined( 'JOAOGRILO_PLUGIN_DIR' ) ) {
define( 'JOAOGRILO_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
}
if ( ! defined( 'JOAOGRILO_PLUGIN_URL' ) ) {
define( 'JOAOGRILO_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
}
}
/**
* Component global variables.
*
* @since JoaoGrilo (1.0)
*
* @access private
*
*/
private function setup_globals() {
/** Versions **********************************************************/
$this->version = '1.1';
$this->db_version = 1;
// Domain
$this->domain = 'joao-grilo';
/** Paths**************************************************************/
// JoaoGrilo root directory
$this->file = constant( 'JOAOGRILO_PLUGIN_DIR' ) . 'joaogrilo.php';
$this->basename = basename( constant( 'JOAOGRILO_PLUGIN_DIR' ) ) . '/joaogrilo.php';
$this->plugin_dir = constant( 'JOAOGRILO_PLUGIN_DIR' );
$this->plugin_url = trailingslashit( constant( 'JOAOGRILO_PLUGIN_URL' ) );
// Languages
$this->lang_dir = $this->plugin_dir . 'jg-languages';
}
/**
* Include required files.
*
* @since JoaoGrilo (1.0)
*
* @access private
*
*/
private function includes() {
// Admin Menu Settings
require( $this->plugin_dir . 'settings/class-settings-api.php' );
require( $this->plugin_dir . 'settings/settings-api.php' );
// Classes
require( $this->plugin_dir . 'classes/core.php' );
require( $this->plugin_dir . 'classes/security.php' );
}
/**
* Setups some hooks to register post type stuff, scripts, set
* the current user & load plugin's BuddyPress integration
*
* @since JoaoGrilo (1.0)
*
* @uses add_action() to perform custom actions at key points
*/
private function setup_hooks() {
// Main hooks
add_action( 'wp_joao-grilo_loaded', array( $this, 'load_textdomain' ), 0 );
}
/**
* Loads the translation files
*
* @since JoaoGrilo (1.0)
*
* @uses get_locale() to get the language of WordPress config
* @uses load_texdomain() to load the translation if any is available for the language
*/
public function load_textdomain() {
// Traditional WordPress plugin locale filter
$locale = apply_filters( 'plugin_locale', get_locale(), $this->domain );
$mofile = sprintf( '%1$s-%2$s.mo', $this->domain, $locale );
// Setup paths to current locale file
$mofile_local = $this->lang_dir . $mofile;
$mofile_global = WP_LANG_DIR . '/' . $this->domain . '/' . $mofile;
// Look in global /wp-content/languages/joaogrilo
load_textdomain( $this->domain, $mofile_global );
// Look in local /wp-content/plugins/joaogrilo/jg-languages/ folder
load_textdomain( $this->domain, $mofile_local );
// Look in global /wp-content/languages/plugins/
load_plugin_textdomain( $this->domain );
}
}
/**
* The main function responsible for returning the one true JoaoGrilo Instance to functions everywhere.
*
* Use this function like you would a global variable, except without needing
* to declare the global.
*
* Example: <?php $jg = joaogrilo(); ?>
*
* @return Joaogrilo The one true JoaoGrilo Instance.
*
* @since JoaoGrilo (1.0)
*/
function joaogrilo() {
return JoaoGrilo::instance();
}
/**
* Hook JoaoGrilo early onto the 'plugins_loaded' action..
*
* This gives all other plugins the chance to load before JoaoGrilo, to get
* their actions, filters, and overrides setup without JoaoGrilo being in the
* way.
*
* @since JoaoGrilo (1.0)
*/
if ( defined( 'JOAOGRILO_LATE_LOAD' ) ) {
add_action( 'plugins_loaded', 'joaogrilo', (int) JOAOGRILO_LATE_LOAD );
// "And now here's something I kinda hope you'll like!" =)
} else {
$GLOBALS['jg'] = joaogrilo();
}
endif;