settings
3 months ago
globals.php
2 years ago
import-export.php
2 years ago
notices.php
1 year ago
welcome.php
2 years ago
notices.php
248 lines
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * Handles additional widget tab options |
| 5 | * run on __construct function |
| 6 | */ |
| 7 | |
| 8 | // Exit if accessed directly |
| 9 | if (!defined('ABSPATH')) exit; |
| 10 | |
| 11 | |
| 12 | /** |
| 13 | * Admin Messages |
| 14 | * @return void |
| 15 | */ |
| 16 | if (!function_exists('widgetopts_admin_notices')) : |
| 17 | function widgetopts_admin_notices() |
| 18 | { |
| 19 | if (!current_user_can('update_plugins')) |
| 20 | return; |
| 21 | |
| 22 | //show rating notice to page that matters most |
| 23 | global $pagenow; |
| 24 | if (!in_array($pagenow, array('widgets.php', 'options-general.php'))) { |
| 25 | return; |
| 26 | } |
| 27 | |
| 28 | if ($pagenow == 'options-general.php' && function_exists('get_current_screen')) { |
| 29 | $screen = get_current_screen(); |
| 30 | if (isset($screen->base) && $screen->base != 'settings_page_widgetopts_plugin_settings') { |
| 31 | return; |
| 32 | } |
| 33 | } |
| 34 | |
| 35 | $install_date = get_option('widgetopts_installDate'); |
| 36 | $saved = get_option('widgetopts_RatingDiv'); |
| 37 | $display_date = date('Y-m-d h:i:s'); |
| 38 | $datetime1 = new DateTime($install_date); |
| 39 | $datetime2 = new DateTime($display_date); |
| 40 | $diff_intrval = round(($datetime2->format('U') - $datetime1->format('U')) / (60 * 60 * 24)); |
| 41 | if ('yes' != $saved && $diff_intrval >= 7) { |
| 42 | echo '<div class="widgetopts_notice updated" style="box-shadow: 0 1px 1px 0 rgba(0,0,0,.1);"> |
| 43 | <p>Well done! You have been enjoying <strong>Widget Options</strong> for more than a week. |
| 44 | <br> |
| 45 | Do you love it? Are you over the moon? Will you give us a <a href="https://wordpress.org/support/view/plugin-reviews/widget-options" class="thankyou" target="_blank" title="Ok, you deserved it" style="font-weight:bold;"><strong>5-star rating</strong></a> on WordPress? |
| 46 | </br> |
| 47 | Your review is essential to the Widget Options community and our ongoing succes. |
| 48 | <br><br> |
| 49 | Thank you so much! � Your Widget Options Team |
| 50 | <ul> |
| 51 | <li><a href="https://wordpress.org/support/view/plugin-reviews/widget-options" class="thankyou" target="_blank" title="Ok, you deserved it" style="font-weight:bold;">' . __('Definitely. Widget Options is the best!', 'widget-options') . '</a></li> |
| 52 | <li><a href="javascript:void(0);" class="widgetopts_bHideRating" title="I already did" style="font-weight:bold;">' . __('Already done!', 'widget-options') . '</a></li> |
| 53 | <li><a href="https://widget-options.com/contact/" class="thankyou" target="_blank" title="Ok, you deserved it" style="font-weight:bold;">' . __("Not convinced yet. Still think about it.", 'widget-options') . '</a></li> |
| 54 | <li><a href="javascript:void(0);" class="widgetopts_bHideRating" title="No, not good enough" style="font-weight:bold;">' . __("Dismiss", 'widget-options') . '</a></li> |
| 55 | </ul> |
| 56 | </div> |
| 57 | <script> |
| 58 | jQuery( document ).ready(function( $ ) { |
| 59 | |
| 60 | jQuery(\'.widgetopts_bHideRating\').click(function(){ |
| 61 | var data={\'action\':\'widgetopts_hideRating\', \'nonce\':\'' . wp_create_nonce('widgetopts_ajax_nonce') . '\'}; |
| 62 | jQuery.ajax({ |
| 63 | |
| 64 | url: "' . admin_url('admin-ajax.php') . '", |
| 65 | type: "post", |
| 66 | data: data, |
| 67 | dataType: "json", |
| 68 | async: !0, |
| 69 | success: function(e) { |
| 70 | if (e.success) { |
| 71 | jQuery(\'.widgetopts_notice\').slideUp(\'slow\'); |
| 72 | |
| 73 | } |
| 74 | } |
| 75 | }); |
| 76 | }) |
| 77 | |
| 78 | }); |
| 79 | </script> |
| 80 | '; |
| 81 | } |
| 82 | } |
| 83 | add_action('admin_notices', 'widgetopts_admin_notices'); |
| 84 | endif; |
| 85 | |
| 86 | if (!function_exists('widgetopts_display_free_liecnse_admin_notice')) { |
| 87 | /** |
| 88 | * Show a notice to subscribe to newsletter |
| 89 | */ |
| 90 | function widgetopts_display_free_liecnse_admin_notice() |
| 91 | { |
| 92 | $license_key = get_option('widgetopts_free_license'); |
| 93 | if (!current_user_can('update_plugins') || !empty($license_key)) |
| 94 | return; |
| 95 | |
| 96 | //show rating notice to page that matters most |
| 97 | global $pagenow; |
| 98 | if (!in_array($pagenow, array('options-general.php'))) { |
| 99 | return; |
| 100 | } |
| 101 | |
| 102 | if ($pagenow == 'options-general.php' && function_exists('get_current_screen')) { |
| 103 | $screen = get_current_screen(); |
| 104 | if (isset($screen->base) && $screen->base != 'settings_page_widgetopts_plugin_settings') { |
| 105 | return; |
| 106 | } |
| 107 | } |
| 108 | |
| 109 | $htmlNotice = ' |
| 110 | <div class="notice widgetopts-notice" style="border-left-color: #064466"> |
| 111 | <form method="post"> |
| 112 | <h3>' . __('Free License', 'widget-options') . '</h3> |
| 113 | <p>' . __("You're currently using the free version of Widget Options. To register a free license for the plugin, please fill in your email below. This is not required but helps us support you better.", 'widget-options') . '</p> |
| 114 | <input type="text" name="email" placeholder="' . __('Email Address', 'widget-options') . '" /> |
| 115 | ' . wp_nonce_field('wo_free_license_action', 'wo_free_license_field') . ' |
| 116 | <input type="submit" name="wo_free_license_activator" value="Register Free License" class="button button-primary" /> |
| 117 | <input type="button" name="wo_free_license_dismiss" value="Dismiss" class="button button-secondary" /><br><br> |
| 118 | <input type="checkbox" name="wo_free_license_subscribe" value="1" checked /> Add me to your newsletter and keep me updated whenever you release news, updates and promos. |
| 119 | <p><small>* ' . __('Your email is secure with us! We will keep you updated on new feature releases and major announcements about Widget Options.', 'widget-options') . '</small></p> |
| 120 | </form> |
| 121 | <form method="post" id="wo_free_license_dismiss_form"> |
| 122 | ' . wp_nonce_field('wo_free_license_dismiss', 'wo_free_license_dismiss_field') . ' |
| 123 | <input type="hidden" name="wo_free_dismiss" value="1" /> |
| 124 | </form> |
| 125 | </div> |
| 126 | <script> |
| 127 | jQuery( document ).ready(function( $ ) { |
| 128 | |
| 129 | jQuery(\'input[name="wo_free_license_dismiss"]\').on("click", function(e){ |
| 130 | e.preventDefault(); |
| 131 | jQuery("#wo_free_license_dismiss_form").submit(); |
| 132 | }); |
| 133 | |
| 134 | }); |
| 135 | </script> |
| 136 | '; |
| 137 | |
| 138 | echo $htmlNotice; |
| 139 | } |
| 140 | add_action('admin_notices', 'widgetopts_display_free_liecnse_admin_notice'); |
| 141 | |
| 142 | function widgetopts_activate_free_liecnse() |
| 143 | { |
| 144 | if (! empty($_POST['wo_free_license_activator'])) { |
| 145 | if (! wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['wo_free_license_field'])), 'wo_free_license_action')) { |
| 146 | return; |
| 147 | } |
| 148 | |
| 149 | $email = sanitize_email(wp_unslash($_POST['email'])); |
| 150 | |
| 151 | if (is_email($email)) { |
| 152 | $user = get_user_by('email', $email); |
| 153 | $first_name = ''; |
| 154 | $last_name = ''; |
| 155 | $url = rawurlencode(home_url()); |
| 156 | |
| 157 | if (is_a($user, 'WP_User')) { |
| 158 | $first_name = $user->first_name; |
| 159 | $last_name = $user->last_name; |
| 160 | } |
| 161 | |
| 162 | if (! empty($_POST['wo_free_license_subscribe'])) { |
| 163 | // Make request, save key. |
| 164 | $request = wp_remote_post( |
| 165 | 'https://widget-options.com/wp-admin/admin-ajax.php', |
| 166 | array( |
| 167 | 'body' => |
| 168 | array( |
| 169 | 'action' => 'wo_free_license', |
| 170 | 'email_address' => $email, |
| 171 | 'fname' => $first_name, |
| 172 | 'lname' => $last_name, |
| 173 | 'url' => $url, |
| 174 | ) |
| 175 | ) |
| 176 | ); |
| 177 | |
| 178 | if (! is_wp_error($request)) { |
| 179 | $license = $email; |
| 180 | |
| 181 | if (! empty($license)) { |
| 182 | update_option('widgetopts_free_license', sanitize_text_field($license)); |
| 183 | |
| 184 | add_action( |
| 185 | 'admin_notices', |
| 186 | function () { |
| 187 | ?> |
| 188 | <div class="notice notice-success"> |
| 189 | <p><?php esc_html_e('Free license activated!', 'widget-options'); ?></p> |
| 190 | </div> |
| 191 | <?php |
| 192 | } |
| 193 | ); |
| 194 | } |
| 195 | } else { |
| 196 | add_action( |
| 197 | 'admin_notices', |
| 198 | function () { |
| 199 | ?> |
| 200 | <div class="notice notice-error"> |
| 201 | <p><?php esc_html_e('Something went wrong! Try again later.', 'widget-options'); ?></p> |
| 202 | </div> |
| 203 | <?php |
| 204 | } |
| 205 | ); |
| 206 | } |
| 207 | } else { |
| 208 | $license = $email; |
| 209 | |
| 210 | if (! empty($license)) { |
| 211 | update_option('widgetopts_free_license', sanitize_text_field($license)); |
| 212 | |
| 213 | add_action( |
| 214 | 'admin_notices', |
| 215 | function () { |
| 216 | ?> |
| 217 | <div class="notice notice-success"> |
| 218 | <p><?php esc_html_e('Free license activated!', 'widget-options'); ?></p> |
| 219 | </div> |
| 220 | <?php |
| 221 | } |
| 222 | ); |
| 223 | } |
| 224 | } |
| 225 | } else { |
| 226 | add_action( |
| 227 | 'admin_notices', |
| 228 | function () { |
| 229 | ?> |
| 230 | <div class="notice notice-error"> |
| 231 | <p><?php esc_html_e('Invalid email address!', 'widget-options'); ?></p> |
| 232 | </div> |
| 233 | <?php |
| 234 | } |
| 235 | ); |
| 236 | } |
| 237 | } |
| 238 | if (! empty($_POST['wo_free_dismiss'])) { |
| 239 | if (! wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['wo_free_license_dismiss_field'])), 'wo_free_license_dismiss')) { |
| 240 | return; |
| 241 | } |
| 242 | |
| 243 | update_option('widgetopts_free_license', sanitize_text_field('NA')); |
| 244 | } |
| 245 | } |
| 246 | add_action('admin_init', 'widgetopts_activate_free_liecnse'); |
| 247 | } |
| 248 |