-
-
Notifications
You must be signed in to change notification settings - Fork 33
/
class-ghost-kit.php
444 lines (383 loc) · 11.2 KB
/
class-ghost-kit.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
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
<?php
/**
* Plugin Name: Ghost Kit
* Description: Page Builder Blocks and Extensions for Gutenberg
* Version: 3.4.0
* Author: Ghost Kit Team
* Author URI: https://www.ghostkit.io/?utm_source=wordpress.org&utm_medium=readme&utm_campaign=byline
* License: GPLv2 or later
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
* Text Domain: ghostkit
*
* @package ghostkit
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
if ( ! defined( 'GHOSTKIT_VERSION' ) ) {
define( 'GHOSTKIT_VERSION', '3.4.0' );
}
if ( ! class_exists( 'GhostKit' ) ) :
/**
* GhostKit Class
*/
class GhostKit {
/**
* The single class instance.
*
* @var $instance
*/
private static $instance = null;
/**
* Path to the plugin directory
*
* @var $plugin_path
*/
public $plugin_path;
/**
* URL to the plugin directory
*
* @var $plugin_url
*/
public $plugin_url;
/**
* Plugin name
*
* @var $plugin_name
*/
public $plugin_name;
/**
* Plugin version
*
* @var $plugin_version
*/
public $plugin_version;
/**
* Plugin slug
*
* @var $plugin_slug
*/
public $plugin_slug;
/**
* Plugin name sanitized
*
* @var $plugin_name_sanitized
*/
public $plugin_name_sanitized;
/**
* GhostKit constructor.
*/
public function __construct() {
/* We do nothing here! */
}
/**
* Main Instance
* Ensures only one instance of this class exists in memory at any one time.
*/
public static function instance() {
if ( is_null( self::$instance ) ) {
self::$instance = new self();
self::$instance->init_options();
self::$instance->init_hooks();
}
return self::$instance;
}
/**
* Init options
*/
public function init_options() {
$this->plugin_path = plugin_dir_path( __FILE__ );
$this->plugin_url = plugin_dir_url( __FILE__ );
require_once $this->plugin_path . 'settings/index.php';
require_once $this->plugin_path . 'gutenberg/index.php';
require_once $this->plugin_path . 'classes/class-rest.php';
require_once $this->plugin_path . 'classes/class-parse-blocks.php';
require_once $this->plugin_path . 'classes/class-assets.php';
require_once $this->plugin_path . 'classes/class-reusable-widget.php';
require_once $this->plugin_path . 'classes/class-icons.php';
require_once $this->plugin_path . 'classes/class-shapes.php';
require_once $this->plugin_path . 'classes/class-typography.php';
require_once $this->plugin_path . 'classes/class-fonts.php';
require_once $this->plugin_path . 'classes/class-templates.php';
require_once $this->plugin_path . 'classes/class-scss-replace-modules.php';
require_once $this->plugin_path . 'classes/class-scss-compiler.php';
require_once $this->plugin_path . 'classes/class-breakpoints-background.php';
require_once $this->plugin_path . 'classes/class-breakpoints.php';
require_once $this->plugin_path . 'classes/class-ask-review.php';
require_once $this->plugin_path . 'classes/class-deactivate-duplicate-plugin.php';
require_once $this->plugin_path . 'gutenberg/utils/encode-decode/index.php';
require_once $this->plugin_path . 'gutenberg/extend/index.php';
// 3rd.
require_once $this->plugin_path . 'classes/3rd/class-astra.php';
require_once $this->plugin_path . 'classes/3rd/class-page-builder-framework.php';
require_once $this->plugin_path . 'classes/3rd/class-blocksy.php';
require_once $this->plugin_path . 'classes/3rd/class-rank-math.php';
// Migration.
require_once $this->plugin_path . 'classes/class-migration.php';
}
/**
* Init hooks
*/
public function init_hooks() {
add_action( 'admin_init', array( $this, 'admin_init' ) );
add_action( 'init', array( $this, 'init_hook' ) );
add_action( 'init', array( $this, 'add_custom_fields_support' ), 100 );
add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), array( $this, 'add_go_pro_link_plugins_page' ) );
add_action( 'wp_enqueue_scripts', array( $this, 'js_translation' ), 11 );
add_action( 'enqueue_block_editor_assets', array( $this, 'js_translation_editor' ) );
// add Ghost Kit blocks category.
add_filter( 'block_categories_all', array( $this, 'block_categories_all' ), 9999 );
// we need to enqueue the main script earlier to let 3rd-party plugins add custom styles support.
add_action( 'enqueue_block_assets', array( $this, 'enqueue_block_assets' ), 9 );
// add support for excerpts to some blocks.
add_filter( 'excerpt_allowed_blocks', array( $this, 'excerpt_allowed_blocks' ) );
// add support for additional mimes.
add_filter( 'upload_mimes', array( $this, 'upload_mimes' ), 100 );
add_filter( 'wp_check_filetype_and_ext', array( $this, 'wp_check_filetype_and_ext' ), 100, 3 );
}
/**
* JS translation.
*/
public function js_translation() {
if ( ! function_exists( 'wp_set_script_translations' ) ) {
return;
}
wp_set_script_translations( 'ghostkit-block-countdown', 'ghostkit', plugin_dir_path( __FILE__ ) . '/languages' );
}
/**
* JS translation for editor.
*/
public function js_translation_editor() {
if ( ! function_exists( 'wp_set_script_translations' ) ) {
return;
}
wp_set_script_translations( 'ghostkit-editor', 'ghostkit', plugin_dir_path( __FILE__ ) . '/languages' );
wp_set_script_translations( 'ghostkit-settings', 'ghostkit', plugin_dir_path( __FILE__ ) . '/languages' );
}
/**
* Register Ghost Kit blocks category
*
* @param array $categories - available categories.
* @return array
*/
public function block_categories_all( $categories ) {
return array_merge(
array(
array(
'slug' => 'ghostkit',
'title' => __( 'Ghost Kit', 'ghostkit' ),
),
),
$categories
);
}
/**
* Enqueue editor assets
*/
public function enqueue_block_assets() {
if ( ! is_admin() ) {
return;
}
global $current_screen;
$css_deps = array();
$js_deps = array( 'ghostkit-helper' );
// Ivent.
if ( apply_filters( 'gkt_enqueue_plugin_ivent', true ) ) {
$js_deps[] = 'ivent';
}
// Motion.
if ( apply_filters( 'gkt_enqueue_plugin_motion', true ) ) {
$js_deps[] = 'motion';
}
// Jarallax.
if ( apply_filters( 'gkt_enqueue_plugin_jarallax', true ) ) {
$js_deps[] = 'jarallax';
$js_deps[] = 'jarallax-video';
}
// Luxon.
if ( apply_filters( 'gkt_enqueue_plugin_luxon', true ) ) {
$js_deps[] = 'luxon';
}
// Lottie Player.
if ( apply_filters( 'gkt_enqueue_plugin_lottie_player', true ) ) {
$js_deps[] = 'lottie-player';
}
// GistEmbed.
if ( apply_filters( 'gkt_enqueue_plugin_gist_simple', true ) ) {
$css_deps[] = 'gist-simple';
$js_deps[] = 'gist-simple';
}
// Ghost Kit.
GhostKit_Assets::enqueue_style(
'ghostkit-editor',
'build/gutenberg/editor',
$css_deps,
filemtime( plugin_dir_path( __FILE__ ) . 'build/gutenberg/editor.css' )
);
wp_style_add_data( 'ghostkit-editor', 'rtl', 'replace' );
wp_style_add_data( 'ghostkit-editor', 'suffix', '.min' );
GhostKit_Assets::enqueue_script(
'ghostkit-editor',
'build/gutenberg/index',
$js_deps
);
// Load plugins in editor only (skip legacy Widgets screen).
if ( ! isset( $current_screen->id ) || 'widgets' !== $current_screen->id ) {
GhostKit_Assets::enqueue_script(
'ghostkit-editor-plugins',
'build/gutenberg/plugins',
array( 'ghostkit-editor' )
);
}
}
/**
* Excerpt allowed wrapper blocks.
*
* @param array $blocks - allowed blocks.
* @return array
*/
public function excerpt_allowed_blocks( $blocks ) {
return array_merge(
$blocks,
array(
'ghostkit/accordion',
'ghostkit/accordion-item',
'ghostkit/alert',
'ghostkit/button',
'ghostkit/carousel',
'ghostkit/carousel-single',
'ghostkit/changelog',
'ghostkit/counter-box',
'ghostkit/grid',
'ghostkit/grid-column',
'ghostkit/icon-box',
'ghostkit/pricing-table',
'ghostkit/pricing-table-item',
'ghostkit/tabs-v2',
'ghostkit/tabs-tab-v2',
'ghostkit/testimonial',
)
);
}
/**
* Allow JSON uploads
*
* @param array $mimes supported mimes.
*
* @return array
*/
public function upload_mimes( $mimes ) {
if ( ! isset( $mimes['json'] ) ) {
$mimes['json'] = 'application/json';
}
return $mimes;
}
/**
* Allow JSON file uploads
*
* @param array $data File data.
* @param array $file File object.
* @param string $filename File name.
*
* @return array
*/
public function wp_check_filetype_and_ext( $data, $file, $filename ) {
$ext = isset( $data['ext'] ) ? $data['ext'] : '';
if ( ! $ext ) {
$exploded = explode( '.', $filename );
$ext = strtolower( end( $exploded ) );
}
if ( 'json' === $ext ) {
$data['type'] = 'application/json';
$data['ext'] = 'json';
}
return $data;
}
/**
* Init variables
*/
public function admin_init() {
// get current plugin data.
$data = get_plugin_data( __FILE__ );
$this->plugin_name = $data['Name'];
$this->plugin_version = $data['Version'];
$this->plugin_slug = plugin_basename( __FILE__ );
$this->plugin_name_sanitized = basename( __FILE__, '.php' );
}
/**
* Init hook
*/
public function init_hook() {
load_plugin_textdomain( 'ghostkit', false, plugin_dir_path( __FILE__ ) . '/languages' );
}
/**
* Add support for 'custom-fields' for all post types.
* Required by Customizer and Custom CSS blocks.
*/
public function add_custom_fields_support() {
$available_post_types = get_post_types(
array(
'show_ui' => true,
),
'object'
);
foreach ( $available_post_types as $post_type ) {
if ( 'attachment' !== $post_type->name ) {
add_post_type_support( $post_type->name, 'custom-fields' );
}
}
}
/**
* Equivalent of GHOSTKIT.replaceVars method.
*
* @param string $str styles string.
* @return string string with replaced vars.
*/
public function replace_vars( $str ) {
$breakpoints = GhostKit_Breakpoints::get_breakpoints();
// TODO: Due to different formats in scss and assets there is an offset.
$vars = array(
'media_sm' => '(max-width: ' . $breakpoints['xs'] . 'px)',
'media_md' => '(max-width: ' . $breakpoints['sm'] . 'px)',
'media_lg' => '(max-width: ' . $breakpoints['md'] . 'px)',
'media_xl' => '(max-width: ' . $breakpoints['lg'] . 'px)',
);
foreach ( $vars as $k => $var ) {
$str = preg_replace( "/#{ghostkitvar:$k}/", $var, $str );
}
return $str;
}
/**
* Add Go Pro link to plugins page.
*
* @param array $links - available links.
*
* @return array
*/
public function add_go_pro_link_plugins_page( $links ) {
return array_merge(
$links,
array(
'<a target="_blank" href="admin.php?page=ghostkit_go_pro&utm_medium=plugins_list">' . esc_html__( 'Go Pro', 'ghostkit' ) . '</a>',
)
);
}
/**
* Get Go Pro link
*
* @return string
*/
public function go_pro_link() {
return 'https://www.ghostkit.io/pricing/';
}
}
/**
* Function works with the GhostKit class instance
*
* @return object GhostKit
*/
function ghostkit() {
return GhostKit::instance();
}
add_action( 'plugins_loaded', 'ghostkit' );
endif;