PHP 未定义索引(WP 客户区在文件下载时中断)

PHP Undefined Index (WP Customer Area breaks on file download)

我工作的公司正在为我们的一位客户使用客户区,直到最近一切都很好。当尝试下载私人文件时,我们会收到几条错误消息:

Notice: Undefined index: force-download in /Users/mathew/Websites/mamp/portal-test/wp-content/plugins/customer-area/src/php/core-addons/private-file/private-file-addon.class.php on line 1029

Warning: Cannot modify header information - headers already sent by (output started at /Users/mathew/Websites/mamp/portal-test/wp-content/plugins/customer-area/src/php/core-addons/private-file/private-file-addon.class.php:1029) in /Users/mathew/Websites/mamp/portal-test/wp-content/plugins/customer-area/src/php/core-addons/private-file/private-file-default-handlers.class.php on line 945

Warning: Cannot modify header information - headers already sent by (output started at /Users/mathew/Websites/mamp/portal-test/wp-content/plugins/customer-area/src/php/core-addons/private-file/private-file-addon.class.php:1029) in /Users/mathew/Websites/mamp/portal-test/wp-content/plugins/customer-area/src/php/core-addons/private-file/private-file-default-handlers.class.php on line 952

Warning: Cannot modify header information - headers already sent by (output started at /Users/mathew/Websites/mamp/portal-test/wp-content/plugins/customer-area/src/php/core-addons/private-file/private-file-addon.class.php:1029) in /Users/mathew/Websites/mamp/portal-test/wp-content/plugins/customer-area/src/php/core-addons/private-file/private-file-default-handlers.class.php on line 955

Warning: Cannot modify header information - headers already sent by (output started at /Users/mathew/Websites/mamp/portal-test/wp-content/plugins/customer-area/src/php/core-addons/private-file/private-file-addon.class.php:1029) in /Users/mathew/Websites/mamp/portal-test/wp-content/plugins/customer-area/src/php/core-addons/private-file/private-file-default-handlers.class.php on line 956

Warning: Cannot modify header information - headers already sent by (output started at /Users/mathew/Websites/mamp/portal-test/wp-content/plugins/customer-area/src/php/core-addons/private-file/private-file-addon.class.php:1029) in /Users/mathew/Websites/mamp/portal-test/wp-content/plugins/customer-area/src/php/core-addons/private-file/private-file-default-handlers.class.php on line 959

Warning: Cannot modify header information - headers already sent by (output started at /Users/mathew/Websites/mamp/portal-test/wp-content/plugins/customer-area/src/php/core-addons/private-file/private-file-addon.class.php:1029) in /Users/mathew/Websites/mamp/portal-test/wp-content/plugins/customer-area/src/php/core-addons/private-file/private-file-default-handlers.class.php on line 960

Warning: Cannot modify header information - headers already sent by (output started at /Users/mathew/Websites/mamp/portal-test/wp-content/plugins/customer-area/src/php/core-addons/private-file/private-file-addon.class.php:1029) in /Users/mathew/Websites/mamp/portal-test/wp-content/plugins/customer-area/src/php/core-addons/private-file/private-file-default-handlers.class.php on line 961

Warning: Cannot modify header information - headers already sent by (output started at /Users/mathew/Websites/mamp/portal-test/wp-content/plugins/customer-area/src/php/core-addons/private-file/private-file-addon.class.php:1029) in /Users/mathew/Websites/mamp/portal-test/wp-content/plugins/customer-area/src/php/core-addons/private-file/private-file-default-handlers.class.php on line 989

当尝试通过插件重置插件设置或数据库时,我们也遇到错误:

Notice: Undefined index: cuar_admin_theme_url in /Users/mathew/Websites/mamp/portal-test/wp-content/plugins/customer-area/src/php/core-classes/settings.class.php on line 674

Warning: Cannot modify header information - headers already sent by (output started at /Users/mathew/Websites/mamp/portal-test/wp-content/plugins/customer-area/src/php/core-classes/settings.class.php:674) in /Users/mathew/Websites/mamp/portal-test/wp-includes/pluggable.php on line 1216

我们正在使用我们自己的 WordPress 主题,我们已经删除了所有自定义的 WP 客户专区模板,甚至将主题切换为 TwentySeventeen,但错误仍然出现。除了切换主题,我们还尝试卸载并重新安装插件。

所以我们决定创建一个新的空白 WordPress 环境并在那里进行测试,然后重新下载插件以确保它是新的。下载按钮随后开始工作,但在测试 second/third 时间后返回错误。

如前所述,该插件在昨天被发现之前一直运行良好。我们没有编辑任何核心文件,只有我们按照 WP 客户区的说明所做的模板文件。该站点是 运行 WordPress 4.9.1,插件版本是 7.4.5。但是,我们已经尝试使用 Wordpress 4.9 和插件版本 7.4.0、7.3.0。

如果有人可以提供帮助,我们将不胜感激。感谢您抽空阅读我的留言。

谢谢

我联系了 WP 客户区的人员,他们正在调查这个问题,因为它似乎是插件中的一个错误。但与此同时,他们给了我一些代码来通过替换来阻止错误:

!isset($_GET['force-download']) && $_GET['force-download'] != 1)

第 1029 行 customer-area/src/php/core-addons/private-file/private-file-addon.class.php.

行:

if ( !isset($_GET['force-download']) || (isset($_GET['force-download']) && $_GET['force-download'] !== 1))

这帮助我解决了错误,希望对你们也有帮助。

不幸的是,您可能需要通过大量代码来解决这个错误,但一般的修复方法是识别假设数组键存在的情况,并用一些代码修复它。

错误告诉你从哪里开始:

Notice: Undefined index: force-download in /Users/mathew/Websites/mamp/portal-test/wp-content/plugins/customer-area/src/php/core-addons/private-file/private-file-addon.class.php on line 1029

根据索引名称,force-download 我猜这是 HTML 表单上复选框的值。未选中时,不会通过 HTTP POST 传递任何值,但脚本正在 $_POST 中查找此值(此处猜测)。

我能给出的最好建议是用类似以下的方法修复此实例:

<?PHP

if( array_key_exists( 'force-download', $_POST ) && $_POST['force-download'] )
{
    // do something
}

?>

我为表格所做的工作:

为了始终具有 $_POST 值,我在复选框字段 之前输出了一个值为零的隐藏表单字段。然后复选框字段的值为 1。这样,如果选中复选框字段,则通过 $_POST 传递“1”,而我的 if 语句就可以正常工作,而不必总是不断地检查空,array_key_exists,等等