| 1 |
<?php |
| 2 |
$optionReview = get_option('bbpc_notify_review'); |
| 3 |
if ( is_admin() && time() >= (int) $optionReview && $optionReview !== '0') { |
| 4 |
add_action('admin_notices', 'bbpc_notify_give_review'); |
| 5 |
add_action('admin_enqueue_scripts', 'bbpc_notify_enqueue_script'); // Hook to admin_enqueue_scripts |
| 6 |
} |
| 7 |
|
| 8 |
function bbpc_notify_enqueue_script() { |
| 9 |
wp_enqueue_script( 'bbpc-notify-review' ); |
| 10 |
} |
| 11 |
|
| 12 |
add_action('wp_ajax_bbpc_notify_save_review', 'bbpc_notify_save_review'); |
| 13 |
|
| 14 |
/** |
| 15 |
** Give Notice |
| 16 |
**/ |
| 17 |
function bbpc_notify_give_review() { |
| 18 |
?> |
| 19 |
<div class="notice notice-success is-dismissible" id="bbpc_notify_review"> |
| 20 |
<h3> <?php _e('Give BBP Core a review', 'bbp-core'); ?> </h3> |
| 21 |
<p> |
| 22 |
<?php _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')?> |
| 23 |
</p> |
| 24 |
<p class="bbpc_notify_review_subheading"> |
| 25 |
<?php _e('We will be forever grateful. Thank you in advance.', 'bbp-core'); ?> |
| 26 |
</p> |
| 27 |
<p> |
| 28 |
<a href="javascript:void(0)" data="rateNow" class="button button-primary" style="margin-right: 5px"><?php _e('Rate now', 'bbp-core')?></a> |
| 29 |
<a href="javascript:void(0)" data="later" class="button" style="margin-right: 5px"><?php _e('Later', 'bbp-core')?></a> |
| 30 |
<a href="javascript:void(0)" data="alreadyDid" class="button"><?php _e('Already did', 'bbp-core')?></a> |
| 31 |
</p> |
| 32 |
</div> |
| 33 |
<?php |
| 34 |
} |
| 35 |
|
| 36 |
/** |
| 37 |
** Save Notice |
| 38 |
**/ |
| 39 |
function bbpc_notify_save_review() { |
| 40 |
if ( isset( $_POST ) ) { |
| 41 |
$nonce = isset( $_POST['nonce'] ) ? sanitize_text_field( $_POST['nonce'] ) : null; |
| 42 |
$field = isset( $_POST['field'] ) ? sanitize_text_field( $_POST['field'] ) : null; |
| 43 |
|
| 44 |
if ( ! wp_verify_nonce( $nonce, 'bbpc-admin-nonce' ) ) { |
| 45 |
wp_send_json_error( array( 'status' => 'Wrong nonce validate!' ) ); |
| 46 |
exit(); |
| 47 |
} |
| 48 |
|
| 49 |
if ( $field == 'later' ) { |
| 50 |
update_option('bbpc_notify_review', time() + 3*60*60*24); //After 3 days show |
| 51 |
} else if ($field == 'alreadyDid') { |
| 52 |
update_option('bbpc_notify_review', 0); |
| 53 |
} |
| 54 |
wp_send_json_success(); |
| 55 |
} |
| 56 |
wp_send_json_error( array( 'message' => 'Update fail!' ) ); |
| 57 |
} |