/includes/admin/pages/dashboard.php

  1. <?php 
  2. /** 
  3. * Callback for getting all of the reports tabs for MonsterInsights. 
  4. * 
  5. * @since 6.0.0 
  6. * @access public 
  7. * 
  8. * @return array Array of tab information. 
  9. */ 
  10. function monsterinsights_get_dashboard_report() { 
  11. $reports = monsterinsights_get_reports(); 
  12. $picked = monsterinsights_get_option( 'dashboard_report', 'overview' ); 
  13. if ( ! empty( $reports ) && is_array( $reports ) && array_key_exists ( $picked, $reports ) ) { 
  14. return array( 'id' => $picked, 'title' => $reports[ $picked ] ); 
  15. } else { 
  16. return array(); 
  17.  
  18. /** 
  19. * Callback to output the MonsterInsights reports page. 
  20. * 
  21. * @since 6.0.0 
  22. * @access public 
  23. * 
  24. * @return void 
  25. */ 
  26. function monsterinsights_dashboard_page() { 
  27. /**  
  28. * Developer Alert: 
  29. * 
  30. * Per the README, this is considered an internal hook and should 
  31. * not be used by other developers. This hook's behavior may be modified 
  32. * or the hook may be removed at any time, without warning. 
  33. */ 
  34. do_action( 'monsterinsights_head' ); 
  35.  
  36. if ( ! current_user_can( 'monsterinsights_view_dashboard' ) ) { 
  37. wp_die( esc_html__( 'Access denied' , 'google-analytics-for-wordpress' ) ); 
  38.  
  39. $dashboard_disabled = monsterinsights_get_option( 'dashboard_disabled', false ); 
  40. $profile_enabled = monsterinsights_get_option( 'analytics_profile', false ); // not using profile 
  41. $oauth_version = monsterinsights_get_option( 'oauth_version', '1.0' ); 
  42. $last_run = monsterinsights_get_option( 'cron_last_run', false ); 
  43. $failed = monsterinsights_get_option( 'cron_failed', false ); 
  44. $pro_access_key = get_option( 'monsterinsights_pro_access_token', false ); 
  45. $lite_access_key = get_option( 'monsterinsights_lite_access_token', false ); 
  46. $needs_re_auth = ( ( $failed && ( $last_run === false || monsterinsights_hours_between( $last_run ) >= 48 ) ) || ( empty( $pro_access_key ) && empty( $lite_access_key ) ) || ( version_compare( $oauth_version, '1.0', '<' ) ) ) ? true : false; 
  47. ?> 
  48. <?php echo monsterinsights_ublock_notice(); ?> 
  49. <div id="monsterinsights-reports" class="wrap"> 
  50. <div class="monsterinsights-clear"> 
  51. <div class="monsterinsights-reports-action-bar"> 
  52. <div class="monsterinsights-reports-action-bar-title"> 
  53. <?php esc_html_e( 'Dashboard', 'google-analytics-for-wordpress' );?> 
  54. </div> 
  55. <div class="monsterinsights-reports-action-bar-actions"><?php  
  56. /**  
  57. * Developer Alert: 
  58. * 
  59. * Per the README, this is considered an internal hook and should 
  60. * not be used by other developers. This hook's behavior may be modified 
  61. * or the hook may be removed at any time, without warning. 
  62. */ 
  63. do_action( 'monsterinsights_tab_reports_actions' );  
  64. ?>  
  65. </div> 
  66. </div> 
  67. <?php  
  68. $report = monsterinsights_get_dashboard_report(); 
  69. ?> 
  70. <div id="monsterinsights_dashboard_container"> 
  71. <?php if ( $dashboard_disabled ) { ?> 
  72. <?php  
  73. if ( current_user_can( 'monsterinsights_save_settings' ) ) { 
  74. echo monsterinsights_get_message( 'error', sprintf( 
  75. sprintf( 
  76. esc_html__( 'Please %1$senable the dashboard%2$s to see report data.', 'google-analytics-for-wordpress' ),  
  77. '<a href="' . admin_url( 'admin.php?page=monsterinsights_settings' ) . '">',  
  78. '</a>' 
  79. ) ); 
  80. } else { 
  81. echo monsterinsights_get_message( 'error', esc_html__( 'The Google oAuth authentication needs to be re-authenticated to view data.', 'google-analytics-for-wordpress' ) ); 
  82. ?> 
  83. <?php } else if ( ! $profile_enabled ) { ?> 
  84. <?php  
  85. if ( current_user_can( 'monsterinsights_save_settings' ) ) { 
  86. echo monsterinsights_get_message( 'error', sprintf( 
  87. sprintf( 
  88. esc_html__( 'Please %1$sauthenticate %2$swith Google Analytics to allow the plugin to fetch data.', 'google-analytics-for-wordpress' ),  
  89. '<a href="' . admin_url( 'admin.php?page=monsterinsights_settings' ) . '">',  
  90. '</a>' 
  91. ) ); 
  92. } else { 
  93. echo monsterinsights_get_message( 'error', esc_html__( 'The Google oAuth authentication needs to be re-authenticated to view data.', 'google-analytics-for-wordpress' ) ); 
  94. ?> 
  95. <?php } else if ( $needs_re_auth ) { ?> 
  96. <?php  
  97. if ( current_user_can( 'monsterinsights_save_settings' ) ) { 
  98. echo monsterinsights_get_message( 'error', sprintf( 
  99. sprintf( 
  100. esc_html__( 'Please %1$sre-authenticate%2$s with Google Analytics to allow the plugin to fetch data.', 'google-analytics-for-wordpress' ),  
  101. '<a href="' . admin_url( 'admin.php?page=monsterinsights_settings' ) . '">',  
  102. '</a>' 
  103. ) ); 
  104. } else { 
  105. echo monsterinsights_get_message( 'error', esc_html__( 'The Google oAuth authentication needs to be re-authenticated to view data.', 'google-analytics-for-wordpress' ) ); 
  106. ?> 
  107. <?php } else if ( $failed ) { ?> 
  108. <?php  
  109. if ( current_user_can( 'monsterinsights_save_settings' ) ) { 
  110. echo monsterinsights_get_message( 'error', sprintf( 
  111. sprintf( 
  112. esc_html__( 'Data is not up-to-date, there was an error in retrieving the data from Google Analytics. This error could be caused by several issues. If the error persists, please see %1$sthis page%2$s.', 'google-analytics-for-wordpress' ),  
  113. '<a href="https://www.monsterinsights.com/docs/blocked-connection/">',  
  114. '</a>' 
  115. ) ); 
  116. } else { 
  117. echo monsterinsights_get_message( 'error', esc_html__( 'The Google oAuth authentication needs to be re-authenticated to view data.', 'google-analytics-for-wordpress' ) ); 
  118. ?> 
  119. <?php } else { ?> 
  120. <div class="monsterinsights-reports-wrap"> 
  121. <?php 
  122. /**  
  123. * Developer Alert: 
  124. * 
  125. * Per the README, this is considered an internal hook and should 
  126. * not be used by other developers. This hook's behavior may be modified 
  127. * or the hook may be removed at any time, without warning. 
  128. */ 
  129. ?> 
  130. <?php do_action( 'monsterinsights_tab_reports_notices' ); ?> 
  131. <?php 
  132. /**  
  133. * Developer Alert: 
  134. * 
  135. * Per the README, this is considered an internal hook and should 
  136. * not be used by other developers. This hook's behavior may be modified 
  137. * or the hook may be removed at any time, without warning. 
  138. */ 
  139. ?> 
  140. <?php do_action( 'monsterinsights_tab_reports_' . $report['id'] ); ?> 
  141. </div> 
  142. <?php } ?> 
  143. </div> 
  144. </div> 
  145. </div> 
  146. <?php 
.