events
5 years ago
views
5 years ago
class-custom-event-factory.php
7 years ago
class-custom-event.php
5 years ago
class-event-id-generator.php
5 years ago
class-events-manager.php
5 years ago
class-pixel.php
7 years ago
class-plugin-updater.php
6 years ago
class-plugin.php
7 years ago
class-pys.php
5 years ago
class-settings.php
5 years ago
functions-admin.php
5 years ago
functions-common.php
5 years ago
functions-custom-event.php
5 years ago
functions-edd.php
5 years ago
functions-gdpr.php
5 years ago
functions-license.php
6 years ago
functions-migrate.php
6 years ago
functions-optin.php
5 years ago
functions-promo-notices.php
5 years ago
functions-system-report.php
7 years ago
functions-update-plugin.php
6 years ago
functions-woo.php
5 years ago
options_defaults.json
5 years ago
options_fields.json
5 years ago
functions-optin.php
199 lines
| 1 | <?php |
| 2 | |
| 3 | namespace PixelYourSite; |
| 4 | |
| 5 | if ( ! defined( 'ABSPATH' ) ) { |
| 6 | exit; // Exit if accessed directly. |
| 7 | } |
| 8 | |
| 9 | add_action( 'admin_notices', 'PixelYourSite\adminRenderOptinNotices' ); |
| 10 | function adminRenderOptinNotices() { |
| 11 | |
| 12 | if ( ! current_user_can( 'manage_pys' ) ) { |
| 13 | return; |
| 14 | } |
| 15 | |
| 16 | $user = wp_get_current_user(); |
| 17 | $user_id = $user->ID; |
| 18 | |
| 19 | // never show again for opted-in users |
| 20 | if ( get_user_meta( $user_id, 'pys_core_opted_in_dismissed_at', true ) ) { |
| 21 | return; |
| 22 | } |
| 23 | |
| 24 | $second_time_dismissed_at = get_user_meta( $user_id, 'pys_core_optin_second_time_dismissed_at', true ); |
| 25 | $first_time_dismissed_at = get_user_meta( $user_id, 'pys_core_optin_first_time_dismissed_at', true ); |
| 26 | |
| 27 | if ( get_user_meta( $user_id, 'pys_core_optin_third_time_dismissed_at', true ) ) { |
| 28 | return; // was dismissed 3 times |
| 29 | } elseif ( $second_time_dismissed_at ) { |
| 30 | $month_ago = time() - MONTH_IN_SECONDS; |
| 31 | |
| 32 | if ( $month_ago < $second_time_dismissed_at ) { |
| 33 | return; // hide if dismissed less then month ago |
| 34 | } |
| 35 | |
| 36 | $header = 'Free PIXELYOURSITE HACKS: Improve your ads return and website tracking - LAST CALL'; |
| 37 | $dismiss_key = 'optin_third_time'; |
| 38 | } elseif ( $first_time_dismissed_at ) { |
| 39 | $week_ago = time() - WEEK_IN_SECONDS; |
| 40 | |
| 41 | if ( $week_ago < $first_time_dismissed_at ) { |
| 42 | return; // hide if dismissed less then week ago |
| 43 | } |
| 44 | |
| 45 | $header = 'PIXELYOURSITE HACKS: Improve your ads return and website tracking with FREE Facebook, Google and Pinterest hacks'; |
| 46 | $dismiss_key = 'optin_second_time'; |
| 47 | |
| 48 | } else { // was never dismissed |
| 49 | $header = 'Free PIXELYOURSITE HACKS: Improve your ads return and website tracking'; |
| 50 | $dismiss_key = 'optin_first_time'; |
| 51 | } |
| 52 | |
| 53 | // hide close button on PYS pages |
| 54 | $dismissable = empty( $_REQUEST['page'] ) || $_REQUEST['page'] != 'pixelyoursite'; |
| 55 | |
| 56 | // on PYS pages message always same |
| 57 | if ( ! $dismissable ) { |
| 58 | $header = 'Free PIXELYOURSITE HACKS: Improve your ads return and website tracking'; |
| 59 | $dismiss_key = ''; |
| 60 | } |
| 61 | |
| 62 | ?> |
| 63 | |
| 64 | <style type="text/css"> |
| 65 | .notice.pys-notice-wrapper { |
| 66 | display: flex; |
| 67 | align-items: center; |
| 68 | padding-top: 15px; |
| 69 | padding-bottom: 15px; |
| 70 | } |
| 71 | .pys-notice-content h4 { |
| 72 | margin-bottom: 10px; |
| 73 | } |
| 74 | .pys-notice-logo { |
| 75 | margin-right: 15px; |
| 76 | width: 50px; |
| 77 | max-width: 50px; |
| 78 | height: auto; |
| 79 | } |
| 80 | .pys-notice-wrapper h4 { |
| 81 | margin-top: 0; |
| 82 | } |
| 83 | .pys-form-text, |
| 84 | .pys-notice-label { |
| 85 | display: block; |
| 86 | margin-top: 4px; |
| 87 | font-size: 12px; |
| 88 | font-weight: 400; |
| 89 | color: #495057 !important; |
| 90 | } |
| 91 | .pys-notice-form-group:not(:last-child) { |
| 92 | margin-right: 12px; |
| 93 | } |
| 94 | </style> |
| 95 | |
| 96 | <div class="notice <?php echo $dismissable ? 'is-dismissible' : ''; ?> pys-optin-notice pys-notice-wrapper"> |
| 97 | <img src="<?php echo PYS_FREE_URL . '/dist/images/pys-square-logo-small.png'; ?>" class="pys-notice-logo"> |
| 98 | <div class="pys-notice-content"> |
| 99 | <h4><?php echo $header; ?></h4> |
| 100 | <form style="display: flex;"> |
| 101 | <div class="pys-notice-form-group"> |
| 102 | <input type="text" name="name" placeholder="Your name" |
| 103 | value="<?php esc_attr_e( $user->first_name ); ?>"> |
| 104 | </div> |
| 105 | <div class="pys-notice-form-group"> |
| 106 | <input type="email" name="email" required |
| 107 | placeholder="Your e-mail" value="<?php esc_attr_e( $user->user_email ); ?>"> |
| 108 | </div> |
| 109 | <?php if ( isWooCommerceActive() ) : ?> |
| 110 | <div class="pys-notice-form-group"> |
| 111 | <label class="pys-notice-label"> |
| 112 | <input type="checkbox" name="tag[]" value="with-woo" checked>I use WooCommerce |
| 113 | </label> |
| 114 | </div> |
| 115 | <?php endif; ?> |
| 116 | <?php if ( isEddActive() ) : ?> |
| 117 | <div class="pys-notice-form-group"> |
| 118 | <label class="pys-notice-label"> |
| 119 | <input type="checkbox" name="tag[]" value="with-edd" checked>I use Easy Digital Downloads |
| 120 | </label> |
| 121 | </div> |
| 122 | <?php endif; ?> |
| 123 | <div class="pys-notice-form-group"> |
| 124 | <button class="button button-primary" style="margin-top: -2px;">SEND ME FREE HACKS</button> |
| 125 | </div> |
| 126 | <div class="pys-notice-form-group"> |
| 127 | <small class="pys-form-text">No spam. You can unsubscribe at any time.</small> |
| 128 | </div> |
| 129 | </form> |
| 130 | </div> |
| 131 | </div> |
| 132 | |
| 133 | <script type="application/javascript"> |
| 134 | jQuery(document).on('click', '.pys-optin-notice .notice-dismiss', function () { |
| 135 | jQuery.ajax({ |
| 136 | url: ajaxurl, |
| 137 | data: { |
| 138 | action: 'pys_notice_dismiss', |
| 139 | nonce: '<?php esc_attr_e( wp_create_nonce( 'pys_notice_dismiss' ) ); ?>', |
| 140 | user_id: '<?php esc_attr_e( $user_id ); ?>', |
| 141 | addon_slug: 'core', |
| 142 | meta_key: '<?php esc_attr_e( $dismiss_key ); ?>' |
| 143 | } |
| 144 | }) |
| 145 | }); |
| 146 | |
| 147 | jQuery(document).on('submit', '.pys-optin-notice form', function (e) { |
| 148 | e.preventDefault(); |
| 149 | |
| 150 | var $form = jQuery(this), |
| 151 | name = $form.find('input[name="name"]').val(), |
| 152 | email = $form.find('input[name="email"]').val(), |
| 153 | $tags = $form.find('input[name="tag[]"]:checked'), |
| 154 | tags = []; |
| 155 | |
| 156 | $tags.each(function (i, elem) { |
| 157 | tags.push(jQuery(elem).val()); |
| 158 | }); |
| 159 | |
| 160 | jQuery.ajax({ |
| 161 | url: 'https://pixelyoursite.com/wp-admin/admin-ajax.php', |
| 162 | method: 'POST', |
| 163 | crossDomain: true, |
| 164 | data: { |
| 165 | action: 'pys_optin_add', |
| 166 | name: name, |
| 167 | email: email, |
| 168 | tags: tags |
| 169 | }, |
| 170 | beforeSend: function () { |
| 171 | $form.find('input, button').attr('disabled', true); |
| 172 | }, |
| 173 | success: function (resp) { |
| 174 | console.log(resp); |
| 175 | $form.closest('.pys-notice-wrapper').fadeOut(); |
| 176 | if (resp.success) { |
| 177 | setOptedInMeta(); |
| 178 | } |
| 179 | } |
| 180 | }); |
| 181 | |
| 182 | var setOptedInMeta = function () { |
| 183 | jQuery.ajax({ |
| 184 | url: ajaxurl, |
| 185 | method: 'POST', |
| 186 | data: { |
| 187 | action: 'pys_notice_dismiss', |
| 188 | nonce: '<?php esc_attr_e( wp_create_nonce( 'pys_notice_dismiss' ) ); ?>', |
| 189 | user_id: '<?php esc_attr_e( $user_id ); ?>', |
| 190 | addon_slug: 'core', |
| 191 | meta_key: 'opted_in' |
| 192 | } |
| 193 | }); |
| 194 | }; |
| 195 | }); |
| 196 | </script> |
| 197 | |
| 198 | <?php |
| 199 | } |