PluginProbe
seQura / 4.3.0
seQura v4.3.0
4.3.4 4.3.3 4.3.2 4.3.1 trunk 2.0.0 2.0.10 2.0.11 2.0.12 2.0.5 2.0.6 2.0.7 2.0.8 2.0.9 3.0.0 3.0.2 3.0.5 3.0.6 3.0.7 3.1.0 3.1.1 3.2.0 3.2.1 3.2.2 4.0.0 All 30 releases
← All changes | src/class-plugin.php +84 -50 3.0.24.3.0 View file →
@@ -14,8 +14,9 @@
14 14 use SeQura\WC\Controllers\Hooks\Payment\Interface_Payment_Controller;
15 15 use SeQura\WC\Controllers\Hooks\Process\Interface_Async_Process_Controller;
16 16 use SeQura\WC\Controllers\Hooks\Settings\Interface_Settings_Controller;
17 17 use SeQura\WC\Controllers\Rest\REST_Controller;
18 +use SeQura\WC\Services\Constants\Interface_Constants;
18 19 use SeQura\WC\Services\Migration\Interface_Migration_Manager;
19 20
20 21 /**
21 22 * The core plugin class.
@@ -29,8 +30,22 @@
29 30 */
30 31 private $data;
31 32
32 33 /**
34 + * The WordPress version
35 + *
36 + * @var string
37 + */
38 + private $wp_version;
39 +
40 + /**
41 + * The WooCommerce version
42 + *
43 + * @var string
44 + */
45 + private $wc_version;
46 +
47 + /**
33 48 * The plugin base name.
34 49 *
35 50 * @var string
36 51 */
@@ -50,16 +65,15 @@
50 65 */
51 66 private $migration_manager;
52 67
53 68 private const HOOK_DELIVERY_REPORT = 'sequra_delivery_report';
69 + private const HOOK_CLEANUP_ORDERS = 'sequra_cleanup_orders';
54 70
55 71 /**
56 72 * Construct the plugin and bind hooks with controllers.
57 73 */
58 74 public function __construct(
59 - array $data,
60 - string $file_path,
61 - string $base_name,
75 + Interface_Constants $constants,
62 76 Interface_Migration_Manager $migration_manager,
63 77 Interface_I18n_Controller $i18n_controller,
64 78 Interface_Assets_Controller $assets_controller,
65 79 Interface_Settings_Controller $settings_controller,
@@ -67,67 +81,76 @@
67 81 REST_Controller $rest_settings_controller,
68 82 REST_Controller $rest_onboarding_controller,
69 83 REST_Controller $rest_payment_controller,
70 84 REST_Controller $rest_log_controller,
85 + REST_Controller $rest_store_integration_controller,
71 86 Interface_Product_Controller $product_controller,
72 87 Interface_Async_Process_Controller $async_process_controller,
73 88 Interface_Order_Controller $order_controller
74 89 ) {
75 - $this->data = $data;
76 - $this->file_path = $file_path;
77 - $this->base_name = $base_name;
90 + $this->data = $constants->get_plugin_data();
91 + $this->wp_version = $constants->get_environment_data()['wp_version'] ?? '';
92 + $this->wc_version = $constants->get_woocommerce_data()['Version'] ?? '';
93 + $this->file_path = $constants->get_plugin_file_path();
94 + $this->base_name = $constants->get_plugin_basename();
78 95 $this->migration_manager = $migration_manager;
79 96
80 - add_action( 'plugins_loaded', array( $this, 'install' ) );
97 + \add_action( 'init', array( $this, 'install' ) );
81 98
82 99 // I18n.
83 - add_action( 'plugins_loaded', array( $i18n_controller, 'load_text_domain' ) );
100 + \add_action( 'plugins_loaded', array( $i18n_controller, 'load_text_domain' ) );
84 101
85 102 // Assets hooks.
86 - add_action( 'admin_enqueue_scripts', array( $assets_controller, 'enqueue_admin' ) );
87 - add_action( 'wp_enqueue_scripts', array( $assets_controller, 'enqueue_front' ) );
103 + \add_action( 'admin_enqueue_scripts', array( $assets_controller, 'enqueue_admin' ) );
104 + \add_action( 'wp_enqueue_scripts', array( $assets_controller, 'enqueue_front' ) );
88 105
89 106 // Settings hooks.
90 - add_action( 'admin_menu', array( $settings_controller, 'register_page' ) );
91 - add_filter( "plugin_action_links_{$base_name}", array( $settings_controller, 'add_action_link' ), 10, 4 );
92 - add_filter( 'sequra_settings_page_url', array( $settings_controller, 'get_settings_page_url' ) );
93 - add_filter( 'admin_footer_text', array( $settings_controller, 'remove_footer_admin' ) );
94 - add_filter( 'plugin_row_meta', array( $settings_controller, 'add_plugin_row_meta' ), 10, 2 );
107 + \add_action( 'admin_menu', array( $settings_controller, 'register_page' ) );
108 + \add_filter( "plugin_action_links_{$this->base_name}", array( $settings_controller, 'add_action_link' ), 10, 4 );
109 + \add_filter( 'sequra_settings_page_url', array( $settings_controller, 'get_settings_page_url' ) );
110 + \add_filter( 'admin_footer_text', array( $settings_controller, 'remove_footer_admin' ) );
111 + \add_filter( 'plugin_row_meta', array( $settings_controller, 'add_plugin_row_meta' ), 10, 2 );
95 112
96 113 // REST Controllers.
97 - add_action( 'rest_api_init', array( $rest_settings_controller, 'register_routes' ) );
98 - add_action( 'rest_api_init', array( $rest_onboarding_controller, 'register_routes' ) );
99 - add_action( 'rest_api_init', array( $rest_payment_controller, 'register_routes' ) );
100 - add_action( 'rest_api_init', array( $rest_log_controller, 'register_routes' ) );
114 + \add_action( 'rest_api_init', array( $rest_settings_controller, 'register_routes' ) );
115 + \add_action( 'rest_api_init', array( $rest_onboarding_controller, 'register_routes' ) );
116 + \add_action( 'rest_api_init', array( $rest_payment_controller, 'register_routes' ) );
117 + \add_action( 'rest_api_init', array( $rest_log_controller, 'register_routes' ) );
118 + \add_action( 'rest_api_init', array( $rest_store_integration_controller, 'register_routes' ) );
101 119
102 120 // Payment hooks.
103 - add_filter( 'woocommerce_payment_gateways', array( $payment_controller, 'register_gateway_classes' ) );
104 - add_action( 'woocommerce_blocks_loaded', array( $payment_controller, 'register_gateway_gutenberg_block' ) );
121 + \add_filter( 'woocommerce_payment_gateways', array( $payment_controller, 'register_gateway_classes' ) );
122 + \add_action( 'woocommerce_blocks_loaded', array( $payment_controller, 'register_gateway_gutenberg_block' ) );
105 123
106 - add_filter( 'woocommerce_thankyou_order_received_text', array( $payment_controller, 'order_received_text' ), 10, 2 );
107 - add_filter( 'woocommerce_order_get_payment_method_title', array( $payment_controller, 'order_get_payment_method_title' ), 10, 2 );
124 + \add_filter( 'woocommerce_thankyou_order_received_text', array( $payment_controller, 'order_received_text' ), 10, 2 );
125 + \add_filter( 'woocommerce_order_get_payment_method_title', array( $payment_controller, 'order_get_payment_method_title' ), 10, 2 );
108 126
109 127 // Product widget.
110 - add_action( 'woocommerce_after_main_content', array( $product_controller, 'add_widget_shortcode_to_page' ) );
111 - add_action( 'wp_footer', array( $product_controller, 'add_widget_shortcode_to_page' ) );
128 + \add_action( 'woocommerce_after_main_content', array( $product_controller, 'add_widget_shortcode_to_page' ) );
129 + \add_action( 'wp_footer', array( $product_controller, 'add_widget_shortcode_to_page' ) );
112 130
113 - add_shortcode( 'sequra_widget', array( $product_controller, 'do_widget_shortcode' ) );
114 - add_shortcode( 'sequra_cart_widget', array( $product_controller, 'do_cart_widget_shortcode' ) );
115 - add_shortcode( 'sequra_product_listing_widget', array( $product_controller, 'do_product_listing_widget_shortcode' ) );
131 + \add_shortcode( 'sequra_widget', array( $product_controller, 'do_widget_shortcode' ) );
132 + \add_shortcode( 'sequra_cart_widget', array( $product_controller, 'do_cart_widget_shortcode' ) );
133 + \add_shortcode( 'sequra_product_listing_widget', array( $product_controller, 'do_product_listing_widget_shortcode' ) );
116 134
117 - add_action( 'add_meta_boxes', array( $product_controller, 'add_meta_boxes' ) );
118 - add_action( 'woocommerce_process_product_meta', array( $product_controller, 'save_product_meta' ) );
135 + \add_action( 'add_meta_boxes', array( $product_controller, 'add_meta_boxes' ) );
136 + \add_action( 'woocommerce_process_product_meta', array( $product_controller, 'save_product_meta' ) );
119 137
120 138 // Delivery report.
121 - add_action( self::HOOK_DELIVERY_REPORT, array( $async_process_controller, 'send_delivery_report' ) );
122 - add_filter( 'woocommerce_order_data_store_cpt_get_orders_query', array( $order_controller, 'handle_custom_query_vars' ), 10, 3 );
139 + \add_action( self::HOOK_DELIVERY_REPORT, array( $async_process_controller, 'send_delivery_report' ) );
140 + \add_filter( 'woocommerce_order_data_store_cpt_get_orders_query', array( $order_controller, 'handle_custom_query_vars' ), 10, 3 );
123 141
124 142 // Order Update.
125 - add_action( 'woocommerce_order_status_changed', array( $order_controller, 'handle_order_status_changed' ), 10, 4 );
126 - add_action( 'woocommerce_admin_order_data_after_order_details', array( $order_controller, 'show_link_to_sequra_back_office' ) );
143 + \add_action( 'woocommerce_order_status_changed', array( $order_controller, 'handle_order_status_changed' ), 10, 4 );
144 + \add_action( 'woocommerce_admin_order_data_after_order_details', array( $order_controller, 'show_link_to_sequra_back_office' ) );
145 + \add_action( self::HOOK_CLEANUP_ORDERS, array( $order_controller, 'cleanup_orders' ) );
146 + \add_action( $constants->get_hook_add_order_indexes(), array( $order_controller, 'migrate_orders_to_use_indexes' ) );
127 147
128 148 // WooCommerce Compat.
129 - add_action( 'before_woocommerce_init', array( $this, 'declare_woocommerce_compatibility' ) );
149 + \add_action( 'before_woocommerce_init', array( $this, 'declare_woocommerce_compatibility' ) );
150 +
151 + // Cart identifier generation.
152 + \add_action( 'woocommerce_init', array( $order_controller, 'ensure_cart_info_exists' ) );
130 153 }
131 154
132 155 /**
133 156 * Handle activation of the plugin.
@@ -133,21 +156,20 @@
133 156 * Handle activation of the plugin.
134 157 */
135 158 public function activate(): void {
136 159 if ( version_compare( PHP_VERSION, $this->data['RequiresPHP'], '<' ) ) {
137 - deactivate_plugins( $this->base_name );
138 - wp_die( esc_html( 'This plugin requires PHP ' . $this->data['RequiresPHP'] . ' or greater.' ) );
160 + \deactivate_plugins( $this->base_name );
161 + \wp_die( \esc_html( 'This plugin requires PHP ' . $this->data['RequiresPHP'] . ' or greater.' ) );
139 162 }
140 163
141 - global $wp_version;
142 - if ( version_compare( $wp_version, $this->data['RequiresWP'], '<' ) ) {
143 - deactivate_plugins( $this->base_name );
144 - wp_die( esc_html( 'This plugin requires WordPress ' . $this->data['RequiresWP'] . ' or greater.' ) );
164 + if ( version_compare( $this->wp_version, $this->data['RequiresWP'], '<' ) ) {
165 + \deactivate_plugins( $this->base_name );
166 + \wp_die( \esc_html( 'This plugin requires WordPress ' . $this->data['RequiresWP'] . ' or greater.' ) );
145 167 }
146 168
147 - if ( ! defined( 'WC_VERSION' ) || version_compare( WC_VERSION, $this->data['RequiresWC'], '<' ) ) {
148 - deactivate_plugins( $this->base_name );
149 - wp_die( esc_html( 'This plugin requires WooCommerce ' . $this->data['RequiresWC'] . ' or greater.' ) );
169 + if ( version_compare( $this->wc_version, $this->data['RequiresWC'], '<' ) ) {
170 + \deactivate_plugins( $this->base_name );
171 + \wp_die( \esc_html( 'This plugin requires WooCommerce ' . $this->data['RequiresWC'] . ' or greater.' ) );
150 172 }
151 173 }
152 174
153 175 /**
@@ -153,20 +175,32 @@
153 175 /**
154 176 * Handle deactivation of the plugin.
155 177 */
156 178 public function deactivate(): void {
157 - wp_clear_scheduled_hook( self::HOOK_DELIVERY_REPORT );
179 + \wp_clear_scheduled_hook( self::HOOK_DELIVERY_REPORT );
180 + \wp_clear_scheduled_hook( self::HOOK_CLEANUP_ORDERS );
158 181 }
159 182
160 183 /**
184 + * Get a random time between 2AM and 8AM.
185 + *
186 + * @return int
187 + */
188 + private function get_random_midnight_time() {
189 + $random_offset = \wp_rand( 0, 25200 ); // 60*60*7 seconds from 2AM to 8AM.
190 + $tomorrow = gmdate( 'Y-m-d 02:00', strtotime( 'tomorrow' ) );
191 + return $random_offset + strtotime( $tomorrow );
192 + }
193 +
194 + /**
161 195 * Execute the installation process if needed.
162 196 */
163 197 public function install(): void {
164 - if ( ! wp_next_scheduled( self::HOOK_DELIVERY_REPORT ) ) {
165 - $random_offset = wp_rand( 0, 25200 ); // 60*60*7 seconds from 2AM to 8AM.
166 - $tomorrow = gmdate( 'Y-m-d 02:00', strtotime( 'tomorrow' ) );
167 - $time = $random_offset + strtotime( $tomorrow );
168 - wp_schedule_event( $time, 'daily', self::HOOK_DELIVERY_REPORT );
198 + if ( ! \wp_next_scheduled( self::HOOK_DELIVERY_REPORT ) ) {
199 + \wp_schedule_event( $this->get_random_midnight_time(), 'daily', self::HOOK_DELIVERY_REPORT );
200 + }
201 + if ( ! \wp_next_scheduled( self::HOOK_CLEANUP_ORDERS ) ) {
202 + \wp_schedule_event( $this->get_random_midnight_time(), 'daily', self::HOOK_CLEANUP_ORDERS );
169 203 }
170 204 $this->migration_manager->run_install_migrations();
171 205 }
172 206