Lesson 40 (Implementation): Improving Auction Card Readability with Better Formatting


In the previous lesson, the auction card displayed all the required information, but the layout looked more like raw data than a professional marketplace listing. In this implementation, the auction card was refined to improve readability and give visitors a cleaner browsing experience.


What We Wanted to Improve

The original auction card displayed:

  • Prices without a currency symbol
  • Auction end date in raw database format (YYYY-MM-DD HH:MM:SS)
  • Labels and values that were difficult to scan quickly

The objective was to make the card resemble a professional online marketplace.


Step 1: Improve the Auction Details Layout

The auction details were converted into a definition list (<dl>), making the labels and values much easier to align.

Instead of using several independent paragraphs, the HTML now groups related information together.

Example:

<dl class="flipnzee-auction-meta">

    <dt>Start Price</dt>
    <dd>...</dd>

    <dt>Current Bid</dt>
    <dd>...</dd>

    <dt>Buy Now</dt>
    <dd>...</dd>

    <dt>Auction Ends</dt>
    <dd>...</dd>

</dl>

This produces a much cleaner appearance.


Step 2: Format Currency Values

Instead of printing plain numbers such as

111
333
0

the values are now formatted using WordPress’s localization function.

Example:

<?php echo esc_html( '$' . number_format_i18n( $auction['start_price'], 0 ) ); ?>

Similarly,

<?php echo esc_html( '$' . number_format_i18n( $auction['current_bid'], 0 ) ); ?>

and

<?php echo esc_html( '$' . number_format_i18n( $auction['buy_now_price'], 0 ) ); ?>

Now the auction card displays

$111
$0
$333

which immediately looks more professional.


Step 3: Display a Friendly Auction End Date

Previously, the auction end date appeared exactly as stored in the database.

Example:

2026-07-03 06:29:00

A visitor does not need to see the database timestamp.

Instead, the value is formatted before displaying it.

<?php
echo esc_html(
    date_i18n(
        'd M Y',
        strtotime( $auction['auction_end'] )
    )
);
?>

The visitor now sees

03 Jul 2026

which is much easier to read.


Step 4: Style the Definition List

CSS was added to create two neat columns.

Example:

.flipnzee-auction-meta {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 12px 20px;
}

.flipnzee-auction-meta dt {
    font-weight: 600;
}

.flipnzee-auction-meta dd {
    margin: 0;
    text-align: right;
}

This aligns every label with its corresponding value.


Step 5: Keep the Call-to-Action Prominent

The View Listing button remains at the bottom of the card, giving visitors a clear next step.

The wording is intentional.

Rather than taking users directly to the website being sold, the button takes them to the listing page where they can review:

  • Verified analytics
  • Traffic statistics
  • Pricing
  • Auction details
  • Future bidding functionality

This avoids any confusion about where the visitor is being directed.


Result

The auction card now provides a much cleaner presentation.

Before:

  • Raw prices
  • Raw timestamps
  • Basic formatting

After:

  • Dollar-formatted prices
  • Human-readable auction dates
  • Better aligned labels and values
  • Improved visual hierarchy
  • More professional marketplace appearance

What We Learned

Small formatting improvements can significantly enhance the perceived quality of a marketplace.

Visitors usually decide within a few seconds whether a listing looks trustworthy. Clear prices, readable dates, and a well-organized layout contribute to a better user experience and help build confidence in the platform.


Source Code

The primary changes were made in:

  • includes/class-shortcodes.php
  • assets/css/frontend.css

Download Source Code

Download the completed version after this lesson:


Next Lesson

In Lesson 41, we’ll begin integrating Flipnzee Analytics into the auction cards themselves, displaying key verified metrics such as Users, Sessions, and Google Impressions directly on the marketplace. This will highlight one of Flipnzee’s unique advantages: allowing buyers to evaluate website performance before even opening the full listing page.

Lesson 40: Building a Professional Auction Card Layout with CSS

In the previous lesson, we transformed our auction listings from plain database records into meaningful website listings by displaying the Listing title, featured image, placeholder image, and a direct link to the Listing page.

Although the auction now contains all the essential information, its appearance is still fairly basic. The next logical step is to improve the user interface so visitors can browse auctions more comfortably and the marketplace begins to resemble a modern website sales platform.

In this lesson, we’ll focus entirely on presentation by styling our auction cards with CSS while keeping the underlying PHP logic unchanged.


What You’ll Learn

By the end of this lesson, you’ll know how to:

  • Style plugin output using a dedicated CSS file.
  • Improve the appearance of auction cards.
  • Make featured images responsive.
  • Add spacing and padding for better readability.
  • Create modern card layouts using borders, shadows, and rounded corners.
  • Improve typography and button styling.
  • Build a responsive layout that works well on desktops, tablets, and mobile devices.

Why This Matters

At the moment, an auction looks something like this:

+--------------------------------------+
| Screenshot                           |
|                                      |
| Calnzee.com                          |
|                                      |
| Start Price: ₹111                    |
| Current Bid: ₹0                      |
| Buy Now: ₹333                        |
| Status: Active                       |
| Auction Ends: 03 Jul 2026            |
|                                      |
| View Listing                         |
+--------------------------------------+

While functional, this still resembles a collection of HTML elements rather than a professional marketplace.

After completing this lesson, the goal is to achieve something closer to:

+--------------------------------------------------+
|               Website Screenshot                 |
|                                                  |
| Calnzee.com                                      |
|--------------------------------------------------|
| Start Price .............. ₹111                 |
| Current Bid .............. ₹0                   |
| Buy Now .................. ₹333                 |
| Auction Ends ............. 03 Jul 2026          |
|                                                  |
|            [ View Listing ]                      |
+--------------------------------------------------+

The cleaner presentation improves readability and creates a much stronger first impression for potential buyers.


Concepts Covered

During this lesson we’ll explore:

  • CSS organization for WordPress plugins
  • Responsive images
  • Card-based layouts
  • Padding and margins
  • Borders and border radius
  • Box shadows
  • Typography improvements
  • Button styling
  • Responsive design fundamentals

Implementation Steps

We’ll implement the lesson gradually:

  1. Style the auction card container.
  2. Make featured images responsive.
  3. Improve spacing between elements.
  4. Style headings and auction details.
  5. Enhance the “View Listing” button.
  6. Remove unnecessary visual clutter.
  7. Improve alignment of auction information.
  8. Add responsive styling for smaller screens.
  9. Test the layout on different devices.

Files We’ll Modify

assets/css/frontend.css

Only minor HTML adjustments may be made if required.

No database changes are required.


Difficulty Level

Intermediate

This lesson focuses primarily on frontend development and demonstrates how separating presentation from business logic leads to cleaner, more maintainable plugins.


Best Practices

Throughout this lesson we’ll continue following WordPress development best practices:

  • Keep PHP focused on generating HTML.
  • Place all presentation rules inside CSS.
  • Use reusable CSS classes.
  • Avoid inline styles.
  • Design with responsiveness in mind.
  • Improve the user experience without changing plugin functionality.

What You’ll Gain

After completing this lesson, your auction listings will no longer look like simple collections of database fields. Instead, they’ll resemble professional marketplace cards that are visually appealing, easier to browse, and ready for future enhancements such as countdown timers, bidding buttons, analytics badges, and seller information.

This lesson also establishes the visual foundation for future integration between the Flipnzee Auctions plugin and the Flipnzee Analytics plugin, allowing auction cards to evolve into rich previews of each website while keeping the detailed analytics available on the corresponding Listing page.

In the implementation that follows, we’ll enhance the stylesheet step by step and transform our auction cards into a polished marketplace interface without altering the underlying auction logic.

Lesson 39: Display Website Titles and Featured Images in the Auction Shortcode

After successfully displaying active auctions on the frontend in Lesson 38, our auction listings are still very plain. Visitors only see the Listing ID and auction details, which isn’t how a professional marketplace should look.

In this lesson, we’ll connect each auction to its corresponding WordPress Listing post and display the website’s title and featured image. This is an important milestone because our auction page will begin to resemble a real website marketplace instead of a simple database report.


What You’ll Learn

By the end of this lesson, you’ll know how to:

  • Retrieve the Listing post associated with an auction.
  • Display the website title instead of the Listing ID.
  • Show the Listing’s featured image.
  • Handle missing images gracefully.
  • Improve the overall appearance of the auction listing.

Why This Matters

Currently, visitors see something like:

Listing #2222

Start Price: ₹333

Current Bid: ₹0

Buy Now: ₹4,444,444

A professional marketplace should instead display something like:

+-------------------------------------------+
| [Featured Image]                          |
|                                           |
| MyBusinessSite.com                        |
|                                           |
| Start Price: ₹333                         |
| Current Bid: ₹0                           |
| Buy Now: ₹4,444,444                       |
| Auction Ends: 25 Jul 2026                 |
+-------------------------------------------+

This makes the auction much easier to browse.


Concepts Covered

In this lesson we’ll learn about:

  • get_post()
  • get_the_title()
  • has_post_thumbnail()
  • get_the_post_thumbnail()
  • Escaping output
  • Building reusable HTML

Implementation Steps

We will implement the lesson step by step:

  1. Retrieve the Listing post using listing_id.
  2. Verify the Listing exists.
  3. Display the website title.
  4. Display the featured image.
  5. Keep auction information below the image.
  6. Add basic HTML structure.
  7. Test the shortcode.

Expected Output

Instead of this:

Listing #2222
Start Price: 333
Current Bid: 0

Visitors will see something like:

[ Website Screenshot ]

MyBusinessSite.com

Start Price: ₹333
Current Bid: ₹0
Buy Now: ₹4,444,444
Auction Ends: 25 Jul 2026

Files We’ll Modify

  • includes/class-shortcodes.php

No database changes are required in this lesson.


Difficulty Level

Intermediate

This lesson introduces interaction between custom database tables and native WordPress posts, a common pattern in WordPress plugin development.


What You’ll Gain

By completing this lesson, you’ll move beyond simply displaying raw auction data. Your shortcode will start presenting auctions as attractive website listings, laying the foundation for future enhancements such as bidding buttons, countdown timers, reserve price indicators, seller information, and responsive auction cards.

In the next implementation, we’ll enhance the frontend so each auction begins to look like a polished marketplace listing rather than a collection of database fields.

Implementing Lesson 38: Creating Your First Frontend Auction Shortcode in the Flipnzee Auctions Plugin

After completing the backend auction management features in previous lessons, it was time to make our auction data visible to website visitors. In this lesson, we created our first frontend shortcode that retrieves active auctions from the database and displays them on any WordPress page or post.

Although the first version is intentionally simple, it establishes the foundation for building a professional auction marketplace.


What We Built

At the end of this lesson, visitors can insert the following shortcode into any page or post:

[flipnzee_auctions]

When the page is viewed, the plugin automatically retrieves all active auctions and displays information such as:

  • Listing ID
  • Start Price
  • Current Bid
  • Buy Now Price
  • Auction Status
  • Auction End Time

Step 1: Create a Shortcodes Class

Instead of placing shortcode logic inside the main plugin file, we created a dedicated class.

File created:

includes/class-shortcodes.php

This keeps the plugin organized and makes future shortcode development much easier.


Step 2: Register the Shortcode

Inside the class constructor we registered our shortcode.

add_shortcode(
    'flipnzee_auctions',
    array( $this, 'auction_list_shortcode' )
);

Now WordPress knows which function to execute whenever it encounters:

[flipnzee_auctions]

Step 3: Load the Shortcodes Class

Next, we loaded the new class from the main plugin file.

require_once FLIPNZEE_AUCTION_PATH . 'includes/class-shortcodes.php';

Then initialized it.

new Flipnzee_Shortcodes();

Without these two steps, WordPress would never register the shortcode.


Step 4: Retrieve Active Auctions

Inside the shortcode callback, we called the Auction Manager.

$auctions = Flipnzee_Auction_Manager::get_active_auctions();

This keeps all database operations inside the Auction Manager instead of mixing SQL with presentation logic.

Keeping responsibilities separate makes the plugin much easier to maintain.


Step 5: Handle Empty Results

If no active auctions exist, the shortcode returns a friendly message.

if ( empty( $auctions ) ) {

    return '<p>No active auctions found.</p>';
}

This provides a much better user experience than displaying an empty page.


Step 6: Loop Through Auctions

The shortcode loops through every active auction.

Example:

foreach ( $auctions as $auction ) {

    // Display auction details.
}

For each auction we displayed several fields stored in the database.


Step 7: Display Auction Information

The first version displays:

  • Listing ID
  • Start Price
  • Current Bid
  • Buy Now Price
  • Status
  • Auction End Date

Although simple, it proves that our shortcode successfully retrieves data from the database.


Step 8: Test the Shortcode

We created a temporary WordPress post named:

testing

Inside the post we inserted:

[flipnzee_auctions]

Initially the page displayed:

No active auctions found.

This was expected because every auction in the database still had the status:

draft

Step 9: Activate an Auction

For testing purposes, we manually changed one auction in phpMyAdmin.

status

draft
↓

active

After refreshing the page, the shortcode immediately displayed the auction.

This confirmed that:

  • the shortcode was registered correctly,
  • the database query worked,
  • the Auction Manager returned the correct records,
  • and the frontend output functioned as expected.

Final Result

The completed shortcode successfully displayed information similar to:

Listing #2222

Start Price: 333.00

Current Bid: 0.00

Buy Now: 4444444.00

Status: Active

Auction Ends:
2026-07-25 16:35:00

This marks the first working frontend feature of the Flipnzee Auctions plugin.


Lessons Learned

During this implementation, several important WordPress concepts became clearer:

  • Create dedicated classes for related functionality.
  • Register shortcodes using add_shortcode().
  • Keep database queries inside manager classes.
  • Separate business logic from presentation.
  • Always handle empty results gracefully.
  • Test shortcodes with real database records.

Tips for Beginners

  • Always build the simplest working version before focusing on appearance.
  • Test with actual database records rather than assuming the code is wrong.
  • If a shortcode displays “No active auctions found,” first verify the database contains records with status = 'active'.
  • Keeping your code modular now will make future features much easier to add.

Download Source Code

Download the starting version of the plugin before the lesson:

Download the completed version after this lesson:


What’s Next?

Our shortcode works, but it still displays plain text. In the next lesson, we’ll start transforming this output into attractive auction cards by showing website titles, featured images, and better formatting so the frontend begins to resemble a real website marketplace.

Every professional marketplace starts with a simple data listing. By completing this lesson, you’ve built the foundation on which all future frontend auction features will be added.

Lesson 37: Automatically Run Auction Maintenance Using WordPress Cron

What You’ll Learn

In this lesson, you’ll replace the manual workflow with automatic background processing using WordPress’s built-in Cron system.

By the end of this lesson, your plugin will:

  • Register a custom scheduled event on plugin activation.
  • Schedule the event if it doesn’t already exist.
  • Execute auction maintenance automatically every few minutes (or hourly in production).
  • Activate scheduled auctions automatically.
  • Close expired auctions automatically.
  • Unschedule the event when the plugin is deactivated.

Topics Covered

  • Understanding WP-Cron
  • Registering scheduled events
  • Using wp_next_scheduled()
  • Using wp_schedule_event()
  • Creating custom cron hooks
  • Hooking your auction manager into the scheduler
  • Cleaning up scheduled events on plugin deactivation

Files We’ll Modify

flipnzee-auctions.php
includes/class-loader.php
includes/class-auction-manager.php

New Features

Instead of clicking:

Activate Scheduled Auctions

or

Close Expired Auctions

the plugin will quietly do this itself whenever WordPress Cron runs.

Administrators will simply create auctions and let the plugin manage their lifecycle automatically.


Expected Workflow

Auction Created
        │
        ▼
Status = Draft
        │
        ▼
Scheduled Start Time Arrives
        │
        ▼
WordPress Cron Runs
        │
        ▼
Status → Active
        │
        ▼
Auction End Time Arrives
        │
        ▼
WordPress Cron Runs Again
        │
        ▼
Status → Closed

This is the same architecture used by many production WordPress plugins that perform background maintenance.


Prerequisites

Before starting this lesson, ensure you have completed:

  • ✅ Lesson 35 – Activate Scheduled Auctions
  • ✅ Lesson 36 – Close Expired Auctions

Estimated Difficulty

⭐⭐⭐⭐☆ (Intermediate)

This lesson introduces WordPress Cron, one of the most useful APIs for background processing in plugin development.


What You’ll Build

By the end of Lesson 37, your plugin will automatically:

  • Activate scheduled auctions.
  • Close expired auctions.
  • Run without administrator intervention.
  • Prepare the project for future features such as automatic bid processing, email notifications, and auction reminders.

Implementation Lesson 37: Automating Auction Maintenance with WordPress Cron


Lesson 38: Display Live Auctions on the Frontend Using a WordPress Shortcode


So far, every feature we’ve built has been available only to WordPress administrators.

In a real auction marketplace, however, the most important audience is not the administrator—it’s the buyers.

Visitors need a simple way to browse active auctions directly from the website.

In this lesson, we’ll create our first frontend auction shortcode.


What You’ll Build

By the end of this lesson, you’ll have a shortcode like:

[flipnzee_auctions]

that displays all active auctions on any WordPress page.


What Visitors Will See

Each auction will display:

  • Listing ID
  • Starting Price
  • Current Bid
  • Buy Now Price
  • Auction Status
  • Auction End Date
  • View Auction button

Example:

---------------------------------------
Listing #105

Current Bid
₹52,000

Buy Now
₹75,000

Ends
12 Jul 2026

Status
Active

[ View Auction ]
---------------------------------------

Why Use a Shortcode?

Shortcodes are one of the simplest ways to expose plugin functionality on the frontend.

Advantages include:

  • Works with Gutenberg
  • Works with Classic Editor
  • Works with Genesis
  • Can be inserted anywhere
  • Easy to extend later

Our First Frontend Query

Instead of retrieving every auction, we’ll display only:

Status = Active

This keeps the marketplace clean and prevents visitors from seeing:

  • Draft auctions
  • Closed auctions

Architecture

Visitor
      │
      ▼
Shortcode
      │
      ▼
Auction Manager
      │
      ▼
Database
      │
      ▼
Active Auctions
      │
      ▼
HTML Output

Notice how we’re reusing our Auction Manager instead of writing SQL directly inside the shortcode.


Files We’ll Modify

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

(new file)

flipnzee-auctions.php

New Shortcode

We’ll register:

[flipnzee_auctions]

Later we’ll extend it with parameters like:

[flipnzee_auctions limit="12"]
Website Preview Unavailable
Live Auction

Trending

✔ Google Verified Analytics
👥 Monthly Users 62
📈 Monthly Sessions 87
🔍 Google Impressions 0
Start Price $100
Current Bid $0
Highest Bidder No bids yet
Buy Now $500
Auction Ends Loading...

Bid History

No bids have been placed yet.

Please to place a bid.

View Listing


Website Preview Unavailable
Live Auction

Trending

✔ Google Verified Analytics
👥 Monthly Users 62
📈 Monthly Sessions 87
🔍 Google Impressions 0
Start Price $100
Current Bid $0
Highest Bidder No bids yet
Buy Now $500
Auction Ends Loading...

Bid History

No bids have been placed yet.

Please to place a bid.

View Listing



Design Goals

Initially we’ll keep the layout simple.

Each auction will appear inside a clean card showing:

  • Listing ID
  • Prices
  • Status
  • End Date

Styling will be improved in future lessons.


Production Benefits

Adding a frontend shortcode is an important milestone because it transforms the plugin from an administrative tool into a real auction platform.

For the first time:

  • Administrators create auctions.
  • Visitors can discover them.
  • The auction system becomes visible on the public website.

What You’ll Learn

In this lesson you’ll learn how to:

  • Register WordPress shortcodes
  • Retrieve database records for the frontend
  • Generate HTML safely
  • Escape output correctly
  • Separate business logic from presentation
  • Prepare your plugin for bidding functionality

What’s Next?

In the next lesson, we’ll build the Single Auction View, where visitors can click View Auction to see detailed information, a live countdown timer, bid history, and eventually place bids.

This will be the foundation for the public-facing bidding experience and the future Escrow.com transaction workflow.

Implementation Lesson 37: Automating Auction Maintenance with WordPress Cron

In the previous two lessons, we added the ability to manually activate scheduled auctions and manually close expired auctions. Those features worked correctly, but they still required an administrator to click buttons from the dashboard.

In this implementation lesson, we’ll take the next logical step by allowing WordPress to perform these maintenance tasks automatically using WP-Cron.

By the end of this lesson, Flipnzee Auctions will periodically check auction schedules in the background without administrator intervention.


Starting Point

Before beginning this lesson, ensure you have completed:

  • Lesson 35 – Activate Scheduled Auctions
  • Lesson 36 – Close Expired Auctions


Why WP-Cron?

Unlike a traditional Linux cron job, WordPress includes its own scheduling system called WP-Cron.

Instead of relying on server-level scheduled tasks, WordPress executes scheduled events whenever someone visits the website.

Many popular plugins use WP-Cron for tasks such as:

  • Publishing scheduled posts
  • Sending email notifications
  • Clearing expired caches
  • Running maintenance jobs

We’ll use the same mechanism for auction management.


Step 1: Create a Central Maintenance Method

Inside:

includes/class-auction-manager.php

we created a new method:

public static function run_scheduled_maintenance() {

	self::activate_scheduled_auctions();

	self::close_expired_auctions();
}

Rather than scheduling multiple background events, we created one maintenance method responsible for the complete auction lifecycle.

This keeps the plugin architecture simple and easier to extend.


Step 2: Register a Custom Cron Hook

Inside:

flipnzee-auctions.php

we registered a custom WordPress action.

add_action(
	'flipnzee_auction_maintenance',
	array(
		'Flipnzee_Auction_Manager',
		'run_scheduled_maintenance',
	)
);

Whenever WordPress executes the custom hook, our maintenance method is called automatically.


Step 3: Schedule the Event During Plugin Activation

Next, we modified the plugin activation routine.

function flipnzee_auction_activate() {

	Flipnzee_Database::create_tables();

	if ( ! wp_next_scheduled( 'flipnzee_auction_maintenance' ) ) {

		wp_schedule_event(
			time(),
			'hourly',
			'flipnzee_auction_maintenance'
		);
	}
}

The plugin now schedules a recurring hourly event when activated.

Using wp_next_scheduled() prevents duplicate scheduled events from being created if the plugin is activated multiple times.


Step 4: Remove the Scheduled Event on Deactivation

Good WordPress plugins clean up after themselves.

We therefore added a deactivation routine.

function flipnzee_auction_deactivate() {

	$timestamp = wp_next_scheduled(
		'flipnzee_auction_maintenance'
	);

	if ( $timestamp ) {

		wp_unschedule_event(
			$timestamp,
			'flipnzee_auction_maintenance'
		);
	}
}

This ensures WordPress no longer runs auction maintenance after the plugin has been deactivated.


Step 5: Register Activation and Deactivation Hooks

Finally, we registered both hooks.

register_activation_hook(
	__FILE__,
	'flipnzee_auction_activate'
);

register_deactivation_hook(
	__FILE__,
	'flipnzee_auction_deactivate'
);

WordPress now automatically schedules the maintenance event during activation and removes it during deactivation.


Plugin Architecture

Our maintenance workflow now looks like this:

Plugin Activated
        │
        ▼
Schedule Hourly Event
        │
        ▼
WordPress Cron
        │
        ▼
flipnzee_auction_maintenance
        │
        ▼
run_scheduled_maintenance()
        │
        ├───────────────┐
        ▼               ▼
Activate Auctions   Close Auctions

Using a single maintenance method keeps the code organized and simplifies future enhancements.


Testing During Development

Although the plugin now supports automatic scheduling, we intentionally kept the two dashboard buttons:

  • Activate Scheduled Auctions
  • Close Expired Auctions

These manual tools remain extremely valuable because they allow developers to test the maintenance logic immediately without waiting for the next scheduled Cron execution.

Keeping manual maintenance actions available is a practical approach during development and troubleshooting.


Debugging Along the Way

During implementation, we temporarily inserted debugging statements such as:

wp_die();

and displayed the number of rows updated by SQL queries.

These temporary diagnostics helped confirm:

  • Dashboard buttons were submitting correctly.
  • Nonce verification was successful.
  • Maintenance methods were being executed.
  • SQL queries were running as expected.
  • WordPress time handling influenced scheduling behaviour.

Once testing was complete, all debugging statements were removed to ensure Cron jobs could run silently in the background.


Lessons Learned

This implementation introduced several important WordPress development concepts:

  • Creating custom Cron hooks
  • Scheduling recurring events
  • Preventing duplicate scheduled events
  • Cleaning up scheduled tasks during plugin deactivation
  • Organizing background processes into a single maintenance method
  • Using temporary debugging techniques while developing background tasks

These concepts are widely used in production-quality WordPress plugins.


Final Result

At the end of this lesson, Flipnzee Auctions is capable of:

  • Scheduling recurring background maintenance
  • Automatically activating scheduled auctions
  • Automatically closing expired auctions
  • Cleaning up scheduled events during plugin deactivation

This marks a significant milestone in the project’s evolution from an administrative CRUD plugin to an intelligent, self-managing auction platform.


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 38, we’ll begin implementing the frontend auction experience, allowing visitors to view live auctions, auction details, countdown timers, and bidding information directly from the website. This will shift the focus from administrator tools to the public-facing auction marketplace.

Lesson 36: Automatically Close Expired Auctions in the Flipnzee Auctions Plugin

In the previous lesson, we implemented the ability to manually activate auctions whose scheduled start time had arrived. That completed the first half of the auction lifecycle.

Now it’s time to implement the second half.

When an auction reaches its scheduled end time, it should no longer accept bids. Instead, it should automatically move from Active to Closed.

In this lesson, we’ll build the first version of that functionality using a manual administrator action. Later, we’ll automate the entire process using WP-Cron.


What You Will Learn

By the end of this lesson, you will know how to:

  • Create a function to close expired auctions.
  • Update multiple auctions using a single SQL query.
  • Add a “Close Expired Auctions” button to the dashboard.
  • Secure administrator actions using WordPress nonces.
  • Display success messages after processing.
  • Prepare your plugin for automatic auction management.

Why Closing Auctions Matters

Every auction platform needs a clearly defined lifecycle.

Draft
   │
   ▼
Active
   │
Auction End Reached
   ▼
Closed

Once an auction is closed:

  • No more bids should be accepted.
  • The winner can be determined.
  • Escrow payment can begin.
  • Ownership transfer can be initiated.

Without a closing mechanism, auctions would remain active indefinitely.


What We Will Build

We’ll implement a new manager function:

Flipnzee_Auction_Manager::close_expired_auctions();

This function will:

  • Find auctions where:
    • Status = Active
    • Auction End has passed
  • Update their status to:
closed

Dashboard Improvements

The Flipnzee Auctions dashboard will receive another administrator tool.

Activate Scheduled Auctions

Close Expired Auctions

This allows administrators to manually manage the auction lifecycle during development.


Security

Like previous admin actions, this feature will include:

  • Capability checks
  • WordPress nonces
  • Safe redirects
  • Administrator-only access

Following WordPress security best practices keeps the plugin production-ready.


Why Manual Closing First?

Eventually, this process should happen automatically.

However, implementing manual closing first offers several advantages:

  • Easier debugging
  • Faster testing
  • Immediate verification
  • No dependency on scheduled cron events

This incremental approach reduces complexity while ensuring each component works correctly.


Database Changes

No database changes are required.

We already have everything needed:

  • Auction Status
  • Auction End
  • Current WordPress time

We’ll simply update qualifying rows.


Expected Workflow

Administrator clicks

Close Expired Auctions
        │
        ▼
Plugin checks all auctions
        │
        ▼
Auction End <= Current Time?
        │
      Yes
        │
        ▼
Status changes:
Active → Closed

Production Benefits

By completing this lesson, the plugin will support nearly the entire auction lifecycle:

  • ✅ Draft auctions
  • ✅ Scheduled auctions
  • ✅ Active auctions
  • ✅ Closed auctions

This is another major milestone toward transforming Flipnzee Auctions into a production-grade marketplace plugin.

Implementation Lesson 36: Automatically Close Expired Auctions in Flipnzee Auctions


What Comes Next?

In the next lesson, we’ll improve the administrator experience by adding auction statistics to the dashboard, including:

  • Total Auctions
  • Draft Auctions
  • Active Auctions
  • Closed Auctions
  • Scheduled Auctions

These live statistics will give administrators an instant overview of marketplace activity and prepare the dashboard for future analytics and reporting.

Implementation Lesson 36: Automatically Close Expired Auctions in Flipnzee Auctions

In the previous lesson, we added the ability to manually activate scheduled auctions. In this lesson, we build another important piece of auction lifecycle management by implementing the ability to automatically close auctions once their end time has passed.

Although the feature is currently triggered manually from the dashboard for testing purposes, the underlying logic is exactly the same as what will later be executed automatically by WordPress Cron.


What We Will Build

At the end of this lesson, the plugin will be able to:

  • Detect auctions whose end time has already passed.
  • Change their status from Active to Closed.
  • Execute the update using a single SQL query.
  • Allow administrators to manually trigger the check from the Dashboard.
  • Protect the action using WordPress nonces.

Starting Point

Download the plugin completed in the previous lesson.

↓ Download Plugin (After Lesson 35)


Step 1: Create the Auction Closing Method

Open:

includes/class-auction-manager.php

Add a new static method.

public static function close_expired_auctions() {

	global $wpdb;

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

	$current_time = current_time( 'mysql' );

	$wpdb->query(
		$wpdb->prepare(
			"UPDATE {$table}
			SET status = %s
			WHERE status = %s
			AND auction_end IS NOT NULL
			AND auction_end <= %s",
			'closed',
			'active',
			$current_time
		)
	);
}

Instead of loading every auction into PHP, this query updates every expired auction directly inside MySQL, making it fast even for large numbers of auctions.


Step 2: Add a Dashboard Button

Open:

admin/class-admin.php

Inside the dashboard form, add another submit button.

submit_button(
	'Close Expired Auctions',
	'secondary',
	'flipnzee_close_now',
	false
);

The dashboard now contains two management tools:

  • Activate Scheduled Auctions
  • Close Expired Auctions

Step 3: Process the Button Submission

Still inside the dashboard page, add another POST handler.

if ( isset( $_POST['flipnzee_close_now'] ) ) {

	check_admin_referer(
		'flipnzee_activate_now',
		'flipnzee_activate_nonce'
	);

	Flipnzee_Auction_Manager::close_expired_auctions();

	?>

	<div class="notice notice-success is-dismissible">
		<p>Expired auctions checked successfully.</p>
	</div>

	<?php
}

When the administrator clicks the button, the plugin securely executes the closing routine.


Step 4: Protect the Form

The dashboard form already contained a nonce from the previous lesson.

wp_nonce_field(
	'flipnzee_activate_now',
	'flipnzee_activate_nonce'
);

Since both dashboard buttons belong to the same form, the same nonce can safely protect both actions.


Step 5: Test the Feature

Create an auction that:

  • has status Active
  • has an auction end time in the past

Click:

Close Expired Auctions

The auction should immediately change its status to:

closed

Debugging During Development

During implementation, we temporarily added debugging statements such as:

wp_die();

and

Rows updated: X

These simple debugging techniques helped verify several important points:

  • the dashboard button was submitting correctly
  • nonce verification succeeded
  • the function was being executed
  • the SQL query was running
  • the number of updated rows matched expectations

After confirming everything worked, the temporary debugging code was removed from the final implementation.


Why Use a Single SQL UPDATE?

Instead of writing code like this:

foreach ($auctions as $auction) {

    if (...) {

        update_database();

    }

}

we execute one SQL statement.

Advantages include:

  • Faster execution
  • Less PHP memory usage
  • Fewer database operations
  • Better scalability

This is a common optimization technique in professional WordPress plugin development.


What We Learned

In this lesson we learned how to:

  • update multiple database records using SQL
  • automatically detect expired auctions
  • change auction status programmatically
  • execute administrative actions from the dashboard
  • secure form submissions using nonces
  • debug SQL updates using temporary diagnostic output

Final Result

The Flipnzee Auctions plugin can now manage both ends of an auction lifecycle:

  • Lesson 35: Activate scheduled auctions.
  • Lesson 36: Close expired auctions.

Together, these features lay the foundation for fully automated auction scheduling in future lessons using WordPress Cron.


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 37, we’ll begin moving these manual processes toward full automation by integrating them with WordPress’s scheduling system, reducing the need for administrators to manually trigger auction state changes.

Implementation Lesson 35: Manually Activate Scheduled Auctions in the Flipnzee Auctions Plugin

In the previous lesson, we added Auction Start and Auction End scheduling fields to our auctions. However, simply storing these dates in the database is not enough. The plugin also needs a mechanism to activate auctions when their scheduled start time arrives.

In this implementation lesson, we built the first version of that mechanism by adding a Manual Auction Activation feature.

Although the final version will eventually run automatically using WordPress Cron, implementing a manual activation tool first makes development, testing, and debugging much easier.


What We Built

By the end of this lesson, our plugin can:

  • Store scheduled auction start dates.
  • Compare scheduled start dates with the current WordPress time.
  • Activate eligible auctions.
  • Provide an administrator button to run the activation process manually.
  • Lay the foundation for future automation.

Step 1: Create the Activation Function

Inside class-auction-manager.php, we created a new method:

public static function activate_scheduled_auctions()

This method:

  • Retrieves the current WordPress time.
  • Searches for auctions whose:
    • status is draft
    • Auction Start has passed
  • Updates their status to:
active

Step 2: Use a Single SQL UPDATE Query

Instead of loading every auction into PHP, we used one efficient SQL query.

The query updates every matching auction in one operation.

Benefits include:

  • Better performance
  • Cleaner code
  • Easier maintenance
  • Scales well for hundreds or thousands of auctions

Step 3: Add a Dashboard Button

Inside the Flipnzee Auctions dashboard, we added a new button:

Activate Scheduled Auctions

Clicking this button executes the activation process immediately.

This allows us to verify our scheduling logic before introducing automatic background processing.


Step 4: Register a Secure Admin Action

We registered a custom admin action using:

admin_post_flipnzee_activate_scheduled_auctions

The handler performs several important tasks:

  • Capability check
  • Nonce verification
  • Calls the activation function
  • Redirects back to the dashboard

This follows standard WordPress security practices.


Step 5: Add Nonce Protection

Every activation request includes a WordPress nonce.

Before processing, the plugin verifies that the request originated from the WordPress administration area.

This prevents Cross-Site Request Forgery (CSRF) attacks.


Step 6: Test the Feature

Testing involved:

  • Creating multiple auctions
  • Assigning different Auction Start dates
  • Saving them
  • Clicking Activate Scheduled Auctions
  • Verifying database values using phpMyAdmin

This confirmed that our activation logic was executing correctly.


Debugging an Unexpected Issue

During testing, auctions were not changing from Draft to Active, even though their scheduled start times had already passed.

Instead of assuming the SQL query was incorrect, we debugged the process step by step.


Checking the Database

Using phpMyAdmin, we verified that:

  • Auction Start values were stored correctly.
  • Auction End values were stored correctly.
  • Auction status remained draft.

This confirmed that the data itself was not the problem.


Verifying the SQL Logic

Next, we reviewed the SQL UPDATE statement.

The query correctly selected auctions where:

  • status = draft
  • auction_start <= current WordPress time

No issues were found in the SQL itself.


Inspecting the Current WordPress Time

To isolate the issue, we temporarily added:

wp_die( current_time( 'mysql' ) );

This allowed us to display the exact time that WordPress was using during the activation process.

The output revealed that WordPress was using a different timezone than expected.


Root Cause

The activation logic depended on:

current_time( 'mysql' )

while the stored auction schedule had been entered using local time.

As a result:

  • Auction Start appeared to be in the future.
  • The SQL condition never matched.
  • No auctions were activated.

The activation function itself was working correctly.


Lessons Learned

This debugging session reinforced several important development principles.

Instead of immediately changing the SQL query, we:

  • Verified the stored database values.
  • Confirmed the SQL logic.
  • Checked the current application time.
  • Identified the real source of the problem.

This systematic approach saved considerable time and prevented unnecessary code changes.


Why We Built Manual Activation First

Eventually, auctions should activate automatically.

However, during development, a manual activation tool provides several advantages:

  • Easier debugging
  • Immediate testing
  • No dependency on WP-Cron
  • Faster development cycle

Once the activation logic has been thoroughly tested, replacing the manual button with automatic scheduling becomes straightforward.


What’s Next?

In the next lesson, we’ll complete the scheduling workflow by implementing Manual Auction Closing.

Auctions whose scheduled end time has passed will automatically transition from Active to Closed, laying another important foundation for a production-ready auction platform.


Download Source Code

Download the starting version before this lesson:

Download the completed version after implementing this lesson: