PluginActivation.php
58 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Class PluginActivation |
| 4 | * |
| 5 | * @package WPDesk\FS\Plugin |
| 6 | */ |
| 7 | |
| 8 | namespace WPDesk\FS\Plugin; |
| 9 | |
| 10 | use FSVendor\WPDesk\PluginBuilder\Plugin\Hookable; |
| 11 | |
| 12 | /** |
| 13 | * Can redirect to FS Info tab on first plugin activation. |
| 14 | */ |
| 15 | class PluginActivation implements Hookable { |
| 16 | |
| 17 | const OPTION_NAME = 'flexible-shipping-activation-redirected'; |
| 18 | const SHIPPING_METHOD_ID = 'flexible_shipping_info'; |
| 19 | |
| 20 | /** |
| 21 | * Hooks. |
| 22 | */ |
| 23 | public function hooks() { |
| 24 | add_action( 'admin_init', array( $this, 'redirect_on_first_activation_or_do_nothing' ) ); |
| 25 | } |
| 26 | |
| 27 | /** |
| 28 | * . |
| 29 | */ |
| 30 | public function redirect_on_first_activation_or_do_nothing() { |
| 31 | if ( 0 === (int) get_option( self::OPTION_NAME, 1 ) ) { |
| 32 | if ( wp_safe_redirect( admin_url( 'admin.php?page=wc-settings&tab=shipping§ion=' . self::SHIPPING_METHOD_ID ) ) ) { |
| 33 | update_option( self::OPTION_NAME, 1 ); |
| 34 | $this->terminate(); |
| 35 | } |
| 36 | } |
| 37 | } |
| 38 | |
| 39 | /** |
| 40 | * . |
| 41 | * |
| 42 | * @codeCoverageIgnore |
| 43 | */ |
| 44 | protected function terminate() { |
| 45 | die(); |
| 46 | } |
| 47 | |
| 48 | /** |
| 49 | * . |
| 50 | */ |
| 51 | public function add_activation_option_if_not_present() { |
| 52 | if ( false === get_option( self::OPTION_NAME, false ) ) { |
| 53 | add_option( self::OPTION_NAME, 0 ); |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | } |
| 58 |