Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Wordpress重定向问题,标题已发送_Wordpress_Wordpress Theming_Updates - Fatal编程技术网

Wordpress重定向问题,标题已发送

Wordpress重定向问题,标题已发送,wordpress,wordpress-theming,updates,Wordpress,Wordpress Theming,Updates,我想知道,根据下面的代码,我想把我的wp_重定向函数放在哪里,因为它当前所在的位置只会发出嘶嘶声并说: Warning: Cannot modify header information - headers already sent by (output started at /***/***/WordPress/WordPressDev/wp-includes/script-loader.php:664) in /***/***/WordPress/WordPressDev/wp-inclu

我想知道,根据下面的代码,我想把我的wp_重定向函数放在哪里,因为它当前所在的位置只会发出嘶嘶声并说:

 Warning: Cannot modify header information - headers already sent by (output started at /***/***/WordPress/WordPressDev/wp-includes/script-loader.php:664) in /***/***/WordPress/WordPressDev/wp-includes/pluggable.php on line 881
这是因为页面已经加载了。但是我不知道在哪里调用这个函数

我已经用stars和example.com替换了我的网站和任何“个人数据”。无论这段代码如何工作,它都不会重定向我

想法

function get_latest_version_zip(){
             global $wp_filesystem;

             if(current_user_can('update_themes')){
                $aisis_file_system_structure = WP_Filesystem();
                $aisis_cred_url = 'admin.php?page=aisis-core-update';
                if($aisis_file_system_structure == false){
                    request_filesystem_credentials($aisis_cred_url);
                    $this->credential_check = true;
                }

                $aisis_temp_file_download = download_url( 'http://example.com/aisis/aisis_update/Aisis2.zip' );

                if(is_wp_error($aisis_temp_file_download)){
                    $error = $aisis_temp_file_download->get_error_code();
                    if($error == 'http_no_url') {
                        add_action( 'admin_notices', 'aisis_framework_download_update_erors' );
                    }
                }

                $aisis_unzip_to = $wp_filesystem->wp_content_dir() . "/themes/" . get_option('template');

                $this->delete_contents_check(); //Check if we need to delete the aisis core folder.

                $aisis_do_unzip = unzip_file($aisis_temp_file_download, $aisis_unzip_to);

                unlink($aisis_temp_file_download); //delete temp jazz

                if(is_wp_error($aisis_do_unzip)){
                    $error = $aisis_do_unzip->get_error_code();
                    if($error == 'incompatible_archive') {
                        $this->aisis_incompatible_archive_errors();
                    }
                    if($error == 'empty_archive') {
                        $this->aisis_empty_archive_errors();
                    }
                    if($error == 'mkdir_failed') {
                        $this->aisis_mkdir_failed_errors();
                    }
                    if($error == 'copy_failed') {
                        $this->aisis_copy_failed_errors();
                    }
                    return;
                }
                //throwing errors
                wp_redirect(admin_url('admin.php?page=aisis-core-options'));
                exit;

             }
         }
在我的functions.php文件中,我放置了以下代码:

 function callback($buffer){
     return $buffer;
 }

 function add_ob_start(){
     ob_start("callback");
 }

 function flush_ob_end(){
     ob_end_flush();
 }

 add_action('wp_head', 'add_ob_start');
 add_action('wp_footer', 'flush_ob_end');

在这种情况下,我仍然得到了错误,我想我误解了什么….

问题是,wordpress中的某个地方调用了
header()
函数,并且在
输出缓冲关闭时,一些输出已经发送到客户端

头必须在任何输出之前发送,否则会出现您描述的错误

wp_redirect(admin_url('admin.php?page=aisis-core-options'));
上面的一行设置了如下标题:
header('Location:admin.php……)

通过php.ini、wordpress的index.php或在向客户机回显任何内容之前打开输出缓冲应该会处理错误

详情/文件可在此处找到:

我能想到的最简单的方法是使您的wordpress index.php如下所示:

ob_start();
// content of your index.php here
ob_flush();

只需替换以下行

add_action('wp_head', 'add_ob_start');


输出缓冲应该在任何发送/回显到浏览器之前开始,并且
wp_head
hook比
init
hook晚一点出现,直到headers已经发送,并将其保留/放置在
函数的顶部。php
在任何回显/发送到浏览器之前。

另一种可能是添加优先权:

add_action('wp_head', 'add_ob_start', 1);
第三个参数是$priority


此外,如果您正在连接多个函数,它会让您完全控制执行链。

当您说“我的WordPress索引文件”时,您的意思是什么?核心?,主题目录中的那个,还是我的主题?据我所知,有很多WP索引文件。据我所知,入口点是theme index.php,因此我将对此进行测试,并报告不起作用的情况。我唯一能想到的另一个地方是WordPress核心文件,但既然这些文件在你更新WordPress时得到更新,你就知道不要碰它们了。你能解释一下我该怎么处理这些文件吗?或者如果我在case函数callback($buffer){//modify buffer here,然后返回已发送的更新代码return$buffer;}头(输出开始于/***/***/WordPress/WordPressDev/wp includes/script loader.php:664)在第881行的/***/***/WordPress/WordPressDev/wp includes/pluggable.php中老实说,我在我的WordPress站点中使用了相同的代码,它运行良好。我只是使用了
init
hook而不是
wp\u head
。使用“init”停止了错误,但代码没有运行。
add_action('wp_head', 'add_ob_start', 1);