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

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