export_csv(); return; } $redirect_map = [ 'cleannetic-bookings' => 'cleannetic#/bookings', 'cleannetic-services' => 'cleannetic#/services', 'cleannetic-categories' => 'cleannetic#/categories', 'cleannetic-customers' => 'cleannetic#/customers', 'cleannetic-staff' => 'cleannetic#/staff', 'cleannetic-cleanproof' => 'cleannetic#/cleanproof', 'cleannetic-settings' => 'cleannetic#/settings', 'cleannetic-pro' => 'cleannetic#/pro', 'cleannetic-wizard' => 'cleannetic#/setup', ]; if ( isset( $redirect_map[ $page ] ) ) { // phpcs:disable WordPress.Security.NonceVerification.Recommended -- Read-only redirect from legacy admin query params. $target = $redirect_map[ $page ]; if ( 'cleannetic-bookings' === $page && ! empty( $_GET['action'] ) ) { $target .= '?action=' . sanitize_text_field( wp_unslash( $_GET['action'] ) ); } if ( ! empty( $_GET['s'] ) ) { $target .= ( strpos( $target, '?' ) !== false ? '&' : '?' ) . 'search=' . rawurlencode( sanitize_text_field( wp_unslash( $_GET['s'] ) ) ); } if ( 'cleannetic-settings' === $page && ! empty( $_GET['tab'] ) ) { $target .= '?tab=' . sanitize_key( wp_unslash( $_GET['tab'] ) ); } // phpcs:enable WordPress.Security.NonceVerification.Recommended wp_safe_redirect( admin_url( 'admin.php?page=' . $target ) ); exit; } } public function register_menus(): void { $icon_url = CLEANNETIC_URL . 'assets/images/cleannetic-icon-64.png'; // Top level menu: Cleannetic add_menu_page( __( 'Cleannetic', 'cleannetic' ), __( 'Cleannetic', 'cleannetic' ), 'manage_options', 'cleannetic', [ $this, 'render_admin_app' ], $icon_url, 26 ); $cleanproof_label = Plugin::is_pro() ? __( 'CleanProof™', 'cleannetic' ) : __( 'CleanProof™ 🔒', 'cleannetic' ); $submenus = [ [ 'cleannetic', 'cleannetic', __( 'Dashboard', 'cleannetic' ), 'manage_options' ], [ 'cleannetic', 'cleannetic#/bookings', __( 'Bookings', 'cleannetic' ), 'manage_options' ], [ 'cleannetic', 'cleannetic#/services', __( 'Services', 'cleannetic' ), 'manage_options' ], [ 'cleannetic', 'cleannetic#/categories', __( 'Categories', 'cleannetic' ), 'manage_options' ], [ 'cleannetic', 'cleannetic#/customers', __( 'Customers', 'cleannetic' ), 'manage_options' ], [ 'cleannetic', 'cleannetic#/staff', __( 'Staff & Crew', 'cleannetic' ), 'manage_options' ], [ 'cleannetic', 'cleannetic#/cleanproof', $cleanproof_label, 'manage_options' ], [ 'cleannetic', 'cleannetic#/settings', __( 'Settings', 'cleannetic' ), 'manage_options' ], ]; foreach ( $submenus as $sm ) { add_submenu_page( $sm[0], $sm[2], $sm[2], $sm[3], $sm[1], [ $this, 'render_admin_app' ] ); } // Upgrade to Pro. if ( ! Plugin::is_pro() ) { add_submenu_page( 'cleannetic', __( 'Upgrade to Pro', 'cleannetic' ), '★ ' . __( 'Upgrade to Pro', 'cleannetic' ) . '', 'manage_options', 'cleannetic#/pro', [ $this, 'render_admin_app' ] ); } } public function render_admin_app(): void { add_filter( 'admin_footer_text', '__return_empty_string', 99 ); add_filter( 'update_footer', '__return_empty_string', 99 ); include CLEANNETIC_DIR . 'templates/admin-app.php'; } private function export_csv(): void { // phpcs:disable WordPress.Security.NonceVerification.Recommended -- Verified in maybe_redirect_legacy_pages(). $booking_repo = new BookingRepository(); $bookings_data = $booking_repo->query( [ 'status' => sanitize_key( wp_unslash( $_GET['status'] ?? '' ) ), 'search' => sanitize_text_field( wp_unslash( $_GET['search'] ?? '' ) ), 'date_from' => Settings::sanitize_dates( [ sanitize_text_field( wp_unslash( $_GET['date_from'] ?? '' ) ) ] )[0] ?? '', 'date_to' => Settings::sanitize_dates( [ sanitize_text_field( wp_unslash( $_GET['date_to'] ?? '' ) ) ] )[0] ?? '', 'per_page' => 5000, ] ); $bookings = $bookings_data['items']; // phpcs:enable WordPress.Security.NonceVerification.Recommended header( 'Content-Type: text/csv; charset=UTF-8' ); header( 'Content-Disposition: attachment; filename="cleannetic-bookings-' . gmdate( 'Y-m-d' ) . '.csv"' ); header( 'Pragma: no-cache' ); header( 'Expires: 0' ); $output = fopen( 'php://output', 'w' ); fputcsv( $output, [ 'Ref #', 'Status', 'Date', 'Time', 'Duration (mins)', 'Service', 'Customer Name', 'Customer Email', 'Customer Phone', 'Address', 'Total Amount', 'Payment Status', 'Payment Method', 'Notes' ] ); foreach ( $bookings as $b ) { $row = [ $b['booking_ref'], BookingStatus::label( $b['status'] ), Formatter::date( $b['start_datetime'] ), Formatter::time( $b['start_datetime'] ), $b['duration_minutes'], $b['service_name'], $b['customer_name'], $b['customer_email'], $b['customer_phone'], implode( ', ', array_filter( [ $b['address_data']['street'] ?? '', $b['address_data']['city'] ?? '', $b['address_data']['zip'] ?? '' ] ) ), $b['total_amount'], BookingStatus::payment_label( $b['payment_status'] ), $b['payment_method'], $b['notes'] ?? '', ]; // Neutralise spreadsheet formulas in customer-supplied text (CSV injection). $row = array_map( static fn( $cell ) => is_string( $cell ) && preg_match( '/^[=+\-@\t\r]/', $cell ) ? "'" . $cell : $cell, $row ); fputcsv( $output, $row ); } fclose( $output ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_fclose -- Closing php://output stream. exit; } }