-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathctx-blocks.php
More file actions
76 lines (55 loc) · 2.13 KB
/
ctx-blocks.php
File metadata and controls
76 lines (55 loc) · 2.13 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
<?php
/**
* Plugin Name: CTX Blocks
* Description: Additional Blocks for Gutenberg
* Version: 3.1.9
* Requires at least: 6.7
* Requires PHP: 8.3
* Author: Thomas Gollenia
* License: GPL-2.0-or-later
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
* Text Domain: ctx-blocks
*
* @package create-block
*/
use Contexis\WpGitHubUpdater\WordPressPluginUpdater;
require_once __DIR__ . '/vendor/autoload.php';
function ctx_block_init() {
$block_directories = glob( __DIR__ . '/build/blocks/*', GLOB_ONLYDIR );
if ( ! $block_directories ) {
return;
}
foreach ( $block_directories as $block_directory ) {
register_block_type( $block_directory );
}
}
add_action( 'init', 'ctx_block_init' );
require_once __DIR__ . '/lib/Posts.php';
require_once __DIR__ . '/lib/Icons.php';
function ctx_blocks_load_textdomain() {
load_plugin_textdomain('ctx-blocks', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' );
}
add_action( 'plugins_loaded', 'ctx_blocks_load_textdomain' );
function modify_render_block_defaults($block_content, $block, $instance) {
if($block['blockName'] !== "core/latest-posts" || !key_exists('animateOnScroll', $block['attrs'])) {
return $block_content;
}
$block_content = str_replace('<ul class="wp-block-latest-posts__list', '<ul class="wp-block-latest-posts__list ctx-animate-children ctx-' . $block['attrs']['animationType'] . ' ', $block_content);
return $block_content;
}
add_filter( "render_block", "modify_render_block_defaults", 10, 3 );
function ctx_add_class_to_list_block( $block_content, $block ) {
if ( 'core/list' === $block['blockName'] ) {
$block_content = new WP_HTML_Tag_Processor( $block_content );
$block_content->next_tag(); /* first tag should always be ul or ol */
$block_content->add_class( 'core-block' );
$block_content->get_updated_html();
}
return $block_content;
}
add_filter( 'render_block', 'ctx_add_class_to_list_block', 10, 2 );
WordPressPluginUpdater::fromPluginFile(
pluginFile: __FILE__,
owner: 'gollenia',
repositoryName: 'ctx-blocks',
)->registerHooks();