PluginProbe
Block Animations, Motion & Scroll Effects – Ghost Kit / trunk
Block Animations, Motion & Scroll Effects – Ghost Kit vtrunk
3.7.1 3.7.0 3.6.1 trunk 1.6.3 2.25.0 3.3.0 3.3.1 3.3.2 3.3.3 3.4.0 3.4.1 3.4.2 3.4.3 3.4.4 3.4.5 3.4.6 3.5.0 3.5.1 3.6.0
ghostkit / classes / class-ask-review.php

class-ask-review.php in Block Animations, Motion & Scroll Effects – Ghost Kit trunk, at classes/class-ask-review.php

138 lines 3.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Ask Review Notice.
4 *
5 * @package ghostkit
6 */
7
8 if ( ! defined( 'ABSPATH' ) ) {
9 exit;
10 }
11
12 /**
13 * Class GhostKit_Ask_Review_Notice
14 */
15 class GhostKit_Ask_Review_Notice {
16 /**
17 * Option name.
18 *
19 * @var string
20 */
21 public $option_name = 'gkt_ask_review_notice';
22
23 /**
24 * GhostKit_Ask_Review_Notice constructor.
25 */
26 public function __construct() {
27 add_action( 'admin_notices', array( $this, 'admin_notices' ) );
28 add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) );
29 add_action( 'wp_ajax_gkt_dismiss_ask_review_notice', array( $this, 'ajax_gkt_dismiss_ask_review_notice' ) );
30 }
31
32 /**
33 * Check if we can display notice.
34 */
35 public function is_notice_allowed() {
36 $state = get_site_option( $this->option_name . '_state' );
37 $time = (int) get_site_option( $this->option_name . '_time' );
38
39 if ( 'yes' === $state || 'already' === $state ) {
40 return false;
41 }
42
43 // Save current time if nothing saved.
44 if ( ! $time ) {
45 $time = time();
46 update_site_option( $this->option_name . '_time', $time );
47 }
48
49 // Allow notice if plugin used for more then 2 weeks.
50 if ( $time < strtotime( '-14 days' ) ) {
51 return true;
52 }
53
54 return false;
55 }
56
57 /**
58 * Display admin notice if needed.
59 */
60 public function admin_notices() {
61 if ( ! $this->is_notice_allowed() ) {
62 return;
63 }
64 ?>
65 <div class="notice notice-info gkt-admin-notice" id="gkt-review-plugin-notice">
66 <div class="gkt-admin-notice-icon">
67 <i class="dashicons-ghostkit"></i>
68 </div>
69 <div class="gkt-admin-notice-content">
70 <h3><?php esc_html_e( 'Satisfied using Ghost Kit?', 'ghostkit' ); ?></h3>
71 <p>
72 <?php
73 // translators: %s - Plugin name.
74 echo wp_kses_post( sprintf( __( 'Hey, we noticed you\'ve been using %s for more than two weeks now - that\'s awesome!', 'ghostkit' ), '<strong>' . _x( 'Ghost Kit', 'plugin name inside the review notice', 'ghostkit' ) . '</strong>' ) );
75 ?>
76 <br>
77 <?php esc_html_e( 'Could you please do us a BIG favor and give it a rating on WordPress.org to help us spread the word and boost our motivation?', 'ghostkit' ); ?>
78 </p>
79 <p>
80 <a href="https://wordpress.org/support/plugin/ghostkit/reviews/?filter=5#new-post" class="gkt-review-plugin-notice-dismiss" data-gkt-review-action="yes" target="_blank" rel="noopener noreferrer">
81 <strong>
82 <?php esc_html_e( 'Yes, you deserve it', 'ghostkit' ); ?>
83 </strong>
84 </a>
85 <br>
86 <a href="#" class="gkt-review-plugin-notice-dismiss" data-gkt-review-action="later">
87 <?php esc_html_e( 'No, maybe later', 'ghostkit' ); ?>
88 </a><br>
89 <a href="#" class="gkt-review-plugin-notice-dismiss" data-gkt-review-action="already">
90 <?php esc_html_e( 'I already did', 'ghostkit' ); ?>
91 </a>
92 </p>
93 </div>
94 </div>
95 <?php
96 }
97
98 /**
99 * Enqueue script.
100 */
101 public function admin_enqueue_scripts() {
102 if ( is_customize_preview() ) {
103 return;
104 }
105
106 GhostKit_Assets::enqueue_script( 'ghostkit-ask-review-notice', 'build/assets/admin/js/ask-review-notice' );
107 wp_localize_script(
108 'ghostkit-ask-review-notice',
109 'GKTAskReviewNotice',
110 array(
111 'nonce' => wp_create_nonce( $this->option_name ),
112 )
113 );
114 }
115
116 /**
117 * Handles Ajax request to persist notices dismissal.
118 * Uses check_ajax_referer to verify nonce.
119 */
120 public function ajax_gkt_dismiss_ask_review_notice() {
121 check_ajax_referer( $this->option_name, 'nonce' );
122
123 $type = isset( $_POST['type'] ) ? sanitize_text_field( wp_unslash( $_POST['type'] ) ) : 'yes';
124
125 update_site_option( $this->option_name . '_state', $type );
126
127 // Update time if user clicked "No, maybe later" button.
128 if ( 'later' === $type ) {
129 $time = time();
130 update_site_option( $this->option_name . '_time', $time );
131 }
132
133 wp_die();
134 }
135 }
136
137 new GhostKit_Ask_Review_Notice();
138