| 1 |
<?php |
| 2 |
/** |
| 3 |
* API Route: Reset patterns API endpoint. |
| 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 = '/patterns_reset'; |
| 14 |
register_rest_route( |
| 15 |
$my_namespace, |
| 16 |
$my_endpoint, |
| 17 |
array( |
| 18 |
'methods' => 'POST', |
| 19 |
'callback' => 'block_manager_patterns_reset', |
| 20 |
'permission_callback' => function () { |
| 21 |
return Gutenberg_Block_Manager::has_access(); |
| 22 |
}, |
| 23 |
) |
| 24 |
); |
| 25 |
} |
| 26 |
); |
| 27 |
|
| 28 |
/** |
| 29 |
* Reset the block patterns. |
| 30 |
* @since 1.2.2 |
| 31 |
*/ |
| 32 |
function block_manager_patterns_reset() { |
| 33 |
if ( is_user_logged_in() && current_user_can( apply_filters( 'block_manager_user_role', 'activate_plugins' ) ) ) { |
| 34 |
error_reporting( E_ALL | E_STRICT ); // @codingStandardsIgnoreLine |
| 35 |
delete_option( BLOCK_MANAGER_PATTERNS ); |
| 36 |
wp_send_json( |
| 37 |
[ |
| 38 |
'success' => true, |
| 39 |
'msg' => __( 'All patterns reset successfully', 'block-manager' ), |
| 40 |
] |
| 41 |
); |
| 42 |
} |
| 43 |
} |
| 44 |
|