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

120 lines 3.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\Services\Importing\Conflicting_Plugins_Service;
10
11 /**
12 * Deactivates plug-ins that cause conflicts with Yoast SEO.
13 *
14 * @phpcs:disable Yoast.NamingConventions.ObjectNameDepth.MaxExceeded
15 */
16 class Deactivate_Conflicting_Plugins_Action extends Abstract_Importing_Action {
17
18 /**
19 * The plugin the class deals with.
20 *
21 * @var string
22 */
23 const PLUGIN = 'conflicting-plugins';
24
25 /**
26 * The type the class deals with.
27 *
28 * @var string
29 */
30 const TYPE = 'deactivation';
31
32 /**
33 * Knows all plugins that might possibly conflict.
34 *
35 * @var Conflicting_Plugins_Service
36 */
37 protected $conflicting_plugins;
38
39 /**
40 * The list of conflicting plugins
41 *
42 * @var array
43 */
44 protected $detected_plugins;
45
46 /**
47 * Class constructor.
48 *
49 * @param Options_Helper $options The options helper.
50 * @param Conflicting_Plugins_Service $conflicting_plugins_service The Conflicting plugins Service.
51 */
52 public function __construct( Options_Helper $options, Conflicting_Plugins_Service $conflicting_plugins_service ) {
53 parent::__construct( $options );
54
55 $this->conflicting_plugins = $conflicting_plugins_service;
56 $this->detected_plugins = [];
57 }
58
59 /**
60 * Get the total number of conflicting plugins.
61 */
62 public function get_total_unindexed() {
63 return \count( $this->get_detected_plugins() );
64 }
65
66 /**
67 * Returns whether the AISOEO post importing action is enabled.
68 *
69 * @return bool True if the AISOEO post importing action is enabled.
70 */
71 public function is_enabled() {
72 $aioseo_importer_conditional = \YoastSEO()->classes->get( AIOSEO_V4_Importer_Conditional::class );
73
74 return $aioseo_importer_conditional->is_met();
75 }
76
77 /**
78 * Deactivate conflicting plugins.
79 */
80 public function index() {
81 $detected_plugins = $this->get_detected_plugins();
82 $this->conflicting_plugins->deactivate_conflicting_plugins( $detected_plugins );
83
84 // We need to conform to the interface, so we report that no indexables were created.
85 return [];
86 }
87
88 /**
89 * {@inheritDoc}
90 */
91 public function get_limit() {
92 return \count( Conflicting_Plugins::all_plugins() );
93 }
94
95 /**
96 * Returns the total number of unindexed objects up to a limit.
97 *
98 * @param int $limit The maximum.
99 *
100 * @return int The total number of unindexed objects.
101 */
102 public function get_limited_unindexed_count( $limit ) {
103 $count = \count( $this->get_detected_plugins() );
104 return ( $count <= $limit ) ? $count : $limit;
105 }
106
107 /**
108 * Returns all detected plugins.
109 *
110 * @return array The detected plugins.
111 */
112 protected function get_detected_plugins() {
113 // The active plugins won't change much. We can reuse the result for the duration of the request.
114 if ( \count( $this->detected_plugins ) < 1 ) {
115 $this->detected_plugins = $this->conflicting_plugins->detect_conflicting_plugins();
116 }
117 return $this->detected_plugins;
118 }
119 }
120