Header位置在我的wordpress插件中不起作用。

问题描述 投票:1回答:3

我正在写一个Wordpress插件。使用此插件,我可以更新一些数据。查询和更新工作正常,但我的标头("location: url");不起作用。如果放置回显,将不会给标头已经发送的任何错误。看起来这些行没有任何作用。我的代码...

<?php require_once('../../../wp-config.php');
$baanstatus_table=$wpdb->prefix . 'baanstatus';
$id = $_GET['id'];
$bijgewerkt =$_GET['bijgewerkt'];
$baanstatus= $_GET['baanstatus'];
$handicarts = $_GET['handicarts'];
$trolleys = $_GET['trolleys'];
$winterontheffing = $_GET['winterontheffing'];
$zomergreens = $_GET['zomergreens'];
$qualifying = $_GET['qualifying'];
$onderhoud_greens = $_GET['onderhoud_greens'];
$onderhoud_anders = $_GET['onderhoud_anders'];
$opmerkingen = $_GET['opmerkingen'];
global $wpdb;
$data_array =array('id' => $id, 
'bijgewerkt' => $bijgewerkt, 
'baanstatus' => $baanstatus, 
'handicarts' => $handicarts, 
'trolleys' => $trolleys,
'winterontheffing' =>$winterontheffing,
'zomergreens' =>$zomergreens,
'qualifying' =>$qualifying,
'onderhoud_greens' =>$onderhoud_greens,
'onderhoud_anders' =>$onderhoud_anders,
'opmerkingen' =>$opmerkingen
);
$where =array('id' => $id);
$wpdb->update( $baanstatus_table, $data_array, $where );
header("location:http://almeerderhout.fcklap.com/wp-admin/options-general.php?page=my-unique-identifier");
exit(); 
?>
wordpress header location
3个回答
3
投票

也许您应该尝试使用javascript,而不是PHP位置。

<?php
   echo '<script>location.href="http://almeerderhout.fcklap.com/wp-admin/options-general.php?page=my-unique-identifier";</script>';
?>

1
投票

下面的代码将帮助您

 <?php
wp_redirect( $location, $status );
exit;
?>

上面的wordpress函数将用于重定向Codex Link function reference


0
投票

您应该将插件挂接到正确的Wordpress操作上,以避免在尝试重定向时出现“标题已发送错误”。

我发现template_redirect操作是执行重定向的一个好地方,因此您可以编写如下内容:

function do_something_then_redirect() {

    // do something with $_GET or $_POST data

    // then redirect to some url defined in the $redirect_url variable
    wp_redirect($redirect_url);
    die;
}
add_action('template_redirect', 'do_something_then_redirect');
© www.soinside.com 2019 - 2024. All rights reserved.