forked from WordPress/plugin-check
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlugin_Uninstall_Constant_Check.php
More file actions
104 lines (95 loc) · 2.99 KB
/
Plugin_Uninstall_Constant_Check.php
File metadata and controls
104 lines (95 loc) · 2.99 KB
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
<?php
/**
* Class Plugin_Uninstall_Constant_Check.
*
* @package plugin-check
*/
namespace WordPress\Plugin_Check\Checker\Checks\Plugin_Repo;
use Exception;
use WordPress\Plugin_Check\Checker\Check_Categories;
use WordPress\Plugin_Check\Checker\Check_Result;
use WordPress\Plugin_Check\Checker\Checks\Abstract_File_Check;
use WordPress\Plugin_Check\Traits\Amend_Check_Result;
use WordPress\Plugin_Check\Traits\Stable_Check;
/**
* Check to detect if a definition check for WP_UNINSTALL_PLUGIN takes place in uninstall.php, if it exists
*
* @since 1.0.0
*/
class Plugin_Uninstall_Constant_Check extends Abstract_File_Check {
use Amend_Check_Result;
use Stable_Check;
/**
* Gets the categories for the check.
*
* Every check must have at least one category.
*
* @since 1.0.0
*
* @return array The categories for the check.
*/
public function get_categories() {
return array( Check_Categories::CATEGORY_PLUGIN_REPO );
}
/**
* Checks the uninstall.php file for a definition check of the WP_UNINSTALL_PLUGIN constant
*
* @since 1.0.0
*
* @param Check_Result $result The check result to amend, including the plugin context to check.
* @param array $files List of absolute file paths.
*
* @throws Exception Thrown when the check fails with a critical error (unrelated to any errors detected as part of
* the check).
*/
protected function check_files( Check_Result $result, array $files ) {
$constant_regex = '#defined\s*\(.*WP_UNINSTALL_PLUGIN.*\)#';
$matches = array();
$plugin_uninstall_file = self::filter_files_by_regex( $files, '/uninstall\.php$/' );
if ( $plugin_uninstall_file ) {
foreach ( $plugin_uninstall_file as $file ) {
$uninstall_constant = self::file_preg_match( $constant_regex, [ $file ], $matches );
if ( ! $uninstall_constant ) {
$this->add_result_warning_for_file(
$result,
sprintf(
/* translators: %s: The match file name. */
__( 'WP_UNINSTALL_PLUGIN constant not being checked. Detected: %s', 'plugin-check' ),
esc_html( $matches[0] )
),
'uninstall_no_constant_check',
$file,
0,
0,
'https://developer.wordpress.org/plugins/plugin-basics/uninstall-methods/#method-2-uninstall-php',
9
);
}
}
}
}
/**
* Gets the description for the check.
*
* Every check must have a short description explaining what the check does.
*
* @since 1.1.0
*
* @return string Description.
*/
public function get_description(): string {
return __( 'Confirms usage of WP_Uninstall_Plugin constant checker in uninstall.php', 'plugin-check' );
}
/**
* Gets the documentation URL for the check.
*
* Every check must have a URL with further information about the check.
*
* @since 1.1.0
*
* @return string The documentation URL.
*/
public function get_documentation_url(): string {
return __( 'https://developer.wordpress.org/plugins/plugin-basics/uninstall-methods/#method-2-uninstall-php', 'plugin-check' );
}
}