PluginProbe
SureDonation – Donation Forms, Fundraising Campaigns & Donor Management / 1.0.0
SureDonation – Donation Forms, Fundraising Campaigns & Donor Management v1.0.0
1.6.0 1.5.1 1.5.0 1.4.0 1.3.0 trunk 0.0.1 1.0.0 1.1.0 1.1.1 1.1.2 1.2.0
suredonation / inc / blocks / base.php

base.php in SureDonation – Donation Forms, Fundraising Campaigns & Donor Management 1.0.0, at inc/blocks/base.php

92 lines 1.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * The blocks base file.
4 *
5 * @package SureDonation
6 * @since 0.0.1
7 */
8
9 namespace SureDonation\Inc\Blocks;
10
11 use SureDonation\Inc\Helper;
12
13 if ( ! defined( 'ABSPATH' ) ) {
14 exit; // Exit if accessed directly.
15 }
16
17 /**
18 * Block base class.
19 *
20 * @since 0.0.1
21 */
22 abstract class Base {
23 /**
24 * Optional directory to .json block data files.
25 *
26 * @var string
27 * @since 0.0.1
28 */
29 protected $directory = '';
30
31 /**
32 * Register the block for dynamic output
33 *
34 * @return void
35 * @since 0.0.1
36 */
37 public function register() {
38 register_block_type(
39 $this->get_dir(),
40 apply_filters(
41 'suredonation_block_registration_args',
42 [ 'render_callback' => [ $this, 'render' ] ]
43 )
44 );
45 }
46
47 /**
48 * Get the called class directory path
49 *
50 * @return string
51 * @since 0.0.1
52 */
53 public function get_dir() {
54 if ( $this->directory ) {
55 return $this->directory;
56 }
57
58 $reflector = new \ReflectionClass( $this );
59 $fn = (string) $reflector->getFileName();
60 return dirname( $fn );
61 }
62
63 /**
64 * Render the block
65 *
66 * @param array<string, mixed> $attributes Block attributes.
67 * @param string $content Block content.
68 *
69 * @return string
70 * @since 0.0.1
71 */
72 public function render( $attributes, $content = '' ) {
73 unset( $content ); // Unused parameter in base class.
74 unset( $attributes ); // Unused parameter in base class.
75 return '';
76 }
77
78 /**
79 * Get allowed HTML tags for form markup.
80 *
81 * The wp_kses_post() doesn't allow form elements, so we need a custom allowed tags array.
82 * This is safe because the markup is generated internally by trusted code that already
83 * escapes user input with esc_attr(), esc_html(), etc.
84 *
85 * @return array<string, array<string, bool>> Allowed HTML tags and attributes.
86 * @since 0.0.1
87 */
88 protected static function get_allowed_form_html() {
89 return Helper::get_allowed_form_html();
90 }
91 }
92