ProVersionUpdateReminder.php
70 lines
| 1 | <?php |
| 2 | |
| 3 | namespace WPDesk\FS\ProVersion; |
| 4 | |
| 5 | use FSVendor\WPDesk\Notice\Notice; |
| 6 | use FSVendor\WPDesk\Notice\PermanentDismissibleNotice; |
| 7 | use FSVendor\WPDesk\PluginBuilder\Plugin\Hookable; |
| 8 | |
| 9 | /** |
| 10 | * Can display PRO version compatibility reminder. |
| 11 | */ |
| 12 | class ProVersionUpdateReminder implements Hookable { |
| 13 | |
| 14 | /** |
| 15 | * @var bool |
| 16 | */ |
| 17 | private $is_pl; |
| 18 | |
| 19 | /** |
| 20 | * @param bool $is_pl |
| 21 | */ |
| 22 | public function __construct( bool $is_pl ) { |
| 23 | $this->is_pl = $is_pl; |
| 24 | } |
| 25 | |
| 26 | |
| 27 | public function hooks() { |
| 28 | add_action( 'admin_notices', [ $this, 'add_notice_when_old_pro_version_detected' ] ); |
| 29 | } |
| 30 | |
| 31 | /** |
| 32 | * @return void |
| 33 | */ |
| 34 | public function add_notice_when_old_pro_version_detected() { |
| 35 | if ( defined( 'FLEXIBLE_SHIPPING_PRO_VERSION' ) && version_compare( FLEXIBLE_SHIPPING_PRO_VERSION, '2.5', '<' ) ) { |
| 36 | $notice_name = 'fs-pro-version-warning-' . date( 'YW' ); |
| 37 | new PermanentDismissibleNotice( |
| 38 | $this->prepare_notice_content(), |
| 39 | $notice_name, |
| 40 | Notice::NOTICE_TYPE_WARNING |
| 41 | ); |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | /** |
| 46 | * @return string |
| 47 | */ |
| 48 | private function prepare_notice_content() { |
| 49 | $my_account_link = $this->is_pl ? 'https://www.wpdesk.pl/moje-konto/api-keys/?utm_source=api-keys&utm_medium=plugin-list&utm_campaign=subscriptions' : 'https://octolize.com/my-account/api-keys/?utm_source=api-keys&utm_medium=plugin-list&utm_campaign=subscriptions'; |
| 50 | $renew_link = $this->is_pl ? 'https://www.wpdesk.pl/moje-konto/subscriptions/?utm_source=fs-update&utm_medium=plugin-list&utm_campaign=subscriptions' : 'https://octolize.com/my-account/subscriptions/?utm_source=fs-update&utm_medium=plugin-list&utm_campaign=subscriptions'; |
| 51 | return sprintf( |
| 52 | // Translators: strong, version, /strong, strong, /strong, link, link. |
| 53 | __( |
| 54 | 'The %1$sFlexible Shipping PRO %2$s%3$s version you are currently using is severely %4$soutdated%5$s. Its further use may result in onward %4$scompatibility issues%5$s. In order to perform the update, please copy your plugin API key from %6$sMy Account / API keys%7$s tab and activate it in your store. If your subscription expired and you don’t own an active one at the moment, please %8$srenew the subscription →%9$s', |
| 55 | 'flexible-shipping' |
| 56 | ), |
| 57 | '<strong>', |
| 58 | FLEXIBLE_SHIPPING_PRO_VERSION, |
| 59 | '</strong>', |
| 60 | '<strong>', |
| 61 | '</strong>', |
| 62 | '<a href="' . $my_account_link . '" target="_blank">', |
| 63 | '</a>', |
| 64 | '<a href="' . $renew_link . '" target="_blank">', |
| 65 | '</a>' |
| 66 | ); |
| 67 | } |
| 68 | |
| 69 | } |
| 70 |