0

I am working on custom login page for WordPress, but I have problem. After I click on submit button I got the following error:

Warning: Cannot modify header information - headers already sent by (output started at C:\wamp\www\wordpress-4.7.3\wp-includes\class.wp-styles.php:237) in C:\wamp\www\wordpress-4.7.3\wp-includes\pluggable.php on line 904 Warning: Cannot modify header information - headers already sent by (output started at C:\wamp\www\wordpress-4.7.3\wp-includes\class.wp-styles.php:237) in C:\wamp\www\wordpress-4.7.3\wp-includes\pluggable.php on line 905 Warning: Cannot modify header information - headers already sent by (output started at C:\wamp\www\wordpress-4.7.3\wp-includes\class.wp-styles.php:237) in C:\wamp\www\wordpress-4.7.3\wp-includes\pluggable.php on line 906 Warning: Cannot modify header information - headers already sent by (output started at C:\wamp\www\wordpress-4.7.3\wp-includes\class.wp-styles.php:237) in C:\wamp\www\wordpress-4.7.3\wp-includes\pluggable.php on line 1195

Here is my custom login full codes

<?php

function dlf_form() {
  echo '
  <form class="form-inline" method="post" action="' . $_SERVER['REQUEST_URI'] . '">
    <div class="form-group">
      <input type="text" id="email" name="login_name" placeholder="إسم المستخدم">
    </div>
    <div class="form-group">
      <input type="password" id="pwd" name="login_password" placeholder="كلمة السر">
    </div>
    <button type="submit" name="dlf_submit">تسجيل</button>
  </form>
  ';
}

function dlf_auth( $username, $password ) {
global $user;
$creds = array();
$creds['user_login'] = $username;
$creds['user_password'] =  $password;
$creds['remember'] = true;
$user = wp_signon( $creds, false );
if ( is_wp_error($user) ) {
echo $user->get_error_message();
}
if ( !is_wp_error($user) ) {
wp_redirect(home_url('wp-admin'));
}
}

function dlf_process() {
if (isset($_POST['dlf_submit'])) {
    dlf_auth($_POST['login_name'], $_POST['login_password']);
    echo 'Test text';
}

dlf_form();
}

function dlf_shortcode() {
ob_start();
dlf_process();
return ob_get_clean();
}


add_shortcode('dm_login_form', 'dlf_shortcode');
Funk Forty Niner
  • 74,372
  • 15
  • 66
  • 132
mohamed youssouf
  • 1,285
  • 2
  • 10
  • 15
  • 4
    Try adding ob_start at the first line of the file like – manian Apr 25 '17 at 11:23
  • [Check this out](http://stackoverflow.com/questions/9707693/warning-cannot-modify-header-information-headers-already-sent-by-error) – Suresh Velusamy Apr 25 '17 at 11:24
  • ensure nothing is output before header is called – atoms Apr 25 '17 at 11:28
  • Thanks everyone specially @manian adding ob_start(); fixed the error :) – mohamed youssouf Apr 25 '17 at 11:29
  • Why do you want to be creating a custom login page. Why not use the existing login page and customise the look of this? It's fairly easy to do with the relevant WP hooks. Alternatively there are several plugins that let you drop a shortcode onto any page and thus add a login box there. – Phill Healey Apr 25 '17 at 12:24
  • @manian after spending almost 5 hours for the same issue I found your comment and it worked. Thank you. – Shwet Jul 20 '17 at 11:43

1 Answers1

0

After wp_redirect(home_url('wp-admin')); put a wp_die();

Alice
  • 1,360
  • 1
  • 16
  • 28