File tree Expand file tree Collapse file tree 1 file changed +8
-4
lines changed
Expand file tree Collapse file tree 1 file changed +8
-4
lines changed Original file line number Diff line number Diff line change @@ -65,8 +65,13 @@ function tootpress_create_mastodon_apiresponse_file($toot_array) {
6565
6666 function tootpress_retrieve_image_from_mastodon ($ image_url ) {
6767
68+ // If download function is not available, include it
69+ if ( ! function_exists ( 'download_url ' ) ) {
70+ require_once ABSPATH . 'wp-admin/includes/file.php ' ;
71+ }
72+
6873 // Retrive Image from Mastodon
69- $ image = file_get_contents ( $ image_url );
74+ $ tmp_image_file = download_url ( $ image_url );
7075
7176 // Create Storage Location URL
7277 $ image_file_name = tootpress_get_image_name ($ image_url );
@@ -77,9 +82,8 @@ function tootpress_retrieve_image_from_mastodon($image_url) {
7782 // Save File to TootPress Image Directory
7883 if (!file_exists ($ tootpress_image_wordpress_url ))
7984 {
80- $ fp = fopen ($ tootpress_image_wordpress_url , "w " );
81- fwrite ($ fp , $ image );
82- fclose ($ fp );
85+ copy ( $ tmp_image_file , $ tootpress_image_wordpress_url );
86+ @unlink ( $ tmp_image_file );
8387 }
8488 } else {
8589 return false ;
You can’t perform that action at this time.
0 commit comments