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

446 lines 11.3 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.3
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.4.3' );
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.php';
112 require_once $this->plugin_path . 'classes/class-reusable-widget.php';
113 require_once $this->plugin_path . 'classes/class-icons.php';
114 require_once $this->plugin_path . 'classes/class-shapes.php';
115 require_once $this->plugin_path . 'classes/class-typography.php';
116 require_once $this->plugin_path . 'classes/class-fonts.php';
117 require_once $this->plugin_path . 'classes/class-templates.php';
118 require_once $this->plugin_path . 'classes/class-scss-replace-modules.php';
119 require_once $this->plugin_path . 'classes/class-scss-compiler.php';
120 require_once $this->plugin_path . 'classes/class-breakpoints-background.php';
121 require_once $this->plugin_path . 'classes/class-breakpoints.php';
122 require_once $this->plugin_path . 'classes/class-ask-review.php';
123 require_once $this->plugin_path . 'classes/class-deactivate-duplicate-plugin.php';
124
125 require_once $this->plugin_path . 'gutenberg/utils/encode-decode/index.php';
126 require_once $this->plugin_path . 'gutenberg/extend/index.php';
127
128 // 3rd.
129 require_once $this->plugin_path . 'classes/3rd/class-astra.php';
130 require_once $this->plugin_path . 'classes/3rd/class-page-builder-framework.php';
131 require_once $this->plugin_path . 'classes/3rd/class-blocksy.php';
132 require_once $this->plugin_path . 'classes/3rd/class-rank-math.php';
133
134 // Migration.
135 require_once $this->plugin_path . 'classes/class-migration.php';
136 }
137
138 /**
139 * Init hooks
140 */
141 public function init_hooks() {
142 add_action( 'admin_init', array( $this, 'admin_init' ) );
143
144 add_action( 'init', array( $this, 'init_hook' ) );
145
146 add_action( 'init', array( $this, 'add_custom_fields_support' ), 100 );
147
148 add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), array( $this, 'add_go_pro_link_plugins_page' ) );
149
150 add_action( 'wp_enqueue_scripts', array( $this, 'js_translation' ), 11 );
151 add_action( 'enqueue_block_editor_assets', array( $this, 'js_translation_editor' ) );
152
153 // add Ghost Kit blocks category.
154 add_filter( 'block_categories_all', array( $this, 'block_categories_all' ), 9999 );
155
156 // we need to enqueue the main script earlier to let 3rd-party plugins add custom styles support.
157 add_action( 'enqueue_block_assets', array( $this, 'enqueue_block_assets' ), 9 );
158
159 // add support for excerpts to some blocks.
160 add_filter( 'excerpt_allowed_blocks', array( $this, 'excerpt_allowed_blocks' ) );
161
162 // add support for additional mimes.
163 add_filter( 'upload_mimes', array( $this, 'upload_mimes' ), 100 );
164 add_filter( 'wp_check_filetype_and_ext', array( $this, 'wp_check_filetype_and_ext' ), 100, 3 );
165 }
166
167 /**
168 * JS translation.
169 */
170 public function js_translation() {
171 if ( ! function_exists( 'wp_set_script_translations' ) ) {
172 return;
173 }
174
175 wp_set_script_translations( 'ghostkit-block-countdown', 'ghostkit', plugin_dir_path( __FILE__ ) . '/languages' );
176 }
177
178 /**
179 * JS translation for editor.
180 */
181 public function js_translation_editor() {
182 if ( ! function_exists( 'wp_set_script_translations' ) ) {
183 return;
184 }
185
186 wp_set_script_translations( 'ghostkit-editor', 'ghostkit', plugin_dir_path( __FILE__ ) . '/languages' );
187 wp_set_script_translations( 'ghostkit-settings', 'ghostkit', plugin_dir_path( __FILE__ ) . '/languages' );
188 }
189
190 /**
191 * Register Ghost Kit blocks category
192 *
193 * @param array $categories - available categories.
194 * @return array
195 */
196 public function block_categories_all( $categories ) {
197 return array_merge(
198 array(
199 array(
200 'slug' => 'ghostkit',
201 'title' => __( 'Ghost Kit', 'ghostkit' ),
202 ),
203 ),
204 $categories
205 );
206 }
207
208 /**
209 * Enqueue editor assets
210 */
211 public function enqueue_block_assets() {
212 if ( ! is_admin() ) {
213 return;
214 }
215
216 global $current_screen;
217
218 $css_deps = array();
219 $js_deps = array( 'ghostkit-helper' );
220
221 // Ivent.
222 if ( apply_filters( 'gkt_enqueue_plugin_ivent', true ) ) {
223 $js_deps[] = 'ivent';
224 }
225
226 // Motion.
227 if ( apply_filters( 'gkt_enqueue_plugin_motion', true ) ) {
228 $js_deps[] = 'motion';
229 }
230
231 // Jarallax.
232 if ( apply_filters( 'gkt_enqueue_plugin_jarallax', true ) ) {
233 $js_deps[] = 'jarallax';
234 $js_deps[] = 'jarallax-video';
235 }
236
237 // Luxon.
238 if ( apply_filters( 'gkt_enqueue_plugin_luxon', true ) ) {
239 $js_deps[] = 'luxon';
240 }
241
242 // Lottie Player.
243 if ( apply_filters( 'gkt_enqueue_plugin_lottie_player', true ) ) {
244 $js_deps[] = 'lottie-player';
245 }
246
247 // GistEmbed.
248 if ( apply_filters( 'gkt_enqueue_plugin_gist_simple', true ) ) {
249 $css_deps[] = 'gist-simple';
250 $js_deps[] = 'gist-simple';
251 }
252
253 // Ghost Kit.
254 GhostKit_Assets::enqueue_style(
255 'ghostkit-editor',
256 'build/gutenberg/editor',
257 $css_deps,
258 filemtime( plugin_dir_path( __FILE__ ) . 'build/gutenberg/editor.css' )
259 );
260 wp_style_add_data( 'ghostkit-editor', 'rtl', 'replace' );
261 wp_style_add_data( 'ghostkit-editor', 'suffix', '.min' );
262
263 GhostKit_Assets::enqueue_script(
264 'ghostkit-editor',
265 'build/gutenberg/index',
266 $js_deps
267 );
268
269 // Load plugins in editor only (skip legacy Widgets screen).
270 if ( ! isset( $current_screen->id ) || 'widgets' !== $current_screen->id ) {
271 GhostKit_Assets::enqueue_script(
272 'ghostkit-editor-plugins',
273 'build/gutenberg/plugins',
274 array( 'ghostkit-editor' )
275 );
276 }
277 }
278
279 /**
280 * Excerpt allowed wrapper blocks.
281 *
282 * @param array $blocks - allowed blocks.
283 * @return array
284 */
285 public function excerpt_allowed_blocks( $blocks ) {
286 return array_merge(
287 $blocks,
288 array(
289 'ghostkit/accordion',
290 'ghostkit/accordion-item',
291 'ghostkit/alert',
292 'ghostkit/button',
293 'ghostkit/carousel',
294 'ghostkit/carousel-single',
295 'ghostkit/changelog',
296 'ghostkit/counter-box',
297 'ghostkit/grid',
298 'ghostkit/grid-column',
299 'ghostkit/icon-box',
300 'ghostkit/pricing-table',
301 'ghostkit/pricing-table-item',
302 'ghostkit/tabs-v2',
303 'ghostkit/tabs-tab-v2',
304 'ghostkit/testimonial',
305 )
306 );
307 }
308
309 /**
310 * Allow JSON uploads
311 *
312 * @param array $mimes supported mimes.
313 *
314 * @return array
315 */
316 public function upload_mimes( $mimes ) {
317 if ( ! isset( $mimes['json'] ) ) {
318 $mimes['json'] = 'application/json';
319 }
320
321 return $mimes;
322 }
323
324 /**
325 * Allow JSON file uploads
326 *
327 * @param array $data File data.
328 * @param array $file File object.
329 * @param string $filename File name.
330 *
331 * @return array
332 */
333 public function wp_check_filetype_and_ext( $data, $file, $filename ) {
334 $ext = isset( $data['ext'] ) ? $data['ext'] : '';
335
336 if ( ! $ext ) {
337 $exploded = explode( '.', $filename );
338 $ext = strtolower( end( $exploded ) );
339 }
340
341 if ( 'json' === $ext ) {
342 $data['type'] = 'application/json';
343 $data['ext'] = 'json';
344 }
345
346 return $data;
347 }
348
349 /**
350 * Init variables
351 */
352 public function admin_init() {
353 // get current plugin data.
354 $data = get_plugin_data( __FILE__ );
355 $this->plugin_name = $data['Name'];
356 $this->plugin_version = $data['Version'];
357 $this->plugin_slug = plugin_basename( __FILE__ );
358 $this->plugin_name_sanitized = basename( __FILE__, '.php' );
359 }
360
361 /**
362 * Init hook
363 */
364 public function init_hook() {
365 load_plugin_textdomain( 'ghostkit', false, plugin_dir_path( __FILE__ ) . '/languages' );
366 }
367
368 /**
369 * Add support for 'custom-fields' for all post types.
370 * Required by Customizer and Custom CSS blocks.
371 */
372 public function add_custom_fields_support() {
373 $available_post_types = get_post_types(
374 array(
375 'show_ui' => true,
376 ),
377 'object'
378 );
379
380 foreach ( $available_post_types as $post_type ) {
381 if ( 'attachment' !== $post_type->name ) {
382 add_post_type_support( $post_type->name, 'custom-fields' );
383 }
384 }
385 }
386
387 /**
388 * Equivalent of GHOSTKIT.replaceVars method.
389 *
390 * @param string $str styles string.
391 * @return string string with replaced vars.
392 */
393 public function replace_vars( $str ) {
394 $breakpoints = GhostKit_Breakpoints::get_breakpoints();
395 // TODO: Due to different formats in scss and assets there is an offset.
396 $vars = array(
397 'media_sm' => '(max-width: ' . $breakpoints['xs'] . 'px)',
398 'media_md' => '(max-width: ' . $breakpoints['sm'] . 'px)',
399 'media_lg' => '(max-width: ' . $breakpoints['md'] . 'px)',
400 'media_xl' => '(max-width: ' . $breakpoints['lg'] . 'px)',
401 );
402
403 foreach ( $vars as $k => $var ) {
404 $str = preg_replace( "/#{ghostkitvar:$k}/", $var, $str );
405 }
406
407 return $str;
408 }
409
410 /**
411 * Add Go Pro link to plugins page.
412 *
413 * @param array $links - available links.
414 *
415 * @return array
416 */
417 public function add_go_pro_link_plugins_page( $links ) {
418 return array_merge(
419 $links,
420 array(
421 '<a target="_blank" href="admin.php?page=ghostkit_go_pro&utm_medium=plugins_list">' . esc_html__( 'Go Pro', 'ghostkit' ) . '</a>',
422 )
423 );
424 }
425
426 /**
427 * Get Go Pro link
428 *
429 * @return string
430 */
431 public function go_pro_link() {
432 return 'https://www.ghostkit.io/pricing/';
433 }
434 }
435
436 /**
437 * Function works with the GhostKit class instance
438 *
439 * @return object GhostKit
440 */
441 function ghostkit() {
442 return GhostKit::instance();
443 }
444 add_action( 'plugins_loaded', 'ghostkit' );
445 endif;
446