为什么函数 metaboxes 导致管理员出现白屏

Why functions metaboxes is causing White Screen in Admin

我在将项目迁移到其他服务器后遇到问题。当我转到 /wp-admin 时,我得到一个 'White Screen of Death'。如果我访问 /wp-login.php 而不是我得到登录表单,但有一个建议

ERROR: Cookies are blocked or not supported by your browser. You must enable cookies to use WordPress.

显然我的浏览器没问题,我在其他电脑上试过了

我浪费了几个小时寻找错误,最后我评论了这些行...

<?php 
function portfolio_custombox($post) {
    $stored_id = get_post_meta( $post->ID, 'pageid_destino', true);
    ?>
    <div class="settBlock"><label for="page_color_scheme">  
    <input type="number" class="" value="<?php echo $stored_id ?>" for="pageid_destino" name="pageid_destino"><br>
    <label for="pageid_destino"><?php _e('Id de la página destino (este número es el que se presenta después del argumento ?post=<b>number</b>)', MY_THEME); ?></label>
<?php } ?>

<?php 
function portfolio_addmetaboxes() {
        $postypes = array('hgr_portfolio');
        foreach ( $postypes as $posttype ) {
            add_meta_box(
            'pageid_destino',
                __( 'ID de Página Destino', MY_THEME ),
                'portfolio_custombox',
                $posttype,
                'normal',
                'high'
            );
        }
    }
    add_action( 'add_meta_boxes', 'portfolio_addmetaboxes' );
    function portfolio_savemetabox($post_id)
    {
        if ( ! isset( $_POST['pageid_destino'] ) ) {
            return $post_id;
        }
        $pageid_destino = sanitize_text_field( $_POST['pageid_destino']);
        update_post_meta($post_id, 'pageid_destino', $pageid_destino );
    }
    add_action( 'save_post', 'portfolio_savemetabox' );

评论完这些行后,我的登录恢复正常了……但是……为什么?

以及为什么这在我的本地环境和以前的主机中没有发生

提前致谢

更新

将 WP_DEBUG 设置为 true 后出现此错误...

Warning: Cannot modify header information - headers already sent by (output started at /home/my/staging/1/wp-content/themes/attractor-child/functions_includes/functions.metaboxes.php:12) in /home/my/staging/1/wp-content/themes/attractor/highgrade/framework/core/newsflash.php on line 72

终于在codex中找到了解决方法....

Interpreting the Error Message:

If the error message states: Warning: Cannot modify header information - headers already sent by (output started at /path/blog/wp-config.php:34) in /path/blog/wp-login.php on line 42, then the problem is at line #34 of wp-config.php, not line #42 of wp-login.php. In this scenario, line #42 of wp-login.php is the victim. It is being affected by the excess whitespace at line #34 of wp-config.php.

If the error message states: Warning: Cannot modify header information - headers already sent by (output started at /path/wp-admin/admin-header.php:8) in /path/wp-admin/post.php on line 569, then the problem is at line #8 of admin-header.php, not line #569 of post.php. In this scenario, line #569 of post.php is the victim. It is being affected by the excess whitespace at line #8 of admin-header.php.

Other issues that might cause that error:

In case you've used the function: wp_redirect() or tried to use a header redirect after the header (or any content at all was sent) that error message will pop. Instead use javascript redirection if needed.

我删除了一些多余的空格,一切正常

add_meta_box(
            'pageid_destino',
                __( 'ID de Página Destino', MY_THEME ),
                'portfolio_custombox',
                $posttype,
                'normal',
                'high'
            ); //spaces were here