PluginProbe
ShareThis Dashboard for Google Analytics / 3.4.1
ShareThis Dashboard for Google Analytics v3.4.1
3.4.1 3.4.0 3.3.2 trunk 1.0.7 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.1 2.1.2 2.1.3 2.1.4 2.1.5 2.2.5 2.3.5 2.3.6 2.3.7 2.3.8 2.4.0 2.4.1 2.5.0 2.5.1 All 45 releases
googleanalytics / googleanalytics.php

googleanalytics.php in ShareThis Dashboard for Google Analytics 3.4.1, at googleanalytics.php

114 lines 3.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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.4.1
7 * Author: ShareThis
8 * Author URI: http://sharethis.com
9 * License: GPLv2 or later
10 * License URI: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
11 *
12 * @package GoogleAnalytics
13 */
14
15 if (!defined('ABSPATH')) exit;
16
17 if ( ! defined( 'WP_CONTENT_URL' ) ) {
18 define( 'WP_CONTENT_URL', get_option( 'siteurl' ) . '/wp-content' );
19 }
20 if ( ! defined( 'WP_CONTENT_DIR' ) ) {
21 define( 'WP_CONTENT_DIR', ABSPATH . 'wp-content' );
22 }
23 if ( ! defined( 'WP_PLUGIN_URL' ) ) {
24 define( 'WP_PLUGIN_URL', WP_CONTENT_URL . '/plugins' );
25 }
26 if ( ! defined( 'SHARETHIS_GA_BROKER_BASE' ) ) {
27 define( 'SHARETHIS_GA_BROKER_BASE', 'https://platform-api.sharethis.com/v2.0/googlewp/' );
28 }
29 if ( ! defined( 'WP_PLUGIN_DIR' ) ) {
30 define( 'WP_PLUGIN_DIR', WP_CONTENT_DIR . '/plugins' );
31 }
32 if ( ! defined( 'GA_NAME' ) ) {
33 define( 'GA_NAME', 'googleanalytics' );
34 }
35 if ( ! defined( 'GA_PLUGIN_DIR' ) ) {
36 define( 'GA_PLUGIN_DIR', WP_PLUGIN_DIR . '/' . GA_NAME );
37 }
38 if ( ! defined( 'GA_PLUGIN_URL' ) ) {
39 define( 'GA_PLUGIN_URL', WP_PLUGIN_URL . '/' . GA_NAME );
40 }
41 if ( ! defined( 'GA_MAIN_FILE_PATH' ) ) {
42 define( 'GA_MAIN_FILE_PATH', __FILE__ );
43 }
44 if ( ! defined( 'GA_SHARETHIS_SCRIPTS_INCLUDED' ) ) {
45 define( 'GA_SHARETHIS_SCRIPTS_INCLUDED', 0 );
46 }
47
48 putenv('GOOGLE_APPLICATION_CREDENTIALS=' . WP_PLUGIN_DIR . '/googleanalytics/credentials.json');
49 define('GOOGLE_APPLICATION_CREDENTIALS', WP_PLUGIN_DIR . '/googleanalytics/credentials.json');
50
51 /**
52 * Prevent to launch the plugin within different plugin dir name
53 */
54 if ( false === preg_match( '/(\/|\\\)' . GA_NAME . '(\/|\\\)/', realpath( __FILE__ ), $test ) ) {
55 echo esc_html(
56 sprintf(
57 /* translators: %s refers to the Google Analytics directory name. */
58 __(
59 'Invalid plugin installation directory. Please verify if the plugin\'s dir name is equal to "%s".', 'googleanalytics'
60 ),
61 esc_attr( GA_NAME )
62 )
63 );
64
65 // To make able the message above to be displayed in the activation error notice.
66 die();
67 }
68
69 const GOOGLEANALYTICS_VERSION = '3.4.1';
70
71 // Requires.
72 require_once GA_PLUGIN_DIR . '/lib/analytics-admin/vendor/autoload.php';
73 require_once GA_PLUGIN_DIR . '/overwrite/ga-overwrite.php';
74 require_once GA_PLUGIN_DIR . '/class/class-ga-autoloader.php';
75 require_once GA_PLUGIN_DIR . '/class/class-ga-autoloader.php';
76 require_once GA_PLUGIN_DIR . '/tools/class-ga-supportlogger.php';
77 require_once GA_PLUGIN_DIR . '/class/class-ga-oauth.php';
78
79 if ( version_compare( phpversion(), '7.4', '>=' ) ) {
80 Ga_Autoloader::register();
81 Ga_Hook::add_hooks( GA_MAIN_FILE_PATH );
82
83 add_action( 'plugins_loaded', 'Ga_Admin::loaded_googleanalytics' );
84 add_action( 'init', 'Ga_Helper::init' );
85
86 add_action( 'plugins_loaded', function() {
87 $sharethis_ga_oauth = new GA_OAuth();
88 $sharethis_ga_oauth->hooks();
89 } );
90 } else {
91 if ( defined( 'WP_CLI' ) ) {
92 WP_CLI::warning( _google_analytics_php_version_text() );
93 } else {
94 add_action( 'admin_notices', '_google_analytics_php_version_error' );
95 }
96 }
97
98 /**
99 * String describing the minimum PHP version.
100 *
101 * @return string
102 */
103 function _google_analytics_php_version_text() {
104 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.', 'googleanalytics' );
105 }
106
107
108 /**
109 * Admin notice for incompatible versions of PHP.
110 */
111 function _google_analytics_php_version_error() {
112 printf( '<div class="error"><p>%s</p></div>', esc_html( _google_analytics_php_version_text() ) );
113 }
114