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