PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / 27.7
Yoast SEO – Advanced SEO with real-time guidance and built-in AI v27.7
28.5 28.4 28.3 28.2 28.1 28.0 27.9 27.8 27.7 27.6 27.5 trunk 18.0 18.1 18.2 18.3 18.4 18.4.1 18.5 18.5.1 18.6 18.7 18.8 18.9 19.0 All 129 releases
wordpress-seo / src / plugins-tab / application / plugins-list-handler.php

plugins-list-handler.php in Yoast SEO – Advanced SEO with real-time guidance and built-in AI 27.7, at src/plugins-tab/application/plugins-list-handler.php

74 lines 1.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 // phpcs:disable Yoast.NamingConventions.NamespaceName.TooLong -- Needed in the folder structure.
4 namespace Yoast\WP\SEO\Plugins_Tab\Application;
5
6 use Yoast\WP\SEO\Plugins_Tab\Domain\Plugin_Detector;
7
8 /**
9 * Handles the filtering logic for the Yoast plugins tab on the Plugins screen.
10 */
11 class Plugins_List_Handler {
12
13 /**
14 * The plugin detector.
15 *
16 * @var Plugin_Detector
17 */
18 private $detector;
19
20 /**
21 * Constructs the handler.
22 *
23 * @param Plugin_Detector $detector The plugin detector.
24 */
25 public function __construct( Plugin_Detector $detector ) {
26 $this->detector = $detector;
27 }
28
29 /**
30 * Filters the plugins list to add a 'yoast' group when 2+ Yoast plugins are installed.
31 *
32 * @param array<string, array<string, array<string, string>>> $plugins The plugins list keyed by status.
33 *
34 * @return array<string, array<string, array<string, string>>> The filtered plugins list.
35 */
36 public function filter_plugins_list( $plugins ) {
37 if ( ! \is_array( $plugins ) || ! isset( $plugins['all'] ) ) {
38 return $plugins;
39 }
40
41 $yoast_plugins = [];
42 foreach ( $plugins['all'] as $plugin_file => $plugin_data ) {
43 if ( $this->detector->is_yoast_plugin( $plugin_data ) ) {
44 $yoast_plugins[ $plugin_file ] = $plugin_data;
45 }
46 }
47
48 if ( \count( $yoast_plugins ) < Plugin_Detector::MINIMUM_FOR_TAB ) {
49 return $plugins;
50 }
51
52 $plugins['yoast'] = $yoast_plugins;
53
54 return $plugins;
55 }
56
57 /**
58 * Returns the status text for the Yoast plugins tab.
59 *
60 * @param string $text The current status text.
61 * @param int $count The number of plugins with this status.
62 * @param string $type The status type slug.
63 *
64 * @return string The status text.
65 */
66 public function get_status_text( $text, $count, $type ) {
67 if ( $type !== 'yoast' ) {
68 return $text;
69 }
70
71 return \_nx( 'Yoast', 'Yoast', $count, 'plugin status', 'wordpress-seo' );
72 }
73 }
74