Plugin Directory

source: googleanalytics/trunk/googleanalytics.php

Last change on this file was 3364575, checked in by ShareThis, 6 months ago

Update to version 3.2.4 from GitHub

File size: 3.2 KB
Line 
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.2.4
7 * Author: ShareThis
8 * Author URI: http://sharethis.com
9 *
10 * @package GoogleAnalytics
11 */
12
13if ( ! defined( 'WP_CONTENT_URL' ) ) {
14        define( 'WP_CONTENT_URL', get_option( 'siteurl' ) . '/wp-content' );
15}
16if ( ! defined( 'WP_CONTENT_DIR' ) ) {
17        define( 'WP_CONTENT_DIR', ABSPATH . 'wp-content' );
18}
19if ( ! defined( 'WP_PLUGIN_URL' ) ) {
20        define( 'WP_PLUGIN_URL', WP_CONTENT_URL . '/plugins' );
21}
22if ( ! defined( 'WP_PLUGIN_DIR' ) ) {
23        define( 'WP_PLUGIN_DIR', WP_CONTENT_DIR . '/plugins' );
24}
25if ( ! defined( 'GA_NAME' ) ) {
26        define( 'GA_NAME', 'googleanalytics' );
27}
28if ( ! defined( 'GA_PLUGIN_DIR' ) ) {
29        define( 'GA_PLUGIN_DIR', WP_PLUGIN_DIR . '/' . GA_NAME );
30}
31if ( ! defined( 'GA_PLUGIN_URL' ) ) {
32        define( 'GA_PLUGIN_URL', WP_PLUGIN_URL . '/' . GA_NAME );
33}
34if ( ! defined( 'GA_MAIN_FILE_PATH' ) ) {
35        define( 'GA_MAIN_FILE_PATH', __FILE__ );
36}
37if ( ! defined( 'GA_SHARETHIS_SCRIPTS_INCLUDED' ) ) {
38        define( 'GA_SHARETHIS_SCRIPTS_INCLUDED', 0 );
39}
40
41putenv('GOOGLE_APPLICATION_CREDENTIALS=' . WP_PLUGIN_DIR . '/googleanalytics/credentials.json');
42define('GOOGLE_APPLICATION_CREDENTIALS', WP_PLUGIN_DIR . '/googleanalytics/credentials.json');
43
44/**
45 * Prevent to launch the plugin within different plugin dir name
46 */
47if ( 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
62const GOOGLEANALYTICS_VERSION = '3.2.4';
63
64// Requires.
65require_once GA_PLUGIN_DIR . '/lib/analytics-admin/vendor/autoload.php';
66require_once GA_PLUGIN_DIR . '/overwrite/ga-overwrite.php';
67require_once GA_PLUGIN_DIR . '/class/class-ga-autoloader.php';
68require_once GA_PLUGIN_DIR . '/class/class-ga-autoloader.php';
69require_once GA_PLUGIN_DIR . '/tools/class-ga-supportlogger.php';
70
71if ( 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 */
90function _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 */
98function _google_analytics_php_version_error() {
99    printf( '<div class="error"><p>%s</p></div>', esc_html( _google_analytics_php_version_text() ) );
100}
Note: See TracBrowser for help on using the repository browser.