1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Admin class. |
5
|
|
|
* |
6
|
|
|
* @since 6.0.0 |
7
|
|
|
* |
8
|
|
|
* @package MonsterInsights |
9
|
|
|
* @subpackage Admin |
10
|
|
|
* @author Chris Christoff |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
// Exit if accessed directly |
14
|
|
|
if (!defined('ABSPATH')) { |
15
|
|
|
exit; |
16
|
|
|
} |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Register menu items for MonsterInsights. |
20
|
|
|
* |
21
|
|
|
* @return void |
22
|
|
|
* @since 6.0.0 |
23
|
|
|
* @access public |
24
|
|
|
* |
25
|
|
|
*/ |
26
|
|
|
function monsterinsights_admin_menu() |
27
|
|
|
{ |
28
|
|
|
$hook = monsterinsights_get_menu_hook(); |
29
|
|
|
$menu_icon_inline = monsterinsights_get_inline_menu_icon(); |
30
|
|
|
$new_indicator = sprintf( |
31
|
|
|
'<span class="monsterinsights-menu-new-indicator"> %s</span>', |
32
|
|
|
__( 'NEW', 'google-analytics-for-wordpress' ) |
33
|
|
|
); |
34
|
|
|
|
35
|
|
|
$menu_notification_indicator = MonsterInsights()->notifications->get_menu_count(); |
36
|
|
|
|
37
|
|
|
if ( MonsterInsights()->license->license_expired() ) { |
|
|
|
|
38
|
|
|
$menu_notification_indicator = MonsterInsights()->notifications->get_license_expired_indicator(); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
if ($hook === 'monsterinsights_settings') { |
42
|
|
|
// If dashboards disabled, first settings page |
43
|
|
|
add_menu_page(__('MonsterInsights', 'google-analytics-for-wordpress'), __('Insights', 'google-analytics-for-wordpress') . $menu_notification_indicator, 'monsterinsights_save_settings', 'monsterinsights_settings', 'monsterinsights_settings_page', $menu_icon_inline, '100.00013467543'); |
|
|
|
|
44
|
|
|
$hook = 'monsterinsights_settings'; |
45
|
|
|
|
46
|
|
|
add_submenu_page($hook, __('MonsterInsights', 'google-analytics-for-wordpress'), __('Settings', 'google-analytics-for-wordpress'), 'monsterinsights_save_settings', 'monsterinsights_settings'); |
47
|
|
|
} else { |
48
|
|
|
// if dashboards enabled, first dashboard |
49
|
|
|
add_menu_page(__('General:', 'google-analytics-for-wordpress'), __('Insights', 'google-analytics-for-wordpress') . $menu_notification_indicator, 'monsterinsights_view_dashboard', 'monsterinsights_reports', 'monsterinsights_reports_page', $menu_icon_inline, '100.00013467543'); |
50
|
|
|
|
51
|
|
|
if ( ! MonsterInsights()->setup_checklist->is_dismissed() ) { |
52
|
|
|
add_submenu_page( $hook, __( 'Setup Checklist', 'google-analytics-for-wordpress' ), __( 'Setup Checklist', 'google-analytics-for-wordpress' ) . MonsterInsights()->setup_checklist->get_menu_count(), 'monsterinsights_save_settings', 'monsterinsights_settings#/setup-checklist', 'monsterinsights_settings_page' ); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
add_submenu_page( $hook, __( 'General Reports:', 'google-analytics-for-wordpress' ), __( 'Reports', 'google-analytics-for-wordpress' ), 'monsterinsights_view_dashboard', 'monsterinsights_reports', 'monsterinsights_reports_page' ); |
56
|
|
|
|
57
|
|
|
// then settings page |
58
|
|
|
add_submenu_page( $hook, __( 'MonsterInsights', 'google-analytics-for-wordpress' ), __( 'Settings', 'google-analytics-for-wordpress' ), 'monsterinsights_save_settings', 'monsterinsights_settings', 'monsterinsights_settings_page' ); |
59
|
|
|
|
60
|
|
|
// Add dashboard submenu. |
61
|
|
|
add_submenu_page( 'index.php', __( 'General Reports:', 'google-analytics-for-wordpress' ), __( 'Insights', 'google-analytics-for-wordpress' ), 'monsterinsights_view_dashboard', 'admin.php?page=monsterinsights_reports' ); |
62
|
|
|
|
63
|
|
|
// If the setup checklist is not dismissed, remove the own submenu of `Insights` main menu that we added on line 52. |
64
|
|
|
// This way the Checklist will be the first submenu which is an important thing for onboarding. |
65
|
|
|
if ( ! MonsterInsights()->setup_checklist->is_dismissed() ) { |
66
|
|
|
|
67
|
|
|
// Check if the user has the capability to save settings and view dashboard. |
68
|
|
|
// We should skip this for editors that have only view capability have only item in the submenu, removing that would break the menu. |
69
|
|
|
if ( ! ( ! current_user_can( 'monsterinsights_save_settings' ) && current_user_can( 'monsterinsights_view_dashboard' ) ) ) { |
70
|
|
|
// Remove own submenu of `Insights` main menu. |
71
|
|
|
remove_submenu_page( 'monsterinsights_reports', 'monsterinsights_reports' ); |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
$submenu_base = add_query_arg('page', 'monsterinsights_settings', admin_url('admin.php')); |
77
|
|
|
|
78
|
|
|
// Site Notes |
79
|
|
|
add_submenu_page( $hook, __( 'Site Notes:', 'google-analytics-for-wordpress' ), __( 'Site Notes', 'google-analytics-for-wordpress' ), 'monsterinsights_save_settings', $submenu_base . '#/site-notes' ); |
80
|
|
|
|
81
|
|
|
// AI Insights |
82
|
|
|
// translators: Icon |
83
|
|
|
add_submenu_page( $hook, __( 'AI Insights:', 'google-analytics-for-wordpress' ), sprintf( __( '%s AI Insights', 'google-analytics-for-wordpress' ), monsterinsights_get_ai_menu_icon() ), 'monsterinsights_save_settings', 'admin.php?page=monsterinsights_reports#/ai-insights' ); |
84
|
|
|
|
85
|
|
|
$license_type = MonsterInsights()->license->get_license_type(); |
86
|
|
|
|
87
|
|
|
// AI Chat |
88
|
|
|
if ( ! monsterinsights_is_pro_version() || 'plus' === $license_type ) { |
89
|
|
|
// translators: Placeholder adds an svg icon |
90
|
|
|
add_submenu_page( $hook, __( 'Conversations AI:', 'google-analytics-for-wordpress' ), sprintf( __( '%s Conversations AI', 'google-analytics-for-wordpress' ), monsterinsights_get_ai_menu_icon() ), 'monsterinsights_save_settings', 'admin.php?page=monsterinsights_reports#/ai-insights/chat' ); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
// Add Popular Posts menu item. |
94
|
|
|
add_submenu_page( $hook, __( 'Popular Posts:', 'google-analytics-for-wordpress' ), __( 'Popular Posts', 'google-analytics-for-wordpress' ), 'monsterinsights_save_settings', $submenu_base . '#/popular-posts' ); |
95
|
|
|
|
96
|
|
|
// Add submenu under `Insights` main menu for user journey report. |
97
|
|
|
add_submenu_page( $hook, __( 'User Journey:', 'google-analytics-for-wordpress' ), __( 'User Journey', 'google-analytics-for-wordpress' ), 'monsterinsights_view_dashboard', 'admin.php?page=monsterinsights_reports#/user-journey-report' ); |
98
|
|
|
|
99
|
|
|
if ( function_exists( 'aioseo' ) ) { |
100
|
|
|
$seo_url = monsterinsights_aioseo_dashboard_url(); |
101
|
|
|
} else { |
102
|
|
|
$seo_url = $submenu_base . '#/seo'; |
103
|
|
|
} |
104
|
|
|
// then SEO |
105
|
|
|
add_submenu_page($hook, __('SEO', 'google-analytics-for-wordpress'), __('SEO', 'google-analytics-for-wordpress'), 'manage_options', $seo_url); |
106
|
|
|
|
107
|
|
|
// then tools |
108
|
|
|
add_submenu_page($hook, __('Tools:', 'google-analytics-for-wordpress'), __('Tools', 'google-analytics-for-wordpress'), 'manage_options', $submenu_base . '#/tools'); |
109
|
|
|
|
110
|
|
|
// then addons |
111
|
|
|
$network_key = monsterinsights_is_pro_version() ? MonsterInsights()->license->get_network_license_key() : ''; |
112
|
|
|
if (!monsterinsights_is_network_active() || (monsterinsights_is_network_active() && empty($network_key))) { |
113
|
|
|
add_submenu_page($hook, __('Addons:', 'google-analytics-for-wordpress'), '<span style="color:' . monsterinsights_menu_highlight_color() . '"> ' . __('Addons', 'google-analytics-for-wordpress') . '</span>', 'monsterinsights_save_settings', $submenu_base . '#/addons'); |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
add_submenu_page( |
117
|
|
|
$hook, |
118
|
|
|
__('UserFeedback:', 'google-analytics-for-wordpress'), |
119
|
|
|
__('UserFeedback', 'google-analytics-for-wordpress') . $new_indicator, |
120
|
|
|
'manage_options', |
121
|
|
|
$submenu_base . '#/userfeedback' |
122
|
|
|
); |
123
|
|
|
|
124
|
|
|
// then About Us page. |
125
|
|
|
add_submenu_page($hook, __('About Us:', 'google-analytics-for-wordpress'), __('About Us', 'google-analytics-for-wordpress'), 'manage_options', $submenu_base . '#/about'); |
126
|
|
|
|
127
|
|
|
if (!monsterinsights_is_pro_version() && !strstr(plugin_basename(__FILE__), 'dashboard-for')) { |
128
|
|
|
// automated promotion |
129
|
|
|
monsterinsights_automated_menu($hook); |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
add_submenu_page($hook, __('Growth Tools:', 'google-analytics-for-wordpress'), __('Growth Tools', 'google-analytics-for-wordpress'), 'manage_options', $submenu_base . '#/growth-tools'); |
133
|
|
|
|
134
|
|
|
// then Upgrade To Pro. |
135
|
|
|
if (!monsterinsights_is_pro_version()) { |
136
|
|
|
add_submenu_page($hook, __('Upgrade to Pro:', 'google-analytics-for-wordpress'), '<span class="monsterinsights-upgrade-submenu"> ' . __('Upgrade to Pro', 'google-analytics-for-wordpress') . '</span>', 'monsterinsights_save_settings', monsterinsights_get_upgrade_link('admin-menu', 'submenu', "https://www.monsterinsights.com/lite/")); |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
if ( class_exists( 'WooCommerce' ) ) { |
140
|
|
|
// Show the Payments submenu only when WooCommerce is active. |
141
|
|
|
add_submenu_page( |
142
|
|
|
$hook, |
143
|
|
|
__('Payments:', 'google-analytics-for-wordpress'), |
144
|
|
|
__('Payments', 'google-analytics-for-wordpress'), |
145
|
|
|
'manage_options', |
146
|
|
|
$submenu_base . '#/payments' |
147
|
|
|
); |
148
|
|
|
} |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
add_action('admin_menu', 'monsterinsights_admin_menu'); |
152
|
|
|
|
153
|
|
|
|
154
|
|
|
function monsterinsights_automated_menu($hook){ |
155
|
|
|
$display = false; |
|
|
|
|
156
|
|
|
|
157
|
|
|
$now = apply_filters('monsterinsights_automated_promotion_date', wp_date('M d, Y h:i:s a')); |
158
|
|
|
$conditions = [ |
159
|
|
|
[ |
160
|
|
|
'title' => __('Earth Day', 'google-analytics-for-wordpress'), |
161
|
|
|
'start_time' => wp_date('M d, Y h:i:s a', strtotime('Apr 17, 2023')), |
162
|
|
|
'end_time' => wp_date('M d, Y h:i:s a', strtotime('Apr 18, 2023')), |
163
|
|
|
'utm_campaign' => 'lite-promo', |
164
|
|
|
'utm_source' => 'liteplugin', |
165
|
|
|
'utm_medium' => 'earth-day', |
166
|
|
|
], |
167
|
|
|
[ |
168
|
|
|
'title' => __('Cinco De Mayo!', 'google-analytics-for-wordpress'), |
169
|
|
|
'start_time' => wp_date('M d, Y h:i:s a', strtotime('May 01, 2023')), |
170
|
|
|
'end_time' => wp_date('M d, Y h:i:s a', strtotime('May 08, 2023')), |
171
|
|
|
'utm_campaign' => 'lite-promo', |
172
|
|
|
'utm_source' => 'liteplugin', |
173
|
|
|
'utm_medium' => 'cinco-de-mayo', |
174
|
|
|
], |
175
|
|
|
[ |
176
|
|
|
'title' => __('Upgrade to GA4', 'google-analytics-for-wordpress'), |
177
|
|
|
'start_time' => wp_date('M d, Y h:i:s a', strtotime('Jun 01, 2023')), |
178
|
|
|
'end_time' => wp_date('M d, Y h:i:s a', strtotime('July 01, 2023')), |
179
|
|
|
'utm_campaign' => 'lite-promo', |
180
|
|
|
'utm_source' => 'liteplugin', |
181
|
|
|
'utm_medium' => 'goodbye-ga3', |
182
|
|
|
], |
183
|
|
|
[ |
184
|
|
|
'title' => __('Summer Sale', 'google-analytics-for-wordpress'), |
185
|
|
|
'start_time' => wp_date('M d, Y h:i:s a', strtotime('Jul 29, 2023')), |
186
|
|
|
'end_time' => wp_date('M d, Y h:i:s a', strtotime('Aug 05, 2023')), |
187
|
|
|
'utm_campaign' => 'lite-promo', |
188
|
|
|
'utm_source' => 'liteplugin', |
189
|
|
|
'utm_medium' => 'dogdays', |
190
|
|
|
], |
191
|
|
|
[ |
192
|
|
|
'title' => __('Fortune Cookie Day', 'google-analytics-for-wordpress'), |
193
|
|
|
'start_time' => wp_date('M d, Y h:i:s a', strtotime('Sep 12, 2023')), |
194
|
|
|
'end_time' => wp_date('M d, Y h:i:s a', strtotime('Sep 13, 2023')), |
195
|
|
|
'utm_campaign' => 'lite-promo', |
196
|
|
|
'utm_source' => 'liteplugin', |
197
|
|
|
'utm_medium' => 'fortune-cookie', |
198
|
|
|
], |
199
|
|
|
[ |
200
|
|
|
'title' => __('Halloween Sale', 'google-analytics-for-wordpress'), |
201
|
|
|
'start_time' => wp_date('M d, Y h:i:s a', strtotime('Oct 26, 2023')), |
202
|
|
|
'end_time' => wp_date('M d, Y h:i:s a', strtotime('Nov 04, 2023')), |
203
|
|
|
'utm_campaign' => 'lite-promo', |
204
|
|
|
'utm_source' => 'liteplugin', |
205
|
|
|
'utm_medium' => 'halloween', |
206
|
|
|
], |
207
|
|
|
]; |
208
|
|
|
|
209
|
|
|
foreach($conditions as $key => $condition){ |
210
|
|
|
if(strtotime($now) >= strtotime($condition['start_time']) && strtotime($now) <= strtotime($condition['end_time'])){ |
|
|
|
|
211
|
|
|
add_submenu_page($hook, $condition['title'], '<span class="monsterinsights-automated-submenu"> ' . $condition['title'] . '</span>', 'monsterinsights_save_settings', monsterinsights_get_upgrade_link($condition['utm_medium'], $condition['utm_campaign'], "https://www.monsterinsights.com/lite-promo/")); |
212
|
|
|
break; |
213
|
|
|
} |
214
|
|
|
} |
215
|
|
|
} |
216
|
|
|
|
217
|
|
|
/** |
218
|
|
|
* Add this separately so all the Woo menu items are loaded and the position parameter works correctly. |
219
|
|
|
*/ |
220
|
|
|
function monsterinsights_woocommerce_menu_item() |
221
|
|
|
{ |
222
|
|
|
if (class_exists('WooCommerce')) { |
223
|
|
|
// Add "Insights" sub menu item for WooCommerce Analytics menu |
224
|
|
|
if (class_exists('MonsterInsights_eCommerce')) { |
225
|
|
|
add_submenu_page('wc-admin&path=/analytics/overview', __('Insights', 'google-analytics-for-wordpress'), __('Insights', 'google-analytics-for-wordpress'), 'monsterinsights_view_dashboard', admin_url('admin.php?page=monsterinsights_reports#/ecommerce'), '', 2); |
226
|
|
|
} else { |
227
|
|
|
$submenu_base = add_query_arg('page', 'monsterinsights_settings', admin_url('admin.php')); |
228
|
|
|
add_submenu_page('wc-admin&path=/analytics/overview', __('Insights', 'google-analytics-for-wordpress'), __('Insights', 'google-analytics-for-wordpress'), 'manage_options', $submenu_base . '#/woocommerce-insights', '', 1); |
229
|
|
|
} |
230
|
|
|
} |
231
|
|
|
} |
232
|
|
|
add_action('admin_menu', 'monsterinsights_woocommerce_menu_item', 11); |
233
|
|
|
|
234
|
|
|
function monsterinsights_get_menu_hook() |
235
|
|
|
{ |
236
|
|
|
$dashboards_disabled = monsterinsights_get_option('dashboards_disabled', false); |
237
|
|
|
if ($dashboards_disabled || (current_user_can('monsterinsights_save_settings') && !current_user_can('monsterinsights_view_dashboard'))) { |
238
|
|
|
return 'monsterinsights_settings'; |
239
|
|
|
} else { |
240
|
|
|
return 'monsterinsights_reports'; |
241
|
|
|
} |
242
|
|
|
} |
243
|
|
|
|
244
|
|
|
function monsterinsights_network_admin_menu() |
245
|
|
|
{ |
246
|
|
|
// Get the base class object. |
247
|
|
|
$base = MonsterInsights(); |
|
|
|
|
248
|
|
|
|
249
|
|
|
// First, let's see if this is an MS network enabled plugin. If it is, we should load the license |
250
|
|
|
// menu page and the updater on the network panel |
251
|
|
|
if (!function_exists('is_plugin_active_for_network')) { |
252
|
|
|
require_once(ABSPATH . '/wp-admin/includes/plugin.php'); |
253
|
|
|
} |
254
|
|
|
|
255
|
|
|
$plugin = plugin_basename(MONSTERINSIGHTS_PLUGIN_FILE); |
256
|
|
|
if (!is_plugin_active_for_network($plugin)) { |
257
|
|
|
return; |
258
|
|
|
} |
259
|
|
|
|
260
|
|
|
$menu_notification_indicator = MonsterInsights()->notifications->get_menu_count(); |
261
|
|
|
|
262
|
|
|
if ( MonsterInsights()->license->license_expired() ) { |
|
|
|
|
263
|
|
|
$menu_notification_indicator = MonsterInsights()->notifications->get_license_expired_indicator(); |
264
|
|
|
} |
265
|
|
|
|
266
|
|
|
$menu_icon_inline = monsterinsights_get_inline_menu_icon(); |
267
|
|
|
$hook = 'monsterinsights_network'; |
268
|
|
|
$submenu_base = add_query_arg('page', 'monsterinsights_network', network_admin_url('admin.php')); |
269
|
|
|
add_menu_page(__('Network Settings:', 'google-analytics-for-wordpress'), __('Insights', 'google-analytics-for-wordpress') . $menu_notification_indicator, 'monsterinsights_save_settings', 'monsterinsights_network', 'monsterinsights_network_page', $menu_icon_inline, '100.00013467543'); |
|
|
|
|
270
|
|
|
|
271
|
|
|
add_submenu_page($hook, __('Network Settings:', 'google-analytics-for-wordpress'), __('Network Settings', 'google-analytics-for-wordpress'), 'monsterinsights_save_settings', 'monsterinsights_network', 'monsterinsights_network_page'); |
272
|
|
|
|
273
|
|
|
add_submenu_page($hook, __('General Reports:', 'google-analytics-for-wordpress'), __('Reports', 'google-analytics-for-wordpress'), 'monsterinsights_view_dashboard', 'monsterinsights_reports', 'monsterinsights_reports_page'); |
274
|
|
|
|
275
|
|
|
if (function_exists('aioseo')) { |
276
|
|
|
$seo_url = monsterinsights_aioseo_dashboard_url(); |
277
|
|
|
} else { |
278
|
|
|
$seo_url = $submenu_base . '#/seo'; |
279
|
|
|
} |
280
|
|
|
// then seo |
281
|
|
|
add_submenu_page($hook, __('SEO:', 'google-analytics-for-wordpress'), __('SEO', 'google-analytics-for-wordpress'), 'manage_options', $seo_url, 'monsterinsights_seo_page'); |
282
|
|
|
|
283
|
|
|
// then addons |
284
|
|
|
add_submenu_page($hook, __('Addons:', 'google-analytics-for-wordpress'), '<span style="color:' . monsterinsights_menu_highlight_color() . '"> ' . __('Addons', 'google-analytics-for-wordpress') . '</span>', 'monsterinsights_save_settings', $submenu_base . '#/addons'); |
285
|
|
|
|
286
|
|
|
$submenu_base = add_query_arg('page', 'monsterinsights_network', network_admin_url('admin.php')); |
287
|
|
|
|
288
|
|
|
// Add About us page. |
289
|
|
|
add_submenu_page($hook, __('About Us:', 'google-analytics-for-wordpress'), __('About Us', 'google-analytics-for-wordpress'), 'manage_options', $submenu_base . '#/about'); |
290
|
|
|
} |
291
|
|
|
|
292
|
|
|
add_action('network_admin_menu', 'monsterinsights_network_admin_menu', 5); |
293
|
|
|
|
294
|
|
|
/** |
295
|
|
|
* Adds one or more classes to the body tag in the dashboard. |
296
|
|
|
* |
297
|
|
|
* @param String $classes Current body classes. |
298
|
|
|
* |
299
|
|
|
* @return String Altered body classes. |
300
|
|
|
*/ |
301
|
|
|
function monsterinsights_add_admin_body_class($classes) |
302
|
|
|
{ |
303
|
|
|
$screen = function_exists('get_current_screen') ? get_current_screen() : false; |
|
|
|
|
304
|
|
|
if (empty($screen) || empty($screen->id) || strpos($screen->id, 'monsterinsights') === false) { |
305
|
|
|
return $classes; |
306
|
|
|
} |
307
|
|
|
|
308
|
|
|
return "$classes monsterinsights_page "; |
309
|
|
|
} |
310
|
|
|
|
311
|
|
|
add_filter('admin_body_class', 'monsterinsights_add_admin_body_class', 10, 1); |
312
|
|
|
|
313
|
|
|
/** |
314
|
|
|
* Adds one or more classes to the body tag in the dashboard. |
315
|
|
|
* |
316
|
|
|
* @param String $classes Current body classes. |
317
|
|
|
* |
318
|
|
|
* @return String Altered body classes. |
319
|
|
|
*/ |
320
|
|
|
function monsterinsights_add_admin_body_class_tools_page($classes) |
321
|
|
|
{ |
322
|
|
|
$screen = function_exists('get_current_screen') ? get_current_screen() : false; |
|
|
|
|
323
|
|
|
|
324
|
|
|
if (empty($screen) || empty($screen->id) || strpos($screen->id, 'monsterinsights_tools') === false || 'insights_page_monsterinsights_tools' === $screen->id) { |
325
|
|
|
return $classes; |
326
|
|
|
} |
327
|
|
|
|
328
|
|
|
return "$classes insights_page_monsterinsights_tools "; |
329
|
|
|
} |
330
|
|
|
|
331
|
|
|
add_filter('admin_body_class', 'monsterinsights_add_admin_body_class_tools_page', 10, 1); |
332
|
|
|
|
333
|
|
|
/** |
334
|
|
|
* Adds one or more classes to the body tag in the dashboard. |
335
|
|
|
* |
336
|
|
|
* @param String $classes Current body classes. |
337
|
|
|
* |
338
|
|
|
* @return String Altered body classes. |
339
|
|
|
*/ |
340
|
|
|
function monsterinsights_add_admin_body_class_addons_page($classes) |
341
|
|
|
{ |
342
|
|
|
$screen = function_exists('get_current_screen') ? get_current_screen() : false; |
|
|
|
|
343
|
|
|
if (empty($screen) || empty($screen->id) || strpos($screen->id, 'monsterinsights_addons') === false || 'insights_page_monsterinsights_addons' === $screen->id) { |
344
|
|
|
return $classes; |
345
|
|
|
} |
346
|
|
|
|
347
|
|
|
return "$classes insights_page_monsterinsights_addons "; |
348
|
|
|
} |
349
|
|
|
|
350
|
|
|
add_filter('admin_body_class', 'monsterinsights_add_admin_body_class_addons_page', 10, 1); |
351
|
|
|
|
352
|
|
|
/** |
353
|
|
|
* Add a link to the settings page to the plugins list |
354
|
|
|
* |
355
|
|
|
* @param array $links array of links for the plugins, adapted when the current plugin is found. |
356
|
|
|
* |
357
|
|
|
* @return array $links |
358
|
|
|
*/ |
359
|
|
|
function monsterinsights_add_action_links($links) |
360
|
|
|
{ |
361
|
|
|
$docs = '<a title="' . esc_attr__('MonsterInsights Knowledge Base', 'google-analytics-for-wordpress') . '" href="' . monsterinsights_get_url('all-plugins', 'kb-link', "https://www.monsterinsights.com/docs/") . '">' . esc_html__('Documentation', 'google-analytics-for-wordpress') . '</a>'; |
362
|
|
|
array_unshift($links, $docs); |
363
|
|
|
|
364
|
|
|
// If Lite, support goes to forum. If pro, it goes to our website |
365
|
|
|
if (monsterinsights_is_pro_version()) { |
366
|
|
|
$support = '<a title="MonsterInsights Pro Support" href="' . monsterinsights_get_url('all-plugins', 'pro-support-link', "https://www.monsterinsights.com/my-account/support/") . '">' . esc_html__('Support', 'google-analytics-for-wordpress') . '</a>'; |
367
|
|
|
array_unshift($links, $support); |
368
|
|
|
} else { |
369
|
|
|
$support = '<a title="MonsterInsights Lite Support" href="' . monsterinsights_get_url('all-plugins', 'lite-support-link', "https://www.monsterinsights.com/lite-support/") . '">' . esc_html__('Support', 'google-analytics-for-wordpress') . '</a>'; |
370
|
|
|
array_unshift($links, $support); |
371
|
|
|
} |
372
|
|
|
|
373
|
|
|
if (is_network_admin()) { |
374
|
|
|
$settings_link = '<a href="' . esc_url(network_admin_url('admin.php?page=monsterinsights_network')) . '">' . esc_html__('Network Settings', 'google-analytics-for-wordpress') . '</a>'; |
375
|
|
|
} else { |
376
|
|
|
$settings_link = '<a href="' . esc_url(admin_url('admin.php?page=monsterinsights_settings')) . '">' . esc_html__('Settings', 'google-analytics-for-wordpress') . '</a>'; |
377
|
|
|
} |
378
|
|
|
|
379
|
|
|
array_unshift($links, $settings_link); |
380
|
|
|
|
381
|
|
|
// If lite, show a link where they can get pro from |
382
|
|
|
if (!monsterinsights_is_pro_version()) { |
383
|
|
|
$get_pro = '<a title="' . esc_attr__('Get MonsterInsights Pro', 'google-analytics-for-wordpress') . '" target="_blank" rel="noopener" href="' . monsterinsights_get_upgrade_link('all-plugins', 'upgrade-link', "https://www.monsterinsights.com/lite/") . '" style="font-weight:700; color: #1da867;">' . esc_html__('Get MonsterInsights Pro', 'google-analytics-for-wordpress') . '</a>'; |
384
|
|
|
array_unshift($links, $get_pro); |
385
|
|
|
} |
386
|
|
|
|
387
|
|
|
return $links; |
388
|
|
|
} |
389
|
|
|
|
390
|
|
|
add_filter('plugin_action_links_' . plugin_basename(MONSTERINSIGHTS_PLUGIN_FILE), 'monsterinsights_add_action_links'); |
391
|
|
|
add_filter('network_admin_plugin_action_links_' . plugin_basename(MONSTERINSIGHTS_PLUGIN_FILE), 'monsterinsights_add_action_links'); |
392
|
|
|
|
393
|
|
|
/** |
394
|
|
|
* Loads a partial view for the Administration screen |
395
|
|
|
* |
396
|
|
|
* @access public |
397
|
|
|
* |
398
|
|
|
* @param string $template PHP file at includes/admin/partials, excluding file extension |
399
|
|
|
* @param array $data Any data to pass to the view |
400
|
|
|
* |
401
|
|
|
* @return void |
402
|
|
|
* @since 6.0.0 |
403
|
|
|
* |
404
|
|
|
*/ |
405
|
|
|
function monsterinsights_load_admin_partial($template, $data = array()) |
|
|
|
|
406
|
|
|
{ |
407
|
|
|
|
408
|
|
|
if (monsterinsights_is_pro_version()) { |
409
|
|
|
$dir = trailingslashit(plugin_dir_path(MonsterInsights()->file) . 'pro/includes/admin/partials'); |
410
|
|
|
|
411
|
|
|
if (file_exists($dir . $template . '.php')) { |
412
|
|
|
require_once($dir . $template . '.php'); |
413
|
|
|
|
414
|
|
|
return true; |
415
|
|
|
} |
416
|
|
|
} else { |
417
|
|
|
$dir = trailingslashit(plugin_dir_path(MonsterInsights()->file) . 'lite/includes/admin/partials'); |
418
|
|
|
|
419
|
|
|
if (file_exists($dir . $template . '.php')) { |
420
|
|
|
require_once($dir . $template . '.php'); |
421
|
|
|
|
422
|
|
|
return true; |
423
|
|
|
} |
424
|
|
|
} |
425
|
|
|
|
426
|
|
|
$dir = trailingslashit(plugin_dir_path(MonsterInsights()->file) . 'includes/admin/partials'); |
427
|
|
|
|
428
|
|
|
if (file_exists($dir . $template . '.php')) { |
429
|
|
|
require_once($dir . $template . '.php'); |
430
|
|
|
|
431
|
|
|
return true; |
432
|
|
|
} |
433
|
|
|
|
434
|
|
|
return false; |
435
|
|
|
} |
436
|
|
|
|
437
|
|
|
/** |
438
|
|
|
* When user is on a MonsterInsights related admin page, display footer text |
439
|
|
|
* that graciously asks them to rate us. |
440
|
|
|
* |
441
|
|
|
* @param string $text |
442
|
|
|
* |
443
|
|
|
* @return string |
444
|
|
|
* @since 6.0.0 |
445
|
|
|
*/ |
446
|
|
|
function monsterinsights_admin_footer($text) |
447
|
|
|
{ |
448
|
|
|
global $current_screen; |
449
|
|
|
if ( |
450
|
|
|
! empty( $current_screen->id ) |
451
|
|
|
&& strpos( $current_screen->id, 'monsterinsights' ) !== false |
452
|
|
|
&& ! monsterinsights_is_pro_version() |
453
|
|
|
) { |
454
|
|
|
$url = 'https://wordpress.org/support/view/plugin-reviews/google-analytics-for-wordpress?filter=5'; |
455
|
|
|
// Translators: Placeholders add a link to the wordpress.org repository. |
456
|
|
|
$text = sprintf(esc_html__('Please rate %1$sMonsterInsights%2$s on %3$s %4$sWordPress.org%5$s to help us spread the word. Thank you from the MonsterInsights team!', 'google-analytics-for-wordpress'), '<strong>', '</strong>', '<a class="monsterinsights-no-text-decoration" href="' . $url . '" target="_blank" rel="noopener noreferrer"><i class="monstericon-star"></i><i class="monstericon-star"></i><i class="monstericon-star"></i><i class="monstericon-star"></i><i class="monstericon-star"></i></a>', '<a href="' . $url . '" target="_blank" rel="noopener noreferrer">', '</a>'); |
457
|
|
|
} |
458
|
|
|
|
459
|
|
|
return $text; |
460
|
|
|
} |
461
|
|
|
|
462
|
|
|
add_filter('admin_footer_text', 'monsterinsights_admin_footer', 1, 2); |
463
|
|
|
|
464
|
|
|
function monsterinsights_admin_setup_notices() |
465
|
|
|
{ |
466
|
|
|
// Make sure they have the permissions to do something |
467
|
|
|
if (!current_user_can('monsterinsights_save_settings')) { |
468
|
|
|
return; |
469
|
|
|
} |
470
|
|
|
|
471
|
|
|
// Priority: |
472
|
|
|
// 0. UA sunset |
473
|
|
|
// 1. Google Analytics not authenticated |
474
|
|
|
// 2. License key not entered for pro |
475
|
|
|
// 3. License key not valid/okay for pro |
476
|
|
|
// 4. WordPress + PHP min versions |
477
|
|
|
// 5. (old) Optin setting not configured |
478
|
|
|
// 6. Manual UA code |
479
|
|
|
// 7. Automatic updates not configured |
480
|
|
|
// 8. Woo upsell |
481
|
|
|
// 9. EDD upsell |
482
|
|
|
|
483
|
|
|
// 0. UA sunset supported alert |
484
|
|
|
$profile = is_network_admin() ? MonsterInsights()->auth->get_network_analytics_profile() : MonsterInsights()->auth->get_analytics_profile(); |
|
|
|
|
485
|
|
|
|
486
|
|
|
if ( !empty($profile['ua']) && empty($profile['v4']) && !monsterinsights_is_own_admin_page() ) { |
487
|
|
|
$title = __('Urgent: Your Website is Not Tracking Any Google Analytics Data!', 'google-analytics-for-wordpress'); |
488
|
|
|
$message = __('Google Analytics 3 (UA) and support was sunset on July 1, 2023. Your website is currently NOT tracking any analytics. </br>Create or connect a new Google Analytics 4 property immediately to start tracking.', 'google-analytics-for-wordpress'); |
489
|
|
|
|
490
|
|
|
$wizard_url = admin_url('admin.php?page=monsterinsights-onboarding'); |
491
|
|
|
|
492
|
|
|
echo '<div class="notice notice-error is-dismissible monsterinsights-notice" data-notice="monsterinsights_ua_sunset">'; |
493
|
|
|
echo '<p><strong>' . $title . '</strong></p>'; |
494
|
|
|
echo '<p>' . $message . '</p>'; |
495
|
|
|
echo '<p>'; |
496
|
|
|
echo '<a href="https://www.monsterinsights.com/docs/connect-google-analytics/" |
497
|
|
|
target="_blank" rel="noopener noreferrer">' . |
498
|
|
|
__( 'Learn How to Create a GA4 Property', 'google-analytics-for-wordpress' ) . |
499
|
|
|
'</a><br>'; |
500
|
|
|
echo '<a href="' . $wizard_url . '">' . |
501
|
|
|
__( 'Connect a Property', 'google-analytics-for-wordpress' ) . |
502
|
|
|
'</a><br>'; |
503
|
|
|
echo '</p>'; |
504
|
|
|
echo '</div>'; |
505
|
|
|
|
506
|
|
|
return; |
507
|
|
|
} |
508
|
|
|
|
509
|
|
|
$is_plugins_page = 'plugins' === get_current_screen()->id; |
|
|
|
|
510
|
|
|
|
511
|
|
|
// 1. Google Analytics not authenticated |
512
|
|
|
if ( ! is_network_admin() && ! monsterinsights_get_v4_id() && ! defined( 'MONSTERINSIGHTS_DISABLE_TRACKING' ) && ! monsterinsights_is_own_admin_page() ) { |
513
|
|
|
|
514
|
|
|
$submenu_base = is_network_admin() ? add_query_arg( 'page', 'monsterinsights_network', network_admin_url( 'admin.php' ) ) : add_query_arg( 'page', 'monsterinsights_settings', admin_url( 'admin.php' ) ); |
515
|
|
|
$title = esc_html__( 'Please Setup Website Analytics to See Audience Insights', 'google-analytics-for-wordpress' ); |
516
|
|
|
$primary = esc_html__( 'Please Connect Your Website to MonsterInsights', 'google-analytics-for-wordpress' ); |
517
|
|
|
$urlone = is_network_admin() ? network_admin_url( 'admin.php?page=monsterinsights-onboarding' ) : admin_url( 'admin.php?page=monsterinsights-onboarding' ); |
518
|
|
|
$secondary = esc_html__( 'Learn More', 'google-analytics-for-wordpress' ); |
519
|
|
|
$urltwo = $submenu_base . '#/about/getting-started'; |
520
|
|
|
$message = esc_html__( 'MonsterInsights, the #1 WordPress Analytics Plugin, helps you easily connect your website to Google Analytics, so that you can see how people find and use your website. Over 3 million website owners use MonsterInsights to see the stats that matter and grow their business.', 'google-analytics-for-wordpress' ); |
521
|
|
|
echo '<div class="notice notice-info"><p style="font-weight:700">' . $title . '</p><p>' . $message . '</p><p><a href="' . $urlone . '" class="button-primary">' . $primary . '</a> <a href="' . $urltwo . '" class="button-secondary">' . $secondary . '</a></p></div>'; |
522
|
|
|
|
523
|
|
|
return; |
524
|
|
|
} |
525
|
|
|
|
526
|
|
|
// 2. License key not entered for pro |
527
|
|
|
$key = monsterinsights_is_pro_version() ? MonsterInsights()->license->get_license_key() : ''; |
|
|
|
|
528
|
|
|
if (monsterinsights_is_pro_version() && empty($key)) { |
529
|
|
|
$page = is_network_admin() ? network_admin_url('admin.php?page=monsterinsights_network') : admin_url('admin.php?page=monsterinsights_settings'); |
530
|
|
|
// Translators: Adds a link to retrieve the license. |
531
|
|
|
$message = sprintf(esc_html__('Warning: No valid license key has been entered for MonsterInsights. You are currently not getting updates, and are not able to view reports. %1$sPlease click here to enter your license key and begin receiving updates and reports.%2$s', 'google-analytics-for-wordpress'), '<a href="' . esc_url($page) . '">', '</a>'); |
532
|
|
|
echo '<div class="error"><p>' . $message . '</p></div>'; // phpcs:ignore |
533
|
|
|
|
534
|
|
|
return; |
535
|
|
|
} |
536
|
|
|
|
537
|
|
|
// 3. License key not valid/okay for pro |
538
|
|
|
if (monsterinsights_is_pro_version()) { |
539
|
|
|
$message = ''; |
540
|
|
|
if (MonsterInsights()->license->get_site_license_key()) { |
541
|
|
|
if (MonsterInsights()->license->site_license_expired()) { |
542
|
|
|
// Translators: Adds a link to the license renewal. |
543
|
|
|
$message = sprintf(esc_html__('Your license key for MonsterInsights has expired. %1$sPlease click here to renew your license key.%2$s', 'google-analytics-for-wordpress'), '<a href="' . monsterinsights_get_url('admin-notices', 'expired-license', "https://www.monsterinsights.com/login/") . '" target="_blank" rel="noopener noreferrer" referrer="no-referrer">', '</a>'); |
544
|
|
|
} else if (MonsterInsights()->license->site_license_disabled()) { |
545
|
|
|
$message = esc_html__('Your license key for MonsterInsights has been disabled. Please use a different key.', 'google-analytics-for-wordpress'); |
546
|
|
|
} else if (MonsterInsights()->license->site_license_invalid()) { |
547
|
|
|
$message = esc_html__('Your license key for MonsterInsights is invalid. The key no longer exists or the user associated with the key has been deleted. Please use a different key.', 'google-analytics-for-wordpress'); |
548
|
|
|
} |
549
|
|
|
} else if (MonsterInsights()->license->get_network_license_key()) { |
550
|
|
|
if (MonsterInsights()->license->network_license_expired()) { |
551
|
|
|
// Translators: Adds a link to renew license. |
552
|
|
|
$message = sprintf(esc_html__('Your network license key for MonsterInsights has expired. %1$sPlease click here to renew your license key.%2$s', 'google-analytics-for-wordpress'), '<a href="' . monsterinsights_get_url('admin-notices', 'expired-license', "https://www.monsterinsights.com/login/") . '" target="_blank" rel="noopener noreferrer" referrer="no-referrer">', '</a>'); |
553
|
|
|
} else if (MonsterInsights()->license->network_license_disabled()) { |
554
|
|
|
$message = esc_html__('Your network license key for MonsterInsights has been disabled. Please use a different key.', 'google-analytics-for-wordpress'); |
555
|
|
|
} else if (MonsterInsights()->license->network_license_invalid()) { |
556
|
|
|
$message = esc_html__('Your network license key for MonsterInsights is invalid. The key no longer exists or the user associated with the key has been deleted. Please use a different key.', 'google-analytics-for-wordpress'); |
557
|
|
|
} |
558
|
|
|
} |
559
|
|
|
if (!empty($message)) { |
560
|
|
|
echo '<div class="error"><p>' . $message . '</p></div>'; // phpcs:ignore |
561
|
|
|
|
562
|
|
|
return; |
563
|
|
|
} |
564
|
|
|
} |
565
|
|
|
|
566
|
|
|
// 4. Notices for PHP/WP version deprecations |
567
|
|
|
if (current_user_can('update_core')) { |
568
|
|
|
global $wp_version; |
569
|
|
|
|
570
|
|
|
$compatible_php_version = apply_filters('monsterinsights_compatible_php_version', false); |
|
|
|
|
571
|
|
|
$compatible_wp_version = apply_filters('monsterinsights_compatible_wp_version', false); |
|
|
|
|
572
|
|
|
|
573
|
|
|
$url = monsterinsights_get_url('global-notice', 'settings-page', 'https://www.monsterinsights.com/docs/update-php/'); |
574
|
|
|
|
575
|
|
|
$message = false; |
576
|
|
|
if (version_compare(phpversion(), $compatible_php_version['required'], '<')) { |
577
|
|
|
// Translators: Placeholders add the PHP version, a link to the MonsterInsights blog and a line break. |
578
|
|
|
$message = sprintf(esc_html__('Your site is running an outdated, insecure version of PHP (%1$s), which could be putting your site at risk for being hacked.%4$sWordPress stopped supporting your PHP version in April, 2019.%4$sUpdating PHP only takes a few minutes and will make your website significantly faster and more secure.%4$s%2$sLearn more about updating PHP%3$s', 'google-analytics-for-wordpress'), phpversion(), '<a href="' . $url . '" target="_blank">', '</a>', '<br>'); |
579
|
|
|
} else if (version_compare(phpversion(), $compatible_php_version['warning'], '<')) { |
580
|
|
|
// Translators: Placeholders add the PHP version, a link to the MonsterInsights blog and a line break. |
581
|
|
|
$message = sprintf(esc_html__('Your site is running an outdated, insecure version of PHP (%1$s), which could be putting your site at risk for being hacked.%4$sWordPress stopped supporting your PHP version in November, 2019.%4$sUpdating PHP only takes a few minutes and will make your website significantly faster and more secure.%4$s%2$sLearn more about updating PHP%3$s', 'google-analytics-for-wordpress'), phpversion(), '<a href="' . $url . '" target="_blank">', '</a>', '<br>'); |
582
|
|
|
} else if (version_compare(phpversion(), $compatible_php_version['recommended'], '<')) { |
583
|
|
|
// Translators: Placeholders add the PHP version, a link to the MonsterInsights blog and a line break. |
584
|
|
|
$message = sprintf(esc_html__('Your site is running an outdated, insecure version of PHP (%1$s), which could be putting your site at risk for being hacked.%4$sWordPress is working towards discontinuing support for your PHP version.%4$sUpdating PHP only takes a few minutes and will make your website significantly faster and more secure.%4$s%2$sLearn more about updating PHP%3$s', 'google-analytics-for-wordpress'), phpversion(), '<a href="' . $url . '" target="_blank">', '</a>', '<br>'); |
585
|
|
|
} |
586
|
|
|
|
587
|
|
|
if ($message) { |
588
|
|
|
echo '<div class="error"><p>' . wp_kses($message, [ |
589
|
|
|
'br' => array(), |
590
|
|
|
'b' => array(), |
591
|
|
|
'strong' => array(), |
592
|
|
|
'i' => array(), |
593
|
|
|
'a' => array( |
594
|
|
|
'href' => array(), |
595
|
|
|
'target' => array(), |
596
|
|
|
'title' => array(), |
597
|
|
|
), |
598
|
|
|
]) . '</p></div>'; |
599
|
|
|
return; |
600
|
|
|
} |
601
|
|
|
|
602
|
|
|
// WordPress 4.9 |
603
|
|
|
/* else if ( version_compare( $wp_version, '5.0', '<' ) ) { |
604
|
|
|
$url = monsterinsights_get_url( 'global-notice', 'settings-page', 'https://www.monsterinsights.com/docs/update-wordpress/' ); |
605
|
|
|
// Translators: Placeholders add the current WordPress version and links to the MonsterInsights blog |
606
|
|
|
$message = sprintf( esc_html__( 'Your site is running an outdated version of WordPress (%1$s).%4$sMonsterInsights will stop supporting WordPress versions lower than 5.0 in 2021.%4$sUpdating WordPress takes just a few minutes and will also solve many bugs that exist in your WordPress install.%4$s%2$sLearn more about updating WordPress%3$s', 'google-analytics-for-wordpress' ), $wp_version, '<a href="' . $url . '" target="_blank">', '</a>', '<br>' ); |
607
|
|
|
echo '<div class="error"><p>'. $message.'</p></div>'; |
608
|
|
|
return; |
609
|
|
|
} */ |
610
|
|
|
// PHP 5.4/5.5 |
611
|
|
|
// else if ( version_compare( phpversion(), '5.6', '<' ) ) { |
612
|
|
|
// $url = monsterinsights_get_url( 'global-notice', 'settings-page', 'https://www.monsterinsights.com/docs/update-php/' ); |
613
|
|
|
// $message = sprintf( esc_html__( 'Your site is running an outdated, insecure version of PHP (%1$s), which could be putting your site at risk for being hacked.%4$sWordPress will stop supporting your PHP version in April, 2019.%4$sUpdating PHP only takes a few minutes and will make your website significantly faster and more secure.%4$s%2$sLearn more about updating PHP%3$s', 'google-analytics-for-wordpress' ), phpversion(), '<a href="' . $url . '" target="_blank">', '</a>', '<br>' ); |
614
|
|
|
// echo '<div class="error"><p>'. $message.'</p></div>'; |
615
|
|
|
// return; |
616
|
|
|
// } |
617
|
|
|
// // WordPress 4.6 - 4.8 |
618
|
|
|
// else if ( version_compare( $wp_version, '4.9', '<' ) ) { |
619
|
|
|
// $url = monsterinsights_get_url( 'global-notice', 'settings-page', 'https://www.monsterinsights.com/docs/update-wordpress/' ); |
620
|
|
|
// $message = sprintf( esc_html__( 'Your site is running an outdated version of WordPress (%1$s).%4$sMonsterInsights will stop supporting WordPress versions lower than 4.9 in October, 2019.%4$sUpdating WordPress takes just a few minutes and will also solve many bugs that exist in your WordPress install.%4$s%2$sLearn more about updating WordPress%3$s', 'google-analytics-for-wordpress' ), $wp_version, '<a href="' . $url . '" target="_blank">', '</a>', '<br>' ); |
621
|
|
|
// echo '<div class="error"><p>'. $message.'</p></div>'; |
622
|
|
|
// return; |
623
|
|
|
// } |
624
|
|
|
|
625
|
|
|
} |
626
|
|
|
|
627
|
|
|
// 5. Optin setting not configured |
628
|
|
|
// if ( ! is_network_admin() ) { |
629
|
|
|
// if ( ! get_option( 'monsterinsights_tracking_notice' ) ) { |
630
|
|
|
// if ( ! monsterinsights_get_option( 'anonymous_data', false ) ) { |
631
|
|
|
// if ( ! monsterinsights_is_dev_url( network_site_url( '/' ) ) ) { |
632
|
|
|
// if ( monsterinsights_is_pro_version() ) { |
633
|
|
|
// monsterinsights_update_option( 'anonymous_data', 1 ); |
634
|
|
|
// return; |
635
|
|
|
// } |
636
|
|
|
// $optin_url = add_query_arg( 'mi_action', 'opt_into_tracking' ); |
637
|
|
|
// $optout_url = add_query_arg( 'mi_action', 'opt_out_of_tracking' ); |
638
|
|
|
// echo '<div class="updated"><p>'; |
639
|
|
|
// echo esc_html__( 'Allow MonsterInsights to track plugin usage? Opt-in to tracking and our newsletter to stay informed of the latest changes to MonsterInsights and help us ensure compatibility.', 'google-analytics-for-wordpress' ); |
640
|
|
|
// echo ' <a href="' . esc_url( $optin_url ) . '" class="button-secondary">' . __( 'Allow', 'google-analytics-for-wordpress' ) . '</a>'; |
641
|
|
|
// echo ' <a href="' . esc_url( $optout_url ) . '" class="button-secondary">' . __( 'Do not allow', 'google-analytics-for-wordpress' ) . '</a>'; |
642
|
|
|
// echo '</p></div>'; |
643
|
|
|
// return; |
644
|
|
|
// } else { |
645
|
|
|
// // is testing site |
646
|
|
|
// update_option( 'monsterinsights_tracking_notice', '1' ); |
647
|
|
|
// } |
648
|
|
|
// } |
649
|
|
|
// } |
650
|
|
|
// } |
651
|
|
|
|
652
|
|
|
$notices = get_option('monsterinsights_notices'); |
653
|
|
|
if (!is_array($notices)) { |
654
|
|
|
$notices = array(); |
655
|
|
|
} |
656
|
|
|
|
657
|
|
|
// 6. Authenticate, not manual |
658
|
|
|
$authed = MonsterInsights()->auth->is_authed() || MonsterInsights()->auth->is_network_authed(); |
659
|
|
|
$url = is_network_admin() ? network_admin_url('admin.php?page=monsterinsights_network') : admin_url('admin.php?page=monsterinsights_settings'); |
660
|
|
|
$tracking_code = monsterinsights_get_v4_id_to_output(); |
661
|
|
|
// Translators: Placeholders add links to the settings panel. |
662
|
|
|
$manual_text = sprintf(esc_html__('Important: You are currently using manual GA4 Measurement ID output. We highly recommend %1$sauthenticating with MonsterInsights%2$s so that you can access our new reporting area and take advantage of new MonsterInsights features.', 'google-analytics-for-wordpress'), '<a href="' . $url . '">', '</a>'); |
663
|
|
|
$migrated = monsterinsights_get_option('gadwp_migrated', 0); |
664
|
|
|
if ($migrated > 0) { |
665
|
|
|
$url = admin_url('admin.php?page=monsterinsights-getting-started&monsterinsights-migration=1'); |
666
|
|
|
// Translators: Placeholders add links to the settings panel. |
667
|
|
|
$text = esc_html__('Click %1$shere%2$s to reauthenticate to be able to access reports. For more information why this is required, see our %3$sblog post%4$s.', 'google-analytics-for-wordpress'); |
668
|
|
|
$manual_text = sprintf($text, '<a href="' . esc_url($url) . '">', '</a>', '<a href="' . monsterinsights_get_url('notice', 'manual-ua', 'https://www.exactmetrics.com/why-did-we-implement-the-new-google-analytics-authentication-flow-challenges-explained/') . '" target="_blank">', '</a>'); |
669
|
|
|
} |
670
|
|
|
|
671
|
|
|
if (empty($authed) && !isset($notices['monsterinsights_auth_not_manual']) && !empty($tracking_code)) { |
672
|
|
|
echo '<div class="notice notice-info is-dismissible monsterinsights-notice" data-notice="monsterinsights_auth_not_manual">'; |
673
|
|
|
echo '<p>'; |
674
|
|
|
echo $manual_text; // phpcs:ignore |
675
|
|
|
echo '</p>'; |
676
|
|
|
echo '</div>'; |
677
|
|
|
|
678
|
|
|
return; |
679
|
|
|
} |
680
|
|
|
|
681
|
|
|
// 7. Automatic updates not configured |
682
|
|
|
// if ( ! is_network_admin() ) { |
683
|
|
|
// $updates = monsterinsights_get_option( 'automatic_updates', false ); |
684
|
|
|
// $url = admin_url( 'admin.php?page=monsterinsights_settings' ); |
685
|
|
|
|
686
|
|
|
// if ( empty( $updates) && ! isset( $notices['monsterinsights_automatic_updates' ] ) ) { |
687
|
|
|
// echo '<div class="notice notice-info is-dismissible monsterinsights-notice" data-notice="monsterinsights_automatic_updates">'; |
688
|
|
|
// echo '<p>'; |
689
|
|
|
// echo sprintf( esc_html__( 'Important: Please %1$sconfigure the Automatic Updates Settings%2$s in MonsterInsights.', 'google-analytics-for-wordpress' ), '<a href="' . $url .'">', '</a>' ); |
690
|
|
|
// echo '</p>'; |
691
|
|
|
// echo '</div>'; |
692
|
|
|
// return; |
693
|
|
|
// } |
694
|
|
|
// } |
695
|
|
|
|
696
|
|
|
// 8. WooUpsell |
697
|
|
|
if (!monsterinsights_is_pro_version() && class_exists('WooCommerce') && $is_plugins_page) { |
698
|
|
|
if (!isset($notices['monsterinsights_woocommerce_tracking_available'])) { |
699
|
|
|
$woo_notice_template = '<div class="notice notice-success is-dismissible monsterinsights-notice monsterinsights-wooedd-upsell-row" data-notice="monsterinsights_woocommerce_tracking_available"> |
700
|
|
|
%1$s |
701
|
|
|
<div class="monsterinsights-wooedd-upsell-left"> |
702
|
|
|
<p><strong>%2$s</strong></p> |
703
|
|
|
<p>%3$s</p> |
704
|
|
|
<p>%4$s</p> |
705
|
|
|
<p>%5$s</p> |
706
|
|
|
<p>%6$s</p> |
707
|
|
|
%7$s |
708
|
|
|
%8$s |
709
|
|
|
</div> |
710
|
|
|
</div>'; |
711
|
|
|
|
712
|
|
|
$woo_notice_button = sprintf( |
713
|
|
|
// Translators: Placeholders add a link to the MonsterInsights website. |
714
|
|
|
esc_html__('%1$sGet MonsterInsights Pro%2$s', 'google-analytics-for-wordpress'), |
715
|
|
|
'<a class="button button-primary button-hero" target="_blank" href="' . esc_url(monsterinsights_get_upgrade_link('admin-notices', 'woocommerce-upgrade')) . '">', |
716
|
|
|
' »</a>' |
717
|
|
|
); |
718
|
|
|
|
719
|
|
|
$woo_notice_offer = sprintf( |
720
|
|
|
'<div class="monsterinsights-wooedd-upsell-offer">%1$s</div>', |
721
|
|
|
__('Save <span>50%</span> Off MonsterInsights Pro', 'google-analytics-for-wordpress') |
722
|
|
|
); |
723
|
|
|
|
724
|
|
|
$woo_notice_bg = esc_url(trailingslashit(MONSTERINSIGHTS_PLUGIN_URL)) . 'assets/images/upsell/monsterinsights-woo-edd-upsell.svg'; |
725
|
|
|
$woo_notice_offer_icon = esc_url(trailingslashit(MONSTERINSIGHTS_PLUGIN_URL)) . 'assets/images/upsell/woo-offer-icon.svg'; |
726
|
|
|
$woo_notice_style = "<style>.monsterinsights-wooedd-upsell-left .button-hero,.monsterinsights-wooedd-upsell-offer{width:270px;margin-bottom:20px;text-align:center}.monsterinsights-wooedd-upsell-row{display:flex;background-image:url($woo_notice_bg);background-repeat:no-repeat;background-position:96% bottom}.monsterinsights-wooedd-upsell-left{margin-left:20px}.monsterinsights-wooedd-upsell-offer{background:#fafeb0;padding:6px 0;position:relative;font-weight:700;font-size:15px;line-height:28px}.monsterinsights-wooedd-upsell-offer span{color:#338eef}.monsterinsights-wooedd-upsell-offer:before{content:url('$woo_notice_offer_icon');position:absolute;left:-23px;bottom:-30px}@media (max-width:1300px){.monsterinsights-wooedd-upsell-row{background-size:60%}}@media (max-width:900px){.monsterinsights-wooedd-upsell-row{background-image:none}.monsterinsights-wooedd-upsell-left,.monsterinsights-wooedd-upsell-left .button-hero,.monsterinsights-wooedd-upsell-offer{width:100%}}</style>"; |
727
|
|
|
|
728
|
|
|
echo sprintf( |
729
|
|
|
$woo_notice_template, |
730
|
|
|
$woo_notice_style, |
731
|
|
|
__('Add eCommerce Analytics to your WooCommerce Store', 'google-analytics-for-wordpress'), |
732
|
|
|
__('Unlock all of our advanced eCommerce features specifically designed to help your store make more money..', 'google-analytics-for-wordpress'), |
733
|
|
|
__('MonsterInsights Pro users instantly gain access to valuable insights such as average order value, conversion rates, as well as marketing performance with UTM tracking.', 'google-analytics-for-wordpress'), |
734
|
|
|
__('And by upgrading, Pro users also get enhanced tracking for Forms, User Journeys, PPC Pixels, Custom UserID tracking, SEO Reports, and much more.', 'google-analytics-for-wordpress'), |
735
|
|
|
__('Start making better data-driven decisions today!', 'google-analytics-for-wordpress'), |
736
|
|
|
$woo_notice_offer, |
737
|
|
|
$woo_notice_button |
738
|
|
|
); |
739
|
|
|
return; |
740
|
|
|
} |
741
|
|
|
} |
742
|
|
|
|
743
|
|
|
// 9. EDDUpsell |
744
|
|
|
if (!monsterinsights_is_pro_version() && class_exists('Easy_Digital_Downloads') && $is_plugins_page) { |
745
|
|
|
if (!isset($notices['monsterinsights_edd_tracking_available'])) { |
746
|
|
|
echo '<div class="notice notice-success is-dismissible monsterinsights-notice monsterinsights-wooedd-upsell-row" data-notice="monsterinsights_edd_tracking_available">'; |
747
|
|
|
echo '<div class="monsterinsights-wooedd-upsell-left">'; |
748
|
|
|
echo '<p><strong>'; |
749
|
|
|
echo esc_html('Enhanced Ecommerce Analytics for Your Easy Digital Downloads Store', 'google-analytics-for-wordpress'); |
|
|
|
|
750
|
|
|
echo '</strong></p>'; |
751
|
|
|
echo '<img class="monsterinsights-wooedd-upsell-image monsterinsights-wooedd-upsell-image-small" src="' . esc_url(trailingslashit(MONSTERINSIGHTS_PLUGIN_URL)) . 'assets/images/upsell/woo-edd-upsell.png">'; |
752
|
|
|
echo '<p>'; |
753
|
|
|
echo esc_html('MonsterInsights Pro gives you detailed stats and insights about your customers.', 'google-analytics-for-wordpress'); |
754
|
|
|
echo '</p>'; |
755
|
|
|
echo '<p>'; |
756
|
|
|
echo esc_html('This helps you make data-driven decisions about your content, and marketing strategy so you can increase your website traffic, leads, and sales.', 'google-analytics-for-wordpress'); |
757
|
|
|
echo '</p>'; |
758
|
|
|
echo '<p>'; |
759
|
|
|
echo esc_html('Pro customers also get Form Tracking, Custom Dimensions Tracking, UserID Tracking and much more.', 'google-analytics-for-wordpress'); |
760
|
|
|
echo '</p>'; |
761
|
|
|
echo '<p>'; |
762
|
|
|
echo esc_html('Start making data-driven decisions to grow your business.', 'google-analytics-for-wordpress'); |
763
|
|
|
echo '</p>'; |
764
|
|
|
echo sprintf(esc_html__('%1$sGet MonsterInsights Pro%2$s', 'google-analytics-for-wordpress'), '<a class="button button-primary button-hero" target="_blank" href="' . esc_url(monsterinsights_get_upgrade_link('admin-notices', 'edd-upgrade')) . '">', ' »</a>'); |
765
|
|
|
echo '</p>'; |
766
|
|
|
echo '</div><div class="monsterinsights-wooedd-upsell-right">'; |
767
|
|
|
echo '<img class="monsterinsights-wooedd-upsell-image monsterinsights-wooedd-upsell-image-large" src="' . esc_url(trailingslashit(MONSTERINSIGHTS_PLUGIN_URL)) . 'assets/images/upsell/woo-edd-upsell.png">'; |
768
|
|
|
echo '</div>'; |
769
|
|
|
echo '</div>'; |
770
|
|
|
|
771
|
|
|
return; |
772
|
|
|
} |
773
|
|
|
} |
774
|
|
|
|
775
|
|
|
|
776
|
|
|
if (isset($notices['monsterinsights_cross_domains_extracted']) && false === $notices['monsterinsights_cross_domains_extracted']) { |
777
|
|
|
$page = is_network_admin() ? network_admin_url('admin.php?page=monsterinsights_network') : admin_url('admin.php?page=monsterinsights_settings'); |
778
|
|
|
$page = $page . '#/advanced'; |
779
|
|
|
// Translators: Adds a link to the settings panel. |
780
|
|
|
$message = sprintf(esc_html__('Warning: MonsterInsights found cross-domain settings in the custom code field and converted them to the new settings structure. %1$sPlease click here to review and remove the code no longer needed.%2$s', 'google-analytics-for-wordpress'), '<a href="' . esc_url($page) . '">', '</a>'); |
781
|
|
|
echo '<div class="notice notice-success is-dismissible monsterinsights-notice" data-notice="monsterinsights_cross_domains_extracted"><p>' . $message . '</p></div>'; // phpcs:ignore |
782
|
|
|
|
783
|
|
|
return; |
784
|
|
|
} |
785
|
|
|
} |
786
|
|
|
|
787
|
|
|
add_action('admin_notices', 'monsterinsights_admin_setup_notices'); |
788
|
|
|
add_action('network_admin_notices', 'monsterinsights_admin_setup_notices'); |
789
|
|
|
|
790
|
|
|
|
791
|
|
|
// AM Notices |
792
|
|
|
function monsterinsights_am_notice_optout($super_admin) |
793
|
|
|
{ |
794
|
|
|
if (monsterinsights_get_option('hide_am_notices', false) || monsterinsights_get_option('network_hide_am_notices', false)) { |
795
|
|
|
return false; |
796
|
|
|
} |
797
|
|
|
|
798
|
|
|
return $super_admin; |
799
|
|
|
} |
800
|
|
|
|
801
|
|
|
add_filter("am_notifications_display", 'monsterinsights_am_notice_optout', 10, 1); |
802
|
|
|
|
803
|
|
|
/** |
804
|
|
|
* Inline critical css for the menu to prevent breaking the layout when our scripts get blocked by browsers. |
805
|
|
|
*/ |
806
|
|
|
function monsterinsights_admin_menu_inline_styles() |
807
|
|
|
{ |
808
|
|
|
?> |
809
|
|
|
<style> |
810
|
|
|
#toplevel_page_monsterinsights_reports .wp-menu-image img, |
811
|
|
|
#toplevel_page_monsterinsights_settings .wp-menu-image img, |
812
|
|
|
#toplevel_page_monsterinsights_network .wp-menu-image img { |
813
|
|
|
width: 18px; |
814
|
|
|
height: auto; |
815
|
|
|
padding-top: 7px; |
816
|
|
|
} |
817
|
|
|
|
818
|
|
|
#toplevel_page_monsterinsights_reports .wp-submenu li a { |
819
|
|
|
display: flex; |
820
|
|
|
align-items: center; |
821
|
|
|
} |
822
|
|
|
|
823
|
|
|
#toplevel_page_monsterinsights_reports .wp-submenu .monsterinsights-sidebar-icon { |
824
|
|
|
padding-right: 6px; |
825
|
|
|
} |
826
|
|
|
</style> |
827
|
|
|
<?php |
828
|
|
|
} |
829
|
|
|
|
830
|
|
|
add_action('admin_head', 'monsterinsights_admin_menu_inline_styles', 300); |
831
|
|
|
|
832
|
|
|
/** |
833
|
|
|
* Display notice in admin when measurement protocol is left blank |
834
|
|
|
*/ |
835
|
|
|
function monsterinsights_empty_measurement_protocol_token() |
836
|
|
|
{ |
837
|
|
|
if (!class_exists('MonsterInsights_eCommerce') && !class_exists('MonsterInsights_Forms')) { |
838
|
|
|
return; |
839
|
|
|
} |
840
|
|
|
|
841
|
|
|
$page = is_network_admin() |
|
|
|
|
842
|
|
|
? network_admin_url('admin.php?page=monsterinsights_network') |
843
|
|
|
: admin_url('admin.php?page=monsterinsights_settings'); |
844
|
|
|
|
845
|
|
|
$api_secret = is_network_admin() |
846
|
|
|
? MonsterInsights()->auth->get_network_measurement_protocol_secret() |
|
|
|
|
847
|
|
|
: MonsterInsights()->auth->get_measurement_protocol_secret(); |
848
|
|
|
|
849
|
|
|
$current_code = monsterinsights_get_v4_id_to_output(); |
850
|
|
|
|
851
|
|
|
if (empty($current_code) || !empty($api_secret)) { |
852
|
|
|
return; |
853
|
|
|
} |
854
|
|
|
|
855
|
|
|
$message = sprintf( |
856
|
|
|
/* translators: Placeholders add a link to an article. */ |
857
|
|
|
esc_html__( |
858
|
|
|
'Your Measurement Protocol API Secret is currently left blank. To see more advanced analytics please enter a Measurement API Secret. %1$sLearn how to find your API Secret%2$s.', |
859
|
|
|
'google-analytics-for-wordpress' |
860
|
|
|
), |
861
|
|
|
'<a target="_blank" href="' . monsterinsights_get_url('notice', 'empty-measurement-protocol-secret', 'https://www.monsterinsights.com/docs/how-to-create-your-measurement-protocol-api-secret-in-ga4/') . '">', |
862
|
|
|
'</a>' |
863
|
|
|
); |
864
|
|
|
echo '<div class="error"><p>' . $message . '</p></div>'; // phpcs:ignore |
865
|
|
|
} |
866
|
|
|
|
867
|
|
|
add_action( 'admin_notices', 'monsterinsights_empty_measurement_protocol_token' ); |
868
|
|
|
add_action( 'network_admin_notices', 'monsterinsights_admin_setup_notices' ); |
869
|
|
|
|
870
|
|
|
/** |
871
|
|
|
* Check if the plugin is MI Lite. |
872
|
|
|
* |
873
|
|
|
* @return bool |
874
|
|
|
*/ |
875
|
|
|
function check_is_it_monsterinsights_lite() { |
876
|
|
|
return 'googleanalytics.php' == basename( MONSTERINSIGHTS_PLUGIN_FILE ); |
877
|
|
|
} |
878
|
|
|
|
879
|
|
|
/** |
880
|
|
|
* Add EEA Compliance file. |
881
|
|
|
*/ |
882
|
|
|
require_once __DIR__ . '/eea-compliance.php'; |
883
|
|
|
|