PHP 致命错误 - 无法取消设置字符串偏移量

Tim*_*URA 1 php wordpress google-app-engine

我正在尝试修复在 Google App Engine 上运行的 WP Plugin Contact Form 7 的问题。

补丁代码为:

<?php 
/*
Plugin Name: Fix Contact Form 7
*/    
add_filter('wp_mail', 'fix_wp_mail_filter', 11);
function fix_wp_mail_filter($args) {
    unset($args['headers']['X-WPCF7-Content-Type']);    
    $new_wp_mail = array(
        'to'          => $args['to'],
        'subject'     => $args['subject'],
        'message'     => $args['message'],
        'headers'     => $args['headers'],
        'attachments' => $args['attachments'],
    );      
    return $new_wp_mail;
}
Run Code Online (Sandbox Code Playgroud)

现在,当我测试联系表单时,我在浏览器中收到 500 错误,并检查 App Engine 请求日志,显示以下错误:

PHP 致命错误:

无法取消第 8 行 /base/data/home/apps/s~aura-www/20170807t210800.403218500896707567/wordpress/wp-content/plugins/cf7_fix_plugin.php 中的字符串偏移量

PHP代码有问题吗?

Nim*_*ima 5

发生这种情况是因为$args['headers']是字符串,而不是数组,因此该行unset($args['headers']['X-WPCF7-Content-Type']);会引发此错误。如果您想更改它,请使用字符串操作函数,例如str_replace.