PluginProbe ʕ •ᴥ•ʔ
Hostinger Reach – AI-Powered Email Marketing for WordPress / 1.5.9
Hostinger Reach – AI-Powered Email Marketing for WordPress v1.5.9
1.6.0 1.5.9 1.5.8 1.5.7 1.5.6 1.5.5 1.5.4 1.5.3 1.5.2 1.5.1 1.5.0 1.4.12 1.4.11 1.4.10 1.4.9 1.4.8 1.4.7 trunk 1.0.1 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.1.1 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 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.3.9 1.4.0 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6
hostinger-reach / src / Blocks / Block.php
hostinger-reach / src / Blocks Last commit date
Block.php 11 months ago SubscriptionFormBlock.php 2 weeks ago
Block.php
100 lines
1 <?php
2
3 namespace Hostinger\Reach\Blocks;
4
5 use Hostinger\Reach\Functions;
6 use Hostinger\Reach\Setup\Assets;
7
8 if ( ! defined( 'ABSPATH' ) ) {
9 die;
10 }
11
12 abstract class Block {
13 public Assets $assets;
14 public Functions $functions;
15 public string $name;
16
17 public function __construct( Assets $assets, Functions $functions ) {
18 $this->assets = $assets;
19 $this->functions = $functions;
20 add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
21 }
22
23
24 public function get_block_name(): string {
25 return "hostinger-reach-$this->name-block";
26 }
27
28 public function enqueue_scripts(): void {
29 $this->enqueue_block_style();
30 $this->enqueue_block_script();
31 }
32
33 public function register(): void {
34 register_block_type(
35 HOSTINGER_REACH_PLUGIN_DIR . "frontend/blocks/$this->name-block/block.json",
36 array(
37 'render_callback' => array( $this, 'render' ),
38 )
39 );
40 }
41
42 public function enqueue_block(): void {
43 if ( $this->functions->block_file_exists( "$this->name.js" ) === false ) {
44 return;
45 }
46
47 wp_enqueue_script(
48 $this->get_block_name() . '-editor',
49 $this->functions->get_blocks_url() . "$this->name.js",
50 array( 'react', 'wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-i18n' ),
51 filemtime( $this->functions->get_block_file_name( "$this->name.js" ) ),
52 true
53 );
54
55 $this->enqueue_block_style();
56 wp_set_script_translations( $this->get_block_name(), 'hostinger-reach', HOSTINGER_REACH_PLUGIN_DIR . 'languages' );
57
58 $this->autoloader();
59 }
60
61 public function enqueue_block_style(): void {
62 if ( $this->functions->block_file_exists( "$this->name.css" ) === false ) {
63 return;
64 }
65
66 wp_enqueue_style(
67 $this->get_block_name(),
68 $this->functions->get_blocks_url() . "$this->name.css",
69 array(),
70 filemtime( $this->functions->get_block_file_name( "$this->name.css" ) )
71 );
72 }
73
74 public function enqueue_block_script(): void {
75 if ( $this->functions->block_file_exists( "$this->name-view.js" ) === false ) {
76 return;
77 }
78
79 $handler = $this->get_block_name() . '-view';
80
81 wp_enqueue_script(
82 $handler,
83 $this->functions->get_blocks_url() . "$this->name-view.js",
84 array(),
85 filemtime( $this->functions->get_block_file_name( "$this->name-view.js" ) ),
86 true
87 );
88
89 wp_localize_script(
90 $handler,
91 "hostinger_reach_{$this->name}_block_data",
92 $this->data()
93 );
94 }
95
96 abstract public function autoloader(): void;
97 abstract public function data(): array;
98 abstract public function render( array $attributes ): bool|string;
99 }
100