DB
1 year ago
Request
1 year ago
UI
1 year ago
Check_Email_Admin_Capability_Giver.php
1 year ago
Check_Email_Export_Log.php
1 year ago
Check_Email_From_Handler.php
1 year ago
Check_Email_Log.php
1 year ago
Check_Email_Logger.php
1 year ago
Check_Email_Review.php
1 year ago
Loadie.php
1 year ago
Check_Email_Review.php
167 lines
| 1 | <?php namespace CheckEmail\Core; |
| 2 | |
| 3 | defined( 'ABSPATH' ) || exit; // Exit if accessed directly |
| 4 | |
| 5 | /** |
| 6 | * Class Check Email Review. |
| 7 | */ |
| 8 | class Check_Email_Review { |
| 9 | |
| 10 | private $value; |
| 11 | private $messages; |
| 12 | private $link = 'https://wordpress.org/support/plugin/%s/reviews/#new-post'; |
| 13 | private $slug = 'check-email'; |
| 14 | |
| 15 | function __construct() { |
| 16 | |
| 17 | $this->messages = array( |
| 18 | 'notice' => esc_html__( "Hi there! Stoked to see you're using Check & Log Email for a few days now - hope you like it! And if you do, please consider rating it. It would mean the world to us. Keep on rocking!", 'check-email' ), |
| 19 | 'rate' => esc_html__( 'Rate the plugin', 'check-email' ), |
| 20 | 'rated' => esc_html__( 'Remind me later', 'check-email' ), |
| 21 | 'no_rate' => esc_html__( 'Don\'t show again', 'check-email' ), |
| 22 | ); |
| 23 | |
| 24 | if ( isset( $args['messages'] ) ) { |
| 25 | $this->messages = wp_parse_args( $args['messages'], $this->messages ); |
| 26 | } |
| 27 | |
| 28 | add_action( 'init', array( $this, 'init' ) ); |
| 29 | |
| 30 | } |
| 31 | |
| 32 | public function init() { |
| 33 | if ( ! is_admin() ) { |
| 34 | return; |
| 35 | } |
| 36 | |
| 37 | $this->value = $this->value(); |
| 38 | |
| 39 | if ( $this->check() ) { |
| 40 | add_action( 'admin_notices', array( $this, 'five_star_wp_rate_notice' ) ); |
| 41 | add_action( 'wp_ajax_epsilon_check-email_review', array( $this, 'ajax' ) ); |
| 42 | add_action( 'admin_enqueue_scripts', array( $this, 'enqueue' ) ); |
| 43 | add_action( 'admin_print_footer_scripts', array( $this, 'ajax_script' ) ); |
| 44 | } |
| 45 | |
| 46 | } |
| 47 | |
| 48 | private function check() { |
| 49 | |
| 50 | if ( ! current_user_can('manage_options') ) { |
| 51 | return false; |
| 52 | } |
| 53 | |
| 54 | return( time() > $this->value ); |
| 55 | |
| 56 | } |
| 57 | |
| 58 | private function value() { |
| 59 | |
| 60 | $value = get_option( 'check-email-rate-time', false ); |
| 61 | |
| 62 | if ( $value ) { |
| 63 | return $value; |
| 64 | } |
| 65 | |
| 66 | $value = time() + DAY_IN_SECONDS; |
| 67 | update_option( 'check-email-rate-time', $value ); |
| 68 | |
| 69 | return $value; |
| 70 | |
| 71 | } |
| 72 | |
| 73 | public function five_star_wp_rate_notice() { |
| 74 | $url = sprintf( $this->link, $this->slug ); |
| 75 | |
| 76 | ?> |
| 77 | <div id="<?php echo esc_attr($this->slug) ?>-epsilon-review-notice" class="notice notice-success is-dismissible" style="margin-top:30px;"> |
| 78 | <p><?php echo sprintf( esc_html( $this->messages['notice'] ), esc_html( $this->value ) ) ; ?></p> |
| 79 | <p class="actions"> |
| 80 | <a id="epsilon-rate" href="<?php echo esc_url( $url ) ?>" target="_blank" class="button button-primary epsilon-review-button"> |
| 81 | <?php echo esc_html( $this->messages['rate'] ); ?> |
| 82 | </a> |
| 83 | <a id="epsilon-later" href="#" style="margin-left:10px" class="epsilon-review-button"><?php echo esc_html( $this->messages['rated'] ); ?></a> |
| 84 | <a id="epsilon-no-rate" href="#" style="margin-left:10px" class="epsilon-review-button"><?php echo esc_html( $this->messages['no_rate'] ); ?></a> |
| 85 | </p> |
| 86 | </div> |
| 87 | <?php |
| 88 | } |
| 89 | |
| 90 | public function ajax() { |
| 91 | |
| 92 | check_ajax_referer( 'epsilon-check-email-review', 'security' ); |
| 93 | |
| 94 | if ( ! current_user_can('manage_options') ) { |
| 95 | return false; |
| 96 | } |
| 97 | |
| 98 | if ( ! isset( $_POST['check'] ) ) { |
| 99 | wp_die( 'ok' ); |
| 100 | } |
| 101 | |
| 102 | $time = get_option( 'check-email-rate-time' ); |
| 103 | |
| 104 | if ( 'epsilon-rate' == $_POST['check'] ) { |
| 105 | $time = time() + YEAR_IN_SECONDS * 5; |
| 106 | }elseif ( 'epsilon-later' == $_POST['check'] ) { |
| 107 | $time = time() + WEEK_IN_SECONDS; |
| 108 | }elseif ( 'epsilon-no-rate' == $_POST['check'] ) { |
| 109 | $time = time() + YEAR_IN_SECONDS * 5; |
| 110 | } |
| 111 | |
| 112 | update_option( 'check-email-rate-time', $time ); |
| 113 | wp_die( 'ok' ); |
| 114 | |
| 115 | } |
| 116 | |
| 117 | public function enqueue() { |
| 118 | wp_enqueue_script( 'jquery' ); |
| 119 | } |
| 120 | |
| 121 | public function ajax_script() { |
| 122 | |
| 123 | $ajax_nonce = wp_create_nonce( "epsilon-check-email-review" ); |
| 124 | |
| 125 | ?> |
| 126 | |
| 127 | <script type="text/javascript"> |
| 128 | jQuery( document ).ready( function( $ ){ |
| 129 | |
| 130 | $( '#check-email-epsilon-review-notice button' ).on( 'click', function(){ |
| 131 | $( '#epsilon-no-rate' ).trigger( 'click' ); |
| 132 | }); |
| 133 | |
| 134 | $( '.epsilon-review-button' ).on( 'click', function( evt ){ |
| 135 | var href = $(this).attr('href'), |
| 136 | id = $(this).attr('id'); |
| 137 | |
| 138 | if ( 'epsilon-rate' != id ) { |
| 139 | evt.preventDefault(); |
| 140 | } |
| 141 | |
| 142 | var data = { |
| 143 | action: 'epsilon_check-email_review', |
| 144 | security: '<?php echo esc_js($ajax_nonce); ?>', |
| 145 | check: id |
| 146 | }; |
| 147 | |
| 148 | if ( 'epsilon-rated' === id ) { |
| 149 | data['epsilon-review'] = 1; |
| 150 | } |
| 151 | |
| 152 | $.post( '<?php echo esc_url( admin_url( 'admin-ajax.php' ) ) ?>', data, function( response ) { |
| 153 | $( '#<?php echo esc_html( $this->slug ) ?>-epsilon-review-notice' ).slideUp( 'fast', function() { |
| 154 | $( this ).remove(); |
| 155 | } ); |
| 156 | }); |
| 157 | |
| 158 | } ); |
| 159 | |
| 160 | }); |
| 161 | </script> |
| 162 | |
| 163 | <?php |
| 164 | } |
| 165 | } |
| 166 | |
| 167 |