PluginProbe
Block Animations, Motion & Scroll Effects – Ghost Kit / 3.6.1
Block Animations, Motion & Scroll Effects – Ghost Kit v3.6.1
3.7.1 3.7.0 3.6.1 trunk 1.6.3 2.25.0 3.3.0 3.3.1 3.3.2 3.3.3 3.4.0 3.4.1 3.4.2 3.4.3 3.4.4 3.4.5 3.4.6 3.5.0 3.5.1 3.6.0
ghostkit / class-ghost-kit.php

class-ghost-kit.php in Block Animations, Motion & Scroll Effects – Ghost Kit 3.6.1, at class-ghost-kit.php

465 lines 12.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Plugin Name: Ghost Kit
4 * Description: Page Builder Blocks and Extensions for Gutenberg
5 * Version: 3.6.1
6 * Plugin URI: https://www.ghostkit.io/?utm_source=wordpress.org&utm_medium=readme&utm_campaign=byline
7 * Author: Ghost Kit Team
8 * Author URI: https://www.ghostkit.io/?utm_source=wordpress.org&utm_medium=readme&utm_campaign=byline
9 * License: GPLv2 or later
10 * License URI: https://www.gnu.org/licenses/gpl-2.0.html
11 * Text Domain: ghostkit
12 *
13 * @package ghostkit
14 */
15
16 if ( ! defined( 'ABSPATH' ) ) {
17 exit;
18 }
19
20 if ( ! defined( 'GHOSTKIT_VERSION' ) ) {
21 define( 'GHOSTKIT_VERSION', '3.6.1' );
22 }
23
24 if ( ! class_exists( 'GhostKit' ) ) :
25 /**
26 * GhostKit Class
27 */
28 class GhostKit {
29
30 /**
31 * The single class instance.
32 *
33 * @var $instance
34 */
35 private static $instance = null;
36
37 /**
38 * Path to the plugin directory
39 *
40 * @var $plugin_path
41 */
42 public $plugin_path;
43
44 /**
45 * URL to the plugin directory
46 *
47 * @var $plugin_url
48 */
49 public $plugin_url;
50
51 /**
52 * Plugin name
53 *
54 * @var $plugin_name
55 */
56 public $plugin_name;
57
58 /**
59 * Plugin version
60 *
61 * @var $plugin_version
62 */
63 public $plugin_version;
64
65 /**
66 * Plugin slug
67 *
68 * @var $plugin_slug
69 */
70 public $plugin_slug;
71
72 /**
73 * Plugin name sanitized
74 *
75 * @var $plugin_name_sanitized
76 */
77 public $plugin_name_sanitized;
78
79 /**
80 * GhostKit constructor.
81 */
82 public function __construct() {
83 /* We do nothing here! */
84 }
85
86 /**
87 * Main Instance
88 * Ensures only one instance of this class exists in memory at any one time.
89 */
90 public static function instance() {
91 if ( is_null( self::$instance ) ) {
92 self::$instance = new self();
93 self::$instance->init_options();
94 self::$instance->init_hooks();
95 }
96 return self::$instance;
97 }
98
99 /**
100 * Init options
101 */
102 public function init_options() {
103 $this->plugin_path = plugin_dir_path( __FILE__ );
104 $this->plugin_url = plugin_dir_url( __FILE__ );
105
106 require_once $this->plugin_path . 'settings/index.php';
107 require_once $this->plugin_path . 'gutenberg/index.php';
108
109 require_once $this->plugin_path . 'classes/class-rest.php';
110 require_once $this->plugin_path . 'classes/class-parse-blocks.php';
111 require_once $this->plugin_path . 'classes/class-assets-detector.php';
112 require_once $this->plugin_path . 'classes/class-assets.php';
113 require_once $this->plugin_path . 'classes/class-reusable-widget.php';
114 require_once $this->plugin_path . 'classes/class-icons.php';
115 require_once $this->plugin_path . 'classes/class-shapes.php';
116 require_once $this->plugin_path . 'classes/class-typography.php';
117 require_once $this->plugin_path . 'classes/class-fonts.php';
118 require_once $this->plugin_path . 'classes/class-templates.php';
119 require_once $this->plugin_path . 'classes/class-scss-replace-modules.php';
120 require_once $this->plugin_path . 'classes/class-scss-compiler.php';
121 require_once $this->plugin_path . 'classes/class-breakpoints-background.php';
122 require_once $this->plugin_path . 'classes/class-breakpoints.php';
123 require_once $this->plugin_path . 'classes/class-ask-review.php';
124 require_once $this->plugin_path . 'classes/class-deactivate-duplicate-plugin.php';
125
126 require_once $this->plugin_path . 'gutenberg/utils/encode-decode/index.php';
127 require_once $this->plugin_path . 'gutenberg/extend/index.php';
128
129 // 3rd.
130 require_once $this->plugin_path . 'classes/3rd/class-astra.php';
131 require_once $this->plugin_path . 'classes/3rd/class-page-builder-framework.php';
132 require_once $this->plugin_path . 'classes/3rd/class-blocksy.php';
133 require_once $this->plugin_path . 'classes/3rd/class-rank-math.php';
134
135 // Migration.
136 require_once $this->plugin_path . 'classes/class-migration.php';
137 }
138
139 /**
140 * Init hooks
141 */
142 public function init_hooks() {
143 add_action( 'admin_init', array( $this, 'admin_init' ) );
144
145 add_action( 'init', array( $this, 'init_hook' ) );
146
147 add_action( 'init', array( $this, 'add_custom_fields_support' ), 100 );
148
149 add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), array( $this, 'add_go_pro_link_plugins_page' ) );
150
151 add_action( 'wp_enqueue_scripts', array( $this, 'js_translation' ), 11 );
152 add_action( 'enqueue_block_editor_assets', array( $this, 'js_translation_editor' ) );
153
154 // add Ghost Kit blocks category.
155 add_filter( 'block_categories_all', array( $this, 'block_categories_all' ), 9999 );
156
157 // we need to enqueue the main script earlier to let 3rd-party plugins add custom styles support.
158 add_action( 'enqueue_block_assets', array( $this, 'enqueue_block_assets' ), 9 );
159
160 // add support for excerpts to some blocks.
161 add_filter( 'excerpt_allowed_blocks', array( $this, 'excerpt_allowed_blocks' ) );
162
163 // add support for additional mimes.
164 add_filter( 'upload_mimes', array( $this, 'upload_mimes' ), 100 );
165 add_filter( 'wp_check_filetype_and_ext', array( $this, 'wp_check_filetype_and_ext' ), 100, 3 );
166 }
167
168 /**
169 * JS translation.
170 */
171 public function js_translation() {
172 if ( ! function_exists( 'wp_set_script_translations' ) ) {
173 return;
174 }
175
176 wp_set_script_translations( 'ghostkit-block-countdown', 'ghostkit', plugin_dir_path( __FILE__ ) . '/languages' );
177 }
178
179 /**
180 * JS translation for editor.
181 */
182 public function js_translation_editor() {
183 if ( ! function_exists( 'wp_set_script_translations' ) ) {
184 return;
185 }
186
187 wp_set_script_translations( 'ghostkit-editor', 'ghostkit', plugin_dir_path( __FILE__ ) . '/languages' );
188 wp_set_script_translations( 'ghostkit-settings', 'ghostkit', plugin_dir_path( __FILE__ ) . '/languages' );
189 }
190
191 /**
192 * Register Ghost Kit blocks category
193 *
194 * @param array $categories - available categories.
195 * @return array
196 */
197 public function block_categories_all( $categories ) {
198 return array_merge(
199 array(
200 array(
201 'slug' => 'ghostkit',
202 'title' => __( 'Ghost Kit', 'ghostkit' ),
203 ),
204 ),
205 $categories
206 );
207 }
208
209 /**
210 * Enqueue editor assets
211 */
212 public function enqueue_block_assets() {
213 if ( ! is_admin() ) {
214 return;
215 }
216
217 global $current_screen;
218
219 $css_deps = array();
220 $js_deps = array( 'ghostkit-helper' );
221
222 // Ivent.
223 if ( apply_filters( 'gkt_enqueue_plugin_ivent', true ) ) {
224 $js_deps[] = 'ivent';
225 }
226
227 // Motion.
228 if ( apply_filters( 'gkt_enqueue_plugin_motion', true ) ) {
229 $js_deps[] = 'motion';
230 }
231
232 // Jarallax.
233 if ( apply_filters( 'gkt_enqueue_plugin_jarallax', true ) ) {
234 $js_deps[] = 'jarallax';
235 $js_deps[] = 'jarallax-video';
236 }
237
238 // Luxon.
239 if ( apply_filters( 'gkt_enqueue_plugin_luxon', true ) ) {
240 $js_deps[] = 'luxon';
241 }
242
243 // Lottie Player.
244 if ( apply_filters( 'gkt_enqueue_plugin_lottie_player', true ) ) {
245 $js_deps[] = 'lottie-player';
246 }
247
248 // GistEmbed.
249 if ( apply_filters( 'gkt_enqueue_plugin_gist_simple', true ) ) {
250 $css_deps[] = 'gist-simple';
251 $js_deps[] = 'gist-simple';
252 }
253
254 // In block metadata, many Ghost Kit blocks declare `style: ["ghostkit", ...]`.
255 // Because of this, WordPress auto-enqueues the `ghostkit` style handle for those blocks
256 // in every context where blocks are rendered, including the editor.
257 //
258 // `ghostkit` is our frontend stylesheet (`build/gutenberg/style.css`), while editor UI
259 // is styled by `ghostkit-editor` (`build/gutenberg/editor.css`). Loading both in editor
260 // causes conflicts (for example, frontend Display extension rules can hide editor blocks).
261 //
262 // To keep block dependency chains intact without editing all block.json files, we override
263 // only the `ghostkit` handle in admin and make it an alias that depends on `ghostkit-editor`.
264 // Result:
265 // - frontend keeps using real `ghostkit` styles;
266 // - editor resolves `ghostkit` dependencies to editor styles, avoiding CSS conflicts.
267 if ( wp_style_is( 'ghostkit', 'registered' ) ) {
268 wp_deregister_style( 'ghostkit' );
269 }
270 wp_register_style( 'ghostkit', false, array( 'ghostkit-editor' ), GHOSTKIT_VERSION );
271
272 // Ghost Kit.
273 GhostKit_Assets::enqueue_style(
274 'ghostkit-editor',
275 'build/gutenberg/editor',
276 $css_deps,
277 filemtime( plugin_dir_path( __FILE__ ) . 'build/gutenberg/editor.css' )
278 );
279 wp_style_add_data( 'ghostkit-editor', 'rtl', 'replace' );
280 wp_style_add_data( 'ghostkit-editor', 'suffix', '.min' );
281
282 GhostKit_Assets::enqueue_script(
283 'ghostkit-editor',
284 'build/gutenberg/index',
285 $js_deps
286 );
287
288 // Load plugins in editor only (skip legacy Widgets screen).
289 if ( ! isset( $current_screen->id ) || 'widgets' !== $current_screen->id ) {
290 GhostKit_Assets::enqueue_script(
291 'ghostkit-editor-plugins',
292 'build/gutenberg/plugins',
293 array( 'ghostkit-editor' )
294 );
295 }
296 }
297
298 /**
299 * Excerpt allowed wrapper blocks.
300 *
301 * @param array $blocks - allowed blocks.
302 * @return array
303 */
304 public function excerpt_allowed_blocks( $blocks ) {
305 return array_merge(
306 $blocks,
307 array(
308 'ghostkit/accordion',
309 'ghostkit/accordion-item',
310 'ghostkit/alert',
311 'ghostkit/button',
312 'ghostkit/carousel',
313 'ghostkit/carousel-single',
314 'ghostkit/changelog',
315 'ghostkit/counter-box',
316 'ghostkit/grid',
317 'ghostkit/grid-column',
318 'ghostkit/icon-box',
319 'ghostkit/pricing-table',
320 'ghostkit/pricing-table-item',
321 'ghostkit/tabs-v2',
322 'ghostkit/tabs-tab-v2',
323 'ghostkit/testimonial',
324 )
325 );
326 }
327
328 /**
329 * Allow JSON uploads
330 *
331 * @param array $mimes supported mimes.
332 *
333 * @return array
334 */
335 public function upload_mimes( $mimes ) {
336 if ( ! isset( $mimes['json'] ) ) {
337 $mimes['json'] = 'application/json';
338 }
339
340 return $mimes;
341 }
342
343 /**
344 * Allow JSON file uploads
345 *
346 * @param array $data File data.
347 * @param array $file File object.
348 * @param string $filename File name.
349 *
350 * @return array
351 */
352 public function wp_check_filetype_and_ext( $data, $file, $filename ) {
353 $ext = isset( $data['ext'] ) ? $data['ext'] : '';
354
355 if ( ! $ext ) {
356 $exploded = explode( '.', $filename );
357 $ext = strtolower( end( $exploded ) );
358 }
359
360 if ( 'json' === $ext ) {
361 $data['type'] = 'application/json';
362 $data['ext'] = 'json';
363 }
364
365 return $data;
366 }
367
368 /**
369 * Init variables
370 */
371 public function admin_init() {
372 // get current plugin data.
373 $data = get_plugin_data( __FILE__ );
374 $this->plugin_name = $data['Name'];
375 $this->plugin_version = $data['Version'];
376 $this->plugin_slug = plugin_basename( __FILE__ );
377 $this->plugin_name_sanitized = basename( __FILE__, '.php' );
378 }
379
380 /**
381 * Init hook
382 */
383 public function init_hook() {
384 load_plugin_textdomain( 'ghostkit', false, plugin_dir_path( __FILE__ ) . '/languages' );
385 }
386
387 /**
388 * Add support for 'custom-fields' for all post types.
389 * Required by Customizer and Custom CSS blocks.
390 */
391 public function add_custom_fields_support() {
392 $available_post_types = get_post_types(
393 array(
394 'show_ui' => true,
395 ),
396 'object'
397 );
398
399 foreach ( $available_post_types as $post_type ) {
400 if ( 'attachment' !== $post_type->name ) {
401 add_post_type_support( $post_type->name, 'custom-fields' );
402 }
403 }
404 }
405
406 /**
407 * Equivalent of GHOSTKIT.replaceVars method.
408 *
409 * @param string $str styles string.
410 * @return string string with replaced vars.
411 */
412 public function replace_vars( $str ) {
413 $breakpoints = GhostKit_Breakpoints::get_breakpoints();
414 // TODO: Due to different formats in scss and assets there is an offset.
415 $vars = array(
416 'media_sm' => '(max-width: ' . $breakpoints['xs'] . 'px)',
417 'media_md' => '(max-width: ' . $breakpoints['sm'] . 'px)',
418 'media_lg' => '(max-width: ' . $breakpoints['md'] . 'px)',
419 'media_xl' => '(max-width: ' . $breakpoints['lg'] . 'px)',
420 );
421
422 foreach ( $vars as $k => $var ) {
423 $str = preg_replace( "/#{ghostkitvar:$k}/", $var, $str );
424 }
425
426 return $str;
427 }
428
429 /**
430 * Add Go Pro link to plugins page.
431 *
432 * @param array $links - available links.
433 *
434 * @return array
435 */
436 public function add_go_pro_link_plugins_page( $links ) {
437 return array_merge(
438 $links,
439 array(
440 '<a target="_blank" href="admin.php?page=ghostkit_go_pro&utm_medium=plugins_list">' . esc_html__( 'Go Pro', 'ghostkit' ) . '</a>',
441 )
442 );
443 }
444
445 /**
446 * Get Go Pro link
447 *
448 * @return string
449 */
450 public function go_pro_link() {
451 return 'https://www.ghostkit.io/pricing/';
452 }
453 }
454
455 /**
456 * Function works with the GhostKit class instance
457 *
458 * @return object GhostKit
459 */
460 function ghostkit() {
461 return GhostKit::instance();
462 }
463 add_action( 'plugins_loaded', 'ghostkit' );
464 endif;
465