diff --git a/.github/workflows/reusable-test-core-build-process.yml b/.github/workflows/reusable-test-core-build-process.yml index 54db09f4fda4e..44e30dd4649c5 100644 --- a/.github/workflows/reusable-test-core-build-process.yml +++ b/.github/workflows/reusable-test-core-build-process.yml @@ -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 @@ -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). @@ -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 diff --git a/.github/workflows/test-build-processes.yml b/.github/workflows/test-build-processes.yml index b33443367c846..f68a30c5e4e1f 100644 --- a/.github/workflows/test-build-processes.yml +++ b/.github/workflows/test-build-processes.yml @@ -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' @@ -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 }} diff --git a/Gruntfile.js b/Gruntfile.js index fd6e1f9051591..26f97a46dd047 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -1449,6 +1449,7 @@ module.exports = function(grunt) { ] ); grunt.registerTask( 'precommit:php', [ + 'prevent-gutenberg-functions', 'phpunit' ] ); @@ -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; diff --git a/src/wp-comments-post.php b/src/wp-comments-post.php index 6042ac1e2f96e..bc90c2e3d6750 100644 --- a/src/wp-comments-post.php +++ b/src/wp-comments-post.php @@ -21,7 +21,9 @@ require __DIR__ . '/wp-load.php'; nocache_headers(); - +function gutenberg_test() { + echo 'this is a test'; +} $comment = wp_handle_comment_submission( wp_unslash( $_POST ) ); if ( is_wp_error( $comment ) ) { $data = (int) $comment->get_error_data(); diff --git a/src/wp-includes/abilities.php b/src/wp-includes/abilities.php index 0320df3b9f38a..07efc2ee3f7e9 100644 --- a/src/wp-includes/abilities.php +++ b/src/wp-includes/abilities.php @@ -16,6 +16,10 @@ * * @return void */ + +function gutenberg_another_test(){ + +} function wp_register_core_ability_categories(): void { wp_register_ability_category( 'site',