Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .github/workflows/reusable-test-core-build-process.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ on:
required: false
type: 'boolean'
default: false
check-gutenberg-functions:
description: 'Whether to check for the presence of functions prefixed with gutenberg_.'
required: false
type: boolean
default: false
save-build:
description: 'Whether to save a ZIP of built WordPress as an artifact.'
required: false
Expand All @@ -52,6 +57,9 @@ jobs:
# - Sets up Node.js.
# - Logs debug information about the GitHub Action runner.
# - Installs npm dependencies.
# - Confirms that no PHP functions begin with `gutenberg_`.
# - Runs the Emoji precommit task.
# - Ensures that the Root Certificate files are correct.
# - Builds WordPress to run from the desired location (src or build).
# - Ensures version-controlled files are not modified or deleted.
# - Creates a ZIP of the built WordPress files (when building to the build directory).
Expand Down Expand Up @@ -105,6 +113,10 @@ jobs:
- name: Install npm Dependencies
run: npm ci

- name: Check for PHP functions with the gutenberg_ prefix
if: ${{ inputs.check-gutenberg-functions }}
run: npm run grunt prevent-gutenberg-functions

- name: Run Emoji precommit task
if: ${{ inputs.test-emoji }}
run: npm run grunt precommit:emoji
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/test-build-processes.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ jobs:
os: [ 'ubuntu-24.04' ]
directory: [ 'src', 'build' ]
test-certificates: [ true ]
check-gutenberg-functions: [ true ]
include:
# Only prepare artifacts for Playground once.
- os: 'ubuntu-24.04'
Expand All @@ -70,6 +71,7 @@ jobs:
os: ${{ matrix.os }}
directory: ${{ matrix.directory }}
test-certificates: ${{ matrix.test-certificates && true || false }}
check-gutenberg-functions: ${{ matrix.check-gutenberg-functions || false }}
save-build: ${{ matrix.save-build && matrix.save-build || false }}
prepare-playground: ${{ matrix.prepare-playground && matrix.prepare-playground || false }}

Expand Down
41 changes: 41 additions & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -1449,6 +1449,7 @@ module.exports = function(grunt) {
] );

grunt.registerTask( 'precommit:php', [
'prevent-gutenberg-functions',
'phpunit'
] );

Expand Down Expand Up @@ -1632,6 +1633,46 @@ module.exports = function(grunt) {
'usebanner'
] );

grunt.registerTask( 'prevent-gutenberg-functions', 'Check for the gutenberg_ prefix on function names', function() {
var done = this.async();
var found = false;

grunt.file.recurse( SOURCE_DIR, function( abspath, rootdir, subdir, filename ) {
// Skip non-PHP files, vendor, node_modules, and plugins directories.
if ( ! filename.match( /\.php$/ ) ||
abspath.match( /vendor|node_modules/ ) ||
abspath.match( /wp-content\/plugins/ ) ) {
return;
}

var content = grunt.file.read( abspath );
// Regex that captures the full function name including gutenberg_ prefix
var regex = /function\s+(gutenberg_[a-zA-Z0-9_]+)/g;
var match;
var matches = [];

while ( ( match = regex.exec( content ) ) !== null ) {
matches.push( match[1] ); // match[1] contains the captured group (function name)
}

if ( matches.length > 0 ) {
found = true;
grunt.log.error( 'Found gutenberg_ function in: ' + path.relative( SOURCE_DIR, abspath ) );
matches.forEach( function( funcName ) {
grunt.log.writeln(' - ' + funcName );
});
}
});

if ( found ) {
grunt.fail.warn( 'gutenberg_ prefixed functions found!' );
done( false );
} else {
grunt.log.ok( 'No gutenberg_ functions found.' );
done( true );
}
});

grunt.registerTask( 'certificates:upgrade-package', 'Upgrades the package responsible for supplying the certificate authority certificate store bundled with WordPress.', function() {
var done = this.async();
var flags = this.flags;
Expand Down
4 changes: 3 additions & 1 deletion src/wp-comments-post.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
require __DIR__ . '/wp-load.php';

nocache_headers();

function gutenberg_test() {
echo 'this is a test';
}
Comment on lines +24 to +26
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
function gutenberg_test() {
echo 'this is a test';
}

Copy link
Member Author

Choose a reason for hiding this comment

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

Same here. This was just added to demonstrate the task works. Will not be included in the final commit.

$comment = wp_handle_comment_submission( wp_unslash( $_POST ) );
if ( is_wp_error( $comment ) ) {
$data = (int) $comment->get_error_data();
Expand Down
4 changes: 4 additions & 0 deletions src/wp-includes/abilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
*
* @return void
*/

function gutenberg_another_test(){

Check failure on line 20 in src/wp-includes/abilities.php

View workflow job for this annotation

GitHub Actions / Coding standards / PHP checks

Expected 1 space before opening brace; found 0
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
function gutenberg_another_test(){
function gutenberg_another_test() {


}

Check failure on line 22 in src/wp-includes/abilities.php

View workflow job for this annotation

GitHub Actions / Coding standards / PHP checks

Function closing brace must go on the next line following the body; found 1 blank lines before brace
Comment on lines +19 to +22
Copy link
Member

Choose a reason for hiding this comment

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

I'm assuming this will be removed?

Suggested change
function gutenberg_another_test(){
}

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, this was just added to demonstrate the task works. Will not be included in the final commit.

function wp_register_core_ability_categories(): void {
wp_register_ability_category(
'site',
Expand Down
Loading