Travel Expense Report
Creates a form for travel expense reports with dynamic items and mileage allowances.
by Pascal Zimmermann · github.com/zpascal/wordpress-travel-expense-report-plugin
Install
No release zip yet. The repository archive installs, but the folder name will carry the branch suffix and updates will not flow:
wp plugin install https://github.com/zpascal/wordpress-travel-expense-report-plugin/archive/refs/heads/main.zipTravel Expense Report Plugin — Installation & Testing Guide
Overview
This is a WordPress plugin for handling travel expense report submissions. It includes:
- Dynamic form with receipt uploads
- PDF generation with receipts
- Email delivery to admin and optionally to the user
- Configurable settings within WordPress admin
- Unit tests (PHP 8.1 with PHPUnit 9.5+)
System Requirements
- WordPress: 5.0+
- PHP: 8.1+
- TCPDF: For PDF generation (included in vendor/)
- FPDI: PDF template support (included in vendor/)
Installation
1. Install as WordPress Plugin
-
Download or clone this repository into your WordPress
wp-content/plugins/directory:cd /path/to/wordpress/wp-content/plugins git clone <repository-url> dpsg-travel-expense-report -
Install PHP dependencies:
cd dpsg-travel-expense-report composer install -
Activate the plugin in WordPress admin:
- Go to Plugins → Find "Travel Expense Report" → Click Activate
2. Configuration
After activation, go to Settings → Reisekostenabrechnung (Travel Expense Report):
General Settings
- Internal Recipient Email: Email address that receives submitted reports
- Send a copy to the customer: Enable/disable sending a copy to the submitter
- Delete uploads after send: Remove uploaded files after email is sent
- Temp folder name: Name of the temporary folder under
get_temp_dir()(default:travel-expense-report) - Subject prefix: Optional prefix for email subjects
Email Templates
- Internal Subject & Message: For the admin notification email
- Customer Subject & Message: For the copy sent to the user
- Success/Failure Messages: Displayed to users on the frontend
Logging
- Log Prefix: Prefix for error_log lines for debugging
3. Usage
Add the shortcode to any page or post:
[travel_expense_report]
Users can then:
- Fill in personal details (name, IBAN, BIC, event)
- Add purchases/receipts (with file uploads)
- Add trips/mileage (with kilometer calculations)
- Add train tickets (with file uploads)
- Submit the form
- Receive confirmation (and optional copy email)
Testing
Setup
Install dev dependencies:
composer require --dev phpunit/phpunit:^9.5
Or use the included composer.json:
composer install
Run Tests
# Run all tests
composer test
# Run with verbose output
composer test:verbose
# Run specific test file
./vendor/bin/phpunit tests/HelpersTest.php
# Run specific test
./vendor/bin/phpunit tests/HelpersTest.php::HelpersTest::testTerReceiptBasenameFromValue_url_query_file
Test Coverage
To generate coverage report:
composer test:coverage
This creates an HTML report in the coverage/ directory.
File Structure
.
├── travel_expense_report.php # Main plugin file
├── assets/
│ ├── css/travel-expense-report.css
│ └── js/travel-expense-report.js
├── templates/
│ ├── travel-expense-report-form.php # Frontend form
│ └── travel-expense-report-email.php # Email template
├── vendor/ # Dependencies (TCPDF, FPDI)
├── tests/
│ ├── bootstrap.php # Test setup/WP stubs
│ └── HelpersTest.php # Unit tests
├── composer.json # PHP dependencies
├── phpunit.xml.dist # PHPUnit configuration
├── README-TESTS.md # Testing documentation
└── README.md # This file
Troubleshooting
Emails not sending
- Check WordPress mail configuration (SMTP plugin may be needed)
- Review error logs: Settings → Reisekostenabrechnung → "Cleanup log"
- Use the "Send test email" button in settings to test configuration
File upload issues
- Check temp folder permissions: Ensure
{get_temp_dir()}/travel-expense-report/is writable - Verify max upload size in PHP settings (
php.ini) - Check available disk space
PDF generation fails
- TCPDF requires GD library; verify it's enabled in PHP
- Check file permissions on temp directory
- Review WordPress debug log for specific errors
Features
✅ Dynamic form with add/remove rows ✅ File upload with secure temp storage ✅ Receipt preview (images and PDFs) ✅ Kilometer/mileage calculation ✅ PDF generation with receipt attachments ✅ Optional customer copy email ✅ Configurable email templates with placeholders ✅ Admin cleanup log for file deletion tracking ✅ Responsive mobile design ✅ Security: Path traversal prevention, nonce validation, XSS escaping
Security Notes
- All file uploads are stored in a plugin-scoped temp folder (not accessible via web)
- Files are served via a secure AJAX endpoint with nonce validation
- Email addresses are validated and sanitized
- Database is not used; state is minimal (settings only via WordPress options)
- All user input is escaped for HTML output
Support & Development
For issues, feature requests, or contributions:
- Review the code and test suite
- Add tests for new features in
tests/ - Follow WordPress coding standards
- Ensure all tests pass before submitting changes
License
This plugin is licensed under the GNU General Public License v2.0 or later (GPL-2.0-or-later).
Changelog
See individual commits in the repository for detailed changes.