review.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. <?php
  2. /**
  3. * Ask for some love.
  4. *
  5. * @package MonsterInsights
  6. * @author MonsterInsights
  7. * @since 7.0.7
  8. * @license GPL-2.0+
  9. * @copyright Copyright (c) 2018, MonsterInsights LLC
  10. */
  11. class MonsterInsights_Review {
  12. /**
  13. * Primary class constructor.
  14. *
  15. * @since 7.0.7
  16. */
  17. public function __construct() {
  18. // Admin notice requesting review.
  19. add_action( 'admin_notices', array( $this, 'review_request' ) );
  20. add_action( 'wp_ajax_monsterinsights_review_dismiss', array( $this, 'review_dismiss' ) );
  21. }
  22. /**
  23. * Add admin notices as needed for reviews.
  24. *
  25. * @since 7.0.7
  26. */
  27. public function review_request() {
  28. // Only consider showing the review request to admin users.
  29. if ( ! is_super_admin() ) {
  30. return;
  31. }
  32. // Don't show to lite users
  33. if ( ! monsterinsights_is_pro_version() ) {
  34. return;
  35. }
  36. // If the user has opted out of product annoucement notifications, don't
  37. // display the review request.
  38. if ( monsterinsights_get_option( 'hide_am_notices', false ) || monsterinsights_get_option( 'network_hide_am_notices', false ) ) {
  39. return;
  40. }
  41. // Verify that we can do a check for reviews.
  42. $review = get_option( 'monsterinsights_review' );
  43. $time = time();
  44. $load = false;
  45. if ( ! $review ) {
  46. $review = array(
  47. 'time' => $time,
  48. 'dismissed' => false,
  49. );
  50. update_option( 'monsterinsights_review', $review );
  51. } else {
  52. // Check if it has been dismissed or not.
  53. if ( ( isset( $review['dismissed'] ) && ! $review['dismissed'] ) && ( isset( $review['time'] ) && ( ( $review['time'] + DAY_IN_SECONDS ) <= $time ) ) ) {
  54. $load = true;
  55. }
  56. }
  57. // If we cannot load, return early.
  58. if ( ! $load ) {
  59. return;
  60. }
  61. $this->review();
  62. }
  63. /**
  64. * Maybe show review request.
  65. *
  66. * @since 7.0.7
  67. */
  68. public function review() {
  69. // Fetch when plugin was initially installed.
  70. $activated = get_option( 'monsterinsights_over_time', array() );
  71. if ( ! empty( $activated['installed_date'] ) ) {
  72. // Only continue if plugin has been installed for at least 14 days.
  73. if ( ( $activated['installed_date'] + ( DAY_IN_SECONDS * 14 ) ) > time() ) {
  74. return;
  75. }
  76. } else {
  77. $data = array(
  78. 'installed_version' => MONSTERINSIGHTS_VERSION,
  79. 'installed_date' => time(),
  80. 'installed_pro' => monsterinsights_is_pro_version(),
  81. );
  82. update_option( 'monsterinsights_over_time', $data );
  83. return;
  84. }
  85. // Only proceed with displaying if the user is tracking.
  86. $ua_code = monsterinsights_get_ua_to_output();
  87. if ( empty( $ua_code ) ) {
  88. return;
  89. }
  90. // We have a candidate! Output a review message.
  91. ?>
  92. <div class="notice notice-info is-dismissible monsterinsights-review-notice">
  93. <p><?php esc_html_e( 'Hey, I noticed you\'ve been using MonsterInsights for a while - that’s awesome! Could you please do me a BIG favor and give it a 5-star rating on WordPress to help us spread the word and boost our motivation?', 'google-analytics-for-wordpress' ); ?></p>
  94. <p><strong><?php echo wp_kses( __( '~ Syed Balkhi<br>Co-Founder of MonsterInsights', 'google-analytics-for-wordpress' ), array( 'br' => array() ) ); ?></strong></p>
  95. <p>
  96. <a href="https://wordpress.org/support/plugin/google-analytics-for-wordpress/reviews/?filter=5#new-post" class="monsterinsights-dismiss-review-notice monsterinsights-review-out" target="_blank" rel="noopener noreferrer"><?php esc_html_e( 'Ok, you deserve it', 'google-analytics-for-wordpress' ); ?></a><br>
  97. <a href="#" class="monsterinsights-dismiss-review-notice" target="_blank" rel="noopener noreferrer"><?php esc_html_e( 'Nope, maybe later', 'google-analytics-for-wordpress' ); ?></a><br>
  98. <a href="#" class="monsterinsights-dismiss-review-notice" target="_blank" rel="noopener noreferrer"><?php esc_html_e( 'I already did', 'google-analytics-for-wordpress' ); ?></a>
  99. </p>
  100. </div>
  101. <script type="text/javascript">
  102. jQuery( document ).ready( function ( $ ) {
  103. $( document ).on( 'click', '.monsterinsights-dismiss-review-notice, .monsterinsights-review-notice button', function ( event ) {
  104. if ( ! $( this ).hasClass( 'monsterinsights-review-out' ) ) {
  105. event.preventDefault();
  106. }
  107. $.post( ajaxurl, {
  108. action: 'monsterinsights_review_dismiss'
  109. } );
  110. $( '.monsterinsights-review-notice' ).remove();
  111. } );
  112. } );
  113. </script>
  114. <?php
  115. }
  116. /**
  117. * Dismiss the review admin notice
  118. *
  119. * @since 7.0.7
  120. */
  121. public function review_dismiss() {
  122. $review = get_option( 'monsterinsights_review', array() );
  123. $review['time'] = time();
  124. $review['dismissed'] = true;
  125. update_option( 'monsterinsights_review', $review );
  126. die;
  127. }
  128. }
  129. new MonsterInsights_Review;