Back to Blog
Lesson 1 of the Intermediate WordPress Plugins: REST API & React Admin course
WordPressJune 25, 20263 min read

Setting up the WordPress Development Environment

Master professional WordPress development by setting up your local environment, initializing the plugin structure, and verifying your first activation.

WordPressLocalWPPlugin DevelopmentSetupEnvironmentphpplugin-development

Welcome to the "Intermediate WordPress Plugins: REST API & React Admin" course. This series assumes you have a baseline understanding of PHP and the WordPress plugin lifecycle, but we are moving beyond simple function files into modern, scalable architecture.

In this lesson, we will establish the foundation for our project: the "Knowledge Base" plugin. We’ll focus on professionalizing your local setup using LocalWP and defining a robust directory structure that supports the build tools we'll introduce in upcoming lessons.

Setting Up Your Local Development Server

To build modern, performant plugins, you need an environment that mimics production while allowing for rapid iteration. While tools like Docker or VVV are popular, LocalWP offers the best balance of speed and ease of use for WordPress plugin development.

  1. Download and Install: Grab the latest version from the official site.
  2. Create a New Site: Use the "Preferred" environment settings (latest PHP and MySQL versions).
  3. Enable WP_DEBUG: This is non-negotiable. Navigate to your site's folder, open wp-config.php, and ensure the following constants are set:
    PHP
    define( 'WP_DEBUG', true );
    define( 'WP_DEBUG_LOG', true );
    define( 'WP_DEBUG_DISPLAY', false );
    Logging errors to wp-content/debug.log is far more professional than cluttering your UI with notices. If you find yourself struggling with complex issues later, refer to our guide on Error Handling and Logging: Building Robust WordPress Plugins for best practices.

Initializing the Plugin Structure

A professional plugin isn't just a single file. As we advance through this course, we will integrate React components, REST API classes, and build scripts. A flat structure will quickly become a maintenance nightmare.

Navigate to your site's wp-content/plugins/ directory and create a new folder named knowledge-base. Inside, we’ll start with this structure:

TEXT
knowledge-base/
├── assets/           # Compiled JS/CSS
├── src/              # Source code (React/JS)
├── includes/         # PHP classes and logic
├── knowledge-base.php # Main plugin entry point
└── package.json      # Dependency management

The Plugin Entry Point

Create knowledge-base.php in the root of your folder. WordPress requires specific headers to recognize your code as a plugin.

PHP
<?php
#6A9955">/**
 * Plugin Name: Knowledge Base
 * Description: A professional knowledge base with REST API and React UI.
 * Version: 1.0.0
 * Author: Your Name
 * Text Domain: knowledge-base
 */

if ( ! defined( 'ABSPATH' ) ) {
    exit; #6A9955">// Exit if accessed directly
}

#6A9955">// Simple autoloader or inclusion logic goes here later

Verifying Plugin Activation

Once the file is created, navigate to your WordPress Admin dashboard. Go to Plugins > Installed Plugins. You should see "Knowledge Base" listed. Click Activate.

If the plugin activates without error, you have successfully initialized your environment. If you receive a "Plugin file does not exist" error, double-check that your directory name matches the folder containing the main plugin file exactly.

Hands-on Exercise

  1. Initialize the folder: Create the knowledge-base directory structure as outlined above.
  2. Add a log test: In your knowledge-base.php file, add error_log('Knowledge Base initialized'); inside a simple activation hook.
  3. Verify: Activate the plugin, then check wp-content/debug.log in your local site folder. You should see your message.

Common Pitfalls

  • Case Sensitivity: WordPress is case-sensitive regarding folder names on Linux servers. Always use lowercase and hyphens for directory names to avoid deployment issues later.
  • Permissions: If you are using a local environment on macOS or Linux, ensure your user has write access to the wp-content/plugins folder.
  • Ignoring wp-config: Developing without WP_DEBUG enabled is the single biggest mistake beginners make. It hides critical warnings that will eventually break your production site.

As we move forward, keep your directory clean. We will be leveraging Advanced MVC: Dependency Injection for WordPress Plugins later in the course to keep our includes/ folder from becoming a procedural mess.

Recap

In this lesson, we configured a stable LocalWP instance, created a clean directory structure, and verified our plugin's activation. This structure is the bedrock for the build tools we will implement next.

Up next: Introduction to @wordpress/scripts — we'll set up your package.json and start compiling JavaScript.

Similar Posts