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( ! isset( $fb->likes ) && isset( $fb->shares ) )
        {
            $fb->likes = $fb->shares;
        }

        if( isset( $fb->likes ) )
        {
            $myfblikes = sprintf( '%04s', (int) $fb->likes );
            update_post_meta( $post->ID, 'fb_likes', $myfblikes );
       }
    }
}

where we can use wp_remote_retrieve_body() to get the response body of wp_remote_get().

Leave a Comment

deneme bonusudeneme bonusu veren sitelerpulibet girişOnwin Güncel Giriştürkçe altyazılı pornocanlı bahis casino