PluginProbe
Gutenberg Essential Blocks – Page Builder for Gutenberg Blocks & Patterns / 6.4.1
Gutenberg Essential Blocks – Page Builder for Gutenberg Blocks & Patterns v6.4.1
6.4.3 6.4.2 6.4.1 6.4.0 6.3.0 6.2.1 6.2.0 6.1.4 6.1.3 6.1.2 6.1.1 6.1.0 trunk 1.0.0 1.1.0 1.1.1 1.1.2 1.2.0 1.3.0 1.3.1 2.0.0 2.0.1 2.0.2 2.1.0 2.2.0 All 198 releases
essential-blocks / includes / API / Base.php

Base.php in Gutenberg Essential Blocks – Page Builder for Gutenberg Blocks & Patterns 6.4.1, at includes/API/Base.php

58 lines 1.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace EssentialBlocks\API;
4
5 use WP_REST_Server;
6 use EssentialBlocks\Traits\HasSingletone;
7
8 abstract class Base {
9 use HasSingletone;
10
11 /**
12 * Register REST Routes
13 *
14 * @return void
15 */
16 abstract function register();
17
18 public function register_endpoint( $endpoint, $args = [] ) {
19 register_rest_route( 'essential-blocks/v1', $endpoint, $args );
20 }
21
22 public function get( $endpoint, $args = [] ) {
23 $_args = wp_parse_args(
24 $args,
25 [
26 'methods' => WP_REST_Server::READABLE,
27 'permission_callback' => '__return_true'
28 ]
29 );
30
31 $this->register_endpoint( $endpoint, $_args );
32 }
33
34 public function post( $endpoint, $args = [] ) {
35 $_args = wp_parse_args(
36 $args,
37 [
38 'methods' => WP_REST_Server::CREATABLE,
39 'permission_callback' => [ $this, 'verify_post_permission' ]
40 ]
41 );
42
43 $this->register_endpoint( $endpoint, $_args );
44 }
45
46 /**
47 * Verify permission for POST requests
48 *
49 * @param WP_REST_Request $request
50 * @return bool
51 */
52 public function verify_post_permission( $request ) {
53 // For public endpoints, we can still allow access but with basic validation
54 // You can add nonce verification here if needed
55 return true;
56 }
57 }
58