PluginProbe
Block Manager / 1.1
Block Manager v1.1
trunk 1.0 1.0.1 1.1 1.2 1.2.1 1.2.2 1.2.3c 1.2.4 1.2.5 2.0.0 2.1.0 2.1.0.1 2.1.1 3.0.0 3.1.0 3.1.1 3.1.2 3.2.0 3.2.1
block-manager / api / export.php

export.php in Block Manager 1.1, at api/export.php

52 lines 1.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Custom API route.
4 *
5 * @since 1.0
6 */
7 add_action( 'rest_api_init', function () {
8 $my_namespace = 'gbm';
9 $my_endpoint = '/export';
10 register_rest_route(
11 $my_namespace,
12 $my_endpoint,
13 array(
14 'methods' => 'GET',
15 'callback' => 'block_manager_export',
16 'permission_callback' => function () {
17 return Gutenberg_Block_Manager::has_access();
18 },
19 )
20 );
21 });
22
23 /**
24 * Export disabled blocks as an erray.
25 *
26 * @param $request $_POST
27 * @return $response json
28 * @since 1.0
29 */
30 function block_manager_export( WP_REST_Request $request ) {
31
32 if ( is_user_logged_in() && current_user_can( apply_filters( 'block_manager_user_role', 'activate_plugins' ) ) ) {
33
34 $blocks = Gutenberg_Block_Manager::gbm_get_disabled_blocks();
35
36 $response = array(
37 'success' => true,
38 'blocks' => json_encode( $blocks ),
39 );
40
41 wp_send_json( $response );
42
43 } else {
44 $response = array(
45 'success' => false,
46 'msg' => __( 'Unatuhorized.', 'block-manager' ),
47 );
48
49 wp_send_json( $response );
50 }
51 }
52