Hey guys,
I have been working on a wordpress theme for a couple of months, that I am planning to release in a week (hopefully). I have been running my theme through the theme check plugin and I see warnings for using PHP file functions (get and put) and cURL (which i use for my twitter widget).
How seriously are they issues considered by the theme reviewers, because I think cURL is good way to access remote servers and I have to use file ops to generate my dynamic CSS . Using the WP Filesystem would make it really convoluted at this point in time. I could use the HTTP API ’s as an alternative to cURL, but WP Filesystem is sure to complicate my work.
I would like have some advise passed on by experienced theme developers and the staff here at themeforest. I have an item in the mojo themes marketplace that has been quite successful and these warnings were ignored.- Microlancer Beta Tester
- Author had a Free File of the Month
- Has been a member for 3-4 years
- Item was Featured
- Author was Featured
- Austria
- Exclusive Author
- Referred between 200 and 499 users
Always use WordPress core function if they are avaiable!
In your case: wp_remote_get()
Thanks I will change that function. But what about file_put_contents(). The themecheck plugin throws warnings for the use of this function ?
file_put_contents() might not work for your customers it depends on their hosting configuration. if you really want to store your data in a file you have to use the Filesystem API which is more complex but recommended by wordpress. or you can use the Transients API which is more reliable in this case.
- Microlancer Beta Tester
- Author had a Free File of the Month
- Has been a member for 3-4 years
- Item was Featured
- Author was Featured
- Austria
- Exclusive Author
- Referred between 200 and 499 users
+1
Use the Transients API for dynamic styles and cache them. Here’s the function I’m using in my plugin:function form_css() {
header( 'Content-Type: text/css' );
header( 'Expires: Thu, 31 Dec 2050 23:59:59 GMT' );
header( 'Pragma: cache' );
if ( false === ( $css = get_transient( 'mymail_form_css' ) ) ) {
// generate your CSS here
set_transient( 'mymail_form_css', $css );
}
echo $css;
die();
}
add two action hooks:
add_action('wp_ajax_my_css', 'form_css');
add_action('wp_ajax_nopriv_my_css', 'form_css');
and enqueue the style:
wp_register_style('my-css', admin_url('admin-ajax.php?action=my_css'));
wp_enqueue_style('my-css');
@revaxarts ,
WOW Thank you so much, worked like a charm 
revaxarts saidfor some strange reason, on free hosting sites this gets you redirected (to their landing/404 page)
Always use WordPress core function if they are avaiable! In your case:wp_remote_get()
Btw, I have some issues with both cURL and file_get_contents(). After updating the file it should read it reads nothing for like 15 minutes. It doesn’t return NULL nor FALSE , just pretends it’s an empty file. I suppose it’s something with the buffer/server session but can’t find a solution.
- Microlancer Beta Tester
- Author had a Free File of the Month
- Has been a member for 3-4 years
- Item was Featured
- Author was Featured
- Austria
- Exclusive Author
- Referred between 200 and 499 users
brandexponents said
@revaxarts , WOW Thank you so much, worked like a charm![]()
Seems like this version doesn’t work on IE9 (works on IE7 +8). I’m searching for a solution to this
What doesn’t work in ie9?
- Microlancer Beta Tester
- Author had a Free File of the Month
- Has been a member for 3-4 years
- Item was Featured
- Author was Featured
- Austria
- Exclusive Author
- Referred between 200 and 499 users
I don’t know why but IE9 always tries to download the file if Content-type = text/css. With text/html I can view it in the browser but the styles doesn’t get applied to the page
