| 1 |
<?php |
| 2 |
|
| 3 |
namespace RadiusTheme\SB\Controllers\Admin\Ajax; |
| 4 |
|
| 5 |
use RadiusTheme\SB\Helpers\BuilderFns; |
| 6 |
use RadiusTheme\SB\Helpers\Fns; |
| 7 |
use RadiusTheme\SB\Traits\SingletonTrait; |
| 8 |
|
| 9 |
// Do not allow directly accessing this file. |
| 10 |
if ( ! defined( 'ABSPATH' ) ) { |
| 11 |
exit( 'This script cannot be accessed directly.' ); |
| 12 |
} |
| 13 |
/** |
| 14 |
* Default Template Switch. |
| 15 |
*/ |
| 16 |
class DefaultTemplate { |
| 17 |
/** |
| 18 |
* Singleton Trait. |
| 19 |
*/ |
| 20 |
use SingletonTrait; |
| 21 |
/** |
| 22 |
* Construct function |
| 23 |
*/ |
| 24 |
private function __construct() { |
| 25 |
add_action( 'wp_ajax_rtsb_default_template', [ $this, 'response' ] ); |
| 26 |
} |
| 27 |
|
| 28 |
/** |
| 29 |
* Set Default Template. |
| 30 |
* |
| 31 |
* @return void |
| 32 |
*/ |
| 33 |
public function response() { |
| 34 |
if ( ! Fns::verify_nonce() ) { |
| 35 |
wp_send_json_error(); |
| 36 |
} |
| 37 |
$page_type = isset( $_POST['template_type'] ) ? sanitize_text_field( wp_unslash( $_POST['template_type'] ) ) : null; // phpcs:ignore WordPress.Security.NonceVerification.Missing |
| 38 |
$page_id = isset( $_POST['page_id'] ) && 'publish' == get_post_status ( $_POST['page_id']) ? absint( wp_unslash( $_POST['page_id'] ) ) : null; // phpcs:ignore WordPress.Security.NonceVerification.Missing |
| 39 |
$option_name = BuilderFns::option_name( $page_type ); |
| 40 |
update_option( $option_name, $page_id ); |
| 41 |
$return = [ |
| 42 |
'post_id' => $page_id, |
| 43 |
'page_type' => $page_type, |
| 44 |
]; |
| 45 |
wp_send_json_success( $return ); |
| 46 |
wp_die(); |
| 47 |
} |
| 48 |
|
| 49 |
} |
| 50 |
|