googleanalytics
Last commit date
assets
3 years ago
class
3 years ago
css
3 years ago
js
3 years ago
lib
3 years ago
overwrite
4 years ago
tools
4 years ago
view
3 years ago
credentials.json
3 years ago
googleanalytics.php
3 years ago
readme.txt
3 years ago
googleanalytics.php
101 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Plugin Name: ShareThis Dashboard for Google Analytics |
| 4 | * Plugin URI: http://wordpress.org/extend/plugins/googleanalytics/ |
| 5 | * Description: Use Google Analytics on your WordPress site without touching any code, and view visitor reports right in your WordPress admin dashboard! |
| 6 | * Version: 3.1.2 |
| 7 | * Author: ShareThis |
| 8 | * Author URI: http://sharethis.com |
| 9 | * |
| 10 | * @package GoogleAnalytics |
| 11 | */ |
| 12 | |
| 13 | if ( ! defined( 'WP_CONTENT_URL' ) ) { |
| 14 | define( 'WP_CONTENT_URL', get_option( 'siteurl' ) . '/wp-content' ); |
| 15 | } |
| 16 | if ( ! defined( 'WP_CONTENT_DIR' ) ) { |
| 17 | define( 'WP_CONTENT_DIR', ABSPATH . 'wp-content' ); |
| 18 | } |
| 19 | if ( ! defined( 'WP_PLUGIN_URL' ) ) { |
| 20 | define( 'WP_PLUGIN_URL', WP_CONTENT_URL . '/plugins' ); |
| 21 | } |
| 22 | if ( ! defined( 'WP_PLUGIN_DIR' ) ) { |
| 23 | define( 'WP_PLUGIN_DIR', WP_CONTENT_DIR . '/plugins' ); |
| 24 | } |
| 25 | if ( ! defined( 'GA_NAME' ) ) { |
| 26 | define( 'GA_NAME', 'googleanalytics' ); |
| 27 | } |
| 28 | if ( ! defined( 'GA_PLUGIN_DIR' ) ) { |
| 29 | define( 'GA_PLUGIN_DIR', WP_PLUGIN_DIR . '/' . GA_NAME ); |
| 30 | } |
| 31 | if ( ! defined( 'GA_PLUGIN_URL' ) ) { |
| 32 | define( 'GA_PLUGIN_URL', WP_PLUGIN_URL . '/' . GA_NAME ); |
| 33 | } |
| 34 | if ( ! defined( 'GA_MAIN_FILE_PATH' ) ) { |
| 35 | define( 'GA_MAIN_FILE_PATH', __FILE__ ); |
| 36 | } |
| 37 | if ( ! defined( 'GA_SHARETHIS_SCRIPTS_INCLUDED' ) ) { |
| 38 | define( 'GA_SHARETHIS_SCRIPTS_INCLUDED', 0 ); |
| 39 | } |
| 40 | |
| 41 | putenv('GOOGLE_APPLICATION_CREDENTIALS=' . WP_PLUGIN_DIR . '/googleanalytics/credentials.json'); |
| 42 | define('GOOGLE_APPLICATION_CREDENTIALS', WP_PLUGIN_DIR . '/googleanalytics/credentials.json'); |
| 43 | |
| 44 | /** |
| 45 | * Prevent to launch the plugin within different plugin dir name |
| 46 | */ |
| 47 | if ( false === preg_match( '/(\/|\\\)' . GA_NAME . '(\/|\\\)/', realpath( __FILE__ ), $test ) ) { |
| 48 | echo esc_html( |
| 49 | sprintf( |
| 50 | /* translators: %s refers to the Google Analytics directory name. */ |
| 51 | __( |
| 52 | 'Invalid plugin installation directory. Please verify if the plugin\'s dir name is equal to "%s".' |
| 53 | ), |
| 54 | esc_attr( GA_NAME ) |
| 55 | ) |
| 56 | ); |
| 57 | |
| 58 | // To make able the message above to be displayed in the activation error notice. |
| 59 | die(); |
| 60 | } |
| 61 | |
| 62 | const GOOGLEANALYTICS_VERSION = '3.1.2'; |
| 63 | |
| 64 | // Requires. |
| 65 | require_once GA_PLUGIN_DIR . '/lib/analytics-admin/vendor/autoload.php'; |
| 66 | require_once GA_PLUGIN_DIR . '/overwrite/ga-overwrite.php'; |
| 67 | require_once GA_PLUGIN_DIR . '/class/class-ga-autoloader.php'; |
| 68 | require_once GA_PLUGIN_DIR . '/class/class-ga-autoloader.php'; |
| 69 | require_once GA_PLUGIN_DIR . '/tools/class-ga-supportlogger.php'; |
| 70 | |
| 71 | if ( version_compare( phpversion(), '7.4', '>=' ) ) { |
| 72 | Ga_Autoloader::register(); |
| 73 | Ga_Hook::add_hooks( GA_MAIN_FILE_PATH ); |
| 74 | |
| 75 | add_action( 'plugins_loaded', 'Ga_Admin::loaded_googleanalytics' ); |
| 76 | add_action( 'init', 'Ga_Helper::init' ); |
| 77 | } else { |
| 78 | if ( defined( 'WP_CLI' ) ) { |
| 79 | WP_CLI::warning( _google_analytics_php_version_text() ); |
| 80 | } else { |
| 81 | add_action( 'admin_notices', '_google_analytics_php_version_error' ); |
| 82 | } |
| 83 | } |
| 84 | |
| 85 | /** |
| 86 | * String describing the minimum PHP version. |
| 87 | * |
| 88 | * @return string |
| 89 | */ |
| 90 | function _google_analytics_php_version_text() { |
| 91 | return __( 'ShareThis Dashboard for Google Analytics plugin error: Your version of PHP is too old to run this plugin. You must be running PHP 7.4 or higher.', 'googlanalytics' ); |
| 92 | } |
| 93 | |
| 94 | |
| 95 | /** |
| 96 | * Admin notice for incompatible versions of PHP. |
| 97 | */ |
| 98 | function _google_analytics_php_version_error() { |
| 99 | printf( '<div class="error"><p>%s</p></div>', esc_html( _google_analytics_php_version_text() ) ); |
| 100 | } |
| 101 |