PluginProbe ʕ •ᴥ•ʔ
SiteGuard WP Plugin / 1.8.7
SiteGuard WP Plugin v1.8.7
1.8.7 1.8.6 1.8.6-beta1 1.8.6-beta2 1.8.4 1.8.5 1.8.3 1.8.2 1.8.1 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.1.0 1.1.1 1.1.2 1.2.0 1.2.1 1.2.2 1.2.3 1.4.3 1.5.0 1.5.1 1.5.2 1.6.0 1.6.1 1.7.0 1.7.1 1.7.10 1.7.11 1.7.12 1.7.2 1.7.3 1.7.4 1.7.5 1.7.6 1.7.7 1.7.8 1.7.9 1.8.0 1.8.0-beta1 1.8.0-beta2 1.8.0-beta3 1.8.0-beta4
siteguard / classes / siteguard-login-alert.php
siteguard / classes Last commit date
siteguard-admin-filter.php 1 month ago siteguard-base.php 1 month ago siteguard-captcha.php 1 month ago siteguard-config.php 11 months ago siteguard-disable-author-query.php 2 weeks ago siteguard-disable-pingback.php 1 month ago siteguard-disable-xmlrpc.php 1 month ago siteguard-htaccess.php 2 weeks ago siteguard-login-alert.php 1 month ago siteguard-login-history.php 1 month ago siteguard-login-lock.php 1 month ago siteguard-rename-login.php 1 week ago siteguard-updates-notify.php 1 month ago siteguard-waf-exclude-rule.php 1 month ago
siteguard-login-alert.php
57 lines
1 <?php
2
3 class SiteGuard_LoginAlert extends SiteGuard_Base {
4 function __construct() {
5 global $siteguard_config;
6 if ( '1' === $siteguard_config->get( 'loginalert_enable' ) ) {
7 add_action( 'wp_login', array( $this, 'handler_wp_login' ), 10, 2 );
8 }
9 }
10 function init() {
11 global $siteguard_config;
12 if ( true === siteguard_check_multisite() ) {
13 $siteguard_config->set( 'loginalert_enable', '1' );
14 } else {
15 $siteguard_config->set( 'loginalert_enable', '0' );
16 }
17 $siteguard_config->set( 'loginalert_admin_only', '1' );
18 $siteguard_config->set( 'loginalert_subject', __( 'New login at %SITENAME%', 'siteguard' ) );
19 $siteguard_config->set( 'loginalert_body', __( "%USERNAME% logged in at %DATE% %TIME%\n\n== Login information ==\nIP Address: %IPADDRESS%\nReferer: %REFERER%\nUser-Agent: %USERAGENT%\n\n--\nSiteGuard WP Plugin", 'siteguard' ) );
20 $siteguard_config->update();
21 }
22 function replace_valuable( $string, $username ) {
23 $search = array( '%SITENAME%', '%USERNAME%', '%DATE%', '%TIME%', '%IPADDRESS%', '%USERAGENT%', '%REFERER%' );
24 $replace = array(
25 get_option( 'blogname' ),
26 $username,
27 date( 'Y-m-d', current_time( 'timestamp' ) ),
28 date( 'H:i:s', current_time( 'timestamp' ) ),
29 $this->get_ip(),
30 isset( $_SERVER['HTTP_USER_AGENT'] ) ? $_SERVER['HTTP_USER_AGENT'] : '-',
31 isset( $_SERVER['HTTP_REFERER'] ) ? $_SERVER['HTTP_REFERER'] : '-',
32 );
33 return str_replace( $search, $replace, $string );
34 }
35 function handler_wp_login( $username, $user ) {
36 global $siteguard_config;
37
38 if ( ( '1' == $siteguard_config->get( 'loginalert_admin_only' ) ) && ( ! $user->has_cap( 'administrator' ) ) ) {
39 return;
40 }
41
42 $user_email = $user->get( 'user_email' );
43
44 $subject = $siteguard_config->get( 'loginalert_subject' );
45 $body = $siteguard_config->get( 'loginalert_body' );
46
47 $subject = $this->replace_valuable( $subject, $username );
48 $body = $this->replace_valuable( $body, $username );
49
50 if ( true !== @wp_mail( $user_email, esc_html( $subject ), esc_html( $body ) ) ) {
51 siteguard_error_log( 'Failed send mail. To:' . $user_email . ' Subject:' . esc_html( $subject ) );
52 }
53
54 return;
55 }
56 }
57