| 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 |
|