| 1 |
<?php |
| 2 |
$optionReview = get_option('bbpc_notify_review'); |
| 3 |
if ( is_admin() && time() >= (int) $optionReview && $optionReview !== '0') { |
| 4 |
add_action('admin_enqueue_scripts', 'bbpc_notify_enqueue_script'); // Hook to admin_enqueue_scripts |
| 5 |
|
| 6 |
$bbpc_installed = get_option('bbpc_installed'); |
| 7 |
// Check if timestamp exists |
| 8 |
if ( $bbpc_installed ) { |
| 9 |
// Add 7days to the timestamp |
| 10 |
$show_notice = $bbpc_installed + (7 * 24 * 60 * 60); |
| 11 |
|
| 12 |
// Get the current time |
| 13 |
$current_time = current_time('timestamp'); |
| 14 |
|
| 15 |
// Compare current time with timestamp + 7 days |
| 16 |
if ( $current_time >= $show_notice ) { |
| 17 |
add_action('admin_notices', 'bbpc_notify_give_review'); |
| 18 |
} |
| 19 |
} |
| 20 |
} |
| 21 |
|
| 22 |
function bbpc_notify_enqueue_script() { |
| 23 |
wp_enqueue_script( 'bbpc-notify-review' ); |
| 24 |
} |
| 25 |
|
| 26 |
add_action('wp_ajax_bbpc_notify_save_review', 'bbpc_notify_save_review'); |
| 27 |
|
| 28 |
/** |
| 29 |
** Give Notice |
| 30 |
**/ |
| 31 |
function bbpc_notify_give_review() { |
| 32 |
?> |
| 33 |
<div class="notice notice-success is-dismissible" id="bbpc_notify_review"> |
| 34 |
<h3> <?php esc_html_e('Give BBP Core a review', 'bbp-core'); ?> </h3> |
| 35 |
<p> |
| 36 |
<?php esc_html_e('Thank you for choosing BBP Core. We hope you love it. Could you take a couple of seconds posting a nice review to share your happy experience?', 'bbp-core')?> |
| 37 |
</p> |
| 38 |
<p class="bbpc_notify_review_subheading"> |
| 39 |
<?php esc_html_e('We will be forever grateful. Thank you in advance.', 'bbp-core'); ?> |
| 40 |
</p> |
| 41 |
<p> |
| 42 |
<a href="javascript:void(0)" data="rateNow" class="button button-primary" style="margin-right: 5px"><?php esc_html_e('Rate now', 'bbp-core')?></a> |
| 43 |
<a href="javascript:void(0)" data="later" class="button" style="margin-right: 5px"><?php esc_html_e('Later', 'bbp-core')?></a> |
| 44 |
<a href="javascript:void(0)" data="alreadyDid" class="button"><?php esc_html_e('Already did', 'bbp-core')?></a> |
| 45 |
</p> |
| 46 |
</div> |
| 47 |
<?php |
| 48 |
} |
| 49 |
|
| 50 |
/** |
| 51 |
** Save Notice |
| 52 |
**/ |
| 53 |
function bbpc_notify_save_review() { |
| 54 |
if ( isset( $_POST ) ) { |
| 55 |
$nonce = isset( $_POST['nonce'] ) ? sanitize_text_field( $_POST['nonce'] ) : null; |
| 56 |
$field = isset( $_POST['field'] ) ? sanitize_text_field( $_POST['field'] ) : null; |
| 57 |
|
| 58 |
if ( ! wp_verify_nonce( $nonce, 'bbpc-admin-nonce' ) ) { |
| 59 |
wp_send_json_error( array( 'status' => esc_html__('Wrong nonce validate!', 'bbp-core') ) ); |
| 60 |
exit(); |
| 61 |
} |
| 62 |
|
| 63 |
if ( $field == 'later' ) { |
| 64 |
update_option('bbpc_notify_review', time() + 3*60*60*24); //After 3 days show |
| 65 |
} else if ( $field == 'alreadyDid' ) { |
| 66 |
update_option('bbpc_notify_review', 0); |
| 67 |
} |
| 68 |
wp_send_json_success(); |
| 69 |
} |
| 70 |
wp_send_json_error( array( 'message' => esc_html__('Update fail!', 'bbp-core') ) ); |
| 71 |
} |
| 72 |
|