Remote Content Shortcode

Note: This plugin is now part of the WordPress Plugin Repository as Remote Content Shortcode.

The Remote Content Shortcode plugin will enable a shortcode to display remote content embedded into a post or page. In fact, it is being used to embed the code below from my SVN server. To use it, just place the code in your page where you want to remote content to be placed.

[remote_content url="http://www.example.com"/]

By default this will just fetch the content and drop it straight into the page, which isn’t always ideal (like when you are using a code formatter like I am). Because of this, there are a few more parameters you can pass to Remote Content Shortcode:

  • url – the url that you want to request.
  • method=[ GET | POST ] – set the request type, defaults to GET.
  • timeout=[ 0-9... ] – set the request timeout in seconds, defaults to 10 seconds.
  • userpwd=[ username:password | post_meta | site_option | constant ] – the username and password to send for BASIC authentication. It is recommended to not set the username and password directly in the tag, as it will be visible on your site if this plugin is disabled, and instead use one of the other options. By order of priority, if the value matches a post meta_key the meta_value is used, if it matches a site_option the option_value is used, and if it matches a constant the constant value is used, otherwise the data is passed as is. The format is username:password.
  • htmlentities=[ false | true ] – if you want to HTML encode the content for display set to true, defaults to false.
  • strip_tags=[ false | true ] – remove all tags from the remote content (after CSS selection).
  • decode_atts=[ false | true ] – the SyntaxHighlighter plugin will HTML encode your shortcode attributes, so attr="blah" becomes attr="blah". This fixes it to the intended value when set to true, defaults to false.
  • selector=[ CSS Selectors... ] – the CSS selector or comma separated list or selectors for the content you would like to display, for example div.main-content or div.this-class #this-id, defaults to the entire document.
  • remove=[ CSS Selectors... ] – the CSS selector or comma separated list or selectors for the content that you would like to remove from the content, for example h2.this-class or div#this-id, defaults to no replacement.
  • find=[ regex ] – use a PHP regular expression to find content and replace it based on the replaceattribute, for example ~http://([^\.]*?)\.example\.com~, defaults to disabled.
  • replace=[ regex ] – the replacement text to use with the results of the find regular expression, for example https://\\1.new-domain.com, defaults to empty string replacement.
  • cache=[true| false ] – set to false to prevent the contents from being cached in the WP-Cache/WordPress transients, defaults to true for performance.
  • cache_ttl=[ 0-9... 3600 ] – the cache expiration in seconds or 0 for as long as possible, defaults to 3600 seconds.
If you specify any content for Remote Content Shortcode, it will be sent to the remote server as the request data.
[remote_content url="http://www.example.com" method="POST"]
{ json: { example: request } }
[/remote_content]

This source files for Remote Content Shortcode are always up to date based on the trunk of the WordPress Plugin SVN repository.

remote-content-shortcode.php

<html>
<head><title>403 Forbidden</title></head>
<body>
<center><h1>403 Forbidden</h1></center>
<hr><center>nginx</center>
</body>
</html>

You may also like...

3 Responses

  1. Alf says:

    Great plugin! Is ti possibile to get HTML which is loaded by Javascript as well?

    • Justin Silver says:

      The content is loaded by curl and parsed by PHP so unfortunately there is no Javascript engine to load any additional HTML.

  2. Mike iLL says:

    This is really sweet, man. I like the code formatting. Great plugin and great post.

Leave a Reply

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