| 1 |
<?php |
| 2 |
namespace BBlocks\Inc; |
| 3 |
|
| 4 |
class BBlocksAjax{ |
| 5 |
function __construct(){ |
| 6 |
add_action( 'wp_ajax_bBlocksUserRoles', [$this, 'bBlocksUserRoles'] ); |
| 7 |
add_action( 'wp_ajax_nopriv_bBlocksUserRoles', [$this, 'bBlocksUserRoles'] ); |
| 8 |
} |
| 9 |
|
| 10 |
function bBlocksUserRoles(){ |
| 11 |
$nonce = sanitize_text_field( wp_unslash( $_POST['_wpnonce'] ) ) ?? null; |
| 12 |
|
| 13 |
if( !wp_verify_nonce( $nonce, 'wp_ajax' )){ |
| 14 |
wp_send_json_error( 'Invalid Request' ); |
| 15 |
} |
| 16 |
|
| 17 |
global $wp_roles; |
| 18 |
wp_send_json_success( $wp_roles->get_names() ); |
| 19 |
} |
| 20 |
} |
| 21 |
|
| 22 |
new BBlocksAjax(); |