Back to Rules
PHP

WordPress PHP Best Practices: Essential Coding Standards and Rules for Developers

Claude Directory November 29, 2025
1 copies 1 downloads

Elevate your WordPress development with these fully rewritten PHP coding guidelines, focusing on security, performance, OOP principles, and WordPress-specific conventions for scalable, maintainable sites.

Rule Content
- **Fundamental Guidelines**
  - Deliver accurate, production-ready PHP code examples tailored for WordPress environments.
  - Maintain code readability and uniformity by following established PHP and WordPress standards.
  - Prioritize object-oriented design to enhance code modularity and scalability.
  - Maximize reusability by breaking down logic into modular components and eliminating redundant code.
  - Select intuitive, descriptive names for variables, functions, classes, and directories.
  - Standardize directories with lowercase letters and hyphens, such as wp-content/themes/your-theme.
  - Extend core functionality exclusively through WordPress actions and filters.
  - Incorporate detailed, explanatory comments to boost code comprehension and long-term upkeep.

- **PHP and WordPress Development Standards**
  - Leverage modern PHP 7.4+ capabilities, including typed properties and arrow functions, when suitable.
  - Strictly adhere to official WordPress PHP coding guidelines across all files.
  - Activate strict type declarations at the file start with declare(strict_types=1);.
  - Prefer native WordPress functions and APIs to minimize custom implementations.
  - Preserve conventional folder structures and naming for themes and plugins.
  - **Robust Error Management**
    - Utilize WP_DEBUG_LOG for systematic debugging and logging.
    - Deploy custom error handlers for specialized scenarios.
    - Employ try-catch mechanisms to gracefully handle exceptions.
  - Enforce data security via WordPress validation and sanitization utilities.
  - Secure form processing by always validating nonces on submissions.
  - **Secure Database Handling**
    - Rely on the $wpdb abstraction for all database operations.
    - Parameterize queries with prepare() to block SQL injection risks.
    - Handle schema modifications using dbDelta() for safe updates.

- **Dependency Management**
  - Ensure full compatibility with the current stable WordPress release.
  - Integrate Composer for efficient package handling in sophisticated themes or plugins.

- **Advanced WordPress Optimization Techniques**
  - Customize via child themes to safeguard against core updates.
  - Avoid altering WordPress core files; rely solely on hooks for extensions.
  - Centralize theme utilities in functions.php for organization.
  - Control access using WordPress user roles and capability checks.
  - Boost speed with the transients API for temporary data storage.
  - Offload intensive tasks to wp_cron() for asynchronous execution.
  - Develop comprehensive unit tests leveraging WP_UnitTestCase.
  - Support global reach with proper i18n via gettext and related functions.
  - Fortify security through nonce checks, input sanitization, and output escaping.
  - Properly register assets using wp_enqueue_script() and wp_enqueue_style().
  - Expand content models with custom post types and taxonomies as needed.
  - Securely store settings via the options API.
  - Implement efficient navigation with paginate_links() and similar tools.

- **Core Conventions for Scalable Code**
  - Build modular extensions following the WordPress plugin API.
  - Honor the template hierarchy in theme development for adaptability.
  - Secure inputs using native sanitization and validation functions.
  - Dynamically render content with template tags and conditionals.
  - Execute custom queries through $wpdb or WP_Query.
  - Enforce security with built-in authentication and authorization.
  - Process AJAX via admin-ajax.php or the REST API.
  - Ensure extensibility by integrating actions and filters universally.
  - Use transactional methods for critical database actions.
  - Automate recurring tasks with the WP_Cron system.

Comments

More Rules

View all
AI/ML

GLM-4.7 Optimized Config & System Prompt Designer

Expert system prompt for designing high-performance configurations tailored to GLM-4.7's strengths in coding, reasoning, tool use, and multilingual tasks, backed by benchmarks like SWE-bench and τ²-Bench.

C
Community
AI/ML

GLM-4.7 Open-Source Coding Expert: Optimized System Prompt

Leverage GLM-4.7's top benchmarks in SWE-bench, LiveCodeBench, and more with this system prompt designed for generating clean, secure, open-source-ready code, stunning UIs, and agentic workflows.

C
Community
AI/ML

GLM-4.7 Optimized Coding Agent

This system prompt transforms an AI into GLM-4.7, a benchmark-leading coding agent excelling in agentic workflows, tool use, multilingual coding, and complex reasoning with verified best practices for production-ready open-source development.

C
Community
DevOps

Agentic Dev Loop: Autonomous Jira-Driven Coding Agent with GitHub CI Self-Healing

Ralph, a persistent autonomous AI agent, implements Jira tickets through an endless loop until 100% test success, with GitHub PRs, Jules AI reviews, and CI self-healing for reliable development workflows.

C
Claude Directory
AI/ML

Türk Hukuku Uzmanı AI Agent: Güvenilir Yasal Danışman System Prompt

Claude'u Türk hukuku alanında dünyanın en önde gelen uzmanı olarak yapılandıran, yapılandırılmış yanıtlar, zorunlu uyarılar ve etik sınırlarla donatılmış profesyonel AI agent promptu.

C
Community
Database

PostgreSQL Best Practices: Expert Subagent Guide

Expert subagent providing production-ready PostgreSQL guidance on schema design, query optimization, security, performance tuning, and administration with structured, actionable advice and official references.

C
Claude Directory