PluginProbe
Block Manager / 1.2.4
Block Manager v1.2.4
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.2.4, at api/export.php

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