My new Plugin for making cURL calls

I created this plugin that uses a shortcode to call wp_remote_get with parameters you pass to parsed and display a bit of HTML from a page on another site. You can include this shortcode in your page or post.

Here is an example of the shortcode that will display the Download Stats page for this Plugin on WordPress.org:
[remote_get url="https://wordpress.org/plugins/shortcurl/stats/" start='<div class="block-content"' stop='!-- block-content--' length="-1"].
and this is what you get:
EZ SHORTCURL Shortcodes to Fetch and Parse External Content — WordPress Plugins

EZ SHORTCURL Shortcodes to Fetch and Parse External Content

Description

Use the shortcode “remote_get” with the parameter “url” to insert the content from that url into your page or post. You can also use parameters like start and stop (or end) to parse out a specific part of the content that you wish to display.

Now you can also wrap any content in the “preg_replace” shortcode to manipulate it into the desired format. Tricky stuff, but very powerful, if you know what you’re doing.

Updated August-3rd

Installation

  1. Download and unzip the plugin into your WordPress plugins directory (usually /wp-content/plugins/).
  2. Activate the plugin through the ‘Plugins’ menu in your WordPress Admin.

FAQ

What do I do after I activate the Plugin?

Use the shorcode remote_get with a url parameter on a page or post to bring in external content.

What does a example of the shortcode look like?

[remote_get url=”https://wordpress.org/plugins/shortcurl/stats/” start='<div class=”block-content”‘ stop=’!– block-content–‘ length=”-1″ replace=”=’/extend” with=”=’https://wordpress.org/extend” replace2=”%2Fextend%2F” with2=”http%3A%2F%2Fwordpress.org%2Fextend%2F”]

Reviews

Read all 3 reviews

Contributors & Developers

“EZ SHORTCURL Shortcodes to Fetch and Parse External Content” is open source software. The following people have contributed to this plugin.

Contributors

Changelog

3.16.29

  • Added a Shortcode Widget with pop-out position options.

3.14.34

  • Replaced the SESSION code with the use of GLOBALS for broader compatibilty.

3.14.53

  • Fixed the “with” parameter in to remote_get function to accempt empty string.
  • Decoded HTML Entities in the URL parameter to improve the handling of GET variables in the URL String.
  • Improved the error messages by adding what URL triggered the error.

3.04.26

  • Added a shortcode for str_replace simple string manipulation.
  • Added support for arrays in preg_replace shortcode.
  • Added an alternate shortcode for running preg_replace on another shortcode vs. on the results of another shortcode.

1.3.03.25

  • Added a shortcode for preg_replace to further manipulate content.

1.3.03.15

  • Fixed error handling on line 71 to report the whole curl error on the admin pages.

1.2.12.06

  • Fixed call to plugin_row_meta.

1.2.12.05

  • Added 24 hour caching to speed up page loads.
  • Added admin_notices if fatching or parsing produces any errors.

1.2.12.01

  • First versions uploaded to WordPress.

26 thoughts on “My new Plugin for making cURL calls

  1. Since there seems to be no simple solution to resizing an iframe, your plugin/shortcode might work, except I have no idea how.

    I’m trying to just grab a webpage http://dmiworks.com/announce.html and insert it into a WordPress page. It seems it will size the page according to the content. Nevertheless, I am lost. Am I barking up the wrong tree? Thanks

    • I just did a llittle testing on that URL you gave and here is what I found…

      This is simple and it works but it may no look great on your site depending on you CSS:
      [remote_get url="http://dmiworks.com/announce.html"]

      Then I tried this to bring in the images and cut out the header:
      [remote_get url="http://dmiworks.com/announce.html" start='<div ' stop='</body>' replace='src="' with='src="http://dmiworks.com/']

      Then I used this to bring in the CSS styles:
      [remote_get url="http://dmiworks.com/announce.html" start='<style ' stop='</body>' replace='src="' with='src="http://dmiworks.com/' replace2='href="' with2='href="http://dmiworks.com/']

      I have to say this is a difficult page to bring into another site because of all the positioning styles.

      Good luck!

  2. Oops, one thing I keep forgetting is that the “preview” doesn’t always match up to the “saved” version in WordPress. Once I saved it, I got an error:

    Fatal error: Cannot use object of type WP_Error as array in /home/schecter/public_html/nickyscorner/wp-content/plugins/shortcurl/index.php on line 71

    • This is a bug in error handling. It was easy to fix though. You can fix it using the plugin editor built into WordPress.
      Just change:
      print_r($got['url'], true)
      to:
      print_r($got, true)
      toward the end of line 71.

  3. Hey there, your plugin looks like something I exactly was looking for. But I have some questions:
    – is there any possibility to specify, that content of external page is in another charset (windows-1250 f.e.) and convert it into utf-8?
    – Caching idea is great, but is there any chance to disable content caching or change the caching period (maybe by some parameter)? Because when Im trying debug blog post or page where I have shortcurl, it holds first version of content I have inserted.
    Thanks anyway for your plugin! s.

    • I’m not really sure how you you could change the character encoding, but changing the cache timeout setting is a great idea. I released an update to this plugin that allows you to pass an “expire” paramater to the remote_get shortcode. It will still default to 24 hours (60*60*24), but if you pass it a “1” (meaning 1 second) then you will not get the cached results.

      Please let me know how this works for you.

      Aloha, Eli

      • Thanks for your time and reply! I dont understand it. It is still caching, but now I’m not sure it is issue of your plugin. Im trying to embed a part of page which is dynamically generated by date parameter in url into post (or page) on my site. Cache directory in Shortcurl plugin’s directory is empty. I have no cache plugin installed in my WordPress. But anyway, if I change this date parameter in url used in shortcode (to embed content from another day) it still holds content, like I never change anything. Doesn’t matter if I’m updating page (or post) or create new one. When I paste this changed url right into browser’s adress bar, I can see exactly what I expect – content from day specified in date parameter. As I said, Im confused. Expire parameter in shortcode unfortunately doesn’t help in my case. s.

          • I have found another source which im processing on temp page (by PHP Simple HTML DOM Parser, because html code of this source is really poor and I want my WP blog valid). And your CURL plugin helps mi insert content from this temp page into my wordpress blog (with no caching issue). So everything now works right for me. Thanks.

          • That’s great. I could not get that other page to load right either, but I could get other dynamic pages to load. I must admit I had a hard time testing that content becuase I couldn’t read the language that the content was in. I don’t think it was a caching issue anyway but I’m glad you got it working another way.

  4. Hi Eli, this plugin does what I need, GREAT, however can’t get it to work on multisite. I’m not a coder but hope it will be easy to resolve. THX

    • Thanks, and sorry it’s not working for you on multisite. If you want to send me a WP Admin login I can troubleshoot the problem and find a fix for it.

      (Comments with private info will not be published on my site)

  5. Hi Eli, figured it out, your plugin does not go well with Shortcodes Ultimate. Without this plugin yours worked fine on multisite. KR

    • I’m not sure exactly what you want but here is an example that may be close to what you need:
      [remote_get url="http://www.corendon.nl/titanic-beach-resort/antalya/turkije/hotel" start='<div class="accoLowestPrice"' stop='<div class="tripsListing"']

      • Thanks Eli! You helped me a lot.

        Can you see away to only get thwe pricing? See http://www.hoteltitanic.be/

        I tried the following [button]vanaf [remote_get url="http://www.corendon.be/titanic-beach-resort/antalya/turkije/hotel" start='<div class="acco_price pricerange" ' stop='</span'][/button]

        The problem is there is some sort of a break I can’t get rid of.

        • Try wrapping the remote_get shortcode in my preg_replace shortcode to get rid of all the tags. So your whole button shortcode call would look somthing like this:

          [button]vanaf [preg_replace replace='/< .*?>/' with=''][remote_get url=”http://www.corendon.be/titanic-beach-resort/antalya/turkije/hotel” start=’

  6. Hi Eli, really excited by your plugin – someone suggested it to me a while back but I have not had a chance to experiment with it till today.

    Thank you for replying to previous comments – it made it easier for me to build my first curl query that also brought in styles/images.

    On the test page I am experimenting with, the content in the table can be sorted using a select script – http://pastebin.com/GKaP2bce – so I thought it would be possible to replace ‘/cgi/’ with the full url of the source and the cgi folder. But it hasn’t worked – thus far, so was wondering if this was feasible and if so, what might be the best way of approaching it?

    Many thanks in advance

    • Sorry – just to say that I was using replace3/with3 to do the search; using replace2/with2 seems to work fine for the actual replacement. Is there any chance replace3/4/5 may become available in future?

      Sadly the script actually loads the source page (rather than being in-situ on the site) so it looks as though I might need to investigate further about other options. Your advice would be very much welcomed :)

      Thanks again

      • The remote_get shortcode only has replace/with and replace2/with2 to execute str_replace on the returned content. However, I think you might find my preg_replace shortcode in this same plugin to be exactly what you are looking for. Just wrap your remote_get call inside the preg_replace shortcode like this:
        [preg_replace replace='/regex/' with='text'][remote_get url='http://pastebin.com/GKaP2bce'][/preg_replace]

        You can use as many replaceX/withY pairs in the preg_replace shortcode as you can keep track of. One difference in the preg_replace shortcode though is that the replace attributes are REGEX not strings, so you should use one of the following to look for this path that contains slashes:
        replace=’/\/cgi\//’
        replace=’#/cgi/#’
        or if you want to replace the single quote too:
        replace=”#’/cgi/#'” with=”‘http://pastebin.com/cgi/”

        Hope that helps. Let me know how that works for you.

  7. Hi Eli,

    Found your script the other day and it’s proven to be a huge asset. I do have a question though.

    I’m attempting to grab data from a website which forces you to view an advertisement for 15 seconds or click on a “continue to site” button.

    When I do any query for data from the site, the advertisement page loads and after the countdown finishes it just refreshes the webpage and the advertisement starts over.

    The website is http://www.mlgpro.com

    Is there any way to bypass this issue, or do I simply have to find another site to get the data from?

    Thanks a lot in advance.

    • That site look carefully crafted to be sure of displaying those add. What you want to do may be possible but it would take a log of experimentation and delicate engineering to get past all the adds to the content within. I would say it would be far easier if you could find another site to get this content from.

  8. Hello.

    I’m using this plugin on my blog. I have an issue here. When I visit my blog home, the plugin is not working on preview text before the “read more” tag on post. It only works on post view.

    What should I do?

    Thanks in advance!

    • I don’t know for sure but maybe your theme does not support shortcodes in the excerpts. Can you send me a link to the page where you are using the shortcode so I can see how it’s being implemented?

Leave a Reply to Dominic Cancel reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>