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

142 lines 4.0 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 wpdb;
6 use Yoast\WP\SEO\Conditionals\AIOSEO_V4_Importer_Conditional;
7 use Yoast\WP\SEO\Config\Conflicting_Plugins;
8 use Yoast\WP\SEO\Helpers\Options_Helper;
9 use Yoast\WP\SEO\Helpers\Sanitization_Helper;
10 use Yoast\WP\SEO\Services\Importing\Aioseo_Replacevar_Handler;
11 use Yoast\WP\SEO\Services\Importing\Aioseo_Robots_Provider_Service;
12 use Yoast\WP\SEO\Services\Importing\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_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_Handler
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 Options_Helper $options The options helper.
61 * @param Sanitization_Helper $sanitization The sanitization helper.
62 * @param Aioseo_Replacevar_Handler $replacevar_handler The replacevar handler.
63 * @param Aioseo_Robots_Provider_Service $robots_provider The robots provider service.
64 * @param Aioseo_Robots_Transformer_Service $robots_transformer The robots transfomer service.
65 * @param Conflicting_Plugins_Service $conflicting_plugins_service The Conflicting plugins Service.
66 */
67 public function __construct(
68 Options_Helper $options,
69 Sanitization_Helper $sanitization,
70 Aioseo_Replacevar_Handler $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( $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 public function get_total_unindexed() {
85 return \count( $this->get_detected_plugins() );
86 }
87
88 /**
89 * Returns whether the AISOEO post importing action is enabled.
90 *
91 * @return bool True if the AISOEO post importing action is enabled.
92 */
93 public function is_enabled() {
94 $aioseo_importer_conditional = \YoastSEO()->classes->get( AIOSEO_V4_Importer_Conditional::class );
95
96 return $aioseo_importer_conditional->is_met();
97 }
98
99 /**
100 * Deactivate conflicting plugins.
101 */
102 public function index() {
103 $detected_plugins = $this->get_detected_plugins();
104 $this->conflicting_plugins->deactivate_conflicting_plugins( $detected_plugins );
105
106 // We need to conform to the interface, so we report that no indexables were created.
107 return [];
108 }
109
110 /**
111 * {@inheritDoc}
112 */
113 public function get_limit() {
114 return \count( Conflicting_Plugins::all_plugins() );
115 }
116
117 /**
118 * Returns the total number of unindexed objects up to a limit.
119 *
120 * @param int $limit The maximum.
121 *
122 * @return int The total number of unindexed objects.
123 */
124 public function get_limited_unindexed_count( $limit ) {
125 $count = \count( $this->get_detected_plugins() );
126 return ( $count <= $limit ) ? $count : $limit;
127 }
128
129 /**
130 * Returns all detected plugins.
131 *
132 * @return array The detected plugins.
133 */
134 protected function get_detected_plugins() {
135 // The active plugins won't change much. We can reuse the result for the duration of the request.
136 if ( \count( $this->detected_plugins ) < 1 ) {
137 $this->detected_plugins = $this->conflicting_plugins->detect_conflicting_plugins();
138 }
139 return $this->detected_plugins;
140 }
141 }
142