Passed
Push — master ( 6f0a6d...90a9ca )
by
unknown
09:41
created

monsterinsights_yearinreview_admin_menu_tooltip()   C

Complexity

Conditions 11
Paths 8

Size

Total Lines 237
Code Lines 210

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 11
eloc 210
nc 8
nop 0
dl 0
loc 237
rs 5.8533
c 2
b 0
f 0

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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
function monsterinsights_is_settings_page() {
18
	$current_screen = function_exists( 'get_current_screen' ) ? get_current_screen() : false;
0 ignored issues
show
Bug introduced by
Are you sure the usage of get_current_screen() is correct as it seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
19
	global $admin_page_hooks;
20
21
	if ( ! is_object( $current_screen ) || empty( $current_screen->id ) || empty( $admin_page_hooks ) ) {
22
		return false;
23
	}
24
25
	$settings_page = false;
26
	if ( ! empty( $admin_page_hooks['monsterinsights_settings'] ) && $current_screen->id === $admin_page_hooks['monsterinsights_settings'] ) {
27
		$settings_page = true;
28
	}
29
30
	if ( $current_screen->id === 'toplevel_page_monsterinsights_settings' ) {
31
		$settings_page = true;
32
	}
33
34
	if ( $current_screen->id === 'insights_page_monsterinsights_settings' ) {
35
		$settings_page = true;
36
	}
37
38
	if ( strpos( $current_screen->id, 'monsterinsights_settings' ) !== false ) {
39
		$settings_page = true;
40
	}
41
42
	if ( ! empty( $current_screen->base ) && strpos( $current_screen->base, 'monsterinsights_network' ) !== false ) {
43
		$settings_page = true;
44
	}
45
46
	return $settings_page;
47
}
48
49
/**
50
 * Determine if the current page is the Reports page.
51
 *
52
 * @return bool
53
 */
54
function monsterinsights_is_reports_page() {
55
	$current_screen = function_exists( 'get_current_screen' ) ? get_current_screen() : false;
0 ignored issues
show
Bug introduced by
Are you sure the usage of get_current_screen() is correct as it seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
56
	global $admin_page_hooks;
57
58
	if ( ! is_object( $current_screen ) || empty( $current_screen->id ) || empty( $admin_page_hooks ) ) {
59
		return false;
60
	}
61
62
	$reports_page = false;
63
	if ( ! empty( $admin_page_hooks['monsterinsights_reports'] ) && $current_screen->id === $admin_page_hooks['monsterinsights_reports'] ) {
64
		$reports_page = true;
65
	}
66
67
	if ( 'toplevel_page_monsterinsights_reports' === $current_screen->id ) {
68
		$reports_page = true;
69
	}
70
71
	if ( strpos( $current_screen->id, 'monsterinsights_reports' ) !== false ) {
72
		$reports_page = true;
73
	}
74
75
	return $reports_page;
76
}
77
78
/**
79
 * Loads styles for all MonsterInsights-based Administration Screens.
80
 *
81
 * @return null Return early if not on the proper screen.
82
 * @since 6.0.0
83
 * @access public
84
 *
85
 */
86
function monsterinsights_admin_styles() {
87
88
	$suffix = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min';
89
90
	// Load Common admin styles.
91
	wp_register_style( 'monsterinsights-admin-common-style', plugins_url( 'assets/css/admin-common' . $suffix . '.css', MONSTERINSIGHTS_PLUGIN_FILE ), array(), monsterinsights_get_asset_version() );
92
	wp_enqueue_style( 'monsterinsights-admin-common-style' );
93
94
	// Get current screen.
95
	$screen = get_current_screen();
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $screen is correct as get_current_screen() seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
96
97
	// Bail if we're not on a MonsterInsights screen.
98
	if ( empty( $screen->id ) || strpos( $screen->id, 'monsterinsights' ) === false ) {
99
		return;
100
	}
101
102
	$version_path = monsterinsights_is_pro_version() ? 'pro' : 'lite';
103
	$rtl          = is_rtl() ? '.rtl' : '';
104
105
	// For the settings page, load the Vue app styles.
106
	if ( monsterinsights_is_settings_page() ) {
107
		if ( ! defined( 'MONSTERINSIGHTS_LOCAL_JS_URL' ) ) {
108
			wp_enqueue_style( 'monsterinsights-vue-style-vendors', plugins_url( $version_path . '/assets/vue/css/chunk-vendors' . $rtl . '.css', MONSTERINSIGHTS_PLUGIN_FILE ), array(), monsterinsights_get_asset_version() );
109
			wp_enqueue_style( 'monsterinsights-vue-style-common', plugins_url( $version_path . '/assets/vue/css/chunk-common' . $rtl . '.css', MONSTERINSIGHTS_PLUGIN_FILE ), array(), monsterinsights_get_asset_version() );
110
			wp_enqueue_style( 'monsterinsights-vue-style', plugins_url( $version_path . '/assets/vue/css/settings' . $rtl . '.css', MONSTERINSIGHTS_PLUGIN_FILE ), array(), monsterinsights_get_asset_version() );
111
		}
112
113
		// Don't load other styles on the settings page.
114
		return;
115
	}
116
117
	if ( monsterinsights_is_reports_page() ) {
118
		if ( ! defined( 'MONSTERINSIGHTS_LOCAL_REPORTS_JS_URL' ) ) {
119
			wp_enqueue_style( 'monsterinsights-vue-style-vendors', plugins_url( $version_path . '/assets/vue/css/chunk-vendors' . $rtl . '.css', MONSTERINSIGHTS_PLUGIN_FILE ), array(), monsterinsights_get_asset_version() );
120
			wp_enqueue_style( 'monsterinsights-vue-style-common', plugins_url( $version_path . '/assets/vue/css/chunk-common' . $rtl . '.css', MONSTERINSIGHTS_PLUGIN_FILE ), array(), monsterinsights_get_asset_version() );
121
			wp_enqueue_style( 'monsterinsights-vue-style', plugins_url( $version_path . '/assets/vue/css/reports' . $rtl . '.css', MONSTERINSIGHTS_PLUGIN_FILE ), array(), monsterinsights_get_asset_version() );
122
		}
123
124
		return;
125
	}
126
127
	// Tooltips
128
	wp_enqueue_script( 'jquery-ui-tooltip' );
129
}
130
131
add_action( 'admin_enqueue_scripts', 'monsterinsights_admin_styles' );
132
133
/**
134
 * Loads scripts for all MonsterInsights-based Administration Screens.
135
 *
136
 * @return null Return early if not on the proper screen.
137
 * @since 6.0.0
138
 * @access public
139
 *
140
 */
141
function monsterinsights_admin_scripts() {
142
143
	// Our Common Admin JS.
144
	$suffix = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min';
145
146
	wp_register_script( 'monsterinsights-admin-common-script', plugins_url( 'assets/js/admin-common' . $suffix . '.js', MONSTERINSIGHTS_PLUGIN_FILE ), array( 'jquery' ), monsterinsights_get_asset_version() );
147
148
	wp_enqueue_script( 'monsterinsights-admin-common-script' );
149
150
	wp_localize_script(
151
		'monsterinsights-admin-common-script',
152
		'monsterinsights_admin_common',
153
		array(
154
			'ajax'                 => admin_url( 'admin-ajax.php' ),
155
			'dismiss_notice_nonce' => wp_create_nonce( 'monsterinsights-dismiss-notice' ),
156
		)
157
	);
158
159
	// Get current screen.
160
	$screen = get_current_screen();
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $screen is correct as get_current_screen() seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
161
162
	// Bail if we're not on a MonsterInsights screen.
163
	if ( empty( $screen->id ) || strpos( $screen->id, 'monsterinsights' ) === false ) {
164
		return;
165
	}
166
167
	$version_path = monsterinsights_is_pro_version() ? 'pro' : 'lite';
168
169
	// For the settings page, load the Vue app.
170
	if ( monsterinsights_is_settings_page() ) {
171
		if ( ! defined( 'MONSTERINSIGHTS_LOCAL_VENDORS_JS_URL' ) ) {
172
			wp_enqueue_script( 'monsterinsights-vue-vendors', plugins_url( $version_path . '/assets/vue/js/chunk-vendors.js', MONSTERINSIGHTS_PLUGIN_FILE ), array(), monsterinsights_get_asset_version(), true );
173
			wp_enqueue_script( 'monsterinsights-vue-common', plugins_url( $version_path . '/assets/vue/js/chunk-common.js', MONSTERINSIGHTS_PLUGIN_FILE ), array(), monsterinsights_get_asset_version(), true );
174
		} else {
175
			wp_enqueue_script( 'monsterinsights-vue-vendors', MONSTERINSIGHTS_LOCAL_VENDORS_JS_URL, array(), monsterinsights_get_asset_version(), true );
0 ignored issues
show
Bug introduced by
The constant MONSTERINSIGHTS_LOCAL_VENDORS_JS_URL was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
176
			wp_enqueue_script( 'monsterinsights-vue-common', MONSTERINSIGHTS_LOCAL_COMMON_JS_URL, array(), monsterinsights_get_asset_version(), true );
0 ignored issues
show
Bug introduced by
The constant MONSTERINSIGHTS_LOCAL_COMMON_JS_URL was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
177
		}
178
		$app_js_url = defined( 'MONSTERINSIGHTS_LOCAL_JS_URL' ) && MONSTERINSIGHTS_LOCAL_JS_URL ? MONSTERINSIGHTS_LOCAL_JS_URL : plugins_url( $version_path . '/assets/vue/js/settings.js', MONSTERINSIGHTS_PLUGIN_FILE );
0 ignored issues
show
Bug introduced by
The constant MONSTERINSIGHTS_LOCAL_JS_URL was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
179
		wp_register_script( 'monsterinsights-vue-script', $app_js_url, array(), monsterinsights_get_asset_version(), true );
180
		wp_enqueue_script( 'monsterinsights-vue-script' );
181
		$plugins         = get_plugins();
182
		$install_amp_url = false;
183
		if ( monsterinsights_can_install_plugins() ) {
184
			$amp_key = 'amp/amp.php';
185
			if ( array_key_exists( $amp_key, $plugins ) ) {
186
				$install_amp_url = wp_nonce_url( self_admin_url( 'plugins.php?action=activate&plugin=' . $amp_key ), 'activate-plugin_' . $amp_key );
187
			} else {
188
				$install_amp_url = wp_nonce_url( self_admin_url( 'update.php?action=install-plugin&plugin=amp' ), 'install-plugin_amp' );
189
			}
190
		}
191
		$install_woocommerce_url = false;
192
		if ( monsterinsights_can_install_plugins() ) {
193
			$woo_key = 'woocommerce/woocommerce.php';
194
			if ( array_key_exists( $woo_key, $plugins ) ) {
195
				$install_woocommerce_url = wp_nonce_url( self_admin_url( 'plugins.php?action=activate&plugin=' . $woo_key ), 'activate-plugin_' . $woo_key );
196
			} else {
197
				$install_woocommerce_url = wp_nonce_url( self_admin_url( 'update.php?action=install-plugin&plugin=woocommerce' ), 'install-plugin_woocommerce' );
198
			}
199
		}
200
		$install_fbia_url = false;
201
		if ( monsterinsights_can_install_plugins() ) {
202
			$fbia_key = 'fb-instant-articles/facebook-instant-articles.php';
203
			if ( array_key_exists( $fbia_key, $plugins ) ) {
204
				$install_fbia_url = wp_nonce_url( self_admin_url( 'plugins.php?action=activate&plugin=' . $fbia_key ), 'activate-plugin_' . $fbia_key );
205
			} else {
206
				$install_fbia_url = wp_nonce_url( self_admin_url( 'update.php?action=install-plugin&plugin=fb-instant-articles' ), 'install-plugin_fb-instant-articles' );
207
			}
208
		}
209
210
		$prepared_dimensions = array();
211
		if ( class_exists( 'MonsterInsights_Admin_Custom_Dimensions' ) ) {
212
			$dimensions          = new MonsterInsights_Admin_Custom_Dimensions();
0 ignored issues
show
Bug introduced by
The type MonsterInsights_Admin_Custom_Dimensions was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
213
			$dimensions          = $dimensions->custom_dimensions();
214
			$prepared_dimensions = array();
215
			foreach ( $dimensions as $dimension_type => $dimension ) {
216
				$dimension['type']     = $dimension_type;
217
				$prepared_dimensions[] = $dimension;
218
			}
219
		}
220
		$is_authed = ( MonsterInsights()->auth->is_authed() || MonsterInsights()->auth->is_network_authed() );
0 ignored issues
show
Bug Best Practice introduced by
The property $auth is declared protected in MonsterInsights_Lite. Since you implement __get, consider adding a @property or @property-read.
Loading history...
221
222
		wp_localize_script(
223
			'monsterinsights-vue-script',
224
			'monsterinsights',
225
			array(
226
				'ajax'                            => admin_url( 'admin-ajax.php' ),
227
				'nonce'                           => wp_create_nonce( 'mi-admin-nonce' ),
228
				'network'                         => is_network_admin(),
229
				'translations'                    => wp_get_jed_locale_data( monsterinsights_is_pro_version() ? 'ga-premium' : 'google-analytics-for-wordpress' ),
230
				'assets'                          => plugins_url( $version_path . '/assets/vue', MONSTERINSIGHTS_PLUGIN_FILE ),
231
				'roles'                           => monsterinsights_get_roles(),
232
				'roles_manage_options'            => monsterinsights_get_manage_options_roles(),
233
				'shareasale_id'                   => monsterinsights_get_shareasale_id(),
234
				'shareasale_url'                  => monsterinsights_get_shareasale_url( monsterinsights_get_shareasale_id(), '' ),
235
				'addons_url'                      => is_multisite() ? network_admin_url( 'admin.php?page=monsterinsights_network#/addons' ) : admin_url( 'admin.php?page=monsterinsights_settings#/addons' ),
236
				'email_summary_url'               => admin_url( 'admin.php?monsterinsights_email_preview&monsterinsights_email_template=summary' ),
237
				'install_amp_url'                 => $install_amp_url,
238
				'install_fbia_url'                => $install_fbia_url,
239
				'install_woo_url'                 => $install_woocommerce_url,
240
				'dimensions'                      => $prepared_dimensions,
241
				'wizard_url'                      => is_network_admin() ? network_admin_url( 'index.php?page=monsterinsights-onboarding' ) : admin_url( 'index.php?page=monsterinsights-onboarding' ),
242
				'install_plugins'                 => monsterinsights_can_install_plugins(),
243
				'unfiltered_html'                 => current_user_can( 'unfiltered_html' ),
244
				'activate_nonce'                  => wp_create_nonce( 'monsterinsights-activate' ),
245
				'deactivate_nonce'                => wp_create_nonce( 'monsterinsights-deactivate' ),
246
				'install_nonce'                   => wp_create_nonce( 'monsterinsights-install' ),
247
				// Used to add notices for future deprecations.
248
				'versions'                        => monsterinsights_get_php_wp_version_warning_data(),
249
				'plugin_version'                  => MONSTERINSIGHTS_VERSION,
250
				'is_admin'                        => true,
251
				'admin_email'                     => get_option( 'admin_email' ),
252
				'site_url'                        => get_site_url(),
253
				'reports_url'                     => add_query_arg( 'page', 'monsterinsights_reports', admin_url( 'admin.php' ) ),
254
				'first_run_notice'                => apply_filters( 'monsterinsights_settings_first_time_notice_hide', monsterinsights_get_option( 'monsterinsights_first_run_notice' ) ),
255
				'getting_started_url'             => is_network_admin() ? network_admin_url( 'admin.php?page=monsterinsights_network#/about' ) : admin_url( 'admin.php?page=monsterinsights_settings#/about/getting-started' ),
256
				'authed'                          => $is_authed,
257
				'new_pretty_link_url'             => admin_url( 'post-new.php?post_type=pretty-link' ),
258
				'wpmailsmtp_admin_url'            => admin_url( 'admin.php?page=wp-mail-smtp' ),
259
				'load_headline_analyzer_settings' => monsterinsights_load_gutenberg_app() ? 'true' : 'false',
260
			)
261
		);
262
263
		// Don't load other scripts on the settings page.
264
		return;
265
	}
266
267
	if ( monsterinsights_is_reports_page() ) {
268
		global $wp_version;
269
		if ( ! defined( 'MONSTERINSIGHTS_LOCAL_VENDORS_JS_URL' ) ) {
270
			wp_enqueue_script( 'monsterinsights-vue-vendors', plugins_url( $version_path . '/assets/vue/js/chunk-vendors.js', MONSTERINSIGHTS_PLUGIN_FILE ), array(), monsterinsights_get_asset_version(), true );
271
			wp_enqueue_script( 'monsterinsights-vue-common', plugins_url( $version_path . '/assets/vue/js/chunk-common.js', MONSTERINSIGHTS_PLUGIN_FILE ), array(), monsterinsights_get_asset_version(), true );
272
		} else {
273
			wp_enqueue_script( 'monsterinsights-vue-vendors', MONSTERINSIGHTS_LOCAL_VENDORS_JS_URL, array(), monsterinsights_get_asset_version(), true );
274
			wp_enqueue_script( 'monsterinsights-vue-common', MONSTERINSIGHTS_LOCAL_COMMON_JS_URL, array(), monsterinsights_get_asset_version(), true );
275
		}
276
		$app_js_url = defined( 'MONSTERINSIGHTS_LOCAL_REPORTS_JS_URL' ) && MONSTERINSIGHTS_LOCAL_REPORTS_JS_URL ? MONSTERINSIGHTS_LOCAL_REPORTS_JS_URL : plugins_url( $version_path . '/assets/vue/js/reports.js', MONSTERINSIGHTS_PLUGIN_FILE );
0 ignored issues
show
Bug introduced by
The constant MONSTERINSIGHTS_LOCAL_REPORTS_JS_URL was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
277
		wp_register_script( 'monsterinsights-vue-reports', $app_js_url, array(), monsterinsights_get_asset_version(), true );
278
		wp_enqueue_script( 'monsterinsights-vue-reports' );
279
280
		// We do not have a current auth.
281
		$site_auth = MonsterInsights()->auth->get_viewname();
282
		$ms_auth   = is_multisite() && MonsterInsights()->auth->get_network_viewname();
283
284
		wp_localize_script(
285
			'monsterinsights-vue-reports',
286
			'monsterinsights',
287
			array(
288
				'ajax'             => admin_url( 'admin-ajax.php' ),
289
				'nonce'            => wp_create_nonce( 'mi-admin-nonce' ),
290
				'network'          => is_network_admin(),
291
				'translations'     => wp_get_jed_locale_data( monsterinsights_is_pro_version() ? 'ga-premium' : 'google-analytics-for-wordpress' ),
292
				'assets'           => plugins_url( $version_path . '/assets/vue', MONSTERINSIGHTS_PLUGIN_FILE ),
293
				'shareasale_id'    => monsterinsights_get_shareasale_id(),
294
				'shareasale_url'   => monsterinsights_get_shareasale_url( monsterinsights_get_shareasale_id(), '' ),
295
				'addons_url'       => is_multisite() ? network_admin_url( 'admin.php?page=monsterinsights_network#/addons' ) : admin_url( 'admin.php?page=monsterinsights_settings#/addons' ),
296
				'timezone'         => date( 'e' ),
297
				'authed'           => $site_auth || $ms_auth,
298
				'settings_url'     => add_query_arg( 'page', 'monsterinsights_settings', admin_url( 'admin.php' ) ),
299
				// Used to add notices for future deprecations.
300
				'versions'         => monsterinsights_get_php_wp_version_warning_data(),
301
				'plugin_version'   => MONSTERINSIGHTS_VERSION,
302
				'is_admin'         => true,
303
				'admin_email'      => get_option( 'admin_email' ),
304
				'site_url'         => get_site_url(),
305
				'wizard_url'       => is_network_admin() ? network_admin_url( 'index.php?page=monsterinsights-onboarding' ) : admin_url( 'index.php?page=monsterinsights-onboarding' ),
306
				'install_nonce'    => wp_create_nonce( 'monsterinsights-install' ),
307
				'activate_nonce'   => wp_create_nonce( 'monsterinsights-activate' ),
308
				'deactivate_nonce' => wp_create_nonce( 'monsterinsights-deactivate' ),
309
				'update_settings'  => current_user_can( 'monsterinsights_save_settings' ),
310
				'migrated'         => monsterinsights_get_option( 'gadwp_migrated', 0 ),
311
			)
312
		);
313
314
		return;
315
	}
316
	// ublock notice
317
	add_action( 'admin_print_footer_scripts', 'monsterinsights_settings_ublock_error_js', 9999999 );
318
}
319
320
add_action( 'admin_enqueue_scripts', 'monsterinsights_admin_scripts' );
321
322
/**
323
 * Remove Assets that conflict with ours from our screens.
324
 *
325
 * @return null Return early if not on the proper screen.
326
 * @since 6.0.4
327
 * @access public
328
 *
329
 */
330
function monsterinsights_remove_conflicting_asset_files() {
331
332
	// Get current screen.
333
	$screen = get_current_screen();
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $screen is correct as get_current_screen() seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
334
335
	// Bail if we're not on a MonsterInsights screen.
336
	if ( empty( $screen->id ) || strpos( $screen->id, 'monsterinsights' ) === false ) {
337
		return;
338
	}
339
340
	$styles = array(
341
		'kt_admin_css', // Pinnacle theme
342
		'select2-css', // Schema theme
343
		'tweetshare_style', // TweetShare - Click To Tweet
344
		'tweetshare_custom_style', // TweetShare - Click To Tweet
345
		'tweeetshare_custome_style', // TweetShare - Click To Tweet
346
		'tweeetshare_notice_style', // TweetShare - Click To Tweet
347
		'tweeetshare_theme_style', // TweetShare - Click To Tweet
348
		'tweeetshare_tweet_box_style', // TweetShare - Click To Tweet
349
		'soultype2-admin', // SoulType Plugin
350
		'thesis-options-stylesheet', // Thesis Options Stylesheet
351
		'imagify-sweetalert-core', // Imagify
352
		'imagify-sweetalert', // Imagify
353
		'smls-backend-style', // Smart Logo Showcase Lite
354
		'wp-reactjs-starter', // wp-real-media-library
355
		'control-panel-modal-plugin', // Ken Theme
356
		'theme-admin-css', // Vitrine Theme
357
		'qi-framework-styles', //  Artisan Nayma Theme
358
		'artisan-pages-style', // Artisan Pages Plugin
359
		'control-panel-modal-plugin', // Ken Theme
360
		'sweetalert', //  Church Suite Theme by Webnus
361
		'woo_stock_alerts_admin_css', // WooCommerce bolder product alerts
362
		'custom_wp_admin_css', // Fix for Add Social Share
363
		'fo_css', // Fix for Add Social Share
364
		'font_css', // Fix for Add Social Share
365
		'font2_css', // Fix for Add Social Share
366
		'font3_css', // Fix for Add Social Share
367
		'hover_css', // Fix for Add Social Share
368
		'fontend_styling', // Fix for Add Social Share
369
		'datatable', // WP Todo
370
		'bootstrap', // WP Todo
371
		'flipclock', // WP Todo
372
		'repuso_css_admin', // Social testimonials and reviews by Repuso
373
	);
374
375
	$scripts = array(
376
		'kad_admin_js', // Pinnacle theme
377
		'dt-chart', // DesignThemes core features plugin
378
		'tweeetshare_font_script', // TweetShare - Click To Tweet
379
		'tweeetshare_jquery_script',  // TweetShare - Click To Tweet
380
		'tweeetshare_jqueryui_script', // TweetShare - Click To Tweet
381
		'tweeetshare_custom_script', // TweetShare - Click To Tweet
382
		'imagify-promise-polyfill', // Imagify
383
		'imagify-sweetalert', // Imagify
384
		'imagify-chart', // Imagify
385
		'chartjs', // Comet Cache Pro
386
		'wp-reactjs-starter', // wp-real-media-library
387
		'jquery-tooltipster', // WP Real Media Library
388
		'jquery-nested-sortable', // WP Real Media Library
389
		'jquery-aio-tree', // WP Real Media Library
390
		'wp-media-picker', // WP Real Media Library
391
		'rml-general', // WP Real Media Library
392
		'rml-library', // WP Real Media Library
393
		'rml-grid', // WP Real Media Library
394
		'rml-list', // WP Real Media Library
395
		'rml-modal', // WP Real Media Library
396
		'rml-order', // WP Real Media Library
397
		'rml-meta', // WP Real Media Library
398
		'rml-uploader',  // WP Real Media Library
399
		'rml-options',  // WP Real Media Library
400
		'rml-usersettings',  // WP Real Media Library
401
		'rml-main', // WP Real Media Library
402
		'control-panel-sweet-alert', // Ken Theme
403
		'sweet-alert-js', // Vitrine Theme
404
		'theme-admin-script', // Vitrine Theme
405
		'sweetalert', //  Church Suite Theme by Webnus
406
		'be_alerts_charts', //  WooCommerce bolder product alerts
407
		'magayo-lottery-results',  //  Magayo Lottery Results
408
		'control-panel-sweet-alert', // Ken Theme
409
		'cpm_chart', // WP Project Manager
410
		'adminscripts', //  Artisan Nayma Theme
411
		'artisan-pages-script', // Artisan Pages Plugin
412
		'tooltipster', // Grand News Theme
413
		'fancybox', // Grand News Theme
414
		'grandnews-admin-cript', // Grand News Theme
415
		'colorpicker', // Grand News Theme
416
		'eye', // Grand News Theme
417
		'icheck', // Grand News Theme
418
		'learn-press-chart', //  LearnPress
419
		'theme-script-main', //  My Listing Theme by 27collective
420
		'selz', //  Selz eCommerce
421
		'tie-admin-scripts', //   Tie Theme
422
		'blossomthemes-toolkit', //   BlossomThemes Toolkit
423
		'illdy-widget-upload-image', //   Illdy Companion By Colorlib
424
		'moment.js', // WooCommerce Table Rate Shipping
425
		'default', //   Bridge Theme
426
		'qode-tax-js', //   Bridge Theme
427
		'wc_smartship_moment_js', // WooCommerce Posti SmartShip by markup.fi
428
		'ecwid-admin-js', // Fixes Conflict for Ecwid Shopping Cart
429
		'td-wp-admin-js', // Newspaper by tagDiv
430
		'moment', // Screets Live Chat
431
		'wpmf-base', //  WP Media Folder Fix
432
		'wpmf-media-filters', //  WP Media Folder Fix
433
		'wpmf-folder-tree', //  WP Media Folder Fix
434
		'wpmf-assign-tree', //  WP Media Folder Fix
435
		'js_files_for_wp_admin', //  TagDiv Composer Fix
436
		'tdb_js_files_for_wp_admin_last', //  TagDiv Composer Fix
437
		'tdb_js_files_for_wp_admin', //  TagDiv Composer Fix
438
		'wd-functions', //  affiliate boxes
439
		'ellk-aliExpansion', // Ali Dropship Plugin
440
		'ftmetajs', // Houzez Theme
441
		'qode_admin_default', //  Fix For Stockholm Theme
442
		'qodef-tax-js', // Fix for Prowess Theme
443
		'qodef-user-js', // Fix for Prowess Theme
444
		'qodef-ui-admin', // Fix for Prowess Theme
445
		'ssi_script', // Fix for Add Social Share
446
		'live_templates', // Fix for Add Social Share
447
		'default', // Fix for Add Social Share
448
		'handsontable', // Fix WP Tables
449
		'moment-js', // Magee Shortcodes
450
		'postbox', // Scripts from wp-admin enqueued everywhere by WP Posts Filter
451
		'link', // Scripts from wp-admin enqueued everywhere by WP Posts Filter
452
		'wpvr_scripts', // WP Video Robot
453
		'wpvr_scripts_loaded', // WP Video Robot
454
		'wpvr_scripts_assets', // WP Video Robot
455
		'writee_widget_admin', // Fix for the Writtee theme
456
		'__ytprefs_admin__', // Fix for YouTube by EmbedPlus plugin
457
		'momentjs', // Fix for Blog Time plugin
458
		'c2c_BlogTime', //  Fix for Blog Time plugin
459
		'material-wp', // Fix for MaterialWP plugin
460
		'wp-color-picker-alpha', // Fix for MaterialWP plugin
461
		'grandtour-theme-script', // Grandtour Theme
462
		'swifty-img-widget-admin-script', // Fix for Swifty Image Widget
463
		'datatable', // WP Todo
464
		'flipclock', // WP Todo
465
		'bootstrap', // WP Todo
466
		'repuso_js_admin', // Social testimonials and reviews by Repuso
467
		'chart', // Video Mate Pro Theme
468
		'reuse_vendor', // RedQ Reuse Form
469
		'jetpack-onboarding-vendor', // Jetpack Onboarding Bluehost
470
		'date-js', // Google Analytics by Web Dorado
471
	);
472
473
	if ( ! empty( $styles ) ) {
474
		foreach ( $styles as $style ) {
475
			wp_dequeue_style( $style ); // Remove CSS file from MI screen
476
			wp_deregister_style( $style );
477
		}
478
	}
479
	if ( ! empty( $scripts ) ) {
480
		foreach ( $scripts as $script ) {
481
			wp_dequeue_script( $script ); // Remove JS file from MI screen
482
			wp_deregister_script( $script );
483
		}
484
	}
485
486
	$third_party = array(
487
		'select2',
488
		'sweetalert',
489
		'clipboard',
490
		'matchHeight',
491
		'inputmask',
492
		'jquery-confirm',
493
		'list',
494
		'toastr',
495
		'tooltipster',
496
		'flag-icon',
497
		'bootstrap',
498
	);
499
500
	global $wp_styles;
501
	foreach ( $wp_styles->queue as $handle ) {
502
		if ( strpos( $wp_styles->registered[ $handle ]->src, 'wp-content' ) === false ) {
503
			return;
504
		}
505
506
		if ( strpos( $wp_styles->registered[ $handle ]->handle, 'monsterinsights' ) !== false ) {
507
			return;
508
		}
509
510
		foreach ( $third_party as $partial ) {
511
			if ( strpos( $wp_styles->registered[ $handle ]->handle, $partial ) !== false ) {
512
				wp_dequeue_style( $handle ); // Remove css file from MI screen
513
				wp_deregister_style( $handle );
514
				break;
515
			} else if ( strpos( $wp_styles->registered[ $handle ]->src, $partial ) !== false ) {
516
				wp_dequeue_style( $handle ); // Remove css file from MI screen
517
				wp_deregister_style( $handle );
518
				break;
519
			}
520
		}
521
	}
522
523
	global $wp_scripts;
524
	foreach ( $wp_scripts->queue as $handle ) {
525
		if ( strpos( $wp_scripts->registered[ $handle ]->src, 'wp-content' ) === false ) {
526
			return;
527
		}
528
529
		if ( strpos( $wp_scripts->registered[ $handle ]->handle, 'monsterinsights' ) !== false ) {
530
			return;
531
		}
532
533
		foreach ( $third_party as $partial ) {
534
			if ( strpos( $wp_scripts->registered[ $handle ]->handle, $partial ) !== false ) {
535
				wp_dequeue_script( $handle ); // Remove JS file from MI screen
536
				wp_deregister_script( $handle );
537
				break;
538
			} else if ( strpos( $wp_scripts->registered[ $handle ]->src, $partial ) !== false ) {
539
				wp_dequeue_script( $handle ); // Remove JS file from MI screen
540
				wp_deregister_script( $handle );
541
				break;
542
			}
543
		}
544
	}
545
546
	// Remove actions from themes that are not following best practices and break the admin doing so
547
	// Theme: Newspaper by tagDiv
548
	remove_action( 'admin_enqueue_scripts', 'load_wp_admin_js' );
549
	remove_action( 'admin_enqueue_scripts', 'load_wp_admin_css' );
550
	remove_action( 'admin_print_scripts-widgets.php', 'td_on_admin_print_scripts_farbtastic' );
551
	remove_action( 'admin_print_styles-widgets.php', 'td_on_admin_print_styles_farbtastic' );
552
	remove_action( 'admin_print_footer_scripts', 'check_if_media_uploads_is_loaded', 9999 );
553
	remove_action( 'print_media_templates', 'td_custom_gallery_settings_hook' );
554
	remove_action( 'print_media_templates', 'td_change_backbone_js_hook' );
555
	remove_action( 'admin_head', 'tdc_on_admin_head' ); //  TagDiv Composer Fix
556
	remove_action( 'print_media_templates', 'us_media_templates' ); // Impreza Theme Fix
557
	remove_action( 'admin_footer', 'gt3pg_add_gallery_template' ); // GT3 Photo & Video Gallery By GT3 Themes Plugin Fix
558
	// Plugin WP Booklist:
559
	remove_action( 'admin_footer', 'wpbooklist_jre_dismiss_prem_notice_forever_action_javascript' );
560
	remove_action( 'admin_footer', 'wpbooklist_dashboard_add_book_action_javascript' );
561
	remove_action( 'admin_footer', 'wpbooklist_edit_book_show_form_action_javascript' );
562
	remove_action( 'admin_footer', 'wpbooklist_show_book_in_colorbox_action_javascript' );
563
	remove_action( 'admin_footer', 'wpbooklist_new_lib_shortcode_action_javascript' );
564
	remove_action( 'admin_footer', 'wpbooklist_dashboard_save_library_display_options_action_javascript' );
565
	remove_action( 'admin_footer', 'wpbooklist_dashboard_save_post_display_options_action_javascript' );
566
	remove_action( 'admin_footer', 'wpbooklist_dashboard_save_page_display_options_action_javascript' );
567
	remove_action( 'admin_footer', 'wpbooklist_update_display_options_action_javascript' );
568
	remove_action( 'admin_footer', 'wpbooklist_edit_book_pagination_action_javascript' );
569
	remove_action( 'admin_footer', 'wpbooklist_edit_book_switch_lib_action_javascript' );
570
	remove_action( 'admin_footer', 'wpbooklist_edit_book_search_action_javascript' );
571
	remove_action( 'admin_footer', 'wpbooklist_edit_book_actual_action_javascript' );
572
	remove_action( 'admin_footer', 'wpbooklist_delete_book_action_javascript' );
573
	remove_action( 'admin_footer', 'wpbooklist_user_apis_action_javascript' );
574
	remove_action( 'admin_footer', 'wpbooklist_upload_new_stylepak_action_javascript' );
575
	remove_action( 'admin_footer', 'wpbooklist_upload_new_post_template_action_javascript' );
576
	remove_action( 'admin_footer', 'wpbooklist_upload_new_page_template_action_javascript' );
577
	remove_action( 'admin_footer', 'wpbooklist_create_db_library_backup_action_javascript' );
578
	remove_action( 'admin_footer', 'wpbooklist_restore_db_library_backup_action_javascript' );
579
	remove_action( 'admin_footer', 'wpbooklist_create_csv_action_javascript' );
580
	remove_action( 'admin_footer', 'wpbooklist_amazon_localization_action_javascript' );
581
	remove_action( 'admin_footer', 'wpbooklist_delete_book_bulk_action_javascript' );
582
	remove_action( 'admin_footer', 'wpbooklist_reorder_action_javascript' );
583
	remove_action( 'admin_footer', 'wpbooklist_exit_results_action_javascript' );
584
	remove_action( 'admin_footer', 'wpbooklist_storytime_select_category_action_javascript' );
585
	remove_action( 'admin_footer', 'wpbooklist_storytime_get_story_action_javascript' );
586
	remove_action( 'admin_footer', 'wpbooklist_storytime_expand_browse_action_javascript' );
587
	remove_action( 'admin_footer', 'wpbooklist_storytime_save_settings_action_javascript' );
588
	remove_action( 'admin_footer', 'wpbooklist_delete_story_action_javascript' );
589
}
590
591
add_action( 'admin_enqueue_scripts', 'monsterinsights_remove_conflicting_asset_files', 9999 );
592
593
/**
594
 * Remove non-MI notices from MI page.
595
 *
596
 * @return null Return early if not on the proper screen.
597
 * @since 6.0.0
598
 * @access public
599
 *
600
 */
601
function hide_non_monsterinsights_warnings() {
602
	// Bail if we're not on a MonsterInsights screen.
603
	if ( empty( $_REQUEST['page'] ) || strpos( $_REQUEST['page'], 'monsterinsights' ) === false ) {
604
		return;
605
	}
606
607
	global $wp_filter;
608
	if ( ! empty( $wp_filter['user_admin_notices']->callbacks ) && is_array( $wp_filter['user_admin_notices']->callbacks ) ) {
609
		foreach ( $wp_filter['user_admin_notices']->callbacks as $priority => $hooks ) {
610
			foreach ( $hooks as $name => $arr ) {
611
				if ( is_object( $arr['function'] ) && $arr['function'] instanceof Closure ) {
612
					unset( $wp_filter['user_admin_notices']->callbacks[ $priority ][ $name ] );
613
					continue;
614
				}
615
				if ( ! empty( $arr['function'][0] ) && is_object( $arr['function'][0] ) && strpos( strtolower( get_class( $arr['function'][0] ) ), 'monsterinsights' ) !== false ) {
616
					continue;
617
				}
618
				if ( ! empty( $name ) && strpos( $name, 'monsterinsights' ) === false ) {
619
					unset( $wp_filter['user_admin_notices']->callbacks[ $priority ][ $name ] );
620
				}
621
			}
622
		}
623
	}
624
625
	if ( ! empty( $wp_filter['admin_notices']->callbacks ) && is_array( $wp_filter['admin_notices']->callbacks ) ) {
626
		foreach ( $wp_filter['admin_notices']->callbacks as $priority => $hooks ) {
627
			foreach ( $hooks as $name => $arr ) {
628
				if ( is_object( $arr['function'] ) && $arr['function'] instanceof Closure ) {
629
					unset( $wp_filter['admin_notices']->callbacks[ $priority ][ $name ] );
630
					continue;
631
				}
632
				if ( ! empty( $arr['function'][0] ) && is_object( $arr['function'][0] ) && strpos( strtolower( get_class( $arr['function'][0] ) ), 'monsterinsights' ) !== false ) {
633
					continue;
634
				}
635
				if ( ! empty( $name ) && strpos( $name, 'monsterinsights' ) === false ) {
636
					unset( $wp_filter['admin_notices']->callbacks[ $priority ][ $name ] );
637
				}
638
			}
639
		}
640
	}
641
642
	if ( ! empty( $wp_filter['all_admin_notices']->callbacks ) && is_array( $wp_filter['all_admin_notices']->callbacks ) ) {
643
		foreach ( $wp_filter['all_admin_notices']->callbacks as $priority => $hooks ) {
644
			foreach ( $hooks as $name => $arr ) {
645
				if ( is_object( $arr['function'] ) && $arr['function'] instanceof Closure ) {
646
					unset( $wp_filter['all_admin_notices']->callbacks[ $priority ][ $name ] );
647
					continue;
648
				}
649
				if ( ! empty( $arr['function'][0] ) && is_object( $arr['function'][0] ) && strpos( strtolower( get_class( $arr['function'][0] ) ), 'monsterinsights' ) !== false ) {
650
					continue;
651
				}
652
				if ( ! empty( $name ) && strpos( $name, 'monsterinsights' ) === false ) {
653
					unset( $wp_filter['all_admin_notices']->callbacks[ $priority ][ $name ] );
654
				}
655
			}
656
		}
657
	}
658
}
659
660
add_action( 'admin_print_scripts', 'hide_non_monsterinsights_warnings' );
661
add_action( 'admin_head', 'hide_non_monsterinsights_warnings', PHP_INT_MAX );
662
663
/**
664
 * Called whenever an upgrade button / link is displayed in Lite, this function will
665
 * check if there's a shareasale ID specified.
666
 *
667
 * There are three ways to specify an ID, ordered by highest to lowest priority
668
 * - add_filter( 'monsterinsights_shareasale_id', function() { return 1234; } );
669
 * - define( 'MONSTERINSIGHTS_SHAREASALE_ID', 1234 );
670
 * - get_option( 'monsterinsights_shareasale_id' ); (with the option being in the wp_options table)
671
 *
672
 * If an ID is present, returns the ShareASale link with the affiliate ID, and tells
673
 * ShareASale to then redirect to monsterinsights.com/lite
674
 *
675
 * If no ID is present, just returns the monsterinsights.com/lite URL with UTM tracking.
676
 *
677
 * @return string Upgrade link.
678
 * @since 6.0.0
679
 * @access public
680
 *
681
 */
682
function monsterinsights_get_upgrade_link( $medium = '', $campaign = '', $url = '' ) {
683
	$url = monsterinsights_get_url( $medium, $campaign, $url, false );
684
685
	if ( monsterinsights_is_pro_version() ) {
686
		return esc_url( $url );
687
	}
688
689
	// Get the ShareASale ID
690
	$shareasale_id = monsterinsights_get_shareasale_id();
691
692
	// If we have a shareasale ID return the shareasale url
693
	if ( ! empty( $shareasale_id ) ) {
694
		$shareasale_id = absint( $shareasale_id );
695
696
		return esc_url( monsterinsights_get_shareasale_url( $shareasale_id, $url ) );
697
	} else {
698
		return esc_url( $url );
699
	}
700
}
701
702
function monsterinsights_get_url( $medium = '', $campaign = '', $url = '', $escape = true ) {
703
	// Setup Campaign variables
704
	$source      = monsterinsights_is_pro_version() ? 'proplugin' : 'liteplugin';
705
	$medium      = ! empty( $medium ) ? $medium : 'defaultmedium';
706
	$campaign    = ! empty( $campaign ) ? $campaign : 'defaultcampaign';
707
	$content     = MONSTERINSIGHTS_VERSION;
708
	$default_url = monsterinsights_is_pro_version() ? '' : 'lite/';
709
	$url         = ! empty( $url ) ? $url : 'https://www.monsterinsights.com/' . $default_url;
710
711
	// Put together redirect URL
712
	$url = add_query_arg(
713
		array(
714
			'utm_source'   => $source,   // Pro/Lite Plugin
715
			'utm_medium'   => sanitize_key( $medium ),   // Area of MonsterInsights (example Reports)
716
			'utm_campaign' => sanitize_key( $campaign ), // Which link (example eCommerce Report)
717
			'utm_content'  => $content,  // Version number of MI
718
		),
719
		trailingslashit( $url )
720
	);
721
722
	if ( $escape ) {
723
		return esc_url( $url );
724
	} else {
725
		return $url;
726
	}
727
}
728
729
function monsterinsights_settings_ublock_error_js() {
730
	echo "<script type='text/javascript'>\n";
731
	echo "jQuery( document ).ready( function( $ ) {
732
			if ( window.uorigindetected == null){
733
			   $('#monsterinsights-ublock-origin-error').show();
734
			   $('.monsterinsights-nav-tabs').hide();
735
			   $('.monsterinsights-nav-container').hide();
736
			   $('#monsterinsights-addon-heading').hide();
737
			   $('#monsterinsights-addons').hide();
738
			   $('#monsterinsights-reports').hide();
739
			}
740
		});";
741
	echo "\n</script>";
742
}
743
744
function monsterinsights_ublock_notice() {
745
	ob_start(); ?>
746
	<div id="monsterinsights-ublock-origin-error" class="error inline" style="display:none;">
747
		<?php
748
		// Translators: Placeholders are for links to fix the issue.
749
		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">' );
750
		?>
751
	</div>
752
	<?php
753
	return ob_get_clean();
754
}
755
756
/**
757
 * Some themes/plugins don't add proper checks and load JS code in all admin pages causing conflicts.
758
 */
759
function monsterinsights_remove_unnecessary_footer_hooks() {
760
761
	$screen = get_current_screen();
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $screen is correct as get_current_screen() seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
762
	// Bail if we're not on a MonsterInsights screen.
763
	if ( empty( $screen->id ) || strpos( $screen->id, 'monsterinsights' ) === false ) {
764
		return;
765
	}
766
767
	// Remove js code added by Newspaper theme - version 8.8.0.
768
	remove_action( 'print_media_templates', 'td_custom_gallery_settings_hook' );
769
	remove_action( 'print_media_templates', 'td_change_backbone_js_hook' );
770
	// Remove js code added by the Brooklyn theme - version 4.5.3.1.
771
	remove_action( 'print_media_templates', 'ut_create_gallery_options' );
772
773
	// Remove js code added by WordPress Book List Plugin - version 5.8.1.
774
	remove_action( 'admin_footer', 'wpbooklist_jre_dismiss_prem_notice_forever_action_javascript' );
775
	remove_action( 'admin_footer', 'wpbooklist_dashboard_add_book_action_javascript' );
776
	remove_action( 'admin_footer', 'wpbooklist_edit_book_show_form_action_javascript' );
777
	remove_action( 'admin_footer', 'wpbooklist_show_book_in_colorbox_action_javascript' );
778
	remove_action( 'admin_footer', 'wpbooklist_new_lib_shortcode_action_javascript' );
779
	remove_action( 'admin_footer', 'wpbooklist_dashboard_save_library_display_options_action_javascript' );
780
	remove_action( 'admin_footer', 'wpbooklist_dashboard_save_post_display_options_action_javascript' );
781
	remove_action( 'admin_footer', 'wpbooklist_dashboard_save_page_display_options_action_javascript' );
782
	remove_action( 'admin_footer', 'wpbooklist_update_display_options_action_javascript' );
783
	remove_action( 'admin_footer', 'wpbooklist_edit_book_pagination_action_javascript' );
784
	remove_action( 'admin_footer', 'wpbooklist_edit_book_switch_lib_action_javascript' );
785
	remove_action( 'admin_footer', 'wpbooklist_edit_book_search_action_javascript' );
786
	remove_action( 'admin_footer', 'wpbooklist_edit_book_actual_action_javascript' );
787
	remove_action( 'admin_footer', 'wpbooklist_delete_book_action_javascript' );
788
	remove_action( 'admin_footer', 'wpbooklist_user_apis_action_javascript' );
789
	remove_action( 'admin_footer', 'wpbooklist_upload_new_stylepak_action_javascript' );
790
	remove_action( 'admin_footer', 'wpbooklist_upload_new_post_template_action_javascript' );
791
	remove_action( 'admin_footer', 'wpbooklist_upload_new_page_template_action_javascript' );
792
	remove_action( 'admin_footer', 'wpbooklist_create_db_library_backup_action_javascript' );
793
	remove_action( 'admin_footer', 'wpbooklist_restore_db_library_backup_action_javascript' );
794
	remove_action( 'admin_footer', 'wpbooklist_create_csv_action_javascript' );
795
	remove_action( 'admin_footer', 'wpbooklist_amazon_localization_action_javascript' );
796
	remove_action( 'admin_footer', 'wpbooklist_delete_book_bulk_action_javascript' );
797
	remove_action( 'admin_footer', 'wpbooklist_reorder_action_javascript' );
798
	remove_action( 'admin_footer', 'wpbooklist_exit_results_action_javascript' );
799
	remove_action( 'admin_footer', 'wpbooklist_storytime_select_category_action_javascript' );
800
	remove_action( 'admin_footer', 'wpbooklist_storytime_get_story_action_javascript' );
801
	remove_action( 'admin_footer', 'wpbooklist_storytime_expand_browse_action_javascript' );
802
	remove_action( 'admin_footer', 'wpbooklist_storytime_save_settings_action_javascript' );
803
	remove_action( 'admin_footer', 'wpbooklist_delete_story_action_javascript' );
804
}
805
806
add_action( 'admin_head', 'monsterinsights_remove_unnecessary_footer_hooks', 15 );
807
808
/**
809
 * Display dismissable admin pointer for year in review 2019 report
810
 *
811
 */
812
function monsterinsights_yearinreview_admin_menu_tooltip() {
813
814
	$dismiss_tooltip     = get_option( 'monsterinsights_yearinreview_dismiss_admin_tooltip', false );
815
	$activated           = get_option( 'monsterinsights_over_time', array() );
816
	$ua_code             = monsterinsights_get_ua();
817
	$dashboards_disabled = monsterinsights_get_option( 'dashboards_disabled', false );
818
819
	if ( $dashboards_disabled ) {
820
		return;
821
	}
822
823
	if ( ! current_user_can( 'monsterinsights_view_dashboard' ) ) {
824
		return;
825
	}
826
827
	if ( monsterinsights_is_reports_page() || monsterinsights_is_settings_page() ) {
828
		// Don't show on MI pages.
829
		return;
830
	}
831
832
	// equivalent to: 01/01/2020 @ 12:00am (UTC)
833
	$new_year = '1577836800';
834
835
	// equivalent to: 01/02/2020 @ 12:00am (UTC)
836
	$start_time = '1577923200';
837
838
	// equivalent to: 01/13/2020 @ 12:00am (UTC)
839
	$end_time = '1578873600';
840
841
	if ( $dismiss_tooltip ) {
842
		return;
843
	}
844
845
	// don't show before January 02, 2020
846
	if ( $start_time > time() ) {
847
		return;
848
	}
849
850
	// don't show after January 13, 2020
851
	if ( $end_time < time() ) {
852
		return;
853
	}
854
855
	if ( empty( $activated['connected_date'] ) || ( $activated['connected_date'] > $new_year ) || empty( $ua_code ) ) {
856
		return;
857
	}
858
859
	// remove lite upsell
860
	remove_action( 'adminmenu', 'monsterinsights_get_admin_menu_tooltip' );
861
862
	$url = admin_url( 'admin.php?page=monsterinsights_reports#/year-in-review' );
863
	?>
864
	<div id="monsterinsights-yearinreview-admin-menu-tooltip" class="monsterinsights-yearinreview-admin-menu-tooltip-hide">
865
		<div class="monsterinsights-yearinreview-admin-menu-tooltip-header">
866
			<span class="monsterinsights-yearinreview-admin-menu-tooltip-icon">
867
				<span class="dashicons dashicons-megaphone"></span>
868
			</span>
869
			<?php esc_html_e( 'Your 2019 Analytics Report', 'google-analytics-for-wordpress' ); ?>
870
			<a href="#" class="monsterinsights-yearinreview-admin-menu-tooltip-close">
871
				<span class="dashicons dashicons-dismiss"></span>
872
			</a>
873
		</div>
874
		<div class="monsterinsights-yearinreview-admin-menu-tooltip-content">
875
			<strong><?php esc_html_e( 'See how your website performed this year and find tips along the way to help grow even more in 2020!', 'google-analytics-for-wordpress' ); ?></strong>
876
			<p>
877
				<a href="<?php echo esc_url( $url ); ?>" class="button button-primary monsterinsights-yearinreview-admin-menu-tooltip-btn-link">
878
					<?php esc_html_e( 'View 2019 Year in Review report!', 'google-analytics-for-wordpress' ); ?>
879
				</a>
880
			</p>
881
		</div>
882
	</div>
883
	<style type="text/css">
884
		#monsterinsights-yearinreview-admin-menu-tooltip {
885
			position: absolute;
886
			left: 100%;
887
			top: 100%;
888
			background: #fff;
889
			margin-left: 16px;
890
			width: 350px;
891
			box-shadow: 0px 4px 7px 0px #ccc;
892
		}
893
894
		#monsterinsights-yearinreview-admin-menu-tooltip:before {
895
			content: '';
896
			width: 0;
897
			height: 0;
898
			border-style: solid;
899
			border-width: 12px 12px 12px 0;
900
			border-color: transparent #fff transparent transparent;
901
			position: absolute;
902
			right: 100%;
903
			top: 130px;
904
			z-index: 10;
905
		}
906
907
		#monsterinsights-yearinreview-admin-menu-tooltip:after {
908
			content: '';
909
			width: 0;
910
			height: 0;
911
			border-style: solid;
912
			border-width: 13px 13px 13px 0;
913
			border-color: transparent #ccc transparent transparent;
914
			position: absolute;
915
			right: 100%;
916
			margin-left: -1px;
917
			top: 129px;
918
			z-index: 5;
919
		}
920
921
		#monsterinsights-yearinreview-admin-menu-tooltip.monsterinsights-yearinreview-tooltip-arrow-top:before {
922
			top: 254px;
923
		}
924
925
		#monsterinsights-yearinreview-admin-menu-tooltip.monsterinsights-yearinreview-tooltip-arrow-top:after {
926
			top: 253px;
927
		}
928
929
		.monsterinsights-yearinreview-admin-menu-tooltip-header {
930
			background: #03a0d2;
931
			padding: 5px 12px;
932
			font-size: 14px;
933
			font-weight: 700;
934
			font-family: Arial, Helvetica, "Trebuchet MS", sans-serif;
935
			color: #fff;
936
			line-height: 1.6;
937
		}
938
939
		.monsterinsights-yearinreview-admin-menu-tooltip-icon {
940
			background: #fff;
941
			border-radius: 50%;
942
			width: 28px;
943
			height: 25px;
944
			display: inline-block;
945
			color: #03a0d2;
946
			text-align: center;
947
			padding: 3px 0 0;
948
			margin-right: 6px;
949
		}
950
951
		.monsterinsights-yearinreview-admin-menu-tooltip-hide {
952
			display: none;
953
		}
954
955
		.monsterinsights-yearinreview-admin-menu-tooltip-content {
956
			padding: 20px 15px 7px;
957
		}
958
959
		.monsterinsights-yearinreview-admin-menu-tooltip-content strong {
960
			font-size: 14px;
961
		}
962
963
		.monsterinsights-yearinreview-admin-menu-tooltip-content p strong {
964
			font-size: 13px;
965
		}
966
967
		.monsterinsights-yearinreview-admin-menu-tooltip-close {
968
			color: #fff;
969
			text-decoration: none;
970
			position: absolute;
971
			right: 10px;
972
			top: 12px;
973
			display: block;
974
		}
975
976
		.monsterinsights-yearinreview-admin-menu-tooltip-close:hover {
977
			color: #fff;
978
			text-decoration: none;
979
		}
980
981
		.monsterinsights-yearinreview-admin-menu-tooltip-close .dashicons {
982
			font-size: 14px;
983
		}
984
985
		@media ( max-width: 782px ) {
986
			#monsterinsights-yearinreview-admin-menu-tooltip {
987
				display: none;
988
			}
989
		}
990
	</style>
991
	<script type="text/javascript">
992
		if ( 'undefined' !== typeof jQuery ) {
993
			jQuery( function ( $ ) {
994
				var $tooltip = $( document.getElementById( 'monsterinsights-yearinreview-admin-menu-tooltip' ) );
995
				var $menuwrapper = $( document.getElementById( 'adminmenuwrap' ) );
996
				var $menuitem = $( document.getElementById( 'toplevel_page_monsterinsights_reports' ) );
997
				if ( 0 === $menuitem.length ) {
998
					$menuitem = $( document.getElementById( 'toplevel_page_monsterinsights_network' ) );
999
				}
1000
1001
				if ( $menuitem.length ) {
1002
					$menuwrapper.append( $tooltip );
1003
					$tooltip.removeClass( 'monsterinsights-yearinreview-admin-menu-tooltip-hide' );
1004
				}
1005
1006
				function alignTooltip() {
1007
					var sticky = $( 'body' ).hasClass( 'sticky-menu' );
1008
1009
					var menuitem_pos = $menuitem.position();
1010
					var tooltip_top = menuitem_pos.top - 124;
1011
					if ( sticky && $( window ).height() > $menuwrapper.height() + 150 ) {
1012
						$tooltip.removeClass( 'monsterinsights-yearinreview-tooltip-arrow-top' );
1013
					} else {
1014
						tooltip_top = menuitem_pos.top - 250;
1015
						$tooltip.addClass( 'monsterinsights-yearinreview-tooltip-arrow-top' );
1016
					}
1017
					// Don't let the tooltip go outside of the screen and make the close button not visible.
1018
					if ( tooltip_top < 40 ) {
1019
						tooltip_top = 40;
1020
					}
1021
					$tooltip.css( {
1022
						top: tooltip_top + 'px'
1023
					} );
1024
				}
1025
1026
				var $document = $( document );
1027
				var timeout = setTimeout( alignTooltip, 10 );
1028
				$document.on( 'wp-pin-menu wp-window-resized.pin-menu postboxes-columnchange.pin-menu postbox-toggled.pin-menu wp-collapse-menu.pin-menu wp-scroll-start.pin-menu', function () {
1029
					if ( timeout ) {
1030
						clearTimeout( timeout );
1031
					}
1032
					timeout = setTimeout( alignTooltip, 10 );
1033
				} );
1034
1035
				$( '.monsterinsights-yearinreview-admin-menu-tooltip-btn-link' ).on( 'click', function ( e ) {
1036
					hideYearInReviewTooltip();
1037
				} );
1038
1039
				$( '.monsterinsights-yearinreview-admin-menu-tooltip-close' ).on( 'click', function ( e ) {
1040
					e.preventDefault();
1041
					hideYearInReviewTooltip();
1042
				} );
1043
1044
				function hideYearInReviewTooltip() {
1045
					$tooltip.addClass( 'monsterinsights-yearinreview-admin-menu-tooltip-hide' );
1046
					$.post( ajaxurl, {
1047
						action: 'monsterinsights_yearinreview_hide_admin_tooltip',
1048
						nonce: '<?php echo esc_js( wp_create_nonce( 'mi-admin-nonce' ) ); ?>',
1049
					} );
1050
				}
1051
			} );
1052
		}
1053
	</script>
1054
	<?php
1055
}
1056
1057
add_action( 'adminmenu', 'monsterinsights_yearinreview_admin_menu_tooltip', 5 );
1058
1059
/**
1060
 * Store the time when the year in review tooltip was hidden so it won't show again
1061
 */
1062
function monsterinsights_mark_yearinreview_tooltip_hidden() {
1063
	check_ajax_referer( 'mi-admin-nonce', 'nonce' );
1064
	update_option( 'monsterinsights_yearinreview_dismiss_admin_tooltip', true );
1065
	wp_send_json_success();
1066
}
1067
1068
add_action( 'wp_ajax_monsterinsights_yearinreview_hide_admin_tooltip', 'monsterinsights_mark_yearinreview_tooltip_hidden' );
1069
1070
/**
1071
 * Prevent plugins/themes from removing the version number from scripts loaded by our plugin.
1072
 * Ideally those plugins/themes would follow WordPress coding best practices, but in lieu of that
1073
 * we can at least attempt to prevent 99% of them from doing bad things.
1074
 *
1075
 * @param string $src The script source.
1076
 *
1077
 * @return string
1078
 */
1079
function monsterinsights_prevent_version_number_removal( $src ) {
1080
	// Apply this only to admin-side scripts.
1081
	if ( ! is_admin() ) {
1082
		return $src;
1083
	}
1084
1085
	// Make sure are only changing our scripts and only if the version number is missing.
1086
	if ( ( false !== strpos( $src, 'monsterinsights' ) || false !== strpos( $src, 'google-analytics-for-wordpress' ) || false !== strpos( $src, 'google-analytics-premium' ) ) && false === strpos( $src, '?ver' ) ) {
1087
		$src = add_query_arg( 'ver', monsterinsights_get_asset_version(), $src );
1088
	}
1089
1090
	return $src;
1091
}
1092
1093
add_filter( 'script_loader_src', 'monsterinsights_prevent_version_number_removal', 9999, 1 );
1094
add_filter( 'style_loader_src', 'monsterinsights_prevent_version_number_removal', 9999, 1 );
1095
1096
/**
1097
 * Data used for the Vue scripts to display old PHP and WP versions warnings.
1098
 */
1099
function monsterinsights_get_php_wp_version_warning_data() {
1100
	global $wp_version;
1101
1102
	return array(
1103
		'php_version'          => phpversion(),
1104
		'php_version_below_54' => apply_filters( 'monsterinsights_temporarily_hide_php_under_56_upgrade_warnings', version_compare( phpversion(), '5.6', '<' ) ),
1105
		'php_version_below_56' => apply_filters( 'monsterinsights_temporarily_hide_php_56_upgrade_warnings', version_compare( phpversion(), '5.6', '>=' ) && version_compare( phpversion(), '7', '<' ) ),
1106
		'php_update_link'      => monsterinsights_get_url( 'settings-notice', 'settings-page', 'https://www.monsterinsights.com/docs/update-php/' ),
1107
		'wp_version'           => $wp_version,
1108
		'wp_version_below_46'  => version_compare( $wp_version, '4.9', '<' ),
1109
		'wp_version_below_49'  => version_compare( $wp_version, '5.3', '<' ),
1110
		'wp_update_link'       => monsterinsights_get_url( 'settings-notice', 'settings-page', 'https://www.monsterinsights.com/docs/update-wordpress/' ),
1111
	);
1112
}
1113