-
Notifications
You must be signed in to change notification settings - Fork 44
/
ForbiddenFunctionsSniff.php
77 lines (70 loc) · 1.95 KB
/
ForbiddenFunctionsSniff.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<?php
/**
* WPThemeReview Coding Standard.
*
* @package WPTRT\WPThemeReview
* @link https://github.com/WPTRT/WPThemeReview
* @license https://opensource.org/licenses/MIT MIT
*/
namespace WPThemeReview\Sniffs\PluginTerritory;
use WordPressCS\WordPress\AbstractFunctionRestrictionsSniff;
/**
* Restricts the use of various functions that are plugin territory.
*
* @link https://make.wordpress.org/themes/handbook/review/required/#presentation-vs-functionality
*
* @since 0.1.0
* @since 0.2.0 Added the `editor-blocks` group.
* Added the `cron-functionality` group.
*/
class ForbiddenFunctionsSniff extends AbstractFunctionRestrictionsSniff {
/**
* Groups of functions to restrict.
*
* Example: groups => [
* 'lambda' => [
* 'type' => 'error' | 'warning',
* 'message' => 'Use anonymous functions instead please!',
* 'functions' => [ 'file_get_contents', 'create_function' ],
* ]
* ]
*
* @return array
*/
public function getGroups() {
return [
'plugin-territory' => [
'type' => 'error',
'message' => 'Function %s() is not allowed because it is plugin territory.',
'functions' => [
'register_post_type',
'register_taxonomy',
'add_shortcode',
'register_taxonomy_for_object_type',
'flush_rewrite_rules',
],
],
'editor-blocks' => [
'type' => 'error',
'message' => 'Registering and deregistering editor blocks should be done in a plugin, not in a theme. Found %s().',
'functions' => [
'register_block_core_*',
'register_block_type',
'register_block_type_from_metadata',
'unregister_block_type',
],
],
'cron-functionality' => [
'type' => 'error',
'message' => 'Themes should not be running regular (Cron) tasks. Found %s().',
'functions' => [
'wp_clear_scheduled_hook',
'wp_cron',
'wp_reschedule_event',
'wp_schedule_*',
'wp_unschedule_*',
],
],
];
}
}