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

Subscribe to the newsletter

Get new articles and course lessons delivered to your inbox. No spam, unsubscribe anytime.

© 2026 Mahamudul Hasan Rubel. All rights reserved.

Built with using Next.js 16 & Tailwind v4

Back to Blog
Lesson 52 of the Advanced WordPress Plugin Engineering: Scale, Security & React UIs course
WordPressJune 28, 20263 min read

Custom Gutenberg Block Controls: InspectorControls and State Sync

Master Gutenberg block controls by using InspectorControls, custom React inputs, and precise attribute synchronization to build professional editor experiences.

GutenbergReactWordPressBlock EditorUIphpplugin-development

Previously in this course, we covered the fundamentals of Block API v2 Essentials and advanced layout patterns like InnerBlocks and Nested Structures. While those lessons focused on the editor canvas, this lesson shifts our focus to the sidebar—the "command center" of your block—where complex configurations live.

The Anatomy of InspectorControls

In Gutenberg, InspectorControls is a specialized component that renders content into the block settings sidebar. It is the designated space for configuration that doesn't belong directly on the canvas, such as toggle switches, color pickers, or API-driven data selectors.

Because our Knowledge Base plugin requires users to configure specific settings (like category filtering or display limits), we cannot rely solely on the main editor area. We must synchronize our React state with the block's attributes defined in block.json.

Building a Custom Configuration Sidebar

To implement this, you'll need the @wordpress/block-editor and @wordpress/components packages. The core pattern involves wrapping your inputs in an InspectorControls component and ensuring your setAttributes function triggers a re-render.

Worked Example: Configuring a Knowledge Base Query

Let’s add a sidebar control to our kb-post-list block that allows the user to toggle whether or not to show the post excerpt.

JSX
import { InspectorControls } from CE9178">'@wordpress/block-editor';
import { PanelBody, ToggleControl } from CE9178">'@wordpress/components';
import { __ } from CE9178">'@wordpress/i18n';

export default function Edit({ attributes, setAttributes }) {
    const { showExcerpt } = attributes;

    return (
        <>
            <InspectorControls>
                <PanelBody title={__(CE9178">'Knowledge Base Settings', CE9178">'kb-plugin')}>
                    <ToggleControl
                        label={__(CE9178">'Show Post Excerpt', CE9178">'kb-plugin')}
                        checked={showExcerpt}
                        onChange={(value) => setAttributes({ showExcerpt: value })}
                    />
                </PanelBody>
            </InspectorControls>
            
            <div className="kb-block-preview">
                {/* Block content logic here */}
            </div>
        </>
    );
}

Advanced Synchronization Patterns

Simple toggles are easy, but real-world requirements often involve fetching remote data—like a list of categories—to populate a dropdown. You’ll want to combine InspectorControls with the techniques we discussed in Custom REST API Integration: Fetching Data in React.

When dealing with complex objects or arrays (e.g., a selection of multiple categories), avoid storing the entire object in your attributes. Store only the ID, and use a selector to hydrate the data in the UI. This keeps your block.json attributes clean and prevents unnecessary bloat in the database.

Hands-on Exercise

  1. Open your Knowledge Base plugin's kb-post-list block.
  2. Add a new attribute postsPerPage (integer) to your block.json.
  3. Inside your Edit.js, add a RangeControl within an InspectorControls panel.
  4. Bind the RangeControl to postsPerPage using setAttributes.
  5. Verify that changing the value in the sidebar updates the block preview on the canvas.

Common Pitfalls

  • Forgetting the React Fragment: InspectorControls must be a sibling to your block's main edit components inside a fragment (<>...</>) or a wrapper div. If you place it inside the block's primary markup, it will render literally on the page.
  • Direct State Mutation: Never modify attributes directly (e.g., attributes.showExcerpt = true). Always use the setAttributes function provided by the block's edit method to ensure the editor registers the change and triggers a save.
  • Over-complicating Attributes: If you find yourself storing massive JSON strings in an attribute, you’re likely doing too much in the block. Use a custom REST API endpoint to fetch the data on the fly rather than baking it into the post content.

Recap

We've successfully extended the block editor UI by:

  1. Utilizing InspectorControls to create a dedicated settings panel.
  2. Implementing standard WordPress components like ToggleControl for consistent UX.
  3. Maintaining strict state synchronization via setAttributes.

These controls are essential for turning a basic block into a production-ready configuration tool for your users.

Up next: We will dive into Block Transforms and Deprecation to ensure your block remains resilient as your plugin evolves.

Previous lessonMulti-tenancy ConsiderationsNext lesson Block Transforms and Deprecation
Back to Blog

Similar Posts

WordPressJune 25, 20263 min read

Working with @wordpress/components for WordPress Admin UIs

Master the @wordpress/components library to build consistent, accessible, and native-feeling WordPress admin interfaces for your plugin's React dashboard.

Read more
WordPressJune 28, 20264 min read

Advanced State Persistence: Syncing Redux with localStorage

Learn to persist Gutenberg state using Redux middleware. We’ll show you how to sync editor data to localStorage for a seamless, high-performance experience.

Part of the course

Advanced WordPress Plugin Engineering: Scale, Security & React UIs

advanced · Lesson 52 of 56

  1. 1

    Modern PHP Standards for WordPress

    3 min
  2. 2

    Dependency Injection Basics

    3 min
  3. 3

    Architecting Service Providers

    3 min
Read more
WordPressJune 28, 20264 min read

Block Transforms and Deprecation: Managing Gutenberg Versioning

Master Gutenberg block evolution. Learn to implement block transforms and deprecation handlers to ensure seamless backward compatibility for your plugin.

Read more
  • 4

    Advanced Custom Database Tables

    4 min
  • 5

    Data Access Objects Pattern

    3 min
  • 6

    Query Caching Strategies

    4 min
  • 7

    Database Indexing for Scale

    4 min
  • 8

    Sanitization Pipelines

    3 min
  • 9

    Output Escaping Patterns

    4 min
  • 10

    Nonce Management Architecture

    3 min
  • 11

    Capability and Permission Systems

    3 min
  • 12

    Preventing SQL Injection

    4 min
  • 13

    Secure REST API Endpoints

    3 min
  • 14

    Cross-Site Scripting Mitigation

    4 min
  • 15

    Auditing Plugin Security

    4 min
  • 16

    Modern Build Tooling with Vite

    3 min
  • 17

    React Component Architecture

    3 min
  • 18

    State Management with @wordpress/data

    3 min
  • 19

    Block API v2 Essentials

    3 min
  • 20

    InnerBlocks and Nested Structures

    3 min
  • 21

    Custom REST API Integration

    3 min
  • 22

    Optimizing React Rendering

    4 min
  • 23

    Code Splitting and Lazy Loading

    4 min
  • 24

    Advanced Admin Dashboards

    4 min
  • 25

    Component Library Design

    3 min
  • 26

    Linting and Code Quality

    3 min
  • 27

    Unit Testing with PHPUnit

    4 min
  • 28

    Integration Testing

    3 min
  • 29

    Test-Driven Development Workflow

    4 min
  • 30

    Automated CI/CD Pipelines

    3 min
  • 31

    Versioning and Release Management

    3 min
  • 32

    Internationalization (i18n)

    3 min
  • 33

    Licensing Infrastructure

    4 min
  • 34

    Automated Update API

    3 min
  • 35

    Documentation Systems

    4 min
  • 36

    Refactoring for Distribution

    4 min
  • 37

    Plugin Lifecycle Management

    3 min
  • 38

    Performance Monitoring

    3 min
  • 39

    Advanced Error Handling

    4 min
  • 40

    User Feedback Loops

    3 min
  • 41

    Handling Plugin Conflicts

    4 min
  • 42

    Advanced Hook Management

    4 min
  • 43

    Database Schema Evolution

    3 min
  • 44

    High-Concurrency Data Handling

    4 min
  • 45

    Object-Relational Mapping (ORM) Lite

    3 min
  • 46

    Advanced Query Filters

    4 min
  • 47

    Secure File Handling

    3 min
  • 48

    Background Processing

    4 min
  • 49

    Transient Caching Patterns

    4 min
  • 50

    Advanced Nonce Security

    3 min
  • 51

    Multi-tenancy Considerations

    3 min
  • 52

    Custom Gutenberg Block Controls

    3 min
  • 53

    Block Transforms and Deprecation

    4 min
  • 54

    Dynamic Block Rendering

    4 min
  • 55

    Advanced State Persistence

    4 min
  • 56

    Custom Hooks for React

    3 min
  • View full course