forked from julien731/AuthPress
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwp-google-authenticator.php
101 lines (83 loc) · 2.77 KB
/
wp-google-authenticator.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
<?php
/**
* Plugin Name: WP Google Authenticator
* Plugin URI: https://github.com/julien731/WP-Google-Authenticator
* Description: WP Google Authenticator provides a safe way to add 2-factor authentication to your WordPress site using the Google 2FA system with the Google Authenticator app.
* Version: 1.1.0
* Author: Julien Liabeuf
* Author URI: http://julienliabeuf.com/
* License: GPL3
*/
/* Define all the plugin constants */
define( 'WPGA_VERSION', '1.1.0' );
define( 'WPGA_NAME', 'WP Google Authenticator' );
define( 'WPGA_AUTHOR', 'Julien Liabeuf' );
define( 'WPGA_URI', 'http://julienliabeuf.com' );
define( 'WPGA_URL', plugin_dir_url( __FILE__ ) );
define( 'WPGA_PATH', plugin_dir_path( __FILE__ ) );
define( 'WPGA_PREFIX', 'wpga' );
define( 'WPGA_BASENAME', plugin_basename(__FILE__) );
define( 'WPGA_LOG', false );
define( 'TAV_SHORTNAME', 'tav' );
require( WPGA_PATH . 'admin/admin.class.php' );
require( WPGA_PATH . 'admin/settings.class.php' );
require( WPGA_PATH . 'admin/functions-apps-passwords.php' );
add_action( 'plugins_loaded', array( 'WPGA_Admin', 'get_instance' ) );
register_activation_hook( __FILE__, 'wpga_installPlugin' );
/**
* Register settings on plugin activation
*/
function wpga_installPlugin() {
$defaults = array(
'blog_name' => get_bloginfo( 'name' ),
'max_attempts' => 3,
'authorized_delay' => 0,
);
if( !get_option( WPGA_PREFIX . '_options' ) )
update_option( WPGA_PREFIX . '_options', $defaults );
/* Add a new cron hook */
if ( ! wp_next_scheduled( 'wpas_clean_totps' ) ) {
wp_schedule_event( time(), 'daily', 'wpas_clean_totps' );
}
}
register_uninstall_hook( __FILE__, 'wpga_uninstallPlugin' );
/**
* Remove plugin data from database
*/
function wpga_uninstallPlugin() {
/* Plugin main options */
delete_option( WPGA_PREFIX . '_options' );
delete_option( WPGA_PREFIX . '_used_totp' );
$args = array( 'meta_query' => array(
'relation' => 'OR',
array(
'key' => 'wpga_attempts',
'value' => '',
'compare' => '!='
),
array(
'key' => 'wpga_secret',
'value' => '',
'compare' => '!='
)
)
);
$users = new WP_User_Query( $args );
/* Delete all user metas */
if( !empty( $users->results ) ) {
foreach( $users->results as $key => $user ) {
delete_user_meta( $user->ID, 'wpga_active' );
delete_user_meta( $user->ID, 'wpga_attempts' );
delete_user_meta( $user->ID, 'wpga_secret' );
delete_user_meta( $user->ID, 'wpga_backup_key' );
delete_user_meta( $user->ID, 'wpga_backup_key_time' );
delete_user_meta( $user->ID, 'wpga_apps_passwords' );
delete_user_meta( $user->ID, 'wpga_apps_passwords_log' );
}
}
/**
* Remove cron task
*/
$timestamp = wp_next_scheduled( 'wpas_clean_totps' );
wp_unschedule_event( $timestamp, 'wpas_clean_totps' );
}