/
blox-lite.php
304 lines (245 loc) · 8.76 KB
/
blox-lite.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
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
<?php
/**
* Plugin Name: Blox Lite - Content Blocks for Genesis
* Plugin URI: https://www.bloxwp.com
* Description: Easily customize themes built on the Genesis Framework
* Author: Nick Diego
* Author URI: http://www.outermostdesign.com
* Version: 1.2.5
* Text Domain: blox
* Domain Path: languages
*
* Copyright 2017 Nick Diego
*
* Blox Lite is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* any later version.
*
* Blox Lite 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 Blox Lite. If not, visit <http://www.gnu.org/licenses/>.
*/
// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) exit;
/**
* Main plugin class.
*
* @since 1.0.0
*
* @package Blox
* @author Nick Diego
*/
class Blox_Lite_Main {
/**
* Holds the class object.
*
* @since 1.0.0
*
* @var object
*/
public static $instance;
/**
* Plugin version, used for cache-busting of style and script file references.
*
* @since 1.0.0
*
* @var string
*/
public $version = '1.2.5';
/**
* The name of the plugin.
*
* @since 1.0.0
*
* @var string
*/
public $plugin_name = 'Blox Lite';
/**
* The unique slug of the plugin.
*
* @since 1.0.0
*
* @var string
*/
public $plugin_slug = 'blox-lite';
/**
* Plugin file.
*
* @since 1.0.0
*
* @var string
*/
public $file = __FILE__;
/**
* Primary class constructor.
*
* @since 1.0.0
*/
public function __construct() {
// Fire a hook before the class is setup.
do_action( 'blox_pre_init' );
// Make sure that Genesis is active before enabling the plugin
register_activation_hook( __FILE__ , array( $this, 'activation_check' ) );
// Disable the plugin if Genesis is not the active theme
add_action('admin_init', array( $this, 'disable_check' ) );
// Load the plugin textdomain.
add_action( 'plugins_loaded', array( $this, 'load_textdomain' ) );
// Load the plugin.
add_action( 'init', array( $this, 'init' ), 0 );
// Add additional links to the plugin's row on the admin plugin page
add_filter( 'plugin_action_links', array( $this, 'plugin_action_links' ), 10, 2 );
add_filter( 'plugin_row_meta', array( $this, 'plugin_row_meta' ), 10, 2 );
}
/**
* This function runs on plugin activation. It checks to make sure the required
* minimum Genesis version is installed. If not, it deactivates the plugin.
*
* @since 1.0.0
*/
public function activation_check() {
$latest = '2.0';
$theme_info = wp_get_theme( 'genesis' );
if ( ! function_exists( 'genesis_pre' ) ) {
deactivate_plugins( plugin_basename( __FILE__ ) ); // Deactivate plugin
wp_die( sprintf( __( 'Sorry, you can\'t activate %1$sBlox-Lite%2$s unless you have installed the %3$sGenesis Framework%4$s. Go back to the %5$sPlugins Page%4$s.', 'blox' ), '<em>', '</em>', '<a href="http://www.studiopress.com/themes/genesis" target="_blank">', '</a>', '<a href="javascript:history.back()">' ) );
}
if ( version_compare( $theme_info['Version'], $latest, '<' ) ) {
deactivate_plugins( plugin_basename( __FILE__ ) ); // Deactivate plugin
wp_die( sprintf( __( 'Sorry, you can\'t activate %1$sBlox-Lite%2$s unless you have installed the %3$sGenesis %4$s%5$s. Go back to the %6$sPlugins Page%5$s.', 'blox' ), '<em>', '</em>', '<a href="http://www.studiopress.com/themes/genesis" target="_blank">', $latest, '</a>', '<a href="javascript:history.back()">' ) );
}
}
/**
* This function runs on admin_init and checks to make sure Genesis is active, if not, it
* disables the plugin. This is useful for when users switch to non-Genesis themes. It does
* not "deactivate" the plugin, so as soon as you switch to a Genesis theme, the plugin
* works again.
*
* @since 1.0.0
*/
public function disable_check() {
if ( ! function_exists('genesis_pre') ) {
return;
}
}
/**
* Loads the plugin textdomain for translation.
*
* @since 1.0.0
*/
public function load_textdomain() {
load_plugin_textdomain( 'blox', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
}
/**
* Loads the plugin into WordPress.
*
* @since 1.0.0
*/
public function init() {
// If the Blox exists and is activated, do nothing.
if ( class_exists( 'Blox_Main' ) ) {
return;
}
// Run hook once Blox has been initialized.
do_action( 'blox_init' );
// Settings class
require plugin_dir_path( __FILE__ ) . 'includes/global/settings.php';
// Plugin utility classes
require plugin_dir_path( __FILE__ ) . 'includes/global/common.php';
require plugin_dir_path( __FILE__ ) . 'includes/global/posttype.php';
require plugin_dir_path( __FILE__ ) . 'includes/global/action-storage.php';
// Content block settings classes that need to be global in scope
require plugin_dir_path( __FILE__ ) . 'includes/global/location.php';
// Content classes
require plugin_dir_path( __FILE__ ) . 'includes/global/content/image.php';
require plugin_dir_path( __FILE__ ) . 'includes/global/content/raw.php';
require plugin_dir_path( __FILE__ ) . 'includes/global/content/shortcodes.php';
// Load admin only components.
if ( is_admin() ) {
// Main admin classes
require plugin_dir_path( __FILE__ ) . 'includes/admin/posttype.php';
require plugin_dir_path( __FILE__ ) . 'includes/admin/metaboxes.php';
// Content block settings classes
require plugin_dir_path( __FILE__ ) . 'includes/admin/content.php';
require plugin_dir_path( __FILE__ ) . 'includes/admin/position.php';
require plugin_dir_path( __FILE__ ) . 'includes/admin/style.php';
// All those annoying marketing notices ;) You can disable them under Misc Settings
require plugin_dir_path( __FILE__ ) . 'includes/admin/marketing.php';
}
// Load frontend only components.
if ( ! is_admin() ) {
// Class for generating all frontend markup
require plugin_dir_path( __FILE__ ) . 'includes/frontend/frontend.php';
}
}
/**
* Adds link to General Settings page in plugin row action links
*
* @since 1.0.0
*
* @param array $links Already defined action links
* @param string $file Plugin file path and name being processed
* @return array $links The new array of action links
*/
public function plugin_action_links( $links, $file ) {
$settings_link = '<a href="' . admin_url( 'edit.php?post_type=blox&page=blox-settings' ) . '">' . __( 'Settings', 'blox' ) . '</a>';
if ( $file == 'blox-lite/blox-lite.php' ) {
array_unshift( $links, $settings_link );
}
return $links;
}
/**
* Adds additional links to the plugin row meta links
*
* @since 1.0.0
*
* @param array $links Already defined meta links
* @param string $file Plugin file path and name being processed
* @return array $links The new array of meta links
*/
function plugin_row_meta( $links, $file ) {
// If we are not on the correct plugin, abort
if ( $file != 'blox-lite/blox-lite.php' ) {
return $links;
}
$docs_link = esc_url( add_query_arg( array(
'utm_source' => 'blox-lite',
'utm_medium' => 'plugin',
'utm_campaign' => 'Blox_Plugin_Links',
'utm_content' => 'plugins-page-link'
), 'https://www.bloxwp.com/documentation/' )
);
$upgrade_link = esc_url( add_query_arg( array(
'utm_source' => 'blox-lite',
'utm_medium' => 'plugin',
'utm_campaign' => 'Blox_Plugin_Links',
'utm_content' => 'plugins-page-link'
), 'https://www.bloxwp.com/features/' )
);
$new_links = array(
'<a href="' . $docs_link . '" target="_blank">' . esc_html__( 'Documentation', 'blox' ) . '</a>',
'<a href="' . $upgrade_link . '" target="_blank">' . esc_html__( 'Upgrade to Blox', 'blox' ) . '</a>',
);
$links = array_merge( $links, $new_links );
return $links;
}
/**
* Returns the singleton instance of the class.
*
* @since 1.0.0
*
* @return object The class object.
*/
public static function get_instance() {
if ( ! isset( self::$instance ) && ! ( self::$instance instanceof Blox_Lite_Main ) ) {
self::$instance = new Blox_Lite_Main();
}
return self::$instance;
}
}
// Load the main plugin class.
$Blox_Lite_Main = Blox_Lite_Main::get_instance();