Lesson 14: Completing Your First End-to-End WordPress Plugin Workflow

Introduction

In the previous lesson, we created a dedicated form handler using the WordPress Admin Post API. The form was successfully submitted, the nonce was verified, and WordPress redirected the administrator back to the Add Auction page.

However, no auction was actually created.

In this lesson, we’ll complete the workflow by validating the submitted data, calling the Auction Manager, inserting the auction into the database, and displaying a confirmation message.

This is the first time every layer of our plugin works together.


Learning Objectives

By the end of this lesson, you’ll be able to:

  • Sanitize submitted data.
  • Call the Auction Manager from the form handler.
  • Insert records into the database.
  • Redirect users with status messages.
  • Display confirmation notices.
  • Complete your first end-to-end plugin workflow.

Our Complete Workflow

Administrator

↓

Add Auction Form

↓

admin-post.php

↓

Nonce Verification

↓

Data Validation

↓

Auction Manager

↓

Database

↓

Redirect

↓

Success Message

Every component now has a clearly defined responsibility.


Step 1 – Process Submitted Data

Open:

admin/class-admin-posts.php

Replace the comment:

/*
 * Form processing will be added
 * in Lesson 14.
 */

with:

$listing_id = absint( $_POST['listing_id'] );

$start_price = (float) $_POST['start_price'];

$reserve_price = (float) $_POST['reserve_price'];

$buy_now_price = (float) $_POST['buy_now_price'];

Step 2 – Create the Auction

Immediately below the previous code, add:

$auction_id = Flipnzee_Auction_Manager::create_auction(
	$listing_id,
	$start_price,
	$reserve_price,
	$buy_now_price
);

The Form Handler doesn’t communicate directly with the database.

Instead, it delegates that responsibility to the Auction Manager.


Step 3 – Redirect with Status

Replace:

wp_safe_redirect(
	admin_url( 'admin.php?page=flipnzee-add-auction' )
);

with:

if ( $auction_id ) {

	wp_safe_redirect(
		admin_url(
			'admin.php?page=flipnzee-add-auction&message=success'
		)
	);

} else {

	wp_safe_redirect(
		admin_url(
			'admin.php?page=flipnzee-add-auction&message=error'
		)
	);

}

exit;

Step 4 – Display the Message

Open:

admin/class-admin.php

Inside add_auction_page(), immediately before:

<div class="wrap">

add:

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

	if ( 'success' === $_GET['message'] ) {

		echo '<div class="notice notice-success is-dismissible"><p>Auction created successfully.</p></div>';

	}

	if ( 'error' === $_GET['message'] ) {

		echo '<div class="notice notice-error is-dismissible"><p>Unable to create auction.</p></div>';

	}
}

Step 5 – Test the Plugin

Create a fresh ZIP.

Upload the plugin.

Open:

Flipnzee Auctions → Add Auction

Enter:

  • Listing ID: 1
  • Start Price: 100
  • Reserve Price: 150
  • Buy Now Price: 300

Click:

Create Auction

You should now see:

Auction created successfully.

Step 6 – Verify the Database

Open phpMyAdmin.

Browse:

wp_flipnzee_auctions

Instead of zero rows, you should now see your first auction record.

Return to the plugin dashboard.

The Total Auctions counter should now display:

1

Congratulations! Your plugin has completed its first full workflow.


Lesson Summary

In this lesson, we completed the first end-to-end workflow of Flipnzee Auctions.

Administrators can now submit auction information through the WordPress Dashboard. The request is securely processed, validated, passed to the Auction Manager, stored in the database, and confirmed with a success message.

This marks the point where the plugin becomes genuinely functional.


Key Takeaways

  • ✓ Separate form processing from page rendering.
  • ✓ Sanitize submitted data.
  • ✓ Let the Auction Manager handle database operations.
  • ✓ Redirect after processing.
  • ✓ Display administrator-friendly status messages.

Common Mistakes

  • Accessing $_POST without validation.
  • Writing SQL inside the form handler.
  • Forgetting to redirect after processing.
  • Displaying raw database errors to users.

Git Commands Used

git add .

git commit -m "Lesson 14: Complete first end-to-end workflow"

git push

Project Status

✅ Development environment

✅ Plugin skeleton

✅ Plugin installation

✅ Plugin lifecycle

✅ .gitignore

✅ Data architecture

✅ Database table

✅ Auction Manager

✅ Retrieve auction records

✅ WordPress admin menu

✅ Plugin dashboard

✅ Add Auction page

✅ Secure form architecture

✅ Admin Post handler

✅ First end-to-end workflow

⬜ Display all auctions

⬜ Edit auctions

⬜ Delete auctions

⬜ Bid engine

⬜ Escrow workflow

⬜ Version 1.0

Project Evolution

Earlier lessons focused on building the plugin’s foundation. This lesson connects those individual pieces into a complete workflow. The administrator no longer interacts directly with the database; instead, each layer performs a specific role, resulting in a cleaner and more maintainable architecture.

This same pattern will be reused for editing auctions, deleting auctions, managing bids, and handling Escrow.com transactions.


Developer’s Notebook

One of the best indicators of a well-designed application is the separation of responsibilities. In Flipnzee Auctions, the form collects information, the Form Handler processes requests, the Auction Manager performs business logic, and the Database class manages storage. Because these responsibilities are clearly separated, the plugin can continue to grow without becoming difficult to understand or maintain.


Looking Ahead

In Lesson 15, we’ll display all saved auctions inside the WordPress Dashboard using a professional table layout. Instead of checking phpMyAdmin, administrators will be able to browse, review, and eventually edit auction records directly from the plugin interface.

Lesson 15: Displaying All Auctions in the WordPress Dashboard

Introduction

In the previous lesson, we completed our first end-to-end workflow by allowing administrators to create auctions directly from the WordPress Dashboard.

Although the auction is successfully stored in the database, administrators still need phpMyAdmin to verify the record.

Professional plugins display data inside the WordPress Dashboard instead of requiring direct database access.

In this lesson, we’ll create our first Auction List page that retrieves every auction from the database and displays it in a clean WordPress table.


Learning Objectives

By the end of this lesson, you’ll be able to:

  • Create another WordPress admin page.
  • Display data retrieved from the database.
  • Loop through auction records.
  • Build an HTML table using WordPress admin styling.
  • Understand how data flows from the database to the user interface.

What We’ll Build

Our admin menu will now become:

Flipnzee Auctions
│
├── Dashboard
├── Add Auction
└── All Auctions

Instead of checking phpMyAdmin, administrators will browse auctions directly inside WordPress.


Why Create an Auction List?

Applications rarely interact directly with databases.

Instead:

Database

↓

Auction Manager

↓

Admin Page

↓

Administrator

The Auction Manager retrieves the data.

The Admin page displays it.

Each component performs one responsibility.


Step 1 – Add a New Submenu

Open:

admin/class-admin.php

Inside register_menu() add another submenu:

add_submenu_page(
	'flipnzee-auctions',
	'All Auctions',
	'All Auctions',
	'manage_options',
	'flipnzee-all-auctions',
	array( $this, 'all_auctions_page' )
);

Step 2 – Create the Page

Inside the class add:

public function all_auctions_page() {

	$auctions = Flipnzee_Auction_Manager::get_all_auctions();

	?>

	<div class="wrap">

		<h1>All Auctions</h1>

		<table class="widefat striped">

			<thead>

				<tr>

					<th>ID</th>
					<th>Listing</th>
					<th>Start Price</th>
					<th>Reserve</th>
					<th>Buy Now</th>
					<th>Status</th>

				</tr>

			</thead>

			<tbody>

			<?php if ( ! empty( $auctions ) ) : ?>

				<?php foreach ( $auctions as $auction ) : ?>

					<tr>

						<td><?php echo esc_html( $auction->id ); ?></td>

						<td><?php echo esc_html( $auction->listing_id ); ?></td>

						<td><?php echo esc_html( $auction->start_price ); ?></td>

						<td><?php echo esc_html( $auction->reserve_price ); ?></td>

						<td><?php echo esc_html( $auction->buy_now_price ); ?></td>

						<td><?php echo esc_html( ucfirst( $auction->status ) ); ?></td>

					</tr>

				<?php endforeach; ?>

			<?php else : ?>

				<tr>

					<td colspan="6">

						No auctions found.

					</td>

				</tr>

			<?php endif; ?>

			</tbody>

		</table>

	</div>

	<?php
}

Step 3 – Test the Plugin

Create another auction.

Open:

Flipnzee Auctions → All Auctions

You should now see every auction displayed in a professional WordPress table.

You no longer need phpMyAdmin to verify your data.


Understanding the Flow

The page never communicates directly with SQL.

Instead:

Database

↓

Auction Manager

↓

PHP Array

↓

foreach()

↓

HTML Table

This separation keeps the code organized and maintainable.


Lesson Summary

In this lesson, we created our first data listing page.

Administrators can now browse auctions directly inside the WordPress Dashboard without using phpMyAdmin.

This marks another important milestone because the plugin now supports both creating and viewing auctions.


Key Takeaways

  • ✓ Retrieve data through the Auction Manager.
  • ✓ Display records using foreach.
  • ✓ Escape all output with esc_html().
  • ✓ Use WordPress admin table styling.
  • ✓ Keep presentation separate from business logic.

Common Mistakes

  • Writing SQL inside the admin page.
  • Forgetting to escape output.
  • Not handling an empty database.
  • Mixing HTML with business logic unnecessarily.

Git Commands Used

git add .

git commit -m "Lesson 15: Display all auctions"

git push

Project Status

✅ Plugin dashboard

✅ Add Auction

✅ Secure form processing

✅ Save auction

✅ Display all auctions

⬜ View auction details

⬜ Edit auction

⬜ Delete auction

⬜ Bid engine

⬜ Escrow workflow

⬜ Version 1.0

Project Evolution

Our plugin has now reached the point where administrators can both create and browse auction records entirely within the WordPress Dashboard.

As the project continues, we’ll build on this interface by adding actions such as editing, deleting, filtering, sorting, and eventually managing bids and escrow transactions. Each new feature will reuse the architecture we’ve established, making the application easier to maintain and extend.


Developer’s Notebook

Although the HTML table works well for learning purposes, many professional plugins eventually migrate to WordPress’s WP_List_Table class. We’ll continue with a simple table for now because it clearly demonstrates how data is retrieved and displayed. Once the plugin becomes more advanced, we’ll refactor the interface to use WP_List_Table for features such as pagination, bulk actions, sorting, and searching.

Lesson 13: Creating a Dedicated Form Handler with the WordPress Admin Post API

Introduction

In the previous lesson, we improved the architecture of our Add Auction form by submitting it to WordPress’s admin-post.php endpoint and protecting it with a nonce.

However, there is still no code that actually receives the submitted form.

In this lesson, we’ll create a dedicated Form Handler class. This class will verify the nonce, validate the submitted data, and then call the Auction Manager to create the auction.

By keeping form processing separate from page rendering, we make the plugin cleaner, easier to maintain, and more aligned with WordPress best practices.


Learning Objectives

By the end of this lesson, you’ll be able to:

  • Understand the WordPress Admin Post API.
  • Register custom admin actions.
  • Create a dedicated form handler class.
  • Verify WordPress nonces.
  • Validate submitted form data.
  • Prepare the plugin for database insertion.

Why Create a Form Handler?

Instead of mixing everything together:

Form

↓

SQL

↓

HTML

we’ll separate responsibilities:

Form

↓

Form Handler

↓

Auction Manager

↓

Database

Each component now has one responsibility.


Step 1 – Create a New File

Inside the admin folder create:

class-admin-posts.php

Step 2 – Create the Form Handler

Copy the following code into the file.

<?php

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

class Flipnzee_Auction_Admin_Posts {

	/**
	 * Constructor.
	 */
	public function __construct() {

		add_action(
			'admin_post_flipnzee_create_auction',
			array( $this, 'handle_create_auction' )
		);
	}

	/**
	 * Handle Add Auction form submission.
	 */
	public function handle_create_auction() {

		// Verify nonce.
		check_admin_referer(
			'flipnzee_create_auction',
			'flipnzee_nonce'
		);

		// Form processing will be added in Lesson 14.

		wp_safe_redirect(
			admin_url( 'admin.php?page=flipnzee-add-auction' )
		);

		exit;
	}
}

new Flipnzee_Auction_Admin_Posts();

Understanding admin_post

WordPress automatically looks for an action matching:

admin_post_{action}

Our form contains:

<input
	type="hidden"
	name="action"
	value="flipnzee_create_auction">

WordPress therefore executes:

admin_post_flipnzee_create_auction

which calls our handler.


Understanding check_admin_referer()

This function verifies the nonce we added in Lesson 12.

If the nonce is invalid:

  • Processing stops immediately.
  • WordPress displays an error.
  • The request is rejected.

This protects our plugin against Cross-Site Request Forgery (CSRF) attacks.


Why Redirect?

After processing the form, we redirect back to the Add Auction page.

This prevents duplicate submissions if the administrator refreshes the page and follows the standard Post/Redirect/Get (PRG) pattern used by professional web applications.


Step 3 – Load the New Class

Open:

flipnzee-auctions.php

Immediately after loading the Admin class, add:

/**
 * Load Admin Posts Class
 */
if ( file_exists( FLIPNZEE_AUCTION_PATH . 'admin/class-admin-posts.php' ) ) {
	require_once FLIPNZEE_AUCTION_PATH . 'admin/class-admin-posts.php';
}

Step 4 – Test the Plugin

Create a new ZIP.

Upload the plugin.

Activate it.

Open:

Flipnzee Auctions → Add Auction

Complete the form.

Click:

Create Auction

Nothing will be saved yet.

However, if everything has been configured correctly, the form should redirect back to the Add Auction page without errors.

That’s exactly what we want at this stage.


Lesson Summary

In this lesson, we created a dedicated Form Handler using the WordPress Admin Post API.

Although the handler currently verifies the nonce and redirects the user, it establishes the architecture we’ll use for all future form processing.

In the next lesson, we’ll finally connect this handler to the Auction Manager and insert our first auction into the database.


Key Takeaways

  • ✓ Use admin_post for processing administration forms.
  • ✓ Verify nonces before processing data.
  • ✓ Separate form handling from page rendering.
  • ✓ Redirect after successful processing.
  • ✓ Build applications one layer at a time.

Common Mistakes

  • Forgetting to register the admin_post action.
  • Processing forms inside page-rendering methods.
  • Omitting nonce verification.
  • Forgetting to call exit after wp_safe_redirect().

Git Commands Used

git add .

git commit -m "Lesson 13: Create Admin Post form handler"

git push

Project Status

✅ Plugin dashboard

✅ Add Auction page

✅ Secure form architecture

✅ Admin Post handler

⬜ Save auction

⬜ Display auctions

⬜ Edit auction

⬜ Bid engine

⬜ Escrow workflow

⬜ Version 1.0

Project Evolution

Our plugin now follows a cleaner architecture by separating administration pages from form processing. This makes future features such as editing auctions, deleting auctions, and managing bids much easier to implement because every form can follow the same pattern.

As the project continues to grow, this separation of concerns will keep the codebase organized and easier to maintain.


Developer’s Notebook

One of the defining characteristics of well-designed WordPress plugins is that user interfaces and request processing are kept separate. While beginners often process forms directly inside page-rendering methods, larger plugins typically use dedicated handlers that can be reused, tested, and extended independently. Adopting this pattern early prepares the project for long-term growth and makes the code easier for other developers to understand.

Lesson 12: Processing WordPress Admin Forms the Professional Way

Introduction

In the previous lesson, we created our first Add Auction page inside the WordPress Dashboard. Although administrators can now fill in auction details, the form doesn’t yet save any information.

There are several ways to process WordPress forms. For small plugins, it’s common to process the submitted data inside the same function that displays the form. While this works, it mixes presentation with business logic.

In this lesson, we’ll adopt a more professional approach by using WordPress’s Admin Post API. This separates form processing from page rendering and produces cleaner, more maintainable code.

By the end of this lesson, administrators will be able to submit an auction through the dashboard, and the Auction Manager will store it in the database.


Learning Objectives

By the end of this lesson, you’ll be able to:

  • Understand the WordPress Admin Post API.
  • Protect forms with WordPress nonces.
  • Process form submissions in a dedicated handler.
  • Validate and sanitize submitted data.
  • Call the Auction Manager to save data.
  • Redirect users safely after processing.

Why Change Our Architecture?

A common beginner approach looks like this:

Display Form
      │
      ▼
Read $_POST
      │
      ▼
Save Database

This mixes multiple responsibilities inside one function.

Instead, we’ll use:

Display Form
      │
      ▼
admin-post.php
      │
      ▼
Form Handler
      │
      ▼
Auction Manager
      │
      ▼
Database

Each component now has one clearly defined responsibility.


What We’ll Build

Our plugin will now consist of:

  • Admin Class – Registers menus and displays pages.
  • Auction Manager – Handles auction business logic.
  • Form Handler – Processes submitted forms.
  • Database Class – Creates and manages database tables.

This separation makes the plugin easier to maintain as it grows.


Step 1 – Add a Nonce to the Form

Every administrative form should include a nonce.

Immediately before the submit button, add:

<?php wp_nonce_field(
	'flipnzee_create_auction',
	'flipnzee_nonce'
); ?>

This generates a hidden security token that WordPress verifies when the form is submitted.


Step 2 – Submit to admin-post.php

Instead of submitting the form back to the same page, we’ll submit it to WordPress.

Our form will eventually look like this:

<form method="post" action="<?php echo esc_url( admin_url( 'admin-post.php' ) ); ?>">

We’ll also include a hidden field named:

<input
	type="hidden"
	name="action"
	value="flipnzee_create_auction">

The value of this field tells WordPress which handler should process the request.


Step 3 – Create a Form Handler

Rather than placing processing code inside the page-rendering method, we’ll create a dedicated handler class.

This handler will:

  • Verify the nonce.
  • Validate the submitted data.
  • Call the Auction Manager.
  • Redirect back to the dashboard.

This keeps the user interface completely separate from the business logic.


Step 4 – Validate and Sanitize Input

Before saving anything, we’ll clean the submitted data.

Examples include:

  • absint() for IDs.
  • (float) for prices.
  • sanitize_text_field() for text values.
  • wp_unslash() when appropriate.

Never trust raw $_POST values.


Step 5 – Save the Auction

Once the data has been validated, we’ll call:

Flipnzee_Auction_Manager::create_auction();

Notice that the form handler doesn’t execute SQL directly.

The Auction Manager remains responsible for interacting with the database.


Step 6 – Redirect Back

After processing the form, the handler redirects the administrator back to the Add Auction page.

This prevents duplicate submissions if the page is refreshed and follows the standard WordPress Post/Redirect/Get pattern.


Why This Is Better

Separating page rendering from form processing provides several advantages:

  • Cleaner code.
  • Easier debugging.
  • Better security.
  • Easier testing.
  • Simpler future enhancements.

As the plugin grows, we’ll reuse this same architecture for editing auctions, deleting auctions, placing bids, and updating settings.


Lesson Summary

In this lesson, we redesigned the way our plugin handles administration forms.

Rather than processing submitted data inside the page-rendering method, we adopted the WordPress Admin Post API. This keeps the user interface, form processing, and business logic separated into dedicated components.

Although this approach requires a little more setup, it scales much better as the plugin becomes more sophisticated.


Key Takeaways

  • ✓ Use WordPress nonces for every administration form.
  • ✓ Process forms through admin-post.php.
  • ✓ Keep HTML separate from business logic.
  • ✓ Validate and sanitize all user input.
  • ✓ Let the Auction Manager handle database operations.

Common Mistakes

  • Processing $_POST directly inside the view.
  • Forgetting nonce verification.
  • Trusting user input without validation.
  • Mixing SQL with HTML.

Git Commands Used

git add .

git commit -m "Lesson 12: Process admin forms using Admin Post API"

git push

Project Status

✅ Plugin dashboard

✅ Add Auction page

✅ Secure form architecture

⬜ Form handler

⬜ Save auction

⬜ Auction listing

⬜ Edit auction

⬜ Bid engine

⬜ Escrow workflow

Project Evolution

Earlier in this series, our focus was simply getting a working plugin. As the project has matured, we’ve begun adopting architectural patterns used in production-quality WordPress plugins.

Introducing the Admin Post API is one such refinement. Although it requires slightly more code, it provides a cleaner separation of responsibilities and lays the foundation for a plugin that will remain maintainable as features such as bidding, escrow integration, and website transfers are added.

Why WordPress Uses Nonces: Understanding CSRF with a Simple Real-World Example

Many WordPress beginners encounter functions like wp_nonce_field() and check_admin_referer() while developing plugins. At first, these functions can seem unnecessary. After all, if only administrators can access your plugin settings, why add another layer of protection?

The answer lies in understanding a common web security attack called Cross-Site Request Forgery (CSRF). In this article, we’ll explore how such an attack works, why it is dangerous, and how WordPress nonces help prevent it.

A Simple Plugin Settings Form

Imagine your plugin has a settings page where an administrator can save an API key.

<form method="post">
    <input type="text" name="api_key">
    <input type="submit" value="Save Settings">
</form>

When the administrator submits the form, the plugin stores the value.

update_option(
    'my_plugin_api_key',
    $_POST['api_key']
);

Everything works perfectly during normal use.

The Administrator Is Already Logged In

When an administrator logs into WordPress, the browser stores a login cookie.

Whenever the browser communicates with the WordPress website, this cookie is automatically included with every request.

This allows WordPress to recognize the administrator without asking them to log in again for every page.

The Unexpected Problem

Now imagine the administrator visits another website while still logged into WordPress.

That website appears harmless, but behind the scenes it contains a hidden HTML form.

<form action="https://mysite.com/wp-admin/admin.php?page=my-plugin"
      method="POST">

    <input type="hidden"
           name="api_key"
           value="HACKED">

</form>

<script>
document.forms[0].submit();
</script>

The administrator never sees this form.

The JavaScript immediately submits it in the background.

What Happens Next?

When the browser submits the hidden form to your WordPress website, it automatically includes the administrator’s login cookie.

From WordPress’s perspective, the request looks completely legitimate because it comes from an authenticated administrator.

If your plugin simply executes:

update_option(
    'my_plugin_api_key',
    $_POST['api_key']
);

the malicious value is saved.

The administrator never clicked your plugin’s Save Settings button. Their browser unknowingly performed the action on their behalf.

Why Is This Dangerous?

At first glance, changing a single setting may not seem like a serious problem. However, many administrative actions can be performed through web forms.

Without CSRF protection, an attacker could trick an administrator’s browser into:

  • Changing plugin or theme settings
  • Publishing unwanted posts or announcements
  • Creating a new administrator account
  • Deleting important data
  • Disabling security plugins
  • Importing malicious configuration files
  • Triggering actions that execute harmful code

The attacker never needs to know the administrator’s password.

Instead, they misuse the administrator’s already authenticated browser.

Enter WordPress Nonces

WordPress solves this problem by adding a nonce to forms.

wp_nonce_field( 'save_settings' );

This generates a hidden field similar to:

<input type="hidden"
       name="_wpnonce"
       value="9f8d72e1ab">

When the form is submitted, your plugin verifies the nonce.

check_admin_referer( 'save_settings' );

If the nonce is missing or invalid, WordPress immediately rejects the request.

Why Can’t the Attacker Guess the Nonce?

The nonce is generated by WordPress specifically for the logged-in user and is embedded in the genuine plugin page.

A malicious website cannot simply invent a valid nonce value.

Without the correct nonce, the forged request fails, even though the administrator is logged in.

Cookies and Nonces Serve Different Purposes

It is important to understand that authentication cookies and nonces solve different problems.

The login cookie answers:

Who is making this request?

The nonce answers:

Did this request originate from a legitimate WordPress form?

Both checks are necessary for secure plugin development.

A Real-World Analogy

Imagine entering your office using your employee ID card.

Once inside, someone hands you a sealed envelope and asks you to place it in the manager’s mailbox.

You assume it’s legitimate and deliver it.

Later, the manager discovers the envelope contains a fake resignation letter or an unauthorized payment request.

The manager trusted the envelope because it was delivered by you, even though you never intended to send that message.

A CSRF attack works in much the same way.

The attacker doesn’t steal your identity. Instead, they trick your browser—which WordPress already trusts—into performing actions on your behalf.

Key Takeaways

  • Being logged into WordPress does not automatically protect against CSRF attacks.
  • A malicious website can cause a logged-in browser to submit unwanted requests.
  • WordPress nonces help verify that a request originated from a genuine WordPress page.
  • Every plugin that processes forms should use wp_nonce_field() when generating the form and check_admin_referer() (or check_ajax_referer() for AJAX requests) before processing submitted data.
  • Authentication confirms who is making the request, while nonces help verify where the request came from.

Understanding this distinction is one of the most important milestones in becoming a secure WordPress plugin developer.

Lesson 11: Creating Your First Auction from the WordPress Dashboard

Introduction

In the previous lesson, we created the first administration dashboard for Flipnzee Auctions. Although the dashboard displays useful plugin information, administrators still cannot create auctions.

In this lesson, we’ll build our first administration form.

Instead of inserting records directly into the database, administrators will be able to create auctions using the familiar WordPress Dashboard.

This marks an important milestone in the project because it connects our user interface to the database through the Auction Manager class.


Learning Objectives

By the end of this lesson, you’ll be able to:

  • Create your first administration form.
  • Submit form data securely.
  • Insert auction records into the database.
  • Use the Auction Manager class from the administration interface.
  • Understand why business logic should remain separate from the user interface.

Our Architecture

Remember the design we’ve adopted throughout this project.

Administrator

        │

        ▼

Admin Form

        │

        ▼

Auction Manager

        │

        ▼

Database

Notice that the form never communicates directly with the database.

Instead, it delegates the work to the Auction Manager.


Why Not Use SQL Here?

Imagine writing SQL inside every administration page.

Soon your project would become difficult to maintain.

Instead:

  • Forms collect information.
  • Auction Manager performs the work.
  • Database stores the results.

Each component has one responsibility.


Step 1 – Create a New Menu

Open:

admin/class-admin.php

Inside the register_menu() method, immediately below add_menu_page(), add:

add_submenu_page(
	'flipnzee-auctions',
	'Add Auction',
	'Add Auction',
	'manage_options',
	'flipnzee-add-auction',
	array( $this, 'add_auction_page' )
);

Step 2 – Create the Add Auction Page

Inside the class, add the following method.

public function add_auction_page() {

	?>

	<div class="wrap">

		<h1>Add Auction</h1>

		<form method="post">

			<table class="form-table">

				<tr>

					<th>Listing ID</th>

					<td>

						<input
							type="number"
							name="listing_id"
							min="1"
							required
						>

					</td>

				</tr>

				<tr>

					<th>Start Price</th>

					<td>

						<input
							type="number"
							step="0.01"
							name="start_price"
							required
						>

					</td>

				</tr>

				<tr>

					<th>Reserve Price</th>

					<td>

						<input
							type="number"
							step="0.01"
							name="reserve_price"
						>

					</td>

				</tr>

				<tr>

					<th>Buy Now Price</th>

					<td>

						<input
							type="number"
							step="0.01"
							name="buy_now_price"
						>

					</td>

				</tr>

			</table>

			<?php submit_button( 'Create Auction' ); ?>

		</form>

	</div>

	<?php
}

Step 3 – Why Listing ID?

Some readers may wonder why we’re asking for a Listing ID instead of a website title.

The answer is simple.

Website listings already belong to the Flipnzee Analytics plugin.

Rather than storing duplicate information, Flipnzee Auctions simply references the existing listing.

For now, we’ll enter the Listing ID manually.

Later in this series, we’ll replace this field with a dropdown that automatically displays verified listings from Flipnzee Analytics.


Step 4 – Upload the Plugin

Create a new ZIP.

Upload it.

Activate the plugin.

Open:

Flipnzee Auctions

↓

Add Auction

You should now see your first administration form.

Although the form doesn’t yet save data, we’ve successfully built the user interface.

We’ll connect it to the Auction Manager in the next lesson.


Lesson Summary

In this lesson, we created our first administration form for Flipnzee Auctions.

Rather than inserting data directly into the database, we focused on building a clean user interface that will soon communicate with the Auction Manager.

This layered approach keeps the plugin organized and prepares us for more advanced functionality.


Key Takeaways

  • ✓ WordPress administration pages use standard HTML forms.
  • ✓ Keep forms separate from database logic.
  • ✓ Prepare for future integrations instead of duplicating data.
  • ✓ Build one layer at a time.

Common Mistakes

  • Writing SQL directly inside administration pages.
  • Mixing business logic with HTML.
  • Duplicating listing information.
  • Building complicated forms before the backend is ready.

Git Commands Used

git add .

git commit -m "Lesson 11: Add Auction form"

git push

Project Status

✅ Development environment

✅ Plugin skeleton

✅ Plugin installation

✅ Plugin lifecycle

✅ .gitignore

✅ Data architecture

✅ Database table

✅ Auction Manager

✅ Retrieve auction records

✅ WordPress admin menu

✅ Plugin dashboard

✅ Add Auction page

⬜ Save auction

⬜ List auctions

⬜ Edit auctions

⬜ Bid engine

⬜ Escrow workflow

⬜ Website transfer

⬜ Version 1.0

Project Evolution

When we first planned this plugin, we considered storing all website information inside Flipnzee Auctions.

As the project evolved, we recognized that Flipnzee Analytics already provides verified website listings. Rather than duplicating that data, the auction plugin now references listings through a listing_id.

This architectural refinement keeps both plugins modular and easier to maintain while allowing them to work together as part of the broader Flipnzee ecosystem.


Developer’s Notebook

One of the biggest advantages of separating the user interface from the business logic is flexibility. Today we’re creating a simple administration form, but tomorrow the same Auction Manager methods could be called from REST APIs, AJAX requests, WP-CLI commands, or even another plugin. By keeping responsibilities separate, we avoid rewriting the core logic every time a new interface is introduced.


Looking Ahead

In Lesson 12, we’ll connect this form to the Auction Manager so that submitting it actually creates a new auction in the database. We’ll also introduce WordPress nonces to protect the form against unauthorized submissions, an essential security practice for professional plugin development.

Lesson 10: Building Your First Plugin Dashboard

Introduction

In the previous lesson, we created our first WordPress administration menu. Although our plugin now has its own dashboard page, the content is very simple.

Professional plugins do more than display a welcome message. They provide administrators with useful information at a glance, such as plugin status, database health, statistics, and recent activity.

In this lesson, we’ll transform our basic dashboard into a professional-looking administration page by displaying several information cards.

Even though most of the values are placeholders for now, this dashboard establishes the layout we’ll continue enhancing throughout the project.


Learning Objectives

By the end of this lesson, you’ll be able to:

  • Build a professional WordPress dashboard page.
  • Display plugin information.
  • Count database records.
  • Use WordPress dashboard styling.
  • Prepare the interface for future features.

Why Build a Dashboard First?

As our plugin grows, administrators will need quick access to important information.

Instead of searching through multiple pages, they’ll be able to see everything from one central dashboard.

Later, this page will display:

  • Total Auctions
  • Active Auctions
  • Sold Auctions
  • Total Bids
  • Pending Transfers
  • Escrow Transactions
  • Plugin Version
  • Database Status

Today’s lesson lays the foundation for that dashboard.


Step 1 – Open the Admin Class

Open:

admin/class-admin.php

We’ll replace the simple welcome page with a more useful dashboard.


Step 2 – Replace dashboard_page()

Replace the existing dashboard_page() method with the following:

/**
 * Dashboard page.
 */
public function dashboard_page() {

	global $wpdb;

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

	$total_auctions = (int) $wpdb->get_var(
		"SELECT COUNT(*) FROM {$table}"
	);

	?>

	<div class="wrap">

		<h1>Flipnzee Auctions Dashboard</h1>

		<p>Welcome to the Flipnzee Auctions administration panel.</p>

		<table class="widefat striped">

			<thead>
				<tr>
					<th>Information</th>
					<th>Value</th>
				</tr>
			</thead>

			<tbody>

				<tr>
					<td>Plugin Version</td>
					<td><?php echo esc_html( FLIPNZEE_AUCTION_VERSION ); ?></td>
				</tr>

				<tr>
					<td>Total Auctions</td>
					<td><?php echo esc_html( $total_auctions ); ?></td>
				</tr>

				<tr>
					<td>Database Table</td>
					<td><?php echo esc_html( $table ); ?></td>
				</tr>

				<tr>
					<td>Plugin Status</td>
					<td>Active</td>
				</tr>

			</tbody>

		</table>

	</div>

	<?php
}

Understanding the Code

The dashboard retrieves the total number of auctions using:

$wpdb->get_var()

Unlike get_row() or get_results(), this method returns only a single value.

In our case:

SELECT COUNT(*)

returns the number of auction records stored in the database.


Why Use COUNT(*)?

Imagine there are:

Auction 1

Auction 2

Auction 3

Instead of loading all three records, MySQL simply returns:

3

This is much faster and more efficient.


Step 3 – Upload the Plugin

Create a new ZIP.

Upload it.

Replace the existing plugin.

Refresh the Dashboard.


What You Should See

Your dashboard should now display something similar to:

Flipnzee Auctions Dashboard

Plugin Version      1.0.0

Total Auctions      0

Database Table      wp_flipnzee_auctions

Plugin Status       Active

Because we haven’t created any auctions yet, the total remains zero.

That’s exactly what we expect.


Lesson Summary

In this lesson, we transformed our simple administration page into a functional plugin dashboard.

Although the statistics are currently minimal, we’ve established a reusable layout that will gradually expand as more features are added.


Key Takeaways

  • ✓ Use $wpdb->get_var() to retrieve a single value.
  • ✓ COUNT(*) efficiently counts database records.
  • ✓ Dashboards provide administrators with useful information.
  • ✓ Build the user interface gradually.
  • ✓ Reuse WordPress styling whenever possible.

Common Mistakes

  • Loading unnecessary data when only a count is required.
  • Forgetting to escape output.
  • Mixing business logic with HTML.
  • Hardcoding plugin information.

Git Commands Used

git add .

git commit -m "Lesson 10: Build plugin dashboard"

git push

Project Status

✅ Development environment

✅ Plugin skeleton

✅ Plugin installation

✅ Plugin lifecycle

✅ .gitignore

✅ Data architecture

✅ Database table

✅ Auction Manager

✅ Retrieve auction records

✅ WordPress admin menu

✅ Plugin dashboard

⬜ Create first auction

⬜ Auction listing page

⬜ Bid engine

⬜ Escrow workflow

⬜ Website transfer

⬜ Notifications

⬜ Version 1.0

Project Evolution

Earlier in the series, our focus was on backend architecture. Now we’re beginning to expose that functionality through a professional administration interface.

As additional features are developed, this dashboard will evolve into the central control panel for the entire auction marketplace, giving administrators quick access to auctions, bids, transfers, and transaction status.

The GitHub repository will always contain the latest implementation, while these lessons explain the reasoning behind each architectural decision.


Developer’s Notebook

A dashboard is often the first screen administrators see when using a plugin. A clean, informative dashboard creates confidence and reduces the time needed to find important information. Even simple statistics such as plugin version, total records, and database status can be valuable during development and troubleshooting.


Looking Ahead

In Lesson 11, we’ll create our first Add New Auction page. Instead of working directly with database methods, administrators will begin creating auctions through a WordPress form, bringing the plugin one step closer to becoming a fully functional marketplace.

Lesson 9: Creating Your First WordPress Admin Menu

Introduction

In the previous lessons, we’ve built a solid backend for our plugin.

We have:

  • A professional plugin structure.
  • A custom database table.
  • An Auction Manager class.
  • Methods for creating and retrieving auction records.

However, everything is still happening behind the scenes.

Professional WordPress plugins provide an administration interface where site owners can manage data without editing code. In this lesson, we’ll create our first administration menu for Flipnzee Auctions.

Although the page will initially contain only placeholder content, it establishes the foundation upon which we’ll build auction management, bidding, transaction workflows, and plugin settings.


Learning Objectives

By the end of this lesson, you’ll be able to:

  • Understand how WordPress admin menus work.
  • Create your first top-level administration menu.
  • Display a custom administration page.
  • Learn about the admin_menu hook.
  • Organize admin-related code into its own class.

Why Use an Admin Class?

As our plugin grows, we’ll eventually have multiple administration pages:

  • Dashboard
  • Auctions
  • Bids
  • Transactions
  • Settings
  • Reports

Rather than placing all this code inside flipnzee-auctions.php, we’ll keep everything related to the administration area inside its own class.

This makes the plugin easier to maintain.


Step 1 – Create the Admin Folder

Inside your plugin folder, create a new directory:

admin

Your structure now becomes:

flipnzee-auctions/
│
├── admin/
├── includes/
├── flipnzee-auctions.php

Step 2 – Create the Admin Class

Inside the admin folder create:

class-admin.php

Step 3 – Add the Admin Class

Copy the following code into the file.

<?php

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

class Flipnzee_Auction_Admin {

	public function __construct() {

		add_action( 'admin_menu', array( $this, 'register_menu' ) );
	}

	/**
	 * Register the admin menu.
	 */
	public function register_menu() {

		add_menu_page(
			'Flipnzee Auctions',
			'Flipnzee Auctions',
			'manage_options',
			'flipnzee-auctions',
			array( $this, 'dashboard_page' ),
			'dashicons-hammer',
			26
		);
	}

	/**
	 * Dashboard page.
	 */
	public function dashboard_page() {

		echo '<div class="wrap">';
		echo '<h1>Flipnzee Auctions</h1>';
		echo '<p>Welcome to the Flipnzee Auctions plugin.</p>';
		echo '<p>This dashboard will gradually grow throughout this tutorial series.</p>';
		echo '</div>';
	}
}

new Flipnzee_Auction_Admin();

Understanding add_menu_page()

The function receives several arguments.

add_menu_page(
    Page Title,
    Menu Title,
    Capability,
    Menu Slug,
    Callback Function,
    Icon,
    Position
);

Let’s briefly look at each one.


Page Title

Appears at the top of the browser window.


Menu Title

The text displayed in the WordPress sidebar.


Capability

manage_options

Only administrators can access the page.


Menu Slug

A unique identifier used internally by WordPress.


Callback Function

The function responsible for displaying the page.


Icon

We’re using:

dashicons-hammer

WordPress includes hundreds of built-in Dashicons that can be used for plugin menus.


Position

The menu position in the WordPress sidebar.


Step 4 – Load the Admin Class

Open:

flipnzee-auctions.php

Add the following code immediately after loading the Auction Manager.

/**
 * Load Admin Class
 */
if ( file_exists( FLIPNZEE_AUCTION_PATH . 'admin/class-admin.php' ) ) {
	require_once FLIPNZEE_AUCTION_PATH . 'admin/class-admin.php';
}

Step 5 – Upload the Updated Plugin

Delete the previous ZIP.

Create a new ZIP.

Upload it to WordPress.

Activate the plugin if necessary.


Step 6 – Visit the Dashboard

Open the WordPress administration area.

You should now see a new menu item:

Flipnzee Auctions

Clicking it should display your first plugin dashboard.

Congratulations! Your plugin now has its own administration interface.


Lesson Summary

In this lesson, we created the first administration page for Flipnzee Auctions. Rather than mixing administration code with plugin initialization, we introduced a dedicated Admin class responsible for registering the plugin’s menu and displaying its dashboard.

Although the page currently contains only simple placeholder content, it provides the framework for all future administration features.


Key Takeaways

  • ✓ Use admin_menu to register administration pages.
  • ✓ Keep administration code in a separate class.
  • ✓ Use add_menu_page() to create top-level menus.
  • ✓ Build the user interface gradually.
  • ✓ Maintain a clean project structure.

Common Mistakes

  • Putting administration code inside the main plugin file.
  • Forgetting to instantiate the Admin class.
  • Using an incorrect capability.
  • Loading the Admin class after trying to use it.

Git Commands Used

git add .

git commit -m "Lesson 9: Create WordPress admin menu"

git push

Project Status

✅ Development environment

✅ Plugin skeleton

✅ Plugin installation

✅ Plugin lifecycle

✅ .gitignore

✅ Data architecture

✅ Database table

✅ Auction Manager

✅ Retrieve auction records

✅ WordPress admin menu

⬜ Dashboard widgets

⬜ Create auctions

⬜ Bid engine

⬜ Escrow workflow

⬜ Website transfer

⬜ Notifications

⬜ Version 1.0

Project Evolution

Earlier in the series, our focus was entirely on the backend architecture. Now that the foundation is in place, we’re beginning to build the user interface. This reflects a common professional development workflow: first establish the application’s core logic, then expose that functionality through a clean and intuitive interface.

As always, the GitHub repository contains the latest implementation, while these lessons explain the reasoning behind each architectural decision.


Developer’s Notebook

One of the strengths of WordPress is its consistent administration interface. Rather than inventing our own dashboard, we integrate seamlessly with the existing WordPress admin area. Users already understand how the Dashboard works, so following WordPress conventions makes the plugin feel familiar and professional from the very beginning.


Looking Ahead

In Lesson 10, we’ll enhance the dashboard by displaying useful information such as the total number of auctions, database status, plugin version, and recent activity. This will transform our placeholder page into the first functional administration dashboard for Flipnzee Auctions.

Lesson 8: Retrieving Auction Records from the Database

Introduction

In the previous lesson, we created our first Auction Manager class and added the create_auction() method. Although the method is capable of inserting auction records into the database, we haven’t used it yet. As a result, our wp_flipnzee_auctions table is still empty.

Before building forms or administration pages, it’s important to learn how to retrieve information from the database.

Professional software is built in layers. First we create the database, then we build classes that communicate with it, and only afterwards do we create user interfaces.

In this lesson, we’ll expand the Auction Manager by adding methods that retrieve auction records from the database.


Learning Objectives

By the end of this lesson, you’ll be able to:

  • Retrieve a single auction by its ID.
  • Retrieve all auctions.
  • Understand WordPress’s $wpdb->get_row() method.
  • Understand WordPress’s $wpdb->get_results() method.
  • Continue separating database logic from presentation.

Why Read Before Writing?

Most applications spend far more time reading data than writing it.

Think about Flipnzee.

Visitors browse listings.

Buyers search auctions.

Search engines index pages.

Administrators review sales.

All of these activities require reading data from the database.

Learning to retrieve records is therefore just as important as learning to create them.


Step 1 – Open the Auction Manager

Open:

includes/class-auction-manager.php

We’ll keep our existing create_auction() method.

Now we’ll extend the class.


Step 2 – Add a Method to Retrieve One Auction

Add the following method below create_auction().

/**
 * Retrieve one auction by ID.
 *
 * @param int $auction_id Auction ID.
 *
 * @return object|null
 */
public static function get_auction( $auction_id ) {

	global $wpdb;

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

	return $wpdb->get_row(
		$wpdb->prepare(
			"SELECT * FROM {$table} WHERE id = %d",
			$auction_id
		)
	);
}

Understanding get_row()

This method retrieves a single record.

If the auction exists:

Auction #15

it returns one object.

If the auction doesn’t exist:

Auction #999

it returns:

null

Why Use $wpdb->prepare()?

Never insert user input directly into SQL queries.

Instead of writing:

SELECT * FROM table WHERE id = $auction_id

we write:

$wpdb->prepare(...)

WordPress safely prepares the query before sending it to MySQL.

This helps protect your plugin from SQL injection attacks.


Step 3 – Retrieve All Auctions

Now add another method.

/**
 * Retrieve all auctions.
 *
 * @return array
 */
public static function get_all_auctions() {

	global $wpdb;

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

	return $wpdb->get_results(
		"SELECT * FROM {$table} ORDER BY created_at DESC"
	);
}

Understanding get_results()

Unlike get_row(),

get_results()

returns multiple rows.

If the database contains:

Auction 1

Auction 2

Auction 3

you receive an array containing three objects.

If there are no auctions yet:

you receive an empty array.


Why Aren’t We Showing Results Yet?

You might wonder:

Why don’t we display these auctions immediately?

Because our plugin still doesn’t have an administration page.

For now, we’re building the backend.

Soon, the administration interface will simply call these methods.


Our Growing Auction Manager

Our class now contains:

create_auction()

get_auction()

get_all_auctions()

Soon we’ll add:

update_auction()

delete_auction()

close_auction()

Notice how everything related to auctions stays inside one class.


Lesson Summary

In this lesson, we expanded the Auction Manager by adding methods to retrieve auction records from the database.

Although our table currently contains zero records, our plugin is now capable of reading both individual auctions and complete auction lists.

This prepares us for building the administration interface in future lessons.


Key Takeaways

  • ✓ Use get_row() when retrieving one record.
  • ✓ Use get_results() when retrieving multiple records.
  • ✓ Always use $wpdb->prepare() with user input.
  • ✓ Keep database operations inside dedicated classes.
  • ✓ Build the backend before the user interface.

Common Mistakes

  • Writing raw SQL with user input.
  • Mixing SQL with HTML.
  • Forgetting to use $wpdb->prepare().
  • Returning multiple rows when only one is expected.

Git Commands Used

git add .

git commit -m "Lesson 8: Retrieve auction records"

git push

Project Status

✅ Development environment

✅ Plugin skeleton

✅ Plugin installation

✅ Plugin lifecycle

✅ .gitignore

✅ Data architecture

✅ Database table

✅ Auction Manager

✅ Retrieve auction records

⬜ Create admin menu

⬜ Create first auction

⬜ Bid engine

⬜ Escrow workflow

⬜ Website transfer

⬜ Notifications

⬜ Version 1.0

Project Evolution

Throughout this project, we’ve been refining the architecture as new requirements become clearer.

One important decision was separating listing management from auction management. Website information remains the responsibility of Flipnzee Analytics, while Flipnzee Auctions focuses on auction logic and transaction workflows.

This lesson continues that philosophy by keeping all database operations inside the Auction Manager rather than scattering SQL queries throughout the plugin.

As always, the GitHub repository contains the latest implementation, while these lessons document the reasoning behind each architectural decision.


Developer’s Notebook

One of the easiest ways to identify well-structured software is by looking at how it accesses the database. Instead of allowing every part of the application to execute SQL queries, professional developers usually centralize database operations inside dedicated classes. This makes the code easier to test, easier to debug, and much simpler to extend. As Flipnzee Auctions grows to include bidding, escrow tracking, and website transfers, this design will allow us to add new functionality without creating unnecessary complexity.


Looking Ahead

In Lesson 9, we’ll create our first WordPress Administration Menu for Flipnzee Auctions. Instead of interacting with the database directly, administrators will begin managing auctions through the WordPress Dashboard. This marks the transition from backend infrastructure to a real user interface.

Lesson 7: Building the Auction Manager – Inserting and Managing Auction Records

Introduction

In the previous lesson, we created our first custom database table using WordPress’s dbDelta() function. Although the table exists, it is currently empty. Our plugin has a place to store auction data, but it doesn’t yet know how to create, retrieve, update, or delete auction records.

This is where an Auction Manager comes in.

Rather than scattering database queries throughout our plugin, we’ll create a dedicated class responsible for interacting with the auction table. This approach keeps our code organized, easier to maintain, and easier to extend as new features are added.

In this lesson, we’ll build the first version of the Auction Manager and learn how to insert our first auction into the database.


Learning Objectives

By the end of this lesson, you’ll be able to:

  • Understand the purpose of an Auction Manager.
  • Create a dedicated class for database operations.
  • Insert records into the database using WordPress’s $wpdb.
  • Understand how $wpdb->insert() works.
  • Keep database logic separate from the rest of your plugin.

Why Create an Auction Manager?

Imagine writing database queries everywhere throughout the plugin.

Soon you’d have SQL scattered across dozens of files.

Instead, we’ll centralize all auction-related database operations inside one class.

Our future Auction Manager will eventually handle:

  • Creating auctions
  • Updating auctions
  • Retrieving auctions
  • Deleting auctions
  • Ending auctions
  • Selecting winners
  • Checking auction status

Keeping all these operations together makes the plugin much easier to maintain.


Step 1 – Create a New Class

Inside the includes folder, create:

class-auction-manager.php

Step 2 – Create the Class

Copy the following code into the file:

<?php

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

class Flipnzee_Auction_Manager {

	/**
	 * Create a new auction.
	 *
	 * @param int   $listing_id    The ID of the listing from Flipnzee Analytics.
	 * @param float $start_price   Starting auction price.
	 * @param float $reserve_price Reserve price.
	 * @param float $buy_now_price Buy Now price.
	 *
	 * @return int|false Auction ID on success, false on failure.
	 */
	public static function create_auction( $listing_id, $start_price, $reserve_price, $buy_now_price ) {

		global $wpdb;

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

		$result = $wpdb->insert(
			$table,
			array(
				'listing_id'    => $listing_id,
				'status'        => 'draft',
				'start_price'   => $start_price,
				'reserve_price' => $reserve_price,
				'buy_now_price' => $buy_now_price,
				'current_bid'   => 0,
			),
			array(
				'%d',
				'%s',
				'%f',
				'%f',
				'%f',
				'%f',
			)
		);

		if ( false === $result ) {
			return false;
		}

		return $wpdb->insert_id;
	}
}

Understanding $wpdb->insert()

Instead of writing raw SQL, WordPress provides helper methods.

Our code:

$wpdb->insert(...)

is equivalent to writing an SQL INSERT statement, but it’s safer and easier to read.

WordPress also prepares the query correctly, reducing the risk of SQL injection.


Understanding the Parameters

The method receives three arguments:

1. Table Name

$table

This tells WordPress where to insert the data.


2. Data Array

array(
    'listing_id' => $listing_id,
    ...
)

Each array key corresponds to a database column.


3. Format Array

array(
    '%d',
    '%s',
    '%f'
)

This tells WordPress what type of data is being inserted.

Examples include:

  • %d Integer
  • %s String
  • %f Decimal

Providing formats makes the query safer and more reliable.


Step 3 – Load the Auction Manager

Open:

flipnzee-auctions.php

Below the database class, add:

/**
 * Load Auction Manager
 */
if ( file_exists( FLIPNZEE_AUCTION_PATH . 'includes/class-auction-manager.php' ) ) {
	require_once FLIPNZEE_AUCTION_PATH . 'includes/class-auction-manager.php';
}

Step 4 – Testing the Class

For now, we’re only building the class.

We won’t yet create auctions from the WordPress dashboard.

That will happen in a later lesson when we build the administration interface.

At this stage, our goal is simply to prepare the plugin architecture.


Why We Aren’t Creating Auctions Yet

Many beginners expect to see forms immediately.

Professional software development works differently.

First we build:

  • Database
  • Database classes
  • Business logic

Only then do we build:

  • Admin pages
  • Forms
  • Buttons
  • User interfaces

This layered approach produces cleaner software.


Looking Ahead

Eventually our Auction Manager will grow to include methods such as:

create_auction()

get_auction()

update_auction()

delete_auction()

close_auction()

select_winner()

Today’s version is intentionally simple.

We’ll expand it gradually throughout the series.


Lesson Summary

In this lesson, we created the first version of the Auction Manager class. Rather than placing database queries throughout the plugin, we introduced a dedicated class responsible for creating auction records.

Although the class currently performs only one operation, it establishes the architectural pattern we’ll use for all future auction-related functionality.


Key Takeaways

  • ✓ Keep database logic inside dedicated classes.
  • ✓ Use $wpdb->insert() instead of writing raw SQL.
  • ✓ Store one responsibility in one class.
  • ✓ Load new classes through the main plugin file.
  • ✓ Build the backend before building the user interface.

Common Mistakes

  • Writing SQL throughout multiple files.
  • Forgetting the format array in $wpdb->insert().
  • Mixing HTML and database code together.
  • Trying to build the admin interface before the backend is ready.

Git Commands Used

git add .

git commit -m "Lesson 7: Create Auction Manager"

git push

Project Status

✅ Development environment

✅ Plugin skeleton

✅ Plugin installation

✅ Plugin lifecycle

✅ .gitignore

✅ Data architecture

✅ Database table

✅ Auction Manager

⬜ Admin interface

⬜ Create auctions

⬜ Bid engine

⬜ Escrow workflow

⬜ Website transfer

⬜ Notifications

⬜ Version 1.0

Project Evolution

If you’ve been following the series from the beginning, you may notice that our architecture continues to evolve.

Originally, we planned for Flipnzee Auctions to manage both website listings and auctions. As the project matured, we recognized that Flipnzee Analytics already provides listing management, analytics, and verification.

Rather than duplicating those responsibilities, the Auction Manager focuses exclusively on auction operations. This separation of concerns keeps the codebase modular and allows both plugins to evolve independently while working together through the listing_id relationship.

The GitHub repository always contains the latest implementation, while these lessons document the reasoning behind each architectural decision.


Developer’s Notebook

One of the hallmarks of professional software is that it separates business logic from presentation. Users interact with forms and buttons, but those interfaces should simply call well-designed classes that perform the actual work. By introducing an Auction Manager early, we’re laying the foundation for a codebase that will remain organized even as the plugin grows to include bidding, escrow workflows, notifications, and website transfers.


Looking Ahead

In Lesson 8, we’ll use the Auction Manager to retrieve auction records from the database and display them inside WordPress. This will be our first step toward building a working administration interface and bringing real auction data onto the screen.