flexible-shipping
/
vendor_prefixed
/
wpdesk
/
wp-plugin-flow-common
/
src
/
Initialization
/
Simple
/
SimpleFreeStrategy.php
flexible-shipping
/
vendor_prefixed
/
wpdesk
/
wp-plugin-flow-common
/
src
/
Initialization
/
Simple
Last commit date
SimpleFactory.php
2 weeks ago
SimpleFreeStrategy.php
2 weeks ago
SimplePaidStrategy.php
2 weeks ago
SimpleFreeStrategy.php
66 lines
| 1 | <?php |
| 2 | |
| 3 | namespace FSVendor\WPDesk\Plugin\Flow\Initialization\Simple; |
| 4 | |
| 5 | use FSVendor\WPDesk\Plugin\Flow\Initialization\ActivationTrait; |
| 6 | use FSVendor\WPDesk\Plugin\Flow\Initialization\BuilderTrait; |
| 7 | use FSVendor\WPDesk\Plugin\Flow\Initialization\InitializationStrategy; |
| 8 | use FSVendor\WPDesk\PluginBuilder\Plugin\SlimPlugin; |
| 9 | /** |
| 10 | * Initialize free plugin |
| 11 | * - just build it already |
| 12 | */ |
| 13 | class SimpleFreeStrategy implements InitializationStrategy |
| 14 | { |
| 15 | use TrackerInstanceAsFilterTrait; |
| 16 | use BuilderTrait; |
| 17 | /** @var \WPDesk_Plugin_Info */ |
| 18 | private $plugin_info; |
| 19 | /** @var SlimPlugin */ |
| 20 | private $plugin; |
| 21 | /** @var bool */ |
| 22 | private $tracker_enabled; |
| 23 | public function __construct(\FSVendor\WPDesk_Plugin_Info $plugin_info, $tracker_enabled = \true) |
| 24 | { |
| 25 | $this->plugin_info = $plugin_info; |
| 26 | $this->tracker_enabled = $tracker_enabled; |
| 27 | } |
| 28 | /** |
| 29 | * Run tasks that prepares plugin to work. Have to run before plugin loaded. |
| 30 | * |
| 31 | * @param \WPDesk_Plugin_Info $plugin_info |
| 32 | * |
| 33 | * @return SlimPlugin |
| 34 | */ |
| 35 | public function run_before_init(\FSVendor\WPDesk_Plugin_Info $plugin_info) |
| 36 | { |
| 37 | $this->plugin = $this->build_plugin($plugin_info); |
| 38 | $this->init_register_hooks($plugin_info, $this->plugin); |
| 39 | } |
| 40 | /** |
| 41 | * Run task that integrates plugin with other dependencies. Can be run in plugins_loaded. |
| 42 | * |
| 43 | * @param \WPDesk_Plugin_Info $plugin_info |
| 44 | * |
| 45 | * @return SlimPlugin |
| 46 | */ |
| 47 | public function run_init(\FSVendor\WPDesk_Plugin_Info $plugin_info) |
| 48 | { |
| 49 | if (!$this->plugin) { |
| 50 | $this->plugin = $this->build_plugin($plugin_info); |
| 51 | } |
| 52 | if ($this->tracker_enabled) { |
| 53 | $this->prepare_tracker_action(); |
| 54 | } |
| 55 | $this->store_plugin($this->plugin); |
| 56 | $this->init_plugin($this->plugin); |
| 57 | if ($this->tracker_enabled) { |
| 58 | // Flush usage tracker late, to remain backward compatible with plugins which could instantiate |
| 59 | // the tracker on their own through `wpdesk_tracker_instance` filter. |
| 60 | $this->get_tracker_instance(); |
| 61 | $this->register_tracker_ui_extensions(); |
| 62 | } |
| 63 | return $this->plugin; |
| 64 | } |
| 65 | } |
| 66 |