Tip
Make sure you've read the core concepts behind Remote Data Blocks before extending the plugin.
Data sources and queries can be configured in the plugin UI, but sometimes, you need to extend the plugin to implement custom functionality. Remote Data Blocks provides extendable classes, global functions, hooks, and filters to help you connect to any data source, parse responses, and customize the display of data.
Here's a short overview of how data flows through the plugin when a post with a remote data block is rendered:
- WordPress core loads the post content, parses the blocks, and recognizes that a paragraph block has a block binding.
- WordPress core calls the block binding callback function:
BlockBindings::get_value()
. - The callback function inspects the paragraph block. Using the block context supplied by the parent remote data block, it determines which query to execute.
- The query is executed:
$query->execute()
(usually by delegating to a query runner). - Various properties of the query are requested by the query runner, including the endpoint, request headers, request method, and request body. Some of these properties are delegated to the data source (
$query->get_data_source()
). - The query is dispatched, and the response data is inspected, formatted into a consistent shape, and returned to the block binding callback function.
- The callback function extracts the requested field from the response data and returns it to WordPress core for rendering.
Providing a custom data source, query, or query runner gives you complete control over how data is fetched, processed, and rendered. In most cases, you only need to extend one of these classes to implement custom behavior. A common approach is to define a data source on the settings screen and then commit a custom query in code to fetch and process the data.
Here are some detailed overviews of these classes with notes on how and why to extend them:
Once you've defined your data source and queries, you can register a remote data block that uses them. That block can use a pattern for display. You can also use overrides to dynamically select the displayed content.
The examples provide detailed code samples of interacting with the plugin various methods of extending the plugin.
This repository includes tools for quickly starting a local development environment.