Make WordPress Core

Opened 5 weeks ago

Closed 2 weeks ago

#64234 closed defect (bug) (fixed)

Remove functions from block pattern class files

Reported by: swissspidy's profile swissspidy Owned by: westonruter's profile westonruter
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)

64234-move-functions.patch (8.6 KB) - added by dhiraj0901 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)

Download all attachments as: .zip

Change History (8)

#1 @SergeyBiryukov
5 weeks ago

  • Milestone changed from Awaiting Review to 7.0

#2 @coderalamin
5 weeks ago

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

#3 @palak678
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

@dhiraj0901
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 @madhavishah01
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:

  1. Moved register_block_pattern_category and unregister_block_pattern_category from src/wp-includes/class-wp-block-pattern-categories-registry.php to src/wp-includes/block-patterns.php
  2. Moved register_block_pattern and unregister_block_pattern from src/wp-includes/class-wp-block-patterns-registry.php to src/wp-includes/block-patterns.php

Trac ticket: https://core.trac.wordpress.org/ticket/64234

#6 @westonruter
2 weeks ago

  • Owner set to westonruter
  • Status changed from new to reviewing

#7 @westonruter
2 weeks ago

  • Resolution set to fixed
  • Status changed from reviewing to closed

In 61348:

Block Editor: Move Block Patterns API functions to block-patterns.php.

Follow-up to [48156].

Props anukasha, dhiraj0901, swissspidy, palak678, madhavishah01.
See #50445.
Fixes #64234.

Note: See TracTickets for help on using tickets.