Autosave: 20260326-123134
This commit is contained in:
parent
39b39e2964
commit
6c0871c2d4
@ -5577,7 +5577,30 @@ function coaching_mvp_ssa_default_appointment_type_slug() {
|
||||
return '30-minute-meeting';
|
||||
}
|
||||
|
||||
function coaching_mvp_ssa_default_customer_information_fields() {
|
||||
return [
|
||||
[
|
||||
'field' => 'Name',
|
||||
'display' => true,
|
||||
'required' => true,
|
||||
'type' => 'single-text',
|
||||
'icon' => 'face',
|
||||
'values' => '',
|
||||
],
|
||||
[
|
||||
'field' => 'Email',
|
||||
'display' => true,
|
||||
'required' => true,
|
||||
'type' => 'single-text',
|
||||
'icon' => 'email',
|
||||
'values' => '',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
function coaching_mvp_ssa_default_appointment_type_data() {
|
||||
$customer_information_fields = coaching_mvp_ssa_default_customer_information_fields();
|
||||
|
||||
return [
|
||||
'author_id' => 1,
|
||||
'title' => '30-Minute Meeting',
|
||||
@ -5606,25 +5629,8 @@ function coaching_mvp_ssa_default_appointment_type_data() {
|
||||
'availability_increment' => 30,
|
||||
'timezone_style' => 'localized',
|
||||
'booking_layout' => 'week',
|
||||
'customer_information' => [],
|
||||
'custom_customer_information' => [
|
||||
[
|
||||
'field' => 'Name',
|
||||
'display' => true,
|
||||
'required' => true,
|
||||
'type' => 'single-text',
|
||||
'icon' => 'face',
|
||||
'values' => '',
|
||||
],
|
||||
[
|
||||
'field' => 'Email',
|
||||
'display' => true,
|
||||
'required' => true,
|
||||
'type' => 'single-text',
|
||||
'icon' => 'email',
|
||||
'values' => '',
|
||||
],
|
||||
],
|
||||
'customer_information' => $customer_information_fields,
|
||||
'custom_customer_information' => $customer_information_fields,
|
||||
'notifications' => [
|
||||
'fields' => [
|
||||
['field' => 'admin', 'send' => true],
|
||||
@ -5666,11 +5672,25 @@ function coaching_mvp_ensure_ssa_booking_setup() {
|
||||
}
|
||||
|
||||
$slug = coaching_mvp_ssa_default_appointment_type_slug();
|
||||
if (coaching_mvp_get_ssa_appointment_type_by_slug($slug)) {
|
||||
$appointment_type = coaching_mvp_get_ssa_appointment_type_by_slug($slug);
|
||||
$default_data = coaching_mvp_ssa_default_appointment_type_data();
|
||||
|
||||
if (empty($appointment_type)) {
|
||||
ssa()->appointment_type_model->insert($default_data);
|
||||
return;
|
||||
}
|
||||
|
||||
ssa()->appointment_type_model->insert(coaching_mvp_ssa_default_appointment_type_data());
|
||||
$existing_customer_information = $appointment_type['customer_information'] ?? [];
|
||||
$existing_custom_customer_information = $appointment_type['custom_customer_information'] ?? [];
|
||||
|
||||
if (!empty($existing_customer_information) && !empty($existing_custom_customer_information)) {
|
||||
return;
|
||||
}
|
||||
|
||||
ssa()->appointment_type_model->update((int) $appointment_type['id'], [
|
||||
'customer_information' => $default_data['customer_information'],
|
||||
'custom_customer_information' => $default_data['custom_customer_information'],
|
||||
]);
|
||||
}
|
||||
add_action('init', 'coaching_mvp_ensure_ssa_booking_setup', 45);
|
||||
|
||||
@ -5701,6 +5721,45 @@ function coaching_mvp_ssa_booking_shortcode() {
|
||||
}
|
||||
add_shortcode('coaching_ssa_booking', 'coaching_mvp_ssa_booking_shortcode');
|
||||
|
||||
function coaching_mvp_ssa_public_rest_permission($request) {
|
||||
if (current_user_can('ssa_manage_site_settings')) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!class_exists('TD_API_Model')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$headers = $request->get_headers();
|
||||
|
||||
if (!empty($headers['x_wp_nonce'][0]) && wp_verify_nonce($headers['x_wp_nonce'][0], 'wp_rest')) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!empty($headers['x_public_nonce'][0]) && TD_API_Model::verify_nonce($headers['x_public_nonce'][0], 'wp_rest')) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function coaching_mvp_patch_ssa_public_booking_permissions($endpoints) {
|
||||
if (empty($endpoints['/ssa/v1/appointments'])) {
|
||||
return $endpoints;
|
||||
}
|
||||
|
||||
foreach ($endpoints['/ssa/v1/appointments'] as $index => $handler) {
|
||||
$methods = $handler['methods'] ?? [];
|
||||
|
||||
if ($methods === WP_REST_Server::CREATABLE || (is_array($methods) && in_array('POST', $methods, true))) {
|
||||
$endpoints['/ssa/v1/appointments'][$index]['permission_callback'] = 'coaching_mvp_ssa_public_rest_permission';
|
||||
}
|
||||
}
|
||||
|
||||
return $endpoints;
|
||||
}
|
||||
add_filter('rest_endpoints', 'coaching_mvp_patch_ssa_public_booking_permissions', 20);
|
||||
|
||||
function coaching_mvp_booking_form_shortcode() {
|
||||
$status = isset($_GET['booking_status']) ? sanitize_key(wp_unslash($_GET['booking_status'])) : '';
|
||||
ob_start();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user