PluginProbe
Booking Calendar / 11.6.1
Booking Calendar v11.6.1
11.8.4 11.8.3 11.8.2 11.8.1 11.8 11.7 11.6.1 11.6 11.5 11.4.3 11.4.2 11.4.1 11.4 11.3 11.2.1 11.2 11.1 11.0 10.15.7 10.15.6 10.1.3 10.10 10.10.1 10.10.2 10.11 All 204 releases
booking / includes / page-appointment-services / ajax / appointment_services__delete.php

appointment_services__delete.php in Booking Calendar 11.6.1, at includes/page-appointment-services/ajax/appointment_services__delete.php

71 lines 2.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Reviewed permanent-deletion endpoints for Appointment Services.
4 *
5 * @package Booking Calendar
6 * @since 11.6.0
7 */
8
9 if ( ! defined( 'ABSPATH' ) ) {
10 exit;
11 }
12
13 /**
14 * Return a signed, non-mutating deletion preview for selected Services.
15 *
16 * @return void Terminates with JSON.
17 */
18 function wpbc_appointment_services_ajax_delete_preview() {
19 wpbc_appointment_services_ajax_authorize();
20 $service_ids = wpbc_appointment_services_catalog_decode_json_field( 'ids' );
21 if ( is_wp_error( $service_ids ) ) {
22 wpbc_appointment_services_send_catalog_edit_error( $service_ids );
23 }
24
25 $result = ( new WPBC_Appointment_Services_Catalog_Deleter() )->preview( $service_ids );
26 if ( is_wp_error( $result ) ) {
27 wpbc_appointment_services_send_catalog_edit_error( $result );
28 }
29
30 wp_send_json_success( $result );
31 }
32 add_action( 'wp_ajax_WPBC_AJX_APPOINTMENT_SERVICES_DELETE_PREVIEW', 'wpbc_appointment_services_ajax_delete_preview' );
33
34 /**
35 * Apply one acknowledged, signed Service deletion after revalidation.
36 *
37 * @return void Terminates with JSON.
38 */
39 function wpbc_appointment_services_ajax_delete_apply() {
40 wpbc_appointment_services_ajax_authorize();
41 // phpcs:ignore WordPress.Security.NonceVerification.Missing -- The catalog nonce was verified above.
42 $acknowledged = isset( $_POST['acknowledged'] ) && '1' === sanitize_text_field( wp_unslash( $_POST['acknowledged'] ) );
43 if ( ! $acknowledged ) {
44 wpbc_appointment_services_send_catalog_edit_error(
45 new WP_Error(
46 'wpbc_service_delete_not_acknowledged',
47 __( 'Confirm that the selected Services will be permanently deleted before continuing.', 'booking' )
48 )
49 );
50 }
51
52 $plan = wpbc_appointment_services_catalog_decode_json_field( 'plan' );
53 if ( is_wp_error( $plan ) ) {
54 wpbc_appointment_services_send_catalog_edit_error( $plan );
55 }
56 // phpcs:ignore WordPress.Security.NonceVerification.Missing -- The catalog nonce was verified above.
57 $token = isset( $_POST['token'] ) && is_scalar( $_POST['token'] ) ? sanitize_text_field( wp_unslash( $_POST['token'] ) ) : '';
58 $result = ( new WPBC_Appointment_Services_Catalog_Deleter() )->apply( $plan, $token );
59 if ( is_wp_error( $result ) ) {
60 wpbc_appointment_services_send_catalog_edit_error( $result );
61 }
62
63 $result['message'] = sprintf(
64 /* translators: %s: Number of permanently deleted Services. */
65 _n( '%s Service permanently deleted.', '%s Services permanently deleted.', absint( $result['deleted_count'] ), 'booking' ),
66 number_format_i18n( absint( $result['deleted_count'] ) )
67 );
68 wp_send_json_success( $result );
69 }
70 add_action( 'wp_ajax_WPBC_AJX_APPOINTMENT_SERVICES_DELETE_APPLY', 'wpbc_appointment_services_ajax_delete_apply' );
71