-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathblocktree.php
95 lines (76 loc) · 2.47 KB
/
blocktree.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
<?php
/**
* Plugin Name: Blocktree
* Description: Build a Linktree-like page with blocks
* Requires at least: 5.8
* Requires PHP: 7.0
* Version: 0.1.0
* Author: Cadu de Castro Alves
* License: GPL-2.0-or-later
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
* Text Domain: blocktree
*
* @package create-block
*/
/**
* 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/block-editor/tutorials/block-tutorial/writing-your-first-block-type/
*/
namespace CastroAlves;
class Blocktree {
private $item = 0;
public function __construct()
{
add_action( 'init', [$this, 'blocktree_register_block_type'] );
add_action( 'wp_enqueue_scripts', [$this, 'blocktree_enqueue_scripts'] );
}
public function blocktree_register_block_type() {
$asset_file = include( plugin_dir_path( __FILE__ ) . 'build/index.asset.php' );
wp_register_script(
'blocktree-script',
plugins_url( 'build/index.js', __FILE__ ),
$asset_file['dependencies'],
$asset_file['version']
);
register_block_type( 'castroalves/blocktree', [
'editor_style' => 'blocktree-styles',
'editor_script' => 'blocktree-script',
'render_callback' => [$this, 'blocktree_render_callback'],
] );
}
public function blocktree_enqueue_scripts() {
wp_enqueue_style(
'blocktree-styles',
plugin_dir_url(__FILE__) . 'build/style-index.css',
['twenty-twenty-one-style']
);
}
public function blocktree_render_callback( $attr ) {
$linkTarget = (bool) $attr['linkTarget'] ? 'target="_blank" rel="noopener noreferrer"' : '';
$html = '<div class="blocktree-link-item blocktree-link-item-' . $this->item . '">';
$html .= '<a href="'.$attr['linkUrl'].'"'.$linkTarget.'>'.$attr['linkTitle'].'</a>';
$html .= '</div>';
return $html;
}
// public function blocktree_late_styles() {
// $cssInline = '
// <style type="text/css">
// .blocktree-link-item-' . $this->item . ' > a,
// .blocktree-link-item-' . $this->item . ' > a:focus {
// background-color: ' . $attr['linkBgColor'] . ' !important,
// color: ' . $attr['linkTextColor'] . ' !important,
// }
// </style>
// ';
// }
private function dd( $content ) {
echo '<pre>';
print_r($content);
echo '</pre>';
die();
}
}
$blocktree = new Blocktree;