-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmailcheck-for-wordpress.php
227 lines (178 loc) · 4.64 KB
/
mailcheck-for-wordpress.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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
<?php
/**
* Plugin Name: MailCheck for WordPress
* Plugin URI:
* Description:
* Version: 1.0.0
* Author: Astoundify
* Author URI: http://www.astoundify.com/
* Text Domain: mailcheck-wordpress
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
/**
* Class MailCheck_WordPress.
*
* Main WCMSA class initializes the plugin.
*
* @class MailCheck_WordPress
* @version 1.0.0
* @author Jeroen Sormani
*/
class MailCheck_WordPress {
/**
* Plugin version.
*
* @since 1.0.0
* @var string $version Plugin version number.
*/
public $version = '1.0.0';
/**
* Plugin file.
*
* @since 1.0.0
* @var string $file Plugin file path.
*/
public $file = __FILE__;
/**
* Instace of MailCheck_WordPress.
*
* @since 1.0.0
* @access private
* @var object $instance The instance of MailCheck_WordPress.
*/
private static $instance;
/**
* Construct.
*
* Initialize the class and plugin.
*
* @since 1.0.0
*/
public function __construct() {
// Initialize plugin parts
$this->init();
}
/**
* Instance.
*
* An global instance of the class. Used to retrieve the instance
* to use on other files/plugins/themes.
*
* @since 1.0.0
* @return object Instance of the class.
*/
public static function instance() {
if ( is_null( self::$instance ) ) :
self::$instance = new self();
endif;
return self::$instance;
}
/**
* Init.
*
* Initialize plugin parts.
*
* @since 1.0.0
*/
public function init() {
// Add mailcheck.js
add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
add_action( 'login_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
// Print mailcheck script
add_action( 'wp_footer', array( $this, 'print_mailcheck_script' ) );
add_action( 'login_footer', array( $this, 'print_mailcheck_script' ) );
add_action( 'wp_head', array( $this, 'print_css' ) );
add_action( 'login_head', array( $this, 'print_css' ) );
// Load textdomain
$this->load_textdomain();
}
/**
* Enqueue scripts.
*
* Enqueue script as javascript and style sheets.
*
* @since 1.0.0
*/
public function enqueue_scripts() {
$suffix = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min';
wp_enqueue_script( 'mailcheck-for-wordpress', plugins_url( 'assets/js/mailcheck' . $suffix . '.js', __FILE__ ), array( 'jquery' ), $this->version, true );
}
/**
* Print CSS.
*
* Prince a little bit of CSS to the head.
*
* @since 1.0.0
*/
public function print_css() {
?><style>
#mailcheck-for-wordpress-suggest {
position: absolute;
font-size: 12px;
color: #F00;
}
body.login #mailcheck-for-wordpress-suggest {
position: relative;
}
.suggestion-link {
font-weight: bold;
}
</style><?php
}
/**
* Print mailcheck script.
*
* Print the mailcheck configuration script.
*
* @since 1.0.0
*/
public function print_mailcheck_script() {
$mailcheck_elements = apply_filters( 'mailcheck_for_wp_elements', '#user_email, #reg_email, #billing_email' );
?><script type='text/javascript'>
jQuery( document ).ready( function( $ ) {
var last_suggestion = '';
$( 'body' ).on( 'blur', '<?php echo $mailcheck_elements; ?>', function() {
$( this ).mailcheck({
suggested: function( element, suggestion ) {
last_suggestion = suggestion.full;
$( '#mailcheck-for-wordpress-suggest' ).remove();
$( '<?php echo $mailcheck_elements; ?>' ).after( '<div id="mailcheck-for-wordpress-suggest"><span class="suggestion-text"><?php _e( 'Did you mean', 'mailcheck-wordpress' ); ?> <a href="javascript:void(0);" class="suggestion-link">' + suggestion.full + '</a>?</span></div>');
},
});
});
$( 'body' ).on( 'click', '.suggestion-link', function() {
$( '<?php echo $mailcheck_elements; ?>' ).val( last_suggestion );
$( '#mailcheck-for-wordpress-suggest' ).remove();
});
});
</script><?php
}
/**
* Textdomain.
*
* Load the textdomain based on WP language.
*
* @since 1.0.0
*/
public function load_textdomain() {
// Load textdomain
load_plugin_textdomain( 'mailcheck-wordpress', false, basename( dirname( __FILE__ ) ) . '/languages' );
}
}
/**
* The main function responsible for returning the MailCheck_WordPress object.
*
* Use this function like you would a global variable, except without needing to declare the global.
*
* Example: <?php MailCheck_WordPress()->method_name(); ?>
*
* @since 1.0.0
*
* @return object MailCheck_WordPress class object.
*/
if ( ! function_exists( 'MailCheck_WordPress' ) ) :
function MailCheck_WordPress() {
return MailCheck_WordPress::instance();
}
endif;
MailCheck_WordPress();