Search code examples
wordpresspaypal-ipn

How can you read php input stream with Wordpress filesystem methods?


I have to rewrite a piece of code on a WordPress theme that handles Paypal payments. The theme is to be published on themeforest.net, so it needs to be checked with Theme Check plugin .

On the file that handle the IPN from Paypal i have this code

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

and i receive this error

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

My question is : How can i read the input stream with Wordpress methods ? I tried wp_remote_get('php://input') but obviously it does not work.

Thank you


Solution

  • I found this solution. It seems to work fine and pass the theme check plugin.

    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');