-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathclass-plugin-list-tab.php
More file actions
124 lines (107 loc) · 3.09 KB
/
Copy pathclass-plugin-list-tab.php
File metadata and controls
124 lines (107 loc) · 3.09 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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
<?php
/**
* Plugin List Tab class file for the Accessibility Checker plugin.
*
* @package Accessibility_Checker
*/
namespace EqualizeDigital\AccessibilityChecker\Admin;
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Registers an "Equalize Digital" tab on the WordPress Plugins screen.
*
* The tab appears when 2 or more Equalize Digital plugins are installed,
* using the plugins_list and plugins_list_status_text filters added in WP 7.0.
*
* @since 1.43.0
*/
class Plugin_List_Tab {
/**
* Minimum number of Equalize Digital plugins required to show the tab.
*
* @var int
*/
const MINIMUM_FOR_TAB = 2;
/**
* The status slug used for the Equalize Digital tab.
*
* @var string
*/
const STATUS_SLUG = 'equalize-digital';
/**
* Initialize hooks.
*
* @since 1.43.0
*
* @return void
*/
public function init_hooks(): void {
global $wp_version;
if ( \version_compare( $wp_version, '7.0-alpha0', '<' ) ) {
return;
}
add_filter( 'plugins_list', [ $this, 'filter_plugins_list' ] );
add_filter( 'plugins_list_status_text', [ $this, 'get_status_text' ], 10, 3 );
}
/**
* Filters the plugins list to add an Equalize Digital group.
*
* Only adds the group when 2 or more Equalize Digital plugins are installed.
*
* @since 1.43.0
*
* @param array<string, array<string, array<string, string>>> $plugins The plugins list keyed by status.
*
* @return array<string, array<string, array<string, string>>> The filtered plugins list.
*/
public function filter_plugins_list( $plugins ) {
if ( ! \is_array( $plugins ) || ! isset( $plugins['all'] ) || ! \is_array( $plugins['all'] ) ) {
return $plugins;
}
$equalize_digital_plugins = [];
foreach ( $plugins['all'] as $plugin_file => $plugin_data ) {
if ( $this->is_equalize_digital_plugin( $plugin_data ) ) {
$equalize_digital_plugins[ $plugin_file ] = $plugin_data;
}
}
if ( \count( $equalize_digital_plugins ) < self::MINIMUM_FOR_TAB ) {
return $plugins;
}
$plugins[ self::STATUS_SLUG ] = $equalize_digital_plugins;
return $plugins;
}
/**
* Returns the label text for the Equalize Digital tab.
*
* @since 1.43.0
*
* @param string $text The current status text.
* @param int $count The number of plugins with this status.
* @param string $type The status type slug.
*
* @return string The status text.
*/
public function get_status_text( $text, $count, $type ) {
if ( self::STATUS_SLUG !== $type ) {
return $text;
}
// translators: %s: Number of plugins.
return \_nx( 'Equalize Digital <span class="count">(%s)</span>', 'Equalize Digital <span class="count">(%s)</span>', $count, 'plugin status', 'accessibility-checker' );
}
/**
* Determines whether a plugin belongs to Equalize Digital.
*
* @since 1.43.0
*
* @param array<string, string> $plugin_data The plugin header data.
*
* @return bool
*/
private function is_equalize_digital_plugin( $plugin_data ): bool {
if ( ! \is_array( $plugin_data ) || empty( $plugin_data['AuthorURI'] ) ) {
return false;
}
return false !== \stripos( $plugin_data['AuthorURI'], 'equalizedigital.com' );
}
}