Lesson 44 Implementation: Building the First Working Bidding System
One of the biggest milestones in the Flipnzee Auctions project was transforming auctions from static listings into interactive auctions where visitors can actually place bids. In this lesson, the bidding engine was implemented from scratch, allowing authenticated users to compete for auction listings in real time.
What We Built
By the end of this lesson, the plugin supports:
- Creating a dedicated database table for bids
- Recording every bid placed by users
- Updating the current highest bid automatically
- Displaying a bid form on the frontend
- Validating that new bids are higher than the existing bid
- Persisting bid history in the database
This is the first version of a fully functional auction engine.
Step 1: Creating the Bid Database Table
A new database table named wp_flipnzee_bids was introduced.
The table stores:
- Auction ID
- Bidder ID
- Bid Amount
- Timestamp
Each bid is preserved permanently, creating a complete bidding history for every auction.
Unlike simply updating a single value, storing individual bids allows future features such as:
- Bid history
- Highest bidder tracking
- Auction analytics
- Winner determination
- Escrow integration
Step 2: Building the Bid Manager
A brand-new class called:
Flipnzee_Bid_Manager
was created.
This class became responsible for all bidding operations, including:
- Receiving new bids
- Checking the current highest bid
- Rejecting invalid bids
- Saving successful bids
- Updating the auction’s current bid
Separating bidding logic into its own class keeps the plugin modular and much easier to maintain.
Step 3: Saving Bids
When a visitor submits a bid:
- The auction is identified.
- The existing highest bid is retrieved.
- The new amount is compared against the current bid.
- Valid bids are inserted into the bids table.
- The auction record is updated with the new highest bid.
This ensures that the auction table always reflects the latest highest bid while preserving every historical bid.
Step 4: Adding the Frontend Bid Form
The auction card on the frontend was enhanced with a simple bidding interface.
Visitors who are logged in can now enter a bid amount and submit it directly from the auction listing.
If the visitor is not logged in, the interface instead prompts them to sign in before participating.
This provides a clean foundation for future enhancements without complicating the user experience.
Step 5: Processing Bid Requests
A new request handler was added to process submitted bids securely.
The handler performs several important tasks:
- Verifies the WordPress nonce
- Ensures the user is authenticated
- Sanitizes user input
- Calls the Bid Manager
- Redirects the visitor back to the auction page
Using WordPress admin-post actions keeps the implementation aligned with WordPress coding standards.
Step 6: Testing the Complete Workflow
The implementation was verified through several tests.
The following scenarios were successfully completed:
- Bid form displayed correctly
- Bid submitted successfully
- Bid stored in the database
- Current bid updated automatically
- Multiple bids recorded correctly
- Frontend reflected the new highest bid
Database verification confirmed that both the wp_flipnzee_bids and wp_flipnzee_auctions tables were updated correctly after each successful bid.
Challenges Encountered
Several implementation issues were encountered during development, including:
- Loading the new Bid Manager class correctly
- Registering new WordPress action hooks
- Resolving PHP syntax errors after adding new functionality
- Ensuring database tables were created properly
- Confirming that current bids updated after inserts
- Troubleshooting bid submission until the complete workflow functioned correctly
These debugging sessions reinforced an important lesson:
Building new features often involves more time spent integrating and testing than writing the original code.
Why This Matters
This lesson transformed the plugin from a simple auction display into a genuine auction platform.
Before this lesson, visitors could only view auction information.
After this lesson, they can actively participate by placing bids that are securely stored and reflected immediately as the current highest bid.
Many advanced features now become possible because this foundation exists.
Download Source Code
Download the starting version of the plugin before the lesson:
Download the completed version after this lesson:
What’s Next?
In the next lesson, we’ll improve the bidding experience by introducing features such as:
- Displaying bid history
- Validating minimum bid increments
- Preventing bids after auctions end
- Better user feedback after bid submission
- Additional auction rules and safeguards
These improvements will make the auction system more robust while preparing it for future features such as automatic winner selection and escrow integration.
Key Takeaways
- Separate functionality into dedicated manager classes.
- Store every bid instead of only the highest bid.
- Always validate user input before writing to the database.
- Use WordPress nonces and admin-post handlers for secure form processing.
- Test every database operation thoroughly to verify the entire workflow.
Lesson Outcome: By the end of Lesson 44, Flipnzee Auctions supports real bid placement with database persistence and automatic highest-bid tracking, laying the groundwork for a complete online auction platform.
