PluginProbe
Instantio — Side Cart & One-Page Checkout for WooCommerce / trunk
Instantio — Side Cart & One-Page Checkout for WooCommerce vtrunk
3.3.34 trunk 1.0 1.1 1.1.1 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.3.0 2.0.0 2.1.0 2.1.2 2.1.3 2.2.0 2.2.1 2.2.2 2.2.3 2.3.1 2.3.2 All 122 releases
instantio / instantio.php

instantio.php in Instantio — Side Cart & One-Page Checkout for WooCommerce trunk, at instantio.php

310 lines 9.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Plugin Name: Instantio — Side Cart & One-Page Checkout for WooCommerce
4 * Plugin URI: https://themefic.com/instantio/
5 * Description: WooCommerce direct checkout plugin with Side Cart, Popup Cart, Floating Cart & Popup Checkout function (+ 4 more WooCommerce Quick Checkout systems).
6 * Author: Themefic
7 * Text Domain: instantio
8 * Domain Path: /lang/
9 * Author URI: https://themefic.com
10 * Tags: woocommerce cart, woocommerce checkout, woocommerce direct checkout, multistep checkout, woocommerce side cart
11 * Version: 3.3.36
12 * Requires PHP: 7.4
13 * License: GPLv3
14 * License URI: https://www.gnu.org/licenses/gpl-3.0.html
15 **/
16
17 // don't load directly
18 defined( 'ABSPATH' ) || exit;
19
20 class INSTANTIO {
21
22 /**
23 * Legacy Pro version prevented from booting during this request.
24 *
25 * @var string
26 */
27 private $instantio_incompatible_pro_version = '';
28
29 public function __construct() {
30 $this->define_constants();
31 $this->init_hooks();
32 $this->includes();
33 $this->ins_public_hooks();
34
35 //enqueue scripts
36 add_action( 'admin_enqueue_scripts', [ $this, 'Ins_tourfic_admin_denqueue_script' ], 20 );
37 }
38
39 /**
40 * Define constants
41 */
42 private function define_constants() {
43 if ( ! defined( 'INSTANTIO_VERSION' ) ) {
44 define( 'INSTANTIO_VERSION', '3.3.36' );
45 }
46 define( 'INSTANTIO_MIN_PREFIXED_PRO_VERSION', '3.2.12' );
47 define( 'INSTANTIO_URL', plugin_dir_url( __FILE__ ) );
48 define( 'INSTANTIO_INC_URL', INSTANTIO_URL . 'includes' );
49 define( 'INSTANTIO_LAYOUTS_URL', INSTANTIO_URL . 'includes/layouts' );
50 define( 'INSTANTIO_ASSETS_URL', INSTANTIO_URL . 'assets' );
51 define( 'INSTANTIO_ADMIN_URL', INSTANTIO_URL . 'admin' );
52
53 define( 'INSTANTIO_PATH', plugin_dir_path( __FILE__ ) );
54 define( 'INSTANTIO_INC_PATH', INSTANTIO_PATH . 'includes' );
55 define( 'INSTANTIO_ADMIN_PATH', INSTANTIO_PATH . 'admin' );
56 define( 'INSTANTIO_CONTROLLER_PATH', INSTANTIO_INC_PATH . '/controller' );
57 define( 'INSTANTIO_BASE_LOCATION', plugin_basename( __FILE__ ) );
58 define( 'INSTANTIO_TEMPLATES_PATH', INSTANTIO_INC_PATH . '/templates' );
59
60 /**
61 * Ajax install & activate WooCommerce
62 *
63 * @since 3.0
64 * @link https://developer.wordpress.org/reference/functions/wp_ajax_install_plugin/
65 */
66 add_action( "wp_ajax_instantio_ajax_install_woocommerce", "wp_ajax_install_plugin" );
67
68 }
69
70 /**
71 * Include required core files used in admin and on the frontend.
72 */
73 private function includes() {
74 require_once __DIR__ . '/vendor/autoload.php';
75 include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
76 require_once( 'functions.php' );
77
78 // Ins Quick Setup wizard & Ins_checkout_Editor
79 if ( is_plugin_active( 'woocommerce/woocommerce.php' ) ) {
80 require_once INSTANTIO_INC_PATH . '/controller/class-setup-wizard.php';
81
82 // Ins_checkout_Editor
83 require_once INSTANTIO_INC_PATH . '/controller/checkout_editor.php';
84 }
85
86 // ins Promo Banner
87 if ( defined('INSTANTIO_INC_PATH') && !empty(INSTANTIO_INC_PATH) ) {
88 require_once INSTANTIO_INC_PATH . '/controller/class-dashboard-widget.php';
89 }
90
91 }
92
93 /**
94 * Init Instantio when WordPress Initialises.
95 */
96 private function init_hooks() {
97 add_action( 'init', array( $this, 'init' ), 0 );
98 }
99
100 /**
101 * init Instantio when WordPress Initialises.
102 *
103 * @since 1.0
104 */
105 public function init() {
106 $this->instantio_guard_legacy_pro();
107
108 add_action( 'init', array( $this, 'ins_plugin_loaded_action' ) );
109
110 if ( is_plugin_active( 'woocommerce/woocommerce.php' ) ) {
111 new Themefic\Instantio\Controller\Assets();
112 }
113
114 if ( is_admin() && ! wp_doing_ajax() ) {
115 new Themefic\Instantio\Controller\Admin();
116
117 } else {
118 new Themefic\Instantio\Controller\App();
119
120 // ins Variation product Quick Views
121 add_action( 'wp_ajax_instantio_variable_product_quick_view', array( $this, 'ins_ajax_quickview_variable_products' ) );
122 add_action( 'wp_ajax_nopriv_instantio_variable_product_quick_view', array( $this, 'ins_ajax_quickview_variable_products' ) );
123 }
124
125 }
126
127 /**
128 * Prevent legacy Pro releases from calling removed, noncompliant Free APIs.
129 *
130 * Instantio Pro versions before 3.2.12 call the former global insopt()
131 * helper. That short global name cannot remain in the WordPress.org package.
132 * Free initializes at priority 0, before Pro's priority-10 bootstrap, so the
133 * incompatible callback can be paused without deactivating the add-on.
134 */
135 private function instantio_guard_legacy_pro() {
136 if ( ! is_plugin_active( 'wooinstant/wooinstant.php' ) || ! class_exists( 'WOOINS', false ) ) {
137 return;
138 }
139
140 $pro_version = defined( 'INSTANTIO_PRO_VERSION' ) ? INSTANTIO_PRO_VERSION : '0';
141 if ( version_compare( $pro_version, INSTANTIO_MIN_PREFIXED_PRO_VERSION, '>=' ) ) {
142 return;
143 }
144
145 global $wp_filter;
146
147 if ( empty( $wp_filter['init'] ) || empty( $wp_filter['init']->callbacks ) ) {
148 return;
149 }
150
151 foreach ( $wp_filter['init']->callbacks as $priority => $callbacks ) {
152 foreach ( $callbacks as $callback ) {
153 $function = isset( $callback['function'] ) ? $callback['function'] : null;
154
155 if (
156 is_array( $function )
157 && isset( $function[0], $function[1] )
158 && is_object( $function[0] )
159 && is_a( $function[0], 'WOOINS' )
160 && 'wooinstant' === $function[1]
161 ) {
162 remove_action( 'init', $function, $priority );
163 $this->instantio_incompatible_pro_version = $pro_version;
164 }
165 }
166 }
167
168 if ( $this->instantio_incompatible_pro_version && is_admin() ) {
169 add_action( 'admin_notices', array( $this, 'instantio_incompatible_pro_notice' ) );
170 }
171 }
172
173 /**
174 * Tell administrators why legacy Pro was safely paused.
175 */
176 public function instantio_incompatible_pro_notice() {
177 if ( ! current_user_can( 'update_plugins' ) ) {
178 return;
179 }
180 ?>
181 <div class="notice notice-error">
182 <p>
183 <?php
184 printf(
185 /* translators: 1: installed Pro version, 2: required Pro version. */
186 esc_html__( 'Instantio Pro %1$s was not loaded because it is incompatible with this Instantio Free release. Update Instantio Pro to version %2$s or newer to restore Pro features.', 'instantio' ),
187 esc_html( $this->instantio_incompatible_pro_version ),
188 esc_html( INSTANTIO_MIN_PREFIXED_PRO_VERSION )
189 );
190 ?>
191 </p>
192 </div>
193 <?php
194 }
195
196 /**
197 * Plugins Loaded Actions
198 *
199 * Including Option Panel
200 *
201 * Including Options
202 */
203 public function ins_plugin_loaded_action() {
204
205 if ( defined('INSTANTIO_PATH') && !empty(INSTANTIO_PATH) ) {
206 require_once INSTANTIO_PATH . 'admin/tf-options/Instantio_Options.php';
207 }
208
209 }
210
211 /**
212 * Ajax variable products quick view
213 */
214
215 public function ins_ajax_quickview_variable_products() {
216 global $post, $product, $woocommerce;
217
218 // return 1;
219 check_ajax_referer( 'instantio_ajax_nonce', 'security' );
220
221 add_action( 'instantio_product_data', 'woocommerce_template_single_add_to_cart' );
222
223 $product_id = isset( $_POST['product_id'] ) ? absint( wp_unslash( $_POST['product_id'] ) ) : 0;
224 if ( ! $product_id ) {
225 wp_send_json_error( array( 'message' => __( 'Invalid product.', 'instantio' ) ), 400 );
226 }
227
228 $wiqv_loop = new WP_Query(
229 array(
230 'post_type' => 'product',
231 'p' => $product_id,
232 )
233 );
234 if ( $wiqv_loop->have_posts() ) :
235 while ( $wiqv_loop->have_posts() ) :
236 $wiqv_loop->the_post(); ?>
237 <?php wc_get_template( 'single-product/add-to-cart/variation.php' ); ?>
238 <script>
239 jQuery.getScript("<?php echo esc_url( $woocommerce->plugin_url() . '/assets/js/frontend/add-to-cart-variation.min.js' ); ?>");
240 </script>
241 <?php
242 do_action( 'instantio_product_data' );
243 endwhile;
244 endif;
245 wp_reset_postdata();
246
247 wp_die();
248 }
249
250 private function ins_public_hooks() {
251 add_action( 'after_setup_theme', [ $this, 'ins_check_editor' ] );
252 }
253
254 public function ins_check_editor() {
255 $ins_billing_fields = apply_filters( 'instantio_billing_fields_priority', 1000 );
256 $ins_shipping_fields = apply_filters( 'instantio_shipping_fields_priority', 1000 );
257
258 add_filter( 'woocommerce_default_address_fields', 'instantio_override_checkout_billing_address', $ins_billing_fields, 2 );
259 add_filter( 'woocommerce_checkout_fields', 'instantio_override_checkout_billing_fields', $ins_billing_fields, 2 );
260 add_filter( 'woocommerce_checkout_fields', 'instantio_override_checkout_shipping_fields', $ins_shipping_fields, 2 );
261 // add_filter('woocommerce_default_address_fields', 'instantio_override_checkout_shipping_address');
262 }
263
264 public function Ins_tourfic_admin_denqueue_script( $screen ) {
265 $ins_options_screens = array(
266 'toplevel_page_wiopt',
267 'instantio_page_ins_dashboard',
268 'instantio_page_tf_license_info',
269 'instantio_page_ins_get_help',
270 'instantio_page_ins_whats_new',
271 'admin_page_ins-setup-wizard',
272 'instantio_page_ins-license-activation'
273 );
274
275 //The tourfic admin js Listings Directory Compatibility
276 if ( in_array( $screen, $ins_options_screens ) ) {
277 wp_dequeue_style( 'tf-admin' );
278 wp_deregister_style( 'tf-admin' );
279 wp_dequeue_style( 'tf-pro' );
280 wp_dequeue_script( 'tf-pro' );
281 wp_deregister_script('tf-pro');
282 }
283 }
284
285 }
286
287
288 new INSTANTIO();
289
290 add_action( 'admin_enqueue_scripts', 'instantio_admin_enqueue_scripts' );
291 add_action( 'before_woocommerce_init', 'instantio_before_woocommerce_init' );
292
293 function instantio_before_woocommerce_init() {
294 if ( class_exists( '\Automattic\WooCommerce\Utilities\FeaturesUtil' ) ) {
295 \Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility( 'custom_order_tables', __FILE__, true );
296 }
297 }
298
299 function instantio_admin_enqueue_scripts($screen) {
300 wp_enqueue_style( 'instantio-admin', INSTANTIO_ASSETS_URL . '/admin/css/instantio-admin-style.css', array(), INSTANTIO_VERSION );
301 wp_enqueue_script( 'instantio-admin-script', INSTANTIO_ASSETS_URL . '/admin/js/instantio-admin-script.js', array( 'jquery' ), INSTANTIO_VERSION, true );
302
303 wp_localize_script( 'instantio-admin-script', 'instantio_admin_params',
304 array(
305 'ins_nonce' => wp_create_nonce( 'instantio_updates' ),
306 'ajax_url' => admin_url( 'admin-ajax.php' ),
307 )
308 );
309 }
310