PluginProbe ʕ •ᴥ•ʔ
Superb Addons: Blocks, Patterns, Pre-built Pages, Sliders, Popups, Free Forms, Animations & More / 3.4.5
Superb Addons: Blocks, Patterns, Pre-built Pages, Sliders, Popups, Free Forms, Animations & More v3.4.5
4.0.7 4.0.6 4.0.5 4.0.4 4.0.3 4.0.2 4.0.1 4.0.0 trunk 1.0.0 2.0.0 2.0.1 2.0.2 2.0.3 3.0 3.0.1 3.0.2 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.2 3.1.3 3.2.0 3.2.1 3.2.2 3.2.4 3.2.5 3.2.7 3.2.8 3.2.9 3.3.0 3.3.1 3.3.2 3.4.0 3.4.1 3.4.2 3.4.5 3.4.6 3.5.0 3.5.1 3.5.2 3.5.3 3.5.4 3.5.6 3.5.7 3.5.8 3.5.9 3.6.0 3.6.1 3.6.2 3.7.0 3.7.1
superb-blocks / src / admin / controllers / class-newsletter-signup-controller.php
superb-blocks / src / admin / controllers Last commit date
wizard 1 year ago class-dashboard-controller.php 1 year ago class-newsletter-signup-controller.php 1 year ago class-notice-controller.php 1 year ago class-settings-controller.php 1 year ago class-troubleshooting-controller.php 1 year ago
class-newsletter-signup-controller.php
74 lines
1 <?php
2
3 namespace SuperbAddons\Admin\Controllers;
4
5 use SuperbAddons\Config\Capabilities;
6 use SuperbAddons\Data\Controllers\DomainShiftController;
7
8 defined('ABSPATH') || exit();
9
10 class NewsletterSignupController
11 {
12 const ID = 'superbaddons-newsletter-form';
13 const ACTION = 'superbaddons_newsletter_form';
14 const META_KEY = 'superbaddons_newsletter_subscribed';
15
16 const NEWSLETTER_ENDPOINT = 'addons-status/newsletter/signup';
17
18 public static function Initialize()
19 {
20 if (!is_admin()) {
21 return;
22 }
23 add_action('wp_ajax_superbaddons_newsletter_form', array(__CLASS__, 'AjaxNewsletterSignupForm'));
24 }
25
26 public static function AjaxNewsletterSignupForm()
27 {
28 check_ajax_referer(NewsletterSignupController::ID, 'nonce');
29
30 if (!current_user_can(Capabilities::CONTRIBUTOR)) {
31 wp_send_json_error(array('message' => __("You do not have permission to perform this action.", "superb-blocks")));
32 }
33
34 $email = sanitize_email($_POST['email']);
35 if (!is_email($email)) {
36 wp_send_json_error(array('message' => __("Invalid email address.", "superb-blocks")));
37 }
38
39 $response = false;
40 $response = DomainShiftController::RemotePost(
41 self::NEWSLETTER_ENDPOINT,
42 array(
43 'headers' => array('Content-Type' => 'application/json'),
44 'method' => 'POST',
45 'body' => json_encode(
46 array(
47 'action' => 'signup_newsletter',
48 'email' => $email
49 )
50 )
51 )
52 );
53
54 if (!$response || is_wp_error($response)) {
55 wp_send_json_error(array('message' => __("A connection error occurred. Please try again later.", "superb-blocks")));
56 }
57
58 $status_code = wp_remote_retrieve_response_code($response);
59
60 if ($status_code !== 200) {
61 wp_send_json_error(array('message' => __("Something went wrong during the signup process. Please try again later or contact support for assistance.", "superb-blocks")));
62 }
63
64 update_user_meta(get_current_user_id(), self::META_KEY, true);
65
66 wp_send_json_success();
67 }
68
69 public static function Cleanup()
70 {
71 delete_metadata('user', 0, self::META_KEY, false, true);
72 }
73 }
74