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 18 of the Intermediate WordPress Plugins: REST API & React Admin course
WordPressJune 25, 20263 min read

Registering a Custom Data Store in WordPress @wordpress/data

Learn to register a custom data store in WordPress using @wordpress/data. Master createReduxStore and store registration to centralize your plugin's state.

@wordpress/dataState managementStore registrationReactWordPressphpplugin-development

Previously in this course, we explored the Understanding WordPress Data Store Architecture | @wordpress/data Guide to grasp the theoretical foundations of the store/selector/action pattern. In this lesson, we move from theory to implementation by creating and registering a custom data store for our Knowledge Base plugin.

By centralizing our state, we avoid "prop drilling" and ensure that multiple components can access the same source of truth for our Knowledge Base articles.

The Mechanics of Store Registration

In WordPress, state management is handled by a global registry provided by the @wordpress/data package. To add our own data to this ecosystem, we use createReduxStore, which follows the standard Redux pattern but is optimized for the WordPress environment.

Registering a store involves three primary steps:

  1. Defining the Store Configuration: Creating an object that contains our initial state, selectors, actions, and reducers.
  2. Creating the Store: Using createReduxStore to generate the store instance.
  3. Registration: Passing that instance to the register method of the wp.data registry.

Worked Example: Scaffolding the Knowledge Base Store

Let's create a new file, src/store/index.js, to house our store configuration. For now, we will focus on defining the initial state and performing the registration.

JAVASCRIPT
/**
 * External dependencies
 */
import { createReduxStore, register } from CE9178">'@wordpress/data';

/**
 * Initial State
 */
const DEFAULT_STATE = {
    items: [],
    isFetching: false,
    error: null,
};

/**
 * Store Configuration
 */
const storeConfig = {
    reducer(state = DEFAULT_STATE, action) {
        // We will fill this in next lesson
        return state;
    },
    selectors: {
        getItems(state) {
            return state.items;
        }
    },
    actions: {
        setItems(items) {
            return { type: CE9178">'SET_ITEMS', items };
        }
    }
};

/**
 * Create and register the store
 */
const store = createReduxStore(CE9178">'kb/knowledge-base', storeConfig);
register(store);

Integrating into the Plugin

Once the store is registered, it becomes available globally in the WordPress admin. You must ensure this file is imported in your main entry point (e.g., src/index.js) so that the code executes when the page loads.

Simply adding import './store'; at the top of your main entry point ensures that the registration logic runs before your React components attempt to access the store via useSelect or useDispatch.

Hands-on Exercise

  1. Create a src/store directory in your plugin folder.
  2. Create src/store/index.js and implement the createReduxStore call using the namespace kb/knowledge-base.
  3. Import this file in your main src/index.js entry point.
  4. Open your browser console on the admin page and type wp.data.select('kb/knowledge-base').getItems(). Verify that it returns the empty array from your DEFAULT_STATE.

Common Pitfalls

  • Namespace Collisions: Always prefix your store name (e.g., kb/). Using a generic name like data will conflict with core WordPress stores and cause unpredictable behavior.
  • Late Registration: If you try to access the store before the registration code runs, the registry will return undefined. Always import your store file at the very top of your application entry point.
  • Ignoring the Registry: Remember that @wordpress/data is a singleton registry. You don't need to pass the store instance down through props; once registered, any component in your React tree can access it using the standard hooks.

Recap

We have successfully moved beyond local component state—which we previously managed using techniques like those described in Handling Asynchronous State in React for WordPress Plugins—into a formal, global state management pattern. By using createReduxStore and register, we have created a scalable foundation for the Knowledge Base plugin that allows for complex data interactions across the entire admin dashboard.

Up next: We will implement the logic to query this store using custom selectors and memoization.

Previous lessonUnderstanding WordPress Data Store ArchitectureNext lesson Writing Selectors for Data Access
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

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.

Part of the course

Intermediate WordPress Plugins: REST API & React Admin

intermediate · Lesson 18 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 26, 20264 min read

Handling Complex State Dependencies in WordPress Data Stores

Master complex state management by chaining selectors and coordinating cross-component dependencies in your WordPress Data store for consistent, clean UI logic.

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

    4 min
  • 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