| 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_bBlocksPipeChecker', [$this, 'bBlocksPipeChecker'] ); |
| 8 |
add_action( 'wp_ajax_nopriv_bBlocksPipeChecker', [$this, 'bBlocksPipeChecker'] ); |
| 9 |
} |
| 10 |
|
| 11 |
function bBlocksUserRoles(){ |
| 12 |
$nonce = sanitize_text_field( wp_unslash( $_POST['_wpnonce'] ?? '' ) ); |
| 13 |
|
| 14 |
if( !wp_verify_nonce( $nonce, 'wp_ajax' )){ |
| 15 |
wp_send_json_error( 'Invalid Request' ); |
| 16 |
} |
| 17 |
|
| 18 |
if ( !current_user_can( 'edit_posts' ) ) { |
| 19 |
wp_send_json_error( 'Unauthorized' ); |
| 20 |
} |
| 21 |
|
| 22 |
global $wp_roles; |
| 23 |
wp_send_json_success( $wp_roles->get_names() ); |
| 24 |
} |
| 25 |
|
| 26 |
function bBlocksPipeChecker() |
| 27 |
{ |
| 28 |
$nonce = sanitize_text_field(wp_unslash($_POST['_wpnonce'] ?? null )); |
| 29 |
|
| 30 |
if (!wp_verify_nonce($nonce, 'wp_ajax')) { |
| 31 |
wp_send_json_error('Invalid Request'); |
| 32 |
} |
| 33 |
|
| 34 |
wp_send_json_success([ |
| 35 |
'isPipe' => Utils::isPro() |
| 36 |
]); |
| 37 |
} |
| 38 |
} |
| 39 |
|
| 40 |
new BBlocksAjax(); |