Mahamudul Hasan Rubel
HomeBlogCoursesAboutProjectsSkillsExperiencePhotosContact
Mahamudul Hasan Rubel

Senior Software Engineer crafting high-performance web applications and SaaS platforms.

Navigation

  • Home
  • Blog
  • Courses
  • About
  • Projects
  • Skills
  • Experience
  • Photos
  • Contact

Get in Touch

Available for senior/lead roles and consulting.

bd.mhrubel@gmail.comHire Me

© 2026 Mahamudul Hasan Rubel. All rights reserved.

Built with using Next.js 16 & Tailwind v4

Back to Blog
Lesson 17 of the Intermediate WordPress Plugins: REST API & React Admin course
WordPressJune 25, 20264 min read

Understanding WordPress Data Store Architecture | @wordpress/data Guide

Master the @wordpress/data architecture. Learn how the store, selector, and action pattern provides a robust, global state for your WordPress plugins.

@wordpress/dataReduxState architectureReactWordPress Developmentwordpressphpplugin-development

Previously in this course, we explored Handling Asynchronous State in React for WordPress Plugins, where we managed local loading and error states within individual components using useState. While useState is excellent for isolated UI logic, it falls short when multiple components need to share data or when your application grows in complexity.

In this lesson, we move beyond local state and into the @wordpress/data architecture. This is the same Redux-based system that powers the WordPress block editor, providing a predictable, global state layer for your plugins.

The Problem: Why Global State is Necessary

As your plugin expands, you'll find yourself "prop drilling"—passing data down through five layers of components just to reach a child that needs it. You might also notice that when you update a piece of data in one part of your dashboard, other parts stay stale because they don't share a single source of truth.

In a standard React app, you might reach for the Context API or Redux. In WordPress, we use @wordpress/data, which provides a standardized way to implement a centralized state. It solves three critical problems:

  1. Consistency: All components see the same data at the same time.
  2. Performance: With memoized selectors, components only re-render when the specific slice of data they care about changes.
  3. Efficiency: It handles the complex logic of fetching, caching, and updating data, preventing redundant API calls.

The Store/Selector/Action Pattern

The WordPress data architecture relies on a "Store," which acts as the single source of truth. To interact with this store, we follow a strict unidirectional flow:

1. The Store

The store holds your application's state. It is a structured object where your data lives. In our Knowledge Base project, the store will hold our collection of articles.

2. Selectors (Reading)

Selectors are functions used to retrieve data from the store. Instead of accessing state directly, you call a selector. Example: select('my-plugin/kb').getArticles(). Crucially, selectors are often memoized. If the underlying data hasn't changed, the selector returns the cached result, saving precious CPU cycles.

3. Actions (Writing)

Actions are plain JavaScript objects that describe what happened (e.g., ADD_ARTICLE). You "dispatch" an action to the store. A "Reducer" then listens for that action and updates the state immutably.

4. Resolvers (Fetching)

Resolvers are a unique WordPress feature. They are functions that automatically trigger API requests when a selector is called but the data isn't in the store yet. This keeps your components clean; they just ask for data, and the store handles the network orchestration.

A Concrete Example: Accessing Core Data

You are likely already using the WordPress data layer without realizing it. When you interact with the block editor, you are querying the core data stores.

JAVASCRIPT
import { useSelect } from CE9178">'@wordpress/data';

const MyComponent = () => {
    // We use useSelect to hook into the global store
    const user = useSelect((select) => {
        return select(CE9178">'core').getCurrentUser();
    }, []);

    if (!user) return <p>Loading...</p>;

    return <h1>Welcome back, {user.name}</h1>;
};

In this example, useSelect subscribes the component to the core data store. When the user object changes, the component automatically updates. If the user data wasn't already cached, the core store's internal resolver would have fetched it from the REST API automatically.

Hands-on Exercise: Exploring the Registry

To understand how this works in your own environment, open your browser’s console on your WordPress admin dashboard (where your plugin is active) and try to inspect the data registry:

  1. Open the Developer Tools (F12).
  2. Type wp.data.select('core').getAuthors() and hit enter.
  3. Observe the returned array of authors.
  4. Now, try wp.data.dispatch('core').saveEntityRecord('postType', 'post', { title: 'Test' }).

You are now interacting with the same architecture that powers the Gutenberg editor.

Common Pitfalls

  • Direct Mutation: Never mutate state directly (e.g., state.articles.push(item)). Always use actions and reducers to return a new state object. This ensures React's change detection triggers correctly.
  • Over-Selecting: Avoid selecting the entire state tree. If you only need articles, create a selector that returns only articles. If you select the whole state, your component will re-render whenever any part of the state changes, causing performance bottlenecks.
  • Ignoring Resolvers: Don't manually trigger apiFetch inside your components if a resolver can handle it. The store’s job is to manage the lifecycle of the data; let it do its job.

Recap

The @wordpress/data architecture provides a robust, scalable way to manage state in your WordPress admin screens. By mastering the store, selector, and action pattern, you ensure your plugin behaves predictably, performs efficiently, and integrates seamlessly with the rest of the WordPress ecosystem.

Next, we will begin the process of formalizing our own data layer by registering a custom store for our Knowledge Base plugin.

Up next: Registering a Custom Data Store

Previous lessonImplementing CRUD in the Admin UINext lesson Registering a Custom Data Store
Back to Blog

Similar Posts

WordPressJune 25, 20263 min read

Implementing Resolvers for Data Fetching in WordPress @wordpress/data

Learn how to implement resolvers in @wordpress/data to automate API data fetching. Discover how to sync your React state with the WordPress REST API seamlessly.

Read more
WordPressJune 25, 20263 min read

Defining Actions and Reducers for WordPress Data Stores

Master the WordPress Data layer by implementing formal Actions and Reducers. Learn to manage state mutation predictably in your React-based admin dashboard.

Part of the course

Intermediate WordPress Plugins: REST API & React Admin

intermediate · Lesson 17 of 45

  1. 1

    Setting up the WordPress Development Environment

    3 min
  2. 2

    Introduction to @wordpress/scripts

    3 min
  3. 3

    Configuring ESLint and Prettier

    3 min
Read more
WordPressJune 25, 20263 min read

Writing Selectors for Data Access: Memoization in WordPress

Master selectors in @wordpress/data to efficiently retrieve state. Learn to implement memoization for high-performance React admin interfaces in WordPress.

Read more
4

Localizing Data for JavaScript

3 min
  • 5

    Anatomy of a REST API Endpoint

    3 min
  • 6

    Implementing REST API Permission Callbacks

    3 min
  • 7

    Handling GET Requests in REST API

    3 min
  • 8

    Validating and Sanitizing API Arguments

    4 min
  • 9

    Creating POST Endpoints for Data Submission

    3 min
  • 10

    Updating Existing API Resources

    3 min
  • 11

    Handling Asynchronous State in React

    3 min
  • 12

    Building the Knowledge Base Service Layer

    3 min
  • 13

    Scaffolding the React Admin Dashboard

    3 min
  • 14

    Working with @wordpress/components

    3 min
  • 15

    Creating a React Form for Submissions

    3 min
  • 16

    Implementing CRUD in the Admin UI

    3 min
  • 17

    Understanding WordPress Data Store Architecture

    4 min
  • 18

    Registering a Custom Data Store

    3 min
  • 19

    Writing Selectors for Data Access

    3 min
  • 20

    Defining Actions and Reducers

    3 min
  • 21

    Implementing Resolvers for Data Fetching

    3 min
  • 22

    Optimizing Performance with Selectors

    3 min
  • 23

    Handling Complex State Dependencies

    Coming soon
  • 24

    Implementing Nonce Verification

    Coming soon
  • 25

    Advanced Sanitization Techniques

    Coming soon
  • 26

    Input Validation and Error Handling

    Coming soon
  • 27

    Protecting Admin Screens

    Coming soon
  • 28

    Production Build Pipeline

    Coming soon
  • 29

    Debugging React in the WordPress Admin

    Coming soon
  • 30

    Building Search and Filter Functionality

    Coming soon
  • 31

    Internationalization in React

    Coming soon
  • 32

    Managing File Uploads via REST API

    Coming soon
  • 33

    Optimizing API Response Times

    Coming soon
  • 34

    Working with Date and Time in React

    Coming soon
  • 35

    Implementing Drag-and-Drop Sorting

    Coming soon
  • 36

    Creating Custom Hooks for API Logic

    Coming soon
  • 37

    Integrating with Gutenberg Blocks

    Coming soon
  • 38

    Handling Conflict Resolution

    Coming soon
  • 39

    Building a Modal Confirmation System

    Coming soon
  • 40

    Implementing Activity Logging

    Coming soon
  • 41

    Using Webpack Aliases

    Coming soon
  • 42

    Unit Testing API Endpoints

    Coming soon
  • 43

    Unit Testing React Components

    Coming soon
  • 44

    Handling Large Datasets with GraphQL

    Coming soon
  • 45

    Implementing Real-time Updates with Web

    Coming soon
  • View full course