PluginProbe ʕ •ᴥ•ʔ
Ocean Extra / 2.5.6
Ocean Extra v2.5.6
trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.1.4.1 1.1.4.2 1.1.5 1.1.5.1 1.1.6 1.1.7 1.1.8 1.1.9 1.2.0 1.2.0.1 1.2.1 1.2.1.1 1.2.1.2 1.2.10 1.2.2 1.2.2.1 1.2.2.2 1.2.2.3 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 1.3.10 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.3.8 1.3.9 1.4.0 1.4.1 1.4.10 1.4.11 1.4.12 1.4.13 1.4.14 1.4.15 1.4.16 1.4.17 1.4.18 1.4.19 1.4.2 1.4.20 1.4.21 1.4.22 1.4.23 1.4.24 1.4.25 1.4.26 1.4.27 1.4.28 1.4.29 1.4.3 1.4.30 1.4.4 1.4.5 1.4.6 1.4.7 1.4.8 1.4.9 1.5.0 1.5.1 1.5.12 1.5.13 1.5.14 1.5.15 1.5.16 1.5.17 1.5.18 1.5.19 1.5.2 1.5.20 1.5.3 1.5.4 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.6 2.2.7 2.2.8 2.2.9 2.3.0 2.3.1 2.4.0 2.4.1 2.4.2 2.4.3 2.4.4 2.4.5 2.4.6 2.4.7 2.4.8 2.4.9 2.5.0 2.5.1 2.5.2 2.5.3 2.5.4 2.5.5 2.5.6
ocean-extra / includes / mautic.php
ocean-extra / includes Last commit date
admin-bar 1 year ago client-migration 6 months ago compatibility 1 year ago customizer 1 year ago freemius 8 months ago menu-icons 1 year ago metabox 1 year ago onboarding 2 weeks ago panel 9 months ago post-settings 2 months ago preloader 1 year ago shortcodes 1 year ago themepanel 1 year ago widgets 8 months ago wizard 3 years ago adobe-font.php 1 year ago custom-code.php 8 months ago dashboard.php 1 year ago image-resizer.php 1 year ago jshrink.php 3 years ago mautic.php 2 months ago ocean-extra-strings.php 3 years ago plugins-tab.php 1 year ago update-message.php 1 year ago utils.php 1 year ago walker.php 4 years ago
mautic.php
128 lines
1 <?php
2 /**
3 * OceanWP Mautic Integration
4 *
5 * @package Ocean_Extra
6 * @category Core
7 * @author OceanWP
8 */
9
10 // Exit if accessed directly.
11 if ( ! defined( 'ABSPATH' ) ) {
12 exit;
13 }
14
15 /**
16 * Ocean Extra Mautic Integration
17 */
18 class Ocean_Extra_Mautic {
19
20 /**
21 * Class instance.
22 *
23 * @var object
24 * @access private
25 */
26 private static $_instance = null;
27
28 /**
29 * Main Ocean_Extra_Mautic Instance
30 *
31 * @static
32 * @return Main Ocean_Extra_Mautic instance
33 */
34 public static function instance() {
35 if ( is_null( self::$_instance ) ) {
36 self::$_instance = new self();
37 }
38 return self::$_instance;
39 }
40
41 /**
42 * Constructor
43 */
44 public function __construct() {
45
46 add_action('wp_ajax_oe_mautic_subscribe', [$this, 'ajax_subscribe']);
47 add_action('wp_ajax_nopriv_oe_mautic_subscribe', [$this, 'ajax_subscribe']);
48 }
49
50 /**
51 * AJAX handler
52 */
53 public function ajax_subscribe() {
54
55 check_ajax_referer('owp-onboarding', 'security');
56
57 $email = isset($_POST['email'])
58 ? sanitize_email($_POST['email'])
59 : '';
60
61 $user_type = isset($_POST['user_type'])
62 ? sanitize_text_field($_POST['user_type'])
63 : 'free';
64
65 if (empty($email) || !is_email($email)) {
66 wp_send_json_error('Invalid email address.');
67 }
68
69 $result = $this->subscribe_to_mautic($email, $user_type);
70
71 if ($result === true) {
72
73 wp_send_json_success('Successfully subscribed!');
74 }
75
76 wp_send_json_error($result);
77 }
78
79 /**
80 * Send data to Mautic
81 */
82 private function subscribe_to_mautic($email, $user_type) {
83
84 $mautic_base_url = 'http://mautic.oceanwp.org';
85
86 $forms = [
87 'free' => 12,
88 'pro' => 13
89 ];
90
91 $form_id = isset($forms[$user_type]) ? $forms[$user_type] : $forms['free'];
92
93 $submit_url = "{$mautic_base_url}/form/submit";
94
95 $body = [
96 "mauticform[email]" => $email,
97 "mauticform[formId]" => $form_id,
98 "mauticform[return]" => '',
99 ];
100
101 $response = wp_remote_post($submit_url, [
102 'method' => 'POST',
103 'timeout' => 15,
104 'headers' => [
105 'User-Agent' => 'OceanExtra-Onboarding/1.0'
106 ],
107 'body' => $body
108 ]);
109
110 if (is_wp_error($response)) {
111 return esc_html__('Connection to mailing server failed.', 'ocean-extra');
112 }
113
114 $code = wp_remote_retrieve_response_code($response);
115
116 if ($code !== 200) {
117 return esc_html__('Subscription failed. Please try again.', 'ocean-extra');
118 }
119
120 return true;
121 }
122 }
123
124 /**
125 * Initialize
126 */
127 return Ocean_Extra_Mautic::instance();
128