PluginProbe
Adminify – White Label, Admin Menu Editor, Login Customizer / 4.2.18
Adminify – White Label, Admin Menu Editor, Login Customizer v4.2.18
4.3.1 4.3.0 4.2.26 4.2.25 4.2.24 4.2.23 4.2.22 4.2.21 4.2.20 4.2.19 4.2.18 4.2.17 4.2.16 4.2.15 4.2.14 4.2.13 4.2.12 4.2.11 4.2.10 4.2.9 4.2.8 4.2.7 4.2.6 4.2.5 4.1.17 All 164 releases
adminify / Inc / Classes / Notifications / Subscribe.php

Subscribe.php in Adminify – White Label, Admin Menu Editor, Login Customizer 4.2.18, at Inc/Classes/Notifications/Subscribe.php

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