Google Analytics Opt-Out - Version 2.0.2

Version Description

  • Make plugin compatible with the latest version of MonsterInsights.
  • Remove/deprecate all functions that have been used when the old Yoast Analytics plugin was active.
  • Remove the 'gaoop_stop_head' filter as it's no longer needed.
  • Display the options submenu under "Insights" menu.
Download this release

Release Info

Developer wp-buddy
Plugin Icon 128x128 Google Analytics Opt-Out
Version 2.0.2
Comparing to
See all releases

Code changes from version 2.0.1 to 2.0.2

google-analytics-opt-out.php CHANGED
@@ -3,7 +3,7 @@
3
  Plugin Name: Google Analytics Opt-Out
4
  Plugin URI: https://wp-buddy.com/products/plugins/google-analytics-opt-out
5
  Description: Provides an Opt-Out functionality for Google Analytics
6
- Version: 2.0.1
7
  Author: WP-Buddy
8
  Author URI: https://wp-buddy.com
9
  License: GPL2
@@ -33,6 +33,7 @@ if ( ! defined( 'ABSPATH' ) ) {
33
  }
34
 
35
  add_action( 'init', function () {
 
36
  # this is still needed @see https://wordpress.org/support/topic/this-plugin-is-not-properly-prepared-for-localization/#post-6885466
37
  load_plugin_textdomain( 'google-analytics-opt-out' );
38
  } );
@@ -54,6 +55,7 @@ require_once GAOOP_PATH . 'inc/frontend.php';
54
 
55
 
56
  function gaoop_activation() {
 
57
  if ( ! function_exists( 'is_plugin_active' ) ) {
58
  include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
59
  }
3
  Plugin Name: Google Analytics Opt-Out
4
  Plugin URI: https://wp-buddy.com/products/plugins/google-analytics-opt-out
5
  Description: Provides an Opt-Out functionality for Google Analytics
6
+ Version: 2.0.2
7
  Author: WP-Buddy
8
  Author URI: https://wp-buddy.com
9
  License: GPL2
33
  }
34
 
35
  add_action( 'init', function () {
36
+
37
  # this is still needed @see https://wordpress.org/support/topic/this-plugin-is-not-properly-prepared-for-localization/#post-6885466
38
  load_plugin_textdomain( 'google-analytics-opt-out' );
39
  } );
55
 
56
 
57
  function gaoop_activation() {
58
+
59
  if ( ! function_exists( 'is_plugin_active' ) ) {
60
  include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
61
  }
inc/admin.php CHANGED
@@ -1,6 +1,7 @@
1
  <?php
2
 
3
  function gaoop_admin_notice() {
 
4
  $code = gaoop_get_ua_code();
5
  if ( ! empty( $code ) ) {
6
  return;
@@ -27,6 +28,7 @@ add_action( 'admin_notices', 'gaoop_admin_notice' );
27
  * @return array
28
  */
29
  function gaoop_plugin_action_links( $links ) {
 
30
  $links[] = '<a href="' . admin_url( 'options-general.php?page=gaoo-options' ) . '">' . __( 'Settings', 'google-analytics-opt-out' ) . '</a>';
31
  $links[] = '<a target="_blank" href="http://wp-buddy.com">' . __( 'More by WP-Buddy', 'google-analytics-opt-out' ) . '</a>';
32
 
@@ -43,6 +45,7 @@ add_filter( 'plugin_action_links_' . plugin_basename( GAOOP_FILE ), 'gaoop_plugi
43
  * @return void
44
  */
45
  function gaoop_editor_button() {
 
46
  if ( get_user_option( 'rich_editing' ) == true ) {
47
  add_filter( "mce_external_plugins", 'gaoop_add_mce_plugin' );
48
  add_filter( 'mce_buttons', 'gaoop_register_mce_buttons' );
@@ -61,6 +64,7 @@ add_action( 'init', 'gaoop_editor_button' );
61
  * @return array
62
  */
63
  function gaoop_add_mce_plugin( $plugin_array ) {
 
64
  $plugin_array['wpb_analytics_opt_out'] = GAOOP_URL . 'js/editor-button.js';
65
 
66
  return $plugin_array;
@@ -76,6 +80,7 @@ function gaoop_add_mce_plugin( $plugin_array ) {
76
  * @return array
77
  */
78
  function gaoop_register_mce_buttons( $buttons ) {
 
79
  array_push( $buttons, "wpb_analytics_opt_out" );
80
 
81
  return $buttons;
@@ -88,6 +93,7 @@ function gaoop_register_mce_buttons( $buttons ) {
88
  * @since 2.0.0
89
  */
90
  function gaoop_import_from_old_version() {
 
91
  $ua_code = get_option( 'gaoo_property', '' );
92
  if ( ! empty( $ua_code ) ) {
93
  update_option( 'gaoop_property', $ua_code );
@@ -98,4 +104,4 @@ function gaoop_import_from_old_version() {
98
  }
99
  }
100
 
101
- add_action('admin_init', 'gaoop_import_from_old_version');
1
  <?php
2
 
3
  function gaoop_admin_notice() {
4
+
5
  $code = gaoop_get_ua_code();
6
  if ( ! empty( $code ) ) {
7
  return;
28
  * @return array
29
  */
30
  function gaoop_plugin_action_links( $links ) {
31
+
32
  $links[] = '<a href="' . admin_url( 'options-general.php?page=gaoo-options' ) . '">' . __( 'Settings', 'google-analytics-opt-out' ) . '</a>';
33
  $links[] = '<a target="_blank" href="http://wp-buddy.com">' . __( 'More by WP-Buddy', 'google-analytics-opt-out' ) . '</a>';
34
 
45
  * @return void
46
  */
47
  function gaoop_editor_button() {
48
+
49
  if ( get_user_option( 'rich_editing' ) == true ) {
50
  add_filter( "mce_external_plugins", 'gaoop_add_mce_plugin' );
51
  add_filter( 'mce_buttons', 'gaoop_register_mce_buttons' );
64
  * @return array
65
  */
66
  function gaoop_add_mce_plugin( $plugin_array ) {
67
+
68
  $plugin_array['wpb_analytics_opt_out'] = GAOOP_URL . 'js/editor-button.js';
69
 
70
  return $plugin_array;
80
  * @return array
81
  */
82
  function gaoop_register_mce_buttons( $buttons ) {
83
+
84
  array_push( $buttons, "wpb_analytics_opt_out" );
85
 
86
  return $buttons;
93
  * @since 2.0.0
94
  */
95
  function gaoop_import_from_old_version() {
96
+
97
  $ua_code = get_option( 'gaoo_property', '' );
98
  if ( ! empty( $ua_code ) ) {
99
  update_option( 'gaoop_property', $ua_code );
104
  }
105
  }
106
 
107
+ add_action( 'admin_init', 'gaoop_import_from_old_version' );
inc/frontend.php CHANGED
@@ -7,6 +7,7 @@
7
  * @return void
8
  */
9
  function gaoop_footer() {
 
10
  if ( ! get_option( 'gaoop_banner', false ) ) {
11
  return;
12
  }
@@ -32,6 +33,7 @@ add_action( 'wp_footer', 'gaoop_footer' );
32
  * @since 1.0
33
  */
34
  function gaoop_optout_text() {
 
35
  $opt_out_text = get_option( 'gaoop_opt_out_text', '' );
36
  if ( empty( $opt_out_text ) ) {
37
  $opt_out_text = __( 'This website is using Google Analytics. Please click here if you want to opt-out.', 'google-analytics-opt-out' );
@@ -71,15 +73,15 @@ function gaoop_wp_head() {
71
  'box-shadow' => $box_shadow,
72
  'background-color' => '#0E90D2',
73
  'padding' => 0,
74
- 'margin' => 0
75
  ),
76
  '.gaoop a' => array(
77
  'color' => '#67C2F0',
78
- 'text-decoration' => 'none'
79
  ),
80
  '.gaoop a:hover' => array(
81
  'color' => '#ffffff',
82
- 'text-decoration' => 'underline'
83
  ),
84
  '.gaoop-info-icon' => array(
85
  'position' => 'relative',
@@ -110,10 +112,10 @@ function gaoop_wp_head() {
110
  'ms-filter' => '"progid:DXImageTransform.Microsoft.Alpha(Opacity=100)"',
111
  'filter' => 'alpha(opacity=100)',
112
  '-moz-opacity' => '1',
113
- '-khtml-opacity' => '1'
114
  ),
115
  '.gaoop_closed .gaoop-opt-out-link, .gaoop_closed .gaoop-close-icon' => array(
116
- 'display' => 'none'
117
  ),
118
  '.gaoop_closed' => array(
119
  'width' => '55px',
@@ -123,14 +125,14 @@ function gaoop_wp_head() {
123
  'ms-filter' => '"progid:DXImageTransform.Microsoft.Alpha(Opacity=50)"',
124
  'filter' => 'alpha(opacity=50)',
125
  '-moz-opacity' => '0.5',
126
- '-khtml-opacity' => '0.5'
127
  ),
128
  '.gaoop_closed:hover' => array(
129
  'opacity' => '1',
130
  'ms-filter' => '"progid:DXImageTransform.Microsoft.Alpha(Opacity=100)"',
131
  'filter' => 'alpha(opacity=100)',
132
  '-moz-opacity' => '1',
133
- '-khtml-opacity' => '1'
134
  ),
135
  '.gaoop_closed .gaoop-opt-out-content' => array(
136
  'display' => 'none',
7
  * @return void
8
  */
9
  function gaoop_footer() {
10
+
11
  if ( ! get_option( 'gaoop_banner', false ) ) {
12
  return;
13
  }
33
  * @since 1.0
34
  */
35
  function gaoop_optout_text() {
36
+
37
  $opt_out_text = get_option( 'gaoop_opt_out_text', '' );
38
  if ( empty( $opt_out_text ) ) {
39
  $opt_out_text = __( 'This website is using Google Analytics. Please click here if you want to opt-out.', 'google-analytics-opt-out' );
73
  'box-shadow' => $box_shadow,
74
  'background-color' => '#0E90D2',
75
  'padding' => 0,
76
+ 'margin' => 0,
77
  ),
78
  '.gaoop a' => array(
79
  'color' => '#67C2F0',
80
+ 'text-decoration' => 'none',
81
  ),
82
  '.gaoop a:hover' => array(
83
  'color' => '#ffffff',
84
+ 'text-decoration' => 'underline',
85
  ),
86
  '.gaoop-info-icon' => array(
87
  'position' => 'relative',
112
  'ms-filter' => '"progid:DXImageTransform.Microsoft.Alpha(Opacity=100)"',
113
  'filter' => 'alpha(opacity=100)',
114
  '-moz-opacity' => '1',
115
+ '-khtml-opacity' => '1',
116
  ),
117
  '.gaoop_closed .gaoop-opt-out-link, .gaoop_closed .gaoop-close-icon' => array(
118
+ 'display' => 'none',
119
  ),
120
  '.gaoop_closed' => array(
121
  'width' => '55px',
125
  'ms-filter' => '"progid:DXImageTransform.Microsoft.Alpha(Opacity=50)"',
126
  'filter' => 'alpha(opacity=50)',
127
  '-moz-opacity' => '0.5',
128
+ '-khtml-opacity' => '0.5',
129
  ),
130
  '.gaoop_closed:hover' => array(
131
  'opacity' => '1',
132
  'ms-filter' => '"progid:DXImageTransform.Microsoft.Alpha(Opacity=100)"',
133
  'filter' => 'alpha(opacity=100)',
134
  '-moz-opacity' => '1',
135
+ '-khtml-opacity' => '1',
136
  ),
137
  '.gaoop_closed .gaoop-opt-out-content' => array(
138
  'display' => 'none',
inc/functions.php CHANGED
@@ -2,11 +2,28 @@
2
 
3
  /**
4
  * Checks if the Yoast Analytics Plugin is active
 
5
  * @since 1.0
 
 
 
 
6
  * @return bool
7
  */
8
  function gaoop_yoast_plugin_active() {
9
- return defined( 'GAWP_VERSION' );
 
 
 
 
 
 
 
 
 
 
 
 
10
  }
11
 
12
  /**
@@ -14,58 +31,55 @@ function gaoop_yoast_plugin_active() {
14
  * If Yoast Analytics is not installed this will return an empty string
15
  *
16
  * @since 1.0
 
 
 
 
17
  * @return string
18
  */
19
  function gaoop_get_yoast_ua() {
20
 
21
- if ( ! gaoop_yoast_plugin_active() ) {
22
- return '';
23
- }
24
-
25
- $ua_code = '';
26
-
27
- if ( is_admin() ) {
28
- global $yoast_ga_admin;
29
-
30
- if ( method_exists( $yoast_ga_admin, 'get_tracking_code' ) ) {
31
- $ua_code = $yoast_ga_admin->get_tracking_code();
32
- }
33
-
34
- } else {
35
 
36
- if ( class_exists( 'Yoast_GA_Options' ) ) {
37
- $yoast_ga_options = Yoast_GA_Options::instance();
 
 
 
 
 
 
38
 
39
- if ( method_exists( $yoast_ga_options, 'get_tracking_code' ) ) {
40
- $ua_code = $yoast_ga_options->get_tracking_code();
41
- }
42
- }
43
  }
44
 
45
- return $ua_code;
46
  }
47
 
48
  /**
49
  * Returns the UA-Code
 
50
  * @since 1.0
51
  * @return string
52
  */
53
  function gaoop_get_ua_code() {
54
 
55
- $use_yoast = get_option( 'gaoop_yoast', null );
56
 
57
  // if the plugin is used the first time, this value is NULL
58
- if ( is_null( $use_yoast ) ) {
59
- $use_yoast = 1;
60
  }
61
 
62
- // if yoast should be used, try to get the ua code from the plugin
63
- if ( 1 == intval( $use_yoast ) && gaoop_yoast_plugin_active() ) {
64
 
65
- $yoast_code = gaoop_get_yoast_ua();
66
 
67
- if ( ! empty( $yoast_code ) ) {
68
- return apply_filters( 'gaoop_get_ua_code', $yoast_code );
69
  }
70
  }
71
 
@@ -76,18 +90,21 @@ function gaoop_get_ua_code() {
76
 
77
  /**
78
  * Sets the message to show when cookie has set
 
79
  * @since 1.0
80
  */
81
  function gaoop_cookie_set() {
 
82
  $message = apply_filters( 'gaoop_opt_out_cookie_set_text', '' );
83
 
84
- return "alert('" . $message . "');";
85
  }
86
 
87
  add_filter( 'gaoop_cookie_set', 'gaoop_cookie_set' );
88
 
89
 
90
  function gaoop_opt_out_cookie_set_text() {
 
91
  $text = sanitize_text_field( get_option( 'gaoop_opt_out_cookie_set_text', '' ) );
92
  if ( ! empty( $text ) ) {
93
  return $text;
2
 
3
  /**
4
  * Checks if the Yoast Analytics Plugin is active
5
+ *
6
  * @since 1.0
7
+ * @deprecated 2.0.2
8
+ *
9
+ * @todo Remove this in a future version.
10
+ *
11
  * @return bool
12
  */
13
  function gaoop_yoast_plugin_active() {
14
+
15
+ return gaoop_monster_insights_plugin_active();
16
+ }
17
+
18
+ /**
19
+ * Checks if Monster Insights is active
20
+ *
21
+ * @since 2.0.2
22
+ * @return bool
23
+ */
24
+ function gaoop_monster_insights_plugin_active() {
25
+
26
+ return function_exists( 'monsterinsights_get_ua_to_output' );
27
  }
28
 
29
  /**
31
  * If Yoast Analytics is not installed this will return an empty string
32
  *
33
  * @since 1.0
34
+ * @deprecated 2.0.2
35
+ *
36
+ * @todo Remove this in a future version.
37
+ *
38
  * @return string
39
  */
40
  function gaoop_get_yoast_ua() {
41
 
42
+ return gaoop_get_monster_insights_ua();
43
+ }
 
 
 
 
 
 
 
 
 
 
 
 
44
 
45
+ /**
46
+ * Return the UA from Monster Insights settings.
47
+ * If Monster Insights is not installed this will return an empty string.
48
+ *
49
+ * @since 1.0
50
+ * @return string
51
+ */
52
+ function gaoop_get_monster_insights_ua() {
53
 
54
+ if ( ! gaoop_monster_insights_plugin_active() ) {
55
+ return '';
 
 
56
  }
57
 
58
+ return monsterinsights_get_ua_to_output();
59
  }
60
 
61
  /**
62
  * Returns the UA-Code
63
+ *
64
  * @since 1.0
65
  * @return string
66
  */
67
  function gaoop_get_ua_code() {
68
 
69
+ $use_monster_insights = get_option( 'gaoop_yoast', null ); # in a past version this was Yoast Analytics.
70
 
71
  // if the plugin is used the first time, this value is NULL
72
+ if ( is_null( $use_monster_insights ) ) {
73
+ $use_monster_insights = 1;
74
  }
75
 
76
+ // if Monster Insights should be used, try to get the ua code from the plugin
77
+ if ( 1 == intval( $use_monster_insights ) && gaoop_monster_insights_plugin_active()) {
78
 
79
+ $monster_insights_ua = gaoop_get_monster_insights_ua();
80
 
81
+ if ( ! empty( $monster_insights_ua ) ) {
82
+ return apply_filters( 'gaoop_get_ua_code', $monster_insights_ua );
83
  }
84
  }
85
 
90
 
91
  /**
92
  * Sets the message to show when cookie has set
93
+ *
94
  * @since 1.0
95
  */
96
  function gaoop_cookie_set() {
97
+
98
  $message = apply_filters( 'gaoop_opt_out_cookie_set_text', '' );
99
 
100
+ return "alert('" . esc_attr( esc_html( $message ) ) . "');";
101
  }
102
 
103
  add_filter( 'gaoop_cookie_set', 'gaoop_cookie_set' );
104
 
105
 
106
  function gaoop_opt_out_cookie_set_text() {
107
+
108
  $text = sanitize_text_field( get_option( 'gaoop_opt_out_cookie_set_text', '' ) );
109
  if ( ! empty( $text ) ) {
110
  return $text;
inc/scripts.php CHANGED
@@ -3,20 +3,22 @@
3
  * Echos out the JavaScript for the opt-out
4
  *
5
  * @since 1.0
 
 
 
 
6
  * @return void
7
  */
8
  function gaoop_head_script() {
9
 
10
- if ( apply_filters( 'gaoop_stop_head', false ) ) {
11
- return;
12
- }
13
-
14
- gaoop_js();
 
15
  }
16
 
17
- // To call it before the Yoast Analytics Plugin (2) this has a priority of 1
18
- add_action( 'wp_head', 'gaoop_head_script', 1 );
19
-
20
  /**
21
  * Echos out the Javascript or returns it (if $echo is set to TRUE)
22
  *
@@ -27,30 +29,38 @@ add_action( 'wp_head', 'gaoop_head_script', 1 );
27
  * @return void|string
28
  */
29
  function gaoop_js( $echo = true ) {
 
30
  $ua_code = gaoop_get_ua_code();
31
  if ( empty( $ua_code ) ) {
32
  return '';
33
  }
34
  ob_start();
 
35
  ?>
36
  <script type="text/javascript">
37
- /* <![CDATA[ */
 
 
38
  /* Google Analytics Opt-Out WordPress by WP-Buddy | http://wp-buddy.com/products/plugins/google-analytics-opt-out */
39
- <?php do_action('gaoop_js_before_script'); ?>
40
- var gaoop_property = '<?php echo $ua_code; ?>';
41
  var gaoop_disable_str = 'ga-disable-' + gaoop_property;
42
  if ( document.cookie.indexOf( gaoop_disable_str + '=true' ) > -1 ) {
43
  window[ gaoop_disable_str ] = true;
44
  }
45
  function gaoop_analytics_optout() {
46
- document.cookie = gaoop_disable_str + '=true; expires=Thu, 31 Dec 2099 23:59:59 UTC; path=/';
47
  window[ gaoop_disable_str ] = true;
48
  <?php echo apply_filters( 'gaoop_cookie_set', '' ); ?>
49
  }
50
- <?php do_action('gaoop_js_after_script'); ?>
51
- /* ]]> */
 
 
 
52
  </script>
53
  <?php
 
54
  $content = ob_get_clean();
55
  if ( $echo ) {
56
  echo $content;
@@ -65,14 +75,20 @@ function gaoop_js( $echo = true ) {
65
  * @since 1.0
66
  */
67
  function gaoop_enqueue_scripts() {
 
68
  wp_enqueue_script( 'goop', GAOOP_URL . 'js/frontend.js', array( 'jquery' ), false, true );
 
69
  add_filter( 'script_loader_tag', function ( $tag, $handle ) {
70
- if ( $handle === 'goop' ) {
71
- return str_replace( '<script', '<script async ', $tag );
 
72
  }
73
 
74
  return $tag;
75
  }, 10, 2 );
 
 
 
76
  }
77
 
78
  add_action( 'init', 'gaoop_enqueue_scripts' );
3
  * Echos out the JavaScript for the opt-out
4
  *
5
  * @since 1.0
6
+ * @deprecated 2.0.2
7
+ *
8
+ * @todo Remove this is a future version.
9
+ *
10
  * @return void
11
  */
12
  function gaoop_head_script() {
13
 
14
+ //
15
+ // if ( apply_filters( 'gaoop_stop_head', false ) ) {
16
+ // return;
17
+ // }
18
+ //
19
+ // gaoop_js();
20
  }
21
 
 
 
 
22
  /**
23
  * Echos out the Javascript or returns it (if $echo is set to TRUE)
24
  *
29
  * @return void|string
30
  */
31
  function gaoop_js( $echo = true ) {
32
+
33
  $ua_code = gaoop_get_ua_code();
34
  if ( empty( $ua_code ) ) {
35
  return '';
36
  }
37
  ob_start();
38
+ if ( $echo ):
39
  ?>
40
  <script type="text/javascript">
41
+ <?php
42
+ endif;
43
+ ?>
44
  /* Google Analytics Opt-Out WordPress by WP-Buddy | http://wp-buddy.com/products/plugins/google-analytics-opt-out */
45
+ <?php do_action( 'gaoop_js_before_script' ); ?>
46
+ var gaoop_property = '<?php echo $ua_code; ?>';
47
  var gaoop_disable_str = 'ga-disable-' + gaoop_property;
48
  if ( document.cookie.indexOf( gaoop_disable_str + '=true' ) > -1 ) {
49
  window[ gaoop_disable_str ] = true;
50
  }
51
  function gaoop_analytics_optout() {
52
+ document.cookie = gaoop_disable_str + '=true; expires=Thu, 31 Dec 2099 23:59:59 UTC; path=/';
53
  window[ gaoop_disable_str ] = true;
54
  <?php echo apply_filters( 'gaoop_cookie_set', '' ); ?>
55
  }
56
+ <?php
57
+ do_action( 'gaoop_js_after_script' );
58
+
59
+ if($echo):
60
+ ?>
61
  </script>
62
  <?php
63
+ endif;
64
  $content = ob_get_clean();
65
  if ( $echo ) {
66
  echo $content;
75
  * @since 1.0
76
  */
77
  function gaoop_enqueue_scripts() {
78
+
79
  wp_enqueue_script( 'goop', GAOOP_URL . 'js/frontend.js', array( 'jquery' ), false, true );
80
+
81
  add_filter( 'script_loader_tag', function ( $tag, $handle ) {
82
+
83
+ if ( $handle === 'goop' && false === stripos( $tag, 'defer' ) ) {
84
+ return str_replace( '<script', '<script defer ', $tag );
85
  }
86
 
87
  return $tag;
88
  }, 10, 2 );
89
+
90
+ $js = gaoop_js( false );
91
+ wp_add_inline_script( 'goop', $js );
92
  }
93
 
94
  add_action( 'init', 'gaoop_enqueue_scripts' );
inc/settings.php CHANGED
@@ -7,10 +7,11 @@
7
  * @return void
8
  */
9
  function gaoop_admin_menu() {
 
10
  $hook = add_submenu_page( 'options-general.php', __( 'Analytics Opt-Out', 'google-analytics-opt-out' ), __( 'Analytics Opt-Out', 'google-analytics-opt-out' ), 'manage_options', 'gaoo-options', 'gaoop_settings_page' );
11
  add_action( "load-$hook", 'gaoop_settings_scripts' );
12
 
13
- $hook = add_submenu_page( 'yst_ga_dashboard', __( 'Analytics Opt-Out', 'google-analytics-opt-out' ), __( 'Opt-Out Settings', 'google-analytics-opt-out' ), 'manage_options', 'gaoo-options', 'gaoop_settings_page' );
14
  add_action( "load-$hook", 'gaoop_settings_scripts' );
15
  }
16
 
@@ -24,6 +25,7 @@ add_action( 'admin_menu', 'gaoop_admin_menu', 30 );
24
  * @return void
25
  */
26
  function gaoop_settings_page() {
 
27
  ?>
28
  <div class="wrap">
29
  <div id="icon-options-general" class="icon32"></div>
@@ -48,6 +50,7 @@ function gaoop_settings_page() {
48
  * @return void
49
  */
50
  function gaoop_settings_scripts() {
 
51
  wp_enqueue_script( 'equipment', GAOOP_URL . '/js/settings.js', array( 'jquery' ), false, true );
52
  }
53
 
@@ -100,7 +103,7 @@ add_action( 'admin_init', 'gaoop_register_theme_options_section' );
100
  */
101
  function gaoop_options_yoast() {
102
 
103
- $yoast_active = gaoop_yoast_plugin_active();
104
 
105
  $option = get_option( 'gaoop_yoast', null );
106
 
@@ -109,13 +112,13 @@ function gaoop_options_yoast() {
109
  $option = 1;
110
  }
111
 
112
- if ( ! $yoast_active ) {
113
  $option = 0;
114
  }
115
 
116
- echo '<input ' . disabled( ! $yoast_active, true, false ) . ' ' . checked( $option, 1, false ) . ' id="gaoop_options_yoast" type="checkbox" name="gaoop_yoast" value="1" />';
117
  echo '<p class="description">';
118
- if ( $yoast_active ) {
119
  echo '<span style="color: #5EB95E;">' . __( 'Monster Insights Plugin has been detected.', 'google-analytics-opt-out' ) . '</span>';
120
  } else {
121
  echo '<span style="color: #DD514C;">' . __( 'Monster Insights Plugin has NOT been detected. Please enter your UA code manually and then check the sourcode of your website. Make sure that Analytics code appears AFTER the opt-out code (which starts with <code>/* Google Analytics Opt-Out</code>).', 'google-analytics-opt-out' ) . '</span>';
@@ -131,11 +134,12 @@ function gaoop_options_yoast() {
131
  * @return void
132
  */
133
  function gaoop_options_property() {
134
- $yoast_active = gaoop_yoast_plugin_active();
 
135
  $option = get_option( 'gaoop_yoast', null );
136
 
137
- if ( $yoast_active && 1 == $option ) {
138
- $value = gaoop_get_yoast_ua();
139
  } else {
140
  $value = sanitize_text_field( get_option( 'gaoop_property', '' ) );
141
  }
@@ -166,6 +170,7 @@ function gaoop_options_banner() {
166
  * @return void
167
  */
168
  function gaoop_options_opt_out_text() {
 
169
  wp_editor(
170
  get_option( 'gaoop_opt_out_text', '' ),
171
  'gaoop_options_opt_out_text',
@@ -183,6 +188,7 @@ function gaoop_options_opt_out_text() {
183
  * @since 1.4
184
  */
185
  function gaoop_options_opt_out_shortcode_integration() {
 
186
  printf(
187
  '<input type="checkbox" id="gaoop_options_opt_out_shortcode_integration" value="1" name="gaoop_opt_out_shortcode_integration" %s />',
188
  checked( (bool) get_option( 'gaoop_opt_out_shortcode_integration', 1 ), true, false )
@@ -197,6 +203,7 @@ function gaoop_options_opt_out_shortcode_integration() {
197
  * @return void
198
  */
199
  function gaoop_options_opt_out_cookie_set_text() {
 
200
  echo '<input id="gaoop_options_opt_out_cookie_set_text" placeholder="' . __( 'Thanks. We have set a cookie so that Google Analytics data collection will be disabled on your next visit.', 'google-analytics-opt-out' ) . '" type="text" class="regular-text" value="' . sanitize_text_field( get_option( 'gaoop_opt_out_cookie_set_text', '' ) ) . '" name="gaoop_opt_out_cookie_set_text" /> ';
201
 
202
  }
@@ -208,6 +215,7 @@ function gaoop_options_opt_out_cookie_set_text() {
208
  * @return void
209
  */
210
  function gaoop_options_hide() {
 
211
  echo '<input type="checkbox" id="gaoop_options_hide" ' . checked( intval( get_option( 'gaoop_hide', 0 ) ), 1, false ) . ' value="1" name="gaoop_hide" /> ';
212
  echo '<p class="description">' . __( 'This will hide the opt-out box after the user has clicked the close-button. Otherwise a little info-button will be fixed to the bottom-right.', 'google-analytics-opt-out' ) . '</p>';
213
 
@@ -220,5 +228,6 @@ function gaoop_options_hide() {
220
  * @return void
221
  */
222
  function gaoop_options_custom_styles() {
 
223
  echo '<textarea id="gaoop_options_custom_styles" style="width: 400px;" cols="30" rows="5" class="regular-text" name="gaoop_custom_styles">' . esc_textarea( get_option( 'gaoop_custom_styles', '' ) ) . '</textarea> ';
224
  }
7
  * @return void
8
  */
9
  function gaoop_admin_menu() {
10
+
11
  $hook = add_submenu_page( 'options-general.php', __( 'Analytics Opt-Out', 'google-analytics-opt-out' ), __( 'Analytics Opt-Out', 'google-analytics-opt-out' ), 'manage_options', 'gaoo-options', 'gaoop_settings_page' );
12
  add_action( "load-$hook", 'gaoop_settings_scripts' );
13
 
14
+ $hook = add_submenu_page( 'monsterinsights_dashboard', __( 'Analytics Opt-Out', 'google-analytics-opt-out' ), __( 'Opt-Out Settings', 'google-analytics-opt-out' ), 'manage_options', 'gaoo-options', 'gaoop_settings_page' );
15
  add_action( "load-$hook", 'gaoop_settings_scripts' );
16
  }
17
 
25
  * @return void
26
  */
27
  function gaoop_settings_page() {
28
+
29
  ?>
30
  <div class="wrap">
31
  <div id="icon-options-general" class="icon32"></div>
50
  * @return void
51
  */
52
  function gaoop_settings_scripts() {
53
+
54
  wp_enqueue_script( 'equipment', GAOOP_URL . '/js/settings.js', array( 'jquery' ), false, true );
55
  }
56
 
103
  */
104
  function gaoop_options_yoast() {
105
 
106
+ $monster_insights_active = gaoop_monster_insights_plugin_active();
107
 
108
  $option = get_option( 'gaoop_yoast', null );
109
 
112
  $option = 1;
113
  }
114
 
115
+ if ( ! $monster_insights_active ) {
116
  $option = 0;
117
  }
118
 
119
+ echo '<input ' . disabled( ! $monster_insights_active, true, false ) . ' ' . checked( $option, 1, false ) . ' id="gaoop_options_yoast" type="checkbox" name="gaoop_yoast" value="1" />';
120
  echo '<p class="description">';
121
+ if ( $monster_insights_active ) {
122
  echo '<span style="color: #5EB95E;">' . __( 'Monster Insights Plugin has been detected.', 'google-analytics-opt-out' ) . '</span>';
123
  } else {
124
  echo '<span style="color: #DD514C;">' . __( 'Monster Insights Plugin has NOT been detected. Please enter your UA code manually and then check the sourcode of your website. Make sure that Analytics code appears AFTER the opt-out code (which starts with <code>/* Google Analytics Opt-Out</code>).', 'google-analytics-opt-out' ) . '</span>';
134
  * @return void
135
  */
136
  function gaoop_options_property() {
137
+
138
+ $monster_insights_active = gaoop_monster_insights_plugin_active();
139
  $option = get_option( 'gaoop_yoast', null );
140
 
141
+ if ( $monster_insights_active && 1 == $option ) {
142
+ $value = gaoop_get_monster_insights_ua();
143
  } else {
144
  $value = sanitize_text_field( get_option( 'gaoop_property', '' ) );
145
  }
170
  * @return void
171
  */
172
  function gaoop_options_opt_out_text() {
173
+
174
  wp_editor(
175
  get_option( 'gaoop_opt_out_text', '' ),
176
  'gaoop_options_opt_out_text',
188
  * @since 1.4
189
  */
190
  function gaoop_options_opt_out_shortcode_integration() {
191
+
192
  printf(
193
  '<input type="checkbox" id="gaoop_options_opt_out_shortcode_integration" value="1" name="gaoop_opt_out_shortcode_integration" %s />',
194
  checked( (bool) get_option( 'gaoop_opt_out_shortcode_integration', 1 ), true, false )
203
  * @return void
204
  */
205
  function gaoop_options_opt_out_cookie_set_text() {
206
+
207
  echo '<input id="gaoop_options_opt_out_cookie_set_text" placeholder="' . __( 'Thanks. We have set a cookie so that Google Analytics data collection will be disabled on your next visit.', 'google-analytics-opt-out' ) . '" type="text" class="regular-text" value="' . sanitize_text_field( get_option( 'gaoop_opt_out_cookie_set_text', '' ) ) . '" name="gaoop_opt_out_cookie_set_text" /> ';
208
 
209
  }
215
  * @return void
216
  */
217
  function gaoop_options_hide() {
218
+
219
  echo '<input type="checkbox" id="gaoop_options_hide" ' . checked( intval( get_option( 'gaoop_hide', 0 ) ), 1, false ) . ' value="1" name="gaoop_hide" /> ';
220
  echo '<p class="description">' . __( 'This will hide the opt-out box after the user has clicked the close-button. Otherwise a little info-button will be fixed to the bottom-right.', 'google-analytics-opt-out' ) . '</p>';
221
 
228
  * @return void
229
  */
230
  function gaoop_options_custom_styles() {
231
+
232
  echo '<textarea id="gaoop_options_custom_styles" style="width: 400px;" cols="30" rows="5" class="regular-text" name="gaoop_custom_styles">' . esc_textarea( get_option( 'gaoop_custom_styles', '' ) ) . '</textarea> ';
233
  }
inc/shortcodes.php CHANGED
@@ -13,6 +13,7 @@ if ( ! defined( 'ABSPATH' ) ) {
13
  * @return bool
14
  */
15
  function gaoop_has_shortcode( $shortcode, $content = '' ) {
 
16
  if ( stripos( $content, '[' . $shortcode ) !== false ) {
17
  return true;
18
  }
@@ -27,6 +28,7 @@ function gaoop_has_shortcode( $shortcode, $content = '' ) {
27
  * @return void
28
  */
29
  function gaoop_init_shortcodes() {
 
30
  add_shortcode( 'google_analytics_optout', 'gaoop_shortcode' );
31
  add_shortcode( 'google_analytics_optout_close', 'gaoop_shortcode_close' );
32
  }
@@ -45,6 +47,7 @@ add_action( 'init', 'gaoop_init_shortcodes' );
45
  * @return string
46
  */
47
  function gaoop_shortcode( $atts, $content = '' ) {
 
48
  //$atts = shortcode_atts( array(), $atts );
49
 
50
  if ( empty( $content ) ) {
@@ -73,6 +76,7 @@ function gaoop_shortcode( $atts, $content = '' ) {
73
  * @return string
74
  */
75
  function gaoop_shortcode_close( $atts, $content, $name ) {
 
76
  if ( empty( $content ) ) {
77
  $content = __( 'OK', 'google-analytics-opt-out' );
78
  }
13
  * @return bool
14
  */
15
  function gaoop_has_shortcode( $shortcode, $content = '' ) {
16
+
17
  if ( stripos( $content, '[' . $shortcode ) !== false ) {
18
  return true;
19
  }
28
  * @return void
29
  */
30
  function gaoop_init_shortcodes() {
31
+
32
  add_shortcode( 'google_analytics_optout', 'gaoop_shortcode' );
33
  add_shortcode( 'google_analytics_optout_close', 'gaoop_shortcode_close' );
34
  }
47
  * @return string
48
  */
49
  function gaoop_shortcode( $atts, $content = '' ) {
50
+
51
  //$atts = shortcode_atts( array(), $atts );
52
 
53
  if ( empty( $content ) ) {
76
  * @return string
77
  */
78
  function gaoop_shortcode_close( $atts, $content, $name ) {
79
+
80
  if ( empty( $content ) ) {
81
  $content = __( 'OK', 'google-analytics-opt-out' );
82
  }
js/frontend.js CHANGED
@@ -1,104 +1,105 @@
1
  (function ( $ ) {
2
- "use strict";
3
- jQuery( document ).ready( function () {
4
-
5
- var $gaoop = jQuery( '.gaoop' );
6
- var ua_code = $gaoop.data( 'gaoop_ua' );
7
-
8
-
9
- /**
10
- * Check if opt-out cookie has NOT been set already
11
- */
12
- if ( document.cookie.indexOf( 'ga-disable-' + ua_code + '=true' ) <= -1 && jQuery.isFunction( window.gaoop_analytics_optout ) ) {
13
- /** Check if hide-info cookie was checked **/
14
- if ( document.cookie.indexOf( 'gaoop_hide_info=true' ) > -1 ) {
15
- /* yes, set */
16
- if ( 1 != $gaoop.data( 'gaoop_hide' ) ) {
17
- $gaoop.addClass( 'gaoop_closed' ).show();
18
- }
19
- } else {
20
- /* not set */
21
- $gaoop.show();
22
- }
23
- }
24
-
25
-
26
- /**
27
- * Close banner
28
- */
29
- function gaoop_close() {
30
-
31
- if ( 1 == $gaoop.data( 'gaoop_hide' ) ) {
32
- $gaoop.fadeOut( 500 );
33
- } else {
34
- $gaoop.css( 'left', 'auto' ).css( 'right', 0 );
35
- $gaoop.find( '.gaoop-opt-out-content' ).hide();
36
- $gaoop.find( '.gaoop-opt-out-link, .gaoop-close-icon' ).hide();
37
- $gaoop.animate( { 'opacity': 0.5, 'width': '55px' }, 500 );
38
- $gaoop.addClass( 'gaoop_closed' );
39
- }
40
-
41
- document.cookie = 'gaoop_hide_info=true; expires=Thu, 31 Dec 2099 23:59:59 UTC; path=/';
42
- }
43
-
44
-
45
- /**
46
- * Open banner
47
- */
48
- function gaoop_open() {
49
- /* destroy cookie */
50
- document.cookie = 'gaoop_hide_info=true; expires=Thu, 31 Dec 1901 23:59:59 UTC; path=/';
51
-
52
- $gaoop.removeClass( 'gaoop_closed' );
53
- $gaoop.animate( { 'opacity': 1, 'width': '100%' }, 500, function () {
54
- $gaoop.find( '.gaoop-opt-out-link, .gaoop-close-icon' ).fadeIn( 300 );
55
- $gaoop.find( '.gaoop-opt-out-content' ).show();
56
- } );
57
- }
58
-
59
-
60
- /**
61
- * Click Opt-Out Button
62
- */
63
- $gaoop.find( 'a.gaoo-opt-out' ).click( function ( e ) {
64
- e.preventDefault();
65
- if ( jQuery.isFunction( window.gaoop_analytics_optout ) ) {
66
- gaoop_analytics_optout();
67
- $gaoop.fadeOut( 500 );
68
- }
69
- } );
70
-
71
-
72
- /**
73
- * Click info icon
74
- */
75
- $gaoop.find( '.gaoop-info-icon' ).click( function ( e ) {
76
- e.preventDefault();
77
-
78
- if ( $gaoop.hasClass( 'gaoop_closed' ) ) {
79
- gaoop_open();
80
- }
81
-
82
- } );
83
-
84
-
85
- /**
86
- * Click to close the window
87
- */
88
- $gaoop.find( '.gaoop-close-icon' ).click( function ( e ) {
89
- e.preventDefault();
90
- gaoop_close();
91
- } );
92
-
93
-
94
- /**
95
- * Click to close the window
96
- */
97
-
98
- jQuery( document ).on( 'click', '.gaoop-close-link', function ( e ) {
99
- e.preventDefault();
100
- gaoop_close();
101
- } );
102
-
103
- } );
 
104
  })( jQuery );
1
  (function ( $ ) {
2
+ "use strict";
3
+ jQuery( document ).ready( function () {
4
+
5
+ var $gaoop = jQuery( '.gaoop' );
6
+ var ua_code = $gaoop.data( 'gaoop_ua' );
7
+
8
+
9
+ /**
10
+ * Check if opt-out cookie has NOT been set already
11
+ */
12
+ console.log(document.cookie);
13
+ if ( document.cookie.indexOf( 'ga-disable-' + ua_code + '=true' ) <= -1 && jQuery.isFunction( window.gaoop_analytics_optout ) ) {
14
+ /** Check if hide-info cookie was checked **/
15
+ if ( document.cookie.indexOf( 'gaoop_hide_info=true' ) > -1 ) {
16
+ /* yes, set */
17
+ if ( 1 != $gaoop.data( 'gaoop_hide' ) ) {
18
+ $gaoop.addClass( 'gaoop_closed' ).show();
19
+ }
20
+ } else {
21
+ /* not set */
22
+ $gaoop.show();
23
+ }
24
+ }
25
+
26
+
27
+ /**
28
+ * Close banner
29
+ */
30
+ function gaoop_close() {
31
+
32
+ if ( 1 == $gaoop.data( 'gaoop_hide' ) ) {
33
+ $gaoop.fadeOut( 500 );
34
+ } else {
35
+ $gaoop.css( 'left', 'auto' ).css( 'right', 0 );
36
+ $gaoop.find( '.gaoop-opt-out-content' ).hide();
37
+ $gaoop.find( '.gaoop-opt-out-link, .gaoop-close-icon' ).hide();
38
+ $gaoop.animate( { 'opacity': 0.5, 'width': '55px' }, 500 );
39
+ $gaoop.addClass( 'gaoop_closed' );
40
+ }
41
+
42
+ document.cookie = 'gaoop_hide_info=true; expires=Thu, 31 Dec 2099 23:59:59 UTC; path=/';
43
+ }
44
+
45
+
46
+ /**
47
+ * Open banner
48
+ */
49
+ function gaoop_open() {
50
+ /* destroy cookie */
51
+ document.cookie = 'gaoop_hide_info=true; expires=Thu, 31 Dec 1901 23:59:59 UTC; path=/';
52
+
53
+ $gaoop.removeClass( 'gaoop_closed' );
54
+ $gaoop.animate( { 'opacity': 1, 'width': '100%' }, 500, function () {
55
+ $gaoop.find( '.gaoop-opt-out-link, .gaoop-close-icon' ).fadeIn( 300 );
56
+ $gaoop.find( '.gaoop-opt-out-content' ).show();
57
+ } );
58
+ }
59
+
60
+
61
+ /**
62
+ * Click Opt-Out Button
63
+ */
64
+ $gaoop.find( 'a.gaoo-opt-out' ).click( function ( e ) {
65
+ e.preventDefault();
66
+ if ( jQuery.isFunction( window.gaoop_analytics_optout ) ) {
67
+ gaoop_analytics_optout();
68
+ $gaoop.fadeOut( 500 );
69
+ }
70
+ } );
71
+
72
+
73
+ /**
74
+ * Click info icon
75
+ */
76
+ $gaoop.find( '.gaoop-info-icon' ).click( function ( e ) {
77
+ e.preventDefault();
78
+
79
+ if ( $gaoop.hasClass( 'gaoop_closed' ) ) {
80
+ gaoop_open();
81
+ }
82
+
83
+ } );
84
+
85
+
86
+ /**
87
+ * Click to close the window
88
+ */
89
+ $gaoop.find( '.gaoop-close-icon' ).click( function ( e ) {
90
+ e.preventDefault();
91
+ gaoop_close();
92
+ } );
93
+
94
+
95
+ /**
96
+ * Click to close the window
97
+ */
98
+
99
+ jQuery( document ).on( 'click', '.gaoop-close-link', function ( e ) {
100
+ e.preventDefault();
101
+ gaoop_close();
102
+ } );
103
+
104
+ } );
105
  })( jQuery );
readme.txt CHANGED
@@ -2,10 +2,11 @@
2
  Contributors: wp-buddy, floriansimeth
3
  Donate link: https://wp-buddy.com/products/plugins/google-analytics-opt-out/
4
  Tags: google analytics, analytics, analytics opt-out, analytics opt out, monster insights, monster insight, yoast analytics
5
- Version: 2.0.1
6
  Requires at least: 3.7
7
- Stable tag: 2.0.1
8
- Tested up to: 4.7
 
9
  License: GPLv2
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
 
@@ -24,11 +25,10 @@ The free and the pro version have now been merged together. So you now can have
24
 
25
  * Install and activate the plugin via your WordPress Administration panel
26
  * Go the "Settings" -> "Analytics Opt Out" and enter your UA-code (you don't need this step if MonsterInsights plugin is active)
27
- * IMPORTANT: Check the sourcecode of your website and make sure that the Analytics code is entered AFTER the opt-out code. Otherwise the Opt-Out feature will not work.
28
- * Read the FAQ for more information.
29
 
30
  == Frequently Asked Questions ==
31
-
32
 
33
  == Screenshots ==
34
 
@@ -40,6 +40,12 @@ The free and the pro version have now been merged together. So you now can have
40
 
41
  == Changelog ==
42
 
 
 
 
 
 
 
43
  = 2.0.1 =
44
  * Plugin can now be translated via [translate.wordpress.org](https://translate.wordpress.org/projects/wp-plugins/google-analytics-opt-out)
45
 
@@ -68,4 +74,4 @@ The free and the pro version have now been merged together. So you now can have
68
  = 0.1 =
69
  * The first version
70
 
71
- == Upgrade Notice ==
2
  Contributors: wp-buddy, floriansimeth
3
  Donate link: https://wp-buddy.com/products/plugins/google-analytics-opt-out/
4
  Tags: google analytics, analytics, analytics opt-out, analytics opt out, monster insights, monster insight, yoast analytics
5
+ Version: 2.0.2
6
  Requires at least: 3.7
7
+ Stable tag: 2.0.2
8
+ Requires PHP: 5.6.0
9
+ Tested up to: 4.9
10
  License: GPLv2
11
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
12
 
25
 
26
  * Install and activate the plugin via your WordPress Administration panel
27
  * Go the "Settings" -> "Analytics Opt Out" and enter your UA-code (you don't need this step if MonsterInsights plugin is active)
28
+ * [Read the FAQ for more information.](https://wp-buddy.com/documentation/plugins/google-analytics-opt/faq/)
 
29
 
30
  == Frequently Asked Questions ==
31
+ [You can find the FAQ on this page here.](https://wp-buddy.com/documentation/plugins/google-analytics-opt/faq/)
32
 
33
  == Screenshots ==
34
 
40
 
41
  == Changelog ==
42
 
43
+ = 2.0.2 =
44
+ * Make plugin compatible with the latest version of MonsterInsights.
45
+ * Remove/deprecate all functions that have been used when the old Yoast Analytics plugin was active.
46
+ * Remove the 'gaoop_stop_head' filter as it's no longer needed.
47
+ * Display the options submenu under "Insights" menu.
48
+
49
  = 2.0.1 =
50
  * Plugin can now be translated via [translate.wordpress.org](https://translate.wordpress.org/projects/wp-plugins/google-analytics-opt-out)
51
 
74
  = 0.1 =
75
  * The first version
76
 
77
+ == Upgrade Notice ==
screenshot-1.png CHANGED
Binary file
screenshot-2.png CHANGED
Binary file
screenshot-3.png CHANGED
Binary file