abstract-rate.php
18 hours ago
admin-notices.php
18 hours ago
interface-rate.php
18 hours ago
rate-notice-implementation.php
18 hours ago
rate-notice.php
18 hours ago
admin-notices.php
134 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Admin notices. |
| 4 | * |
| 5 | * @package Flexible Shipping |
| 6 | */ |
| 7 | |
| 8 | /** |
| 9 | * Can display notices in admin. |
| 10 | */ |
| 11 | class WPDesk_Flexible_Shipping_Admin_Notices { |
| 12 | |
| 13 | const SETTINGS_CHECKED_OPTION_VALUE_SHOW_MESSAGE = '1'; |
| 14 | |
| 15 | const SETTINGS_CHECKED_OPTION_VALUE_DO_NOT_SHOW_MESSAGE = '2'; |
| 16 | |
| 17 | const BASED_ON_VALUE = 'value'; |
| 18 | |
| 19 | /** |
| 20 | * @var Flexible_Shipping_Plugin |
| 21 | */ |
| 22 | private $plugin; |
| 23 | |
| 24 | /** |
| 25 | * WPDesk_Flexible_Shipping_Admin_Notices constructor. |
| 26 | * |
| 27 | * @param Flexible_Shipping_Plugin $plugin . |
| 28 | */ |
| 29 | public function __construct( Flexible_Shipping_Plugin $plugin ) { |
| 30 | $this->plugin = $plugin; |
| 31 | $this->hooks(); |
| 32 | } |
| 33 | |
| 34 | /** |
| 35 | * Hooks. |
| 36 | */ |
| 37 | private function hooks() { |
| 38 | add_action( 'admin_notices', array( $this, 'admin_notices_plugin_activepayments' ) ); |
| 39 | add_action( 'admin_notices', array( $this, 'admin_notices_plugin_enadawca' ) ); |
| 40 | add_action( 'admin_notices', array( $this, 'admin_notices_plugin_pwr' ) ); |
| 41 | } |
| 42 | |
| 43 | |
| 44 | /** |
| 45 | * @param WC_Shipping_Method $shipping_method . |
| 46 | * |
| 47 | * @return bool |
| 48 | */ |
| 49 | private function has_value_based_rule( $shipping_method ) { |
| 50 | $methods = get_option( 'flexible_shipping_methods_' . $shipping_method->instance_id, array() ); |
| 51 | if ( is_array( $methods ) ) { |
| 52 | foreach ( $methods as $method_settings ) { |
| 53 | if ( isset( $method_settings['method_rules'] ) && is_array( $method_settings['method_rules'] ) ) { |
| 54 | foreach ( $method_settings['method_rules'] as $rule ) { |
| 55 | if ( isset( $rule['based_on'] ) && self::BASED_ON_VALUE === $rule['based_on'] ) { |
| 56 | return true; |
| 57 | } |
| 58 | } |
| 59 | } |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | return false; |
| 64 | } |
| 65 | |
| 66 | /** |
| 67 | * @return bool |
| 68 | */ |
| 69 | public function is_in_zones() { |
| 70 | if ( isset( $_GET['page'] ) && 'wc-settings' === sanitize_key( $_GET['page'] ) |
| 71 | && isset( $_GET['tab'] ) && 'shipping' === sanitize_key( $_GET['tab'] ) |
| 72 | && ( ! isset( $_GET['section'] ) || '' === $_GET['section'] ) |
| 73 | ) { |
| 74 | return true; |
| 75 | } |
| 76 | |
| 77 | return false; |
| 78 | } |
| 79 | |
| 80 | /** |
| 81 | * Active payments notice. |
| 82 | */ |
| 83 | public function admin_notices_plugin_activepayments() { |
| 84 | if ( is_plugin_active( 'woocommerce-active-payments/activepayments.php' ) ) { |
| 85 | $plugin_activepayments = get_plugin_data( WP_PLUGIN_DIR . '/woocommerce-active-payments/activepayments.php' ); |
| 86 | $version_compare = version_compare( $plugin_activepayments['Version'], '2.7' ); |
| 87 | if ( $version_compare < 0 ) { |
| 88 | $class = 'notice notice-error'; |
| 89 | $message = __( 'Flexible Shipping requires at least version 2.7 of Active Payments plugin.', 'flexible-shipping' ); |
| 90 | $this->print_notice( $class, $message ); |
| 91 | } |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | /** |
| 96 | * Enadawca notice. |
| 97 | */ |
| 98 | public function admin_notices_plugin_enadawca() { |
| 99 | if ( is_plugin_active( 'woocommerce-enadawca/woocommerce-enadawca.php' ) ) { |
| 100 | $plugin_enadawca = get_plugin_data( WP_PLUGIN_DIR . '/woocommerce-enadawca/woocommerce-enadawca.php' ); |
| 101 | $version_compare = version_compare( $plugin_enadawca['Version'], '1.2' ); |
| 102 | if ( $version_compare < 0 ) { |
| 103 | $class = 'notice notice-error'; |
| 104 | $message = __( 'Flexible Shipping requires at least version 1.2 of eNadawca plugin.', 'flexible-shipping' ); |
| 105 | $this->print_notice( $class, $message ); |
| 106 | } |
| 107 | } |
| 108 | } |
| 109 | |
| 110 | /** |
| 111 | * Paczka w Ruchu notice. |
| 112 | */ |
| 113 | public function admin_notices_plugin_pwr() { |
| 114 | if ( is_plugin_active( 'woocommerce-paczka-w-ruchu/woocommerce-paczka-w-ruchu.php' ) ) { |
| 115 | $plugin_pwr = get_plugin_data( WP_PLUGIN_DIR . '/woocommerce-paczka-w-ruchu/woocommerce-paczka-w-ruchu.php' ); |
| 116 | $version_compare = version_compare( $plugin_pwr['Version'], '1.1' ); |
| 117 | if ( $version_compare < 0 ) { |
| 118 | $class = 'notice notice-error'; |
| 119 | $message = __( 'Flexible Shipping requires at least version 1.1 of Orlen Paczka plugin.', 'flexible-shipping' ); |
| 120 | $this->print_notice( $class, $message ); |
| 121 | } |
| 122 | } |
| 123 | } |
| 124 | |
| 125 | /** |
| 126 | * @param string $class . |
| 127 | * @param string $message . |
| 128 | */ |
| 129 | private function print_notice( $class, $message ) { |
| 130 | printf( '<div class="%1$s"><p>%2$s</p></div>', $class, $message ); // phpcs:ignore |
| 131 | } |
| 132 | |
| 133 | } |
| 134 |