Plugin Directory

Changeset 2896199


Ignore:
Timestamp:
04/09/2023 12:00:00 PM (3 years ago)
Author:
schweizersolutions
Message:
  • Fix: Paste tracking code in manual mode will now read GA4 id from JavaScript code and automatically insert it into input field, if it is empty.
  • Tweaks: Optimized code and UX.
  • Updated: Support for WordPress 6.2
  • Updated: Support for PHP 8.1
Location:
opt-out-for-google-analytics/trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • opt-out-for-google-analytics/trunk/assets/admin.js

    r2266057 r2896199  
    6060
    6161    $('input[name="gaoo[ga_plugin]"]').change(function () {
    62         var $textarea_tracking_code = $('#ga-plugin-tracking-code').parent();
     62        var $this = $(this),
     63            $textarea_tracking_code = $('#ga-plugin-tracking-code').parent();
    6364
    64         if ($(this).val() != 'manual') {
     65        if ($this.val() != 'manual') {
    6566            $textarea_tracking_code.slideUp();
    6667        } else {
     
    6970    });
    7071
    71     $('#ga-plugin-tracking-code').focusout(function () {
     72    $('#ga-plugin-tracking-code').on('focusout keyup paste', function () {
    7273        var val = $(this).val(),
    7374            $input_ua = $('#gaoo-ua-code');
    7475
    75         if (val.length && !$input_ua.val().length) {
    76             var matches = val.toString().match(/(UA|YT|MO)-\d{4,}-\d+/gmi);
     76        if (val.length && !$input_ua.val().trim().length) {
     77            var matches = val.toString().match(/(G|UA|YT|MO)-[a-zA-Z0-9-]+/gmi);
    7778
    7879            if (matches != null) {
  • opt-out-for-google-analytics/trunk/constants.php

    r2787042 r2896199  
    88    defined( 'GAOO_PLUGIN_URL' ) || define( 'GAOO_PLUGIN_URL', WP_PLUGIN_URL . DIRECTORY_SEPARATOR . GAOO_PLUGIN_NAME );
    99    defined( 'GAOO_PREFIX' ) || define( 'GAOO_PREFIX', '_gaoo_' );
    10     defined( 'GAOO_VERSION' ) || define( 'GAOO_VERSION', '2.1' );
     10    defined( 'GAOO_VERSION' ) || define( 'GAOO_VERSION', '2.2' );
    1111    defined( 'GAOO_SHORTCODE' ) || define( 'GAOO_SHORTCODE', '[ga_optout]' );
    1212    defined( 'GAOO_CAPABILITY' ) || define( 'GAOO_CAPABILITY', 'manage_options' );
  • opt-out-for-google-analytics/trunk/ga-opt-out.php

    r2787042 r2896199  
    44     * Plugin URI: https://www.schweizersolutions.com/?utm_source=wordpress&utm_medium=plugin&utm_campaign=plugin_uri
    55     * Description: Adds the possibility for the user to opt out from Google Analytics. The user will not be tracked by Google Analytics on this site until he allows it again, clears his cookies or uses a different browser.
    6      * Version: 2.1
     6     * Version: 2.2
    77     * Author: Schweizer Solutions GmbH
    88     * Author URI: https://www.schweizersolutions.com/?utm_source=wordpress&utm_medium=plugin&utm_campaign=author_uri
  • opt-out-for-google-analytics/trunk/inc/admin.class.php

    r2787042 r2896199  
    11<?php
    22
    3     // If this file is called directly, abort.
    4     defined( 'WPINC' ) || die;
    5 
    6     class GAOO_Admin {
    7 
    8         private $messages;
    9         private $csstidy;
    10         private $plugin;
    11         private $promotion;
    12 
    13         /**
    14          * GAOO_Admin constructor.
    15          */
    16         public function __construct() {
    17             add_action( 'admin_menu', array(
     3// If this file is called directly, abort.
     4defined('WPINC') || die;
     5
     6class GAOO_Admin
     7{
     8
     9    private $messages;
     10    private $csstidy;
     11    private $plugin;
     12    private $promotion;
     13
     14    /**
     15     * GAOO_Admin constructor.
     16     */
     17    public function __construct()
     18    {
     19        add_action('admin_menu', array(
     20            $this,
     21            'menu'
     22        ));
     23
     24        add_action('admin_notices', array(
     25            $this,
     26            'admin_notices'
     27        ));
     28
     29        add_action('admin_enqueue_scripts', array(
     30            $this,
     31            'enqueue_scripts'
     32        ));
     33
     34        add_action('save_post_page', array(
     35            $this,
     36            'save_page'
     37        ), 10, 1);
     38
     39        add_action('gaoo_cronjob', array(
     40            $this,
     41            'send_status_mail'
     42        ));
     43
     44        add_action('wp_dashboard_setup', array(
     45            $this,
     46            'add_dashboard_widget'
     47        ));
     48
     49        add_action('upgrader_process_complete', array(
     50            $this,
     51            'upgrader_process_complete'
     52        ), 10, 2);
     53
     54        add_action('admin_notices', array(
     55            'GAOO_Promo',
     56            'render_admin_notice'
     57        ));
     58
     59
     60        add_filter('plugin_action_links', array(
     61            $this,
     62            'plugin_action_links'
     63        ), 10, 2);
     64
     65        add_action('plugin_row_meta', array(
     66            $this,
     67            'plugin_row_meta'
     68        ), 10, 2);
     69
     70        $this->plugin = GAOO_PLUGIN_NAME . DIRECTORY_SEPARATOR . 'ga-opt-out.php';
     71        $this->messages = GAOO_Messages::getInstance();
     72        $this->csstidy = new csstidy();
     73        $this->promotion = GAOO_Promo::get_links();
     74
     75        $this->add_tinymce_button();
     76    }
     77
     78    /**
     79     * Handling functions after the update completed for this plugin.
     80     *
     81     * @param WP_Upgrader $upgrader_object WP_Upgrader instance. In other contexts this might be a Theme_Upgrader, Plugin_Upgrader, Core_Upgrade, or Language_Pack_Upgrader instance.
     82     * @param array $options Array of bulk item update data.
     83     */
     84    function upgrader_process_complete($upgrader_object, $options)
     85    {
     86        if ($options['action'] == 'update' && $options['type'] == 'plugin' && isset($options['plugins']) && in_array(plugin_basename(__FILE__), $options['plugins'])) {
     87            GAOO_Promo::clear_cache();
     88        }
     89    }
     90
     91    /**
     92     * Load TinyMCE filters and hooks
     93     */
     94    public function add_tinymce_button()
     95    {
     96        global $post;
     97
     98        $post_id = !empty($post) ? $post->ID : filter_input(INPUT_GET, 'post', FILTER_SANITIZE_NUMBER_INT);
     99
     100        // Check if it is the WP Privacy page and user has access to it
     101        if (!current_user_can('edit_pages') || empty($post_id) || $post_id != get_option('wp_page_for_privacy_policy', 0) || get_user_option('rich_editing') != 'true') {
     102            return;
     103        }
     104
     105        add_filter("mce_external_plugins", array(
     106            $this,
     107            'add_tinymce_plugin'
     108        ));
     109        add_filter('mce_buttons', array(
     110            $this,
     111            'register_tinymce_button'
     112        ));
     113    }
     114
     115    /**
     116     * Render the dashboard widget content.
     117     */
     118    public function render_dashboard_widget()
     119    {
     120        GAOO_Utils::render_checklist();
     121
     122        $promo = GAOO_Promo::get_data();
     123        $links = array(
     124            array(
     125                'link' => esc_url(admin_url('options-general.php?page=gaoo')),
     126                'text' => esc_html__('Settings'),
     127            ),
     128        );
     129
     130        if (!empty($promo) && !empty($promo['promo'])) {
     131            $promo = array_pop($promo['promo']);
     132
     133            if (empty($promo['hide_if_active']) || !is_array($promo['hide_if_active']) || !GAOO_Promo::should_hide($promo['hide_if_active'])) {
     134                $links[] = array(
     135                    'link' => $promo['link'],
     136                    'text' => $promo['link_text'],
     137                    'target' => '_blank',
     138                );
     139            }
     140        }
     141
     142        echo '<ul class="subsubsub">';
     143
     144        foreach ($links as $link) {
     145            printf('<li><a href="%s" %s>%s</a></li>', $link['link'], (empty($link['target']) ? '' : 'target="' . esc_attr($link['target']) . '"'), $link['text']);
     146        }
     147
     148        echo '</ul>';
     149    }
     150
     151    /**
     152     * Add new dashboard widgets.
     153     */
     154    public function add_dashboard_widget()
     155    {
     156        if (GAOO_Utils::get_option('disable_dashboard') != 'on') {
     157            wp_add_dashboard_widget('ga-opt-out', esc_html__('Opt-Out for Google Analytics - Status Check', 'opt-out-for-google-analytics'), array(
    18158                $this,
    19                 'menu'
    20             ) );
    21 
    22             add_action( 'admin_notices', array(
    23                 $this,
    24                 'admin_notices'
    25             ) );
    26 
    27             add_action( 'admin_enqueue_scripts', array(
    28                 $this,
    29                 'enqueue_scripts'
    30             ) );
    31 
    32             add_action( 'save_post_page', array(
    33                 $this,
    34                 'save_page'
    35             ), 10, 1 );
    36 
    37             add_action( 'gaoo_cronjob', array(
    38                 $this,
    39                 'send_status_mail'
    40             ) );
    41 
    42             add_action( 'wp_dashboard_setup', array(
    43                 $this,
    44                 'add_dashboard_widget'
    45             ) );
    46 
    47             add_action( 'upgrader_process_complete', array(
    48                 $this,
    49                 'upgrader_process_complete'
    50             ), 10, 2 );
    51 
    52             add_action( 'admin_notices', array(
    53                 'GAOO_Promo',
    54                 'render_admin_notice'
    55             ) );
    56 
    57 
    58             add_filter( 'plugin_action_links', array(
    59                 $this,
    60                 'plugin_action_links'
    61             ), 10, 2 );
    62 
    63             add_action( 'plugin_row_meta', array(
    64                 $this,
    65                 'plugin_row_meta'
    66             ), 10, 2 );
    67 
    68             $this->plugin    = GAOO_PLUGIN_NAME . DIRECTORY_SEPARATOR . 'ga-opt-out.php';
    69             $this->messages  = GAOO_Messages::getInstance();
    70             $this->csstidy   = new csstidy();
    71             $this->promotion = GAOO_Promo::get_links();
    72 
    73             $this->add_tinymce_button();
    74         }
    75 
    76         /**
    77          * Handling functions after the update completed for this plugin.
    78          *
    79          * @param WP_Upgrader $upgrader_object WP_Upgrader instance. In other contexts this might be a Theme_Upgrader, Plugin_Upgrader, Core_Upgrade, or Language_Pack_Upgrader instance.
    80          * @param array $options Array of bulk item update data.
    81          */
    82         function upgrader_process_complete( $upgrader_object, $options ) {
    83             if ( $options[ 'action' ] == 'update' && $options[ 'type' ] == 'plugin' && isset( $options[ 'plugins' ] ) && in_array( plugin_basename( __FILE__ ), $options[ 'plugins' ] ) ) {
    84                 GAOO_Promo::clearCache();
    85             }
    86         }
    87 
    88         /**
    89          * Load TinyMCE filters and hooks
    90          */
    91         public function add_tinymce_button() {
    92             global $post;
    93 
    94             $post_id = ! empty( $post ) ? $post->ID : filter_input( INPUT_GET, 'post', FILTER_SANITIZE_NUMBER_INT );
    95 
    96             // Check if it is the WP Privacy page and user has access to it
    97             if ( ! current_user_can( 'edit_pages' ) || empty( $post_id ) || $post_id != get_option( 'wp_page_for_privacy_policy', 0 ) || get_user_option( 'rich_editing' ) != 'true' ) {
    98                 return;
    99             }
    100 
    101             add_filter( "mce_external_plugins", array(
    102                 $this,
    103                 'add_tinymce_plugin'
    104             ) );
    105             add_filter( 'mce_buttons', array(
    106                 $this,
    107                 'register_tinymce_button'
    108             ) );
    109         }
    110 
    111         /**
    112          * Render the dashboard widget content.
    113          */
    114         public function render_dashboard_widget() {
    115             GAOO_Utils::render_checklist();
    116 
    117             $promo = GAOO_Promo::get_data();
    118             $links = array(
    119                 array(
    120                     'link' => esc_url( admin_url( 'options-general.php?page=gaoo' ) ),
    121                     'text' => esc_html__( 'Settings' ),
     159                'render_dashboard_widget'
     160            ));
     161        }
     162    }
     163
     164    /**
     165     * Clear the checklist cache after the page saved.
     166     *
     167     * @param int $post_id ID of the post
     168     */
     169    public function save_page($post_id)
     170    {
     171        // run only if this page is configured for the monitoring
     172        if ($post_id != GAOO_Utils::get_option('privacy_page_id') || $post_id != GAOO_Utils::get_option('wp_privacy_page')) {
     173            return;
     174        }
     175
     176        GAOO_Utils::delete_todo_cache();
     177    }
     178
     179    /**
     180     * Add this plugin to TinyMCE.
     181     *
     182     * @param array $plugins List with plugin URLs
     183     *
     184     * @return array List with plugin URLs
     185     */
     186    public function add_tinymce_plugin($plugins)
     187    {
     188        $plugins['gaoptout'] = GAOO_PLUGIN_URL . '/assets/tinymce.js';
     189
     190        return $plugins;
     191    }
     192
     193    /**
     194     * Add buttons to TinyMCE.
     195     *
     196     * @param array $buttons List of buttons
     197     *
     198     * @return array List of buttons
     199     */
     200    public function register_tinymce_button($buttons)
     201    {
     202        array_push($buttons, "gaoptout");
     203
     204        return $buttons;
     205    }
     206
     207    /**
     208     * Add menu items to the admin menu
     209     */
     210    public function menu()
     211    {
     212        add_options_page('Opt-Out for Google Analytics', 'GA Opt-Out', GAOO_CAPABILITY, 'gaoo', array(
     213            $this,
     214            'menu_settings'
     215        ));
     216    }
     217
     218    /**
     219     * Customize the action links.
     220     *
     221     * @param array $links Actions links.
     222     * @param string $file Filename of the activated plugin.
     223     *
     224     * @return array Action links.
     225     */
     226    public function plugin_action_links($links, $file)
     227    {
     228        if ($file == $this->plugin) {
     229            $links[] = '<a href="' . esc_url(admin_url('options-general.php?page=gaoo')) . '">' . esc_html__('Settings') . '</a>';
     230        }
     231
     232        return $links;
     233    }
     234
     235    /**
     236     * Plugin row meta links
     237     *
     238     * @param array $links already defined meta links.
     239     * @param string $file plugin file path and name being processed.
     240     *
     241     * @return array $input
     242     * @since 1.1
     243     *
     244     */
     245    function plugin_row_meta($links, $file)
     246    {
     247        if ($file == $this->plugin) {
     248            $links[] = "<a href='https://wordpress.org/support/plugin/opt-out-for-google-analytics/reviews/?rate=5#new-post' target='_blank'>" . esc_html__('Rate:', 'opt-out-for-google-analytics') . "<i class='gaoo-rate-stars'>" . "<svg xmlns='http://www.w3.org/2000/svg' width='15' height='15' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round' class='feather feather-star'><polygon points='12 2 15.09 8.26 22 9.27 17 14.14 18.18 21.02 12 17.77 5.82 21.02 7 14.14 2 9.27 8.91 8.26 12 2'/></svg>" . "<svg xmlns='http://www.w3.org/2000/svg' width='15' height='15' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round' class='feather feather-star'><polygon points='12 2 15.09 8.26 22 9.27 17 14.14 18.18 21.02 12 17.77 5.82 21.02 7 14.14 2 9.27 8.91 8.26 12 2'/></svg>" . "<svg xmlns='http://www.w3.org/2000/svg' width='15' height='15' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round' class='feather feather-star'><polygon points='12 2 15.09 8.26 22 9.27 17 14.14 18.18 21.02 12 17.77 5.82 21.02 7 14.14 2 9.27 8.91 8.26 12 2'/></svg>" . "<svg xmlns='http://www.w3.org/2000/svg' width='15' height='15' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round' class='feather feather-star'><polygon points='12 2 15.09 8.26 22 9.27 17 14.14 18.18 21.02 12 17.77 5.82 21.02 7 14.14 2 9.27 8.91 8.26 12 2'/></svg>" . "<svg xmlns='http://www.w3.org/2000/svg' width='15' height='15' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round' class='feather feather-star'><polygon points='12 2 15.09 8.26 22 9.27 17 14.14 18.18 21.02 12 17.77 5.82 21.02 7 14.14 2 9.27 8.91 8.26 12 2'/></svg>" . "</i></a>";
     249
     250            if (!empty($this->promotion)) {
     251                foreach ($this->promotion as $item) {
     252                    $links[] = '<strong><a target="_blank" href="' . esc_url($item['link']) . '">' . esc_html($item['link_text']) . '</a></strong>';
     253                }
     254            }
     255        }
     256
     257        return $links;
     258    }
     259
     260    /**
     261     * Enqueue scripts and styles for the admin pages.
     262     */
     263    public function enqueue_scripts()
     264    {
     265        wp_enqueue_style('gaoo-admin-styles', GAOO_PLUGIN_URL . '/assets/admin.css', array(), GAOO_VERSION);
     266
     267        // Run only if functionallity on the right pages
     268        if (isset($_GET['page']) && $_GET['page'] === 'gaoo') {
     269            wp_enqueue_script('gaoo-admin-script', GAOO_PLUGIN_URL . '/assets/admin.js', array('jquery'), GAOO_VERSION, true);
     270
     271            wp_localize_script('gaoo-admin-script', 'gaoo', array(
     272                'edit_link' => esc_url(admin_url('post.php?action=edit&post=%d')),
     273                'text' => array(
     274                    'copied' => esc_html__('Copied!', 'opt-out-for-google-analytics'),
     275                    'notcopied' => esc_html__("Couldn't copy!", 'opt-out-for-google-analytics'),
    122276                ),
    123             );
    124 
    125             if ( ! empty( $promo ) && ! empty( $promo[ 'promo' ] ) ) {
    126                 $promo = array_pop( $promo[ 'promo' ] );
    127 
    128                 if ( empty( $promo[ 'hide_if_active' ] ) || ! is_array( $promo[ 'hide_if_active' ] ) || ! GAOO_Promo::should_hide( $promo[ 'hide_if_active' ] ) ) {
    129                     $links[] = array(
    130                         'link'   => $promo[ 'link' ],
    131                         'text'   => $promo[ 'link_text' ],
    132                         'target' => '_blank',
    133                     );
    134                 }
    135             }
    136 
    137             echo '<ul class="subsubsub">';
    138 
    139             foreach ( $links as $link ) {
    140                 printf( '<li><a href="%s" %s>%s</a></li>', $link[ 'link' ], ( empty( $link[ 'target' ] ) ? '' : 'target="' . esc_attr( $link[ 'target' ] ) . '"' ), $link[ 'text' ] );
    141             }
    142 
    143             echo '</ul>';
    144         }
    145 
    146         /**
    147          * Add new dashboard widgets.
    148          */
    149         public function add_dashboard_widget() {
    150             if ( GAOO_Utils::get_option( 'disable_dashboard' ) != 'on' ) {
    151                 wp_add_dashboard_widget( 'ga-opt-out', esc_html__( 'Opt-Out for Google Analytics - Status Check', 'opt-out-for-google-analytics' ), array(
    152                     $this,
    153                     'render_dashboard_widget'
    154                 ) );
    155             }
    156         }
    157 
    158         /**
    159          * Clear the checklist cache after the page saved.
    160          *
    161          * @param int $post_id ID of the post
    162          */
    163         public function save_page( $post_id ) {
    164             // run only if this page is configured for the monitoring
    165             if ( $post_id != GAOO_Utils::get_option( 'privacy_page_id' ) || $post_id != GAOO_Utils::get_option( 'wp_privacy_page' ) ) {
    166                 return;
    167             }
    168 
     277            ));
     278        }
     279
     280        // Load the Gutenberg block
     281        $current_screen = get_current_screen();
     282
     283        if (!empty($current_screen) && method_exists($current_screen, 'is_block_editor') && $current_screen->is_block_editor()) {
     284            wp_enqueue_script('gaoo-block', GAOO_PLUGIN_URL . '/assets/optout-block.js', array(
     285                'wp-blocks',
     286                'wp-editor'
     287            ), GAOO_VERSION);
     288        }
     289    }
     290
     291    /**
     292     * Add admin notices, if function is enabled and no UA code is configured.
     293     */
     294    public function admin_notices()
     295    {
     296        if ((isset($_GET['page']) && $_GET['page'] == 'gaoo') && $this->is_cronjob_disabled()) {
     297            echo '<div class="notice update-nag is-dismissable"><p>' . esc_html__('It seems like you have disabled the cronjob through your wp-config.php ... Please make sure that you have installed a server-side cronjob, otherwise you wont receive the status reports via mail.', 'opt-out-for-google-analytics') . '</p></div>';
     298        }
     299
     300        // Run only if open todos available.
     301        if (!current_user_can(GAOO_CAPABILITY) || GAOO_Utils::get_option('disable_monitoring', false) || !GAOO_Utils::has_todos() || (isset($_GET['page']) && $_GET['page'] == 'gaoo')) {
     302            return;
     303        }
     304
     305        echo '<div class="notice notice-error is-dismissable"><p>' . sprintf(__('Google Analytics does not appear to function in compliance with data protection regulations. Please check the settings <a href="%s">here</a>.', 'opt-out-for-google-analytics'), esc_url(admin_url('options-general.php?page=gaoo'))) . '</p></div>';
     306    }
     307
     308    /**
     309     * Check if cronjob is disabled, if status mails should be send.
     310     *
     311     * @return bool True if disabled, otherwise false.
     312     */
     313    private function is_cronjob_disabled()
     314    {
     315        return defined('DISABLE_WP_CRON') && DISABLE_WP_CRON && !empty(GAOO_Utils::get_option('status_mails', false));
     316    }
     317
     318    /**
     319     * Show the settings page.
     320     */
     321    public function menu_settings()
     322    {
     323        // Handle form save
     324        $form_data = isset($_POST['gaoo']) ? $this->save_menu_settings() : GAOO_Utils::get_options();
     325
     326        $ga_plugins = array(
     327            'monsterinsights' => array(
     328                'label' => 'MonsterInsights – Google Analytics Dashboard for WordPress (Website Stats Made Easy)',
     329                'url_install' => admin_url('plugin-install.php?tab=search&s=Google+Analytics+MonsterInsights'),
     330                'url_activate' => admin_url('plugins.php?plugin_status=inactive&s=MonsterInsights'),
     331                'is_active' => (is_plugin_active('google-analytics-premium' . DIRECTORY_SEPARATOR . 'googleanalytics-premium.php') || is_plugin_active('google-analytics-for-wordpress' . DIRECTORY_SEPARATOR . 'googleanalytics.php')),
     332                'is_installed' => (file_exists(WP_PLUGIN_DIR . DIRECTORY_SEPARATOR . 'google-analytics-premium' . DIRECTORY_SEPARATOR . 'googleanalytics-premium.php') || file_exists(WP_PLUGIN_DIR . DIRECTORY_SEPARATOR . 'google-analytics-for-wordpress' . DIRECTORY_SEPARATOR . 'googleanalytics.php')),
     333            ),
     334            'gadash' => array(
     335                'label' => 'ExactMetrics – Google Analytics Dashboard for WordPress (Website Stats Plugin)',
     336                'url_install' => admin_url('plugin-install.php?tab=search&s=exactmetrics+google+analytics'),
     337                'url_activate' => admin_url('plugins.php?plugin_status=inactive&s=GADWP'),
     338                'is_active' => is_plugin_active('google-analytics-dashboard-for-wp' . DIRECTORY_SEPARATOR . 'gadwp.php'),
     339                'is_installed' => file_exists(WP_PLUGIN_DIR . DIRECTORY_SEPARATOR . 'google-analytics-dashboard-for-wp' . DIRECTORY_SEPARATOR . 'gadwp.php'),
     340            ),
     341            'analytify' => array(
     342                'label' => 'Analytify – Google Analytics Dashboard Plugin For WordPress',
     343                'url_install' => admin_url('plugin-install.php?tab=search&s=Analytify'),
     344                'url_activate' => admin_url('plugins.php?plugin_status=inactive&s=Analytify'),
     345                'target' => '_blank',
     346                'is_active' => is_plugin_active('wp-analytify' . DIRECTORY_SEPARATOR . 'wp-analytify.php'),
     347                'is_installed' => file_exists(WP_PLUGIN_DIR . DIRECTORY_SEPARATOR . 'wp-analytify' . DIRECTORY_SEPARATOR . 'wp-analytify.php'),
     348            ),
     349            'gaga' => array(
     350                'label' => 'GA Google Analytics',
     351                'url_install' => admin_url('plugin-install.php?tab=search&s=GA+Google+Analytics'),
     352                'url_activate' => admin_url('plugins.php?plugin_status=inactive&s=GA+Google'),
     353                'target' => '_blank',
     354                'is_active' => is_plugin_active('ga-google-analytics' . DIRECTORY_SEPARATOR . 'ga-google-analytics.php'),
     355                'is_installed' => file_exists(WP_PLUGIN_DIR . DIRECTORY_SEPARATOR . '/ga-google-analytics' . DIRECTORY_SEPARATOR . 'ga-google-analytics.php'),
     356            ),
     357            'sitekit' => array(
     358                'label' => 'Site Kit by Google – Analytics, Search Console, AdSense, Speed',
     359                'url_install' => admin_url('plugin-install.php?tab=search&s=Google+site+kit'),
     360                'url_activate' => admin_url('plugins.php?plugin_status=inactive&s=site+kit'),
     361                'target' => '_blank',
     362                'is_active' => is_plugin_active('google-site-kit' . DIRECTORY_SEPARATOR . 'google-site-kit.php'),
     363                'is_installed' => file_exists(WP_PLUGIN_DIR . DIRECTORY_SEPARATOR . 'google-site-kit' . DIRECTORY_SEPARATOR . 'google-site-kit.php'),
     364            ),
     365        );
     366
     367        extract($form_data);
     368
     369        // if plugin set as current but not installed or activated, remove it from settings
     370        if (!empty($ga_plugin) && isset($ga_plugins[$ga_plugin]) && ((isset($ga_plugins[$ga_plugin]['is_active']) && !$ga_plugins[$ga_plugin]['is_active']) || isset($ga_plugins[$ga_plugin]['is_installed']) && !$ga_plugins[$ga_plugin]['is_installed'])) {
     371            delete_option(GAOO_PREFIX . 'ga_plugin');
     372            $ga_plugin = null;
     373        }
     374
     375        $wp_privacy_page_id = get_option('wp_page_for_privacy_policy', 0);
     376        $wp_admin_mail = get_option('admin_email', null);
     377        $promotion = $this->promotion;
     378
     379        include_once GAOO_PLUGIN_DIR . DIRECTORY_SEPARATOR . 'templates' . DIRECTORY_SEPARATOR . 'settings.php';
     380    }
     381
     382    /**
     383     * Handle the submited form data.
     384     *
     385     * @return array Stored options with the value.
     386     */
     387    private function save_menu_settings()
     388    {
     389
     390        // Check if form submited by the right site
     391        if (!isset($_REQUEST['_wpnonce']) || !wp_verify_nonce($_REQUEST['_wpnonce'], 'gaoo-settings')) {
     392            $this->messages->addError(esc_html__('Security check fail!', 'opt-out-for-google-analytics'));
     393
     394            return array();
     395        }
     396
     397        // Validate inputs
     398        $skip_save = array();
     399        $data = filter_var_array($_POST['gaoo'], array(
     400            'ga_plugin' => FILTER_UNSAFE_RAW,
     401            'link_deactivate' => FILTER_UNSAFE_RAW,
     402            'link_activate' => FILTER_UNSAFE_RAW,
     403            'ua_code' => FILTER_UNSAFE_RAW,
     404            'popup_deactivate' => FILTER_UNSAFE_RAW,
     405            'popup_activate' => FILTER_UNSAFE_RAW,
     406            'status' => FILTER_UNSAFE_RAW,
     407            'privacy_page_id' => FILTER_SANITIZE_NUMBER_INT,
     408            'disable_monitoring' => FILTER_SANITIZE_NUMBER_INT,
     409            'force_reload' => FILTER_SANITIZE_NUMBER_INT,
     410            'wp_privacy_page' => FILTER_SANITIZE_NUMBER_INT,
     411            'custom_css' => FILTER_UNSAFE_RAW,
     412            'tracking_code' => FILTER_UNSAFE_RAW,
     413            'status_intervall' => FILTER_UNSAFE_RAW,
     414            'status_mails' => FILTER_SANITIZE_EMAIL,
     415            'uninstall_keep_data' => FILTER_UNSAFE_RAW,
     416            'disable_dashboard' => FILTER_UNSAFE_RAW,
     417            'status_mails_sync' => FILTER_SANITIZE_NUMBER_INT,
     418        ), false);
     419
     420        // Sanitize string / text
     421        $text_fields = array('ga_plugin', 'popup_activate', 'popup_deactivate', 'ua_code', 'link_activate', 'link_deactivate');
     422
     423        foreach ($text_fields as $text_field) {
     424            if (empty($data[$text_field])) {
     425                continue;
     426            }
     427
     428            $data[$text_field] = htmlspecialchars($data[$text_field], ENT_QUOTES);
     429        }
     430
     431        // Validate checkboxes
     432        $checkboxes = array('status', 'uninstall_keep_data', 'disable_dashboard');
     433
     434        foreach ($checkboxes as $checkbox) {
     435            if (!isset($data[$checkbox])) {
     436                continue;
     437            }
     438
     439            if ($data[$checkbox] != 'on' && $data[$checkbox] != 'off') {
     440                $data[$checkbox] = 'off';
     441            }
     442        }
     443
     444        // Validate UA code if entered manually, otherwise empty field.
     445        if ($data['ga_plugin'] == 'manual' && !empty($data['ua_code'])) {
     446            $data['ua_code'] = GAOO_Utils::validate_ua_code(strtoupper($data['ua_code']));
     447
     448            if (empty($data['ua_code'])) {
     449                $this->messages->addError(esc_html__("Please enter a valid UA- or G-Code (Google Analytics 4). Format: UA-XXXXXX-Y or G-XXXXXXXXXX", 'opt-out-for-google-analytics'));
     450            }
     451        } else {
     452            $data['ua_code'] = '';
     453            $data['tracking_code'] = '';
     454        }
     455
     456        // Validate status intervall
     457        if (isset($data['status_intervall']) && !in_array($data['status_intervall'], array('daily', 'monthly', 'weekly'))) {
     458            $data['status_intervall'] = 'weekly';
     459        }
     460
     461        // Removes space from start and end of the text.
     462        $data['link_activate'] = trim($data['link_activate']);
     463        $data['link_deactivate'] = trim($data['link_deactivate']);
     464        $data['popup_activate'] = trim($data['popup_activate']);
     465        $data['popup_deactivate'] = trim($data['popup_deactivate']);
     466        $data['tracking_code'] = trim($data['tracking_code']);
     467
     468        // Check and validate the custom css code
     469        if (!empty($data['custom_css'])) {
     470            if (!$this->csstidy->parse(stripslashes($data['custom_css']))) {
     471                $skip_save[] = 'custom_css';
     472                $this->messages->addWarning(esc_html__("Your custom css code was not stored, because it is not valid! We stoll hold the old version of it, please check below the code and save again.", 'opt-out-for-google-analytics'));
     473            } else {
     474                $data['custom_css'] = $this->csstidy->print->plain();
     475            }
     476        }
     477
     478        // Store only validated mails into database
     479        if (!empty($data['status_mails'])) {
     480            $mails = explode(',', $data['status_mails']);
     481            $mails = array_filter(array_map('trim', $mails), 'is_email');
     482
     483            $data['status_mails'] = empty($mails) ? '' : implode(',', $mails);
     484        }
     485
     486        if (empty($data['link_deactivate'])) {
     487            $this->messages->addError(esc_html__("Please enter the text for the deactivate link, otherwise link doesn't appears!", 'opt-out-for-google-analytics'));
     488        }
     489
     490        if (empty($data['link_activate'])) {
     491            $this->messages->addError(esc_html__("Please enter the text for the activate link, otherwise link doesn't appears!", 'opt-out-for-google-analytics'));
     492        }
     493
     494        if ($this->messages->hasError()) {
     495            return $data;
     496        }
     497
     498        // If an option is not set, fill it with the default value.
     499        $data = array_merge(GAOO_Utils::get_options_list(), $data);
     500        $old_status_intervall = GAOO_Utils::get_option('status_intervall');
     501
     502        // Sync. with WP Privacy page
     503        if (!empty($data['wp_privacy_page'])) {
     504            $data['privacy_page_id'] = get_option('wp_page_for_privacy_policy', 0);
     505        }
     506
     507        foreach ($data as $k => $v) {
     508            if (!in_array($k, $skip_save, true)) {
     509                update_option(GAOO_PREFIX . $k, $v);
     510            }
     511        }
     512
     513        // Show warniung if cronjob is disabled
     514        if ($this->is_cronjob_disabled()) {
     515            $this->messages->addWarning(esc_html__('It seems like you have disabled the cronjob through your wp-config.php ... Please make sure that you have installed a server-side cronjob, otherwise you wont receive the status reports via mail.', 'opt-out-for-google-analytics'));
     516        }
     517
     518        // Restart cronjob etc. if intervall is changed
     519        if ($old_status_intervall != $data['status_intervall']) {
    169520            GAOO_Utils::delete_todo_cache();
    170         }
    171 
    172         /**
    173          * Add this plugin to TinyMCE.
    174          *
    175          * @param array $plugins List with plugin URLs
    176          *
    177          * @return array List with plugin URLs
    178          */
    179         public function add_tinymce_plugin( $plugins ) {
    180             $plugins[ 'gaoptout' ] = GAOO_PLUGIN_URL . '/assets/tinymce.js';
    181 
    182             return $plugins;
    183         }
    184 
    185         /**
    186          * Add buttons to TinyMCE.
    187          *
    188          * @param array $buttons List of buttons
    189          *
    190          * @return array List of buttons
    191          */
    192         public function register_tinymce_button( $buttons ) {
    193             array_push( $buttons, "gaoptout" );
    194 
    195             return $buttons;
    196         }
    197 
    198         /**
    199          * Add menu items to the admin menu
    200          */
    201         public function menu() {
    202             add_options_page( 'Opt-Out for Google Analytics', 'GA Opt-Out', GAOO_CAPABILITY, 'gaoo', array(
    203                 $this,
    204                 'menu_settings'
    205             ) );
    206         }
    207 
    208         /**
    209          * Customize the action links.
    210          *
    211          * @param array $links Actions links.
    212          * @param string $file Filename of the activated plugin.
    213          *
    214          * @return array Action links.
    215          */
    216         public function plugin_action_links( $links, $file ) {
    217             if ( $file == $this->plugin ) {
    218                 $links[] = '<a href="' . esc_url( admin_url( 'options-general.php?page=gaoo' ) ) . '">' . esc_html__( 'Settings' ) . '</a>';
    219             }
    220 
    221             return $links;
    222         }
    223 
    224         /**
    225          * Plugin row meta links
    226          *
    227          * @param array $links already defined meta links.
    228          * @param string $file plugin file path and name being processed.
    229          *
    230          * @return array $input
    231          * @since 1.1
    232          *
    233          */
    234         function plugin_row_meta( $links, $file ) {
    235             if ( $file == $this->plugin ) {
    236                 $links[] = "<a href='https://wordpress.org/support/plugin/opt-out-for-google-analytics/reviews/?rate=5#new-post' target='_blank'>" . esc_html__( 'Rate:', 'opt-out-for-google-analytics' ) . "<i class='gaoo-rate-stars'>" . "<svg xmlns='http://www.w3.org/2000/svg' width='15' height='15' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round' class='feather feather-star'><polygon points='12 2 15.09 8.26 22 9.27 17 14.14 18.18 21.02 12 17.77 5.82 21.02 7 14.14 2 9.27 8.91 8.26 12 2'/></svg>" . "<svg xmlns='http://www.w3.org/2000/svg' width='15' height='15' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round' class='feather feather-star'><polygon points='12 2 15.09 8.26 22 9.27 17 14.14 18.18 21.02 12 17.77 5.82 21.02 7 14.14 2 9.27 8.91 8.26 12 2'/></svg>" . "<svg xmlns='http://www.w3.org/2000/svg' width='15' height='15' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round' class='feather feather-star'><polygon points='12 2 15.09 8.26 22 9.27 17 14.14 18.18 21.02 12 17.77 5.82 21.02 7 14.14 2 9.27 8.91 8.26 12 2'/></svg>" . "<svg xmlns='http://www.w3.org/2000/svg' width='15' height='15' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round' class='feather feather-star'><polygon points='12 2 15.09 8.26 22 9.27 17 14.14 18.18 21.02 12 17.77 5.82 21.02 7 14.14 2 9.27 8.91 8.26 12 2'/></svg>" . "<svg xmlns='http://www.w3.org/2000/svg' width='15' height='15' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round' class='feather feather-star'><polygon points='12 2 15.09 8.26 22 9.27 17 14.14 18.18 21.02 12 17.77 5.82 21.02 7 14.14 2 9.27 8.91 8.26 12 2'/></svg>" . "</i></a>";
    237 
    238                 if ( ! empty( $this->promotion ) ) {
    239                     foreach ( $this->promotion as $item ) {
    240                         $links[] = '<strong><a target="_blank" href="' . esc_url( $item[ 'link' ] ) . '">' . esc_html( $item[ 'link_text' ] ) . '</a></strong>';
    241                     }
    242                 }
    243             }
    244 
    245             return $links;
    246         }
    247 
    248         /**
    249          * Enqueue scripts and styles for the admin pages.
    250          */
    251         public function enqueue_scripts() {
    252             wp_enqueue_style( 'gaoo-admin-styles', GAOO_PLUGIN_URL . '/assets/admin.css', array(), GAOO_VERSION );
    253 
    254             // Run only if functionallity on the right pages
    255             if ( isset( $_GET[ 'page' ] ) && $_GET[ 'page' ] === 'gaoo' ) {
    256                 wp_enqueue_script( 'gaoo-admin-script', GAOO_PLUGIN_URL . '/assets/admin.js', array( 'jquery' ), GAOO_VERSION, true );
    257 
    258                 wp_localize_script( 'gaoo-admin-script', 'gaoo', array(
    259                     'edit_link' => esc_url( admin_url( 'post.php?action=edit&post=%d' ) ),
    260                     'text'      => array(
    261                         'copied'    => esc_html__( 'Copied!', 'opt-out-for-google-analytics' ),
    262                         'notcopied' => esc_html__( "Couldn't copy!", 'opt-out-for-google-analytics' ),
    263                     ),
    264                 ) );
    265             }
    266 
    267             // Load the Gutenberg block
    268             $current_screen = get_current_screen();
    269 
    270             if ( ! empty( $current_screen ) && method_exists( $current_screen, 'is_block_editor' ) && $current_screen->is_block_editor() ) {
    271                 wp_enqueue_script( 'gaoo-block', GAOO_PLUGIN_URL . '/assets/optout-block.js', array(
    272                     'wp-blocks',
    273                     'wp-editor'
    274                 ), GAOO_VERSION );
    275             }
    276         }
    277 
    278         /**
    279          * Add admin notices, if function is enabled and no UA code is configured.
    280          */
    281         public function admin_notices() {
    282             if ( ( isset( $_GET[ 'page' ] ) && $_GET[ 'page' ] == 'gaoo' ) && $this->is_cronjob_disabled() ) {
    283                 echo '<div class="notice update-nag is-dismissable"><p>' . esc_html__( 'It seems like you have disabled the cronjob through your wp-config.php ... Please make sure that you have installed a server-side cronjob, otherwise you wont receive the status reports via mail.', 'opt-out-for-google-analytics' ) . '</p></div>';
    284             }
    285 
    286             // Run only if open todos available.
    287             if ( ! current_user_can( GAOO_CAPABILITY ) || GAOO_Utils::get_option( 'disable_monitoring', false ) || ! GAOO_Utils::has_todos() || ( isset( $_GET[ 'page' ] ) && $_GET[ 'page' ] == 'gaoo' ) ) {
    288                 return;
    289             }
    290 
    291             echo '<div class="notice notice-error is-dismissable"><p>' . sprintf( __( 'Google Analytics does not appear to function in compliance with data protection regulations. Please check the settings <a href="%s">here</a>.', 'opt-out-for-google-analytics' ), esc_url( admin_url( 'options-general.php?page=gaoo' ) ) ) . '</p></div>';
    292         }
    293 
    294         /**
    295          * Check if cronjob is disabled, if status mails should be send.
    296          *
    297          * @return bool True if disabled, otherwise false.
    298          */
    299         private function is_cronjob_disabled() {
    300             return defined( 'DISABLE_WP_CRON' ) && DISABLE_WP_CRON && ! empty( GAOO_Utils::get_option( 'status_mails', false ) );
    301         }
    302 
    303         /**
    304          * Show the settings page.
    305          */
    306         public function menu_settings() {
    307             // Handle form save
    308             $form_data = isset( $_POST[ 'gaoo' ] ) ? $this->save_menu_settings() : GAOO_Utils::get_options();
    309 
    310             $ga_plugins = array(
    311                 'monsterinsights' => array(
    312                     'label'        => 'MonsterInsights – Google Analytics Dashboard for WordPress (Website Stats Made Easy)',
    313                     'url_install'  => admin_url( 'plugin-install.php?tab=search&s=Google+Analytics+MonsterInsights' ),
    314                     'url_activate' => admin_url( 'plugins.php?plugin_status=inactive&s=MonsterInsights' ),
    315                     'is_active'    => ( is_plugin_active( 'google-analytics-premium' . DIRECTORY_SEPARATOR . 'googleanalytics-premium.php' ) || is_plugin_active( 'google-analytics-for-wordpress' . DIRECTORY_SEPARATOR . 'googleanalytics.php' ) ),
    316                     'is_installed' => ( file_exists( WP_PLUGIN_DIR . DIRECTORY_SEPARATOR . 'google-analytics-premium' . DIRECTORY_SEPARATOR . 'googleanalytics-premium.php' ) || file_exists( WP_PLUGIN_DIR . DIRECTORY_SEPARATOR . 'google-analytics-for-wordpress' . DIRECTORY_SEPARATOR . 'googleanalytics.php' ) ),
    317                 ),
    318                 'gadash'          => array(
    319                     'label'        => 'ExactMetrics – Google Analytics Dashboard for WordPress (Website Stats Plugin)',
    320                     'url_install'  => admin_url( 'plugin-install.php?tab=search&s=exactmetrics+google+analytics' ),
    321                     'url_activate' => admin_url( 'plugins.php?plugin_status=inactive&s=GADWP' ),
    322                     'is_active'    => is_plugin_active( 'google-analytics-dashboard-for-wp' . DIRECTORY_SEPARATOR . 'gadwp.php' ),
    323                     'is_installed' => file_exists( WP_PLUGIN_DIR . DIRECTORY_SEPARATOR . 'google-analytics-dashboard-for-wp' . DIRECTORY_SEPARATOR . 'gadwp.php' ),
    324                 ),
    325                 'analytify'       => array(
    326                     'label'        => 'Analytify – Google Analytics Dashboard Plugin For WordPress',
    327                     'url_install'  => admin_url( 'plugin-install.php?tab=search&s=Analytify' ),
    328                     'url_activate' => admin_url( 'plugins.php?plugin_status=inactive&s=Analytify' ),
    329                     'target'       => '_blank',
    330                     'is_active'    => is_plugin_active( 'wp-analytify' . DIRECTORY_SEPARATOR . 'wp-analytify.php' ),
    331                     'is_installed' => file_exists( WP_PLUGIN_DIR . DIRECTORY_SEPARATOR . 'wp-analytify' . DIRECTORY_SEPARATOR . 'wp-analytify.php' ),
    332                 ),
    333                 'gaga'            => array(
    334                     'label'        => 'GA Google Analytics',
    335                     'url_install'  => admin_url( 'plugin-install.php?tab=search&s=GA+Google+Analytics' ),
    336                     'url_activate' => admin_url( 'plugins.php?plugin_status=inactive&s=GA+Google' ),
    337                     'target'       => '_blank',
    338                     'is_active'    => is_plugin_active( 'ga-google-analytics' . DIRECTORY_SEPARATOR . 'ga-google-analytics.php' ),
    339                     'is_installed' => file_exists( WP_PLUGIN_DIR . DIRECTORY_SEPARATOR . '/ga-google-analytics' . DIRECTORY_SEPARATOR . 'ga-google-analytics.php' ),
    340                 ),
    341                 'sitekit'         => array(
    342                     'label'        => 'Site Kit by Google – Analytics, Search Console, AdSense, Speed',
    343                     'url_install'  => admin_url( 'plugin-install.php?tab=search&s=Google+site+kit' ),
    344                     'url_activate' => admin_url( 'plugins.php?plugin_status=inactive&s=site+kit' ),
    345                     'target'       => '_blank',
    346                     'is_active'    => is_plugin_active( 'google-site-kit' . DIRECTORY_SEPARATOR . 'google-site-kit.php' ),
    347                     'is_installed' => file_exists( WP_PLUGIN_DIR . DIRECTORY_SEPARATOR . 'google-site-kit' . DIRECTORY_SEPARATOR . 'google-site-kit.php' ),
    348                 ),
    349             );
    350 
    351             extract( $form_data );
    352 
    353             // if plugin set as current but not installed or activated, remove it from settings
    354             if ( ! empty( $ga_plugin ) && isset( $ga_plugins[ $ga_plugin ] ) && ( ( isset( $ga_plugins[ $ga_plugin ][ 'is_active' ] ) && ! $ga_plugins[ $ga_plugin ][ 'is_active' ] ) || isset( $ga_plugins[ $ga_plugin ][ 'is_installed' ] ) && ! $ga_plugins[ $ga_plugin ][ 'is_installed' ] ) ) {
    355                 delete_option( GAOO_PREFIX . 'ga_plugin' );
    356                 $ga_plugin = null;
    357             }
    358 
    359             $wp_privacy_page_id = get_option( 'wp_page_for_privacy_policy', 0 );
    360             $wp_admin_mail      = get_option( 'admin_email', null );
    361             $promotion          = $this->promotion;
    362 
    363             include_once GAOO_PLUGIN_DIR . DIRECTORY_SEPARATOR . 'templates' . DIRECTORY_SEPARATOR . 'settings.php';
    364         }
    365 
    366         /**
    367          * Handle the submited form data.
    368          *
    369          * @return array Stored options with the value.
    370          */
    371         private function save_menu_settings() {
    372 
    373             // Check if form submited by the right site
    374             if ( ! isset( $_REQUEST[ '_wpnonce' ] ) || ! wp_verify_nonce( $_REQUEST[ '_wpnonce' ], 'gaoo-settings' ) ) {
    375                 $this->messages->addError( esc_html__( 'Security check fail!', 'opt-out-for-google-analytics' ) );
    376 
    377                 return array();
    378             }
    379 
    380             // Validate inputs
    381             $skip_save = array();
    382             $data      = filter_var_array( $_POST[ 'gaoo' ], array(
    383                 'ga_plugin'           => FILTER_SANITIZE_STRING,
    384                 'link_deactivate'     => FILTER_SANITIZE_STRING,
    385                 'link_activate'       => FILTER_SANITIZE_STRING,
    386                 'ua_code'             => FILTER_SANITIZE_STRING,
    387                 'popup_deactivate'    => FILTER_SANITIZE_STRING,
    388                 'popup_activate'      => FILTER_SANITIZE_STRING,
    389                 'status'              => FILTER_SANITIZE_STRING,
    390                 'privacy_page_id'     => FILTER_SANITIZE_STRING,
    391                 'disable_monitoring'  => FILTER_SANITIZE_NUMBER_INT,
    392                 'force_reload'        => FILTER_SANITIZE_NUMBER_INT,
    393                 'wp_privacy_page'     => FILTER_SANITIZE_NUMBER_INT,
    394                 'custom_css'          => FILTER_UNSAFE_RAW,
    395                 'tracking_code'       => FILTER_UNSAFE_RAW,
    396                 'status_intervall'    => FILTER_SANITIZE_STRING,
    397                 'status_mails'        => FILTER_SANITIZE_STRING,
    398                 'uninstall_keep_data' => FILTER_SANITIZE_STRING,
    399                 'disable_dashboard'   => FILTER_SANITIZE_STRING,
    400                 'status_mails_sync'   => FILTER_SANITIZE_NUMBER_INT,
    401             ), false );
    402 
    403             // Validate UA code if entered manually, otherwise empty field.
    404             if ( $data[ 'ga_plugin' ] == 'manual' && ! empty( $data[ 'ua_code' ] ) ) {
    405                 $data[ 'ua_code' ] = GAOO_Utils::validate_ua_code( strtoupper( $data[ 'ua_code' ] ) );
    406 
    407                 if ( empty( $data[ 'ua_code' ] ) ) {
    408                     $this->messages->addError( esc_html__( "Please enter a valid UA- or G-Code (Google Analytics 4). Format: UA-XXXXXX-Y or G-XXXXXXXXXX", 'opt-out-for-google-analytics' ) );
    409                 }
    410             }
    411             else {
    412                 $data[ 'ua_code' ]       = '';
    413                 $data[ 'tracking_code' ] = '';
    414             }
    415 
    416             // Removes space from start and end of the text.
    417             $data[ 'link_activate' ]    = trim( $data[ 'link_activate' ] );
    418             $data[ 'link_deactivate' ]  = trim( $data[ 'link_deactivate' ] );
    419             $data[ 'popup_activate' ]   = trim( $data[ 'popup_activate' ] );
    420             $data[ 'popup_deactivate' ] = trim( $data[ 'popup_deactivate' ] );
    421             $data[ 'tracking_code' ]    = trim( $data[ 'tracking_code' ] );
    422 
    423             // Check and validate the custom css code
    424             if ( ! empty( $data[ 'custom_css' ] ) ) {
    425                 if ( ! $this->csstidy->parse( stripslashes( $data[ 'custom_css' ] ) ) ) {
    426                     $skip_save[] = 'custom_css';
    427                     $this->messages->addWarning( esc_html__( "Your custom css code was not stored, because it is not valid! We stoll hold the old version of it, please check below the code and save again.", 'opt-out-for-google-analytics' ) );
    428                 }
    429                 else {
    430                     $data[ 'custom_css' ] = $this->csstidy->print->plain();
    431                 }
    432             }
    433 
    434             // Store only validated mails into database
    435             if ( ! empty( $data[ 'status_mails' ] ) ) {
    436                 $mails = explode( ',', $data[ 'status_mails' ] );
    437                 $mails = array_filter( array_map( 'trim', $mails ), 'is_email' );
    438 
    439                 $data[ 'status_mails' ] = empty( $mails ) ? '' : implode( ',', $mails );
    440             }
    441 
    442             if ( empty( $data[ 'link_deactivate' ] ) ) {
    443                 $this->messages->addError( esc_html__( "Please enter the text for the deactivate link, otherwise link doesn't appears!", 'opt-out-for-google-analytics' ) );
    444             }
    445 
    446             if ( empty( $data[ 'link_activate' ] ) ) {
    447                 $this->messages->addError( esc_html__( "Please enter the text for the activate link, otherwise link doesn't appears!", 'opt-out-for-google-analytics' ) );
    448             }
    449 
    450             if ( $this->messages->hasError() ) {
    451                 return $data;
    452             }
    453 
    454             // If an option is not set, fill it with the default value.
    455             $data                 = array_merge( GAOO_Utils::get_options_list(), $data );
    456             $old_status_intervall = GAOO_Utils::get_option( 'status_intervall' );
    457 
    458             // Sync. with WP Privacy page
    459             if ( ! empty( $data[ 'wp_privacy_page' ] ) ) {
    460                 $data[ 'privacy_page_id' ] = get_option( 'wp_page_for_privacy_policy', 0 );
    461             }
    462 
    463             foreach ( $data as $k => $v ) {
    464                 if ( ! in_array( $k, $skip_save, true ) ) {
    465                     update_option( GAOO_PREFIX . $k, $v );
    466                 }
    467             }
    468 
    469             // Show warniung if cronjob is disabled
    470             if ( $this->is_cronjob_disabled() ) {
    471                 $this->messages->addWarning( esc_html__( 'It seems like you have disabled the cronjob through your wp-config.php ... Please make sure that you have installed a server-side cronjob, otherwise you wont receive the status reports via mail.', 'opt-out-for-google-analytics' ) );
    472             }
    473 
    474             // Restart cronjob etc. if intervall is changed
    475             if ( $old_status_intervall != $data[ 'status_intervall' ] ) {
    476                 GAOO_Utils::delete_todo_cache();
    477                 GAOO_Utils::start_cronjob( true );
    478             }
    479 
    480             $this->messages->addSuccess( esc_html__( 'Settings saved.', 'opt-out-for-google-analytics' ) );
    481 
    482             return $data;
    483         }
    484 
    485         /**
    486          * Send a mail with the status check report.
    487          */
    488         public function send_status_mail() {
    489             // Delete todo cache if cronjob is triggered
    490             GAOO_Utils::delete_todo_cache();
    491 
    492             $data = GAOO_Utils::get_options();
    493 
    494             if ( empty( $data[ 'status_mails' ] ) ) {
    495                 return;
    496             }
    497 
    498             $checklist = GAOO_Utils::check_todos( $data, true );
    499             $checked   = array_unique( array_filter( array_column( $checklist, 'checked' ), 'is_bool' ) );
    500 
    501             if ( count( $checked ) == 1 && array_pop( $checked ) == true ) {
    502                 return;
    503             }
    504 
    505             $mail_to = explode( ',', $data[ 'status_mails' ] );
    506             $mail_to = array_filter( array_map( 'trim', $mail_to ), 'is_email' );
    507 
    508             if ( empty( $mail_to ) ) {
    509                 return;
    510             }
    511 
    512             $mail_subject = '[ ' . esc_html( get_bloginfo( 'name' ) ) . ' ] ' . esc_html__( 'Opt-Out for Google Analytics - Status check failed!', 'opt-out-for-google-analytics' );
    513             $mail_body    = esc_html__( 'Here is your status check report:', 'opt-out-for-google-analytics' ) . PHP_EOL . PHP_EOL;
    514 
    515             foreach ( $checklist as $checkpoint ) {
    516                 $checked = $checkpoint[ 'checked' ];
    517 
    518                 if ( $checked === false ) {
    519                     $checked = '✕';
    520                 }
    521                 elseif ( $checked === true ) {
    522                     $checked = '✔';
    523                 }
    524                 else {
    525                     $checked = '?';
    526                 }
    527 
    528                 $mail_body .= "[ {$checked} ] " . esc_html( $checkpoint[ 'label' ] ) . PHP_EOL;
    529             }
    530 
    531             $mail_body .= PHP_EOL . sprintf( esc_html__( 'Check the settings: %s', 'opt-out-for-google-analytics' ), esc_url( admin_url( 'options-general.php?page=gaoo' ) ) );
    532 
    533             wp_mail( $mail_to, $mail_subject, $mail_body );
    534         }
    535 
    536 
    537     }
     521            GAOO_Utils::start_cronjob(true);
     522        }
     523
     524        $this->messages->addSuccess(esc_html__('Settings saved.', 'opt-out-for-google-analytics'));
     525
     526        return $data;
     527    }
     528
     529    /**
     530     * Send a mail with the status check report.
     531     */
     532    public function send_status_mail()
     533    {
     534        // Delete todo cache if cronjob is triggered
     535        GAOO_Utils::delete_todo_cache();
     536
     537        $data = GAOO_Utils::get_options();
     538
     539        if (empty($data['status_mails'])) {
     540            return;
     541        }
     542
     543        $checklist = GAOO_Utils::check_todos($data, true);
     544        $checked = array_unique(array_filter(array_column($checklist, 'checked'), 'is_bool'));
     545
     546        if (count($checked) == 1 && array_pop($checked) == true) {
     547            return;
     548        }
     549
     550        $mail_to = explode(',', $data['status_mails']);
     551        $mail_to = array_filter(array_map('trim', $mail_to), 'is_email');
     552
     553        if (empty($mail_to)) {
     554            return;
     555        }
     556
     557        $mail_subject = '[ ' . esc_html(get_bloginfo('name')) . ' ] ' . esc_html__('Opt-Out for Google Analytics - Status check failed!', 'opt-out-for-google-analytics');
     558        $mail_body = esc_html__('Here is your status check report:', 'opt-out-for-google-analytics') . PHP_EOL . PHP_EOL;
     559
     560        foreach ($checklist as $checkpoint) {
     561            $checked = $checkpoint['checked'];
     562
     563            if ($checked === false) {
     564                $checked = '✕';
     565            } elseif ($checked === true) {
     566                $checked = '✔';
     567            } else {
     568                $checked = '?';
     569            }
     570
     571            $mail_body .= "[ {$checked} ] " . esc_html($checkpoint['label']) . PHP_EOL;
     572        }
     573
     574        $mail_body .= PHP_EOL . sprintf(esc_html__('Check the settings: %s', 'opt-out-for-google-analytics'), esc_url(admin_url('options-general.php?page=gaoo')));
     575
     576        wp_mail($mail_to, $mail_subject, $mail_body);
     577    }
     578
     579
     580}
  • opt-out-for-google-analytics/trunk/inc/promo.class.php

    r2787042 r2896199  
    6161         * @return bool
    6262         */
    63         public static function clearCache() {
     63        public static function clear_cache() {
    6464            return delete_transient( self::$transient_key_cache ) && delete_transient( self::$transient_key_notices );
    6565        }
  • opt-out-for-google-analytics/trunk/inc/utils.class.php

    r2664664 r2896199  
    323323            foreach ( $checklist as $check ):
    324324                if ( ! empty( $check[ 'url' ] ) ) {
    325                     $check[ 'label' ] = '<a title="' . esc_html__( "Got to page", 'opt-out-for-google-analytics' ) . '" href="' . esc_url( $check[ 'url' ] ) . '">' . $check[ 'label' ] . '<span class="dashicons dashicons-external"></span></a>';
     325                    $check[ 'label' ] = '<a title="' . esc_html__( "Got to page", 'opt-out-for-google-analytics' ) . '" target="_blank" href="' . esc_url( $check[ 'url' ] ) . '">' . $check[ 'label' ] . '<span class="dashicons dashicons-external"></span></a>';
    326326                }
    327327
     
    430430            }
    431431            else { // manual
    432                 $anonymip_enabled = $anonymip_url = $uacode_url = null;
     432                $anonymip_enabled = null;
     433                $anonymip_url = null;
     434                $uacode_url = null;
    433435
    434436                if ( GAOO_Utils::is_ga4_code( $data[ 'ua_code' ] ) ) {
  • opt-out-for-google-analytics/trunk/readme.txt

    r2787042 r2896199  
    33Tags: google analytics, opt-out, dsgvo, gdpr, analytics
    44Requires at least: 3.5
    5 Tested up to: 6.0.2
     5Tested up to: 6.2
    66Requires PHP: 7.0
    7 Stable tag: 2.1
     7Stable tag: 2.2
    88License: GPLv2 or later
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    3636* Visual customizations through custom CSS codes that are loaded only together with the shortcode (optimized loading time).
    3737* Translation for DE and EN available.
    38 * Full support for PHP 8
     38* Full support for PHP 8.1
    3939
    4040**Regularly check whether the settings are still data protection compliant!**
     
    287287
    288288== Changelog ==
     289
     290= 2.2 =
     291* Fix: Paste tracking code in manual mode will now read GA4 id from JavaScript code and automatically insert it into input field, if it is empty.
     292* Tweaks: Optimized code and UX.
     293* Updated: Support for WordPress 6.2
     294* Updated: Support for PHP 8.1
    289295
    290296= 2.1 =
Note: See TracChangeset for help on using the changeset viewer.