-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmail-capture.php
114 lines (67 loc) · 2.21 KB
/
mail-capture.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
<?php
/*
* Plugin Name: No BS Email Capture
* Plugin URI: http://imakewp.com/
* Description: No Bullshit way to capture Email Address as leads from visitors.
* Version: 0.1
* Author: Vajrasar Goswami | Obbserv Online Services Pvt. Ltd.
*/
function nobsmail_enqueue_scripts() {
wp_enqueue_script( 'mailcapturejs', plugins_url() . '/mail-capture/mailcapture.js', array('jquery'), '1.0', true );
wp_localize_script( 'mailcapturejs', 'nobsmail', array( 'ajax_url' => admin_url( 'admin-ajax.php' ) ));
}
add_action( 'wp_enqueue_scripts', 'nobsmail_enqueue_scripts' );
function lets_catch_emails() {
?>
<div id="catch-email">
<!--<p>
<label for="name"/>Name:</label>
<input type="text" name="name" id="subs-name"/>
</p>-->
<p>
<label for="email"/>Email:</label>
<input type="text" name="email" id="subs-email"/>
</p>
<p>
<input type="submit" value="Sign up" id="mail-submit-btn"/>
</p>
<p id="status"></p>
</div>
<?php
}
function vg_no_bs_mail_func() {
//$usrname = $_REQUEST['thename'];
$usremail = $_REQUEST['theemail'];
$weshoulddie = 0;
/*
if( $usrname == null || empty( $usrname ) ) {
echo "Username Empty." . "<br />";
$weshoulddie = 1;
}
*/
if ( ( $usremail == null ) || ( empty( $usremail ) ) || ( !is_email( $usremail ) ) ) {
echo "Email Empty or invalid" . "<br />";
$weshoulddie = 1;
}
if( $weshoulddie == 1 ) {
die();
exit();
}
if ( defined( 'DOING_AJAX' ) && DOING_AJAX && ( $weshoulddie == 0 ) ) {
if( null == username_exists( $usremail ) ) {
$password = wp_generate_password( 12, true );
$user_id = wp_create_user ( $usremail, $password, $usremail );
$user = new WP_User( $user_id );
$user->set_role( 'subscriber' );
wp_mail( $usremail, 'Welcome to BCM!', 'You will recieve updates from now on!' );
echo "You've succesfully subscribed.";
} else {
echo "User with this email already exists. Please register with a different Email. Thanks!";
}
die();
} else {
echo "No Ajax!";
}
}
add_action( 'wp_ajax_nopriv_vg_no_bs_mail_func', 'vg_no_bs_mail_func' ); // for ajax
add_action( 'wp_ajax_vg_no_bs_mail_func', 'vg_no_bs_mail_func' ); // for ajax