| 1 |
<?php |
| 2 |
/** |
| 3 |
* Admin Notices |
| 4 |
* |
| 5 |
* @package GamiPress\Admin\Notices |
| 6 |
* @author GamiPress <contact@gamipress.com>, Ruben Garcia <rubengcdev@gmail.com> |
| 7 |
* @since 1.5.9 |
| 8 |
*/ |
| 9 |
// Exit if accessed directly |
| 10 |
if( !defined( 'ABSPATH' ) ) exit; |
| 11 |
|
| 12 |
/** |
| 13 |
* GamiPress admin notices |
| 14 |
* |
| 15 |
* @since 1.5.9 |
| 16 |
*/ |
| 17 |
function gamipress_admin_notices() { |
| 18 |
|
| 19 |
// Bail if current user is not a site administrator |
| 20 |
if( ! current_user_can( 'update_plugins' ) ){ |
| 21 |
return; |
| 22 |
} |
| 23 |
|
| 24 |
// Check if user checked already hide the review notice |
| 25 |
if( gamipress_is_network_wide_active() ) { |
| 26 |
$hide_review_notice = ( $exists = get_site_option( 'gamipress_hide_review_notice' ) ) ? $exists : ''; |
| 27 |
} else { |
| 28 |
$hide_review_notice = ( $exists = get_option( 'gamipress_hide_review_notice' ) ) ? $exists : ''; |
| 29 |
} |
| 30 |
|
| 31 |
if( $hide_review_notice !== 'yes' ) { |
| 32 |
|
| 33 |
// Get the GamiPress installation date |
| 34 |
if( gamipress_is_network_wide_active() ) { |
| 35 |
$gamipress_install_date = ( $exists = get_site_option( 'gamipress_install_date' ) ) ? $exists : date( 'Y-m-d H:i:s' ); |
| 36 |
} else { |
| 37 |
$gamipress_install_date = ( $exists = get_option( 'gamipress_install_date' ) ) ? $exists : date( 'Y-m-d H:i:s' ); |
| 38 |
} |
| 39 |
|
| 40 |
$now = date( 'Y-m-d h:i:s' ); |
| 41 |
$datetime1 = new DateTime( $gamipress_install_date ); |
| 42 |
$datetime2 = new DateTime( $now ); |
| 43 |
|
| 44 |
// Difference in days between installation date and now |
| 45 |
$diff_interval = round( ( $datetime2->format( 'U' ) - $datetime1->format( 'U' ) ) / ( 60 * 60 * 24 ) ); |
| 46 |
|
| 47 |
if( $diff_interval >= 7 ) { |
| 48 |
?> |
| 49 |
|
| 50 |
<div class="notice gamipress-review-notice"> |
| 51 |
<p> |
| 52 |
<?php _e( 'Awesome! You\'ve been using <strong>GamiPress</strong> for a while.', 'gamipress' ); ?><br> |
| 53 |
<?php _e( 'May I ask you to give it a <strong>5-star rating</strong> on WordPress?', 'gamipress' ); ?><br> |
| 54 |
<?php _e( 'This will help to spread its popularity and to make this plugin a better one.', 'gamipress' ); ?><br> |
| 55 |
<br> |
| 56 |
<?php _e( 'Your help is much appreciated. Thank you very much,', 'gamipress' ); ?><br> |
| 57 |
<span>~Ruben Garcia</span> |
| 58 |
</p> |
| 59 |
<ul> |
| 60 |
<li><a href="https://wordpress.org/support/plugin/gamipress/reviews/?rate=5#new-post" class="button button-primary" target="_blank" title="<?php _e( 'Yes, I want to rate it!', 'gamipress' ); ?>"><?php _e( 'Yes, I want to rate it!', 'gamipress' ); ?></a></li> |
| 61 |
<li><a href="javascript:void(0);" class="gamipress-hide-review-notice button" title="<?php _e( 'I already did', 'gamipress' ); ?>"><?php _e( 'I already did', 'gamipress' ); ?></a></li> |
| 62 |
<li><a href="javascript:void(0);" class="gamipress-hide-review-notice" title="<?php _e( 'No, I don\'t want to rate it', 'gamipress' ); ?>"><small><?php _e( 'No, I don\'t want to rate it', 'gamipress' ); ?></small></a></li> |
| 63 |
</ul> |
| 64 |
<span class="dashicons-before dashicons-gamipress"></span> |
| 65 |
</div> |
| 66 |
|
| 67 |
<?php |
| 68 |
} |
| 69 |
|
| 70 |
} |
| 71 |
|
| 72 |
} |
| 73 |
add_action( 'admin_notices', 'gamipress_admin_notices' ); |
| 74 |
|
| 75 |
/** |
| 76 |
* Ajax handler for hide review notice action |
| 77 |
* |
| 78 |
* @since 1.5.9 |
| 79 |
*/ |
| 80 |
function gamipress_ajax_hide_review_notice() { |
| 81 |
// Security check, forces to die if not security passed |
| 82 |
check_ajax_referer( 'gamipress_admin', 'nonce' ); |
| 83 |
|
| 84 |
if( gamipress_is_network_wide_active() ) { |
| 85 |
update_site_option( 'gamipress_hide_review_notice', 'yes' ); |
| 86 |
} else { |
| 87 |
update_option( 'gamipress_hide_review_notice', 'yes' ); |
| 88 |
} |
| 89 |
|
| 90 |
wp_send_json_success( array( 'success' ) ); |
| 91 |
exit; |
| 92 |
} |
| 93 |
|
| 94 |
add_action( 'wp_ajax_gamipress_hide_review_notice', 'gamipress_ajax_hide_review_notice' ); |
| 95 |
|