prefix . 'abp_staff'; $services_table = $wpdb->prefix . 'appointment_services'; $staff_services = $wpdb->prefix . 'abp_staff_services'; // relationship table $wpdb->query("CREATE TABLE IF NOT EXISTS $staff_services ( id INT AUTO_INCREMENT PRIMARY KEY, staff_id INT NOT NULL, service_id INT NOT NULL, INDEX (staff_id), INDEX (service_id) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;"); function abp_get_all_services() { global $wpdb; return $wpdb->get_results("SELECT * FROM {$wpdb->prefix}appointment_services"); } function abp_get_services_for_staff($staff_id) { global $wpdb; return $wpdb->get_col($wpdb->prepare("SELECT service_id FROM {$wpdb->prefix}abp_staff_services WHERE staff_id = %d", $staff_id)); } if (isset($_POST['abp_add_staff']) || isset($_POST['abp_update_staff'])) { check_admin_referer('abp_add_staff_action', 'abp_add_staff_nonce'); $name = sanitize_text_field($_POST['staff_name']); $email = sanitize_email($_POST['staff_email']); $phone = sanitize_text_field($_POST['staff_phone']); $services = isset($_POST['staff_services']) ? array_map('intval', $_POST['staff_services']) : []; $staff_user = !empty($_POST['staff_user']) ? intval($_POST['staff_user']) : null; if (isset($_POST['staff_id']) && $_POST['staff_id']) { $staff_id = intval($_POST['staff_id']); $wpdb->update($staff_table, [ 'name' => $name, 'email' => $email, 'phone' => $phone, 'user_id' => $staff_user ], ['id' => $staff_id]); $wpdb->delete($staff_services, ['staff_id' => $staff_id]); foreach ($services as $service_id) { $wpdb->insert($staff_services, [ 'staff_id' => $staff_id, 'service_id' => $service_id ]); } echo '
Staff updated successfully.
Staff added successfully.
Staff deleted successfully.
| ID | Name | Phone | WP User | Services | Created | Action | |
|---|---|---|---|---|---|---|---|
| id); ?> | name); ?> | email); ?> | phone); ?> | created_at); ?> | Edit Delete |
No staff members found.