1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Common admin class. |
4
|
|
|
* |
5
|
|
|
* @since 6.0.0 |
6
|
|
|
* |
7
|
|
|
* @package MonsterInsights |
8
|
|
|
* @subpackage Common |
9
|
|
|
* @author Chris Christoff |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
// Exit if accessed directly |
13
|
|
|
if ( ! defined( 'ABSPATH' ) ) { |
14
|
|
|
exit; |
15
|
|
|
} |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Loads styles for all MonsterInsights-based Administration Screens. |
19
|
|
|
* |
20
|
|
|
* @since 6.0.0 |
21
|
|
|
* @access public |
22
|
|
|
* |
23
|
|
|
* @return null Return early if not on the proper screen. |
24
|
|
|
*/ |
25
|
|
|
function monsterinsights_admin_styles() { |
26
|
|
|
|
27
|
|
|
$suffix = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min'; |
28
|
|
|
|
29
|
|
|
// Load Common admin styles. |
30
|
|
|
wp_register_style( 'monsterinsights-admin-common-style', plugins_url( 'assets/css/admin-common' . $suffix . '.css', MONSTERINSIGHTS_PLUGIN_FILE ), array(), monsterinsights_get_asset_version() ); |
31
|
|
|
wp_enqueue_style( 'monsterinsights-admin-common-style' ); |
32
|
|
|
|
33
|
|
|
// Get current screen. |
34
|
|
|
$screen = get_current_screen(); |
35
|
|
|
|
36
|
|
|
// Bail if we're not on a MonsterInsights screen. |
37
|
|
|
if ( empty( $screen->id ) || strpos( $screen->id, 'monsterinsights' ) === false ) { |
38
|
|
|
return; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
// Bootstrap |
42
|
|
|
// Primary |
43
|
|
|
wp_register_style( 'monsterinsights-bootstrap', plugins_url( 'assets/css/bootstrap-prefixed' . $suffix . '.css', MONSTERINSIGHTS_PLUGIN_FILE ), array(), monsterinsights_get_asset_version() ); |
44
|
|
|
wp_enqueue_style( 'monsterinsights-bootstrap' ); |
45
|
|
|
|
46
|
|
|
// Secondary |
47
|
|
|
//wp_register_style( 'monsterinsights-bootstrap-base', plugins_url( 'assets/css/bootstrap' . $suffix . '.css', MONSTERINSIGHTS_PLUGIN_FILE ), array(), monsterinsights_get_asset_version() ); |
48
|
|
|
//wp_enqueue_style( 'monsterinsights-bootstrap-base' ); |
49
|
|
|
//wp_register_style( 'monsterinsights-bootstrap-theme', plugins_url( 'assets/css/bootstrap-theme' . $suffix . '.css', MONSTERINSIGHTS_PLUGIN_FILE ), array( 'monsterinsights-bootstrap-base' ), monsterinsights_get_asset_version() ); |
50
|
|
|
//wp_enqueue_style( 'monsterinsights-bootstrap-theme' ); |
51
|
|
|
|
52
|
|
|
// Select300 |
53
|
|
|
wp_register_style( 'monsterinsights-select300-style', plugins_url( 'assets/css/select300/select300.css', MONSTERINSIGHTS_PLUGIN_FILE ), array(), monsterinsights_get_asset_version() ); |
54
|
|
|
wp_enqueue_style( 'monsterinsights-select300-style' ); |
55
|
|
|
|
56
|
|
|
// Vendors |
57
|
|
|
wp_register_style( 'monsterinsights-vendors-style', plugins_url( 'assets/css/vendors' . $suffix . '.css', MONSTERINSIGHTS_PLUGIN_FILE ), array(), monsterinsights_get_asset_version() ); |
58
|
|
|
wp_enqueue_style( 'monsterinsights-vendors-style' ); |
59
|
|
|
|
60
|
|
|
// Tooltips |
61
|
|
|
wp_enqueue_script( 'jquery-ui-tooltip' ); |
62
|
|
|
|
63
|
|
|
// Load necessary admin styles. |
64
|
|
|
wp_register_style( 'monsterinsights-admin-style', plugins_url( 'assets/css/admin' . $suffix . '.css', MONSTERINSIGHTS_PLUGIN_FILE ), array(), monsterinsights_get_asset_version() ); |
65
|
|
|
wp_enqueue_style( 'monsterinsights-admin-style' ); |
66
|
|
|
} |
67
|
|
|
add_action( 'admin_enqueue_scripts', 'monsterinsights_admin_styles' ); |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* Loads scripts for all MonsterInsights-based Administration Screens. |
71
|
|
|
* |
72
|
|
|
* @since 6.0.0 |
73
|
|
|
* @access public |
74
|
|
|
* |
75
|
|
|
* @return null Return early if not on the proper screen. |
76
|
|
|
*/ |
77
|
|
|
function monsterinsights_admin_scripts() { |
78
|
|
|
|
79
|
|
|
// Our Common Admin JS |
80
|
|
|
$suffix = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min'; |
81
|
|
|
|
82
|
|
|
wp_register_script( 'monsterinsights-admin-common-script', plugins_url( 'assets/js/admin-common' . $suffix . '.js', MONSTERINSIGHTS_PLUGIN_FILE ), array( 'jquery' ), monsterinsights_get_asset_version() ); |
83
|
|
|
wp_enqueue_script( 'monsterinsights-admin-common-script' ); |
84
|
|
|
wp_localize_script( |
85
|
|
|
'monsterinsights-admin-common-script', |
86
|
|
|
'monsterinsights_admin_common', |
87
|
|
|
array( |
88
|
|
|
'ajax' => admin_url( 'admin-ajax.php' ), |
89
|
|
|
'dismiss_notice_nonce' => wp_create_nonce( 'monsterinsights-dismiss-notice' ), |
90
|
|
|
) |
91
|
|
|
); |
92
|
|
|
|
93
|
|
|
// Get current screen. |
94
|
|
|
$screen = get_current_screen(); |
95
|
|
|
|
96
|
|
|
// Bail if we're not on a MonsterInsights screen. |
97
|
|
|
if ( empty( $screen->id ) || strpos( $screen->id, 'monsterinsights' ) === false ) { |
98
|
|
|
return; |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
// Tooltips |
102
|
|
|
wp_enqueue_script( 'jquery-ui-tooltip' ); |
103
|
|
|
|
104
|
|
|
// Select300 |
105
|
|
|
wp_register_script( 'monsterinsights-select300-script', plugins_url( 'assets/js/select300/select300.full.js', MONSTERINSIGHTS_PLUGIN_FILE ), array( 'jquery' ), monsterinsights_get_asset_version() ); |
106
|
|
|
wp_enqueue_script( 'monsterinsights-select300-script' ); |
107
|
|
|
|
108
|
|
|
// Vendors |
109
|
|
|
wp_register_script( 'monsterinsights-vendors-script', plugins_url( 'assets/js/vendors.js', MONSTERINSIGHTS_PLUGIN_FILE ), array( 'jquery' ), monsterinsights_get_asset_version() ); |
110
|
|
|
wp_enqueue_script( 'monsterinsights-vendors-script' ); |
111
|
|
|
|
112
|
|
|
|
113
|
|
|
// Our Admin JS |
114
|
|
|
$deps = array( |
115
|
|
|
'jquery', |
116
|
|
|
'jquery-ui-tooltip', |
117
|
|
|
'monsterinsights-select300-script', |
118
|
|
|
'monsterinsights-vendors-script' |
119
|
|
|
); |
120
|
|
|
|
121
|
|
|
wp_register_script( 'monsterinsights-admin-script', plugins_url( 'assets/js/admin.js', MONSTERINSIGHTS_PLUGIN_FILE ), $deps, monsterinsights_get_asset_version() ); |
122
|
|
|
wp_enqueue_script( 'monsterinsights-admin-script' ); |
123
|
|
|
wp_localize_script( |
124
|
|
|
'monsterinsights-admin-script', |
125
|
|
|
'monsterinsights_admin', |
126
|
|
|
array( |
127
|
|
|
'ajax' => admin_url( 'admin-ajax.php' ), |
128
|
|
|
'dismiss_notice_nonce' => wp_create_nonce( 'monsterinsights-dismiss-notice' ), |
129
|
|
|
'loadingtext' => esc_html__( 'Loading...', 'google-analytics-for-wordpress' ), |
130
|
|
|
'settings_changed_confirm' => esc_html__( 'Warning: You have unsaved setting changes. If you leave the settings page without saving your changes will be lost. Did you still want to leave the page?', 'google-analytics-for-wordpress' ), |
131
|
|
|
'activate_nonce' => wp_create_nonce( 'monsterinsights-activate' ), |
132
|
|
|
'active' => esc_html__( 'Status: Active', 'google-analytics-for-wordpress' ), |
133
|
|
|
'activate' => esc_html__( 'Activate', 'google-analytics-for-wordpress' ), |
134
|
|
|
'networkactive' => esc_html__( 'Status: Network Activated', 'google-analytics-for-wordpress' ), |
135
|
|
|
'networkactivate' => esc_html__( 'Network activate', 'google-analytics-for-wordpress' ), |
136
|
|
|
'get_addons_nonce' => wp_create_nonce( 'monsterinsights-get-addons' ), |
137
|
|
|
'activating' => esc_html__( 'Activating...', 'google-analytics-for-wordpress' ), |
138
|
|
|
'deactivate' => esc_html__( 'Deactivate', 'google-analytics-for-wordpress' ), |
139
|
|
|
'networkdeactivate' => esc_html__( 'Network deactivate', 'google-analytics-for-wordpress' ), |
140
|
|
|
'deactivate_nonce' => wp_create_nonce( 'monsterinsights-deactivate' ), |
141
|
|
|
'deactivating' => esc_html__( 'Deactivating...', 'google-analytics-for-wordpress' ), |
142
|
|
|
'inactive' => esc_html__( 'Status: Inactive', 'google-analytics-for-wordpress' ), |
143
|
|
|
'networkinactive' => esc_html__( 'Status: Network inactive', 'google-analytics-for-wordpress' ), |
144
|
|
|
'install' => esc_html__( 'Install', 'google-analytics-for-wordpress' ), |
145
|
|
|
'install_nonce' => wp_create_nonce( 'monsterinsights-install' ), |
146
|
|
|
'installing' => esc_html__( 'Installing...', 'google-analytics-for-wordpress' ), |
147
|
|
|
'proceed' => esc_html__( 'Proceed', 'google-analytics-for-wordpress' ), |
148
|
|
|
'isnetwork' => is_network_admin(), |
149
|
|
|
'copied' => esc_html__( 'Copied!', 'google-analytics-for-wordpress' ), |
150
|
|
|
'copytoclip' => esc_html__( 'Copy to Clipboard', 'google-analytics-for-wordpress' ), |
151
|
|
|
'failed' => esc_html__( 'Failed!', 'google-analytics-for-wordpress' ), |
152
|
|
|
'admin_nonce' => wp_create_nonce( 'mi-admin-nonce' ), |
153
|
|
|
'shorten' => esc_html__( 'Shorten URL' ,'google-analytics-for-wordpress'), |
154
|
|
|
'shortened' => esc_html__( 'Shortened!' ,'google-analytics-for-wordpress'), |
155
|
|
|
'working' => esc_html__( 'Working...' ,'google-analytics-for-wordpress'), |
156
|
|
|
'importtext' => esc_html__( 'Import' ,'google-analytics-for-wordpress'), |
157
|
|
|
'imported' => esc_html__( 'Imported!' ,'google-analytics-for-wordpress'), |
158
|
|
|
'redirect_loading_title_text' => esc_html__( 'Preparing to redirect:' ,'google-analytics-for-wordpress'), |
159
|
|
|
'redirect_loading_text_text' => esc_html__( "You'll be redirected momentarily to complete authentication. This may take a couple seconds." ,'google-analytics-for-wordpress'), |
160
|
|
|
'redirect_loading_error_title' => esc_html__( "Authentication Error:" ,'google-analytics-for-wordpress'), |
161
|
|
|
'deauth_loading_title_text' => esc_html__( 'Deauthenticating....' ,'google-analytics-for-wordpress'), |
162
|
|
|
'deauth_loading_text_text' => esc_html__( "We're deactivating your site. This may take a couple seconds." ,'google-analytics-for-wordpress'), |
163
|
|
|
'deauth_loading_error_title' => esc_html__( "Deactivation Error:" ,'google-analytics-for-wordpress'), |
164
|
|
|
'deauth_success_title_text' => esc_html__( 'Deactivated Successfully!' ,'google-analytics-for-wordpress'), |
165
|
|
|
'deauth_success_text_text' => esc_html__( "You've disconnected your site from MonsterInsights. Your site is no longer being tracked by Google Analytics and you won't see reports anymore." ,'google-analytics-for-wordpress'), |
166
|
|
|
'verify_loading_title_text' => esc_html__( 'Verifying....' ,'google-analytics-for-wordpress'), |
167
|
|
|
'verify_loading_text_text' => esc_html__( "We're verifying your site. This may take a couple seconds." ,'google-analytics-for-wordpress'), |
168
|
|
|
'verify_loading_error_title' => esc_html__( "Verification Error:" ,'google-analytics-for-wordpress'), |
169
|
|
|
'verify_success_title_text' => esc_html__( 'Verified Successfully!' ,'google-analytics-for-wordpress'), |
170
|
|
|
'verify_success_text_text' => esc_html__( "Your site is connected to MonsterInsights!" ,'google-analytics-for-wordpress'), |
171
|
|
|
'ok_text' => esc_html__( "OK" ,'google-analytics-for-wordpress'), |
172
|
|
|
'force_deauth_button_text' => esc_html__( "Force Deauthenticate" ,'google-analytics-for-wordpress'), |
173
|
|
|
'refresh_report_title' => esc_html__( 'Refreshing Report', 'google-analytics-for-wordpress' ), |
174
|
|
|
'refresh_report_text' => esc_html__( 'Loading new report data...', 'google-analytics-for-wordpress' ), |
175
|
|
|
'refresh_report_success_text' => esc_html__( 'Success', 'google-analytics-for-wordpress' ), |
176
|
|
|
'refresh_report_success_text' => esc_html__( 'Retrieved the new report data successfully', 'google-analytics-for-wordpress' ), |
177
|
|
|
'refresh_report_failure_title' => esc_html__( 'Error', 'google-analytics-for-wordpress' ), |
178
|
|
|
'timezone' => date('e'), |
179
|
|
|
) |
180
|
|
|
); |
181
|
|
|
|
182
|
|
|
// ublock notice |
183
|
|
|
add_action( 'admin_print_footer_scripts', 'monsterinsights_settings_ublock_error_js', 9999999 ); |
184
|
|
|
} |
185
|
|
|
add_action( 'admin_enqueue_scripts', 'monsterinsights_admin_scripts' ); |
186
|
|
|
|
187
|
|
|
/** |
188
|
|
|
* Remove Assets that conflict with ours from our screens. |
189
|
|
|
* |
190
|
|
|
* @since 6.0.4 |
191
|
|
|
* @access public |
192
|
|
|
* |
193
|
|
|
* @return null Return early if not on the proper screen. |
194
|
|
|
*/ |
195
|
|
|
function monsterinsights_remove_conflicting_asset_files() { |
196
|
|
|
|
197
|
|
|
// Get current screen. |
198
|
|
|
$screen = get_current_screen(); |
199
|
|
|
|
200
|
|
|
// Bail if we're not on a MonsterInsights screen. |
201
|
|
|
if ( empty( $screen->id ) || strpos( $screen->id, 'monsterinsights' ) === false ) { |
202
|
|
|
return; |
203
|
|
|
} |
204
|
|
|
|
205
|
|
|
$styles = array( |
206
|
|
|
'kt_admin_css', // Pinnacle theme |
207
|
|
|
'select2-css', // Schema theme |
208
|
|
|
'tweetshare_style', // TweetShare - Click To Tweet |
209
|
|
|
'tweetshare_custom_style', // TweetShare - Click To Tweet |
210
|
|
|
'tweeetshare_custome_style', // TweetShare - Click To Tweet |
211
|
|
|
'tweeetshare_notice_style', // TweetShare - Click To Tweet |
212
|
|
|
'tweeetshare_theme_style', // TweetShare - Click To Tweet |
213
|
|
|
'tweeetshare_tweet_box_style', // TweetShare - Click To Tweet |
214
|
|
|
'soultype2-admin', // SoulType Plugin |
215
|
|
|
'thesis-options-stylesheet', // Thesis Options Stylesheet |
216
|
|
|
'imagify-sweetalert-core', // Imagify |
217
|
|
|
'imagify-sweetalert', // Imagify |
218
|
|
|
'smls-backend-style', // Smart Logo Showcase Lite |
219
|
|
|
'wp-reactjs-starter', // wp-real-media-library |
220
|
|
|
'control-panel-modal-plugin', // Ken Theme |
221
|
|
|
'theme-admin-css', // Vitrine Theme |
222
|
|
|
'qi-framework-styles', // Artisan Nayma Theme |
223
|
|
|
'artisan-pages-style', // Artisan Pages Plugin |
224
|
|
|
'control-panel-modal-plugin', // Ken Theme |
225
|
|
|
'sweetalert', // Church Suite Theme by Webnus |
226
|
|
|
'woo_stock_alerts_admin_css', // WooCommerce bolder product alerts |
227
|
|
|
); |
228
|
|
|
|
229
|
|
|
$scripts = array( |
230
|
|
|
'kad_admin_js', // Pinnacle theme |
231
|
|
|
'dt-chart', // DesignThemes core features plugin |
232
|
|
|
'tweeetshare_font_script', // TweetShare - Click To Tweet |
233
|
|
|
'tweeetshare_jquery_script', // TweetShare - Click To Tweet |
234
|
|
|
'tweeetshare_jqueryui_script', // TweetShare - Click To Tweet |
235
|
|
|
'tweeetshare_custom_script', // TweetShare - Click To Tweet |
236
|
|
|
'imagify-promise-polyfill', // Imagify |
237
|
|
|
'imagify-sweetalert', // Imagify |
238
|
|
|
'imagify-chart', // Imagify |
239
|
|
|
'chartjs', // Comet Cache Pro |
240
|
|
|
'wp-reactjs-starter', // wp-real-media-library |
241
|
|
|
'jquery-tooltipster', // WP Real Media Library |
242
|
|
|
'jquery-nested-sortable', // WP Real Media Library |
243
|
|
|
'jquery-aio-tree', // WP Real Media Library |
244
|
|
|
'wp-media-picker', // WP Real Media Library |
245
|
|
|
'rml-general', // WP Real Media Library |
246
|
|
|
'rml-library', // WP Real Media Library |
247
|
|
|
'rml-grid', // WP Real Media Library |
248
|
|
|
'rml-list', // WP Real Media Library |
249
|
|
|
'rml-modal', // WP Real Media Library |
250
|
|
|
'rml-order', // WP Real Media Library |
251
|
|
|
'rml-meta', // WP Real Media Library |
252
|
|
|
'rml-uploader', // WP Real Media Library |
253
|
|
|
'rml-options', // WP Real Media Library |
254
|
|
|
'rml-usersettings', // WP Real Media Library |
255
|
|
|
'rml-main', // WP Real Media Library |
256
|
|
|
'control-panel-sweet-alert', // Ken Theme |
257
|
|
|
'sweet-alert-js', // Vitrine Theme |
258
|
|
|
'theme-admin-script', // Vitrine Theme |
259
|
|
|
'sweetalert', // Church Suite Theme by Webnus |
260
|
|
|
'be_alerts_charts', // WooCommerce bolder product alerts |
261
|
|
|
'magayo-lottery-results', // Magayo Lottery Results |
262
|
|
|
'control-panel-sweet-alert', // Ken Theme |
263
|
|
|
'cpm_chart', // WP Project Manager |
264
|
|
|
'adminscripts', // Artisan Nayma Theme |
265
|
|
|
'artisan-pages-script', // Artisan Pages Plugin |
266
|
|
|
'tooltipster', // Grand News Theme |
267
|
|
|
'fancybox', // Grand News Theme |
268
|
|
|
'grandnews-admin-cript', // Grand News Theme |
269
|
|
|
'colorpicker', // Grand News Theme |
270
|
|
|
'eye', // Grand News Theme |
271
|
|
|
'utils', // Grand News Theme |
272
|
|
|
'icheck', // Grand News Theme |
273
|
|
|
'learn-press-chart', // LearnPress |
274
|
|
|
'theme-script-main', // My Listing Theme by 27collective |
275
|
|
|
'selz', // Selz eCommerce |
276
|
|
|
'tie-admin-scripts', // Tie Theme |
277
|
|
|
'blossomthemes-toolkit', // BlossomThemes Toolkit |
278
|
|
|
'illdy-widget-upload-image', // Illdy Companion By Colorlib |
279
|
|
|
'moment.js', // WooCommerce Table Rate Shipping |
280
|
|
|
'default', // Bridge Theme |
281
|
|
|
'qode-tax-js', // Bridge Theme |
282
|
|
|
'wc_smartship_moment_js', // WooCommerce Posti SmartShip by markup.fi |
283
|
|
|
'ecwid-admin-js', // Fixes Conflict for Ecwid Shopping Cart |
284
|
|
|
'td-wp-admin-js', // Newspaper by tagDiv |
285
|
|
|
'moment', // Screets Live Chat |
286
|
|
|
); |
287
|
|
|
|
288
|
|
|
if ( ! empty( $styles ) ) { |
289
|
|
|
foreach ( $styles as $style ) { |
290
|
|
|
wp_dequeue_style( $style ); // Remove CSS file from MI screen |
291
|
|
|
wp_deregister_style( $style ); |
292
|
|
|
} |
293
|
|
|
} |
294
|
|
|
if ( ! empty( $scripts ) ) { |
295
|
|
|
foreach ( $scripts as $script ) { |
296
|
|
|
wp_dequeue_script( $script ); // Remove JS file from MI screen |
297
|
|
|
wp_deregister_script( $script ); |
298
|
|
|
} |
299
|
|
|
} |
300
|
|
|
|
301
|
|
|
$third_party = array( |
302
|
|
|
'select300', |
303
|
|
|
'sweetalert', |
304
|
|
|
'clipboard', |
305
|
|
|
'matchHeight', |
306
|
|
|
'inputmask', |
307
|
|
|
'jquery-confirm', |
308
|
|
|
'list', |
309
|
|
|
'toastr', |
310
|
|
|
'tooltipster', |
311
|
|
|
'flag-icon', |
312
|
|
|
'bootstrap', |
313
|
|
|
); |
314
|
|
|
|
315
|
|
|
global $wp_styles; |
316
|
|
|
foreach ( $wp_styles->queue as $handle ) { |
317
|
|
|
if ( strpos( $wp_styles->registered[$handle]->src, 'wp-content') === false ) { |
318
|
|
|
return; |
319
|
|
|
} |
320
|
|
|
|
321
|
|
|
if ( strpos( $wp_styles->registered[$handle]->handle, 'monsterinsights') !== false ) { |
322
|
|
|
return; |
323
|
|
|
} |
324
|
|
|
|
325
|
|
|
foreach( $third_party as $partial ) { |
326
|
|
|
if ( strpos( $wp_styles->registered[$handle]->handle, $partial ) !== false ) { |
327
|
|
|
wp_dequeue_style( $handle ); // Remove css file from MI screen |
328
|
|
|
wp_deregister_style( $handle ); |
329
|
|
|
break; |
330
|
|
|
} else if ( strpos( $wp_styles->registered[$handle]->src, $partial ) !== false ) { |
331
|
|
|
wp_dequeue_style( $handle ); // Remove css file from MI screen |
332
|
|
|
wp_deregister_style( $handle ); |
333
|
|
|
break; |
334
|
|
|
} |
335
|
|
|
} |
336
|
|
|
} |
337
|
|
|
|
338
|
|
|
global $wp_scripts; |
339
|
|
|
foreach ( $wp_scripts->queue as $handle ) { |
340
|
|
|
if ( strpos( $wp_scripts->registered[$handle]->src, 'wp-content') === false ) { |
341
|
|
|
return; |
342
|
|
|
} |
343
|
|
|
|
344
|
|
|
if ( strpos( $wp_scripts->registered[$handle]->handle, 'monsterinsights') !== false ) { |
345
|
|
|
return; |
346
|
|
|
} |
347
|
|
|
|
348
|
|
|
foreach( $third_party as $partial ) { |
349
|
|
|
if ( strpos( $wp_scripts->registered[$handle]->handle, $partial ) !== false ) { |
350
|
|
|
wp_dequeue_script( $handle ); // Remove JS file from MI screen |
351
|
|
|
wp_deregister_script( $handle ); |
352
|
|
|
break; |
353
|
|
|
} else if ( strpos( $wp_scripts->registered[$handle]->src, $partial ) !== false ) { |
354
|
|
|
wp_dequeue_script( $handle ); // Remove JS file from MI screen |
355
|
|
|
wp_deregister_script( $handle ); |
356
|
|
|
break; |
357
|
|
|
} |
358
|
|
|
} |
359
|
|
|
} |
360
|
|
|
|
361
|
|
|
// Remove actions from themes that are not following best practices and break the admin doing so |
362
|
|
|
// Theme: Newspaper by tagDiv |
363
|
|
|
remove_action('admin_enqueue_scripts', 'load_wp_admin_js'); |
364
|
|
|
remove_action('admin_enqueue_scripts', 'load_wp_admin_css'); |
365
|
|
|
remove_action('admin_print_scripts-widgets.php', 'td_on_admin_print_scripts_farbtastic'); |
366
|
|
|
remove_action('admin_print_styles-widgets.php', 'td_on_admin_print_styles_farbtastic'); |
367
|
|
|
remove_action('admin_print_footer_scripts', 'check_if_media_uploads_is_loaded', 9999); |
368
|
|
|
remove_action('print_media_templates', 'td_custom_gallery_settings_hook'); |
369
|
|
|
remove_action('print_media_templates', 'td_change_backbone_js_hook'); |
370
|
|
|
} |
371
|
|
|
add_action( 'admin_enqueue_scripts', 'monsterinsights_remove_conflicting_asset_files', 9999 ); |
372
|
|
|
|
373
|
|
|
/** |
374
|
|
|
* Remove non-MI notices from MI page. |
375
|
|
|
* |
376
|
|
|
* @since 6.0.0 |
377
|
|
|
* @access public |
378
|
|
|
* |
379
|
|
|
* @return null Return early if not on the proper screen. |
380
|
|
|
*/ |
381
|
|
|
function hide_non_monsterinsights_warnings () { |
382
|
|
|
// Bail if we're not on a MonsterInsights screen. |
383
|
|
|
if ( empty( $_REQUEST['page'] ) || strpos( $_REQUEST['page'], 'monsterinsights' ) === false ) { |
384
|
|
|
return; |
385
|
|
|
} |
386
|
|
|
|
387
|
|
|
global $wp_filter; |
388
|
|
|
if ( !empty( $wp_filter['user_admin_notices']->callbacks ) && is_array( $wp_filter['user_admin_notices']->callbacks ) ) { |
389
|
|
|
foreach( $wp_filter['user_admin_notices']->callbacks as $priority => $hooks ) { |
390
|
|
|
foreach ( $hooks as $name => $arr ) { |
391
|
|
|
if ( is_object( $arr['function'] ) && $arr['function'] instanceof Closure ) { |
392
|
|
|
unset( $wp_filter['user_admin_notices']->callbacks[ $priority ][ $name ] ); |
393
|
|
|
continue; |
394
|
|
|
} |
395
|
|
|
if ( ! empty( $arr['function'][0] ) && is_object( $arr['function'][0] ) && strpos( strtolower( get_class( $arr['function'][0] ) ), 'monsterinsights' ) !== false ) { |
396
|
|
|
continue; |
397
|
|
|
} |
398
|
|
|
if ( !empty( $name ) && strpos( $name, 'monsterinsights' ) === false ) { |
399
|
|
|
unset( $wp_filter['user_admin_notices']->callbacks[$priority][$name] ); |
400
|
|
|
} |
401
|
|
|
} |
402
|
|
|
} |
403
|
|
|
} |
404
|
|
|
|
405
|
|
|
if ( !empty( $wp_filter['admin_notices']->callbacks ) && is_array( $wp_filter['admin_notices']->callbacks ) ) { |
406
|
|
|
foreach( $wp_filter['admin_notices']->callbacks as $priority => $hooks ) { |
407
|
|
|
foreach ( $hooks as $name => $arr ) { |
408
|
|
|
if ( is_object( $arr['function'] ) && $arr['function'] instanceof Closure ) { |
409
|
|
|
unset( $wp_filter['admin_notices']->callbacks[ $priority ][ $name ] ); |
410
|
|
|
continue; |
411
|
|
|
} |
412
|
|
|
if ( ! empty( $arr['function'][0] ) && is_object( $arr['function'][0] ) && strpos( strtolower( get_class( $arr['function'][0] ) ), 'monsterinsights' ) !== false ) { |
413
|
|
|
continue; |
414
|
|
|
} |
415
|
|
|
if ( !empty( $name ) && strpos( $name, 'monsterinsights' ) === false ) { |
416
|
|
|
unset( $wp_filter['admin_notices']->callbacks[$priority][$name] ); |
417
|
|
|
} |
418
|
|
|
} |
419
|
|
|
} |
420
|
|
|
} |
421
|
|
|
|
422
|
|
|
if ( !empty( $wp_filter['all_admin_notices']->callbacks ) && is_array( $wp_filter['all_admin_notices']->callbacks ) ) { |
423
|
|
|
foreach( $wp_filter['all_admin_notices']->callbacks as $priority => $hooks ) { |
424
|
|
|
foreach ( $hooks as $name => $arr ) { |
425
|
|
|
if ( is_object( $arr['function'] ) && $arr['function'] instanceof Closure ) { |
426
|
|
|
unset( $wp_filter['all_admin_notices']->callbacks[ $priority ][ $name ] ); |
427
|
|
|
continue; |
428
|
|
|
} |
429
|
|
|
if ( ! empty( $arr['function'][0] ) && is_object( $arr['function'][0] ) && strpos( strtolower( get_class( $arr['function'][0] ) ), 'monsterinsights' ) !== false ) { |
430
|
|
|
continue; |
431
|
|
|
} |
432
|
|
|
if ( !empty( $name ) && strpos( $name, 'monsterinsights' ) === false ) { |
433
|
|
|
unset( $wp_filter['all_admin_notices']->callbacks[$priority][$name] ); |
434
|
|
|
} |
435
|
|
|
} |
436
|
|
|
} |
437
|
|
|
} |
438
|
|
|
} |
439
|
|
|
add_action('admin_print_scripts', 'hide_non_monsterinsights_warnings'); |
440
|
|
|
|
441
|
|
|
/** |
442
|
|
|
* Called whenever an upgrade button / link is displayed in Lite, this function will |
443
|
|
|
* check if there's a shareasale ID specified. |
444
|
|
|
* |
445
|
|
|
* There are three ways to specify an ID, ordered by highest to lowest priority |
446
|
|
|
* - add_filter( 'monsterinsights_shareasale_id', function() { return 1234; } ); |
447
|
|
|
* - define( 'MONSTERINSIGHTS_SHAREASALE_ID', 1234 ); |
448
|
|
|
* - get_option( 'monsterinsights_shareasale_id' ); (with the option being in the wp_options table) |
449
|
|
|
* |
450
|
|
|
* If an ID is present, returns the ShareASale link with the affiliate ID, and tells |
451
|
|
|
* ShareASale to then redirect to monsterinsights.com/lite |
452
|
|
|
* |
453
|
|
|
* If no ID is present, just returns the monsterinsights.com/lite URL with UTM tracking. |
454
|
|
|
* |
455
|
|
|
* @since 6.0.0 |
456
|
|
|
* @access public |
457
|
|
|
* |
458
|
|
|
* @return string Upgrade link. |
459
|
|
|
*/ |
460
|
|
|
function monsterinsights_get_upgrade_link( $medium = '', $campaign = '', $url = '' ) { |
461
|
|
|
$url = monsterinsights_get_url( $medium, $campaign, $url, false ); |
462
|
|
|
|
463
|
|
|
if ( monsterinsights_is_pro_version() ) { |
464
|
|
|
return esc_url( $url ); |
465
|
|
|
} |
466
|
|
|
|
467
|
|
|
// Get the ShareASale ID |
468
|
|
|
$shareasale_id = monsterinsights_get_shareasale_id(); |
469
|
|
|
|
470
|
|
|
// If we have a shareasale ID return the shareasale url |
471
|
|
|
if ( ! empty( $shareasale_id ) ) { |
472
|
|
|
$shareasale_id = absint( $shareasale_id ); |
473
|
|
|
return esc_url( monsterinsights_get_shareasale_url( $shareasale_id, $url ) ); |
474
|
|
|
} else { |
475
|
|
|
return esc_url( $url ); |
476
|
|
|
} |
477
|
|
|
} |
478
|
|
|
|
479
|
|
|
function monsterinsights_get_url( $medium = '', $campaign = '', $url = '', $escape = true ) { |
480
|
|
|
// Setup Campaign variables |
481
|
|
|
$source = monsterinsights_is_pro_version() ? 'proplugin' : 'liteplugin'; |
482
|
|
|
$medium = ! empty( $medium ) ? $medium : 'defaultmedium'; |
483
|
|
|
$campaign = ! empty( $campaign ) ? $campaign : 'defaultcampaign'; |
484
|
|
|
$content = MONSTERINSIGHTS_VERSION; |
485
|
|
|
$default_url = monsterinsights_is_pro_version() ? '' : 'lite/'; |
486
|
|
|
$url = ! empty( $url ) ? $url : 'https://www.monsterinsights.com/' . $default_url; |
487
|
|
|
|
488
|
|
|
// Put together redirect URL |
489
|
|
|
$url = add_query_arg( |
490
|
|
|
array( |
491
|
|
|
'utm_source' => $source, // Pro/Lite Plugin |
492
|
|
|
'utm_medium' => sanitize_key( $medium ), // Area of MonsterInsights (example Reports) |
493
|
|
|
'utm_campaign' => sanitize_key( $campaign ), // Which link (example eCommerce Report) |
494
|
|
|
'utm_content' => $content, // Version number of MI |
495
|
|
|
), |
496
|
|
|
trailingslashit( $url ) |
497
|
|
|
); |
498
|
|
|
|
499
|
|
|
if ( $escape ) { |
500
|
|
|
return esc_url( $url ); |
501
|
|
|
} else { |
502
|
|
|
return $url; |
503
|
|
|
} |
504
|
|
|
} |
505
|
|
|
|
506
|
|
|
function monsterinsights_get_shareasale_id() { |
507
|
|
|
// Check if there's a constant. |
508
|
|
|
$shareasale_id = ''; |
509
|
|
|
if ( defined( 'MONSTERINSIGHTS_SHAREASALE_ID' ) ) { |
510
|
|
|
$shareasale_id = MONSTERINSIGHTS_SHAREASALE_ID; |
|
|
|
|
511
|
|
|
} |
512
|
|
|
|
513
|
|
|
// If there's no constant, check if there's an option. |
514
|
|
|
if ( empty( $shareasale_id ) ) { |
515
|
|
|
$shareasale_id = get_option( 'monsterinsights_shareasale_id', '' ); |
516
|
|
|
} |
517
|
|
|
|
518
|
|
|
// Whether we have an ID or not, filter the ID. |
519
|
|
|
$shareasale_id = apply_filters( 'monsterinsights_shareasale_id', $shareasale_id ); |
520
|
|
|
|
521
|
|
|
// Ensure it's a number |
522
|
|
|
$shareasale_id = absint( $shareasale_id ); |
523
|
|
|
return $shareasale_id; |
524
|
|
|
} |
525
|
|
|
|
526
|
|
|
// Passed in with mandatory default redirect and shareasaleid from monsterinsights_get_upgrade_link |
527
|
|
|
function monsterinsights_get_shareasale_url( $shareasale_id, $shareasale_redirect ) { |
528
|
|
|
// Check if there's a constant. |
529
|
|
|
$custom = false; |
530
|
|
|
if ( defined( 'MONSTERINSIGHTS_SHAREASALE_REDIRECT_URL' ) ) { |
531
|
|
|
$shareasale_redirect = MONSTERINSIGHTS_SHAREASALE_REDIRECT_URL; |
|
|
|
|
532
|
|
|
$custom = true; |
533
|
|
|
} |
534
|
|
|
|
535
|
|
|
// If there's no constant, check if there's an option. |
536
|
|
|
if ( empty( $custom ) ) { |
537
|
|
|
$shareasale_redirect = get_option( 'monsterinsights_shareasale_redirect_url', '' ); |
538
|
|
|
$custom = true; |
539
|
|
|
} |
540
|
|
|
|
541
|
|
|
// Whether we have an ID or not, filter the ID. |
542
|
|
|
$shareasale_redirect = apply_filters( 'monsterinsights_shareasale_redirect_url', $shareasale_redirect, $custom ); |
543
|
|
|
$shareasale_url = sprintf( 'http://www.shareasale.com/r.cfm?B=971799&U=%s&M=69975&urllink=%s', $shareasale_id, $shareasale_redirect ); |
544
|
|
|
return $shareasale_url; |
545
|
|
|
} |
546
|
|
|
|
547
|
|
|
function monsterinsights_settings_ublock_error_js(){ |
548
|
|
|
echo "<script type='text/javascript'>\n"; |
549
|
|
|
echo "jQuery( document ).ready( function( $ ) { |
550
|
|
|
if ( window.uorigindetected == null){ |
551
|
|
|
$('#monsterinsights-ublock-origin-error').show(); |
552
|
|
|
$('.monsterinsights-nav-tabs').hide(); |
553
|
|
|
$('.monsterinsights-nav-container').hide(); |
554
|
|
|
$('#monsterinsights-addon-heading').hide(); |
555
|
|
|
$('#monsterinsights-addons').hide(); |
556
|
|
|
$('#monsterinsights-reports').hide(); |
557
|
|
|
} |
558
|
|
|
});"; |
559
|
|
|
echo "\n</script>"; |
560
|
|
|
} |
561
|
|
|
|
562
|
|
|
function monsterinsights_ublock_notice() { |
563
|
|
|
ob_start();?> |
564
|
|
|
<div id="monsterinsights-ublock-origin-error" class="error inline" style="display:none;"> |
565
|
|
|
<?php echo sprintf( esc_html__( 'MonsterInsights has detected that it\'s files are being blocked. This is usually caused by a adblock browser plugin (particularly uBlock Origin), or a conflicting WordPress theme or plugin. This issue only affects the admin side of MonsterInsights. To solve this, ensure MonsterInsights is whitelisted for your website URL in any adblock browser plugin you use. For step by step directions on how to do this, %1$sclick here%2$s. If this doesn\'t solve the issue (rare), send us a ticket %3$shere%2$s and we\'ll be happy to help diagnose the issue.', 'google-analytics-for-wordpress'), '<a href="https://monsterinsights.com/docs/monsterinsights-asset-files-blocked/" target="_blank" rel="noopener noreferrer" referrer="no-referrer">', '</a>', '<a href="https://monsterinsights.com/contact/" target="_blank" rel="noopener noreferrer" referrer="no-referrer">'); |
566
|
|
|
?> |
567
|
|
|
</div> |
568
|
|
|
<?php |
569
|
|
|
return ob_get_clean(); |
570
|
|
|
} |