暂无描述

class-review.php 6.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. <?php
  2. /**
  3. * Ask for some love.
  4. *
  5. * @since 1.3.2
  6. */
  7. class WPForms_Review {
  8. /**
  9. * Primary class constructor.
  10. *
  11. * @since 1.3.2
  12. */
  13. public function __construct() {
  14. // Admin notice requesting review.
  15. add_action( 'admin_init', [ $this, 'review_request' ] );
  16. add_action( 'wp_ajax_wpforms_review_dismiss', [ $this, 'review_dismiss' ] );
  17. // Admin footer text.
  18. add_filter( 'admin_footer_text', [ $this, 'admin_footer' ], 1, 2 );
  19. }
  20. /**
  21. * Add admin notices as needed for reviews.
  22. *
  23. * @since 1.3.2
  24. */
  25. public function review_request() {
  26. // Only consider showing the review request to admin users.
  27. if ( ! is_super_admin() ) {
  28. return;
  29. }
  30. // If the user has opted out of product announcement notifications, don't
  31. // display the review request.
  32. if ( wpforms_setting( 'hide-announcements', false ) ) {
  33. return;
  34. }
  35. // Verify that we can do a check for reviews.
  36. $notices = get_option( 'wpforms_admin_notices', [] );
  37. $time = time();
  38. $load = false;
  39. if ( empty( $notices['review_request'] ) ) {
  40. $notices['review_request'] = [
  41. 'time' => $time,
  42. 'dismissed' => false,
  43. ];
  44. update_option( 'wpforms_admin_notices', $notices );
  45. return;
  46. }
  47. // Check if it has been dismissed or not.
  48. if (
  49. ( isset( $notices['review_request']['dismissed'] ) &&
  50. ! $notices['review_request']['dismissed'] ) &&
  51. (
  52. isset( $notices['review_request']['time'] ) &&
  53. ( ( $notices['review_request']['time'] + DAY_IN_SECONDS ) <= $time )
  54. )
  55. ) {
  56. $load = true;
  57. }
  58. // If we cannot load, return early.
  59. if ( ! $load ) {
  60. return;
  61. }
  62. // Logic is slightly different depending on what's at our disposal.
  63. if ( wpforms()->pro && class_exists( 'WPForms_Entry_Handler', false ) ) {
  64. $this->review();
  65. } else {
  66. $this->review_lite();
  67. }
  68. }
  69. /**
  70. * Maybe show review request.
  71. *
  72. * @since 1.3.9
  73. */
  74. public function review() {
  75. // Fetch total entries.
  76. $entries = wpforms()->entry->get_entries( [ 'number' => 50 ], true );
  77. // Only show review request if the site has collected at least 50 entries.
  78. if ( empty( $entries ) || $entries < 50 ) {
  79. return;
  80. }
  81. ob_start();
  82. // We have a candidate! Output a review message.
  83. ?>
  84. <p><?php esc_html_e( 'Hey, I noticed you collected over 50 entries from WPForms - 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?', 'wpforms-lite' ); ?></p>
  85. <p><strong><?php echo wp_kses( __( '~ Syed Balkhi<br>Co-Founder of WPForms', 'wpforms-lite' ), [ 'br' => [] ] ); ?></strong></p>
  86. <p>
  87. <a href="https://wordpress.org/support/plugin/wpforms-lite/reviews/?filter=5#new-post" class="wpforms-notice-dismiss wpforms-review-out" target="_blank" rel="noopener"><?php esc_html_e( 'Ok, you deserve it', 'wpforms-lite' ); ?></a><br>
  88. <a href="#" class="wpforms-notice-dismiss" target="_blank" rel="noopener noreferrer"><?php esc_html_e( 'Nope, maybe later', 'wpforms-lite' ); ?></a><br>
  89. <a href="#" class="wpforms-notice-dismiss" target="_blank" rel="noopener noreferrer"><?php esc_html_e( 'I already did', 'wpforms-lite' ); ?></a>
  90. </p>
  91. <?php
  92. \WPForms\Admin\Notice::info(
  93. ob_get_clean(),
  94. [
  95. 'dismiss' => \WPForms\Admin\Notice::DISMISS_GLOBAL,
  96. 'slug' => 'review_request',
  97. 'autop' => false,
  98. 'class' => 'wpforms-review-notice',
  99. ]
  100. );
  101. }
  102. /**
  103. * Maybe show Lite review request.
  104. *
  105. * @since 1.3.9
  106. */
  107. public function review_lite() {
  108. // Fetch when plugin was initially installed.
  109. $activated = get_option( 'wpforms_activated', [] );
  110. if ( ! empty( $activated['lite'] ) ) {
  111. // Only continue if plugin has been installed for at least 7 days.
  112. if ( ( $activated['lite'] + ( DAY_IN_SECONDS * 14 ) ) > time() ) {
  113. return;
  114. }
  115. } else {
  116. $activated['lite'] = time();
  117. update_option( 'wpforms_activated', $activated );
  118. return;
  119. }
  120. // Only proceed with displaying if the user created at least one form.
  121. $form_count = wp_count_posts( 'wpforms' );
  122. if ( empty( $form_count->publish ) ) {
  123. return;
  124. }
  125. // Check if the Constant Contact notice is displaying.
  126. $cc = get_option( 'wpforms_constant_contact', false );
  127. // If it's displaying don't ask for review until they configure CC or
  128. // dismiss the notice.
  129. if ( $cc ) {
  130. return;
  131. }
  132. ob_start();
  133. // We have a candidate! Output a review message.
  134. ?>
  135. <p><?php esc_html_e( 'Hey, I noticed you created a contact form with WPForms - 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?', 'wpforms-lite' ); ?></p>
  136. <p><strong><?php echo wp_kses( __( '~ Syed Balkhi<br>Co-Founder of WPForms', 'wpforms-lite' ), [ 'br' => [] ] ); ?></strong></p>
  137. <p>
  138. <a href="https://wordpress.org/support/plugin/wpforms-lite/reviews/?filter=5#new-post" class="wpforms-notice-dismiss wpforms-review-out" target="_blank" rel="noopener noreferrer"><?php esc_html_e( 'Ok, you deserve it', 'wpforms-lite' ); ?></a><br>
  139. <a href="#" class="wpforms-notice-dismiss" target="_blank" rel="noopener noreferrer"><?php esc_html_e( 'Nope, maybe later', 'wpforms-lite' ); ?></a><br>
  140. <a href="#" class="wpforms-notice-dismiss" target="_blank" rel="noopener noreferrer"><?php esc_html_e( 'I already did', 'wpforms-lite' ); ?></a>
  141. </p>
  142. <?php
  143. \WPForms\Admin\Notice::info(
  144. ob_get_clean(),
  145. [
  146. 'dismiss' => \WPForms\Admin\Notice::DISMISS_GLOBAL,
  147. 'slug' => 'review_lite_request',
  148. 'autop' => false,
  149. 'class' => 'wpforms-review-notice',
  150. ]
  151. );
  152. }
  153. /**
  154. * Dismiss the review admin notice.
  155. *
  156. * @deprecated 1.6.7.1
  157. *
  158. * @since 1.3.2
  159. */
  160. public function review_dismiss() {
  161. _deprecated_function( __CLASS__ . '::' . __METHOD__, '1.6.7.1 of the WPForms plugin' );
  162. $review = get_option( 'wpforms_review', [] );
  163. $review['time'] = time();
  164. $review['dismissed'] = true;
  165. update_option( 'wpforms_review', $review );
  166. die;
  167. }
  168. /**
  169. * When user is on a WPForms related admin page, display footer text
  170. * that graciously asks them to rate us.
  171. *
  172. * @since 1.3.2
  173. *
  174. * @param string $text Footer text.
  175. *
  176. * @return string
  177. */
  178. public function admin_footer( $text ) {
  179. global $current_screen;
  180. if ( ! empty( $current_screen->id ) && strpos( $current_screen->id, 'wpforms' ) !== false ) {
  181. $url = 'https://wordpress.org/support/plugin/wpforms-lite/reviews/?filter=5#new-post';
  182. $text = sprintf(
  183. wp_kses( /* translators: $1$s - WPForms plugin name; $2$s - WP.org review link; $3$s - WP.org review link. */
  184. __( 'Please rate %1$s <a href="%2$s" target="_blank" rel="noopener noreferrer">&#9733;&#9733;&#9733;&#9733;&#9733;</a> on <a href="%3$s" target="_blank" rel="noopener">WordPress.org</a> to help us spread the word. Thank you from the WPForms team!', 'wpforms-lite' ),
  185. [
  186. 'a' => [
  187. 'href' => [],
  188. 'target' => [],
  189. 'rel' => [],
  190. ],
  191. ]
  192. ),
  193. '<strong>WPForms</strong>',
  194. $url,
  195. $url
  196. );
  197. }
  198. return $text;
  199. }
  200. }
  201. new WPForms_Review();