gadwp.php 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. <?php
  2. /**
  3. * Plugin Name: Google Analytics Dashboard for WP (GADWP)
  4. * Plugin URI: https://exactmetrics.com
  5. * Description: Displays Google Analytics Reports and Real-Time Statistics in your Dashboard. Automatically inserts the tracking code in every page of your website.
  6. * Author: ExactMetrics
  7. * Version: 5.3.5
  8. * Author URI: https://exactmetrics.com
  9. * Text Domain: google-analytics-dashboard-for-wp
  10. * Domain Path: /languages
  11. */
  12. // Exit if accessed directly
  13. if ( ! defined( 'ABSPATH' ) )
  14. exit();
  15. // Plugin Version
  16. if ( ! defined( 'GADWP_CURRENT_VERSION' ) ) {
  17. define( 'GADWP_CURRENT_VERSION', '5.3.5' );
  18. }
  19. if ( ! defined( 'GADWP_ENDPOINT_URL' ) ) {
  20. define( 'GADWP_ENDPOINT_URL', 'https://gadwp.exactmetrics.com/' );
  21. }
  22. if ( ! class_exists( 'GADWP_Manager' ) ) {
  23. final class GADWP_Manager {
  24. private static $instance = null;
  25. public $config = null;
  26. public $frontend_actions = null;
  27. public $common_actions = null;
  28. public $backend_actions = null;
  29. public $tracking = null;
  30. public $frontend_item_reports = null;
  31. public $backend_setup = null;
  32. public $frontend_setup = null;
  33. public $backend_widgets = null;
  34. public $backend_item_reports = null;
  35. public $gapi_controller = null;
  36. public $usage_tracking = null;
  37. /**
  38. * Construct forbidden
  39. */
  40. private function __construct() {
  41. if ( null !== self::$instance ) {
  42. _doing_it_wrong( __FUNCTION__, __( "This is not allowed, read the documentation!", 'google-analytics-dashboard-for-wp' ), '4.6' );
  43. }
  44. }
  45. /**
  46. * Clone warning
  47. */
  48. private function __clone() {
  49. _doing_it_wrong( __FUNCTION__, __( "This is not allowed, read the documentation!", 'google-analytics-dashboard-for-wp' ), '4.6' );
  50. }
  51. /**
  52. * Wakeup warning
  53. */
  54. private function __wakeup() {
  55. _doing_it_wrong( __FUNCTION__, __( "This is not allowed, read the documentation!", 'google-analytics-dashboard-for-wp' ), '4.6' );
  56. }
  57. /**
  58. * Creates a single instance for GADWP and makes sure only one instance is present in memory.
  59. *
  60. * @return GADWP_Manager
  61. */
  62. public static function instance() {
  63. if ( null === self::$instance ) {
  64. self::$instance = new self();
  65. self::$instance->setup();
  66. self::$instance->config = new GADWP_Config();
  67. if ( is_admin() && class_exists( 'AM_Notification' ) && defined( 'GADWP_CURRENT_VERSION' ) ) {
  68. new AM_Notification( 'exact-metrics', GADWP_CURRENT_VERSION );
  69. }
  70. }
  71. return self::$instance;
  72. }
  73. /**
  74. * Defines constants and loads required resources
  75. */
  76. private function setup() {
  77. // Plugin Path
  78. if ( ! defined( 'GADWP_DIR' ) ) {
  79. define( 'GADWP_DIR', plugin_dir_path( __FILE__ ) );
  80. }
  81. // Plugin URL
  82. if ( ! defined( 'GADWP_URL' ) ) {
  83. define( 'GADWP_URL', plugin_dir_url( __FILE__ ) );
  84. }
  85. // Plugin main File
  86. if ( ! defined( 'GADWP_FILE' ) ) {
  87. define( 'GADWP_FILE', __FILE__ );
  88. }
  89. /*
  90. * Load notifications class
  91. */
  92. if ( is_admin() ) {
  93. include_once ( GADWP_DIR . 'admin/class-am-notification.php' );
  94. }
  95. /*
  96. * Load Tools class
  97. */
  98. include_once ( GADWP_DIR . 'tools/tools.php' );
  99. /*
  100. * Load Config class
  101. */
  102. include_once ( GADWP_DIR . 'config.php' );
  103. /*
  104. * Load GAPI Controller class
  105. */
  106. include_once ( GADWP_DIR . 'tools/gapi.php' );
  107. /*
  108. * Plugin i18n
  109. */
  110. add_action( 'init', array( self::$instance, 'load_i18n' ) );
  111. /*
  112. * Plugin Init
  113. */
  114. add_action( 'init', array( self::$instance, 'load' ) );
  115. /*
  116. * Include Install
  117. */
  118. include_once ( GADWP_DIR . 'install/install.php' );
  119. register_activation_hook( GADWP_FILE, array( 'GADWP_Install', 'install' ) );
  120. /*
  121. * Include Uninstall
  122. */
  123. include_once ( GADWP_DIR . 'install/uninstall.php' );
  124. register_uninstall_hook( GADWP_FILE, array( 'GADWP_Uninstall', 'uninstall' ) );
  125. /*
  126. * Load Frontend Widgets
  127. * (needed during ajax)
  128. */
  129. include_once ( GADWP_DIR . 'front/widgets.php' );
  130. /*
  131. * Add Frontend Widgets
  132. * (needed during ajax)
  133. */
  134. add_action( 'widgets_init', array( self::$instance, 'add_frontend_widget' ) );
  135. }
  136. /**
  137. * Load i18n
  138. */
  139. public function load_i18n() {
  140. load_plugin_textdomain( 'google-analytics-dashboard-for-wp', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' );
  141. }
  142. /**
  143. * Register Frontend Widgets
  144. */
  145. public function add_frontend_widget() {
  146. register_widget( 'GADWP_Frontend_Widget' );
  147. }
  148. /**
  149. * Conditional load
  150. */
  151. public function load() {
  152. if ( is_admin() ) {
  153. if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
  154. if ( GADWP_Tools::check_roles( self::$instance->config->options['access_back'] ) ) {
  155. /*
  156. * Load Backend ajax actions
  157. */
  158. include_once ( GADWP_DIR . 'admin/ajax-actions.php' );
  159. self::$instance->backend_actions = new GADWP_Backend_Ajax();
  160. }
  161. /*
  162. * Load Frontend ajax actions
  163. */
  164. include_once ( GADWP_DIR . 'front/ajax-actions.php' );
  165. self::$instance->frontend_actions = new GADWP_Frontend_Ajax();
  166. /*
  167. * Load Common ajax actions
  168. */
  169. include_once ( GADWP_DIR . 'common/ajax-actions.php' );
  170. self::$instance->common_actions = new GADWP_Common_Ajax();
  171. if ( self::$instance->config->options['backend_item_reports'] ) {
  172. /*
  173. * Load Backend Item Reports for Quick Edit
  174. */
  175. include_once ( GADWP_DIR . 'admin/item-reports.php' );
  176. self::$instance->backend_item_reports = new GADWP_Backend_Item_Reports();
  177. }
  178. } else if ( GADWP_Tools::check_roles( self::$instance->config->options['access_back'] ) ) {
  179. /*
  180. * Load Backend Setup
  181. */
  182. include_once ( GADWP_DIR . 'admin/setup.php' );
  183. self::$instance->backend_setup = new GADWP_Backend_Setup();
  184. if ( self::$instance->config->options['dashboard_widget'] ) {
  185. /*
  186. * Load Backend Widget
  187. */
  188. include_once ( GADWP_DIR . 'admin/widgets.php' );
  189. self::$instance->backend_widgets = new GADWP_Backend_Widgets();
  190. }
  191. if ( self::$instance->config->options['backend_item_reports'] ) {
  192. /*
  193. * Load Backend Item Reports
  194. */
  195. include_once ( GADWP_DIR . 'admin/item-reports.php' );
  196. self::$instance->backend_item_reports = new GADWP_Backend_Item_Reports();
  197. }
  198. include_once ( GADWP_DIR . 'admin/tracking.php' );
  199. self::$instance->usage_tracking = new ExactMetrics_Tracking();
  200. }
  201. } else {
  202. if ( GADWP_Tools::check_roles( self::$instance->config->options['access_front'] ) ) {
  203. /*
  204. * Load Frontend Setup
  205. */
  206. include_once ( GADWP_DIR . 'front/setup.php' );
  207. self::$instance->frontend_setup = new GADWP_Frontend_Setup();
  208. if ( self::$instance->config->options['frontend_item_reports'] ) {
  209. /*
  210. * Load Frontend Item Reports
  211. */
  212. include_once ( GADWP_DIR . 'front/item-reports.php' );
  213. self::$instance->frontend_item_reports = new GADWP_Frontend_Item_Reports();
  214. }
  215. }
  216. if ( ! GADWP_Tools::check_roles( self::$instance->config->options['track_exclude'], true ) && 'disabled' != self::$instance->config->options['tracking_type'] ) {
  217. /*
  218. * Load tracking class
  219. */
  220. include_once ( GADWP_DIR . 'front/tracking.php' );
  221. self::$instance->tracking = new GADWP_Tracking();
  222. }
  223. }
  224. }
  225. }
  226. }
  227. /**
  228. * Returns a unique instance of GADWP
  229. */
  230. function GADWP() {
  231. return GADWP_Manager::instance();
  232. }
  233. /*
  234. * Start GADWP
  235. */
  236. GADWP();