【问题标题】:Header location doesn't work in my wordpress plugin.标题位置在我的 wordpress 插件中不起作用。
【发布时间】:2014-04-18 01:28:32
【问题描述】:

我正在编写一个 Wordpress 插件。使用这个插件我更新了一些数据。查询和更新工作正常,但我的 header("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


    【解决方案1】:

    也许你应该试试 javascript,而不是 PHP 位置。

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

    【讨论】:

      【解决方案2】:

      下面的代码会帮助你

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

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

      【讨论】:

      • 不工作....问题是标题已经发送到我需要的文件中。警告:无法修改标头信息 - 标头已由 /home/almeer/domains/ 中的(输出开始于 /home/almeer/domains/almeerderhout.nl/public_html/wp-content/plugins/baanstatus/index.php:86)发送almeerderhout.nl/public_html/wp-includes/pluggable.php 在第 896 行
      • 在wordpress主插件文件中避免程序开始行和结束行的空闲空间。 codex.wordpress.org/Writing_a_Plugin请看链接。
      【解决方案3】:

      您应该将您的插件与正确的 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');
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2013-08-22
        • 1970-01-01
        • 2020-05-21
        • 2013-09-01
        • 1970-01-01
        相关资源
        最近更新 更多