Opened 5 weeks ago
Closed 2 weeks ago
#64234 closed defect (bug) (fixed)
Remove functions from block pattern class files
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| Milestone: | 7.0 | Priority: | normal |
| Severity: | normal | Version: | |
| Component: | General | Keywords: | good-first-bug has-patch |
| Focuses: | coding-standards | Cc: |
Description
register_block_pattern_category and unregister_block_pattern_category should be moved out of src/wp-includes/class-wp-block-pattern-categories-registry.php into a separate file.
Same for register_block_pattern and unregister_block_pattern in src/wp-includes/class-wp-block-patterns-registry.php
It's bad practice to mix class declarations with function declarations in the same file.
Attachments (1)
Change History (8)
#3
@
3 weeks ago
Tested this with 6.9 Beta version in local setup and find out this:-
I tested by adding a test pattern category and a test pattern using a small code snippet in functions.php. Both showed up in the editor under Patterns, and I was able to insert the pattern without any problems.
I also checked unregistering, and that worked as expected too. No errors, no regressions, and everything behaves the same as before the functions were moved.
Please refer below screenshot:-
https://prnt.sc/5h9gLKqt2ffr
@
3 weeks ago
I’m attaching a patch for Trac #64234: 64234-move-functions.patch. Summary: Moved register_block_pattern_category() / unregister_block_pattern_category() into src/wp-includes/block-pattern-categories-functions.php. Moved register_block_pattern() / unregister_block_pattern() into src/wp-includes/block-patterns-functions.php. Removed the free function declarations from class-wp-block-pattern-categories-registry.php and class-wp-block-patterns-registry.php and added require_once to maintain backward compatibility. Tests performed: Committed local changes and created this patch. (Note: PHP CLI is not installed on my environment so I could not run php -l locally — happy to run additional checks if requested.) Local smoke testing (editor inserter and registration/unregistration) was performed and no issues observed. Please review and let me know if you prefer the require_once inclusion to be placed in a different loader file. Happy to update. — Dhiraj Joshi (dhiraj0901)
#4
@
3 weeks ago
I tested the patch which moves the functions into the new files (block-pattern-categories-functions.php and block-patterns-functions.php) and everything works as expected. My custom pattern category and test pattern both load correctly in the editor, and inserting them works without any errors.
Kindly refer below screenshot for results:-
https://prnt.sc/2ZLCiIjs6klM
This ticket was mentioned in PR #10567 on WordPress/wordpress-develop by @anukasha.
3 weeks ago
#5
- Keywords has-patch added; needs-patch removed
PR contains following changes:
- Moved
register_block_pattern_categoryandunregister_block_pattern_categoryfromsrc/wp-includes/class-wp-block-pattern-categories-registry.phptosrc/wp-includes/block-patterns.php - Moved
register_block_patternandunregister_block_patternfromsrc/wp-includes/class-wp-block-patterns-registry.phptosrc/wp-includes/block-patterns.php
Trac ticket: https://core.trac.wordpress.org/ticket/64234
Hi! I'd like to work on this ticket as my first contribution.
Plan: Move the mentioned functions into separate files while ensuring backward compatibility and updating includes.
I'll prepare a patch shortly.
– @coderalamin