Passed
Push — master ( e0709e...805894 )
by Chris
06:51
created

monsterinsights_mark_yearinreview_tooltip_hidden()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 4
rs 10
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
	return $settings_page;
46
}
47
48
/**
49
 * Determine if the current page is the Reports page.
50
 *
51
 * @return bool
52
 */
53
function monsterinsights_is_reports_page() {
54
	$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...
55
	global $admin_page_hooks;
56
57
	if ( ! is_object( $current_screen ) || empty( $current_screen->id ) || empty( $admin_page_hooks ) ) {
58
		return false;
59
	}
60
61
	$settings_page = false;
62
	if ( ! empty( $admin_page_hooks['monsterinsights_reports'] ) && $current_screen->id === $admin_page_hooks['monsterinsights_reports'] ) {
63
		$settings_page = true;
64
	}
65
66
	if ( 'toplevel_page_monsterinsights_reports' === $current_screen->id ) {
67
		$settings_page = true;
68
	}
69
70
	if ( strpos( $current_screen->id, 'monsterinsights_reports' ) !== false ) {
71
		$settings_page = true;
72
	}
73
74
	if ( ! empty( $current_screen->base ) && strpos( $current_screen->base, 'monsterinsights_network' ) !== false ) {
75
		$settings_page = true;
76
	}
77
78
	return $settings_page;
79
}
80
81
/**
82
 * Loads styles for all MonsterInsights-based Administration Screens.
83
 *
84
 * @return null Return early if not on the proper screen.
85
 * @since 6.0.0
86
 * @access public
87
 *
88
 */
89
function monsterinsights_admin_styles() {
90
91
	$suffix = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min';
92
93
	// Load Common admin styles.
94
	wp_register_style( 'monsterinsights-admin-common-style', plugins_url( 'assets/css/admin-common' . $suffix . '.css', MONSTERINSIGHTS_PLUGIN_FILE ), array(), monsterinsights_get_asset_version() );
95
	wp_enqueue_style( 'monsterinsights-admin-common-style' );
96
97
	// Get current screen.
98
	$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...
99
100
	// Bail if we're not on a MonsterInsights screen.
101
	if ( empty( $screen->id ) || strpos( $screen->id, 'monsterinsights' ) === false ) {
102
		return;
103
	}
104
105
	$version_path = monsterinsights_is_pro_version() ? 'pro' : 'lite';
106
	$rtl          = is_rtl() ? '.rtl' : '';
107
108
	// For the settings page, load the Vue app styles.
109
	if ( monsterinsights_is_settings_page() ) {
110
		if ( ! defined( 'MONSTERINSIGHTS_LOCAL_JS_URL' ) ) {
111
			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() );
112
			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() );
113
			wp_enqueue_style( 'monsterinsights-vue-style', plugins_url( $version_path . '/assets/vue/css/settings' . $rtl . '.css', MONSTERINSIGHTS_PLUGIN_FILE ), array(), monsterinsights_get_asset_version() );
114
		}
115
116
		// Don't load other styles on the settings page.
117
		return;
118
	}
119
120
	if ( monsterinsights_is_reports_page() ) {
121
		if ( ! defined( 'MONSTERINSIGHTS_LOCAL_REPORTS_JS_URL' ) ) {
122
			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() );
123
			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() );
124
			wp_enqueue_style( 'monsterinsights-vue-style', plugins_url( $version_path . '/assets/vue/css/reports' . $rtl . '.css', MONSTERINSIGHTS_PLUGIN_FILE ), array(), monsterinsights_get_asset_version() );
125
		}
126
127
		return;
128
	}
129
130
	// Tooltips
131
	wp_enqueue_script( 'jquery-ui-tooltip' );
132
}
133
134
add_action( 'admin_enqueue_scripts', 'monsterinsights_admin_styles' );
135
136
/**
137
 * Loads scripts for all MonsterInsights-based Administration Screens.
138
 *
139
 * @return null Return early if not on the proper screen.
140
 * @since 6.0.0
141
 * @access public
142
 *
143
 */
144
function monsterinsights_admin_scripts() {
145
146
	// Our Common Admin JS.
147
	$suffix = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min';
148
149
	wp_register_script( 'monsterinsights-admin-common-script', plugins_url( 'assets/js/admin-common' . $suffix . '.js', MONSTERINSIGHTS_PLUGIN_FILE ), array( 'jquery' ), monsterinsights_get_asset_version() );
150
	wp_enqueue_script( 'monsterinsights-admin-common-script' );
151
	wp_localize_script(
152
		'monsterinsights-admin-common-script',
153
		'monsterinsights_admin_common',
154
		array(
155
			'ajax'                  => admin_url( 'admin-ajax.php' ),
156
			'dismiss_notice_nonce'  => wp_create_nonce( 'monsterinsights-dismiss-notice' ),
157
		)
158
	);
159
160
	// Get current screen.
161
	$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...
162
163
	// Bail if we're not on a MonsterInsights screen.
164
	if ( empty( $screen->id ) || strpos( $screen->id, 'monsterinsights' ) === false ) {
165
		return;
166
	}
167
168
	$version_path = monsterinsights_is_pro_version() ? 'pro' : 'lite';
169
170
	// For the settings page, load the Vue app.
171
	if ( monsterinsights_is_settings_page() ) {
172
		global $wp_version;
173
174
		if ( ! defined( 'MONSTERINSIGHTS_LOCAL_VENDORS_JS_URL' ) ) {
175
			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 );
176
			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 );
177
		} else {
178
			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...
179
			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...
180
		}
181
		$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...
182
		wp_register_script( 'monsterinsights-vue-script', $app_js_url, array(), monsterinsights_get_asset_version(), true );
183
		wp_enqueue_script( 'monsterinsights-vue-script' );
184
		$plugins         = get_plugins();
185
		$install_amp_url = false;
186
		if ( current_user_can( 'install_plugins' ) ) {
187
			$amp_key = 'amp/amp.php';
188
			if ( array_key_exists( $amp_key, $plugins ) ) {
189
				$install_amp_url = wp_nonce_url( self_admin_url( 'plugins.php?action=activate&plugin=' . $amp_key ), 'activate-plugin_' . $amp_key );
190
			} else {
191
				$install_amp_url = wp_nonce_url( self_admin_url( 'update.php?action=install-plugin&plugin=amp' ), 'install-plugin_amp' );
192
			}
193
		}
194
		$install_fbia_url = false;
195
		if ( current_user_can( 'install_plugins' ) ) {
196
			$fbia_key = 'fb-instant-articles/facebook-instant-articles.php';
197
			if ( array_key_exists( $fbia_key, $plugins ) ) {
198
				$install_fbia_url = wp_nonce_url( self_admin_url( 'plugins.php?action=activate&plugin=' . $fbia_key ), 'activate-plugin_' . $fbia_key );
199
			} else {
200
				$install_fbia_url = wp_nonce_url( self_admin_url( 'update.php?action=install-plugin&plugin=fb-instant-articles' ), 'install-plugin_fb-instant-articles' );
201
			}
202
		}
203
204
		$prepared_dimensions = array();
205
		if ( class_exists( 'MonsterInsights_Admin_Custom_Dimensions' ) ) {
206
			$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...
207
			$dimensions          = $dimensions->custom_dimensions();
208
			$prepared_dimensions = array();
209
			foreach ( $dimensions as $dimension_type => $dimension ) {
210
				$dimension['type']     = $dimension_type;
211
				$prepared_dimensions[] = $dimension;
212
			}
213
		}
214
		$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...
215
216
		wp_localize_script(
217
			'monsterinsights-vue-script',
218
			'monsterinsights',
219
			array(
220
				'ajax'                 => admin_url( 'admin-ajax.php' ),
221
				'nonce'                => wp_create_nonce( 'mi-admin-nonce' ),
222
				'network'              => is_network_admin(),
223
				'translations'         => wp_get_jed_locale_data( monsterinsights_is_pro_version() ? 'ga-premium' : 'google-analytics-for-wordpress' ),
224
				'assets'               => plugins_url( $version_path . '/assets/vue', MONSTERINSIGHTS_PLUGIN_FILE ),
225
				'roles'                => monsterinsights_get_roles(),
226
				'roles_manage_options' => monsterinsights_get_manage_options_roles(),
227
				'shareasale_id'        => monsterinsights_get_shareasale_id(),
228
				'shareasale_url'       => monsterinsights_get_shareasale_url( monsterinsights_get_shareasale_id(), '' ),
229
				'addons_url'           => is_multisite() ? network_admin_url( 'admin.php?page=monsterinsights_network#/addons' ) : admin_url( 'admin.php?page=monsterinsights_settings#/addons' ),
230
				'install_amp_url'      => $install_amp_url,
231
				'install_fbia_url'     => $install_fbia_url,
232
				'dimensions'           => $prepared_dimensions,
233
				'wizard_url'           => admin_url( 'index.php?page=monsterinsights-onboarding' ),
234
				'install_plugins'      => current_user_can( 'install_plugins' ),
235
				'unfiltered_html'      => current_user_can( 'unfiltered_html' ),
236
				'activate_nonce'       => wp_create_nonce( 'monsterinsights-activate' ),
237
				'deactivate_nonce'     => wp_create_nonce( 'monsterinsights-deactivate' ),
238
				'install_nonce'        => wp_create_nonce( 'monsterinsights-install' ),
239
				// Used to add notices for future deprecations.
240
				'versions'             => array(
241
					'php_version'          => phpversion(),
242
					'php_version_below_54' => apply_filters( 'monsterinsights_temporarily_hide_php_52_and_53_upgrade_warnings', version_compare( phpversion(), '5.4', '<' ) ),
243
					'php_version_below_56' => apply_filters( 'monsterinsights_temporarily_hide_php_54_and_55_upgrade_warnings', version_compare( phpversion(), '5.6', '<' ) ),
244
					'php_update_link'      => monsterinsights_get_url( 'settings-notice', 'settings-page', 'https://www.monsterinsights.com/docs/update-php/' ),
245
					'wp_version'           => $wp_version,
246
					'wp_version_below_46'  => version_compare( $wp_version, '4.6', '<' ),
247
					'wp_version_below_49'  => version_compare( $wp_version, '4.9', '<' ),
248
					'wp_update_link'       => monsterinsights_get_url( 'settings-notice', 'settings-page', 'https://www.monsterinsights.com/docs/update-wordpress/' ),
249
				),
250
				'plugin_version'       => MONSTERINSIGHTS_VERSION,
251
				'is_admin'             => true,
252
				'reports_url'          => add_query_arg( 'page', 'monsterinsights_reports', admin_url( 'admin.php' ) ),
253
				'first_run_notice'     => apply_filters( 'monsterinsights_settings_first_time_notice_hide', monsterinsights_get_option( 'monsterinsights_first_run_notice' ) ),
254
				'getting_started_url'  => is_multisite() ? network_admin_url( 'admin.php?page=monsterinsights_network#/about/getting-started' ) : admin_url( 'admin.php?page=monsterinsights_settings#/about/getting-started' ),
255
				'authed'               => $is_authed,
256
			)
257
		);
258
259
		// Don't load other scripts on the settings page.
260
		return;
261
	}
262
263
	if ( monsterinsights_is_reports_page() ) {
264
		global $wp_version;
265
		if ( ! defined( 'MONSTERINSIGHTS_LOCAL_VENDORS_JS_URL' ) ) {
266
			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 );
267
			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 );
268
		} else {
269
			wp_enqueue_script( 'monsterinsights-vue-vendors', MONSTERINSIGHTS_LOCAL_VENDORS_JS_URL, array(), monsterinsights_get_asset_version(), true );
270
			wp_enqueue_script( 'monsterinsights-vue-common', MONSTERINSIGHTS_LOCAL_COMMON_JS_URL, array(), monsterinsights_get_asset_version(), true );
271
		}
272
		$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...
273
		wp_register_script( 'monsterinsights-vue-reports', $app_js_url, array(), monsterinsights_get_asset_version(), true );
274
		wp_enqueue_script( 'monsterinsights-vue-reports' );
275
276
		// We do not have a current auth.
277
		$site_auth = MonsterInsights()->auth->get_viewname();
278
		$ms_auth   = is_multisite() && MonsterInsights()->auth->get_network_viewname();
279
280
		wp_localize_script(
281
			'monsterinsights-vue-reports',
282
			'monsterinsights',
283
			array(
284
				'ajax'            => admin_url( 'admin-ajax.php' ),
285
				'nonce'           => wp_create_nonce( 'mi-admin-nonce' ),
286
				'network'         => is_network_admin(),
287
				'translations'    => wp_get_jed_locale_data( monsterinsights_is_pro_version() ? 'ga-premium' : 'google-analytics-for-wordpress' ),
288
				'assets'          => plugins_url( $version_path . '/assets/vue', MONSTERINSIGHTS_PLUGIN_FILE ),
289
				'shareasale_id'   => monsterinsights_get_shareasale_id(),
290
				'shareasale_url'  => monsterinsights_get_shareasale_url( monsterinsights_get_shareasale_id(), '' ),
291
				'addons_url'      => is_multisite() ? network_admin_url( 'admin.php?page=monsterinsights_network#/addons' ) : admin_url( 'admin.php?page=monsterinsights_settings#/addons' ),
292
				'timezone'        => date( 'e' ),
293
				'authed'          => $site_auth || $ms_auth,
294
				'settings_url'    => add_query_arg( 'page', 'monsterinsights_settings', admin_url( 'admin.php' ) ),
295
				// Used to add notices for future deprecations.
296
				'versions'        => array(
297
					'php_version'          => phpversion(),
298
					'php_version_below_54' => apply_filters( 'monsterinsights_temporarily_hide_php_52_and_53_upgrade_warnings', version_compare( phpversion(), '5.4', '<' ) ),
299
					'php_version_below_56' => apply_filters( 'monsterinsights_temporarily_hide_php_54_and_55_upgrade_warnings', version_compare( phpversion(), '5.6', '<' ) ),
300
					'php_update_link'      => monsterinsights_get_url( 'settings-notice', 'settings-page', 'https://www.monsterinsights.com/docs/update-php/' ),
301
					'wp_version'           => $wp_version,
302
					'wp_version_below_46'  => version_compare( $wp_version, '4.6', '<' ),
303
					'wp_version_below_49'  => version_compare( $wp_version, '4.9', '<' ),
304
					'wp_update_link'       => monsterinsights_get_url( 'settings-notice', 'settings-page', 'https://www.monsterinsights.com/docs/update-wordpress/' ),
305
				),
306
				'plugin_version'  => MONSTERINSIGHTS_VERSION,
307
				'is_admin'        => true,
308
				'wizard_url'      => admin_url( 'index.php?page=monsterinsights-onboarding' ),
309
				'install_nonce'   => wp_create_nonce( 'monsterinsights-install' ),
310
				'activate_nonce'  => wp_create_nonce( 'monsterinsights-activate' ),
311
				'deactivate_nonce'=> wp_create_nonce( 'monsterinsights-deactivate' ),
312
				'update_settings' => current_user_can( 'monsterinsights_save_settings' ),
313
			)
314
		);
315
316
		return;
317
	}
318
	// ublock notice
319
	add_action( 'admin_print_footer_scripts', 'monsterinsights_settings_ublock_error_js', 9999999 );
320
}
321
322
add_action( 'admin_enqueue_scripts', 'monsterinsights_admin_scripts' );
323
324
/**
325
 * Remove Assets that conflict with ours from our screens.
326
 *
327
 * @return null Return early if not on the proper screen.
328
 * @since 6.0.4
329
 * @access public
330
 *
331
 */
332
function monsterinsights_remove_conflicting_asset_files() {
333
334
	// Get current screen.
335
	$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...
336
337
	// Bail if we're not on a MonsterInsights screen.
338
	if ( empty( $screen->id ) || strpos( $screen->id, 'monsterinsights' ) === false ) {
339
		return;
340
	}
341
342
	$styles = array(
343
		'kt_admin_css', // Pinnacle theme
344
		'select2-css', // Schema theme
345
		'tweetshare_style', // TweetShare - Click To Tweet
346
		'tweetshare_custom_style', // TweetShare - Click To Tweet
347
		'tweeetshare_custome_style', // TweetShare - Click To Tweet
348
		'tweeetshare_notice_style', // TweetShare - Click To Tweet
349
		'tweeetshare_theme_style', // TweetShare - Click To Tweet
350
		'tweeetshare_tweet_box_style', // TweetShare - Click To Tweet
351
		'soultype2-admin', // SoulType Plugin
352
		'thesis-options-stylesheet', // Thesis Options Stylesheet
353
		'imagify-sweetalert-core', // Imagify
354
		'imagify-sweetalert', // Imagify
355
		'smls-backend-style', // Smart Logo Showcase Lite
356
		'wp-reactjs-starter', // wp-real-media-library
357
		'control-panel-modal-plugin', // Ken Theme
358
		'theme-admin-css', // Vitrine Theme
359
		'qi-framework-styles', //  Artisan Nayma Theme
360
		'artisan-pages-style', // Artisan Pages Plugin
361
		'control-panel-modal-plugin', // Ken Theme
362
		'sweetalert', //  Church Suite Theme by Webnus
363
		'woo_stock_alerts_admin_css', // WooCommerce bolder product alerts
364
		'custom_wp_admin_css', // Fix for Add Social Share
365
		'fo_css', // Fix for Add Social Share
366
		'font_css', // Fix for Add Social Share
367
		'font2_css', // Fix for Add Social Share
368
		'font3_css', // Fix for Add Social Share
369
		'hover_css', // Fix for Add Social Share
370
		'fontend_styling', // Fix for Add Social Share
371
		'datatable', // WP Todo
372
		'bootstrap', // WP Todo
373
		'flipclock', // WP Todo
374
		'repuso_css_admin', // Social testimonials and reviews by Repuso
375
	);
376
377
	$scripts = array(
378
		'kad_admin_js', // Pinnacle theme
379
		'dt-chart', // DesignThemes core features plugin
380
		'tweeetshare_font_script', // TweetShare - Click To Tweet
381
		'tweeetshare_jquery_script',  // TweetShare - Click To Tweet
382
		'tweeetshare_jqueryui_script', // TweetShare - Click To Tweet
383
		'tweeetshare_custom_script', // TweetShare - Click To Tweet
384
		'imagify-promise-polyfill', // Imagify
385
		'imagify-sweetalert', // Imagify
386
		'imagify-chart', // Imagify
387
		'chartjs', // Comet Cache Pro
388
		'wp-reactjs-starter', // wp-real-media-library
389
		'jquery-tooltipster', // WP Real Media Library
390
		'jquery-nested-sortable', // WP Real Media Library
391
		'jquery-aio-tree', // WP Real Media Library
392
		'wp-media-picker', // WP Real Media Library
393
		'rml-general', // WP Real Media Library
394
		'rml-library', // WP Real Media Library
395
		'rml-grid', // WP Real Media Library
396
		'rml-list', // WP Real Media Library
397
		'rml-modal', // WP Real Media Library
398
		'rml-order', // WP Real Media Library
399
		'rml-meta', // WP Real Media Library
400
		'rml-uploader',  // WP Real Media Library
401
		'rml-options',  // WP Real Media Library
402
		'rml-usersettings',  // WP Real Media Library
403
		'rml-main', // WP Real Media Library
404
		'control-panel-sweet-alert', // Ken Theme
405
		'sweet-alert-js', // Vitrine Theme
406
		'theme-admin-script', // Vitrine Theme
407
		'sweetalert', //  Church Suite Theme by Webnus
408
		'be_alerts_charts', //  WooCommerce bolder product alerts
409
		'magayo-lottery-results',  //  Magayo Lottery Results
410
		'control-panel-sweet-alert', // Ken Theme
411
		'cpm_chart', // WP Project Manager
412
		'adminscripts', //  Artisan Nayma Theme
413
		'artisan-pages-script', // Artisan Pages Plugin
414
		'tooltipster', // Grand News Theme
415
		'fancybox', // Grand News Theme
416
		'grandnews-admin-cript', // Grand News Theme
417
		'colorpicker', // Grand News Theme
418
		'eye', // Grand News Theme
419
		'icheck', // Grand News Theme
420
		'learn-press-chart', //  LearnPress
421
		'theme-script-main', //  My Listing Theme by 27collective
422
		'selz', //  Selz eCommerce
423
		'tie-admin-scripts', //   Tie Theme
424
		'blossomthemes-toolkit', //   BlossomThemes Toolkit
425
		'illdy-widget-upload-image', //   Illdy Companion By Colorlib
426
		'moment.js', // WooCommerce Table Rate Shipping
427
		'default', //   Bridge Theme
428
		'qode-tax-js', //   Bridge Theme
429
		'wc_smartship_moment_js', // WooCommerce Posti SmartShip by markup.fi
430
		'ecwid-admin-js', // Fixes Conflict for Ecwid Shopping Cart
431
		'td-wp-admin-js', // Newspaper by tagDiv
432
		'moment', // Screets Live Chat
433
		'wpmf-base', //  WP Media Folder Fix
434
		'wpmf-media-filters', //  WP Media Folder Fix
435
		'wpmf-folder-tree', //  WP Media Folder Fix
436
		'wpmf-assign-tree', //  WP Media Folder Fix
437
		'js_files_for_wp_admin', //  TagDiv Composer Fix
438
		'tdb_js_files_for_wp_admin_last', //  TagDiv Composer Fix
439
		'tdb_js_files_for_wp_admin', //  TagDiv Composer Fix
440
		'wd-functions', //  affiliate boxes
441
		'ellk-aliExpansion', // Ali Dropship Plugin
442
		'ftmetajs', // Houzez Theme
443
		'qode_admin_default', //  Fix For Stockholm Theme
444
		'qodef-tax-js', // Fix for Prowess Theme
445
		'qodef-user-js', // Fix for Prowess Theme
446
		'qodef-ui-admin', // Fix for Prowess Theme
447
		'ssi_script', // Fix for Add Social Share
448
		'live_templates', // Fix for Add Social Share
449
		'default', // Fix for Add Social Share
450
		'handsontable', // Fix WP Tables
451
		'moment-js', // Magee Shortcodes
452
		'postbox', // Scripts from wp-admin enqueued everywhere by WP Posts Filter
453
		'link', // Scripts from wp-admin enqueued everywhere by WP Posts Filter
454
		'wpvr_scripts', // WP Video Robot
455
		'wpvr_scripts_loaded', // WP Video Robot
456
		'wpvr_scripts_assets', // WP Video Robot
457
		'writee_widget_admin', // Fix for the Writtee theme
458
		'__ytprefs_admin__', // Fix for YouTube by EmbedPlus plugin
459
		'momentjs', // Fix for Blog Time plugin
460
		'c2c_BlogTime', //  Fix for Blog Time plugin
461
		'material-wp', // Fix for MaterialWP plugin
462
		'wp-color-picker-alpha', // Fix for MaterialWP plugin
463
		'grandtour-theme-script', // Grandtour Theme
464
		'swifty-img-widget-admin-script', // Fix for Swifty Image Widget
465
		'datatable', // WP Todo
466
		'flipclock', // WP Todo
467
		'bootstrap', // WP Todo
468
		'repuso_js_admin', // Social testimonials and reviews by Repuso
469
		'chart', // Video Mate Pro Theme
470
		'reuse_vendor', // RedQ Reuse Form
471
		'jetpack-onboarding-vendor', // Jetpack Onboarding Bluehost
472
		'date-js', // Google Analytics by Web Dorado
473
	);
474
475
	if ( ! empty( $styles ) ) {
476
		foreach ( $styles as $style ) {
477
			wp_dequeue_style( $style ); // Remove CSS file from MI screen
478
			wp_deregister_style( $style );
479
		}
480
	}
481
	if ( ! empty( $scripts ) ) {
482
		foreach ( $scripts as $script ) {
483
			wp_dequeue_script( $script ); // Remove JS file from MI screen
484
			wp_deregister_script( $script );
485
		}
486
	}
487
488
	$third_party = array(
489
		'select2',
490
		'sweetalert',
491
		'clipboard',
492
		'matchHeight',
493
		'inputmask',
494
		'jquery-confirm',
495
		'list',
496
		'toastr',
497
		'tooltipster',
498
		'flag-icon',
499
		'bootstrap',
500
	);
501
502
	global $wp_styles;
503
	foreach ( $wp_styles->queue as $handle ) {
504
		if ( strpos( $wp_styles->registered[ $handle ]->src, 'wp-content' ) === false ) {
505
			return;
506
		}
507
508
		if ( strpos( $wp_styles->registered[ $handle ]->handle, 'monsterinsights' ) !== false ) {
509
			return;
510
		}
511
512
		foreach ( $third_party as $partial ) {
513
			if ( strpos( $wp_styles->registered[ $handle ]->handle, $partial ) !== false ) {
514
				wp_dequeue_style( $handle ); // Remove css file from MI screen
515
				wp_deregister_style( $handle );
516
				break;
517
			} else if ( strpos( $wp_styles->registered[ $handle ]->src, $partial ) !== false ) {
518
				wp_dequeue_style( $handle ); // Remove css file from MI screen
519
				wp_deregister_style( $handle );
520
				break;
521
			}
522
		}
523
	}
524
525
	global $wp_scripts;
526
	foreach ( $wp_scripts->queue as $handle ) {
527
		if ( strpos( $wp_scripts->registered[ $handle ]->src, 'wp-content' ) === false ) {
528
			return;
529
		}
530
531
		if ( strpos( $wp_scripts->registered[ $handle ]->handle, 'monsterinsights' ) !== false ) {
532
			return;
533
		}
534
535
		foreach ( $third_party as $partial ) {
536
			if ( strpos( $wp_scripts->registered[ $handle ]->handle, $partial ) !== false ) {
537
				wp_dequeue_script( $handle ); // Remove JS file from MI screen
538
				wp_deregister_script( $handle );
539
				break;
540
			} else if ( strpos( $wp_scripts->registered[ $handle ]->src, $partial ) !== false ) {
541
				wp_dequeue_script( $handle ); // Remove JS file from MI screen
542
				wp_deregister_script( $handle );
543
				break;
544
			}
545
		}
546
	}
547
548
	// Remove actions from themes that are not following best practices and break the admin doing so
549
	// Theme: Newspaper by tagDiv
550
	remove_action( 'admin_enqueue_scripts', 'load_wp_admin_js' );
551
	remove_action( 'admin_enqueue_scripts', 'load_wp_admin_css' );
552
	remove_action( 'admin_print_scripts-widgets.php', 'td_on_admin_print_scripts_farbtastic' );
553
	remove_action( 'admin_print_styles-widgets.php', 'td_on_admin_print_styles_farbtastic' );
554
	remove_action( 'admin_print_footer_scripts', 'check_if_media_uploads_is_loaded', 9999 );
555
	remove_action( 'print_media_templates', 'td_custom_gallery_settings_hook' );
556
	remove_action( 'print_media_templates', 'td_change_backbone_js_hook' );
557
	remove_action( 'admin_head', 'tdc_on_admin_head' ); //  TagDiv Composer Fix
558
	remove_action( 'print_media_templates', 'us_media_templates' ); // Impreza Theme Fix
559
	remove_action( 'admin_footer', 'gt3pg_add_gallery_template' ); // GT3 Photo & Video Gallery By GT3 Themes Plugin Fix
560
	// Plugin WP Booklist:
561
	remove_action( 'admin_footer', 'wpbooklist_jre_dismiss_prem_notice_forever_action_javascript' );
562
	remove_action( 'admin_footer', 'wpbooklist_dashboard_add_book_action_javascript' );
563
	remove_action( 'admin_footer', 'wpbooklist_edit_book_show_form_action_javascript' );
564
	remove_action( 'admin_footer', 'wpbooklist_show_book_in_colorbox_action_javascript' );
565
	remove_action( 'admin_footer', 'wpbooklist_new_lib_shortcode_action_javascript' );
566
	remove_action( 'admin_footer', 'wpbooklist_dashboard_save_library_display_options_action_javascript' );
567
	remove_action( 'admin_footer', 'wpbooklist_dashboard_save_post_display_options_action_javascript' );
568
	remove_action( 'admin_footer', 'wpbooklist_dashboard_save_page_display_options_action_javascript' );
569
	remove_action( 'admin_footer', 'wpbooklist_update_display_options_action_javascript' );
570
	remove_action( 'admin_footer', 'wpbooklist_edit_book_pagination_action_javascript' );
571
	remove_action( 'admin_footer', 'wpbooklist_edit_book_switch_lib_action_javascript' );
572
	remove_action( 'admin_footer', 'wpbooklist_edit_book_search_action_javascript' );
573
	remove_action( 'admin_footer', 'wpbooklist_edit_book_actual_action_javascript' );
574
	remove_action( 'admin_footer', 'wpbooklist_delete_book_action_javascript' );
575
	remove_action( 'admin_footer', 'wpbooklist_user_apis_action_javascript' );
576
	remove_action( 'admin_footer', 'wpbooklist_upload_new_stylepak_action_javascript' );
577
	remove_action( 'admin_footer', 'wpbooklist_upload_new_post_template_action_javascript' );
578
	remove_action( 'admin_footer', 'wpbooklist_upload_new_page_template_action_javascript' );
579
	remove_action( 'admin_footer', 'wpbooklist_create_db_library_backup_action_javascript' );
580
	remove_action( 'admin_footer', 'wpbooklist_restore_db_library_backup_action_javascript' );
581
	remove_action( 'admin_footer', 'wpbooklist_create_csv_action_javascript' );
582
	remove_action( 'admin_footer', 'wpbooklist_amazon_localization_action_javascript' );
583
	remove_action( 'admin_footer', 'wpbooklist_delete_book_bulk_action_javascript' );
584
	remove_action( 'admin_footer', 'wpbooklist_reorder_action_javascript' );
585
	remove_action( 'admin_footer', 'wpbooklist_exit_results_action_javascript' );
586
	remove_action( 'admin_footer', 'wpbooklist_storytime_select_category_action_javascript' );
587
	remove_action( 'admin_footer', 'wpbooklist_storytime_get_story_action_javascript' );
588
	remove_action( 'admin_footer', 'wpbooklist_storytime_expand_browse_action_javascript' );
589
	remove_action( 'admin_footer', 'wpbooklist_storytime_save_settings_action_javascript' );
590
	remove_action( 'admin_footer', 'wpbooklist_delete_story_action_javascript' );
591
}
592
593
add_action( 'admin_enqueue_scripts', 'monsterinsights_remove_conflicting_asset_files', 9999 );
594
595
/**
596
 * Remove non-MI notices from MI page.
597
 *
598
 * @return null Return early if not on the proper screen.
599
 * @since 6.0.0
600
 * @access public
601
 *
602
 */
603
function hide_non_monsterinsights_warnings() {
604
	// Bail if we're not on a MonsterInsights screen.
605
	if ( empty( $_REQUEST['page'] ) || strpos( $_REQUEST['page'], 'monsterinsights' ) === false ) {
606
		return;
607
	}
608
609
	global $wp_filter;
610
	if ( ! empty( $wp_filter['user_admin_notices']->callbacks ) && is_array( $wp_filter['user_admin_notices']->callbacks ) ) {
611
		foreach ( $wp_filter['user_admin_notices']->callbacks as $priority => $hooks ) {
612
			foreach ( $hooks as $name => $arr ) {
613
				if ( is_object( $arr['function'] ) && $arr['function'] instanceof Closure ) {
614
					unset( $wp_filter['user_admin_notices']->callbacks[ $priority ][ $name ] );
615
					continue;
616
				}
617
				if ( ! empty( $arr['function'][0] ) && is_object( $arr['function'][0] ) && strpos( strtolower( get_class( $arr['function'][0] ) ), 'monsterinsights' ) !== false ) {
618
					continue;
619
				}
620
				if ( ! empty( $name ) && strpos( $name, 'monsterinsights' ) === false ) {
621
					unset( $wp_filter['user_admin_notices']->callbacks[ $priority ][ $name ] );
622
				}
623
			}
624
		}
625
	}
626
627
	if ( ! empty( $wp_filter['admin_notices']->callbacks ) && is_array( $wp_filter['admin_notices']->callbacks ) ) {
628
		foreach ( $wp_filter['admin_notices']->callbacks as $priority => $hooks ) {
629
			foreach ( $hooks as $name => $arr ) {
630
				if ( is_object( $arr['function'] ) && $arr['function'] instanceof Closure ) {
631
					unset( $wp_filter['admin_notices']->callbacks[ $priority ][ $name ] );
632
					continue;
633
				}
634
				if ( ! empty( $arr['function'][0] ) && is_object( $arr['function'][0] ) && strpos( strtolower( get_class( $arr['function'][0] ) ), 'monsterinsights' ) !== false ) {
635
					continue;
636
				}
637
				if ( ! empty( $name ) && strpos( $name, 'monsterinsights' ) === false ) {
638
					unset( $wp_filter['admin_notices']->callbacks[ $priority ][ $name ] );
639
				}
640
			}
641
		}
642
	}
643
644
	if ( ! empty( $wp_filter['all_admin_notices']->callbacks ) && is_array( $wp_filter['all_admin_notices']->callbacks ) ) {
645
		foreach ( $wp_filter['all_admin_notices']->callbacks as $priority => $hooks ) {
646
			foreach ( $hooks as $name => $arr ) {
647
				if ( is_object( $arr['function'] ) && $arr['function'] instanceof Closure ) {
648
					unset( $wp_filter['all_admin_notices']->callbacks[ $priority ][ $name ] );
649
					continue;
650
				}
651
				if ( ! empty( $arr['function'][0] ) && is_object( $arr['function'][0] ) && strpos( strtolower( get_class( $arr['function'][0] ) ), 'monsterinsights' ) !== false ) {
652
					continue;
653
				}
654
				if ( ! empty( $name ) && strpos( $name, 'monsterinsights' ) === false ) {
655
					unset( $wp_filter['all_admin_notices']->callbacks[ $priority ][ $name ] );
656
				}
657
			}
658
		}
659
	}
660
}
661
662
add_action( 'admin_print_scripts', 'hide_non_monsterinsights_warnings' );
663
add_action( 'admin_head', 'hide_non_monsterinsights_warnings', PHP_INT_MAX );
664
665
/**
666
 * Called whenever an upgrade button / link is displayed in Lite, this function will
667
 * check if there's a shareasale ID specified.
668
 *
669
 * There are three ways to specify an ID, ordered by highest to lowest priority
670
 * - add_filter( 'monsterinsights_shareasale_id', function() { return 1234; } );
671
 * - define( 'MONSTERINSIGHTS_SHAREASALE_ID', 1234 );
672
 * - get_option( 'monsterinsights_shareasale_id' ); (with the option being in the wp_options table)
673
 *
674
 * If an ID is present, returns the ShareASale link with the affiliate ID, and tells
675
 * ShareASale to then redirect to monsterinsights.com/lite
676
 *
677
 * If no ID is present, just returns the monsterinsights.com/lite URL with UTM tracking.
678
 *
679
 * @return string Upgrade link.
680
 * @since 6.0.0
681
 * @access public
682
 *
683
 */
684
function monsterinsights_get_upgrade_link( $medium = '', $campaign = '', $url = '' ) {
685
	$url = monsterinsights_get_url( $medium, $campaign, $url, false );
686
687
	if ( monsterinsights_is_pro_version() ) {
688
		return esc_url( $url );
689
	}
690
691
	// Get the ShareASale ID
692
	$shareasale_id = monsterinsights_get_shareasale_id();
693
694
	// If we have a shareasale ID return the shareasale url
695
	if ( ! empty( $shareasale_id ) ) {
696
		$shareasale_id = absint( $shareasale_id );
697
698
		return esc_url( monsterinsights_get_shareasale_url( $shareasale_id, $url ) );
699
	} else {
700
		return esc_url( $url );
701
	}
702
}
703
704
function monsterinsights_get_url( $medium = '', $campaign = '', $url = '', $escape = true ) {
705
	// Setup Campaign variables
706
	$source      = monsterinsights_is_pro_version() ? 'proplugin' : 'liteplugin';
707
	$medium      = ! empty( $medium ) ? $medium : 'defaultmedium';
708
	$campaign    = ! empty( $campaign ) ? $campaign : 'defaultcampaign';
709
	$content     = MONSTERINSIGHTS_VERSION;
710
	$default_url = monsterinsights_is_pro_version() ? '' : 'lite/';
711
	$url         = ! empty( $url ) ? $url : 'https://www.monsterinsights.com/' . $default_url;
712
713
	// Put together redirect URL
714
	$url = add_query_arg(
715
		array(
716
			'utm_source'   => $source,   // Pro/Lite Plugin
717
			'utm_medium'   => sanitize_key( $medium ),   // Area of MonsterInsights (example Reports)
718
			'utm_campaign' => sanitize_key( $campaign ), // Which link (example eCommerce Report)
719
			'utm_content'  => $content,  // Version number of MI
720
		),
721
		trailingslashit( $url )
722
	);
723
724
	if ( $escape ) {
725
		return esc_url( $url );
726
	} else {
727
		return $url;
728
	}
729
}
730
731
function monsterinsights_settings_ublock_error_js() {
732
	echo "<script type='text/javascript'>\n";
733
	echo "jQuery( document ).ready( function( $ ) {
734
			if ( window.uorigindetected == null){
735
			   $('#monsterinsights-ublock-origin-error').show();
736
			   $('.monsterinsights-nav-tabs').hide();
737
			   $('.monsterinsights-nav-container').hide();
738
			   $('#monsterinsights-addon-heading').hide();
739
			   $('#monsterinsights-addons').hide();
740
			   $('#monsterinsights-reports').hide();
741
			}
742
		});";
743
	echo "\n</script>";
744
}
745
746
function monsterinsights_ublock_notice() {
747
	ob_start(); ?>
748
	<div id="monsterinsights-ublock-origin-error" class="error inline" style="display:none;">
749
		<?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">' );
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"><?php esc_html_e( 'View 2019 Year in Review report!', 'google-analytics-for-wordpress' ); ?></a>
878
			</p>
879
		</div>
880
	</div>
881
	<style type="text/css">
882
		#monsterinsights-yearinreview-admin-menu-tooltip {
883
			position: absolute;
884
			left: 100%;
885
			top: 100%;
886
			background: #fff;
887
			margin-left: 16px;
888
			width: 350px;
889
			box-shadow: 0px 4px 7px 0px #ccc;
890
		}
891
892
		#monsterinsights-yearinreview-admin-menu-tooltip:before {
893
			content: '';
894
			width: 0;
895
			height: 0;
896
			border-style: solid;
897
			border-width: 12px 12px 12px 0;
898
			border-color: transparent #fff transparent transparent;
899
			position: absolute;
900
			right: 100%;
901
			top: 130px;
902
			z-index: 10;
903
		}
904
905
		#monsterinsights-yearinreview-admin-menu-tooltip:after {
906
			content: '';
907
			width: 0;
908
			height: 0;
909
			border-style: solid;
910
			border-width: 13px 13px 13px 0;
911
			border-color: transparent #ccc transparent transparent;
912
			position: absolute;
913
			right: 100%;
914
			margin-left: -1px;
915
			top: 129px;
916
			z-index: 5;
917
		}
918
919
		#monsterinsights-yearinreview-admin-menu-tooltip.monsterinsights-yearinreview-tooltip-arrow-top:before {
920
			top: 254px;
921
		}
922
923
		#monsterinsights-yearinreview-admin-menu-tooltip.monsterinsights-yearinreview-tooltip-arrow-top:after {
924
			top: 253px;
925
		}
926
927
		.monsterinsights-yearinreview-admin-menu-tooltip-header {
928
			background: #03a0d2;
929
			padding: 5px 12px;
930
			font-size: 14px;
931
			font-weight: 700;
932
			font-family: Arial, Helvetica, "Trebuchet MS", sans-serif;
933
			color: #fff;
934
			line-height: 1.6;
935
		}
936
937
		.monsterinsights-yearinreview-admin-menu-tooltip-icon {
938
			background: #fff;
939
			border-radius: 50%;
940
			width: 28px;
941
			height: 25px;
942
			display: inline-block;
943
			color: #03a0d2;
944
			text-align: center;
945
			padding: 3px 0 0;
946
			margin-right: 6px;
947
		}
948
949
		.monsterinsights-yearinreview-admin-menu-tooltip-hide {
950
			display: none;
951
		}
952
953
		.monsterinsights-yearinreview-admin-menu-tooltip-content {
954
			padding: 20px 15px 7px;
955
		}
956
957
		.monsterinsights-yearinreview-admin-menu-tooltip-content strong {
958
			font-size: 14px;
959
		}
960
961
		.monsterinsights-yearinreview-admin-menu-tooltip-content p strong {
962
			font-size: 13px;
963
		}
964
965
		.monsterinsights-yearinreview-admin-menu-tooltip-close {
966
			color: #fff;
967
			text-decoration: none;
968
			position: absolute;
969
			right: 10px;
970
			top: 12px;
971
			display: block;
972
		}
973
974
		.monsterinsights-yearinreview-admin-menu-tooltip-close:hover {
975
			color: #fff;
976
			text-decoration: none;
977
		}
978
979
		.monsterinsights-yearinreview-admin-menu-tooltip-close .dashicons {
980
			font-size: 14px;
981
		}
982
983
		@media ( max-width: 782px ) {
984
			#monsterinsights-yearinreview-admin-menu-tooltip {
985
				display: none;
986
			}
987
		}
988
	</style>
989
	<script type="text/javascript">
990
		if ( 'undefined' !== typeof jQuery ) {
991
			jQuery( function ( $ ) {
992
				var $tooltip = $( document.getElementById( 'monsterinsights-yearinreview-admin-menu-tooltip' ) );
993
				var $menuwrapper = $( document.getElementById( 'adminmenuwrap' ) );
994
				var $menuitem = $( document.getElementById( 'toplevel_page_monsterinsights_reports' ) );
995
				if ( 0 === $menuitem.length ) {
996
					$menuitem = $( document.getElementById( 'toplevel_page_monsterinsights_network' ) );
997
				}
998
999
				if ( $menuitem.length ) {
1000
					$menuwrapper.append( $tooltip );
1001
					$tooltip.removeClass( 'monsterinsights-yearinreview-admin-menu-tooltip-hide' );
1002
				}
1003
1004
				function alignTooltip() {
1005
					var sticky = $( 'body' ).hasClass( 'sticky-menu' );
1006
1007
					var menuitem_pos = $menuitem.position();
1008
					var tooltip_top = menuitem_pos.top - 124;
1009
					if ( sticky && $( window ).height() > $menuwrapper.height() + 150 ) {
1010
						$tooltip.removeClass( 'monsterinsights-yearinreview-tooltip-arrow-top' );
1011
					} else {
1012
						tooltip_top = menuitem_pos.top - 250;
1013
						$tooltip.addClass( 'monsterinsights-yearinreview-tooltip-arrow-top' );
1014
					}
1015
					// Don't let the tooltip go outside of the screen and make the close button not visible.
1016
					if ( tooltip_top < 40 ) {
1017
						tooltip_top = 40;
1018
					}
1019
					$tooltip.css( {
1020
						top: tooltip_top + 'px'
1021
					} );
1022
				}
1023
1024
				var $document = $( document );
1025
				var timeout = setTimeout( alignTooltip, 10 );
1026
				$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 () {
1027
					if ( timeout ) {
1028
						clearTimeout( timeout );
1029
					}
1030
					timeout = setTimeout( alignTooltip, 10 );
1031
				} );
1032
1033
				$( '.monsterinsights-yearinreview-admin-menu-tooltip-btn-link' ).on( 'click', function ( e ) {
1034
					hideYearInReviewTooltip();
1035
				} );
1036
1037
				$( '.monsterinsights-yearinreview-admin-menu-tooltip-close' ).on( 'click', function ( e ) {
1038
					e.preventDefault();
1039
					hideYearInReviewTooltip();
1040
				} );
1041
1042
				function hideYearInReviewTooltip() {
1043
					$tooltip.addClass( 'monsterinsights-yearinreview-admin-menu-tooltip-hide' );
1044
					$.post( ajaxurl, {
1045
						action: 'monsterinsights_yearinreview_hide_admin_tooltip',
1046
						nonce: '<?php echo esc_js( wp_create_nonce( 'mi-admin-nonce' ) ); ?>',
1047
					} );
1048
				}
1049
			} );
1050
		}
1051
	</script>
1052
	<?php
1053
}
1054
1055
add_action( 'adminmenu', 'monsterinsights_yearinreview_admin_menu_tooltip', 5 );
1056
1057
/**
1058
 * Store the time when the year in review tooltip was hidden so it won't show again
1059
 */
1060
function monsterinsights_mark_yearinreview_tooltip_hidden() {
1061
	check_ajax_referer( 'mi-admin-nonce', 'nonce' );
1062
	update_option( 'monsterinsights_yearinreview_dismiss_admin_tooltip', true );
1063
	wp_send_json_success();
1064
}
1065
1066
add_action( 'wp_ajax_monsterinsights_yearinreview_hide_admin_tooltip', 'monsterinsights_mark_yearinreview_tooltip_hidden' );
1067