PluginProbe ʕ •ᴥ•ʔ
ShopPress – Shop Builder for Elementor and WooCommerce / trunk
ShopPress – Shop Builder for Elementor and WooCommerce vtrunk
shop-press / blocks / BlockAPI.php
shop-press / blocks Last commit date
build 1 week ago src 1 week ago BlockAPI.php 1 year ago FilterBlocks.php 4 months ago Integration.php 1 week ago RegisterBlocks.php 1 year ago editor.css 2 years ago editor.js 2 years ago
BlockAPI.php
83 lines
1 <?php
2 /**
3 * Block API.
4 *
5 * @package ShopPress
6 */
7
8 namespace ShopPress\BlockEditor;
9
10 defined( 'ABSPATH' ) || exit;
11
12 use ShopPress\Templates;
13
14 class BlockAPI {
15 /**
16 * Instance of this class.
17 *
18 * @since 1.4.0
19 */
20 public static $instance;
21
22 /**
23 * Provides access to a single instance of a module using the singleton pattern.
24 *
25 * @since 1.4.0
26 *
27 * @return object
28 */
29 public static function instance() {
30 if ( self::$instance === null ) {
31 self::$instance = new self();
32 }
33 return self::$instance;
34 }
35
36 /**
37 * Constructor.
38 *
39 * @since 1.4.0
40 */
41 public function __construct() {
42 add_action( 'rest_api_init', array( $this, 'register_routes' ) );
43 }
44
45 /**
46 * Register routes.
47 *
48 * @since 1.4.0
49 */
50 public function register_routes() {
51 register_rest_route(
52 'sp-block',
53 '/loop-templates',
54 array(
55 array(
56 'methods' => \WP_REST_Server::READABLE,
57 'callback' => array( $this, 'get_loop_templates' ),
58 'permission_callback' => '__return_true',
59 ),
60 )
61 );
62 }
63
64 /**
65 * Get loop templates.
66 *
67 * @since 1.4.0
68 *
69 * @param object $request
70 */
71 public function get_loop_templates( $request ) {
72 $nonce = $request->get_header( 'x_wp_nonce' );
73
74 if ( ! $nonce || ! wp_verify_nonce( $nonce, 'wp_rest' ) ) {
75 return;
76 }
77
78 $templates = Templates\Utils::get_loop_builder_templates();
79
80 return $templates;
81 }
82 }
83