daily notes

WP_Query What WP_Query is WP_Query is WordPress’s main class for querying posts from the database. It powers: The main loop Custom loops (recommended way) Complex queries (meta, tax, date, pagination, etc.) Use it instead of query_posts() (which you should basically never use). Basic Usage Pattern $args = [ 'post_type' => 'post', 'posts_per_page' => 10, ]; $query = new WP_Query($args); if ($query->have_posts()) { while ($query->have_posts()) { $query->the_post(); the_title(); } wp_reset_postdata(); } Key points Always call wp_reset_postdata() after a custom loop $query->the_post() sets up global $post Common Query Arguments Post Type 'post_type' => 'post' // or 'page', 'product', 'custom_post_type' Multiple post types: ...

February 5, 2026 · 2 min · Ashish Verma

daily notes

WordPress uses a MySQL (or MariaDB) database. By default, it consists of 12 core tables. The 12 core tables are: wp_commentmeta: Stores extra information (metadata) about comments. wp_comments: Contains all comments on posts and pages. wp_links: Stores information related to the Links feature (often deprecated but still included for backward compatibility). wp_options: Stores general site settings, configuration options, and temporary data (transients) for themes and plugins.(Site URL, Admin email, active plugins, and theme configurations). ...

February 4, 2026 · 4 min · Ashish Verma

daily notes

defined( 'ABSPATH' ) || exit; contains the absolute path to the WordPress root directory. If php run directly, it exits. $this Refers to the current object instance Used for non-static properties and methods Only available inside object context self:: Refers to the class itself Used for static properties and methods Does NOT require an object add_action( 'init', array( $post_types, 'register_post_types' ) ) is a callable reference that means: When the init hook fires, call $post_types->register_post_types() ...

February 3, 2026 · 2 min · Ashish Verma

daily notes

Create a folder named plugin name in wp-content/plugins directory. Inside it create a php file with same name as plugin name. It should contain header which is used by wordpress to display meta information about it. WordPress uses gettext via wrapper functions to make strings translatable. A text domain uniquely identifies your plugin’s translations. Must match the plugin slug (folder or main file name). /* * Plugin Name: My Plugin * Text Domain: my-plugin */ Domain Path Defines where translation files live. Defaults to the plugin folder. If using a /languages directory, add to header: /* * Domain Path: /languages */ __( 'Text', 'my-plugin' ) Returns a translated string. _e( 'Text', 'my-plugin' ) Echoes the translated string. Uninstall hook Method 1: register_uninstall_hook( __FILE__, 'pluginprefix_function_to_run' ); Method 2: To use this method you need to create an uninstall.php file inside the root folder of your plugin. This magic file is run automatically when the users deletes the plugin. /plugin-name/uninstall.php If both are defined, uninstall.php will be used. // if uninstall.php is not called by WordPress, die if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) { die; } $option_name = 'wporg_option'; delete_option( $option_name ); // for site options in Multisite delete_site_option( $option_name ); // drop a custom database table global $wpdb; $wpdb->query( "DROP TABLE IF EXISTS {$wpdb->prefix}mytable" ); wpdb This is WordPress’s global database object. It’s an instance of the wpdb class. You use it to safely interact with the WordPress database instead of using raw mysqli or PDO. require Includes and loads a PHP file so its code can run. use Imports a namespace or class so you can refer to it with a shorter name. use works after the code is loaded (so you still need require or autoloading). shortcode add_shortcode('wporg', 'wporg_shortcode'); function wporg_shortcode( $atts = [], $content = null) { // do something to $content // always return return $content; } [wporg] is your new shortcode. The use of the shortcode will trigger the wporg_shortcode callback function. Actions allow you to add data or change how WordPress operates. Callback functions for Actions will run at a specific point in the execution of WordPress. Actions do not return anything back to the calling hook,(i.e., do_action() do not return anythin) ...

February 2, 2026 · 4 min · Ashish Verma

daily notes

Plugins are packages of code that extend the core functionality of WordPress. WordPress plugins are made up of PHP code and can include other assets such as images, CSS, and JavaScript. FileDoc comment example: /** * Get all image nodes. * * @param \DOMNode $node The \DOMDocument instance * @param boolean $strict If the document has to be valid * * @return \DOMNode */ public function getImageNodes(\DOMNode $node, $strict = true): \DOMNode { // ... } Example: Hello Dolly Plugin <?php /** * @package Hello_Dolly * @version 1.7.2 */ /* Plugin Name: Hello Dolly Plugin URI: http://wordpress.org/plugins/hello-dolly/ Description: This is not just a plugin, it symbolizes the hope and enthusiasm of an entire generation summed up in two words sung most famously by Louis Armstrong: Hello, Dolly. When activated you will randomly see a lyric from <cite>Hello, Dolly</cite> in the upper right of your admin screen on every page. Author: Matt Mullenweg Version: 1.7.2 Author URI: http://ma.tt/ */ function hello_dolly_get_lyric() { /** These are the lyrics to Hello Dolly */ $lyrics = "Hello, Dolly Well, hello, Dolly It's so nice to have you back where you belong You're lookin' swell, Dolly I can tell, Dolly You're still glowin', you're still crowin' You're still goin' strong I feel the room swayin' While the band's playin' One of our old favorite songs from way back when So, take her wrap, fellas Dolly, never go away again Hello, Dolly Well, hello, Dolly It's so nice to have you back where you belong You're lookin' swell, Dolly I can tell, Dolly You're still glowin', you're still crowin' You're still goin' strong I feel the room swayin' While the band's playin' One of our old favorite songs from way back when So, golly, gee, fellas Have a little faith in me, fellas Dolly, never go away Promise, you'll never go away Dolly'll never go away again"; // Here we split it into lines. $lyrics = explode( "\n", $lyrics ); // And then randomly choose a line. return wptexturize( $lyrics[ mt_rand( 0, count( $lyrics ) - 1 ) ] ); } // This just echoes the chosen line, we'll position it later. function hello_dolly() { $chosen = hello_dolly_get_lyric(); $lang = ''; if ( 'en_' !== substr( get_user_locale(), 0, 3 ) ) { $lang = ' lang="en"'; } printf( '<p id="dolly"><span class="screen-reader-text">%s </span><span dir="ltr"%s>%s</span></p>', __( 'Quote from Hello Dolly song, by Jerry Herman:', 'hello-dolly' ), $lang, $chosen ); } // Now we set that function up to execute when the admin_notices action is called. add_action( 'admin_notices', 'hello_dolly' ); // We need some CSS to position the paragraph. function dolly_css() { echo " <style type='text/css'> #dolly { float: right; padding: 5px 10px; margin: 0; font-size: 12px; line-height: 1.6666; } .rtl #dolly { float: left; } .block-editor-page #dolly { display: none; } @media screen and (max-width: 782px) { #dolly, .rtl #dolly { float: none; padding-left: 0; padding-right: 0; } } </style> "; } add_action( 'admin_head', 'dolly_css' ); A WordPress installation is a website/project that is built using WordPress. It is a folder on a server (or your local machine) that contains files like: # example files in wordpress project wp-admin/ wp-content/ wp-includes/ wp-config.php index.php # Create your plugin here your-wordpress-site/ └── wp-content/ └── plugins/ └── plugin-name/ └── plugin-name.php Header format. Simple and extended: /* * Plugin Name: YOUR PLUGIN NAME */ /** * Plugin Name * * @package PluginPackage * @author Your Name * @copyright 2019 Your Name or Company Name * @license GPL-2.0-or-later * * @wordpress-plugin * Plugin Name: Plugin Name * Plugin URI: https://example.com/plugin-name * Description: Description of the plugin. * Version: 1.0.0 * Requires at least: 5.2 * Requires PHP: 7.2 * Author: Your Name * Author URI: https://example.com * Text Domain: plugin-slug * License: GPL v2 or later * License URI: http://www.gnu.org/licenses/gpl-2.0.txt * Update URI: https://example.com/my-plugin/ * Requires Plugins: my-plugin, yet-another-plugin */ Activation and deactivation hooks let your plugin react to being turned on or off, so it can set itself up properly and clean up after itself — without doing unnecessary work every time WordPress runs. The deactivation hook is sometimes confused with the uninstall hook. The uninstall hook is best suited to delete all data permanently such as deleting plugin options and custom tables, etc. register_activation_hook( __FILE__, 'pluginprefix_function_to_run' ); register_deactivation_hook( __FILE__, 'pluginprefix_function_to_run' ); # first parameter in each of these functions refers to your main plugin file PHP provides a number of functions to verify existence of variables, functions, classes and constants. All of these will return true if the entity exists. Variables: isset() (includes arrays, objects, etc.) Functions: function_exists() Classes: class_exists() Constants: defined() The root level of your plugin directory should contain your plugin-name.php file and, optionally, your uninstall.php file. All other files should be organized into sub folders whenever possible. /plugin-name plugin-name.php uninstall.php /languages /includes /admin /js /css /images /public /js /css /images __FILE__ is a PHP magic constant. It resolves to the full filesystem path of the current PHP file at runtime. Authorization checking: # Example of a core wordpress fn to chck permission current_user_can( 'edit_others_posts' ); i18n and l10n i18n refers to preparing a theme or plugin so it can be easily translated into multiple languages. This involves wrapping all text strings in translation functions (__(), _e(), _x(), etc.) so they can later be translated without editing the code. 10n stands for “localization” (10 letters between “l” and “n”). This is the process of translating and adapting a theme/plugin for a specific language or region. It uses the internationalization groundwork (i18n) to actually provide translated content to users. Internationalisation (i18n) Localisation (l10n) Product design & architecture Language & cultural adaptation One-time (mostly) effort Repeated for each locale Done by developers Done by translators & local experts Makes localisation possible Uses internationalisation __('Settings saved', 'super-plugin'); : translates string for localisation. It is core wordpress function. ...

January 30, 2026 · 6 min · Ashish Verma

daily notes

Traits Traits are used to declare methods that can be used in multiple classes. Traits can have methods and abstract methods that can be used in multiple classes, and the methods can have any access modifier (public, private, or protected). Traits allow you to reuse several methods freely in different classes, and are a mechanism for code reuse. trait TraitName { // some code...} class MyClass { use TraitName; } // ---------------------------------- <?php // Define a trait trait message1 { public function msg1() { echo "PHP OOP is fun! "; } } // Use the trait in a class class Welcome { use message1; } $obj = new Welcome(); $obj->msg1(); ?> Static methods and properties <?php class pi { // static property public static $value = 3.14159; } // Get static property directly echo pi::$value; ?> <?php class greeting { // static method public static function welcome() { echo "Hello World!"; } } // Call static method directly greeting::welcome(); ?> The purpose of these lessons is to get a conceptual understanding of PHPUnit testing using WP_PHPUnit for WordPress plugins/themes. ...

January 29, 2026 · 2 min · Ashish Verma

daily notes

Coding standards help avoid common coding errors, improve the readability of code, and simplify modification. They ensure that files within the project appear as if they were created by a single person. The WordPress commitment is to conform to all WCAG 2.2 Level A and Level AA guidelines. Conformance to level AAA success criteria is encouraged where relevant, as is exceeding the accessibility of any of these guidelines. Level A success criteria address concerns considered to be accessibility barriers on a very wide scale that will prevent many people from accessing the site and the minimum set of accomplished goals required for the majority of web-based interfaces. ...

January 28, 2026 · 4 min · Ashish Verma

daily notes

WP_PHPUnit Testing Architecture Purpose of WP_PHPUnit WP_PHPUnit extends PHPUnit to work within the WordPress ecosystem. Its main goal is to validate WordPress-specific behavior that cannot be tested in isolation. Test Lifecycle in WordPress Each test follows a predictable lifecycle managed by WP_PHPUnit. Lifecycle Phases setUp() Runs before each test method. Used to create test data (users, posts, options). Database transaction begins here. Test Execution The actual test logic runs. Assertions check expected vs actual behavior. ...

January 27, 2026 · 2 min · Ashish Verma

daily notes

Full Site Editing (FSE) Full Site Editing (FSE) is a modern WordPress feature introduced in WordPress 5.9. It allows users to edit the entire website visually (header, footer, templates, layouts) without writing code. FSE is built on the Gutenberg block editor and works only with Block Themes. Full Site Editing (FSE) FSE is an umbrella project that includes multiple Gutenberg-related features. It focuses on user-friendly site customization using blocks. Users can design pages, posts, headers, footers, and templates directly from the dashboard. Core Concepts of Full Site Editing 1. Site Editor Used to build and edit the entire site using blocks. Allows customization of templates, layouts, menus, and styles. Accessible via Appearance → Editor. Works only with Block Themes. 2. Blocks Blocks are individual, reusable components (e.g., paragraph, image, button). Pages, posts, and templates are created by combining multiple blocks. Blocks are customizable and flexible. 3. Templates A template is a collection of blocks arranged for a specific purpose. Used for pages, posts, archives, search results, etc. Examples: Single Post template, Page template, Archive template. 4. Block Themes Themes designed specifically for Full Site Editing. Fully editable using the Site Editor. Include a theme.json file to control: Colors Typography Layout settings Block styles Key Benefits of Full Site Editing No coding required for site-wide changes. Unified editing experience for content and design. Better control over global styles and layouts. Faster and more consistent site customization. Multisite / Network WordPress Multisite allows multiple websites to run from a single WordPress installation. All sites share the same core files but have: Separate dashboards Separate content Individual users Managed by a Network Admin (Super Admin) Multisite Setup Basics Enabled by adding one line of code in wp-config.php. Can be created easily using LocalWP. Multisite options during setup: Single Site (default) Subdirectory Multisite Example: myproject.local/site1 Subdomain Multisite Example: site1.myproject.local Use Cases of Multisite Managing multiple blogs or websites from one dashboard. Useful for universities, companies, or agencies. Centralized updates and plugin management.

January 23, 2026 · 2 min · Ashish Verma

daily notes

WordPress Customizing Themes & Plugins Themes control the appearance of a WordPress site. Plugins extend functionality beyond WordPress core features. WordPress relies heavily on plugins for customization and scalability. Multiple themes can be installed, but only one theme can be active at a time. Theme and plugin auto-updates can be enabled or disabled. WordPress Customizer Allows real-time visual customization of site settings. Common options include: Site Identity (logo, title, tagline) Colors & typography Menus & widgets Homepage settings WordPress Editor (Block Editor / Gutenberg) Default editor since WordPress 5.0. Uses a block-based content creation approach. Everything is a block: text, images, buttons, headings, etc. Supports: Block patterns Reusable / Synced blocks Block directory for third-party blocks WordPress Terminology (Key Terms) Back-end: Admin dashboard for managing the site. Front-end: Public-facing part of the website. CMS: Content Management System. Theme: Controls site design and layout. Plugin: Adds or modifies functionality. Permalink: Permanent URL for posts/pages. Widgets: Small content blocks in sidebars or footers. Menu / Navigation: Structured links for site navigation. Sidebar: Widget-ready area (can have multiple). User Roles: Define access and permissions. Nonce: Security token to prevent unauthorized actions. Full Site Editing (FSE) Introduced in WordPress 5.9. Enables editing the entire site using blocks (no code required). Works only with Block Themes. Core Concepts Site Editor: Edit templates, headers, footers, and layouts. Blocks: Building units of content and layout. Templates: Define structure for pages, posts, archives, etc. Template Parts: Reusable sections (header, footer). Global Styles: Control site-wide typography, colors, and spacing via theme.json Key Takeaways WordPress customization relies on themes, plugins, and blocks. Gutenberg and FSE shift WordPress toward a visual, block-first editing experience. Block themes + Global Styles = powerful, code-free site customization. Understanding WordPress terminology improves development and collaboration.

January 22, 2026 · 2 min · Ashish Verma