0
0
Wordpressframework~10 mins

Plugin file structure in Wordpress - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - Plugin file structure
Create plugin folder
Add main plugin file
Add plugin header comment
Add additional files (optional)
Activate plugin in WordPress
Plugin runs and hooks into WordPress
This flow shows how a WordPress plugin is structured starting from folder creation to activation and running inside WordPress.
Execution Sample
Wordpress
<?php
/*
Plugin Name: My Plugin
*/
// Plugin code here
This is the main plugin file with the required header comment that WordPress reads to identify the plugin.
Execution Table
StepActionFile/Folder CreatedContent SummaryWordPress Reaction
1Create plugin foldermy-plugin/Empty folder to hold plugin filesRecognizes folder as plugin container
2Add main plugin filemy-plugin/my-plugin.phpPHP fileRecognizes main plugin file
3Add plugin header commentmy-plugin/my-plugin.phpContains Plugin Name and infoPlugin appears in admin plugins list
4Add additional filesmy-plugin/includes/functions.phpOptional PHP files for organizationFiles loaded by main plugin file if included
5Activate pluginWordPress adminUser activates plugin in dashboardPlugin code runs and hooks into WordPress
6Plugin runsN/AHooks and functions executePlugin functionality is available on site
💡 Plugin is fully loaded and active after activation step
Variable Tracker
Variable/FileStartAfter Step 2After Step 4After Activation
Plugin folderNot createdCreatedExistsExists
Main plugin fileNot createdCreatedExists with headerExists and loaded
Additional filesNoneNoneAddedLoaded if included
Plugin active stateInactiveInactiveInactiveActive
Key Moments - 3 Insights
Why is the plugin header comment important?
WordPress reads the header comment in the main plugin file to identify the plugin and show it in the admin list. Without it, WordPress ignores the plugin folder (see execution_table step 3).
Can a plugin have multiple PHP files?
Yes, additional PHP files can be added for better organization, but the main plugin file must include or require them to run (see execution_table step 4).
What happens if the plugin is not activated?
The plugin files exist but WordPress does not run the plugin code or hooks until the user activates it in the admin dashboard (see execution_table step 5).
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, at which step does WordPress recognize the plugin metadata?
AStep 2
BStep 3
CStep 4
DStep 5
💡 Hint
Check the 'WordPress Reaction' column for when the plugin appears in the admin list.
According to the variable tracker, when does the plugin become active?
AAfter Step 2
BAfter Step 4
CAfter Activation
DAt Start
💡 Hint
Look at the 'Plugin active state' row in the variable tracker.
If you add a new PHP file but do not include it in the main plugin file, what happens?
AThe file is ignored and code inside does not run
BWordPress loads it automatically
CPlugin fails to activate
DPlugin header comment is ignored
💡 Hint
Refer to key moment about additional files and execution_table step 4.
Concept Snapshot
WordPress Plugin File Structure:
- Create a plugin folder inside wp-content/plugins
- Add a main PHP file with a plugin header comment
- Optionally add more PHP files for organization
- Activate plugin in WordPress admin
- Plugin code runs and hooks into WordPress
Header comment is required for WordPress to detect the plugin.
Full Transcript
A WordPress plugin starts as a folder inside the plugins directory. Inside this folder, you create a main PHP file that must include a special header comment with the plugin name and info. This header allows WordPress to recognize and list the plugin in the admin dashboard. You can add more PHP files for organizing your code, but these must be included by the main plugin file to run. The plugin remains inactive until you activate it in the WordPress admin. Once activated, WordPress runs the plugin code and hooks, making the plugin's features available on the site.