-
Notifications
You must be signed in to change notification settings - Fork 2
/
slider-block.php
74 lines (65 loc) · 2.47 KB
/
slider-block.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
<?php
/**
* Plugin Name: Slider Block
* Description: Display a slider.
* Plugin URI: https://pixelalbatross.pt/?utm_source=wp-plugins&utm_medium=slider-block&utm_campaign=plugin-uri
* Requires at least: 6.1
* Requires PHP: 7.4
* Version: 0.5.0
* Author: Pixel Albatross
* Author URI: https://pixelalbatross.pt/?utm_source=wp-plugins&utm_medium=slider-block&utm_campaign=author-uri
* License: GPL-2.0-or-later
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
* Update URI: https://pixelalbatross.pt/
* GitHub Plugin URI: https://github.com/pixelalbatross/slider-block
* Text Domain: slider-block
*
* @package pixelalbatross/slider-block
*/
// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
die;
}
define( 'PIXELALBATROSS_SLIDER_BLOCK_PLUGIN_PATH', plugin_dir_path( __FILE__ ) );
/**
* Registers the block using the metadata loaded from the `block.json` file.
* Behind the scenes, it registers also all assets so they can be enqueued
* through the block editor in the corresponding context.
*
* @see https://developer.wordpress.org/reference/functions/register_block_type/
*/
function pixelalbatross_slider_block_init() {
$block_json_files = glob( PIXELALBATROSS_SLIDER_BLOCK_PLUGIN_PATH . 'build/*/block.json' );
foreach ( $block_json_files as $filename ) {
$block_folder = dirname( $filename );
$block_type = register_block_type_from_metadata( $block_folder );
if ( ! empty( $block_type->editor_script_handles ) ) {
foreach ( $block_type->editor_script_handles as $handle ) {
wp_set_script_translations(
$handle,
'slider-block',
PIXELALBATROSS_SLIDER_BLOCK_PLUGIN_PATH . 'languages'
);
}
}
}
}
add_action( 'init', 'pixelalbatross_slider_block_init' );
/**
* Registers the block textdomain.
*
* @return void
*/
function pixelalbatross_slider_block_i18n() {
load_plugin_textdomain( 'slider-block', false, plugin_basename( PIXELALBATROSS_SLIDER_BLOCK_PLUGIN_PATH ) . '/languages' );
}
add_action( 'plugins_loaded', 'pixelalbatross_slider_block_i18n' );
/**
* Handles JavaScript detection.
*
* Adds a `js` class to the root `<html>` element when JavaScript is detected.
*/
function pixelalbatross_slider_block_js_detection() {
echo "<script>!function(s){s.classList.contains('js')?s.classList:s.classList.add('js')}(document.documentElement);</script>\n";
}
add_action( 'wp_head', 'pixelalbatross_slider_block_js_detection', 0 );