| 1 |
<?php |
| 2 |
/** AJAX: duplicate an Appointment Service. @package Booking Calendar */ |
| 3 |
if ( ! defined( 'ABSPATH' ) ) { exit; } |
| 4 |
|
| 5 |
/** |
| 6 |
* Duplicate one Service through the configured data provider. |
| 7 |
* |
| 8 |
* @return void Terminates with a JSON success or error response. |
| 9 |
*/ |
| 10 |
function wpbc_appointment_services_ajax_duplicate() { |
| 11 |
wpbc_appointment_services_ajax_authorize(); $provider = wpbc_appointment_services_get_data_provider(); |
| 12 |
if ( ! is_object( $provider ) || ! method_exists( $provider, 'duplicate' ) ) { wpbc_appointment_services_send_provider_error( wpbc_appointment_services_storage_error(), __( 'Service storage is unavailable.', 'booking' ) ); } |
| 13 |
// phpcs:ignore WordPress.Security.NonceVerification.Missing |
| 14 |
$service_id = isset( $_POST['service_id'] ) ? absint( $_POST['service_id'] ) : 0; |
| 15 |
$result = $service_id ? $provider->duplicate( $service_id ) : new WP_Error( 'invalid_service_id', __( 'A valid Service ID is required.', 'booking' ) ); |
| 16 |
if ( is_wp_error( $result ) || empty( $result ) ) { wpbc_appointment_services_send_provider_error( $result, __( 'The Service could not be duplicated.', 'booking' ) ); } |
| 17 |
wp_send_json_success( array( 'service' => wpbc_appointment_services_normalize_item( $result ), 'message' => __( 'Service duplicated.', 'booking' ) ) ); |
| 18 |
} |
| 19 |
add_action( 'wp_ajax_WPBC_AJX_APPOINTMENT_SERVICE_DUPLICATE', 'wpbc_appointment_services_ajax_duplicate' ); |
| 20 |
|