【问题标题】:How can you read php input stream with Wordpress filesystem methods?如何使用 Wordpress 文件系统方法读取 php 输入流?
【发布时间】:2023-03-16 01:10:02
【问题描述】:

我必须在处理 Paypal 付款的 WordPress 主题上重写一段代码。主题要发布在themeforest.net上,所以需要通过主题检查插件进行检查。

在处理来自 Paypal 的 IPN 的文件中,我有这个代码

$raw_post_data  = file_get_contents('php://input');

我收到此错误

"file_get_contents was found in the file xxx File operations should use the WP_Filesystem methods instead of direct PHP filesystem calls."

我的问题是: 如何使用 Wordpress 方法读取输入流?我试过 wp_remote_get('php://input') 但显然它不起作用。

谢谢

【问题讨论】:

    标签: wordpress paypal-ipn


    【解决方案1】:

    我找到了这个解决方案。它似乎工作正常并通过了主题检查插件。

    global $wp_filesystem;
    if (empty($wp_filesystem)) {
                require_once (ABSPATH . '/wp-admin/includes/file.php');
                WP_Filesystem();
            }
    
    //$raw_post_data  = file_get_contents('php://input');
    $raw_post_data =  $wp_filesystem->get_contents('php://input');
    

    【讨论】:

      猜你喜欢
      • 2015-06-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-24
      • 1970-01-01
      • 2018-11-07
      • 2012-02-06
      相关资源
      最近更新 更多