File: /home/globfdxw/public_html/wp-content/plugins/wpforms-pdf/src/Builder/Ajax/Theme.php
<?php
namespace WPFormsPDF\Builder\Ajax;
/**
* Theme AJAX class.
*
* Handles AJAX requests for updating theme data.
*
* @since 1.0.0
*/
class Theme extends Base {
/**
* Register hooks.
*
* @since 1.0.0
*/
protected function hooks(): void {
add_action( 'wp_ajax_wpforms_pdf_update_theme_data', [ $this, 'update_theme_data' ] );
}
/**
* Update theme data.
*
* @since 1.0.0
*/
public function update_theme_data(): void {
// Verify the AJAX request.
$this->verify_ajax_request();
// Get and sanitize POST data.
$theme_data = $this->get_post_data( 'data', 'array' );
// Validate IDs.
if ( empty( $theme_data ) ) {
wp_send_json_error( esc_html__( 'Empty theme data.', 'wpforms-pdf' ) );
}
$is_delete = ! empty( $theme_data['delete'] );
if ( $is_delete ) {
// Delete custom theme.
$result = wpforms_pdf()->themes->delete_custom_theme( $theme_data );
} else {
// Update custom theme data.
$result = wpforms_pdf()->themes->update_custom_theme( $theme_data );
}
// Check for errors.
if ( ! $result ) {
// Log the error.
wpforms_pdf()->helpers->log(
[
'message' => 'Can\'t update custom theme data.',
'theme_data' => $theme_data,
'operation' => $is_delete ? 'delete' : 'update',
],
'error'
);
wp_send_json_error();
}
// Send the response.
wp_send_json_success();
}
}