| 1 |
<?php |
| 2 |
namespace PFB; |
| 3 |
|
| 4 |
if ( ! defined( 'ABSPATH' ) ) { |
| 5 |
exit; |
| 6 |
} |
| 7 |
|
| 8 |
class Ajax { |
| 9 |
|
| 10 |
function __construct() { |
| 11 |
add_action('wp_ajax_pfb_get_blocks', [ $this, 'pfb_get_blocks' ]); |
| 12 |
|
| 13 |
} |
| 14 |
public function pfb_get_blocks(){ |
| 15 |
$nonce = sanitize_text_field( wp_unslash( $_POST['_wpnonce'] ) ) ?? null; |
| 16 |
|
| 17 |
if( !wp_verify_nonce( $nonce, 'pfb_admin_nonce' )){ |
| 18 |
wp_send_json_error( 'Invalid Request' ); |
| 19 |
} |
| 20 |
|
| 21 |
$data = json_decode( stripslashes( $_POST['data'] ), true ); |
| 22 |
$db_data = get_option( 'pfb_disabled_blocks', [] ); |
| 23 |
|
| 24 |
if( !isset( $data ) && $db_data ){ |
| 25 |
wp_send_json_success( $db_data ); |
| 26 |
} |
| 27 |
|
| 28 |
update_option( 'pfb_disabled_blocks', $data ); |
| 29 |
wp_send_json_success( $data ); |
| 30 |
|
| 31 |
} |
| 32 |
|
| 33 |
} |
| 34 |
|