Passed
Push — master ( 2bd1cf...bfbffa )
by
unknown
05:03
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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A monsterinsights_get_php_wp_version_warning_data() 0 12 2
A monsterinsights_maybe_add_wp_php_version_notification() 0 61 4
A monsterinsights_prevent_version_number_removal() 0 12 6
A monsterinsights_year_in_review_notification() 0 20 2

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
/**
810
 * Prevent plugins/themes from removing the version number from scripts loaded by our plugin.
811
 * Ideally those plugins/themes would follow WordPress coding best practices, but in lieu of that
812
 * we can at least attempt to prevent 99% of them from doing bad things.
813
 *
814
 * @param string $src The script source.
815
 *
816
 * @return string
817
 */
818
function monsterinsights_prevent_version_number_removal( $src ) {
819
	// Apply this only to admin-side scripts.
820
	if ( ! is_admin() ) {
821
		return $src;
822
	}
823
824
	// Make sure are only changing our scripts and only if the version number is missing.
825
	if ( ( false !== strpos( $src, 'monsterinsights' ) || false !== strpos( $src, 'google-analytics-for-wordpress' ) || false !== strpos( $src, 'google-analytics-premium' ) ) && false === strpos( $src, '?ver' ) ) {
826
		$src = add_query_arg( 'ver', monsterinsights_get_asset_version(), $src );
827
	}
828
829
	return $src;
830
}
831
832
add_filter( 'script_loader_src', 'monsterinsights_prevent_version_number_removal', 9999, 1 );
833
add_filter( 'style_loader_src', 'monsterinsights_prevent_version_number_removal', 9999, 1 );
834
835
/**
836
 * Data used for the Vue scripts to display old PHP and WP versions warnings.
837
 */
838
function monsterinsights_get_php_wp_version_warning_data() {
839
	global $wp_version;
840
841
	return array(
842
		'php_version'          => phpversion(),
843
		'php_version_below_54' => apply_filters( 'monsterinsights_temporarily_hide_php_under_56_upgrade_warnings', version_compare( phpversion(), '5.6', '<' ) ),
844
		'php_version_below_56' => apply_filters( 'monsterinsights_temporarily_hide_php_56_upgrade_warnings', version_compare( phpversion(), '5.6', '>=' ) && version_compare( phpversion(), '7', '<' ) ),
845
		'php_update_link'      => monsterinsights_get_url( 'settings-notice', 'settings-page', 'https://www.monsterinsights.com/docs/update-php/' ),
846
		'wp_version'           => $wp_version,
847
		'wp_version_below_46'  => version_compare( $wp_version, '4.9', '<' ),
848
		'wp_version_below_49'  => version_compare( $wp_version, '5.3', '<' ),
849
		'wp_update_link'       => monsterinsights_get_url( 'settings-notice', 'settings-page', 'https://www.monsterinsights.com/docs/update-wordpress/' ),
850
	);
851
}
852
853
/**
854
 * Check WP and PHP version and add contextual notifications for upgrades.
855
 */
856
function monsterinsights_maybe_add_wp_php_version_notification() {
857
	global $wp_version;
858
859
	$icon              = '<svg width="32" height="32" viewBox="0 0 32 32" fill="none" xmlns="http://www.w3.org/2000/svg"><circle cx="16" cy="16" r="16" fill="#FAD1D1"/><path d="M17.3634 19.0714C17.792 19.4821 18.0063 19.9821 18.0063 20.5714C18.0063 21.1607 17.792 21.6607 17.3634 22.0714C16.9527 22.5 16.4527 22.7143 15.8634 22.7143C15.2742 22.7143 14.7652 22.5 14.3367 22.0714C13.9259 21.6607 13.7206 21.1607 13.7206 20.5714C13.7206 19.9821 13.9259 19.4821 14.3367 19.0714C14.7652 18.6429 15.2742 18.4286 15.8634 18.4286C16.4527 18.4286 16.9527 18.6429 17.3634 19.0714ZM13.9617 9.66964C13.9617 9.49107 14.0242 9.33929 14.1492 9.21429C14.2742 9.07143 14.4259 9 14.6045 9H17.1224C17.3009 9 17.4527 9.07143 17.5777 9.21429C17.7027 9.33929 17.7652 9.49107 17.7652 9.66964L17.3902 16.9554C17.3902 17.1339 17.3277 17.2857 17.2027 17.4107C17.0777 17.5179 16.9259 17.5714 16.7474 17.5714H14.9795C14.8009 17.5714 14.6492 17.5179 14.5242 17.4107C14.3992 17.2857 14.3367 17.1339 14.3367 16.9554L13.9617 9.66964Z" fill="#EB5757"/></svg>';
860
	$needs_php_warning = version_compare( phpversion(), '5.6', '<' );
861
	$needs_wp_warning  = version_compare( $wp_version, '4.9', '<' );
862
863
	if ( $needs_php_warning ) {
864
		$notification['id']    = 'upgrade_php_56_notification';
0 ignored issues
show
Comprehensibility Best Practice introduced by
$notification was never initialized. Although not strictly required by PHP, it is generally a good practice to add $notification = array(); before regardless.
Loading history...
865
		$notification['title'] = __( 'ACTION REQUIRED: Your PHP version is putting your site at risk!', 'google-analytics-for-wordpress' );
866
		if ( $needs_wp_warning ) {
867
			$notification['title'] = __( 'ACTION REQUIRED: Speed your website up 400% with a single email!', 'google-analytics-for-wordpress' );
868
		}
869
870
		$php_url = monsterinsights_get_url( 'notifications', 'upgrade-php', 'https://www.monsterinsights.com/docs/update-php' );
871
872
		$notification['type'] = array( 'basic', 'lite', 'master', 'plus', 'pro' );
873
		// Translators: Placeholder is for the current PHP version.
874
		$notification['content'] = sprintf( esc_html__( 'In the next major release of MonsterInsights we are planning to remove support for the version of PHP you are using (%s). This insecure version is no longer supported by WordPress itself, so you are already missing out on the latest features of WordPress along with critical updates for security and performance (modern PHP versions make websites much faster).', 'google-analytics-for-wordpress' ), phpversion() ) . "\n\n";
875
876
		// Translators: Placeholders add a link to an article.
877
		$notification['content'] .= sprintf( esc_html__( 'To ensure MonsterInsights and other plugins on your site continue to function properly, and avoid putting your site at risk, please take a few minutes to ask your website hosting provider to upgrade the version of PHP to a modern PHP version (7.2 or newer). We provide helpful templates for how to ask them %1$shere%2$s.', 'google-analytics-for-wordpress' ), '<a target="_blank" href="' . $php_url . '">', '</a>' ) . "\n\n";
878
		$notification['content'] .= esc_html__( 'Upgrading your PHP version will make sure you are able to continue using WordPress without issues in the future, keep your site secure, and will also make your website up to 400% faster!', 'google-analytics-for-wordpress' );
879
880
		$notification['icon'] = $icon;
881
		$notification['btns'] = array(
882
			'learn_more' => array(
883
				'url'  => $php_url,
884
				'text' => esc_html__( 'Learn More', 'google-analytics-for-wordpress' ),
885
			),
886
		);
887
888
		// Add the notification.
889
		MonsterInsights()->notifications->add( $notification );
890
	}
891
892
	if ( $needs_wp_warning ) {
893
894
		$isitwp_url     = 'https://www.isitwp.com/upgrading-wordpress-is-easier-than-you-think/?utm_source=monsterinsights&utm_medium=notifications&utm_campaign=upgradewp';
895
		$wpbeginner_url = 'https://www.wpbeginner.com/beginners-guide/why-you-should-always-use-the-latest-version-of-wordpress/utm_source=monsterinsights&utm_medium=notifications&utm_campaign=upgradewp';
896
897
		$notification['id']    = 'upgrade_wp_49_notification';
898
		$notification['title'] = __( 'ACTION REQUIRED: Your WordPress version is putting your site at risk!', 'google-analytics-for-wordpress' );
899
		$notification['type']  = array( 'basic', 'lite', 'master', 'plus', 'pro' );
900
		// Translators: Placeholder is for the current WordPress version.
901
		$notification['content'] = sprintf( esc_html__( 'In the next major release of MonsterInsights we are planning to remove support for the version of WordPress you are using (version %s). This version is several years out of date, and most plugins do not support this version anymore, so you could be missing out on critical updates for performance and security already!', 'google-analytics-for-wordpress' ), $wp_version ) . "\n\n";
902
903
		$notification['content'] .= esc_html__( 'The good news: updating WordPress has never been easier and only takes a few moments.', 'google-analytics-for-wordpress' );
904
		// Translators: Placeholders add links to articles.
905
		$notification['content'] .= sprintf( esc_html__( 'To update, we recommend following this %1$sstep by step guide for updating WordPress%2$s from IsItWP and afterwards check out %3$sWhy You Should Always Use the Latest Version of WordPress%4$s on WPBeginner.', 'google-analytics-for-wordpress' ), '<a target="_blank" href="' . $isitwp_url . '">', '</a>', '<a target="_blank" href="' . $wpbeginner_url . '">', '</a>' ) . "\n\n";
906
907
		$notification['icon'] = $icon;
908
		$notification['btns'] = array(
909
			'learn_more' => array(
910
				'url'  => $isitwp_url,
911
				'text' => esc_html__( 'Learn More', 'google-analytics-for-wordpress' ),
912
			),
913
		);
914
915
		// Add the notification.
916
		MonsterInsights()->notifications->add( $notification );
917
	}
918
919
}
920
921
add_action( 'admin_init', 'monsterinsights_maybe_add_wp_php_version_notification' );
922
923
/**
924
 * Add notification for Year In Review report for year 2021.
925
 *
926
 * @since 7.13.2
927
 *
928
 * @return void
929
 */
930
function monsterinsights_year_in_review_notification() {
931
932
	// Check if dates are between Jan 1st 2021 & 13th Jan 2021.
933
	if ( monsterinsights_date_is_between( '2021-01-01', '2021-01-14' ) ) {
934
935
		$notification['id']      = 'monsterinsights_notification_year_in_review';
0 ignored issues
show
Comprehensibility Best Practice introduced by
$notification was never initialized. Although not strictly required by PHP, it is generally a good practice to add $notification = array(); before regardless.
Loading history...
936
		$notification['type']    = array( 'basic', 'lite', 'master', 'plus', 'pro' );
937
		$notification['start']   = '2021-01-01';
938
		$notification['end']     = '2021-01-14';
939
		$notification['title']   = esc_html__( 'View 2020 Year in Review report!', 'google-analytics-for-wordpress' );
940
		$notification['content'] = esc_html__( 'See how your website performed this year and find tips along the way to help grow even more in 2021!', 'google-analytics-for-wordpress' );
941
		$notification['btns']    = array(
942
			'learn_more' => array(
943
				'url'  => esc_url( admin_url( 'admin.php?page=monsterinsights_reports#/year-in-review' ) ),
944
				'text' => esc_html__( 'Learn More', 'google-analytics-for-wordpress' ),
945
			),
946
		);
947
948
		// Add the notification.
949
		MonsterInsights()->notifications->add( $notification );
950
	}
951
}
952
953
add_action( 'admin_init', 'monsterinsights_year_in_review_notification' );
954