From 7f273b7314ca240baa70192f5fc485c7259e7e25 Mon Sep 17 00:00:00 2001 From: Greg Sullivan Date: Sun, 18 Mar 2018 19:26:51 -0700 Subject: [PATCH] =?UTF-8?q?Add=20text=20replacement=20for=20=E2=80=9C=5Fs?= =?UTF-8?q?=E2=80=9D=20in=20phpcs.xml.dist?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../underscoresme-generator.php | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) 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.