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3.2.1 6.3.0-beta.1 3.2.2 6.3.0-rc.1 3.2.3 6.3.0-rc.2 3.2.4 6.3.1 3.2.5 6.3.2 3.2.6 6.4.0 3.3.0 6.4.0-beta.1 3.3.1 6.4.0-rc.1 3.3.2 6.4.1 3.3.2-rc.1 6.4.2 3.3.3 6.5.0 3.3.4 6.5.0-beta.1 3.3.5 6.5.0-rc.1 3.3.6 6.5.0-rc.2 3.4.0 6.5.1 3.4.0-beta.1 6.5.2 3.4.0-rc.2 6.6.0 3.4.1 6.6.0-beta.1 3.4.2 6.6.0-rc.1 3.4.3 6.6.0-rc.2 3.4.4 6.6.1 3.4.5 6.6.2 3.4.6 6.7.0 3.4.7 6.7.0-beta.1 3.4.8 6.7.0-beta.2 3.5.0 6.7.0-rc.1 3.5.0-beta.1 6.7.1 3.5.0-rc.1 6.8.0 3.5.0-rc.2 6.8.0-beta.1 3.5.1 6.8.0-beta.2 3.5.10 6.8.0-rc.1 3.5.2 6.8.1 3.5.3 6.8.2 3.5.4 6.8.3 3.5.5 6.9.0 3.5.6 6.9.0-beta.1 3.5.7 6.9.0-beta.2 3.5.8 6.9.0-rc.1 3.5.9 6.9.1 3.6.0 6.9.2 3.6.0-beta.1 6.9.3 3.6.0-rc.1 6.9.4 3.6.0-rc.2 6.9.5 3.6.0-rc.3 7.0.0 3.6.1 7.0.0-beta.1 3.6.2 7.0.0-beta.2 3.6.3 7.0.0-beta.3 3.6.4 7.0.0-rc.1 3.6.5 7.0.0-rc.2 3.6.6 7.0.1 3.6.7 7.0.2 3.7.0 7.1.0 3.7.0-beta.1 7.1.0-beta.1 3.7.0-rc.1 7.1.0-beta.2 3.7.0-rc.2 7.1.0-rc.1 3.7.1 7.1.0-rc.2 3.7.2 7.1.1
woocommerce / src / Utilities / PluginUtil.php
woocommerce / src / Utilities Last commit date
ArrayUtil.php 2 years ago FeaturesUtil.php 3 years ago I18nUtil.php 3 years ago NumberUtil.php 5 years ago OrderUtil.php 2 years ago PluginUtil.php 2 years ago StringUtil.php 2 years ago
PluginUtil.php
236 lines
1 <?php
2 /**
3 * A class of utilities for dealing with plugins.
4 */
5
6 namespace Automattic\WooCommerce\Utilities;
7
8 use Automattic\WooCommerce\Internal\Traits\AccessiblePrivateMethods;
9 use Automattic\WooCommerce\Proxies\LegacyProxy;
10
11 /**
12 * A class of utilities for dealing with plugins.
13 */
14 class PluginUtil {
15
16 use AccessiblePrivateMethods;
17
18 /**
19 * The LegacyProxy instance to use.
20 *
21 * @var LegacyProxy
22 */
23 private $proxy;
24
25 /**
26 * The cached list of WooCommerce aware plugin ids.
27 *
28 * @var null|array
29 */
30 private $woocommerce_aware_plugins = null;
31
32 /**
33 * The cached list of enabled WooCommerce aware plugin ids.
34 *
35 * @var null|array
36 */
37 private $woocommerce_aware_active_plugins = null;
38
39 /**
40 * Creates a new instance of the class.
41 */
42 public function __construct() {
43 self::add_action( 'activated_plugin', array( $this, 'handle_plugin_de_activation' ), 10, 0 );
44 self::add_action( 'deactivated_plugin', array( $this, 'handle_plugin_de_activation' ), 10, 0 );
45 }
46
47 /**
48 * Initialize the class instance.
49 *
50 * @internal
51 *
52 * @param LegacyProxy $proxy The instance of LegacyProxy to use.
53 */
54 final public function init( LegacyProxy $proxy ) {
55 $this->proxy = $proxy;
56 require_once ABSPATH . WPINC . '/plugin.php';
57 }
58
59 /**
60 * Get a list with the names of the WordPress plugins that are WooCommerce aware
61 * (they have a "WC tested up to" header).
62 *
63 * @param bool $active_only True to return only active plugins, false to return all the active plugins.
64 * @return string[] A list of plugin ids (path/file.php).
65 */
66 public function get_woocommerce_aware_plugins( bool $active_only = false ): array {
67 if ( is_null( $this->woocommerce_aware_plugins ) ) {
68 // In case `get_plugins` was called much earlier in the request (before our headers could be injected), we
69 // invalidate the plugin cache list.
70 wp_cache_delete( 'plugins', 'plugins' );
71 $all_plugins = $this->proxy->call_function( 'get_plugins' );
72
73 $this->woocommerce_aware_plugins =
74 array_keys(
75 array_filter(
76 $all_plugins,
77 array( $this, 'is_woocommerce_aware_plugin' )
78 )
79 );
80
81 $this->woocommerce_aware_active_plugins =
82 array_values(
83 array_filter(
84 $this->woocommerce_aware_plugins,
85 function ( $plugin_name ) {
86 return $this->proxy->call_function( 'is_plugin_active', $plugin_name );
87 }
88 )
89 );
90 }
91
92 return $active_only ? $this->woocommerce_aware_active_plugins : $this->woocommerce_aware_plugins;
93 }
94
95 /**
96 * Get the printable name of a plugin.
97 *
98 * @param string $plugin_id Plugin id (path/file.php).
99 * @return string Printable plugin name, or the plugin id itself if printable name is not available.
100 */
101 public function get_plugin_name( string $plugin_id ): string {
102 $plugin_data = $this->proxy->call_function( 'get_plugin_data', WP_PLUGIN_DIR . DIRECTORY_SEPARATOR . $plugin_id );
103 return $plugin_data['Name'] ?? $plugin_id;
104 }
105
106 /**
107 * Check if a plugin is WooCommerce aware.
108 *
109 * @param string|array $plugin_file_or_data Plugin id (path/file.php) or plugin data (as returned by get_plugins).
110 * @return bool True if the plugin exists and is WooCommerce aware.
111 * @throws \Exception The input is neither a string nor an array.
112 */
113 public function is_woocommerce_aware_plugin( $plugin_file_or_data ): bool {
114 if ( is_string( $plugin_file_or_data ) ) {
115 return in_array( $plugin_file_or_data, $this->get_woocommerce_aware_plugins(), true );
116 } elseif ( is_array( $plugin_file_or_data ) ) {
117 return '' !== ( $plugin_file_or_data['WC tested up to'] ?? '' );
118 } else {
119 throw new \Exception( 'is_woocommerce_aware_plugin requires a plugin name or an array of plugin data as input' );
120 }
121 }
122
123 /**
124 * Match plugin identifier passed as a parameter with the output from `get_plugins()`.
125 *
126 * @param string $plugin_file Plugin identifier, either 'my-plugin/my-plugin.php', or output from __FILE__.
127 *
128 * @return string|false Key from the array returned by `get_plugins` if matched. False if no match.
129 */
130 public function get_wp_plugin_id( $plugin_file ) {
131 $wp_plugins = array_keys( $this->proxy->call_function( 'get_plugins' ) );
132
133 // Try to match plugin_basename().
134 $plugin_basename = $this->proxy->call_function( 'plugin_basename', $plugin_file );
135 if ( in_array( $plugin_basename, $wp_plugins, true ) ) {
136 return $plugin_basename;
137 }
138
139 // Try to match by the my-file/my-file.php (dir + file name), then by my-file.php (file name only).
140 $plugin_file = str_replace( array( '\\', '/' ), DIRECTORY_SEPARATOR, $plugin_file );
141 $file_name_parts = explode( DIRECTORY_SEPARATOR, $plugin_file );
142 $file_name = array_pop( $file_name_parts );
143 $directory_name = array_pop( $file_name_parts );
144 $full_matches = array();
145 $partial_matches = array();
146 foreach ( $wp_plugins as $wp_plugin ) {
147 if ( false !== strpos( $wp_plugin, $directory_name . DIRECTORY_SEPARATOR . $file_name ) ) {
148 $full_matches[] = $wp_plugin;
149 }
150
151 if ( false !== strpos( $wp_plugin, $file_name ) ) {
152 $partial_matches[] = $wp_plugin;
153 }
154 }
155
156 if ( 1 === count( $full_matches ) ) {
157 return $full_matches[0];
158 }
159
160 if ( 1 === count( $partial_matches ) ) {
161 return $partial_matches[0];
162 }
163
164 return false;
165 }
166
167 /**
168 * Handle plugin activation and deactivation by clearing the WooCommerce aware plugin ids cache.
169 */
170 private function handle_plugin_de_activation(): void {
171 $this->woocommerce_aware_plugins = null;
172 $this->woocommerce_aware_active_plugins = null;
173 }
174
175 /**
176 * Util function to generate warning string for incompatible features based on active plugins.
177 *
178 * @param string $feature_id Feature id.
179 * @param array $plugin_feature_info Array of plugin feature info. See FeaturesControllers->get_compatible_plugins_for_feature() for details.
180 *
181 * @return string Warning string.
182 */
183 public function generate_incompatible_plugin_feature_warning( string $feature_id, array $plugin_feature_info ) : string {
184 $feature_warning = '';
185 $incompatibles = array_merge( $plugin_feature_info['incompatible'], $plugin_feature_info['uncertain'] );
186 $incompatibles = array_filter( $incompatibles, 'is_plugin_active' );
187 $incompatible_count = count( $incompatibles );
188 if ( $incompatible_count > 0 ) {
189 if ( 1 === $incompatible_count ) {
190 /* translators: %s = printable plugin name */
191 $feature_warning = sprintf( __( '⚠ 1 Incompatible plugin detected (%s).', 'woocommerce' ), $this->get_plugin_name( $incompatibles[0] ) );
192 } elseif ( 2 === $incompatible_count ) {
193 $feature_warning = sprintf(
194 /* translators: %1\$s, %2\$s = printable plugin names */
195 __( '⚠ 2 Incompatible plugins detected (%1$s and %2$s).', 'woocommerce' ),
196 $this->get_plugin_name( $incompatibles[0] ),
197 $this->get_plugin_name( $incompatibles[1] )
198 );
199 } else {
200
201 $feature_warning = sprintf(
202 /* translators: %1\$s, %2\$s = printable plugin names, %3\$d = plugins count */
203 _n(
204 '⚠ Incompatible plugins detected (%1$s, %2$s and %3$d other).',
205 '⚠ Incompatible plugins detected (%1$s and %2$s plugins and %3$d others).',
206 $incompatible_count - 2,
207 'woocommerce'
208 ),
209 $this->get_plugin_name( $incompatibles[0] ),
210 $this->get_plugin_name( $incompatibles[1] ),
211 $incompatible_count - 2
212 );
213 }
214
215 $incompatible_plugins_url = add_query_arg(
216 array(
217 'plugin_status' => 'incompatible_with_feature',
218 'feature_id' => $feature_id,
219 ),
220 admin_url( 'plugins.php' )
221 );
222 $extra_desc_tip = '<br>' . sprintf(
223 /* translators: %1$s opening link tag %2$s closing link tag. */
224 __( '%1$sView and manage%2$s', 'woocommerce' ),
225 '<a href="' . esc_url( $incompatible_plugins_url ) . '">',
226 '</a>'
227 );
228
229 $feature_warning .= $extra_desc_tip;
230
231 }
232
233 return $feature_warning;
234 }
235 }
236