PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / 18.5
Yoast SEO – Advanced SEO with real-time guidance and built-in AI v18.5
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 18.5, at src/actions/importing/deactivate-conflicting-plugins-action.php

144 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 * @phpcs:disable Yoast.NamingConventions.ObjectNameDepth.MaxExceeded
19 */
20 class Deactivate_Conflicting_Plugins_Action extends Abstract_Aioseo_Importing_Action {
21
22 /**
23 * The plugin the class deals with.
24 *
25 * @var string
26 */
27 const PLUGIN = 'conflicting-plugins';
28
29 /**
30 * The type the class deals with.
31 *
32 * @var string
33 */
34 const TYPE = 'deactivation';
35
36 /**
37 * The replacevar handler.
38 *
39 * @var Aioseo_Replacevar_Service
40 */
41 protected $replacevar_handler;
42
43 /**
44 * Knows all plugins that might possibly conflict.
45 *
46 * @var Conflicting_Plugins_Service
47 */
48 protected $conflicting_plugins;
49
50 /**
51 * The list of conflicting plugins
52 *
53 * @var array
54 */
55 protected $detected_plugins;
56
57 /**
58 * Class constructor.
59 *
60 * @param Import_Cursor_Helper $import_cursor The import cursor helper.
61 * @param Options_Helper $options The options helper.
62 * @param Sanitization_Helper $sanitization The sanitization helper.
63 * @param Aioseo_Replacevar_Service $replacevar_handler The replacevar handler.
64 * @param Aioseo_Robots_Provider_Service $robots_provider The robots provider service.
65 * @param Aioseo_Robots_Transformer_Service $robots_transformer The robots transfomer service.
66 * @param Conflicting_Plugins_Service $conflicting_plugins_service The Conflicting plugins Service.
67 */
68 public function __construct(
69 Import_Cursor_Helper $import_cursor,
70 Options_Helper $options,
71 Sanitization_Helper $sanitization,
72 Aioseo_Replacevar_Service $replacevar_handler,
73 Aioseo_Robots_Provider_Service $robots_provider,
74 Aioseo_Robots_Transformer_Service $robots_transformer,
75 Conflicting_Plugins_Service $conflicting_plugins_service
76 ) {
77 parent::__construct( $import_cursor, $options, $sanitization, $replacevar_handler, $robots_provider, $robots_transformer );
78
79 $this->conflicting_plugins = $conflicting_plugins_service;
80 $this->detected_plugins = [];
81 }
82
83 /**
84 * Get the total number of conflicting plugins.
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 public function index() {
105 $detected_plugins = $this->get_detected_plugins();
106 $this->conflicting_plugins->deactivate_conflicting_plugins( $detected_plugins );
107
108 // We need to conform to the interface, so we report that no indexables were created.
109 return [];
110 }
111
112 /**
113 * {@inheritDoc}
114 */
115 public function get_limit() {
116 return \count( Conflicting_Plugins::all_plugins() );
117 }
118
119 /**
120 * Returns the total number of unindexed objects up to a limit.
121 *
122 * @param int $limit The maximum.
123 *
124 * @return int The total number of unindexed objects.
125 */
126 public function get_limited_unindexed_count( $limit ) {
127 $count = \count( $this->get_detected_plugins() );
128 return ( $count <= $limit ) ? $count : $limit;
129 }
130
131 /**
132 * Returns all detected plugins.
133 *
134 * @return array The detected plugins.
135 */
136 protected function get_detected_plugins() {
137 // The active plugins won't change much. We can reuse the result for the duration of the request.
138 if ( \count( $this->detected_plugins ) < 1 ) {
139 $this->detected_plugins = $this->conflicting_plugins->detect_conflicting_plugins();
140 }
141 return $this->detected_plugins;
142 }
143 }
144