← All changes
|
vendor/codeinwp/themeisle-sdk/src/Common/Abstract_module.php
+58
-6
4.2.11
→
trunk
View file →
| @@ -32,8 +32,9 @@ | ||
| 32 | 32 | 'otter-blocks' => 'otter-blocks/otter-blocks.php', |
| 33 | 33 | 'optimole-wp' => 'optimole-wp/optimole-wp.php', |
| 34 | 34 | 'tweet-old-post' => 'tweet-old-post/tweet-old-post.php', |
| 35 | 35 | 'feedzy-rss-feeds' => 'feedzy-rss-feeds/feedzy-rss-feed.php', |
| 36 | + 'insert-php' => 'insert-php/insert_php.php', | |
| 36 | 37 | 'woocommerce-product-addon' => 'woocommerce-product-addon/woocommerce-product-addon.php', |
| 37 | 38 | 'visualizer' => 'visualizer/index.php', |
| 38 | 39 | 'wp-landing-kit' => 'wp-landing-kit/wp-landing-kit.php', |
| 39 | 40 | 'multiple-pages-generator-by-porthas' => 'multiple-pages-generator-by-porthas/porthas-multi-pages-generator.php', |
| @@ -39,14 +40,23 @@ | ||
| 39 | 40 | 'multiple-pages-generator-by-porthas' => 'multiple-pages-generator-by-porthas/porthas-multi-pages-generator.php', |
| 40 | 41 | 'sparks-for-woocommerce' => 'sparks-for-woocommerce/sparks-for-woocommerce.php', |
| 41 | 42 | 'templates-patterns-collection' => 'templates-patterns-collection/templates-patterns-collection.php', |
| 42 | 43 | 'wpcf7-redirect' => 'wpcf7-redirect/wpcf7-redirect.php', |
| 44 | + 'anti-spam' => 'anti-spam/anti-spam.php', | |
| 43 | 45 | 'wp-full-stripe-free' => 'wp-full-stripe-free/wp-full-stripe.php', |
| 44 | 46 | 'learning-management-system' => 'learning-management-system/lms.php', |
| 45 | 47 | 'wp-cloudflare-page-cache' => 'wp-cloudflare-page-cache/wp-cloudflare-super-page-cache.php', |
| 48 | + 'easy-mcp-ai' => 'easy-mcp-ai/easy-mcp-ai.php', | |
| 46 | 49 | ]; |
| 47 | 50 | |
| 48 | 51 | /** |
| 52 | + * Runtime-resolved plugin paths. | |
| 53 | + * | |
| 54 | + * @var string[] $resolved_plugin_paths Plugin main file path by slug. | |
| 55 | + */ | |
| 56 | + private $resolved_plugin_paths = []; | |
| 57 | + | |
| 58 | + /** | |
| 49 | 59 | * Product which use the module. |
| 50 | 60 | * |
| 51 | 61 | * @var Product $product Product object. |
| 52 | 62 | */ |
| @@ -173,13 +183,11 @@ | ||
| 173 | 183 | * |
| 174 | 184 | * @return bool |
| 175 | 185 | */ |
| 176 | 186 | public function is_plugin_installed( $plugin ) { |
| 177 | - if ( ! isset( $this->plugin_paths[ $plugin ] ) ) { | |
| 178 | - return false; | |
| 179 | - } | |
| 187 | + $plugin_file = $this->resolve_plugin_main_file( $plugin ); | |
| 180 | 188 | |
| 181 | - if ( file_exists( WP_CONTENT_DIR . '/plugins/' . $this->plugin_paths[ $plugin ] ) ) { | |
| 189 | + if ( file_exists( WP_CONTENT_DIR . '/plugins/' . $plugin_file ) ) { | |
| 182 | 190 | return true; |
| 183 | 191 | } |
| 184 | 192 | |
| 185 | 193 | return false; |
| @@ -193,9 +201,9 @@ | ||
| 193 | 201 | * @return string |
| 194 | 202 | */ |
| 195 | 203 | public function get_plugin_activation_link( $slug ) { |
| 196 | 204 | $reference_key = $slug === 'otter-blocks' ? 'reference_key' : 'optimole_reference_key'; |
| 197 | - $plugin = isset( $this->plugin_paths[ $slug ] ) ? $this->plugin_paths[ $slug ] : $slug . '/' . $slug . '.php'; | |
| 205 | + $plugin = $this->resolve_plugin_main_file( $slug ); | |
| 198 | 206 | |
| 199 | 207 | return add_query_arg( |
| 200 | 208 | array( |
| 201 | 209 | 'plugin_status' => 'all', |
| @@ -218,11 +226,55 @@ | ||
| 218 | 226 | */ |
| 219 | 227 | public function is_plugin_active( $plugin ) { |
| 220 | 228 | include_once ABSPATH . 'wp-admin/includes/plugin.php'; |
| 221 | 229 | |
| 222 | - $plugin = isset( $this->plugin_paths[ $plugin ] ) ? $this->plugin_paths[ $plugin ] : $plugin . '/' . $plugin . '.php'; | |
| 230 | + $plugin = $this->resolve_plugin_main_file( $plugin ); | |
| 223 | 231 | |
| 224 | 232 | return is_plugin_active( $plugin ); |
| 233 | + } | |
| 234 | + | |
| 235 | + /** | |
| 236 | + * Resolve a plugin's main file path by slug. | |
| 237 | + * | |
| 238 | + * @param string $slug Plugin slug. | |
| 239 | + * | |
| 240 | + * @return string | |
| 241 | + */ | |
| 242 | + private function resolve_plugin_main_file( $slug ) { | |
| 243 | + if ( isset( $this->resolved_plugin_paths[ $slug ] ) ) { | |
| 244 | + return $this->resolved_plugin_paths[ $slug ]; | |
| 245 | + } | |
| 246 | + | |
| 247 | + if ( isset( $this->plugin_paths[ $slug ] ) ) { | |
| 248 | + $this->resolved_plugin_paths[ $slug ] = $this->plugin_paths[ $slug ]; | |
| 249 | + return $this->resolved_plugin_paths[ $slug ]; | |
| 250 | + } | |
| 251 | + | |
| 252 | + $default_plugin_file = $slug . '/' . $slug . '.php'; | |
| 253 | + | |
| 254 | + if ( file_exists( WP_CONTENT_DIR . '/plugins/' . $default_plugin_file ) ) { | |
| 255 | + $this->resolved_plugin_paths[ $slug ] = $default_plugin_file; | |
| 256 | + return $this->resolved_plugin_paths[ $slug ]; | |
| 257 | + } | |
| 258 | + | |
| 259 | + include_once ABSPATH . 'wp-admin/includes/plugin.php'; | |
| 260 | + | |
| 261 | + if ( function_exists( 'get_plugins' ) ) { | |
| 262 | + $plugins = get_plugins( '/' . $slug ); | |
| 263 | + | |
| 264 | + if ( ! empty( $plugins ) ) { | |
| 265 | + $plugin_files = array_keys( $plugins ); | |
| 266 | + $plugin_file = $slug . '/' . reset( $plugin_files ); | |
| 267 | + | |
| 268 | + $this->resolved_plugin_paths[ $slug ] = $plugin_file; | |
| 269 | + | |
| 270 | + return $this->resolved_plugin_paths[ $slug ]; | |
| 271 | + } | |
| 272 | + } | |
| 273 | + | |
| 274 | + $this->resolved_plugin_paths[ $slug ] = $default_plugin_file; | |
| 275 | + | |
| 276 | + return $this->resolved_plugin_paths[ $slug ]; | |
| 225 | 277 | } |
| 226 | 278 | |
| 227 | 279 | /** |
| 228 | 280 | * Get the current date. |