【问题标题】:Wordpress Custom Import Plugin Not workingWordPress 自定义导入插件不起作用
【发布时间】:2016-11-23 10:11:45
【问题描述】:

我有一个运行良好的 wordpress 自定义导入插件,但由于某种原因,它在新的 wordpress 安装 Dropbox link 中无法运行。插件查找两个提要文件 barneys_feed.txt 和 barneyswarehouse_feed.txt(包含在插件中),应在插件设置页面 Detailed Description 中进行配置。激活时,必须创建自定义表,但不创建,并且在产品运行时,日志中会显示以下内容:

[Tue Nov 22 18:28:08.931419 2016] [:error] [pid 11484] [client 38.140.212.19:64906] PHP Catchable fatal error:  Argument 1 passed to sjr\\product_import\\SJR_Product_Import::get_line() must be an instance of SplFileObject, null given, called in /nas/content/live/testwindow/wp-content/plugins/sjr-product-import/includes/class-sjr-product-import.php on line 334 and defined in /nas/content/live/testwindow/wp-content/plugins/sjr-product-import/includes/class-sjr-product-import.php on line 372, referer: http://testwindow.wpengine.com/wp-admin/options-general.php?page=sjr_product_import_settings 

无法联系插件开发人员。请帮忙。谢谢。

更新: 以下是我现在遇到的错误。

 PHP Fatal error: Uncaught TypeError: Argument 1 passed to sjr\\product_import\\SJR_Product_Import::get_line() must be an instance of SplFileObject, null given, called in /nas/content/live/testwindow/wp-content/plugins/sjr-product-import/includes/class-sjr-product-import.php on line 334 and defined in /nas/content/live/testwindow/wp-content/plugins/sjr-product-import/includes/class-sjr-product-import.php:372\nStack trace:\n#0 /nas/content/live/testwindow/wp-content/plugins/sjr-product-import/includes/class-sjr-product-import.php(334): sjr\\product_import\\SJR_Product_Import->get_line(NULL, 1)\n#1 [internal function]: sjr\\product_import\\SJR_Product_Import->csv_to_database()\n#2 /nas/content/live/testwindow/wp-includes/plugin.php(600): call_user_func_array(Array, Array)\n#3 /nas/content/live/testwindow/wp-cron.php(117): do_action_ref_array('sjr_product_imp...', Array)\n#4 {main}\n thrown in /nas/content/live/testwindow/wp-content/plugins/sjr-product-import/includes/class-sjr-product-import.php on line 372, referer: http://testwindow.wpengine.com/wp-cron.php?doing_wp_cron=1480412579.4279830455780029296875

【问题讨论】:

  • 到目前为止,您采取了哪些步骤来尝试自己解决此问题?
  • 尝试进入插件设置并检查导入文件1的服务器路径导入文件2的服务器路径路径;即使您看到填充了值的文本框,也请点击保存设置。还要检查这些文件路径是否存在于路径中,并且您的 WP 应用可以访问它们。

标签: php wordpress import


【解决方案1】:

我发现有助于调试此类问题的方法是查看错误所在的堆栈跟踪。您可以在调用get_line 的每个位置打印每个debug_backtrace() 的堆栈跟踪,以查看调用失败时堆栈上的内容。

我目前没有您的项目,但看起来您的 $file 对象不再在此调用 get_line 的范围内(因此为空)

foreach( $lines as $line_item ){
    if( $file_name != $line_item['file'] ){
        $file_name = $line_item['file'];
        $basename = basename( $file_name );

        // get columns
        $file = new \SplFileObject( $file_name, 'r' );
        $file->setFlags( \SplFileObject::READ_CSV );
        $file->setCsvControl( "\t", " " );

        // get first row with column names
        $first_row = $this->get_line( $file, 0 );
    } // You lose scope on $file here

    $row = $this->get_line( $file, $line_item['line_number'] - 1 ); // <-- This one is the likely cause

你应该在这里做两件事:

  1. 在 if 语句之前定义 $file(可能是$file = null
  2. 处理在 if 语句之后和问题 get_line 调用之前仍然有空 $file 对象的情况。

【讨论】:

    【解决方案2】:

    错误消息告诉您,在某些时候,sjr\product_import\SJR_Product_Importget_line 函数将获得 SplFileObject 的实例而不是 null

    我猜get_line 函数看起来像这样:
    public function get_line(SplFileObject $file) { /* do some stuff */ }

    您可以做的(假设您自己编写了该代码)是将函数更改为如下所示: public function get_line(SplFileObject $file=null) { /* do some stuff */ }

    告诉 PHP 除了对象之外,您还接受 null 作为默认值。在这种情况下,您必须更新您的函数,以检查给定变量是否为空。例如,您可以使用

    进行检查

    if (!is_null($file)) { /* every thing is fine */ } else { /* there was an error, maybe write it to a error log */ }

    我完全猜测,正如错误所述,该位置包含 /nas/ 我假设 PHP 代码在 NAS 上运行并且映射了一些驱动器,您尝试从中导入一些东西定期,因为导入是由 cron 作业启动的。也许其中一个映射驱动器以某种方式丢失了连接,因此 PHP 无法读取文件。但正如我所说,这只是一个疯狂的猜测。要“调试”它,您可以在运行 cron 作业时手动检查映射驱动器的状态,看看问题是否仍然存在。另一件事可能是,PHP(或更准确地说,Apache 或 Nginx)无权访问这些文件/共享。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-06-18
      • 2015-01-29
      • 1970-01-01
      • 2014-02-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-11-08
      相关资源
      最近更新 更多