should_show_alert()) { add_action('admin_notices', [$this, 'display_alert']); add_action('wp_ajax_iwptpl_renew_license_alert_dismiss', [$this, 'dismiss']); add_action('admin_enqueue_scripts', [$this, 'enqueue_scripts']); } } private function should_show_alert() { if (empty(get_option('iwptpl_etableit'))) { update_option('iwptpl_etableit', strtotime('+ ' . wp_rand(10, 20) . ' days')); } $pro_version = get_option('iwptp-version'); if (!empty($pro_version) && version_compare($pro_version, '2.1.1', '>=')) { return false; } return true; } public function display_alert() { include_once IWPTPL_FW_DIR . 'renew_license_alert/views/alert.php'; } public function dismiss() { if (!isset($_POST['nonce']) || !wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['nonce'])), 'iwptpl_ajax_nonce')) { die(); } // update_option('iwptpl_renew_license_alert_dismissed', 'yes'); wp_send_json([ 'success' => true ]); } public function enqueue_scripts() { wp_enqueue_style('iwptpl-renew-license-alert', IWPTPL_FW_URL . 'renew_license_alert/assets/css/style.css', [], IWPTPL_VERSION); wp_enqueue_script('iwptpl-renew-license-alert', IWPTPL_FW_URL . 'renew_license_alert/assets/js/renew-license-alert.js', [], IWPTPL_VERSION); //phpcs:ignore wp_localize_script('iwptpl-renew-license-alert', 'IWPTPL_PRO_VERSION_ALERT', [ 'ajax_url' => admin_url('admin-ajax.php'), 'ajax_nonce' => wp_create_nonce('iwptpl_ajax_nonce'), ]); } public static function remove() { delete_option('iwptpl_etableit'); delete_option('iwptpl_renew_license_alert_dismissed'); } }