PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / trunk
Yoast SEO – Advanced SEO with real-time guidance and built-in AI vtrunk
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 / actions / importing / deactivate-conflicting-plugins-action.php

deactivate-conflicting-plugins-action.php in Yoast SEO – Advanced SEO with real-time guidance and built-in AI trunk, at src/actions/importing/deactivate-conflicting-plugins-action.php

146 lines 4.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Yoast\WP\SEO\Actions\Importing;
4
5 use Yoast\WP\SEO\Conditionals\Updated_Importer_Framework_Conditional;
6 use Yoast\WP\SEO\Config\Conflicting_Plugins;
7 use Yoast\WP\SEO\Helpers\Import_Cursor_Helper;
8 use Yoast\WP\SEO\Helpers\Options_Helper;
9 use Yoast\WP\SEO\Helpers\Sanitization_Helper;
10 use Yoast\WP\SEO\Services\Importing\Aioseo\Aioseo_Replacevar_Service;
11 use Yoast\WP\SEO\Services\Importing\Aioseo\Aioseo_Robots_Provider_Service;
12 use Yoast\WP\SEO\Services\Importing\Aioseo\Aioseo_Robots_Transformer_Service;
13 use Yoast\WP\SEO\Services\Importing\Conflicting_Plugins_Service;
14
15 /**
16 * Deactivates plug-ins that cause conflicts with Yoast SEO.
17 */
18 class Deactivate_Conflicting_Plugins_Action extends Abstract_Aioseo_Importing_Action {
19
20 /**
21 * The plugin the class deals with.
22 *
23 * @var string
24 */
25 public const PLUGIN = 'conflicting-plugins';
26
27 /**
28 * The type the class deals with.
29 *
30 * @var string
31 */
32 public const TYPE = 'deactivation';
33
34 /**
35 * The replacevar handler.
36 *
37 * @var Aioseo_Replacevar_Service
38 */
39 protected $replacevar_handler;
40
41 /**
42 * Knows all plugins that might possibly conflict.
43 *
44 * @var Conflicting_Plugins_Service
45 */
46 protected $conflicting_plugins;
47
48 /**
49 * The list of conflicting plugins
50 *
51 * @var array
52 */
53 protected $detected_plugins;
54
55 /**
56 * Class constructor.
57 *
58 * @param Import_Cursor_Helper $import_cursor The import cursor helper.
59 * @param Options_Helper $options The options helper.
60 * @param Sanitization_Helper $sanitization The sanitization helper.
61 * @param Aioseo_Replacevar_Service $replacevar_handler The replacevar handler.
62 * @param Aioseo_Robots_Provider_Service $robots_provider The robots provider service.
63 * @param Aioseo_Robots_Transformer_Service $robots_transformer The robots transfomer service.
64 * @param Conflicting_Plugins_Service $conflicting_plugins_service The Conflicting plugins Service.
65 */
66 public function __construct(
67 Import_Cursor_Helper $import_cursor,
68 Options_Helper $options,
69 Sanitization_Helper $sanitization,
70 Aioseo_Replacevar_Service $replacevar_handler,
71 Aioseo_Robots_Provider_Service $robots_provider,
72 Aioseo_Robots_Transformer_Service $robots_transformer,
73 Conflicting_Plugins_Service $conflicting_plugins_service
74 ) {
75 parent::__construct( $import_cursor, $options, $sanitization, $replacevar_handler, $robots_provider, $robots_transformer );
76
77 $this->conflicting_plugins = $conflicting_plugins_service;
78 $this->detected_plugins = [];
79 }
80
81 /**
82 * Get the total number of conflicting plugins.
83 *
84 * @return int
85 */
86 public function get_total_unindexed() {
87 return \count( $this->get_detected_plugins() );
88 }
89
90 /**
91 * Returns whether the updated importer framework is enabled.
92 *
93 * @return bool True if the updated importer framework is enabled.
94 */
95 public function is_enabled() {
96 $updated_importer_framework_conditional = \YoastSEO()->classes->get( Updated_Importer_Framework_Conditional::class );
97
98 return $updated_importer_framework_conditional->is_met();
99 }
100
101 /**
102 * Deactivate conflicting plugins.
103 *
104 * @return array
105 */
106 public function index() {
107 $detected_plugins = $this->get_detected_plugins();
108 $this->conflicting_plugins->deactivate_conflicting_plugins( $detected_plugins );
109
110 // We need to conform to the interface, so we report that no indexables were created.
111 return [];
112 }
113
114 /**
115 * {@inheritDoc}
116 */
117 public function get_limit() {
118 return \count( Conflicting_Plugins::all_plugins() );
119 }
120
121 /**
122 * Returns the total number of unindexed objects up to a limit.
123 *
124 * @param int $limit The maximum.
125 *
126 * @return int The total number of unindexed objects.
127 */
128 public function get_limited_unindexed_count( $limit ) {
129 $count = \count( $this->get_detected_plugins() );
130 return ( $count <= $limit ) ? $count : $limit;
131 }
132
133 /**
134 * Returns all detected plugins.
135 *
136 * @return array The detected plugins.
137 */
138 protected function get_detected_plugins() {
139 // The active plugins won't change much. We can reuse the result for the duration of the request.
140 if ( \count( $this->detected_plugins ) < 1 ) {
141 $this->detected_plugins = $this->conflicting_plugins->detect_conflicting_plugins();
142 }
143 return $this->detected_plugins;
144 }
145 }
146