| name | wp-plugin-quick |
| description | Build production-ready WordPress plugins following best practices and WordPress coding standards. |
Skill: WordPress Plugin Development
Build production-ready WordPress plugins following best practices and WordPress coding standards.
Before Starting
- Load
/CLAUDE/context/wordpress-dev.md for standards
- Check
/CLAUDE/knowledge/wordpress-hooks.md for hook reference
- Review
/CLAUDE/knowledge/wordpress-patterns.md for common patterns
Plugin Boilerplate
Main Plugin File
<?php
defined( 'ABSPATH' ) || exit;
define( 'PLUGIN_NAME_VERSION', '1.0.0' );
define( 'PLUGIN_NAME_FILE', __FILE__ );
define( 'PLUGIN_NAME_PATH', plugin_dir_path( __FILE__ ) );
define( 'PLUGIN_NAME_URL', plugin_dir_url( __FILE__ ) );
if ( file_exists( PLUGIN_NAME_PATH . 'vendor/autoload.php' ) ) {
require_once PLUGIN_NAME_PATH . 'vendor/autoload.php';
}
function plugin_name_init() {
load_plugin_textdomain(
'plugin-name',
false,
dirname( plugin_basename( __FILE__ ) ) . '/languages'
);
if ( class_exists( 'PluginName\\Plugin' ) ) {
\PluginName\Plugin::instance();
}
}
add_action( 'plugins_loaded', 'plugin_name_init' );
register_activation_hook( __FILE__, 'plugin_name_activate' );
function plugin_name_activate() {
if ( version_compare( PHP_VERSION, '8.0', '<' ) ) {
deactivate_plugins( plugin_basename( __FILE__ ) );
wp_die( esc_html__( 'This plugin requires PHP 8.0 or higher.', 'plugin-name' ) );
}
if ( class_exists( 'PluginName\\Activator' ) ) {
\PluginName\Activator::activate();
}
set_transient( 'plugin_name_activated', true, 30 );
}
register_deactivation_hook( __FILE__, 'plugin_name_deactivate' );
function plugin_name_deactivate() {
if ( class_exists( 'PluginName\\Deactivator' ) ) {
\PluginName\Deactivator::deactivate();
}
}
Main Plugin Class (Singleton)
<?php
namespace PluginName;
defined( 'ABSPATH' ) || exit;
final class Plugin {
private static $instance = null;
public $version = PLUGIN_NAME_VERSION;
public static function instance() {
if ( null === self::$instance ) {
self::$instance = new self();
}
return self::$instance;
}
private function __construct() {
$this->define_constants();
$this->();
->();
}
{}
{
( );
}
{
}
{
PLUGIN_NAME_PATH . ;
( () ) {
PLUGIN_NAME_PATH . ;
}
( ! () ) {
PLUGIN_NAME_PATH . ;
}
}
{
( , ( , ), );
( , ( , ) );
}
{
( );
}
{
( ( ) ) {
( );
( ! ( [] ) ) {
( ( ) );
;
}
}
}
{
PLUGIN_NAME_URL . ( , );
}
{
PLUGIN_NAME_PATH . ( , );
}
}
Admin Settings Page
Settings Class
<?php
namespace PluginName;
defined( 'ABSPATH' ) || exit;
class Admin {
private $option_name = 'plugin_name_settings';
public function __construct() {
add_action( 'admin_menu', array( $this, 'add_menu_page' ) );
add_action( 'admin_init', array( $this, 'register_settings' ) );
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
}
public function add_menu_page() {
add_menu_page(
__( 'Plugin Name', 'plugin-name' ),
__( 'Plugin Name', ),
,
,
( , ),
,
);
(
,
( , ),
( , ),
,
,
( , )
);
}
{
(
,
->option_name,
(
=> ,
=> ( , ),
=> ->(),
)
);
(
,
( , ),
( , ),
);
(
,
( , ),
( , ),
,
,
(
=> ,
=> ( , ),
)
);
(
,
( , ),
( , ),
,
,
(
=> ,
=> ,
=> ( , ),
)
);
}
{
(
=> ,
=> ,
);
}
{
= ( ->option_name, ->() );
[ ] ?? ?? ->()[ ] ?? ;
}
{
= ();
[] = ( [] ) ? () [] : ;
[] = ( [] ?? );
;
}
{
( ! ( ) ) {
;
}
( ( [] ) ) {
(
,
,
( , ),
);
}
( );
<div {
. ( , ) . ;
}
{
= ->( [] );
<label>
<input
type=
name=
value=
( , );
/>
( [] );
</label>
}
{
= ->( [] );
= [] ?? ;
<input
type=
name=
value=
{
( !== ) {
;
}
(
,
PLUGIN_NAME_URL . ,
(),
PLUGIN_NAME_VERSION
);
(
,
PLUGIN_NAME_URL . ,
( ),
PLUGIN_NAME_VERSION,
);
(
,
,
(
=> ( ),
=> ( ),
)
);
}
}
AJAX Handler
<?php
namespace PluginName;
defined( 'ABSPATH' ) || exit;
class Ajax {
public function __construct() {
add_action( 'wp_ajax_plugin_name_action', array( $this, 'handle_action' ) );
add_action( 'wp_ajax_plugin_name_public', array( $this, 'handle_public_action' ) );
add_action( 'wp_ajax_nopriv_plugin_name_public', array( $this, 'handle_public_action' ) );
}
public function handle_action() {
if ( ! check_ajax_referer( 'plugin_name_admin', 'nonce', false ) ) {
wp_send_json_error(
( => ( , ) ),
);
}
( ! ( ) ) {
(
( => ( , ) ),
);
}
= ( [] ) ? ( ( [] ) ) : ;
( ( ) ) {
(
( => ( , ) ),
);
}
{
= ->( );
( ( => ) );
} ( \ ) {
(
( => ->() ),
);
}
}
{
;
}
{
( ! ( , , ) ) {
( ( => ( , ) ) );
}
= ( ( [] ?? ) );
( ->( ) ) {
(
( => ( , ) ),
);
}
( ( => ) );
}
{
= . ( );
= () ( );
( >= ) {
;
}
( , + , MINUTE_IN_SECONDS );
;
}
}
REST API Endpoint
<?php
namespace PluginName;
defined( 'ABSPATH' ) || exit;
class REST_API {
private $namespace = 'plugin-name/v1';
public function __construct() {
add_action( 'rest_api_init', array( $this, 'register_routes' ) );
}
public function register_routes() {
register_rest_route(
$this->namespace,
'/items',
array(
array(
'methods' => \WP_REST_Server::READABLE,
'callback' => array( $this, 'get_items' ),
'permission_callback' => array( $this, ),
=> ->(),
),
(
=> ::,
=> ( , ),
=> ( , ),
=> ->(),
),
)
);
(
->namespace,
,
(
(
=> ::,
=> ( , ),
=> ( , ),
=> (
=> (
=> {
( );
},
),
),
),
(
=> ::,
=> ( , ),
=> ( , ),
),
(
=> ::,
=> ( , ),
=> ( , ),
),
)
);
}
{
(
=> (
=> ,
=> ,
),
=> (
=> ,
=> ,
),
=> (
=> ,
),
);
}
{
(
=> (
=> ,
=> ,
),
=> (
=> ,
),
);
}
{
;
}
{
( );
}
{
= ->( );
= ->( );
= ->( );
= ();
( );
}
{
= ->( );
= ->( );
= (
(
=> ,
=> ,
=> ,
=> ,
)
);
( ( ) ) {
;
}
(
(
=> ,
=> ( , ),
)
);
}
}
Custom Post Type
<?php
namespace PluginName;
defined( 'ABSPATH' ) || exit;
class Post_Types {
public function __construct() {
add_action( 'init', array( $this, 'register_post_types' ) );
add_action( 'init', array( $this, 'register_taxonomies' ) );
}
public function register_post_types() {
$labels = array(
'name' => _x( 'Items', 'Post type general name', 'plugin-name' ),
'singular_name' => _x( 'Item', 'Post type singular name', 'plugin-name' ),
'menu_name' => _x( 'Items', 'Admin Menu text', ),
=> ( , ),
=> ( , ),
=> ( , ),
=> ( , ),
=> ( , ),
=> ( , ),
=> ( , ),
=> ( , ),
=> ( , ),
=> ( , ),
=> ( , ),
=> ( , ),
);
= (
=> ,
=> ,
=> ,
=> ,
=> ,
=> ,
=> ,
=> ( => ),
=> ,
=> ,
=> ,
=> ,
=> ,
=> ( , , , , ),
);
( , );
}
{
= (
=> ( , , ),
=> ( , , ),
=> ( , ),
=> ( , ),
=> ( , ),
=> ( , ),
=> ( , ),
=> ( , ),
=> ( , ),
=> ( , ),
=> ( , ),
);
= (
=> ,
=> ,
=> ,
=> ,
=> ,
=> ,
=> ( => ),
);
( , ( ), );
}
}
Uninstall
<?php
if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
exit;
}
delete_option( 'plugin_name_settings' );
delete_option( 'plugin_name_version' );
delete_transient( 'plugin_name_cache' );
delete_metadata( 'user', 0, 'plugin_name_user_data', '', true );
global $wpdb;
$wpdb->query( "DROP TABLE IF EXISTS {$wpdb->prefix}plugin_name_table" );
wp_clear_scheduled_hook( 'plugin_name_cron_event' );
Quality Checklist
Before releasing: