I created a little private plugin for me, which contains a form, that saves data to a database.
Every user should only have one dataset. If he already has one, he should only be able to edit his current one (similar to profile settings).
Thats no problem, works great. But I have one issue: I want to redirect a user to his edit page, if he views the main plugin page (like site.com/submit/ -> site.com/submit/?id=das12d&edit=1)
So building this url is also no problem. But here is the real issue: I tried using this:
wp-redirect( $url );
And
header('Location: '.$url);
But both causing a Cannot modify header information - headers already sent by...
error
How can I solve it?
edit: Some sample code:
function login_data() {
global $current_user;
if (is_user_logged_in()) {
if (isset($_GET['id'])) {
$id = $_GET['id'];
show_submission($id);
} else {
} elseif(has_submission()) {
$url = 'http://'.$_SERVER["HTTP_HOST"].$_SERVER["REQUEST_URI"].'?id='.$get_submission_id();
header('Location: '.$url);
} else {
show_form();
}
}
}
}
wp_redirect
.login_data
. Look at any calls tologin_form
and verify that no output has been sent yet.