diff --git a/plugins/underscoresme-generator/underscoresme-generator.php b/plugins/underscoresme-generator/underscoresme-generator.php index 90b4d54..e5a452c 100644 --- a/plugins/underscoresme-generator/underscoresme-generator.php +++ b/plugins/underscoresme-generator/underscoresme-generator.php @@ -181,7 +181,7 @@ function init() { function do_replacements( $contents, $filename ) { // Replace only text files, skip png's and other stuff. - $valid_extensions = array( 'php', 'css', 'scss', 'js', 'txt' ); + $valid_extensions = array( 'php', 'css', 'scss', 'js', 'txt', 'dist' ); $valid_extensions_regex = implode( '|', $valid_extensions ); if ( ! preg_match( "/\.({$valid_extensions_regex})$/", $filename ) ) return $contents; @@ -243,6 +243,21 @@ function do_replacements( $contents, $filename ) { // Function names can not contain hyphens. $slug = str_replace( '-', '_', $this->theme['slug'] ); + // Special treatment for phpcs.xml.dist + if ( 'phpcs.xml.dist' == $filename ) { + preg_match_all( '//', $contents, $matches, PREG_SET_ORDER ); + + foreach ( $matches as $match ) { + if ( 'text_domain' === $match[1] ) { + $replace = str_replace( '_s', $this->theme['slug'], $match[0] ); + } elseif ( 'prefixes' === $match[1] ) { + $replace = str_replace( '_s', $slug, $match[0] ); + } + + $contents = str_replace( $match[0], $replace, $contents ); + } + } + // Regular treatment for all other files. $contents = str_replace( "@package _s", sprintf( "@package %s", str_replace( ' ', '_', $this->theme['name'] ) ), $contents ); // Package declaration. $contents = str_replace( "_s-", sprintf( "%s-", $this->theme['slug'] ), $contents ); // Script/style handles.