Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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.

share|improve this question

1 Answer 1

up vote 3 down vote accepted

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.
share|improve this answer
    
Thanks. I don't have any issue with PHP. I'm just checking my theme with the theme checker plugin, and that gives me this warning, which means WP does not recommend using this function in the theme development. But I'll check wp_remote_get as you suggested. –  casper Jun 15 '12 at 10:02
    
@eugene What if I want to read a file that is being uploaded, wp_remote_get need a valid url, I only want to check the uploaded file, but using file_get_contents won't pass the theme check –  nackle Mar 26 '13 at 13:02
    
@nackle read about Filesystem API codex.wordpress.org/Filesystem_API –  Eugene Manuilov Mar 26 '13 at 13:19

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.