class-connect-helper.php
1 year ago
class-core.php
11 months ago
class-database.php
11 months ago
class-google-api-new.php
1 year ago
class-google-api-old.php
11 months ago
class-google-connect.php
11 months ago
class-google-dao.php
11 months ago
class-google-utils.php
1 year ago
class-connect-helper.php
28 lines
| 1 | <?php |
| 2 | |
| 3 | namespace WP_Rplg_Google_Reviews\Includes\Core; |
| 4 | |
| 5 | class Connect_Helper { |
| 6 | |
| 7 | public function upload_image($url, $name) { |
| 8 | $res = wp_remote_get($url, array('timeout' => 8)); |
| 9 | |
| 10 | if(is_wp_error($res)) { |
| 11 | // LOG |
| 12 | return null; |
| 13 | } |
| 14 | |
| 15 | $bits = wp_remote_retrieve_body($res); |
| 16 | $filename = $name . '.jpg'; |
| 17 | |
| 18 | $upload_dir = wp_upload_dir(); |
| 19 | $full_filepath = $upload_dir['path'] . '/' . $filename; |
| 20 | if (file_exists($full_filepath)) { |
| 21 | wp_delete_file($full_filepath); |
| 22 | } |
| 23 | |
| 24 | $upload = wp_upload_bits($filename, null, $bits); |
| 25 | return $upload['url']; |
| 26 | } |
| 27 | |
| 28 | } |