PluginProbe
Block Animations, Motion & Scroll Effects – Ghost Kit / 3.7.0
Block Animations, Motion & Scroll Effects – Ghost Kit v3.7.0
3.7.2 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.7.0, at class-ghost-kit.php

480 lines 13.2 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.7.0
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.7.0' );
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 // Since WordPress 7.1 the post editor canvas is always iframed, and core collects
283 // the iframe assets by running `enqueue_block_assets` a second time with
284 // `should_load_block_editor_scripts_and_styles` forced to false.
285 // The editor bundles belong to the editor chrome only - loading them in the canvas
286 // would boot a second copy of the block editor inside the iframe. The vendor
287 // libraries, on the other hand, are needed inside the canvas to render block previews
288 // (for example the `lottie-player` custom element, which is registered per window).
289 if ( ! wp_should_load_block_editor_scripts_and_styles() ) {
290 foreach ( $js_deps as $dep ) {
291 wp_enqueue_script( $dep );
292 }
293
294 return;
295 }
296
297 GhostKit_Assets::enqueue_script(
298 'ghostkit-editor',
299 'build/gutenberg/index',
300 $js_deps
301 );
302
303 // Load plugins in editor only (skip legacy Widgets screen).
304 if ( ! isset( $current_screen->id ) || 'widgets' !== $current_screen->id ) {
305 GhostKit_Assets::enqueue_script(
306 'ghostkit-editor-plugins',
307 'build/gutenberg/plugins',
308 array( 'ghostkit-editor' )
309 );
310 }
311 }
312
313 /**
314 * Excerpt allowed wrapper blocks.
315 *
316 * @param array $blocks - allowed blocks.
317 * @return array
318 */
319 public function excerpt_allowed_blocks( $blocks ) {
320 return array_merge(
321 $blocks,
322 array(
323 'ghostkit/accordion',
324 'ghostkit/accordion-item',
325 'ghostkit/alert',
326 'ghostkit/button',
327 'ghostkit/carousel',
328 'ghostkit/carousel-single',
329 'ghostkit/changelog',
330 'ghostkit/counter-box',
331 'ghostkit/grid',
332 'ghostkit/grid-column',
333 'ghostkit/icon-box',
334 'ghostkit/pricing-table',
335 'ghostkit/pricing-table-item',
336 'ghostkit/tabs-v2',
337 'ghostkit/tabs-tab-v2',
338 'ghostkit/testimonial',
339 )
340 );
341 }
342
343 /**
344 * Allow JSON uploads
345 *
346 * @param array $mimes supported mimes.
347 *
348 * @return array
349 */
350 public function upload_mimes( $mimes ) {
351 if ( ! isset( $mimes['json'] ) ) {
352 $mimes['json'] = 'application/json';
353 }
354
355 return $mimes;
356 }
357
358 /**
359 * Allow JSON file uploads
360 *
361 * @param array $data File data.
362 * @param array $file File object.
363 * @param string $filename File name.
364 *
365 * @return array
366 */
367 public function wp_check_filetype_and_ext( $data, $file, $filename ) {
368 $ext = isset( $data['ext'] ) ? $data['ext'] : '';
369
370 if ( ! $ext ) {
371 $exploded = explode( '.', $filename );
372 $ext = strtolower( end( $exploded ) );
373 }
374
375 if ( 'json' === $ext ) {
376 $data['type'] = 'application/json';
377 $data['ext'] = 'json';
378 }
379
380 return $data;
381 }
382
383 /**
384 * Init variables
385 */
386 public function admin_init() {
387 // get current plugin data.
388 $data = get_plugin_data( __FILE__ );
389 $this->plugin_name = $data['Name'];
390 $this->plugin_version = $data['Version'];
391 $this->plugin_slug = plugin_basename( __FILE__ );
392 $this->plugin_name_sanitized = basename( __FILE__, '.php' );
393 }
394
395 /**
396 * Init hook
397 */
398 public function init_hook() {
399 load_plugin_textdomain( 'ghostkit', false, plugin_dir_path( __FILE__ ) . '/languages' );
400 }
401
402 /**
403 * Add support for 'custom-fields' for all post types.
404 * Required by Customizer and Custom CSS blocks.
405 */
406 public function add_custom_fields_support() {
407 $available_post_types = get_post_types(
408 array(
409 'show_ui' => true,
410 ),
411 'object'
412 );
413
414 foreach ( $available_post_types as $post_type ) {
415 if ( 'attachment' !== $post_type->name ) {
416 add_post_type_support( $post_type->name, 'custom-fields' );
417 }
418 }
419 }
420
421 /**
422 * Equivalent of GHOSTKIT.replaceVars method.
423 *
424 * @param string $str styles string.
425 * @return string string with replaced vars.
426 */
427 public function replace_vars( $str ) {
428 $breakpoints = GhostKit_Breakpoints::get_breakpoints();
429 // TODO: Due to different formats in scss and assets there is an offset.
430 $vars = array(
431 'media_sm' => '(max-width: ' . $breakpoints['xs'] . 'px)',
432 'media_md' => '(max-width: ' . $breakpoints['sm'] . 'px)',
433 'media_lg' => '(max-width: ' . $breakpoints['md'] . 'px)',
434 'media_xl' => '(max-width: ' . $breakpoints['lg'] . 'px)',
435 );
436
437 foreach ( $vars as $k => $var ) {
438 $str = preg_replace( "/#{ghostkitvar:$k}/", $var, $str );
439 }
440
441 return $str;
442 }
443
444 /**
445 * Add Go Pro link to plugins page.
446 *
447 * @param array $links - available links.
448 *
449 * @return array
450 */
451 public function add_go_pro_link_plugins_page( $links ) {
452 return array_merge(
453 $links,
454 array(
455 '<a target="_blank" href="admin.php?page=ghostkit_go_pro&utm_medium=plugins_list">' . esc_html__( 'Go Pro', 'ghostkit' ) . '</a>',
456 )
457 );
458 }
459
460 /**
461 * Get Go Pro link
462 *
463 * @return string
464 */
465 public function go_pro_link() {
466 return 'https://www.ghostkit.io/pricing/';
467 }
468 }
469
470 /**
471 * Function works with the GhostKit class instance
472 *
473 * @return object GhostKit
474 */
475 function ghostkit() {
476 return GhostKit::instance();
477 }
478 add_action( 'plugins_loaded', 'ghostkit' );
479 endif;
480