| 1 |
<?php |
| 2 |
|
| 3 |
if(!defined('ABSPATH')){ |
| 4 |
die('Hacking Attempt!'); |
| 5 |
} |
| 6 |
|
| 7 |
// Loginizer - PasswordLess Page |
| 8 |
function loginizer_page_passwordless(){ |
| 9 |
|
| 10 |
global $loginizer, $lz_error, $lz_env; |
| 11 |
|
| 12 |
if(!current_user_can('manage_options')){ |
| 13 |
wp_die('Sorry, but you do not have permissions to change settings.'); |
| 14 |
} |
| 15 |
|
| 16 |
if(!loginizer_is_premium() && count($_POST) > 0){ |
| 17 |
$lz_error['not_in_free'] = __('This feature is not available in the Free version. <a href="'.LOGINIZER_PRICING_URL.'" target="_blank" style="text-decoration:none; color:green;"><b>Upgrade to Pro</b></a>', 'loginizer'); |
| 18 |
return loginizer_page_passwordless_T(); |
| 19 |
} |
| 20 |
|
| 21 |
/* Make sure post was from this page */ |
| 22 |
if(count($_POST) > 0){ |
| 23 |
check_admin_referer('loginizer-options'); |
| 24 |
} |
| 25 |
|
| 26 |
if(isset($_POST['save_lz'])){ |
| 27 |
|
| 28 |
// In the future there can be more settings |
| 29 |
$option['email_pass_less'] = (int) lz_optpost('email_pass_less'); |
| 30 |
$option['passwordless_sub'] = @stripslashes($_POST['lz_passwordless_sub']); |
| 31 |
$option['passwordless_msg'] = @stripslashes($_POST['lz_passwordless_msg']); |
| 32 |
$option['passwordless_html'] = (int) lz_optpost('lz_passwordless_html'); |
| 33 |
$option['passwordless_redirect'] = esc_url_raw($_POST['lz_passwordless_redirect']); |
| 34 |
$option['passwordless_redirect_for'] = !empty($_POST['lz_passwordless_redirect_for']) ? map_deep($_POST['lz_passwordless_redirect_for'], 'sanitize_text_field') : []; |
| 35 |
$option['passwordless_disabled_for'] = !empty($_POST['lz_passwordless_disabled_for']) ? map_deep(wp_unslash($_POST['lz_passwordless_disabled_for']), 'sanitize_text_field') : []; |
| 36 |
|
| 37 |
// Is there an error ? |
| 38 |
if(!empty($lz_error)){ |
| 39 |
return loginizer_page_passwordless_T(); |
| 40 |
} |
| 41 |
|
| 42 |
// Save the options |
| 43 |
update_option('loginizer_epl', $option); |
| 44 |
|
| 45 |
// Mark as saved |
| 46 |
$GLOBALS['lz_saved'] = true; |
| 47 |
|
| 48 |
} |
| 49 |
|
| 50 |
// Call theme |
| 51 |
loginizer_page_passwordless_T(); |
| 52 |
} |
| 53 |
|
| 54 |
// Loginizer - PasswordLess Page Theme |
| 55 |
function loginizer_page_passwordless_T(){ |
| 56 |
|
| 57 |
global $loginizer, $lz_error, $lz_env; |
| 58 |
|
| 59 |
$lz_options = get_option('loginizer_epl'); |
| 60 |
|
| 61 |
// Universal header |
| 62 |
loginizer_page_header('PasswordLess Settings'); |
| 63 |
|
| 64 |
loginizer_feature_available('PasswordLess Login'); |
| 65 |
|
| 66 |
// Saved ? |
| 67 |
if(!empty($GLOBALS['lz_saved'])){ |
| 68 |
echo '<div id="message" class="updated"><p>'. __('The settings were saved successfully', 'loginizer'). '</p></div><br />'; |
| 69 |
} |
| 70 |
|
| 71 |
// Any errors ? |
| 72 |
if(!empty($lz_error)){ |
| 73 |
lz_report_error($lz_error);echo '<br />'; |
| 74 |
} |
| 75 |
|
| 76 |
?> |
| 77 |
|
| 78 |
<style> |
| 79 |
input[type="text"], textarea, select { |
| 80 |
width: 90%; |
| 81 |
} |
| 82 |
|
| 83 |
.form-table label{ |
| 84 |
font-weight:bold; |
| 85 |
} |
| 86 |
|
| 87 |
.form-table td{ |
| 88 |
vertical-align:top; |
| 89 |
} |
| 90 |
|
| 91 |
.exp{ |
| 92 |
font-size:12px; |
| 93 |
} |
| 94 |
</style> |
| 95 |
|
| 96 |
<div id="" class="postbox"> |
| 97 |
|
| 98 |
<div class="postbox-header"> |
| 99 |
<h2 class="hndle ui-sortable-handle"> |
| 100 |
<span><?php echo __('PasswordLess Settings', 'loginizer'); ?></span> |
| 101 |
</h2> |
| 102 |
</div> |
| 103 |
|
| 104 |
<div class="inside"> |
| 105 |
|
| 106 |
<form action="" method="post" enctype="multipart/form-data" loginizer-premium-only="1"> |
| 107 |
<?php wp_nonce_field('loginizer-options'); ?> |
| 108 |
<table class="form-table"> |
| 109 |
<tr> |
| 110 |
<td scope="row" valign="top" style="width:350px !important"><label for="email_pass_less"><?php echo __('Enable PasswordLess Login', 'loginizer'); ?></label></td> |
| 111 |
<td> |
| 112 |
<input type="checkbox" value="1" name="email_pass_less" id="email_pass_less" <?php echo lz_POSTchecked('email_pass_less', (empty($loginizer['email_pass_less']) ? false : true)); echo (defined('SITEPAD') ? 'disabled="disabled"' : '') ?> /> |
| 113 |
</td> |
| 114 |
</tr> |
| 115 |
<tr> |
| 116 |
<td colspan="2" valign="top"> |
| 117 |
<?php echo __('If enabled, the login screen will just ask for the username <b>OR</b> email address of the user. If such a user exists, an email with a <b>One Time Login </b> link will be sent to the email address of the user. The link will be valid for 10 minutes only.', 'loginizer'); ?><br><br> |
| 118 |
<?php echo __('If a wrong username/email is given, the brute force checker will prevent any brute force attempt !', 'loginizer'); ?> |
| 119 |
</td> |
| 120 |
</tr> |
| 121 |
<tr> |
| 122 |
<td scope="row" valign="top"> |
| 123 |
<label for="lz_passwordless_sub"><?php echo __('Email Subject', 'loginizer'); ?></label><br> |
| 124 |
<span class="exp"><?php echo __('Set blank to reset to the default subject', 'loginizer'); ?></span> |
| 125 |
<br />Default : <?php echo (!empty($loginizer['pl_d_sub']) ? $loginizer['pl_d_sub'] : ''); ?> |
| 126 |
</td> |
| 127 |
<td valign="top"> |
| 128 |
<input type="text" size="40" value="<?php echo lz_htmlizer(!empty($_POST['lz_passwordless_sub']) ? stripslashes($_POST['lz_passwordless_sub']) : (empty($lz_options['passwordless_sub']) ? '' : $lz_options['passwordless_sub'])); ?>" name="lz_passwordless_sub" id="lz_passwordless_sub" /> |
| 129 |
</td> |
| 130 |
</tr> |
| 131 |
<tr> |
| 132 |
<td scope="row" valign="top"> |
| 133 |
<label for="lz_passwordless_msg"><?php echo __('Email Body', 'loginizer'); ?></label><br> |
| 134 |
<span class="exp"><?php echo __('Set blank to reset to the default message', 'loginizer'); ?></span> |
| 135 |
<br />Default : <pre style="font-size:10px"><?php echo (!empty($loginizer['pl_d_msg']) ? $loginizer['pl_d_msg'] : '') ; ?></pre> |
| 136 |
</td> |
| 137 |
<td valign="top"> |
| 138 |
<textarea rows="10" name="lz_passwordless_msg" id="lz_passwordless_msg"><?php echo lz_htmlizer(!empty($_POST['lz_passwordless_msg']) ? stripslashes($_POST['lz_passwordless_msg']) : (empty($lz_options['passwordless_msg']) ? '' : $lz_options['passwordless_msg'])); ?></textarea> |
| 139 |
<br /> |
| 140 |
Variables : |
| 141 |
<br />$email - Users Email |
| 142 |
<br />$site_name - The Site Name |
| 143 |
<br />$site_url - The Site URL |
| 144 |
<br />$login_url - The Login URL |
| 145 |
</td> |
| 146 |
</tr> |
| 147 |
<tr> |
| 148 |
<td scope="row" valign="top"><label for="lz_passwordless_html"><?php echo __('Send email as HTML', 'loginizer'); ?></label></td> |
| 149 |
<td> |
| 150 |
<input type="checkbox" value="1" name="lz_passwordless_html" id="lz_passwordless_html" <?php echo lz_POSTchecked('lz_passwordless_html', (empty($loginizer['passwordless_html']) ? false : true)); ?> /> |
| 151 |
</td> |
| 152 |
</tr> |
| 153 |
<tr> |
| 154 |
<td scope="row" valign="top" style="width:350px !important"> |
| 155 |
<label for="lz_passwordless_redirect"><?php echo __('Custom redirect to', 'loginizer'); ?></label><br/> |
| 156 |
<span class="exp"><?php echo __('Redirects user to a page of your website other than the admin panel', 'loginizer'); ?></span> |
| 157 |
</td> |
| 158 |
<td align="top"> |
| 159 |
<input type="text" size="40" value="<?php echo lz_htmlizer(!empty($_POST['lz_passwordless_redirect']) ? stripslashes($_POST['lz_passwordless_redirect']) : (empty($lz_options['passwordless_redirect']) ? '' : $lz_options['passwordless_redirect'])); ?>" name="lz_passwordless_redirect" id="lz_passwordless_redirect" /> |
| 160 |
</td> |
| 161 |
</tr> |
| 162 |
|
| 163 |
<tr> |
| 164 |
<td scope="row" valign="top" style="width:350px !important"> |
| 165 |
<label for="lz_passwordless_redirect_for"><?php echo __('Custom redirect for', 'loginizer'); ?></label><br/> |
| 166 |
<span class="exp"><?php echo __('Select the user roles for whom this custom redirect will be used', 'loginizer'); ?></span> |
| 167 |
</td> |
| 168 |
<td align="top"> |
| 169 |
<?php |
| 170 |
$editable_roles = get_editable_roles(); |
| 171 |
echo '<div style="max-height:120px; overflow:auto;">'; |
| 172 |
$r = ''; |
| 173 |
foreach($editable_roles as $role => $details) { |
| 174 |
$name = translate_user_role( $details['name'] ); |
| 175 |
// Preselect specified role. |
| 176 |
if(!empty($lz_options['passwordless_redirect_for']) && in_array($role, $lz_options['passwordless_redirect_for'])) { |
| 177 |
$r .= "\n\t<input type=\"checkbox\" checked name=\"lz_passwordless_redirect_for[]\" value='" . esc_attr($role) . "' style=\"margin-top:5px\">$name</option>"; |
| 178 |
} else { |
| 179 |
$r .= "\n\t<input type=\"checkbox\" value='" . esc_attr($role) . "' name=\"lz_passwordless_redirect_for[]\">$name</option>"; |
| 180 |
} |
| 181 |
|
| 182 |
$r .= '<br/>'; |
| 183 |
} |
| 184 |
echo $r . '</div>'; |
| 185 |
?> |
| 186 |
</td> |
| 187 |
</tr> |
| 188 |
|
| 189 |
<tr> |
| 190 |
<td scope="row" valign="top" style="width:350px !important"> |
| 191 |
<label for="lz_passwordless_disabled_for"><?php echo __('Disable for', 'loginizer'); ?></label><br/> |
| 192 |
<span class="exp"><?php echo __('Which login form you want to disable passwordless login for', 'loginizer'); ?></span> |
| 193 |
</td> |
| 194 |
<td align="top"> |
| 195 |
<?php |
| 196 |
$forms = ['admin', 'woocommerce']; |
| 197 |
echo '<div>'; |
| 198 |
$r = ''; |
| 199 |
foreach($forms as $form) { |
| 200 |
// Preselect specified form. |
| 201 |
if(!empty($lz_options['passwordless_disabled_for']) && in_array($form, $lz_options['passwordless_disabled_for'])){ |
| 202 |
$r .= "\n\t<input type=\"checkbox\" checked name=\"lz_passwordless_disabled_for[]\" value='" . esc_attr($form) . "' style=\"margin-top:5px\">".esc_html(ucfirst($form))."</option>"; |
| 203 |
} else { |
| 204 |
$r .= "\n\t<input type=\"checkbox\" value='" . esc_attr($form) . "' name=\"lz_passwordless_disabled_for[]\">".esc_html(ucfirst($form))."</option>"; |
| 205 |
} |
| 206 |
|
| 207 |
$r .= '<br/>'; |
| 208 |
} |
| 209 |
echo $r . '</div>'; |
| 210 |
?> |
| 211 |
</td> |
| 212 |
</tr> |
| 213 |
|
| 214 |
</table><br /> |
| 215 |
<center><input name="save_lz" class="button button-primary action" value="<?php echo __('Save Settings', 'loginizer'); ?>" type="submit" /></center> |
| 216 |
</form> |
| 217 |
|
| 218 |
</div> |
| 219 |
</div> |
| 220 |
<br /> |
| 221 |
|
| 222 |
<?php |
| 223 |
loginizer_page_footer(); |
| 224 |
|
| 225 |
} |