-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #65 from khacoder/feature/no-auto-generate
No Auto Generated Themes
- Loading branch information
Showing
4 changed files
with
218 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
<?php | ||
/** | ||
* WordPress Coding Standard. | ||
* | ||
* @package WPCS\WordPressCodingStandards | ||
* @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards | ||
* @license https://opensource.org/licenses/MIT MIT | ||
*/ | ||
|
||
/** | ||
* Check for auto generated themes. | ||
* | ||
* @package WPCS\WordPressCodingStandards | ||
* | ||
* @since 0.xx.0 | ||
*/ | ||
class WordPress_Sniffs_Theme_NoAutoGenerateSniff implements PHP_CodeSniffer_Sniff { | ||
|
||
/** | ||
* A list of tokenizers this sniff supports. | ||
* | ||
* @var array | ||
*/ | ||
public $supportedTokenizers = array( | ||
'PHP', | ||
'CSS', | ||
); | ||
|
||
/** | ||
* A list of strings found in the generated themes. | ||
* | ||
* @var array | ||
*/ | ||
protected $generated_themes = array( | ||
'artisteer', // Artisteer. | ||
'themler', // Themler. | ||
'lubith', // Lubith. | ||
'templatetoaster', // TemplateToaster. | ||
'wpthemegenerator', // WP Theme Generator. | ||
'pinegrow', // Pinegrow. | ||
); | ||
|
||
/** | ||
* Returns an array of tokens this test wants to listen for. | ||
* | ||
* @return array | ||
*/ | ||
public function register() { | ||
$tokens = PHP_CodeSniffer_Tokens::$stringTokens; | ||
$tokens[] = T_STRING; | ||
$tokens[] = T_INLINE_HTML; | ||
$tokens[] = T_COMMENT; | ||
$tokens[] = T_DOC_COMMENT_STRING; | ||
return $tokens; | ||
} | ||
|
||
/** | ||
* Processes this test, when one of its tokens is encountered. | ||
* | ||
* @param PHP_CodeSniffer_File $phpcsFile The file being scanned. | ||
* @param int $stackPtr The position of the current token | ||
* in the stack passed in $tokens. | ||
* | ||
* @return void | ||
*/ | ||
public function process( PHP_CodeSniffer_File $phpcsFile, $stackPtr ) { | ||
|
||
$tokens = $phpcsFile->getTokens(); | ||
$token = $tokens[ $stackPtr ]; | ||
$content = trim( $token['content'] ); | ||
|
||
// No need to check an empty string. | ||
if ( '' === $content ) { | ||
return; | ||
} | ||
|
||
foreach ( $this->generated_themes as $generated_theme ) { | ||
// The check can have false positives like artisteers but chances of that in a valid theme is low. | ||
if ( false === strpos( strtolower( $content ), $generated_theme ) ) { | ||
continue; | ||
} | ||
$phpcsFile->addError( | ||
'Auto generated themes are not allowed in the theme directory. Found: %s', | ||
$stackPtr, | ||
'AutoGeneratedFound', | ||
array( $generated_theme ) | ||
); | ||
} | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* | ||
{ | ||
Theme URI:http://TemplateToaster.com | ||
Author:TemplateToaster | ||
Author URI:http://TemplateToaster.com | ||
} | ||
*/ | ||
/* | ||
Theme URI: http://www.themler.com/wordpress-themes | ||
Description: Themler-generated theme | ||
*/ | ||
/* | ||
Theme URI: http://www.WpThemeGenerator.com/ | ||
Author: WpThemeGenerator | ||
Author URI:www.WpThemeGenerator.com | ||
*/ | ||
/* OK. */ | ||
/* | ||
Theme Name: Twenty Seventeen | ||
Theme URI: http://example.com | ||
Author: WordPress.org | ||
Author URI: example.com/author | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
|
||
<p>Lubith</p> | ||
<!-- saved from url=(0045)http://docs.pinegrow.com/editing/code-editing --> | ||
<?php | ||
/** | ||
* This theme was generated with Lubith - The Wordpress Theme Generator: http://www.lubith.com | ||
*/ | ||
$shortname = "artisteer"; | ||
function themler_shortcode_login_link() {} | ||
/** | ||
* @package templatetoaster | ||
*/ | ||
/* funcion que verifica si el dominio es wpthemegenerator */ | ||
function is_wpthemegenerator(){ | ||
if( $_SERVER['HTTP_HOST'] === 'www.wpthemegenerator.com' ){ | ||
return true; | ||
} else { | ||
return false; | ||
} | ||
} | ||
/* | ||
* Resource files included by Pinegrow. | ||
*/ | ||
|
||
// OK. | ||
|
||
/* | ||
* Pine tress grow everywhere. | ||
*/ | ||
|
||
/** | ||
* This theme template was built in a toaster by artists | ||
*/ | ||
|
||
function wp_vs_them() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
<?php | ||
/** | ||
* Unit test class for WordPress Coding Standard. | ||
* | ||
* @package WPCS\WordPressCodingStandards | ||
* @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards | ||
* @license https://opensource.org/licenses/MIT MIT | ||
*/ | ||
|
||
/** | ||
* Unit test class for the Theme_NoAutoGenerate sniff. | ||
* | ||
* @package WPCS\WordPressCodingStandards | ||
* @since 0.xx.0 | ||
*/ | ||
class WordPress_Tests_Theme_NoAutoGenerateUnitTest extends AbstractSniffUnitTest { | ||
|
||
/** | ||
* Returns the lines where errors should occur. | ||
* | ||
* @param string $testFile The name of the file being tested. | ||
* | ||
* @return array <int line number> => <int number of errors> | ||
*/ | ||
public function getErrorList( $testFile = '' ) { | ||
switch ( $testFile ) { | ||
case 'NoAutoGenerateUnitTest.inc': | ||
return array( | ||
2 => 1, | ||
3 => 1, | ||
6 => 1, | ||
8 => 1, | ||
9 => 1, | ||
11 => 1, | ||
13 => 1, | ||
14 => 1, | ||
15 => 1, | ||
22 => 1, | ||
); | ||
break; | ||
case 'NoAutoGenerateUnitTest.css': | ||
return array( | ||
3 => 1, | ||
4 => 1, | ||
5 => 1, | ||
9 => 1, | ||
10 => 1, | ||
13 => 1, | ||
14 => 1, | ||
15 => 1, | ||
); | ||
break; | ||
default: | ||
return array(); | ||
break; | ||
} | ||
} | ||
|
||
/** | ||
* Returns the lines where warnings should occur. | ||
* | ||
* @return array <int line number> => <int number of warnings> | ||
*/ | ||
public function getWarningList() { | ||
return array(); | ||
} | ||
|
||
} // End class. |