Lesson 50: Prevent Last-Second Bid Sniping with an Auction Time Extension

One of the biggest frustrations in online auctions is bid sniping—when someone waits until the last few seconds to place a bid, leaving no time for other bidders to respond. Many professional auction platforms solve this by automatically extending the auction whenever a bid is placed near the end.

In this lesson, we’ll implement the same feature in the Flipnzee Auctions plugin.


What You Will Build

By the end of this lesson, your plugin will automatically extend an auction if a bid is placed during the final minute.

For example:

  • Auction ends at 10:00:00 AM
  • A bid is placed at 9:59:45 AM
  • The auction end time automatically changes to 10:05:00 AM

This gives other bidders a fair opportunity to respond.


Why This Feature Is Important

Without an extension mechanism:

  • Someone can win with a last-second bid.
  • Other bidders never get a chance to react.
  • Auctions feel unfair.

With an automatic extension:

  • Competition remains active.
  • Sellers often receive higher final prices.
  • Buyers perceive the auction as more transparent and fair.

How the Feature Will Work

Each time a bid is accepted, the plugin will:

  1. Read the current auction end time.
  2. Compare it with the current server time.
  3. Calculate the remaining time.
  4. If less than 60 seconds remain:
    • Extend the auction by 5 minutes.
  5. Save the new end time in the database.
  6. The countdown timer automatically updates on the frontend.

Logic Flow

Bid Received
      │
      ▼
Is Auction Ending Within 60 Seconds?
      │
 ┌────┴────┐
 │         │
No        Yes
 │         │
 ▼         ▼
Keep     Add 5 Minutes
Time     to auction_end
 │         │
 └────┬────┘
      ▼
Save Auction
      ▼
Update Countdown

Files We Will Modify

During this lesson we will work with:

includes/class-bid-manager.php

to update the auction end time after a successful bid.

We will also verify the countdown in:

assets/js/countdown.js

No changes should be needed there because it already reads the updated end time from the database.


What You Will Learn

In this lesson you will learn how to:

  • Work with PHP date and time functions.
  • Compare timestamps.
  • Update auction records automatically.
  • Modify existing database values.
  • Build anti-sniping protection similar to commercial auction platforms.

Expected Result

Before:

Auction Ends In

00m 40s

User places a bid.

After:

Auction Extended!

04m 59s

The countdown immediately reflects the new auction end time, giving all bidders additional time to compete.


Why This Makes Flipnzee Better

Adding automatic auction extensions moves Flipnzee Auctions closer to enterprise-grade auction platforms. It encourages fair competition, discourages last-second bid sniping, and can help sellers achieve better final prices through increased bidding activity.


Coming Up Next

In Lesson 51, we’ll build an Auction Winner System that automatically determines the winning bidder once the auction ends and records the auction result, paving the way for payment processing and order fulfillment.

Lesson 49 (Implementation): Display Professional Success and Error Messages After Bidding

In the previous lesson, the Flipnzee Auctions plugin redirected users back to the auction page after a bid was processed. While the functionality worked, users had no confirmation that their bid had been accepted or rejected.

In this implementation lesson, the plugin is enhanced to display clear success and error notifications using URL parameters, providing a much better user experience.


Objective

Implement professional notification messages that inform users whether:

  • Their bid was accepted.
  • Their bid was rejected.

Instead of silently refreshing the page, users now receive immediate feedback.


Step 1: Redirect With Status Parameter

The bid handler already redirects back to the auction page.

Instead of simply redirecting:

wp_safe_redirect( get_permalink( $listing_id ) );
exit;

it was updated to include a status parameter.

Successful bid:

wp_safe_redirect(
    add_query_arg(
        'bid',
        'success',
        get_permalink( $listing_id )
    )
);

exit;

Failed bid:

wp_safe_redirect(
    add_query_arg(
        'bid',
        'failed',
        get_permalink( $listing_id )
    )
);

exit;

This produces URLs like:

https://flipnzee.com/testing/?bid=success

or

https://flipnzee.com/testing/?bid=failed

Step 2: Detect the Status Parameter

Inside includes/class-shortcodes.php, just before displaying the auction details table, a check was added.

<?php

if ( isset( $_GET['bid'] ) ) {

    $status = sanitize_text_field(
        wp_unslash( $_GET['bid'] )
    );

    if ( 'success' === $status ) {
        ?>

        <div class="flipnzee-notice flipnzee-success">
            ✅ Your bid has been placed successfully.
        </div>

        <?php

    } elseif ( 'failed' === $status ) {
        ?>

        <div class="flipnzee-notice flipnzee-error">
            ❌ Your bid could not be accepted.
        </div>

        <?php
    }
}
?>

The plugin now safely reads the URL parameter and displays the appropriate message.


Step 3: Style the Notifications

The following CSS was added to assets/css/frontend.css.

.flipnzee-notice {

    padding: 15px;

    margin: 20px 0;

    border-radius: 6px;

    font-weight: 600;

}

.flipnzee-success {

    background: #ecfdf3;

    color: #046c4e;

    border-left: 5px solid #10b981;

}

.flipnzee-error {

    background: #fef2f2;

    color: #b91c1c;

    border-left: 5px solid #ef4444;

}

These styles make notifications stand out while remaining consistent with modern WordPress admin and frontend design.


Step 4: Test the Feature

Two scenarios were tested.

Successful Bid

After placing a valid bid, the user is redirected to:

?bid=success

and sees:

✅ Your bid has been placed successfully.

Failed Bid

If the bid is rejected, the user is redirected to:

?bid=failed

and sees:

❌ Your bid could not be accepted.

Troubleshooting During Implementation

Several issues were encountered before the feature worked correctly.

1. Notification Did Not Appear

Initially, the URL contained:

?bid=success

but no message appeared.

The issue was that the notification block had been inserted inside a section of code that wasn’t executed at the correct point in the page lifecycle.

Moving the notification logic immediately before the auction details table resolved the problem.


2. PHP Syntax Error

A parse error occurred after moving code.

Using the PHP linter helped identify the exact line causing the issue.

php -l includes/class-shortcodes.php

This quickly revealed an unexpected token error, allowing it to be corrected before uploading the plugin.


3. HTML Structure

During implementation, the winning/outbid status message was accidentally placed inside a <tr> element.

This produced invalid HTML.

The message block was moved outside the table so that the auction metadata table remained structurally correct.


4. User Display Name

While testing, the highest bidder appeared simply as:

user

instead of the expected display name.

The SQL query was working correctly—the WordPress account’s Display Name was simply set to “user”. Updating the profile’s display name fixed the issue.


Final Result

The auction page now provides immediate visual feedback whenever a bid is processed.

Users no longer have to guess whether their action succeeded, making the bidding experience more intuitive and professional.

Download Source Code

Download the starting version of the plugin before the lesson:

Download the completed version after this lesson:


What We Learned

In this lesson, we learned how to:

  • Redirect users with URL parameters.
  • Read query string values safely using sanitize_text_field() and wp_unslash().
  • Display contextual success and error notices.
  • Style frontend notifications with CSS.
  • Validate PHP files using the built-in linter.
  • Keep HTML structure valid while inserting dynamic content.

Conclusion

Although the underlying bidding logic was already functional, adding user-facing notifications significantly improved the usability of the Flipnzee Auctions plugin. Small enhancements like clear feedback messages create a smoother and more professional user experience, reducing confusion and increasing user confidence during the bidding process.

Lesson 49: Display Professional Success and Error Messages After Bid Submission

In the previous lesson, we prevented users from bidding on their own highest bid using server-side validation. Although the validation worked correctly, users received no explanation when their bid was rejected.

In this lesson, we’ll build a simple notification system that displays clear success and error messages after every bid submission.

This greatly improves the user experience and makes our auction plugin feel much more professional.


Why User Feedback Matters

Imagine clicking Place Bid and nothing appears to happen.

Questions immediately arise:

  • Was my bid accepted?
  • Was there an error?
  • Should I click again?
  • Did the auction end?

Professional websites always inform users about the result of their actions.


The Solution

We’ll use a simple three-step approach:

  1. Detect whether the bid succeeded or failed.
  2. Redirect back to the auction page with a status parameter.
  3. Display a colored notification at the top of the auction.

Example User Experience

Successful Bid

✅ Your bid has been placed successfully.

Already Highest Bidder

❌ You are already the highest bidder.

Bid Too Low

❌ Your bid must be higher than the current bid.

Auction Closed

❌ This auction has already ended.

Login Required

❌ Please log in before placing a bid.

Step 1: Return Meaningful Error Codes

Our bid manager already returns:

return new WP_Error(
    'already_highest_bidder',
    __( 'You are already the highest bidder.', 'flipnzee-auctions' )
);

We’ll use these error codes to determine which message should be shown after the redirect.


Step 2: Redirect With a Status

Instead of silently redirecting back to the auction page, we’ll append a query parameter.

For example:

?bid=success

or

?bid=already_highest_bidder

or

?bid=too_low

These parameters tell the frontend exactly what happened.


Step 3: Read the Status

When the auction page loads, we’ll check:

$_GET['bid']

Depending on its value, we’ll display the appropriate notification.


Step 4: Style the Notification

Instead of plain text, we’ll create attractive notice boxes.

Examples:

Green success box

✅ Your bid has been placed successfully.

Red error box

❌ You are already the highest bidder.

Yellow warning box

⚠ Auction has ended.

Benefits

Implementing a notification system provides several advantages:

  • Better user experience
  • Immediate feedback after bidding
  • Fewer accidental duplicate submissions
  • Easier troubleshooting
  • More professional interface
  • Consistent behavior across all bid scenarios

Real-World Examples

Many popular platforms provide similar feedback after user actions.

For example:

  • eBay displays confirmation when a bid is accepted.
  • WooCommerce shows notices after adding items to the cart.
  • WordPress displays success and error notices after saving settings.

Users have come to expect this behavior, making it an essential feature for any interactive application.


What You’ll Learn Next

In Lesson 50, we’ll implement an Auction Winner system.

When an auction ends, the plugin will automatically determine the highest bidder and mark them as the winner. This lays the foundation for future features such as winner notifications, payment processing, and auction completion workflows.

Lesson 48 Implementation – Prevent Users from Bidding on Their Own Highest Bid

In the previous lesson, we discussed why an auction system should not allow the current highest bidder to keep increasing their own bid. In this implementation lesson, we’ll add server-side validation that prevents self-bidding.

By the end of this lesson, if the highest bidder attempts to place another bid, the bid will be rejected before it is saved to the database.


Step 1: Open the Bid Manager

Open the following file:

includes/class-bid-manager.php

Locate the place_bid() method:

public static function place_bid(
    $auction_id,
    $bidder_id,
    $bid_amount
) {

Step 2: Retrieve the Current Highest Bidder

Inside the function, locate the following code:

global $wpdb;

$bid_table = $wpdb->prefix . 'flipnzee_bids';

$auction_table = $wpdb->prefix . 'flipnzee_auctions';

Immediately after it, add:

$highest_bidder = self::get_highest_bidder(
    $auction_id
);

The beginning of the function now becomes:

global $wpdb;

$bid_table = $wpdb->prefix . 'flipnzee_bids';

$auction_table = $wpdb->prefix . 'flipnzee_auctions';

$highest_bidder = self::get_highest_bidder(
    $auction_id
);

This loads the user who currently owns the highest bid.


Step 3: Locate the Current Bid

Further down in the same function, locate the code that retrieves the current bid:

$current_bid = $wpdb->get_var(
    $wpdb->prepare(
        "SELECT current_bid
        FROM {$auction_table}
        WHERE id = %d",
        $auction_id
    )
);

Step 4: Prevent Self-Bidding

Immediately after the code above, add:

if (
    $highest_bidder &&
    (int) $highest_bidder->bidder_id === (int) $bidder_id
) {

    return new WP_Error(

        'already_highest_bidder',

        __(
            'You are already the highest bidder.',
            'flipnzee-auctions'
        )

    );

}

The complete section now becomes:

$current_bid = $wpdb->get_var(
    $wpdb->prepare(
        "SELECT current_bid
        FROM {$auction_table}
        WHERE id = %d",
        $auction_id
    )
);

if (
    $highest_bidder &&
    (int) $highest_bidder->bidder_id === (int) $bidder_id
) {

    return new WP_Error(

        'already_highest_bidder',

        __(
            'You are already the highest bidder.',
            'flipnzee-auctions'
        )

    );

}

Whenever the logged-in user is already leading the auction, the function stops immediately and returns a WP_Error.


Step 5: Upload the Updated Plugin

Create a fresh ZIP archive of the plugin:

zip -r flipnzee-auctions.zip flipnzee-auctions

Upload it through:

Plugins → Add New → Upload Plugin

Activate the updated version.


Step 6: Test the Feature

Log in as the user who currently has the highest bid.

Try placing another bid.

Expected Result

The bid is rejected.

No new row is inserted into the bids table.

The current bid remains unchanged.

Although no message is displayed yet, the backend validation is working correctly.


Complete Source Code

Retrieve the Highest Bidder

global $wpdb;

$bid_table = $wpdb->prefix . 'flipnzee_bids';

$auction_table = $wpdb->prefix . 'flipnzee_auctions';

$highest_bidder = self::get_highest_bidder(
    $auction_id
);

Prevent Self-Bidding

$current_bid = $wpdb->get_var(
    $wpdb->prepare(
        "SELECT current_bid
        FROM {$auction_table}
        WHERE id = %d",
        $auction_id
    )
);

if (
    $highest_bidder &&
    (int) $highest_bidder->bidder_id === (int) $bidder_id
) {

    return new WP_Error(

        'already_highest_bidder',

        __(
            'You are already the highest bidder.',
            'flipnzee-auctions'
        )

    );

}

What We Achieved

By implementing this lesson, we made the auction system smarter and fairer.

The plugin now:

  • Prevents users from bidding against themselves.
  • Stops unnecessary increases in the auction price.
  • Uses secure server-side validation that cannot be bypassed from the browser.
  • Returns a WP_Error when a self-bid is detected.
  • Ensures the current bid and bid history remain unchanged when the validation fails.

At this stage, the validation works correctly, although users do not yet receive a visible explanation when their bid is rejected.

Download Source Code

Download the starting version of the plugin before the lesson:

Download the completed version after this lesson:

What’s Next?

In Lesson 49, we’ll build a proper notification system to display friendly success and error messages after bid submission, including:

  • ✅ Bid placed successfully.
  • ❌ You are already the highest bidder.
  • ❌ Bid amount is too low.
  • ❌ Auction has ended.

This will complete the bidding workflow and provide users with clear, professional feedback after every action.

Lesson 48: Prevent Users from Bidding on Their Own Highest Bid

In the previous lesson, we showed users whether they are currently winning or have been outbid. However, there is still one issue with our auction system:

A user who is already the highest bidder can continue placing higher bids against themselves.

Real-world auction platforms like eBay don’t allow this because it serves no purpose. In this lesson, we’ll prevent users from bidding again if they already hold the highest bid.


Why Is This Important?

Imagine this scenario:

  • Rajeev bids $500
  • Rajeev is now the highest bidder
  • Rajeev accidentally bids $550
  • Nobody else has bid yet

The auction price increases without any competition.

Preventing this keeps auctions fair and avoids unnecessary price inflation.


The Solution

Before accepting a bid, we need to determine:

  1. Who is currently the highest bidder?
  2. Is the logged-in user the same person?
  3. If yes, reject the bid.

This validation belongs in the bid processing logic, not just the frontend.


Step 1: Retrieve the Highest Bidder

Inside the bid placement function, retrieve the current highest bidder.

$highest_bidder =
    self::get_highest_bidder(
        $auction_id
    );

Step 2: Compare User IDs

Check whether the logged-in user already owns the highest bid.

if (
    $highest_bidder &&
    (int) $highest_bidder->bidder_id === (int) $bidder_id
) {
    return new WP_Error(
        'already_highest_bidder',
        __( 'You are already the highest bidder.', 'flipnzee-auctions' )
    );
}

Step 3: Stop Processing

If this condition is true:

  • No new bid is inserted.
  • Current bid remains unchanged.
  • Bid history remains unchanged.

The function exits immediately.


Step 4: Display the Error

Instead of silently failing, redirect back to the auction page with an error message such as:

You are already the highest bidder.

This provides immediate feedback to the user.


Why Backend Validation Matters

Some developers disable the bid button on the frontend and think the problem is solved.

It isn’t.

A malicious user could still:

  • submit the form manually
  • use browser developer tools
  • send a POST request directly

That’s why validation must happen inside the PHP bid processing code.


Example Flow

Current Auction

BidderAmount
Rajeev$500

Rajeev clicks Place Bid again.

Server checks:

Current Highest Bidder = Rajeev

Current User = Rajeev

Match = TRUE

Result:

❌ Bid rejected.

Another user bids:

BidderAmount
Rajeev$500
Amit$550

Now Rajeev is allowed to bid again because he is no longer the highest bidder.


Benefits

Implementing this validation provides several advantages:

  • Prevents self-bidding
  • Makes auctions behave like professional auction websites
  • Prevents accidental price increases
  • Protects users from unnecessary mistakes
  • Keeps auction history meaningful
  • Enforces rules securely on the server

What You’ll Learn Next

In Lesson 49, we’ll improve the bidding experience further by displaying success and error notifications after a bid is submitted, so users receive clear feedback such as:

  • ✅ Bid placed successfully.
  • ❌ Bid is too low.
  • ❌ You are already the highest bidder.
  • ❌ Auction has ended.

This will make the auction workflow much more user-friendly and professional.

Lesson 47 Implementation – Display the Highest Bidder and Show Winning/Outbid Status

In the previous lesson, we created the method to retrieve the highest bidder from the database. In this implementation lesson, we integrate that functionality into the auction page so visitors can immediately see who is currently leading the auction.

Additionally, logged-in bidders receive a visual message telling them whether they are currently winning or have been outbid.

This makes the auction experience much more interactive and similar to professional auction platforms.


Step 1: Retrieve the Highest Bidder

Open:

includes/class-shortcodes.php

Locate the code where bids are loaded for the Bid History section.

It should look like this:

$bids = Flipnzee_Bid_Manager::get_bids(
    $auction['id']
);

Immediately after it, add:

$highest_bidder =
    Flipnzee_Bid_Manager::get_highest_bidder(
        $auction['id']
    );

The final code becomes:

$bids = Flipnzee_Bid_Manager::get_bids(
    $auction['id']
);

$highest_bidder =
    Flipnzee_Bid_Manager::get_highest_bidder(
        $auction['id']
    );

This retrieves the highest bid record from the database and stores it for use throughout the auction page.


Step 2: Display the Highest Bidder

Locate the auction details table.

Replace the existing Highest Bidder row with:

<tr>

    <th>Highest Bidder</th>

    <td>

        <?php

        if ( $highest_bidder ) {

            echo esc_html(
                $highest_bidder->display_name
            );

        } else {

            esc_html_e(
                'No bids yet',
                'flipnzee-auctions'
            );

        }

        ?>

    </td>

</tr>

Now the auction page displays the current leading bidder instead of the placeholder text.


Step 3: Show the Winning/Outbid Status

After the auction details table closes:

</table>

add:

<?php if ( is_user_logged_in() && $highest_bidder ) : ?>

    <?php if (
        get_current_user_id()
        === (int) $highest_bidder->bidder_id
    ) : ?>

        <div class="flipnzee-bid-status flipnzee-winning">
            🏆 You are currently the highest bidder.
        </div>

    <?php else : ?>

        <div class="flipnzee-bid-status flipnzee-outbid">
            ⚠️ You have been outbid.
        </div>

    <?php endif; ?>

<?php endif; ?>

Because this block is placed outside the table, it produces valid HTML and displays correctly.


Step 4: Add CSS Styling

Open:

assets/css/frontend.css

Add:

.flipnzee-bid-status {

    margin: 15px 0;

    padding: 12px 15px;

    border-radius: 6px;

    font-weight: 600;

}

.flipnzee-winning {

    background: #e9f8ef;

    color: #0b6b35;

    border-left: 4px solid #2ecc71;

}

.flipnzee-outbid {

    background: #fff3f3;

    color: #b30000;

    border-left: 4px solid #e74c3c;

}

This makes the notification visually stand out and improves the overall user experience.


Step 5: Test the Feature

Create two WordPress user accounts.

Log in as the first user and place a bid.

You should see:

🏆 You are currently the highest bidder.

Log in as the second user and place a higher bid.

Now:

  • User 2 sees:
🏆 You are currently the highest bidder.
  • User 1 sees:
⚠️ You have been outbid.

The Highest Bidder row also updates automatically after refreshing the page.


Complete Source Code

Loading the Highest Bidder

$bids = Flipnzee_Bid_Manager::get_bids(
    $auction['id']
);

$highest_bidder =
    Flipnzee_Bid_Manager::get_highest_bidder(
        $auction['id']
    );

Highest Bidder Row

<tr>

    <th>Highest Bidder</th>

    <td>

        <?php

        if ( $highest_bidder ) {

            echo esc_html(
                $highest_bidder->display_name
            );

        } else {

            esc_html_e(
                'No bids yet',
                'flipnzee-auctions'
            );

        }

        ?>

    </td>

</tr>

Winning / Outbid Message

<?php if ( is_user_logged_in() && $highest_bidder ) : ?>

    <?php if (
        get_current_user_id()
        === (int) $highest_bidder->bidder_id
    ) : ?>

        <div class="flipnzee-bid-status flipnzee-winning">
            🏆 You are currently the highest bidder.
        </div>

    <?php else : ?>

        <div class="flipnzee-bid-status flipnzee-outbid">
            ⚠️ You have been outbid.
        </div>

    <?php endif; ?>

<?php endif; ?>

CSS

.flipnzee-bid-status {

    margin: 15px 0;

    padding: 12px 15px;

    border-radius: 6px;

    font-weight: 600;

}

.flipnzee-winning {

    background: #e9f8ef;

    color: #0b6b35;

    border-left: 4px solid #2ecc71;

}

.flipnzee-outbid {

    background: #fff3f3;

    color: #b30000;

    border-left: 4px solid #e74c3c;

}

Download Source Code

Download the starting version of the plugin before the lesson:

Download the completed version after this lesson:


What We Achieved

By completing this implementation:

  • Displayed the current highest bidder on every auction.
  • Replaced the placeholder text with real bidder information from the database.
  • Added personalized Winning and Outbid notifications for logged-in users.
  • Styled the notifications for a more professional appearance.
  • Improved the auction experience by giving bidders immediate feedback on their current status.

With Lesson 47 complete, Flipnzee Auctions now provides real-time auction context that helps users quickly understand whether they are leading the auction or need to place a higher bid.

Lesson 47: Showing the Highest Bidder and Bid Status

Now that our auction system records bids, validates minimum bid increments, and displays bid history, it’s time to improve the user experience.

One of the first things bidders want to know after placing a bid is:

  • Am I currently winning?
  • Who is the highest bidder?
  • Has someone outbid me?

In this lesson, we’ll enhance Flipnzee Auctions by displaying the current highest bidder and showing personalized bid status messages.


Why Is This Important?

Imagine placing a bid and seeing only this:

Current Bid: $2,500

You have no idea whether:

  • you are winning,
  • someone else has already outbid you,
  • or you are still the highest bidder.

Professional auction platforms always provide this information.


What We’ll Build

After this lesson, the auction page will display something like:

Current Bid
$2,500

Highest Bidder
Rajeev B.

✔ You are currently the highest bidder.

Or, if another user submits a higher bid:

Current Bid
$2,700

Highest Bidder
John D.

⚠ You have been outbid.

Step 1: Identify the Highest Bid

Since our bids are already stored in the database, we’ll retrieve the latest highest bid for the auction.

Conceptually:

SELECT *
FROM wp_flipnzee_bids
WHERE auction_id = ?
ORDER BY bid_amount DESC
LIMIT 1;

Step 2: Retrieve the Bidder

Once the highest bid is known, we’ll obtain the bidder’s WordPress user information.

Example:

$user = get_userdata( $highest_bid->bidder_id );

This allows us to display:

  • Display Name
  • Username
  • Or an anonymized version

Step 3: Display the Highest Bidder

The auction details will gain a new row.

Example:

Current Bid      $2,500
Highest Bidder   Rajeev B.
Buy Now          $3,000

This immediately makes the auction more engaging.


Step 4: Detect the Logged-in User

If the visitor is logged in, we can compare:

Current User ID

vs

Highest Bidder ID

If they match:

✔ You are currently the highest bidder.

Otherwise:

⚠ You have been outbid.

Step 5: Improve Privacy

Some auction websites display full names.

Others show only initials.

For example:

Instead of:

Rajeev Bagra

display:

Rajeev B.

or

R*** B***

This balances transparency with user privacy.


Step 6: Handle Auctions Without Bids

When no bids exist, the page should gracefully display:

Highest Bidder

No bids yet.

instead of leaving the section blank.


Expected Result

Before:

Current Bid
$2,500

Bid History
...

After:

Current Bid
$2,500

Highest Bidder
Rajeev B.

✔ You are currently the highest bidder.

Bid History
...

What We’ll Learn

In this lesson you’ll learn how to:

  • Query the highest bid from the database.
  • Retrieve WordPress user information.
  • Compare bidder IDs.
  • Display personalized auction messages.
  • Improve auction transparency.
  • Handle edge cases where no bids exist.

Why This Matters

Displaying the highest bidder transforms the auction from a simple list of numbers into a live, competitive experience. Visitors immediately understand who is leading, and bidders receive instant feedback about whether they are winning or have been outbid.

These small usability improvements make the plugin feel much closer to a production-ready auction platform.


Assignment

Before moving to Lesson 48, try to:

  • Display the current highest bidder.
  • Show “You are currently the highest bidder” when appropriate.
  • Show “You have been outbid” when another user places a higher bid.
  • Display “No bids yet” when an auction has received no bids.

In the next lesson, we’ll build on this by introducing automatic auction closing, so auctions can end on schedule and no longer accept bids after their closing time.

Implementing Lesson 46: Enforcing a Minimum Bid Increment in Flipnzee Auctions

In the previous lesson, we discussed why every professional auction system should require a minimum increase over the current highest bid. In this implementation lesson, we’ll modify the Flipnzee Auctions plugin so that users cannot place insignificant bids and always know the minimum amount required.

By the end of this implementation, the plugin will:

  • Reject bids that are too low.
  • Display the minimum allowed bid.
  • Guide users with browser-side validation.
  • Improve the overall auction experience.

Step 1: Define the Minimum Increment

Open:

includes/class-bid-manager.php

Locate the section where the current highest bid is retrieved.

Immediately afterwards, add:

/*
 * Minimum bid increment.
 */
$minimum_increment = 10;

$minimum_allowed_bid =
    (float) $current_bid +
    $minimum_increment;

This calculates the lowest amount that can be accepted.

For example:

Current Bid:      $444
Minimum Increment $10
Minimum Bid:      $454

Step 2: Validate Incoming Bids

Find the existing validation:

if ( $bid_amount <= (float) $current_bid ) {
    return false;
}

Replace it with:

/*
 * Validate minimum bid.
 */
if ( $bid_amount < $minimum_allowed_bid ) {
    return false;
}

Now every new bid must be at least Current Bid + $10.

Examples:

Current BidSubmitted BidResult
$444$445❌ Rejected
$444$450❌ Rejected
$444$454✅ Accepted
$444$500✅ Accepted

Step 3: Display the Minimum Bid

Open:

includes/class-shortcodes.php

Locate the auction details table.

Immediately below the Current Bid row, insert:

<tr>
    <th>Minimum Bid</th>
    <td>
        <?php
        $minimum_bid =
            (float) $auction['current_bid'] + 10;

        echo esc_html(
            '$' . number_format_i18n(
                $minimum_bid,
                0
            )
        );
        ?>
    </td>
</tr>

The auction information now becomes:

Start Price      $111
Current Bid      $444
Minimum Bid      $454
Buy Now          $333

Visitors immediately know the next valid bid amount.


Step 4: Restrict the Bid Input

Still in:

includes/class-shortcodes.php

Locate the bid input field.

Replace it with:

<?php
$minimum_bid =
    (float) $auction['current_bid'] + 10;
?>

<input
    type="number"
    step="10"
    min="<?php echo esc_attr( $minimum_bid ); ?>"
    value="<?php echo esc_attr( $minimum_bid ); ?>"
    name="bid_amount"
    placeholder="Your Bid"
    required
>

This provides three improvements:

  • min prevents smaller values from being submitted.
  • value pre-fills the next valid bid.
  • step increases or decreases by $10 using the spinner controls.

Testing the Feature

After refreshing the auction page, the auction details should resemble:

Current Bid      $999
Minimum Bid      $1009

Your Bid
[1009]

[ Place Bid ]

Testing results:

BidExpected
1000❌ Rejected
1005❌ Rejected
1009✅ Accepted
1019✅ Accepted

Browser Validation

Modern browsers also assist users before the form is submitted.

Attempting to enter a value below the minimum now displays a validation message similar to:

Value must be greater than or equal to 1009.

This improves usability by informing users immediately rather than after submission.


Files Modified

During this implementation, only two files required changes:

includes/class-bid-manager.php
includes/class-shortcodes.php

Keeping the modifications localized makes the feature easier to maintain and extend.


Result

After completing this implementation, Flipnzee Auctions now provides a more professional bidding experience by:

  • Enforcing a minimum bid increment on the server.
  • Displaying the minimum allowed bid to visitors.
  • Preventing invalid bids through browser validation.
  • Reducing unnecessary or insignificant bid increases.

These enhancements make the auction process clearer, fairer, and more intuitive for bidders.

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 continue improving the auction experience by adding more intelligent bidding features, making Flipnzee Auctions feel even closer to a production-ready auction platform.

Lesson 46: Enforcing a Minimum Bid Increment in Flipnzee Auctions

One of the easiest ways to improve an auction system is by preventing bidders from increasing the current price by tiny amounts. On professional auction platforms like eBay, each new bid must exceed the current bid by a minimum increment.

In this lesson, we’ll implement the same concept in our Flipnzee Auctions plugin by introducing a Minimum Bid Increment. This ensures every new bid is meaningful and keeps the auction moving smoothly.


Why Is a Minimum Bid Increment Important?

Imagine an auction with a current bid of $1,000.

Without validation, users could place bids like:

  • $1,000.01
  • $1,000.02
  • $1,000.03

Technically, each bid is higher, but they barely advance the auction. This can frustrate bidders and unnecessarily prolong the bidding process.

By requiring a minimum increment—for example, $10—the next valid bid would have to be at least $1,010.


What We’ll Build

At the end of this lesson, bidders will only be allowed to submit bids that satisfy:

New Bid >= Current Bid + Minimum Increment

For example:

Current BidMinimum IncrementMinimum Allowed Bid
$100$5$105
$250$25$275
$1,000$50$1,050

Step 1: Define a Minimum Increment

We’ll begin with a fixed increment.

$minimum_increment = 10;

Later, we’ll make this configurable from the WordPress admin.


Step 2: Calculate the Minimum Allowed Bid

Instead of checking only whether the bid is greater than the current bid, we’ll calculate the next valid amount.

Example:

$minimum_allowed_bid =
    $current_bid +
    $minimum_increment;

Step 3: Validate the Bid

The bidding logic will reject bids below the minimum requirement.

Conceptually:

if (
    $bid_amount <
    $minimum_allowed_bid
) {

    return false;

}

Step 4: Show a Helpful Error Message

Instead of silently rejecting the bid, inform the user why it failed.

Example:

Your bid must be at least $1,010.

Helpful validation messages create a much better user experience.


Step 5: Display the Minimum Bid

Near the bid input box, we’ll display information such as:

Minimum Bid:
$1,010

This tells visitors exactly what they need to bid.


Step 6: Prevent Invalid Form Submission

We’ll add HTML attributes so users cannot enter values below the minimum amount.

For example:

<input
type="number"
min="1010"
step="10">

This provides immediate feedback before the form is even submitted.


Expected Result

Instead of allowing any value above the current bid:

Current Bid:
$1,000

Your Bid:
1001 ❌

Place Bid

Visitors will see:

Current Bid:
$1,000

Minimum Bid:
$1,010

Your Bid:
1010 ✔

Place Bid

What We’ll Learn

In this lesson, you’ll learn how to:

  • Calculate dynamic minimum bid values
  • Validate bids on the server
  • Improve user experience with meaningful validation messages
  • Add client-side validation using HTML attributes
  • Prepare the plugin for configurable bidding rules

Why This Matters

Professional auction platforms don’t simply accept any higher bid—they enforce bidding rules that keep auctions fair, competitive, and easy to follow.

By adding a minimum bid increment, Flipnzee Auctions becomes significantly more professional and prevents users from placing trivial bid increases.


Assignment

Before moving to Lesson 47, try the following:

  • Set the minimum increment to $10.
  • Verify that bids below the required amount are rejected.
  • Confirm that valid bids are still accepted and saved.
  • Display the minimum required bid below the current bid so visitors always know the next valid amount.

In the next lesson, we’ll take this a step further by making the minimum bid increment configurable from the WordPress admin, allowing different auction strategies without changing any code.

Implementing Lesson 45: Displaying Bid History in Flipnzee Auctions

In Lesson 45, we transformed our auction system from simply displaying the current highest bid into a much more transparent platform by introducing Bid History.

Instead of showing only the latest bid amount, visitors can now see every bid placed on an auction, who placed it, and when it was submitted. This feature is common on professional auction platforms because it builds trust and encourages competitive bidding.

In this implementation post, we’ll walk through the complete code used to build the Bid History feature.


Step 1: Create a Method to Retrieve Bids

The first step is to retrieve all bids for a particular auction from the database.

Open:

includes/class-bid-manager.php

Add the following method inside the Flipnzee_Bid_Manager class.

/**
 * Get all bids for an auction.
 *
 * @param int $auction_id Auction ID.
 *
 * @return array
 */
public static function get_bids( $auction_id ) {

	global $wpdb;

	$bid_table = $wpdb->prefix . 'flipnzee_bids';

	return $wpdb->get_results(
		$wpdb->prepare(
			"SELECT *
			FROM {$bid_table}
			WHERE auction_id = %d
			ORDER BY bid_amount DESC,
			         created_at DESC",
			$auction_id
		)
	);

}

What this code does

  • Retrieves every bid for the selected auction
  • Uses prepared SQL statements for security
  • Orders bids from highest to lowest
  • Displays newer bids first if two bids have the same amount

Step 2: Retrieve Bid History Inside the Shortcode

Open:

includes/class-shortcodes.php

Locate the auction details table.

Immediately after the closing </table> tag, retrieve all bids.

<?php
$bids = Flipnzee_Bid_Manager::get_bids(
	$auction['id']
);
?>

This gives us all bids belonging to the currently displayed auction.


Step 3: Display the Bid History Heading

If bids exist, display a heading.

<h3>Bid History</h3>

Step 4: Handle Auctions With No Bids

Before creating the table, check whether any bids exist.

<?php if ( empty( $bids ) ) : ?>

<p>No bids have been placed yet.</p>

<?php else : ?>

This provides a better user experience than displaying an empty table.


Step 5: Create the Bid History Table

Now create the HTML table.

<table class="flipnzee-bid-history">

<thead>

<tr>

<th>Bidder</th>

<th>Amount</th>

<th>Time</th>

</tr>

</thead>

<tbody>

Step 6: Display Every Bid

Loop through all bids.

<?php foreach ( $bids as $bid ) : ?>

<?php
$user = get_userdata(
	$bid->bidder_id
);
?>

<tr>

<td>

<?php
echo esc_html(
	$user
	? $user->display_name
	: 'Unknown'
);
?>

</td>

<td>

<?php
echo '$' .
	number_format_i18n(
		$bid->bid_amount,
		2
	);
?>

</td>

<td>

<?php
echo esc_html(
	wp_date(
		'd M Y g:i A',
		strtotime(
			$bid->created_at
		)
	)
);
?>

</td>

</tr>

<?php endforeach; ?>

This code displays:

  • Bidder name
  • Bid amount
  • Bid date and time

Step 7: Close the Table

Finish the table.

</tbody>

</table>

<?php endif; ?>

Step 8: Improve the Table Appearance

Open:

assets/css/frontend.css

Add the following styles.

.flipnzee-bid-history{
	width:100%;
	border-collapse:collapse;
	margin:20px 0;
}

.flipnzee-bid-history th,
.flipnzee-bid-history td{
	padding:10px;
	border-bottom:1px solid #ddd;
	text-align:left;
	white-space:nowrap;
}

.flipnzee-bid-history th{
	background:#f5f5f5;
	font-weight:600;
}

This produces a cleaner and more professional table.


Final Result

After completing this lesson, each auction page now displays something like:

BidderAmountTime
Rajeev Bagra$66,666.0003 Jul 2026 12:09 PM
Rajeev Bagra$444.0003 Jul 2026 12:09 PM

Visitors can immediately understand:

  • Who is bidding
  • How the auction has progressed
  • When bids were placed
  • The current competition

Troubleshooting During Development

While implementing this feature, a few issues were encountered and resolved:

  • Initially, the page displayed “No bids have been placed yet.” even though bids existed in the database.
  • A temporary debug statement was added to display the current auction ID, confirming that the correct auction (Auction ID: 31) was being queried.
  • After verifying the auction ID and database records, the bid history displayed correctly.
  • The bid amount column initially wrapped because of the narrow card layout; this was improved using CSS with white-space: nowrap.
  • The raw database timestamp was replaced with a more readable format using wp_date().

These small debugging steps are a normal part of plugin development and highlight the importance of verifying data flow before assuming the query itself is incorrect.


What We Achieved

By the end of this implementation, Flipnzee Auctions gained another feature found in professional auction platforms:

  • ✅ Secure database retrieval of bid history
  • ✅ Display bidder names
  • ✅ Display bid amounts
  • ✅ Display bid timestamps
  • ✅ Graceful handling of auctions with no bids
  • ✅ Clean, responsive frontend table
  • ✅ Increased transparency and trust for bidders

Download Source Code

Download the starting version of the plugin before the lesson:

Download the completed version after this lesson:

In the next lesson, we’ll enhance the bidding engine further by introducing Minimum Bid Increment Validation, ensuring that every new bid must exceed the current highest bid by a configurable minimum amount.