@@ -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 ( / \. p h p $ / ) ||
1643+ abspath . match ( / v e n d o r | n o d e _ m o d u l e s / ) ||
1644+ abspath . match ( / w p - c o n t e n t \/ p l u g i n s / ) ) {
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 = / f u n c t i o n \s + ( g u t e n b e r g _ [ a - z A - Z 0 - 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 ;
0 commit comments