WordPress Developer Ukraine, Kyiv
Build a Gutenberg Block with InnerBlocks and Block Templates

Build a Gutenberg Block with InnerBlocks and Block Templates

A Gutenberg block with InnerBlocks and a template Some content has a fixed shape: a feature card is always an icon, a heading, a paragraph and a button. A custom block with InnerBlocks gives editors exactly that shape, filled with core blocks they already know, and the theme styles one predictable structure instead of whatever…
Create a WooCommerce Payment Gateway Plugin from Scratch

Create a WooCommerce Payment Gateway Plugin from Scratch

A WooCommerce payment gateway plugin from scratch When a regional payment provider has no WooCommerce plugin, you write one. The gateway class extends WC_Payment_Gateway: settings for the API keys and a test mode, process_payment() to start the payment, and a webhook that confirms it. The common case today is a redirect gateway: the customer pays…
Add Custom User Roles and Capabilities to WordPress Programmatically

Add Custom User Roles and Capabilities to WordPress Programmatically

Add custom user roles and capabilities to WordPress programmatically A WordPress role is a named set of capabilities, stored in the wp_user_roles option. A user can have several roles, and code checks the capabilities, not the roles: current_user_can( 'edit_posts' ). Custom roles and capabilities let you give exactly the rights a job needs, instead of…
Write Unit Tests for WordPress Plugins with PHPUnit and WP-CLI Scaffold

Write Unit Tests for WordPress Plugins with PHPUnit and WP-CLI Scaffold

Write unit tests for WordPress plugins with PHPUnit and WP-CLI scaffolding WordPress unit tests run against a real WordPress loaded with a separate test database. Every test runs inside a database transaction that is rolled back afterwards, so each test starts from a clean state. WP-CLI generates the whole setup, and the base class WP_UnitTestCase…
Register Custom REST API Endpoints with Authentication and Schema Validation in WordPress

Register Custom REST API Endpoints with Authentication and Schema Valida ...

Register custom REST API endpoints with authentication and schema validation register_rest_route() adds your own endpoints to the WordPress REST API. A route has a namespace (by convention myplugin/v1), a path (with optional regex parameters) and one or more handlers, each with HTTP methods, a callback, a permission callback and a description of the parameters. The…
Migrate WooCommerce Orders to High-Performance Order Storage (HPOS)

Migrate WooCommerce Orders to High-Performance Order Storage (HPOS)

Migrate WooCommerce orders to High-Performance Order Storage (HPOS) High-Performance Order Storage moves WooCommerce orders out of wp_posts and wp_postmeta into their own tables: wc_orders, wc_order_addresses, wc_order_operational_data and wc_orders_meta. It appeared as an opt-in feature in WooCommerce 7.1, and with WooCommerce 8.2 (October 2023) it becomes the default for new stores. The reason is performance: in…
Run Custom SQL Queries in WordPress with $wpdb->prepare and get_results

Run Custom SQL Queries in WordPress with $wpdb->prepare and get_results

Run custom SQL queries in WordPress with $wpdb->prepare() and get_results() WP_Query covers most needs, but some queries it cannot express or makes inefficient: aggregations with GROUP BY, joins across several tables, bulk updates. For those, WordPress gives the $wpdb object, a direct connection to the database, with $wpdb->prepare() for safe parameters.