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/" start='<div class="entry-meta"' stop='!-- .entry-meta --' length="-1"].
and this is what you get:

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

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.