rewrite script to use wp_remote_get instead of file_get_contents_curl

You can try this: foreach( $posts as $post ) { $url = sprintf( ‘http://graph.facebook.com/?id=%s’, get_permalink( $post->ID ) ); $response = wp_remote_get( $url, array( ‘timeout’ => 15 ) ); if( ! is_wp_error( $response ) && isset( $response[‘response’][‘code’] ) && 200 === $response[‘response’][‘code’] ) { $body = wp_remote_retrieve_body( $response ); $fb = json_decode( $body ); if( ! … Read more

How to wp_upload_bits() to a sub-folder?

wp_upload_bits() uses wp_upload_dir() which fires the upload_dir filter allowing you to modify the upload directory’s path, sub-directory and URL. So you can use that filter to “force” wp_upload_bits() to use a custom path by doing something like: // Demo to get the image data. $url=”https://logo.clearbit.com/starcomww.com”; $content = file_get_contents( $url ); $_filter = true; // For … Read more

wp_remote_get(), downloading and saving files

Well here’s the solution that I came up with: // Use wp_remote_get to fetch the data $response = wp_remote_get($url); // Save the body part to a variable $zip = $data[‘body’]; // In the header info is the name of the XML or CVS file. I used preg_match to find it preg_match(“/.datafeed_([0-9]*)\../”, $response[‘headers’][‘content-disposition’], $match); // Create … Read more

using wp_remote_get instead of file_get_contents [duplicate]

If you need to send a JSON response, then there’s a set of functions for that. In case you need that for an AJAX callback: wp_remote_retrieve_response_message() wp_remote_retrieve_response_code() wp_send_json_success() wp_send_json_error() wp_send_json() Would finally be something like that: $request = wp_remote_get( ‘http://example.com’ ); $response = wp_remote_retrieve_body( $request ); if ( ‘OK’ !== wp_remote_retrieve_response_message( $response ) OR 200 … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)