-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgood-slider.php
117 lines (105 loc) · 3.07 KB
/
good-slider.php
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
<?php
/**
* Plugin Name: Good Slider
* Description: A simple and extendable slider block using Swiper
* Requires at least: 6.4
* Requires PHP: 8.1
* Version: 3.1.0
* Author: GoodWP
* Author URI: https://goodwp.io
* License: GPL-3.0-or-later
* License URI: https://www.gnu.org/licenses/gpl-3.0.html
* Text Domain: good-slider
* Domain Path: /languages
*
* @package GoodWP\GoodSlider
*/
namespace GoodWP\GoodSlider;
/**
* Loads the plugin text domain for translation.
*
* @wp-hook
* @return void
*/
function load_languages(): void {
load_plugin_textdomain(
'good-slider',
false,
dirname( plugin_dir_path( __FILE__ ) ) . 'languages'
);
}
add_action( 'init', __NAMESPACE__ . '\load_languages' );
/**
* Register swiper and frontend assets
*
* @wp-hook
* @return void
*/
function register_assets(): void {
/**
* 1. Plugin's swiper script & styles,
* can be disabled, see good-slider/swiper-script-handle filter below and in renderSliderBlock
*/
$swiper_asset_file = plugin_dir_path( __FILE__ ) . 'build/swiper.asset.php';
$swiper_asset_data = require $swiper_asset_file;
/**
* Standard swiper config with most used modules
*/
wp_register_script(
'good-slider-swiper',
plugins_url( 'build/swiper.js', __FILE__ ),
$swiper_asset_data['dependencies'],
'8.4.4', // Use swiper version.
true
);
wp_register_style(
'good-slider-swiper',
plugins_url( 'build/style-swiper.css', __FILE__ ),
[],
'8.4.4' // Use swiper version.
);
/**
* Complete swiper with all modules
*/
wp_register_script(
'good-slider-swiper-full',
plugins_url( 'build/swiper-full.js', __FILE__ ),
$swiper_asset_data['dependencies'],
'8.4.4', // Use swiper version.
true
);
wp_register_style(
'good-slider-swiper-full',
plugins_url( 'build/swiper-full.css', __FILE__ ),
[],
'8.4.4' // Use swiper version.
);
/**
* 2. Plugins frontend js
* Do not add as file-viewScript to block but with asset handle,
* because needs to be registered with custom swiper handle
*/
$script_asset_file = plugin_dir_path( __FILE__ ) . 'build/frontend.asset.php';
$scrip_asset_data = require $script_asset_file;
$script_dependencies = $scrip_asset_data['dependencies'];
/**
* This filter is documented in Blocks\Slider\render_block (src/blocks/slider/index.php#40ff)
* use good-slider-swiper or good-slider-swiper-full for examples
*/
$swiper_script_handle = apply_filters( 'good-slider/swiper-script-handle', 'good-slider-swiper' );
if ( $swiper_script_handle ) {
$script_dependencies[] = $swiper_script_handle;
}
wp_register_script(
'good-slider',
plugins_url( 'build/frontend.js', __FILE__ ),
$script_dependencies,
$scrip_asset_data['version'],
true
);
}
add_action( 'wp_enqueue_scripts', __NAMESPACE__ . '\register_assets' );
require_once plugin_dir_path( __FILE__ ) . 'build/blocks/slider/index.php';
require_once plugin_dir_path( __FILE__ ) . 'build/blocks/slide/index.php';
// Deprecated. Remove in 3.1.0.
require_once plugin_dir_path( __FILE__ ) . 'build/blocks/item/index.php';