Skip to content

Commit a99f399

Browse files
committed
Add a Grunt task for detecting gutenberg_* names
1 parent a107147 commit a99f399

File tree

4 files changed

+54
-1
lines changed

4 files changed

+54
-1
lines changed

.github/workflows/reusable-test-core-build-process.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ jobs:
5252
# - Sets up Node.js.
5353
# - Logs debug information about the GitHub Action runner.
5454
# - Installs npm dependencies.
55+
# - Confirms that no PHP functions begin with `gutenberg_`.
56+
# - Runs the Emoji precommit task.
57+
# - Ensures that the Root Certificate files are correct.
5558
# - Builds WordPress to run from the desired location (src or build).
5659
# - Ensures version-controlled files are not modified or deleted.
5760
# - Creates a ZIP of the built WordPress files (when building to the build directory).
@@ -105,6 +108,9 @@ jobs:
105108
- name: Install npm Dependencies
106109
run: npm ci
107110

111+
- name: Check for PHP functions with the gutenberg_ prefix
112+
run: npm run grunt prevent-gutenberg-functions || true
113+
108114
- name: Run Emoji precommit task
109115
if: ${{ inputs.test-emoji }}
110116
run: npm run grunt precommit:emoji

Gruntfile.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1449,6 +1449,7 @@ module.exports = function(grunt) {
14491449
] );
14501450

14511451
grunt.registerTask( 'precommit:php', [
1452+
'prevent-gutenberg-functions',
14521453
'phpunit'
14531454
] );
14541455

@@ -1632,6 +1633,46 @@ module.exports = function(grunt) {
16321633
'usebanner'
16331634
] );
16341635

1636+
grunt.registerTask( 'prevent-gutenberg-functions', 'Check for the gutenberg_ prefix on function names', function() {
1637+
var done = this.async();
1638+
var found = false;
1639+
1640+
grunt.file.recurse( SOURCE_DIR, function( abspath, rootdir, subdir, filename ) {
1641+
// Skip non-PHP files, vendor, node_modules, and plugins directories.
1642+
if ( ! filename.match( /\.php$/ ) ||
1643+
abspath.match( /vendor|node_modules/ ) ||
1644+
abspath.match( /wp-content\/plugins/ ) ) {
1645+
return;
1646+
}
1647+
1648+
var content = grunt.file.read( abspath );
1649+
// Regex that captures the full function name including gutenberg_ prefix
1650+
var regex = /function\s+(gutenberg_[a-zA-Z0-9_]+)/g;
1651+
var match;
1652+
var matches = [];
1653+
1654+
while ( ( match = regex.exec( content ) ) !== null ) {
1655+
matches.push( match[1] ); // match[1] contains the captured group (function name)
1656+
}
1657+
1658+
if ( matches.length > 0 ) {
1659+
found = true;
1660+
grunt.log.error( 'Found gutenberg_ function in: ' + path.relative( SOURCE_DIR, abspath ) );
1661+
matches.forEach( function( funcName ) {
1662+
grunt.log.writeln(' - ' + funcName );
1663+
});
1664+
}
1665+
});
1666+
1667+
if ( found ) {
1668+
grunt.fail.warn( 'gutenberg_ prefixed functions found!' );
1669+
done( false );
1670+
} else {
1671+
grunt.log.ok( 'No gutenberg_ functions found.' );
1672+
done( true );
1673+
}
1674+
});
1675+
16351676
grunt.registerTask( 'certificates:upgrade-package', 'Upgrades the package responsible for supplying the certificate authority certificate store bundled with WordPress.', function() {
16361677
var done = this.async();
16371678
var flags = this.flags;

src/wp-comments-post.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@
2121
require __DIR__ . '/wp-load.php';
2222

2323
nocache_headers();
24-
24+
function gutenberg_test() {
25+
echo 'this is a test';
26+
}
2527
$comment = wp_handle_comment_submission( wp_unslash( $_POST ) );
2628
if ( is_wp_error( $comment ) ) {
2729
$data = (int) $comment->get_error_data();

src/wp-includes/abilities.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@
1616
*
1717
* @return void
1818
*/
19+
20+
function gutenberg_another_test(){
21+
22+
}
1923
function wp_register_core_ability_categories(): void {
2024
wp_register_ability_category(
2125
'site',

0 commit comments

Comments
 (0)