Проблема с переадресацией WordPress, заголовки уже отправлены

Мне интересно, основываясь на приведенном ниже коде, где я хотел бы поместить мою функцию wp_redirect, потому что там, где она в данный момент находится, ничего не происходит, кроме spazzes out и sais:

 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

Который я получаю, потому что страница уже загружена. но я не уверен, где вызвать эту функцию.

Я заменил свой веб-сайт и любые «личные данные» со звездами и 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');

с этим я все равно получаю ошибку, я думаю, что-то недопонимание ....

Ответы на вопрос(3)

Ваш ответ на вопрос