Skip to content

Fix/update hide ticket block logic to prevent errors in editor#72

Merged
gin0115 merged 2 commits into
trunkfrom
fix/update-hide-ticket-block-logic-to-prevent-errors-in-editor
Apr 9, 2026
Merged

Fix/update hide ticket block logic to prevent errors in editor#72
gin0115 merged 2 commits into
trunkfrom
fix/update-hide-ticket-block-logic-to-prevent-errors-in-editor

Conversation

@gin0115

@gin0115 gin0115 commented Apr 9, 2026

Copy link
Copy Markdown
Collaborator

Changes proposed in this Pull Request

This pull request updates the logic for unregistering and re-registering the simple-events/event-tickets block to ensure it is not available in the block inserter for certain post types. The change checks if the block type exists before modifying its registration and updates its supports property to disable the inserter.

Block registration logic improvements:

  • Added a check to ensure the simple-events/event-tickets block type exists before attempting to unregister and re-register it, preventing potential errors.
  • After unregistering, re-registers the block with its original settings but sets supports.inserter to false, hiding it from the block inserter for non-se-event post types.

Testing instructions

Mentions #71

Summary by CodeRabbit

  • Bug Fixes
    • Improved Event Tickets block handling to properly restrict its availability for insertion.

gin0115 added 2 commits April 9, 2026 12:12
…y its insertaion so it cant be inserted when nont on an event post
@coderabbitai

coderabbitai Bot commented Apr 9, 2026

Copy link
Copy Markdown

Walkthrough

The src/variations/blocks/unregister_blocks.js module was updated to add conditional block retrieval and re-registration logic. The change now first retrieves the simple-events/event-tickets block definition using getBlockType before attempting to unregister it. If the block type exists, the module unregisters and immediately re-registers the block with modified supports settings, specifically setting supports.inserter to false while preserving all other original supports properties and block settings through object spread syntax. This modification only applies when window.seSettings.postType is present and is not 'se-event'. The changes total 12 additions and 3 removals with no changes to exported or public entities.

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: updating block registration logic to prevent editor errors by hiding the ticket block. It is concise, specific, and directly relates to the primary objective of the changeset.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
src/variations/blocks/unregister_blocks.js (1)

6-10: Optional: extract the block name into a constant.

Using a single const BLOCK_NAME = 'simple-events/event-tickets'; would reduce repetition and avoid future string drift across getBlockType, unregisterBlockType, and registerBlockType.

♻️ Suggested small cleanup
 domReady( function () {
 	if ( window?.seSettings?.postType && 'se-event' !== window.seSettings.postType ) {
-		const blockType = getBlockType( 'simple-events/event-tickets' );
+		const BLOCK_NAME = 'simple-events/event-tickets';
+		const blockType = getBlockType( BLOCK_NAME );
 		if ( blockType ) {
-			unregisterBlockType( 'simple-events/event-tickets' );
-			registerBlockType( 'simple-events/event-tickets', {
+			unregisterBlockType( BLOCK_NAME );
+			registerBlockType( BLOCK_NAME, {
 				...blockType,
 				supports: {
 					...blockType.supports,
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/variations/blocks/unregister_blocks.js` around lines 6 - 10, Declare a
constant like BLOCK_NAME = 'simple-events/event-tickets' and replace the
repeated string literals in getBlockType, unregisterBlockType, and
registerBlockType calls with that constant (i.e., use getBlockType(BLOCK_NAME),
unregisterBlockType(BLOCK_NAME), registerBlockType(BLOCK_NAME, { ...blockType
})). This reduces repetition and prevents string drift while leaving the
existing logic in getBlockType, unregisterBlockType, and registerBlockType
unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@src/variations/blocks/unregister_blocks.js`:
- Around line 6-10: Declare a constant like BLOCK_NAME =
'simple-events/event-tickets' and replace the repeated string literals in
getBlockType, unregisterBlockType, and registerBlockType calls with that
constant (i.e., use getBlockType(BLOCK_NAME), unregisterBlockType(BLOCK_NAME),
registerBlockType(BLOCK_NAME, { ...blockType })). This reduces repetition and
prevents string drift while leaving the existing logic in getBlockType,
unregisterBlockType, and registerBlockType unchanged.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 92de2c3c-2484-4b25-a63c-fbef66ab0fa9

📥 Commits

Reviewing files that changed from the base of the PR and between f337b5a and e3deeac.

📒 Files selected for processing (1)
  • src/variations/blocks/unregister_blocks.js

@gin0115 gin0115 merged commit bc66c00 into trunk Apr 9, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant