Php 如何修复仅WP文件的头输出?
所以我开始害怕了 警告:无法修改标题信息-标题已发送 尝试重定向到我的Wordpress插件上的成功页面时出现错误消息 问题是,我使用的Php 如何修复仅WP文件的头输出?,php,wordpress,redirect,http-headers,Php,Wordpress,Redirect,Http Headers,所以我开始害怕了 警告:无法修改标题信息-标题已发送 尝试重定向到我的Wordpress插件上的成功页面时出现错误消息 问题是,我使用的wp\u safe\u redirect如法典所示: wp_safe_redirect(admin_url("admin.php?page=bv_before_after&msg=4")); exit; 但令人沮丧的是,似乎存在问题的文件都是Wordpress核心文件: (输出开始于/var/www/html/wp includes/formattin
wp\u safe\u redirect
如法典所示:
wp_safe_redirect(admin_url("admin.php?page=bv_before_after&msg=4"));
exit;
但令人沮丧的是,似乎存在问题的文件都是Wordpress核心文件:
(输出开始于/var/www/html/wp includes/formatting.php:4586)
/var/www/html/wp-includes/pluggable.php,第1228行
很多教程都在谈论OB_flush(),但到目前为止,我发现的每一件事都有两面性。似乎没有任何东西可以解释在我的情况下发生了什么以及为什么
我不认为这是我的插件文件中的空白问题,因为我已经删除了所有这些内容。我不太擅长创建WP插件,这可能是我的第一次或第二次。关于我能做什么有什么想法吗
摘录:
这是从文件开始到包含第一个重定向的函数结束的一部分
<?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>';
}
}
您不能安全地依赖该消息,因为wordpress使用操作和过滤器来允许将代码注入这些位置,php将遇到错误并使该文件看起来像是问题所在,实际上,当某个插件在某处运行某个操作时,您最好使用a来查找实际的问题位置。根据执行的操作,PHP文件中有几个wp\u safe\u redirect
s。我正在使用exit代码>在这之前,这是法典指示的..?请显示更多的代码。如果在重定向之前有任何输出,它将不起作用。添加菜单页面()
的可能重复已经太晚,无法使用wp\u安全重定向()
(因为管理中已经有wp的输出)。您需要将isset($\u POST['deleteItem'])
逻辑添加到早期的钩子(理想情况下,init
或类似)