WordPress Plugin & Theme Development
7 questions found
What is the difference between a WordPress plugin and a WordPress theme, and what kind of functionality does each one typically control?
Beginner
A WordPress theme controls the visual appearance and layout of a website, including how pages, posts, and other content are actually displayed to visitors, while a plugin adds new functionality or features to a WordPress site that are typically independent of visual appearance, such as adding a contact form, an online store, or search engine optimization tools, and importantly, a well built plugin's functionality should generally continue working correctly even if a site's theme is later changed to a completely different one.
// Plugin header comment, required at the top of the main plugin file
<?php
/**
* Plugin Name: My Custom Plugin
* Version: 1.0
*/
Real-world example
A business switches their WordPress site's visual theme to give it a fresh new look, while their previously installed contact form and online store plugins continue functioning exactly the same as before, since that functionality was never tied to the specific theme in the first place.
Common follow-ups: Can a theme also include some plugin like functionality directly within it?;What is a child theme, and why is it recommended when customizing an existing theme?
MVC Architecture in PHP;Security
What are WordPress hooks, specifically actions and filters, and how do they let plugins and themes modify or extend WordPress's default behavior?
Beginner
WordPress hooks provide the primary mechanism through which plugins and themes can modify or extend WordPress's core behavior without needing to directly edit WordPress's own core files, and an action hook lets you run your own custom code at a specific predetermined point during WordPress's execution, such as right after a new post is published, while a filter hook lets you intercept and modify a specific piece of data as it passes through WordPress, such as changing the exact text of a post's title before it is actually displayed to a visitor.
add_action('publish_post', 'notify_team_of_new_post');
add_filter('the_title', function ($title) {
return strtoupper($title);
});
Real-world example
A plugin uses an action hook to automatically send an internal team notification whenever a new blog post is published, and separately uses a filter hook to automatically convert every displayed post title to uppercase letters.
Common follow-ups: What is the difference between add_action and add_filter, and how do you know which one to use in a given situation?;How do you find a complete list of all the hooks available within WordPress core?
Design Patterns in PHP;Security
How does the WordPress plugin file structure typically work, including the required plugin header comment that WordPress uses to recognize and display a plugin?
Intermediate
A WordPress plugin at its simplest consists of at least one PHP file placed within its own dedicated folder inside the wp content plugins directory, and that main PHP file must begin with a specially formatted comment block, known as the plugin header, containing metadata such as the plugin's name, version number, and description, which WordPress specifically reads and uses to correctly display that plugin within the admin dashboard's plugins list, allowing a site administrator to then activate or deactivate it.
<?php
/**
* Plugin Name: Simple Contact Form
* Description: Adds a basic contact form shortcode.
* Version: 1.2
* Author: Your Name
*/
if (!defined('ABSPATH')) exit;
Real-world example
A developer creates a new plugin folder containing a single main PHP file with a properly formatted plugin header comment, allowing WordPress to correctly recognize, list, and allow activation of that new plugin directly from the admin dashboard.
Common follow-ups: Why is checking for the ABSPATH constant considered an important security practice in a plugin's main file?;How does a plugin properly organize its code across multiple files as it grows larger?
Security;Namespaces & Autoloading
What are custom post types and custom fields in WordPress, and how do they let you extend WordPress beyond its default posts and pages to represent other kinds of content?
Intermediate
A custom post type lets you define an entirely new kind of content beyond WordPress's default built in posts and pages, such as a dedicated product, event, or testimonial content type, each with its own listing and editing screens within the admin dashboard, while custom fields let you attach additional, structured pieces of information to any individual piece of content, such as attaching a specific price and stock quantity field to each individual product, giving you the flexibility to model many different kinds of real world content beyond a standard WordPress blog post.
register_post_type('product', [
'label' => 'Products',
'public' => true,
'supports' => ['title', 'editor', 'thumbnail'],
]);
Real-world example
An online store built on WordPress registers a custom product post type, letting a site administrator manage individual products through their own dedicated screens within the admin dashboard, completely separate from the site's regular blog posts.
Common follow-ups: What is the difference between a custom post type and a regular WordPress category or tag?;How do you actually query and display a list of a specific custom post type on the front end of a site?
PDO & Databases;MVC Architecture in PHP
Why is properly sanitizing input and escaping output especially critical in WordPress plugin and theme development, and what built in WordPress functions help with this?
Intermediate
Since WordPress plugins and themes are extremely widely used, running on a very large percentage of all websites, a security vulnerability discovered in a single popular plugin can potentially affect an enormous number of individual websites simultaneously, making rigorous input sanitization and output escaping especially critical, and WordPress provides a set of dedicated built in functions specifically for this purpose, such as sanitize_text_field for cleaning a piece of submitted text input, and esc_html for safely escaping a piece of text immediately before it is displayed within HTML output.
$name = sanitize_text_field($_POST['name']);
echo '<p>Hello, ' . esc_html($name) . '</p>';
Real-world example
A WordPress contact form plugin sanitizes every submitted field using sanitize_text_field before saving it, and separately escapes that same data using esc_html immediately before displaying it back anywhere on the page, protecting against both malicious stored data and cross site scripting.
Common follow-ups: What is the difference between sanitizing input and escaping output, and why are both steps genuinely necessary?;What other specific sanitization and escaping functions does WordPress provide for different types of data, such as URLs or email addresses?
Security;Form Handling & Validation
How does the WordPress database abstraction layer, specifically the global $wpdb object, let you safely run custom database queries beyond what the standard WordPress functions already provide?
Advanced
While WordPress provides many built in functions for common database operations like retrieving posts or managing options, sometimes a plugin genuinely needs to run a custom database query beyond what those standard functions cover, and the global $wpdb object provides direct, safe access to the underlying WordPress database connection, including a prepare method that works similarly to a prepared statement, safely inserting user supplied values into a custom SQL query without introducing a SQL injection vulnerability.
global $wpdb;
$results = $wpdb->get_results(
$wpdb->prepare("SELECT * FROM {$wpdb->prefix}products WHERE price > %d", $minPrice)
);
Real-world example
A custom reporting plugin uses the global $wpdb object with its prepare method to safely run a custom query filtering products above a specific price threshold, correctly avoiding SQL injection even though the query goes well beyond what WordPress's standard built in functions could provide.
Common follow-ups: Why is it important to always use the $wpdb table prefix rather than hardcoding a table name directly?;When is it appropriate to use $wpdb directly instead of the WordPress Options or Post Meta APIs?
PDO & Databases;Security
What performance and caching considerations become especially important when developing a WordPress plugin that will run on a high traffic website?
Advanced
A WordPress plugin running on a high traffic website needs particular attention paid to performance, since a poorly optimized plugin, such as one that runs an expensive, unnecessary database query on every single page load regardless of whether that specific page actually needs that data, can noticeably slow down an entire site, and important considerations include using the WordPress Transients API or an external caching layer like Redis to cache the results of expensive operations, being careful about exactly when and how often a plugin's hooked functions actually execute, and avoiding loading unnecessary CSS or JavaScript files on pages where a plugin's specific functionality is not actually being used at all.
$data = get_transient('expensive_report_data');
if ($data === false) {
$data = generate_expensive_report();
set_transient('expensive_report_data', $data, HOUR_IN_SECONDS);
}
Real-world example
A WordPress analytics plugin caches the results of an expensive report generation process using the Transients API for one hour, dramatically reducing server load on a high traffic site compared to regenerating that same expensive report from scratch on every single page load.
Common follow-ups: How does the WordPress Transients API differ from directly using an external caching system like Redis?;What tools are available for actually profiling and measuring where a WordPress plugin's performance bottlenecks genuinely lie?
Caching Strategies in PHP;Performance Optimization & OPcache