' . __('Settings') . '';
array_unshift($links, $settings_link); // before other links
return $links;
}
function xlttotpauth_activate() {
update_option('xlttotpauth_enabled', 'true');
}
add_action('admin_init', 'xlttotpauth_register_my_setting');
add_action('admin_menu', 'xlttotpauth_adminmenu');
register_activation_hook(__FILE__, 'xltadincode_activate');
add_filter( 'plugin_action_links_' . plugin_basename(__FILE__), 'xlttotpauth_filter_plugin_actions', 10, 2 );
function xlttotpauth_adminmenu() {
add_options_page('XLT TOTP Auth', __('XLT TOTP Auth'), 'level_10', 'xlttotpauth', 'xlttotpauth_main');
}
function xlttotpauth_main() {
$act = (isset($_GET['act']) ? $_GET['act'] : null);
switch ($act) {
case null:
default:
xlttotpauth_main_overview();
break;
case 'users':
xlttotpauth_users();
break;
case 'generatenew':
xlttotpauth_generatenewtoken();
break;
}
}
function xlttotpauth_main_overview() {
print "
";
screen_icon();
print "
" . __('XLT TOTP Auth Settings', 'xlttotpauth') . "
";
if (isset($_GET['settings-updated']) && @$_GET['settings-updated'] == 'true') {
print "
" . __("Changes has been saved.", "xlttotpauth") . "
";
}
print "
";
}
function xlttotpauth_login_form() {
?>
";
screen_icon('users');
print "
" . __('XLT TOTP User list', 'xlttotpauth') . "
";
$args = array(
'blog_id' => $GLOBALS['blog_id'],
'role' => '',
'meta_key' => '',
'meta_value' => '',
'meta_compare' => '',
'meta_query' => array(),
'include' => array(),
'exclude' => array(),
'orderby' => 'login',
'order' => 'ASC',
'offset' => '',
'search' => '',
'number' => '',
'count_total' => false,
'fields' => array('ID', 'user_login', 'user_nicename'),
'who' => ''
);
print var_export(get_users($args), true);
print "
";
}
add_action('show_user_profile', 'xlttotpauth_profile');
add_action('edit_user_profile', 'xlttotpauth_profile');
function xlttotpauth_profile($user) {
$enabled = get_user_meta($user->data->ID, 'xlttotpauth_enabled');
if (isset($enabled[0])) {
$enabled = (bool) $enabled[0];
}
$token = get_user_meta($user->data->ID, 'xlttotpauth_seckey');
if (isset($token[0])) {
$token = $token[0];
} else {
$token = '';
}
wp_enqueue_script('jquery');
echo "" . __("XLT TOTP Auth", "xlttotpauth") . "
";
echo "";
echo "";
}
add_action('personal_options_update', 'xlttotpauth_user_update');
add_action('edit_user_profile_update', 'xlttotpauth_user_update');
function xlttotpauth_user_update($uid) {
$checked = (isset($_POST['token_auth']));
$token = @$_POST['token_auth_code'];
if ($token == null) {
$checked = false;
}
update_user_meta($uid, 'xlttotpauth_enabled', (bool) $checked);
update_user_meta($uid, 'xlttotpauth_seckey', $token);
}
add_action('wp_ajax_xlttotpauth_newtoken', 'xlttotpauth_generatenewtoken');
function xlttotpauth_generatenewtoken() {
$string = 'qwertyuiopasdfghjklzxcvbnm0987654321QWERTYUIOPASDFGHJKLZXCVBNM';
$code = '';
for ($i = 0; $i < 10; $i++) {
$code .= substr(str_shuffle($string), 0, 1);
}
wp_send_json(array('res' => 0, 'code' => $code));
}
?>