PluginProbe
Image Slider Block / trunk
Image Slider Block vtrunk
trunk 1.0.0 1.1.0 1.2.0 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.3.8 1.4.0
slider-block / slider-block.php

slider-block.php in Image Slider Block trunk, at slider-block.php

189 lines 6.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Plugin Name: Image Slider Block
5 * Description: Display Multiple Images In Beautiful Slider & Reduce Page Scroll
6 * Version: 1.4.0
7 * Author: WPDeveloper
8 * Author URI: https://wpdeveloper.net
9 * License: GPL-3.0-or-later
10 * License URI: https://www.gnu.org/licenses/gpl-3.0.html
11 * Text Domain: slider-block
12 * Requires at least: 6.0
13 * Tested up to: 7.0.4
14 * Requires PHP: 7.4
15 *
16 * @package slider-block
17 */
18
19 // Exit if accessed directly.
20 if ( ! defined( 'ABSPATH' ) ) {
21 exit;
22 }
23
24 /**
25 * Registers all block assets so that they can be enqueued through the block editor
26 * in the corresponding context.
27 *
28 * @see https://developer.wordpress.org/block-editor/tutorials/block-tutorial/applying-styles-with-stylesheets/
29 */
30
31 require_once __DIR__ . '/includes/font-loader.php';
32 require_once __DIR__ . '/includes/post-meta.php';
33 require_once __DIR__ . '/includes/helpers.php';
34
35 /**
36 * Shipped as a git submodule, so it is absent from an uninitialised checkout
37 * and from GitHub's "Download ZIP" (which never includes submodules).
38 *
39 * EbStyleHandler is what turns each block's saved `blockMeta` attribute into
40 * the per-post stylesheet under uploads/eb-style/ and enqueues it on the front
41 * end. Without it the editor still looks right -- it injects its own <style>
42 * tag live -- while the front end silently loses every configured dot, arrow,
43 * spacing and sizing rule. Keep the require guarded so a partial checkout does
44 * not fatal, but surface the state in wp-admin so it cannot go unnoticed.
45 */
46 if ( file_exists( __DIR__ . '/lib/style-handler/style-handler.php' ) ) {
47 require_once __DIR__ . '/lib/style-handler/style-handler.php';
48 } else {
49 add_action( 'admin_notices', 'slider_block_style_handler_missing_notice' );
50 }
51
52 function slider_block_style_handler_missing_notice() {
53 if ( ! current_user_can( 'activate_plugins' ) ) {
54 return;
55 }
56
57 printf(
58 '<div class="notice notice-error"><p><strong>%1$s</strong> %2$s <code>git submodule update --init --recursive</code></p></div>',
59 esc_html__( 'Image Slider Block:', 'slider-block' ),
60 esc_html__( 'the bundled style-handler library is missing, so slider styling will not be applied on the front end. If you installed this plugin from a git checkout, run:', 'slider-block' )
61 );
62 }
63
64 function create_block_slider_block_init() {
65 if ( ! defined( 'SLIDER_BLOCK_VERSION' ) ) {
66 define( 'SLIDER_BLOCK_VERSION', "1.4.0" );
67 }
68 if ( ! defined( 'SLIDER_BLOCK_ADMIN_URL' ) ) {
69 define( 'SLIDER_BLOCK_ADMIN_URL', plugin_dir_url( __FILE__ ) );
70 }
71 if ( ! defined( 'SLIDER_BLOCK_ADMIN_PATH' ) ) {
72 define( 'SLIDER_BLOCK_ADMIN_PATH', dirname( __FILE__ ) );
73 }
74
75 $script_asset_path = SLIDER_BLOCK_ADMIN_PATH . "/dist/index.asset.php";
76 $frontend_asset_path = SLIDER_BLOCK_ADMIN_PATH . '/dist/frontend/index.asset.php';
77 if ( ! file_exists( $script_asset_path ) || ! file_exists( $frontend_asset_path ) ) {
78 throw new Error(
79 'You need to run `npm start` or `npm run build` for the "block/testimonial" block first.'
80 );
81 }
82 $index_js = SLIDER_BLOCK_ADMIN_URL . 'dist/index.js';
83 $script_asset = require $script_asset_path;
84 $script_asset = is_array( $script_asset ) ? $script_asset : [];
85 $all_dependencies = array_merge( isset( $script_asset['dependencies'] ) ? $script_asset['dependencies'] : [], [
86 'wp-blocks',
87 'wp-i18n',
88 'wp-element',
89 'wp-block-editor',
90 'slider-block-controls-util',
91 'essential-blocks-slickjs',
92 'essential-blocks-eb-animation'
93 ] );
94
95 wp_register_script(
96 'create-block-slider-block-editor-script',
97 $index_js,
98 $all_dependencies,
99 isset( $script_asset['version'] ) ? $script_asset['version'] : SLIDER_BLOCK_VERSION,
100 true
101 );
102
103 $animate_css = SLIDER_BLOCK_ADMIN_URL . 'lib/css/animate.min.css';
104 wp_register_style(
105 'essential-blocks-animation',
106 $animate_css,
107 [],
108 SLIDER_BLOCK_VERSION
109 );
110
111 $slick_css = SLIDER_BLOCK_ADMIN_URL . 'lib/css/slick.css';
112 wp_register_style(
113 'slick-style',
114 $slick_css,
115 [],
116 SLIDER_BLOCK_VERSION
117 );
118
119 $slick_js = SLIDER_BLOCK_ADMIN_URL . 'lib/js/slick.min.js';
120 wp_register_script(
121 'essential-blocks-slickjs',
122 $slick_js,
123 ["jquery"],
124 SLIDER_BLOCK_VERSION,
125 true
126 );
127
128 $load_animation_js = SLIDER_BLOCK_ADMIN_URL . 'lib/js/eb-animation-load.js';
129 wp_register_script(
130 'essential-blocks-eb-animation',
131 $load_animation_js,
132 ["jquery"],
133 SLIDER_BLOCK_VERSION,
134 true
135 );
136
137 wp_register_style(
138 'essential-blocks-fontawesome',
139 SLIDER_BLOCK_ADMIN_URL . 'lib/css/fontawesome/css/all.min.css',
140 [],
141 SLIDER_BLOCK_VERSION
142 );
143
144 $style_css = SLIDER_BLOCK_ADMIN_URL . 'dist/style.css';
145 //Frontend & Editor Style
146 wp_register_style(
147 'create-block-slider-block-frontend-style',
148 $style_css,
149 [
150 'slick-style',
151 'essential-blocks-animation',
152 'essential-blocks-fontawesome'
153 ],
154 SLIDER_BLOCK_VERSION
155 );
156
157 //Frontend Style
158 $frontend_js = SLIDER_BLOCK_ADMIN_URL . 'dist/frontend/index.js';
159 $frontend_asset = require $frontend_asset_path;
160 $frontend_asset = is_array( $frontend_asset ) ? $frontend_asset : [];
161 wp_register_script(
162 'slider-block-frontend-js',
163 $frontend_js,
164 isset( $frontend_asset['dependencies'] ) ? $frontend_asset['dependencies'] : [],
165 isset( $frontend_asset['version'] ) ? $frontend_asset['version'] : SLIDER_BLOCK_VERSION,
166 true
167 );
168
169 if ( ! WP_Block_Type_Registry::get_instance()->is_registered( 'essential-blocks/slider' ) ) {
170 register_block_type(
171 Slider_Helper::get_block_register_path( "slider-block/slider-block", SLIDER_BLOCK_ADMIN_PATH ),
172 [
173 'editor_script' => 'create-block-slider-block-editor-script',
174 'editor_style' => 'create-block-slider-block-frontend-style',
175 'render_callback' => function ( $attributes, $content ) {
176 if ( ! is_admin() ) {
177 wp_enqueue_style( 'create-block-slider-block-frontend-style' );
178 wp_enqueue_script( 'essential-blocks-slickjs' );
179 wp_enqueue_script( 'essential-blocks-eb-animation' );
180 wp_enqueue_script( 'slider-block-frontend-js' );
181 }
182 return $content;
183 }
184 ]
185 );
186 }
187 }
188 add_action( 'init', 'create_block_slider_block_init', 99 );
189