-
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.
Add sniff to check for
add_..._page()
functions + unit tests.
Closes #11.
- Loading branch information
Showing
4 changed files
with
139 additions
and
1 deletion.
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
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,55 @@ | ||
/** | ||
* WordPress_Sniffs_Theme_NoAddAdminPagesSniff. | ||
* | ||
* Forbids the use of add_..._page() functions within Themes with the exception of `add_theme_page()`. | ||
* | ||
* @category Theme | ||
* @package PHP_CodeSniffer | ||
* @author Juliette Reinders Folmer <[email protected]> | ||
*/ | ||
class WordPress_Sniffs_Theme_NoAddAdminPagesSniff extends WordPress_Sniffs_Functions_FunctionRestrictionsSniff { | ||
|
||
/** | ||
* Groups of functions to restrict | ||
* | ||
* Example: groups => array( | ||
* 'lambda' => array( | ||
* 'type' => 'error' | 'warning', | ||
* 'message' => 'Use anonymous functions instead please!', | ||
* 'functions' => array( 'eval', 'create_function' ), | ||
* ) | ||
* ) | ||
* | ||
* @return array | ||
*/ | ||
public function getGroups() { | ||
return array( | ||
|
||
'add_menu_pages' => array( | ||
'type' => 'error', | ||
'message' => 'Themes should use <strong>add_theme_page()</strong> for adding admin pages. Found %s.', | ||
'functions' => array( | ||
// Menu Pages. | ||
'add_menu_page', | ||
'add_object_page', | ||
'add_utility_page', | ||
|
||
// SubMenu Pages. | ||
'add_submenu_page', | ||
|
||
// WordPress Administration Menus. | ||
'add_dashboard_page', | ||
'add_posts_page', | ||
'add_media_page', | ||
'add_pages_page', | ||
'add_comments_page', | ||
'add_plugins_page', | ||
'add_users_page', | ||
'add_management_page', | ||
'add_options_page', | ||
), | ||
), | ||
); | ||
|
||
} | ||
} // end class |
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,28 @@ | ||
<?php | ||
|
||
// Menu Pages. | ||
add_menu_page(); | ||
add_object_page(); | ||
add_utility_page(); | ||
|
||
// SubMenu Pages. | ||
add_submenu_page(); | ||
|
||
// WordPress Administration Menus. | ||
add_dashboard_page(); | ||
add_posts_page(); | ||
add_media_page(); | ||
add_pages_page(); | ||
add_comments_page(); | ||
add_plugins_page(); | ||
add_users_page(); | ||
add_management_page(); | ||
add_options_page(); | ||
|
||
// Add Theme Page is allowed. | ||
add_theme_page(); // Ok. | ||
|
||
// Method names within a Theme class should be fine. | ||
Theme_Object::add_menu_page(); // Ok. | ||
$this->add_plugins_page(); // Ok. | ||
$theme_object->add_options_page(); // Ok. |
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,55 @@ | ||
<?php | ||
/** | ||
* Unit test class for the NoAddAdminPages sniff. | ||
* | ||
* A sniff unit test checks a .inc file for expected violations of a single | ||
* coding standard. Expected errors and warnings are stored in this class. | ||
* | ||
* @category Theme | ||
* @package PHP_CodeSniffer | ||
* @author Juliette Reinders Folmer <[email protected]> | ||
*/ | ||
class WordPress_Tests_Theme_NoAddAdminPagesUnitTest extends AbstractSniffUnitTest { | ||
|
||
/** | ||
* Returns the lines where errors should occur. | ||
* | ||
* The key of the array should represent the line number and the value | ||
* should represent the number of errors that should occur on that line. | ||
* | ||
* @return array(int => int) | ||
*/ | ||
public function getErrorList() { | ||
return array( | ||
4 => 1, | ||
5 => 1, | ||
6 => 1, | ||
9 => 1, | ||
12 => 1, | ||
13 => 1, | ||
14 => 1, | ||
15 => 1, | ||
16 => 1, | ||
17 => 1, | ||
18 => 1, | ||
19 => 1, | ||
20 => 1, | ||
); | ||
|
||
} // end getErrorList() | ||
|
||
|
||
/** | ||
* Returns the lines where warnings should occur. | ||
* | ||
* The key of the array should represent the line number and the value | ||
* should represent the number of warnings that should occur on that line. | ||
* | ||
* @return array(int => int) | ||
*/ | ||
public function getWarningList() { | ||
return array(); | ||
|
||
} // end getWarningList() | ||
|
||
} // end class |