dts777777 2016-03-23 15:02
浏览 28

如何修复仅WP文件的标题输出?

So I'm getting the dreaded

Warning: Cannot modify header information - headers already sent

error message when trying to redirect to a success page on my Wordpress plugin.

The issue is, I'm using wp_safe_redirect as instructed in the Codex like this:

wp_safe_redirect(admin_url("admin.php?page=bv_before_after&msg=4"));
exit;

But what's frustrating, is the files that seem to be having the issue, are both Wordpress core files:

(output started at /var/www/html/wp-includes/formatting.php:4586) in /var/www/html/wp-includes/pluggable.php on line 1228

Lots of tutorials talk about OB_flush(), but there are two sides of every thing I've found so far. There doesn't seem to be anything that seems to explain what's happening in my situation, and why.

I don't think it's a whitespace issue in my plugin file, as I've removed all of that. I'm not too good on creating WP plugins, this is my first or second probably. Any ideas as to what I can do?

EXCERPT: This is a portion from the start of the file, to the end of the function that includes the first redirect

<?php
/*
Plugin Name: BellaVou Before & After Manager
Description: Admin interface for managing Before & After photo sets.
Version: 1.0
Author: Lee Collings
*/
function registration_scripts() {
    wp_register_style('style', plugins_url('style.css', __FILE__));
    wp_enqueue_style('fontAwesome','https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css');
    wp_enqueue_style('style');
}
add_action( 'admin_enqueue_scripts', 'registration_scripts' );
add_action('admin_menu','bv_before_after_menu');
function bv_before_after_menu() {
    add_menu_page( 'BV Before & Afters', 'BV Before & Afters', 'manage_options', 'bv_before_after', 'test_init' );
}
function test_init(){
    global $wpdb;
    $msg = isset($_GET['msg']) ? $_GET['msg'] : '';
    $dateFormat = 'd/M/y';
    // Edit URL param
    $editID = isset($_GET['edit']) ? $_GET['edit'] : '';
    $addItem = isset($_GET['add']) ? $_GET['add'] : '';
    // SQL call if editID present
    if ($editID != '') {
        $editItem = $wpdb->get_row("SELECT * FROM wp_before_after WHERE ID = $editID");
    }else{
        $editItem = null;
    }
    // Delete Item
    if(isset($_POST['deleteItem'])) {
        $result = $wpdb->delete( 'wp_before_after', array( 'ID' => $editID ) );
        if($result) {
            wp_safe_redirect(admin_url("admin.php?page=bv_before_after&msg=4"));
            exit;
        } else {
            $msg = array('danger','The entry could not be deleted');
            echo '<div class="notice notice-'.$msg[0].'"><p>'.$msg[1].'</p></div>';
        }
    }
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥170 如图所示配置eNSP
    • ¥20 docker里部署springboot项目,访问不到扬声器
    • ¥15 netty整合springboot之后自动重连失效
    • ¥15 悬赏!微信开发者工具报错,求帮改
    • ¥20 wireshark抓不到vlan
    • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
    • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
    • ¥15 stata安慰剂检验作图但是真实值不出现在图上
    • ¥15 c程序不知道为什么得不到结果
    • ¥15 键盘指令混乱情况下的启动盘系统重装