file_get_contents Not allowed in Themes?

I’m using file_get_contents in a theme development (in a widget of the theme). However the theme check plugin gives me following warning:

WARNING: file_get_contents was found in the file file.php possible file operations.

Line 49: $data = file_get_contents ( 'http://example.com');
Line 62: $count= file_get_contents ( $cfile );

My question is that if it is not allowed in the themes, is there any alternative for this function which can be used?
Thanks.

Related posts

Leave a Reply

1 comment

  1. Line 49: $data = file_get_contents ( 'http://example.com');

    Don’t use file_get_contents to download web page. WordPress has HTTP API for such needs. In your case, I would suggest you to use wp_remote_get( 'http://example.com' ); function instead of file_get_contents.

    Further reading:

    1. WordPress HTTP API
    2. wp_remote_get function.