PluginProbe ʕ •ᴥ•ʔ
Independent Analytics – WordPress Analytics Plugin / 1.19.0
Independent Analytics – WordPress Analytics Plugin v1.19.0
2.15.5 2.15.4 2.15.3 2.15.2 2.15.1 2.15.0 2.14.10 trunk 1.1 1.10 1.10.1 1.11 1.12 1.13 1.14 1.15 1.16 1.17 1.17.1 1.17.2 1.17.3 1.17.4 1.18 1.18.1 1.19.0 1.19.1 1.2 1.20.0 1.21.0 1.22.0 1.22.1 1.23.0 1.23.1 1.24.0 1.24.1 1.25.0 1.25.1 1.26.0 1.27.0 1.28.0 1.28.1 1.28.2 1.28.3 1.29.0 1.3 1.30.0 1.30.1 1.4 1.5 1.6 1.7 1.8 1.9 2.0.0 2.0.1 2.1.4 2.1.5 2.1.6 2.10.0 2.10.1 2.10.2 2.10.3 2.10.4 2.11.0 2.11.1 2.11.10 2.11.2 2.11.3 2.11.4 2.11.5 2.11.6 2.11.7 2.11.8 2.11.9 2.12.0 2.12.1 2.12.2 2.13.1 2.13.2 2.13.5 2.13.6 2.14.0 2.14.1 2.14.2 2.14.4 2.14.6 2.14.7 2.14.8 2.14.9 2.2.0 2.2.1 2.3.1 2.3.2 2.4.2 2.4.3 2.5.0 2.5.1 2.6.0 2.6.1 2.6.2 2.6.3 2.6.4 2.7.0 2.7.1 2.7.2 2.7.3 2.8.2 2.8.3 2.8.4 2.8.5 2.8.6 2.8.7 2.8.8 2.8.9 2.9.2 2.9.3 2.9.4 2.9.5 2.9.6 2.9.7
independent-analytics / iawp-bootstrap.php
independent-analytics Last commit date
IAWP 3 years ago dist 3 years ago freemius 3 years ago img 3 years ago languages 3 years ago sql 3 years ago templates 3 years ago vendor 3 years ago iawp-bootstrap.php 3 years ago iawp.php 3 years ago readme.txt 3 years ago
iawp-bootstrap.php
181 lines
1 <?php
2
3 use IAWP\Geo_Database ;
4 use IAWP\Independent_Analytics ;
5 use IAWP\Migrations ;
6 use IAWP\Utils\Request ;
7 use IAWP\WP_Option_Cache_Bust ;
8 define( 'IAWP_DIRECTORY', rtrim( plugin_dir_path( __FILE__ ), DIRECTORY_SEPARATOR ) );
9 define( 'IAWP_URL', rtrim( plugin_dir_url( __FILE__ ), '/' ) );
10 define( 'IAWP_VERSION', '1.19.0' );
11 define( 'IAWP_LANGUAGES_DIRECTORY', dirname( plugin_basename( __FILE__ ) ) . '/languages' );
12 // Load scoped composer autoloader
13 require_once iawp_path_to( 'vendor/scoper-autoload.php' );
14 /**
15 * @param $log
16 * @return void
17 */
18 function iawp_log( $log ) : void
19 {
20 if ( WP_DEBUG === true && WP_DEBUG_LOG === true ) {
21
22 if ( is_array( $log ) || is_object( $log ) ) {
23 error_log( print_r( $log, true ) );
24 } else {
25 error_log( $log );
26 }
27
28 }
29 }
30
31 /**
32 * @param $path
33 * @return string
34 */
35 function iawp_path_to( $path ) : string
36 {
37 $path = trim( $path, DIRECTORY_SEPARATOR );
38 return implode( DIRECTORY_SEPARATOR, [ IAWP_DIRECTORY, $path ] );
39 }
40
41 /**
42 * @param $path
43 * @return string
44 */
45 function iawp_url_to( $path ) : string
46 {
47 $path = trim( $path, '/' );
48 return implode( '/', [ IAWP_URL, $path ] );
49 }
50
51 /**
52 * Provide defaults for arguments provided as an associated array
53 * @param array $args
54 * @param array $defaults
55 * @return array
56 */
57 function iawp_default_args( array $args = array(), array $defaults = array() ) : array
58 {
59 $args = array_filter( $args, function ( $value ) {
60 // Remove key/value pairs where value is null
61 return $value !== null;
62 } );
63 $args = array_intersect_key( $args, $defaults );
64 return array_replace( $defaults, $args );
65 }
66
67 /**
68 * Determines if the user is running a licensed pro version
69 *
70 * @return bool
71 */
72 function iawp_is_pro() : bool
73 {
74 return false;
75 }
76
77 /**
78 * Determines if the user is running a free version or an unlicensed pro version
79 * @return bool
80 */
81 function iawp_is_free() : bool
82 {
83 return !iawp_is_pro();
84 }
85
86 /**
87 * Determines if a pro user has WooCommerce activated
88 * @return bool
89 */
90 function iawp_using_woocommerce() : bool
91 {
92 global $wpdb ;
93 if ( iawp_is_free() ) {
94 return false;
95 }
96 $class_missing = class_exists( 'WooCommerce' ) === false;
97 if ( $class_missing ) {
98 return false;
99 }
100 $table_name = $wpdb->prefix . 'wc_order_stats';
101 $order_stats_table = $wpdb->get_row( $wpdb->prepare( '
102 SELECT * FROM INFORMATION_SCHEMA.TABLES
103 WHERE TABLE_SCHEMA = %s AND TABLE_NAME = %s
104 ', DB_NAME, $table_name ) );
105 if ( is_null( $order_stats_table ) ) {
106 return false;
107 }
108 return true;
109 }
110
111 function iawp()
112 {
113 return Independent_Analytics::getInstance();
114 }
115
116 iawp();
117 WP_Option_Cache_Bust::register( 'iawp_is_migrating' );
118 WP_Option_Cache_Bust::register( 'iawp_is_database_downloading' );
119 WP_Option_Cache_Bust::register( 'iawp_db_version' );
120 WP_Option_Cache_Bust::register( 'iawp_geo_database_version' );
121 register_activation_hook( __DIR__ . '/iawp.php', function () {
122
123 if ( get_option( 'iawp_db_version', '0' ) === '0' ) {
124 // If there is no database installed, run migration on current process
125 Migrations\Migration::create_or_migrate();
126 } else {
127 // If there is a database, run migration in a background process
128 Migrations\Migration_Job::maybe_dispatch();
129 }
130
131 $geo_database = new Geo_Database();
132 $geo_database->maybe_dispatch_download_job();
133 update_option( 'iawp_need_clear_cache', true );
134 if ( iawp_is_pro() ) {
135 iawp()->email_reports->schedule_email_report();
136 }
137 } );
138 register_deactivation_hook( __DIR__ . '/iawp.php', function () {
139 if ( iawp_is_pro() ) {
140 iawp()->email_reports->unschedule_email_report();
141 }
142 } );
143 /*
144 * The admin_init hook will fire when the dashboard is loaded or an admin ajax request is made
145 */
146 add_action( 'admin_init', function () {
147 new Migrations\Migration_Job();
148
149 if ( get_option( 'iawp_db_version', '0' ) === '0' ) {
150 // If there is no database installed, run migration on current process
151 Migrations\Migration::create_or_migrate();
152 } else {
153 // If there is a database, run migration in a background process
154 Migrations\Migration_Job::maybe_dispatch();
155 }
156
157 $geo_database = new Geo_Database();
158 $geo_database->maybe_dispatch_download_job();
159 } );
160 // Since WC 4.3.0
161 add_action( 'woocommerce_checkout_order_created', function ( $order ) {
162 global $wpdb ;
163 $views_table = Query::get_table_name( Query::VIEWS );
164 $sessions_table = Query::get_table_name( Query::SESSIONS );
165 $wc_orders_table = Query::get_table_name( Query::WC_ORDERS );
166 $order_id = $order->id;
167 $visitor = new Visitor( Request::ip(), Request::user_agent() );
168 $most_recent_view = $wpdb->get_row( $wpdb->prepare( "SELECT views.id as id FROM {$views_table} AS views LEFT JOIN {$sessions_table} AS sessions ON sessions.session_id = views.session_id WHERE sessions.visitor_id = %s ORDER BY views.viewed_at DESC LIMIT 1", $visitor->id() ) );
169 if ( is_null( $most_recent_view ) ) {
170 return;
171 }
172 $existing_wc_order = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wc_orders_table} WHERE order_id = %d", $order_id ) );
173 if ( !is_null( $existing_wc_order ) ) {
174 return;
175 }
176 $wpdb->insert( $wc_orders_table, [
177 'view_id' => $most_recent_view->id,
178 'order_id' => $order_id,
179 'created_at' => ( new \DateTime() )->format( 'Y-m-d H:i:s' ),
180 ] );
181 } );