Plugin Directory

source: gdpr-cookie-compliance/tags/4.15.1/controllers/class-moove-gdpr-review.php

Last change on this file was 3102142, checked in by MooveAgency, 4 weeks ago

Version 4.15.1 released

File size: 8.9 KB
Line 
1<?php
2/**
3 * Moove_GDPR_Review File Doc Comment
4 *
5 * @category Moove_GDPR_Review
6 * @package   gdpr-cookie-compliance
7 * @author    Moove Agency
8 */
9
10if ( ! defined( 'ABSPATH' ) ) {
11        exit;
12} // Exit if accessed directly
13
14/**
15 * Moove_GDPR_Review Class Doc Comment
16 *
17 * @category Class
18 * @package  Moove_GDPR_Review
19 * @author   Moove Agency
20 */
21class Moove_GDPR_Review {
22        /**
23         * Construct function
24         */
25        public function __construct() {
26    add_action( 'admin_notices', array( &$this, 'gdpr_add_review_notice' ) );
27    add_action( 'admin_print_footer_scripts', array( &$this, 'gdpr_add_review_script' ) );
28    add_action( 'wp_ajax_gdpr_cc_dismiss_review_notice', array( &$this, 'gdpr_cc_dismiss_review_notice' ) );
29    add_filter( 'gdpr_check_review_banner_condition', array( &$this, 'gdpr_check_review_banner_condition_func' ), 10, 1 );
30        }
31
32  /**
33   * Function which checks when to display the banner
34   */
35  public static function gdpr_check_review_banner_condition_func( $show_banner = false ){
36 
37    $current_screen         = get_current_screen();
38    $disabled               = false;
39
40    if ( 'moove-gdpr' !== $current_screen->parent_base || ! current_user_can( apply_filters( 'gdpr_options_page_cap', 'manage_options' ) ) ) :
41      $disabled     = true;
42      $show_banner  = false;
43    endif;
44
45    if ( ! $disabled && is_user_logged_in() ) :
46      $user             = wp_get_current_user();
47      $dismiss_stamp_p  = get_user_meta( $user->ID, 'gdpr_cc_dismiss_stamp_p', true );
48     
49      if ( ! intval( $dismiss_stamp_p ) ) :
50        $dismiss_stamp    = get_user_meta( $user->ID, 'gdpr_cc_dismiss_stamp', true );
51
52        if ( intval( $dismiss_stamp ) ) :
53          $now_stamp    = strtotime('now');
54          $show_banner  = intval( $dismiss_stamp ) <= $now_stamp;
55        else :
56          $dismiss_3m   = update_user_meta( $user->ID, 'gdpr_cc_dismiss_stamp', strtotime('+3 months') );
57          $show_banner  = false;
58        endif;
59      else :
60        $show_banner = false;
61      endif;
62    endif;
63    return $show_banner;
64  }
65
66  /**
67   * Dismiss notice on AJAX call
68   */
69  public static function gdpr_cc_dismiss_review_notice() {
70    $nonce      = isset( $_POST['nonce'] ) ? sanitize_key( wp_unslash( $_POST['nonce'] ) ) : false;
71    $type       = isset( $_POST['type'] ) ? sanitize_text_field( wp_unslash( $_POST['type'] ) ) : '';
72    $response   = array(
73      'success' => false,
74      'message' => 'Invalid request!',
75    );
76    if ( $nonce && wp_verify_nonce( $nonce, 'gdpr_cc_dismiss_nonce_field' ) && current_user_can( apply_filters( 'gdpr_options_page_cap', 'manage_options' ) ) ) :
77      $user = wp_get_current_user();
78      if ( $user && isset( $user->ID ) ) :
79        $dismiss_3m = update_user_meta( $user->ID, 'gdpr_cc_dismiss_stamp' . $type, strtotime('+3 months') );
80     
81        $response = array(
82          'success' => true,
83          'message' => '',
84        );
85      endif;
86    endif;
87    echo json_encode( $response );
88    die();
89  }
90
91  /**
92   * Show the admin notice
93   */
94  public static function gdpr_add_review_notice() {
95    $show_notice = apply_filters('gdpr_check_review_banner_condition', false);
96    if ( $show_notice ) :
97      ?>
98      <div class="gdpr-cc-review-notice is-dismissible notice gdpr-cc-notice" data-adminajax="<?php echo esc_url( admin_url( 'admin-ajax.php' ) ); ?>">
99        <div class="gdpr-ccrn-label">
100          <span class="gdpr-cc-icon" style="background-image: url('<?php echo moove_gdpr_get_plugin_directory_url() ?>/dist/images/gdpr-cookie-compliance-icon.png')"></span>
101
102          <div class="gdpr-ccrn-content">
103            <h3 style="margin-bottom: 10px;"><?php esc_html_e( 'GDPR Cookie Compliance Plugin (CCPA ready)', 'gdpr-cookie-compliance' ); ?></h3>
104            <p><?php echo wp_kses_post( sprintf( __( 'Hi, thank you for using our plugin. We would really appreciate if you could take a moment to drop a quick review that will inspire us to keep going.', 'gdpr-cookie-compliance' ), '<strong>', '</strong>', '<br>' ) ); ?></p>
105            <div class="gdpr-ccrn-button-wrap">
106         
107              <a href="https://wordpress.org/support/plugin/gdpr-cookie-compliance/reviews/?rate=5#new-post" target="_blank" class="button button-gdpr-orange gdpr-ccrn-review">Review</a>
108           
109              <button class="button button-gdpr-alt gdpr-ccrn-dismiss">Remind me later</button>
110               
111            </div>
112            <!-- .gdpr-ccrn-button-wrap -->
113          </div>
114          <!-- .gdpr-ccrn-content -->
115         
116        </div>
117        <!-- .gdpr-ccrn-label -->
118        <?php wp_nonce_field( 'gdpr_cc_dismiss_nonce_field', 'gdpr_cc_dismiss_nonce' ); ?>
119      </div>
120      <!-- .gdpr-cc-review-notice -->
121      <?php
122    endif;
123  }
124
125  /**
126   * Notice CSS and JS added to admin footer if the banner should be visible
127   */
128  public static function gdpr_add_review_script() {
129    $show_notice = apply_filters('gdpr_check_review_banner_condition', false);
130    if ( $show_notice ) :
131      ?>
132      <style>
133        .gdpr-cc-review-notice {
134          background-color: #fff;
135          padding: 20px;
136          border-left-color: #f79322;
137          padding-top: 10px;
138          padding-bottom: 10px;
139        }
140
141        .gdpr-cc-review-notice .gdpr-ccrn-button-wrap {
142          display: flex;
143          margin: 0 -5px;
144        }
145
146        .gdpr-cc-review-notice .button-gdpr-alt {
147          border-radius: 0;
148          text-shadow: none;
149          box-shadow: none;
150          outline: none;
151          padding: 3px 10px;
152          font-size: 12px;
153          font-weight: 400;
154          color: #fff;
155          transition: all .3s ease;
156          height: auto;
157          line-height: 22px;
158          border: 1px solid #d28b21;
159          background-color: #262c33;
160          border-color: #737373;
161          opacity: .5;
162          margin: 10px 5px;
163        }
164
165        .gdpr-cc-review-notice .button-gdpr-alt:hover {
166          opacity: 1;
167        }
168
169        .gdpr-cc-review-notice .button-gdpr-orange {
170          border-radius: 0;
171          text-shadow: none;
172          box-shadow: none;
173          outline: none;
174          padding: 3px 10px;
175          font-size: 12px;
176          font-weight: 400;
177          color: #fff;
178          transition: all .3s ease;
179          height: auto;
180          line-height: 22px;
181          border: 1px solid #d28b21;
182          background-color: #f79322;
183          margin: 10px 5px;
184        }
185
186        .gdpr-cc-review-notice .button-gdpr-orange:hover {
187          background-color: #1d2327;
188          color: #f0f0f1;
189        }
190
191        .gdpr-cc-review-notice .gdpr-ccrn-content {
192          flex: 0 0 calc( 100% - 100px);
193          max-width: calc( 100% - 100px);
194        }
195
196        .gdpr-cc-review-notice .gdpr-ccrn-content p {
197          font-size: 14px;
198          margin: 0;
199        }
200
201        .gdpr-cc-review-notice .gdpr-cc-icon {
202          flex: 0 0 80px;
203          max-width: 80px;
204          height: 80px;
205          background-size: contain;
206          background-position: center;
207          background-repeat: no-repeat;
208          margin: 0;
209        }
210
211        .gdpr-cc-review-notice .gdpr-ccrn-label {
212          display: flex;
213          justify-content: space-between;
214          align-items: center;
215        }
216      </style>
217
218      <script>
219        (function($) {
220          $(document).ready(function() {
221           
222            $(document).on('click','.gdpr-cc-review-notice .gdpr-ccrn-review', function(e){
223              $(this).closest('.gdpr-cc-notice').slideUp();
224              var ajax_url =$(this).closest('.gdpr-cc-notice').attr('data-adminajax');
225              try {
226                if ( ajax_url ) {
227                  jQuery.post(
228                    ajax_url,
229                    {
230                      action: 'gdpr_cc_dismiss_review_notice',
231                      type: '_p',
232              ��       nonce: $('#gdpr_cc_dismiss_nonce').val(),
233                    },
234                    function( msg ) {
235                      console.warn(msg);
236                    }
237                  );
238                }
239              } catch(err) {
240                console.error(err);
241              }
242            });
243            $(document).on('click','.gdpr-cc-review-notice .gdpr-ccrn-dismiss, .gdpr-cc-review-notice .notice-dismiss', function(e){
244              e.preventDefault();
245              $(this).closest('.gdpr-cc-notice').slideUp();
246              var ajax_url =$(this).closest('.gdpr-cc-notice').attr('data-adminajax');
247              try {
248                if ( ajax_url ) {
249                  jQuery.post(
250                    ajax_url,
251                    {
252                      action: 'gdpr_cc_dismiss_review_notice',
253                      type: '',
254                      nonce: $('#gdpr_cc_dismiss_nonce').val(),
255                    },
256                    function( msg ) {
257                      console.warn(msg);
258                    }
259                  );
260                }
261              } catch(err) {
262                console.error(err);
263              }
264            });
265          });
266        })(jQuery);
267      </script>
268      <?php
269    endif;
270  }
271}
272$gdpr_review = new Moove_GDPR_Review();
Note: See TracBrowser for help on using the repository browser.