-
Notifications
You must be signed in to change notification settings - Fork 967
Expand file tree
/
Copy pathplugins-list-handler.php
More file actions
73 lines (61 loc) · 1.84 KB
/
Copy pathplugins-list-handler.php
File metadata and controls
73 lines (61 loc) · 1.84 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
<?php
// phpcs:disable Yoast.NamingConventions.NamespaceName.TooLong -- Needed in the folder structure.
namespace Yoast\WP\SEO\Plugins_Tab\Application;
use Yoast\WP\SEO\Plugins_Tab\Domain\Plugin_Detector;
/**
* Handles the filtering logic for the Yoast plugins tab on the Plugins screen.
*/
class Plugins_List_Handler {
/**
* The plugin detector.
*
* @var Plugin_Detector
*/
private $detector;
/**
* Constructs the handler.
*
* @param Plugin_Detector $detector The plugin detector.
*/
public function __construct( Plugin_Detector $detector ) {
$this->detector = $detector;
}
/**
* Filters the plugins list to add a 'yoast' group when 2+ Yoast plugins are installed.
*
* @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'] ) ) {
return $plugins;
}
$yoast_plugins = [];
foreach ( $plugins['all'] as $plugin_file => $plugin_data ) {
if ( $this->detector->is_yoast_plugin( $plugin_data ) ) {
$yoast_plugins[ $plugin_file ] = $plugin_data;
}
}
if ( \count( $yoast_plugins ) < Plugin_Detector::MINIMUM_FOR_TAB ) {
return $plugins;
}
$plugins['yoast'] = $yoast_plugins;
return $plugins;
}
/**
* Returns the status text for the Yoast plugins tab.
*
* @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 ( $type !== 'yoast' ) {
return $text;
}
return \_nx( 'Yoast', 'Yoast', $count, 'plugin status', 'wordpress-seo' );
}
}