-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathimage-gallery-block.php
More file actions
159 lines (142 loc) · 5.24 KB
/
image-gallery-block.php
File metadata and controls
159 lines (142 loc) · 5.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
<?php
/**
* Plugin Name: Image Gallery Block
* Plugin URI: https://essential-blocks.com
* Description: Impress your audience with beautiful image gallery with lightbox.
* Version: 1.3.1
* Author: WPDeveloper
* Author URI: https://wpdeveloper.net
* License: GPL-3.0-or-later
* License URI: https://www.gnu.org/licenses/gpl-3.0.html
* Text Domain: image-gallery-block
*
* @package image-gallery-block
*/
/**
* Registers all block assets so that they can be enqueued through the block editor
* in the corresponding context.
*
* @see https://developer.wordpress.org/block-editor/tutorials/block-tutorial/applying-styles-with-stylesheets/
*/
require_once __DIR__ . '/includes/font-loader.php';
require_once __DIR__ . '/includes/post-meta.php';
require_once __DIR__ . '/includes/helpers.php';
require_once __DIR__ . '/lib/style-handler/style-handler.php';
function create_block_image_gallery_block_init() {
define( 'IMAGEGALLERY_BLOCK_VERSION', "1.3.1" );
define( 'IMAGEGALLERY_BLOCK_ADMIN_URL', plugin_dir_url( __FILE__ ) );
define( 'IMAGEGALLERY_BLOCK_ADMIN_PATH', dirname( __FILE__ ) );
$script_asset_path = IMAGEGALLERY_BLOCK_ADMIN_PATH . "/dist/index.asset.php";
if ( ! file_exists( $script_asset_path ) ) {
throw new Error(
'You need to run `npm start` or `npm run build` for the "block/testimonial" block first.'
);
}
$index_js = IMAGEGALLERY_BLOCK_ADMIN_URL . 'dist/index.js';
$script_asset = require $script_asset_path;
$all_dependencies = array_merge( $script_asset['dependencies'], [
'wp-blocks',
'wp-i18n',
'wp-element',
'wp-block-editor',
'imagegallery-block-controls-util',
'essential-blocks-eb-animation',
'image-gallery-isotope-js',
'image-gallery-images-loaded-js'
] );
wp_register_script(
'create-block-imagegallery-block-editor-script',
$index_js,
$all_dependencies,
$script_asset['version'],
true
);
$lightbox_css = IMAGEGALLERY_BLOCK_ADMIN_URL . 'lib/css/fslightbox.min.css';
wp_register_style(
'fslightbox-style',
$lightbox_css,
[],
IMAGEGALLERY_BLOCK_VERSION
);
$lightbox_js = IMAGEGALLERY_BLOCK_ADMIN_URL . 'lib/js/fslightbox.min.js';
wp_register_script(
'fslightbox-js',
$lightbox_js,
[ "jquery" ],
IMAGEGALLERY_BLOCK_VERSION,
true
);
$images_loaded_js = IMAGEGALLERY_BLOCK_ADMIN_URL . 'lib/js/images-loaded.min.js';
wp_register_script(
'image-gallery-images-loaded-js',
$images_loaded_js,
[],
IMAGEGALLERY_BLOCK_VERSION,
true
);
$isotope_js = IMAGEGALLERY_BLOCK_ADMIN_URL . 'lib/js/isotope.pkgd.min.js';
wp_register_script(
'image-gallery-isotope-js',
$isotope_js,
[],
IMAGEGALLERY_BLOCK_VERSION,
true
);
$load_animation_js = IMAGEGALLERY_BLOCK_ADMIN_URL . 'lib/js/eb-animation-load.js';
wp_register_script(
'essential-blocks-eb-animation',
$load_animation_js,
[],
IMAGEGALLERY_BLOCK_VERSION,
true
);
$animate_css = IMAGEGALLERY_BLOCK_ADMIN_URL . 'lib/css/animate.min.css';
wp_register_style(
'essential-blocks-animation',
$animate_css,
[],
IMAGEGALLERY_BLOCK_VERSION
);
$style_css = IMAGEGALLERY_BLOCK_ADMIN_URL . 'dist/style.css';
//Frontend Style
wp_register_style(
'create-block-imagegallery-block-frontend-style',
$style_css,
[ 'essential-blocks-animation' ],
IMAGEGALLERY_BLOCK_VERSION
);
//Frontend Script
$frontend_js = IMAGEGALLERY_BLOCK_ADMIN_URL . 'dist/frontend/index.js';
wp_register_script(
'image-gallery-block-frontend-js',
$frontend_js,
[
'image-gallery-isotope-js',
'image-gallery-images-loaded-js'
],
IMAGEGALLERY_BLOCK_VERSION,
true
);
if ( ! WP_Block_Type_Registry::get_instance()->is_registered( 'essential-blocks/advanced-heading' ) ) {
register_block_type(
Image_Gallery_Helper::get_block_register_path( "advanced-heading/advanced-heading", IMAGEGALLERY_BLOCK_ADMIN_PATH ),
[
'editor_script' => 'create-block-imagegallery-block-editor-script',
'editor_style' => 'create-block-imagegallery-block-frontend-style',
'render_callback' => function ( $attributes, $content ) {
if ( ! is_admin() ) {
wp_enqueue_style( 'create-block-imagegallery-block-frontend-style' );
wp_enqueue_style( 'fslightbox-style' );
wp_enqueue_script( 'fslightbox-js' );
wp_enqueue_script( 'essential-blocks-eb-animation' );
wp_enqueue_script( 'image-gallery-images-loaded-js' );
wp_enqueue_script( 'image-gallery-isotope-js' );
wp_enqueue_script( 'image-gallery-block-frontend-js' );
}
return $content;
}
]
);
}
}
add_action( 'init', 'create_block_image_gallery_block_init', 99 );