PluginProbe
Master Addons for Elementor – Elementor Addons, Widgets, Mega Menu Builder, Popup Builder, Widget Builder & Template Kits / trunk
Master Addons for Elementor – Elementor Addons, Widgets, Mega Menu Builder, Popup Builder, Widget Builder & Template Kits vtrunk
3.2.2 3.2.3 3.2.1 3.2.0 3.1.9 3.1.8 3.1.7 3.1.6 3.1.5 3.1.4 3.1.3 3.1.2 3.1.1 3.1.0 3.0.9 trunk 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.1.1 1.1.3 1.1.4 1.1.5 All 174 releases
master-addons / inc / classes / notifications / subscribe.php

subscribe.php in Master Addons for Elementor – Elementor Addons, Widgets, Mega Menu Builder, Popup Builder, Widget Builder & Template Kits trunk, at inc/classes/notifications/subscribe.php

233 lines 6.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace MasterAddons\Inc\Classes\Notifications;
4
5 if (!defined('ABSPATH')) {
6 exit; // Exit if accessed directly
7 }
8
9 use MasterAddons\Inc\Classes\Notifications\Base\User_Data;
10 use MasterAddons\Inc\Classes\Notifications\Model\Notice;
11
12 if (!class_exists('Subscribe')) {
13 /**
14 * Subscribe Class
15 *
16 * Jewel Theme <support@jeweltheme.com>
17 */
18 class Subscribe extends Notice
19 {
20
21 use User_Data;
22
23 public $color = 'warning';
24
25 /**
26 * Construct method
27 *
28 * @author Jewel Theme <support@jeweltheme.com>
29 */
30 public function __construct()
31 {
32 parent::__construct();
33 add_action('wp_ajax_jltma_subscribe', array($this, 'jltma_subscribe'));
34 }
35
36 /**
37 * Subscribe method
38 *
39 * @author Jewel Theme <support@jeweltheme.com>
40 */
41 public function jltma_subscribe()
42 {
43 check_ajax_referer('jltma_subscribe_nonce');
44
45 if ( ! current_user_can( 'manage_options' ) ) {
46 wp_send_json_error( [ 'message' => __( 'Insufficient permissions', 'master-addons' ) ] );
47 }
48
49 $name = !empty($_POST['name']) ? sanitize_text_field(wp_unslash($_POST['name'])) : '';
50 $email = !empty($_POST['email']) ? sanitize_email(wp_unslash($_POST['email'])) : '';
51
52 if (!is_email($email)) {
53 $email = get_bloginfo('admin_email');
54 }
55
56 $author_obj = get_user_by('email', get_bloginfo('admin_email'));
57 $user_id = $author_obj->ID;
58
59 // First Name & Last name .
60 if (!empty($name)) {
61 $full_name = $name;
62 } else {
63 $full_name = $author_obj->display_name;
64 }
65
66 $response = $this->get_collect_data($user_id, array(
67 'first_name' => $full_name,
68 'email' => $email,
69 ));
70
71 if (!is_wp_error($response) && 200 === $response['response']['code'] && 'OK' === $response['response']['message']) {
72 wp_send_json_success('Thanks for Subscribe!');
73 } else {
74 wp_send_json_error("Couldn't Subscribe");
75 }
76 }
77
78 /**
79 * Notice Header
80 *
81 * @author Jewel Theme <support@jeweltheme.com>
82 */
83 public function notice_header()
84 {
85 return '';
86 }
87
88 /**
89 * Notice footer
90 *
91 * @author Jewel Theme <support@jeweltheme.com>
92 */
93 public function notice_footer()
94 {
95 return '';
96 }
97
98 /**
99 * Set Title
100 *
101 * @author Jewel Theme <support@jeweltheme.com>
102 */
103 public function set_title()
104 {
105 printf(
106 '<h4>Wanna get some discount for %1$s? No Worries!! We got you!! Enter your email, we will send you the discount code?</h4>',
107 esc_html__('Master Addons', 'master-addons')
108 );
109 }
110
111 /**
112 * Notice Content
113 *
114 * @author Jewel Theme <support@jeweltheme.com>
115 */
116 public function notice_content()
117 {
118 $userdata = \wp_get_current_user();
119 ?>
120 <div class="notice notice-jltma is-dismissible notice-plugin-review notice-<?php echo esc_attr($this->color); ?> jltma-notice-<?php echo esc_attr($this->get_id()); ?>">
121 <button type="button" class="notice-dismiss jltma-notice-dismiss"></button>
122 <img width="70" height="70" src="<?php echo esc_url(JLTMA_IMAGE_DIR . 'logo.png'); ?>" alt="<?php esc_attr_e('Logo', 'master-addons'); ?>">
123 <div class="jltma-subscribe-content">
124 <?php $this->set_title(); ?>
125 <form style="display:flex">
126 <div class="jltma-plugin-subscribe-input">
127 <input type="text" id="name" name="name" placeholder="Name" value="<?php echo esc_attr($userdata->display_name); ?>">
128 </div>
129 <div class="jltma-plugin-subscribe-input">
130 <input type="text" id="email" name="email" placeholder="Email" value="<?php echo esc_attr($userdata->user_email); ?>">
131 </div>
132 <button type="submit" class="button button-primary jltma-subscribe-btn"><?php esc_html_e('Get Discount', 'master-addons'); ?></button>
133 </form>
134 </div>
135 </div>
136 <?php
137 }
138
139 /**
140 * Rate URL
141 *
142 * @author Jewel Theme <support@jeweltheme.com>
143 */
144 public function plugin_rate_url()
145 {
146 return 'https://wordpress.org/plugins/' . JLTMA_SLUG;
147 }
148
149 /**
150 * Footer content
151 *
152 * @author Jewel Theme <support@jeweltheme.com>
153 */
154 public function footer_content()
155 {
156 ?>
157 <a class="button button-primary rate-plugin-button" href="<?php echo esc_url($this->plugin_rate_url()); ?>" rel="nofollow" target="_blank">
158 <?php echo esc_html__('Rate Now', 'master-addons'); ?>
159 </a>
160 <a class="button notice-review-btn review-later jltma-notice-dismiss" href="#" rel="nofollow">
161 <?php echo esc_html__('Later', 'master-addons'); ?>
162 </a>
163 <a class="button notice-review-btn review-done jltma-notice-disable" href="#" rel="nofollow">
164 <?php echo esc_html__('I already did', 'master-addons'); ?>
165 </a>
166 <?php
167 }
168
169 /**
170 * Intervals
171 *
172 * @author Jewel Theme <support@jeweltheme.com>
173 */
174 public function intervals()
175 {
176 return array(5, 4, 10, 20, 15, 25, 30);
177 }
178
179 /**
180 * Core Script
181 *
182 * @param [type] $trigger_time .
183 *
184 * @return void
185 * @author Jewel Theme <support@jeweltheme.com>
186 */
187 public function core_script($trigger_time)
188 {
189 parent::core_script($trigger_time);
190 ?>
191
192 <script>
193 jQuery(document).on('submit', '.jltma-notice-subscribe .jltma-subscribe-content form', function(e) {
194
195 e.preventDefault();
196
197 let form = jQuery(this);
198 let name = form.find('input[name=name]').val();
199 let email = form.find('input[name=email]').val();
200 let formWrapper = form.closest('.jltma-subscribe-content');
201
202 formWrapper.css('opacity', '0.4').find('button').prop('disabled', true);
203
204 jQuery.ajax({
205 url: '<?php echo esc_url(admin_url('admin-ajax.php')); ?>',
206 method: 'POST',
207 crossDomain: true,
208 data: {
209 action: 'jltma_subscribe',
210 _wpnonce: '<?php echo esc_js(wp_create_nonce('jltma_subscribe_nonce')); ?>',
211 name: name,
212 email: email,
213 }
214 })
215 .done(function(response) {
216 formWrapper.hide().after('<p class="jltma--notice-message"><strong>' + response.data + '</strong><p>');
217 let subsTimeout = setTimeout(function() {
218 jltma_notice_action(null, form, 'disable');
219 clearTimeout(subsTimeout);
220 }, 1500);
221 })
222 .always(function() {
223 formWrapper.css('opacity', '1').find('button').prop('disabled', false);
224 })
225
226 });
227 </script>
228
229 <?php
230 }
231 }
232 }
233