K
K
kogetem3202020-06-01 15:59:41
WordPress
kogetem320, 2020-06-01 15:59:41

How to make wordpress login without plugins?

I tried to implement authorization in wordpress without plugins by writing a script in header.php -
1 script:

spoiler
<?php

require('wp-load.php');
$error = null;
$user = wp_signon();

if(!empty($_POST)) {
  $creds = array();
  $creds['user_login'] = strip_tags(trim($_POST['login']));
  $creds['user_password'] = strip_tags(trim($_POST['password']));
  $user = wp_signon($creds, false);

  if($user->errors) {
    $error = 'Неверный логин или пароль';
  
  } else {
    header('Location: http://airemont/');
    $error = null;
  }
}
?>

2 script (together with the form):
spoiler
<?php if (!current_user_can('level_0')) { ?>

<script type="text/javascript">
function login_clear() {
var log = document.getElementById('log');
if (log.value == "Логин"){ log.value = "";}
}
function pwd_clear() {
var pwd = document.getElementById('pwd');
if (pwd.value == "Пароль"){ pwd.value = "";}
}
</script>

<div class="loginlabel" align="center">
<table width="885" border="0" cellspacing="0" cellpadding="7">
<tr>
<td align="left" bgcolor="#cccccc" height="30">

<form action="<?php echo get_option('home'); ?>/wp-login.php" method="post" >
<input type="text" name="log" id="log" value="<?php echo wp_specialchars(stripslashes($user_login), 1) ?>" size="20" />
<input type="password" name="pwd" id="pwd" size="20" value="" />
<input type="submit" name="submit" value=" Войти " class="button" />
<label for="rememberme"><input name="rememberme" id="rememberme" type="checkbox"  value="forever" /> Запомнить</label>&nbsp;&nbsp;&nbsp;
<input type="hidden" name="redirect_to" value="<?php echo $_SERVER['REQUEST_URI']; ?>" />
<a href="<?php echo get_option('home'); ?>/wp-login.php?action=lostpassword">Забыли пароль?</a>&nbsp;&nbsp;&nbsp;
<a href="<?php echo get_option('home'); ?>/wp-login.php?action=register">Регистрация</a>
</form>

</td>
<td align="right" bgcolor="#CCCCCC" height="30"><?php get_search_form(); ?></td>
</tr>
</table>
</div>
<?php } ?>


If you register plugins separately, they do not work.
I don't understand php very well, I would like to know what my mistakes are

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dima, 2020-06-01
Dolgoter @SpiderPigAndCat

here

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question