WordPress.org

Ready to get started?Download WordPress

Forums

Need help replacing allow_url_fopen with cURL in a plugin. (4 posts)

  1. SavoryMedia
    Member
    Posted 8 years ago #

    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

  2. Cypher
    Member
    Posted 8 years ago #

    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

  3. SavoryMedia
    Member
    Posted 8 years ago #

    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

  4. Cypher
    Member
    Posted 8 years ago #

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

    Regards

Topic Closed

This topic has been closed to new replies.

About this Topic