flexible-shipping
/
vendor_prefixed
/
wpdesk
/
wp-plugin-flow-common
/
src
/
Initialization
/
PluginDisablerByFileTrait.php
flexible-shipping
/
vendor_prefixed
/
wpdesk
/
wp-plugin-flow-common
/
src
/
Initialization
Last commit date
Simple
2 weeks ago
BuilderTrait.php
2 weeks ago
InitializationFactory.php
2 weeks ago
InitializationStrategy.php
2 weeks ago
PluginDisablerByFileTrait.php
2 weeks ago
TrackerInstanceAsFilterTrait.php
2 weeks ago
PluginDisablerByFileTrait.php
49 lines
| 1 | <?php |
| 2 | |
| 3 | namespace FSVendor\WPDesk\Plugin\Flow\Initialization; |
| 4 | |
| 5 | /** |
| 6 | * Can disable shared plugin before it's loaded using plugin filename |
| 7 | */ |
| 8 | class PluginDisablerByFileTrait |
| 9 | { |
| 10 | /** @var string */ |
| 11 | private $plugin_file; |
| 12 | /** |
| 13 | * @param string $plugin_file |
| 14 | */ |
| 15 | public function __construct($plugin_file) |
| 16 | { |
| 17 | $this->plugin_file = $plugin_file; |
| 18 | } |
| 19 | /** |
| 20 | * @return void |
| 21 | */ |
| 22 | public function disable() |
| 23 | { |
| 24 | /** |
| 25 | * @param WPDesk_Loader[] $loaders |
| 26 | * |
| 27 | * @return array |
| 28 | */ |
| 29 | $false_for_helper = function ($loaders) { |
| 30 | return array_filter($loaders, function ($loader) { |
| 31 | try { |
| 32 | // BIG HACK TO GET PRIVATE PROPERTY |
| 33 | $reflection = new \ReflectionClass($loader); |
| 34 | $property = $reflection->getProperty('loader_info'); |
| 35 | $property->setAccessible(\true); |
| 36 | /** @var WPDesk_Composer_Loader_Info $inner_info */ |
| 37 | $inner_info = $property->getValue($loader); |
| 38 | $plugin_info = $inner_info->get_plugin_info(); |
| 39 | return basename($plugin_info->get_plugin_file_name()) !== basename($this->plugin_file); |
| 40 | } catch (\Exception $e) { |
| 41 | return \true; |
| 42 | } |
| 43 | }); |
| 44 | }; |
| 45 | add_filter('wp_autoloader_loader_loaders_to_load', $false_for_helper); |
| 46 | add_filter('wp_autoloader_loader_loaders_to_create', $false_for_helper); |
| 47 | } |
| 48 | } |
| 49 |