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

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