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

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