WordPress.org

Support

Support » How-To and Troubleshooting » Need help replacing allow_url_fopen with cURL in a plugin.

Need help replacing allow_url_fopen with cURL in a plugin.

  • SavoryMedia
    Member

    @savorymedia

    I have a plugin that uses allow_url_fopen, but my host (Dreamhost) has disabled allow_url_fopen but allows cURL.

    I think I’ve isolated the problematic code:

    $content = @file_get_contents($this->url);
    if(!$content) {
    echo "<!-- BDPFeed could not open ".$this->url." -->n";
    return FALSE;
    }

    What I need to know is how to go about replacing the @file_get_contents function with its cURL equivalent.

    Anyone have any ideas? (I’m *not* a hardcore coder.)

    Thanks in advance,
    MJ

    PS: If anyone is interested, the plugin I’m trying to hack is BDP RSS Aggregator v 0.2.2 and the file the above code is from is bdp-rssfeed.php

Viewing 3 replies - 1 through 3 (of 3 total)
  • You would change that code to something like this:
    $curl_handle = curl_init($this->url);
    curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT,10);
    curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1);
    $content = "";
    $content = curl_exec($curl_handle);
    curl_close($curl_handle);

    Regards

    SavoryMedia
    Member

    @savorymedia

    Cypher,

    You f’n RULE! I just replaced that first line of code with the cURL code you posted and bingo!…it works like a charm.

    I’m going to send this code to the plugin developer and credit you. Good work!

    And THANK YOU *SO* much. You just saved my bacon.

    MJ

    You’re welcome. This was pretty much the code changes I did for the WP Plugin Manager to make it cURL compliant. 🙂

    Regards

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Need help replacing allow_url_fopen with cURL in a plugin.’ is closed to new replies.