You are already logged in.
'; } ob_start(); ?> $log, 'user_password' => $pwd, 'remember' => true, ); $user = wp_signon($creds, false); if (is_wp_error($user)) { echo 'Login failed. Please check your credentials.
'; } else { wp_redirect(home_url('')); exit; } } return ob_get_clean(); } // Register form shortcode public function abp_appointment_register_form_shortcode() { if (is_user_logged_in()) { return 'You are already logged in.
'; } ob_start(); ?> $username, 'user_email' => $email, 'user_pass' => $password, 'display_name' => $full_name, ); $user_id = wp_insert_user($userdata); if (is_wp_error($user_id)) { echo 'Registration failed. Please try again.
'; } else { wp_set_current_user($user_id); wp_set_auth_cookie($user_id); wp_redirect(home_url('')); exit; } } return ob_get_clean(); } // Shortcode for Bookings page public function abp_bookings_page_shortcode() { // If form is submitted, verify nonce first if (isset($_POST['cancel_booking_id'])) { // Verify nonce in form handler if (!isset($_POST['book_appointment_nonce']) || !wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['book_appointment_nonce'])), 'book_appointment_action')) { wp_die('Invalid request.'); } if (is_user_logged_in()) { $current_user_id = get_current_user_id(); global $wpdb; $table_name = $wpdb->prefix . 'appointment_booking'; $booking_id = intval($_POST['cancel_booking_id']); $wpdb->update( $table_name, array('status' => 'Canceled'), array('id' => $booking_id, 'user_id' => $current_user_id) ); echo 'Your booking has been canceled.
Please login to view your bookings.
'; } $current_user_id = get_current_user_id(); global $wpdb; $table_name = $wpdb->prefix . 'appointment_booking'; $bookings = $wpdb->get_results($wpdb->prepare("SELECT * FROM {$wpdb->prefix}appointment_booking WHERE user_id = %d", $current_user_id)); ob_start(); if ($bookings) { echo '' . esc_html__('No bookings found.', 'text-domain') . '
'; } return ob_get_clean(); } //end function abp_book_appointment_form_shortcode() { ob_start(); // Fetch available services global $wpdb; $table_name = $wpdb->prefix . 'appointment_services'; $services = $wpdb->get_results("SELECT * FROM {$wpdb->prefix}appointment_services"); ?> get_var("SELECT COUNT(*) FROM {$wpdb->prefix}appointment_booking"); // Fetch approved appointments $approved_appointments = $wpdb->get_var($wpdb->prepare( " SELECT COUNT(*) FROM {$wpdb->prefix}appointment_booking WHERE status = %s", 'approved' )); // Fetch total customers $total_customers = $wpdb->get_var("SELECT COUNT(ID) FROM {$wpdb->users}"); // Fetch total services $total_services = $wpdb->get_var("SELECT COUNT(*) FROM {$wpdb->prefix}appointment_services"); echo '' . esc_html($total_appointments ? $total_appointments : 0) . '
' . esc_html($total_services ? $total_services : 0) . '
' . esc_html($approved_appointments ? $approved_appointments : 0) . '
' . esc_html($total_customers ? $total_customers : 0) . '
No appointments found or table missing.
'; return; } if (isset($_POST['update_appointment_status']) && isset($_POST['appointment_id']) && isset($_POST['appointment_status'])) { // Verify nonce if (!isset($_POST['appointment_nonce']) || !wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['appointment_nonce'])), 'update_appointment_status_nonce')) { die('Nonce verification failed.'); } $appointment_id = intval($_POST['appointment_id']); $new_status = sanitize_text_field(wp_unslash($_POST['appointment_status'])); $wpdb->update( $appointments_table, ['status' => $new_status], ['id' => $appointment_id], ['%s'], ['%d'] ); echo 'Appointment status updated.
Appointment deleted successfully.
No appointments found.
'; return; } ?>| ID | User | Service | Booking Date | Booking Time | Status | Actions |
|---|---|---|---|---|---|---|
| id); ?> | name); ?> | service_id); ?> | booking_date); ?> | booking_time); ?> |
| User ID | Username | Display Name | Total Appointments | |
|---|---|---|---|---|
| ' . esc_html($user->ID) . ' | ' . esc_html($user->user_login) . ' | ' . esc_html($user->user_email) . ' | ' . esc_html($user->display_name) . ' | ' . esc_html($user->total_appointments) . ' |
No customers found.
'; } } //end } new ABP_Admin(); ?>