{"id":12812358,"date":"2020-05-11T01:39:50","date_gmt":"2020-05-11T01:39:50","guid":{"rendered":"https:\/\/wordpress.org\/support\/topic\/image-sync\/"},"modified":"2020-05-11T01:40:06","modified_gmt":"2020-05-11T01:40:06","slug":"image-sync","status":"publish","type":"topic","link":"https:\/\/wordpress.org\/support\/topic\/image-sync\/","title":{"rendered":"Image Sync url_get_contents"},"content":{"rendered":"<p>Currently setting up Squareup for a client and noticed images don&#8217;t sync due to the allow_url_fopen requirement.  I haven&#8217;t seen this usage in code in years due to the exploitative capabilities of turning this on for php. Mosts hosts have this off by default.<\/p>\n<p>An alternative that works using curl but would be great to have it as standard.<\/p>\n<p>Function:<\/p>\n<pre><code>function url_get_contents ( $url ) {\n\n    if ( ! function_exists( &#039;curl_init&#039; ) ) {\n        die( &#039;The cURL library is not installed.&#039; );\n    }\n\n    $ch = curl_init();\n\n    curl_setopt( $ch, CURLOPT_URL, $url );\n    curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );\n\n    $output = curl_exec( $ch );\n\n    curl_close( $ch );\n\n    return $output;\n\n}<\/code><\/pre>\n<p>Usage:<\/p>\n<p>$remote_file_data = url_get_contents( $image_url );<\/p>\n","protected":false},"template":"","class_list":["post-12812358","topic","type-topic","status-publish","hentry","topic-tag-allow_url_fopen","topic-tag-curl","topic-tag-images"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/12812358","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic"}],"about":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/types\/topic"}],"version-history":[{"count":1,"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/12812358\/revisions"}],"predecessor-version":[{"id":12812360,"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/12812358\/revisions\/12812360"}],"wp:attachment":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/media?parent=12812358"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}