Welcome to Dagon Design. In addition to free scripts, WordPress plugins, and articles, we offer a variety of services including custom theme design, plugin creation, and PHP scripting. Contact me for more information.

Version 1.0   Updated Sunday, February 22nd, 2009 at 5:17pm

Retrieve Data Plugin for WordPress

This plugin provides a simple way to include the contents of data files into your posts or pages. The data files can be local to your server, or on remote servers (if your PHP configuration allows it). In the options page for the plugin, just define the trigger text and the file the data will be retrieved from. When that trigger text appears in a post or page, the contents of the specified data file will be shown.

Download

  If you have found this page useful, please consider donating. Thanks!

Installation

  • Download the above file, rename it from .txt to .php, and upload it to your plugins directory
  • Enable the plugin
  • Configure the plugin under the DDRetrieveData options page

Requirements

This plugin uses the file_get_contents function in PHP. While this function supports the reading of files on remote servers, the allow_url_fopen option must be enabled in PHP. Additionally, firewall software on the server may block remote access.

Change Log

  • 12-27-08 Version 1.0 – First release.

Usage Notes

From the plugin’s options page (DDRetrieveData), simply enter the trigger text and the path to the data file for each set of data you would like to use. If you need more fields, just click ‘Update Options’ to save your changes, and more fields will appear. There is no limit to how many fields you can have.

If using a local file, the path is relative to the WordPress installation directory. Examples:

file.txt
path/to/data/file.txt

If using a remote file, be sure to include the full path. Examples:

http://example.com/file.txt
ftp://example.com/file.txt
ftp://user:pass@example.com/file.txt

The default options show an example of each type. Just clear them out to use your own.

The trigger text can be anything you like. The default options show the trigger text being wrapped inside html comment tags. This is optional, but it prevents the trigger text from being shown if the plugin is disabled (as it will just be treated as a comment).

Note: Make sure you add this to your posts/pages using the html/code editor in WordPress, not the visual editor. In new versions of WordPress, just click the ‘html’ button above the edit box. If you use the visual editor it will not work, as the actual code you entered will be seen on the page, instead of being processed by the script.

Data Output

Currently the output of the data is rather simple. It can be seen in this function:

function ddrd_fetch_data($url) {
  return htmlspecialchars(file_get_contents($url));
}

As you can see, the htmlspecialchars function is used to force the data to show up exactly like it does in the file. If you would rather have html processed, remove that function. If you want to modify the way that the script retrives data (to use CURL for example), this is the function you need to change. The function is given the $url parameter, and returns the contents of the file.

Possible Future Updates

Currently there is no local caching of remote files. This may be added in the future. Other options may be added as well.

  1. Dear Admin

    I have got the plugin working for one trigger item, however when I try to update the 2nd trigger with a path and save it clears the field back to blank?

    I am running WordPress 2.8.5

  2. I must compliment you for providing remarkable stuff for the readers which has made our life easier and has helped us to march ahead in providing Stock Tips in India which rock every day and these plugins works perfectly and must commend the same for a great tutorial. It has been of a great help to me.
    Regards
    Analyst
    Indian-share-tips.com

  3. 7
    bharti

    after i receive “Configuration Updated!” message in the options page… how do i retrieve the data in my post/ page.

  4. This plugin has been tested, and works, in the latest release of WordPress – 2.9

    sergiu: Newlines will not automatically get converted to HTML line breaks. You can use the PHP function nl2br to do this.

    Just apply that function _after_ you run htmlspecialchars (or it will render the breaks useless. Try changing the line to this:

    return nl2br(htmlspecialchars(file_get_contents($url)));

    alexander: I do not currently have a demo of this plugin on the site.

  5. Works perfectly, great tutorial. Much help.Where can I see the demo?

  6. 4
    sergiu

    Hi,

    thanks for this plugin. It fits my needs, but I have a problem: I cannot make it to read correctly the “end of line” character. My text file has several lines, but the plugin is wrapping it all in one line.

    Is there a way to fix this?

  7. This plugin has been tested in the latest release of WordPress (2.7.1)

    As for examples, it could be used for just about anything. Any situation where you want to grab data from an online data file, and display the output on your site.

  8. This sounds great, I have just reviewed a similar project that is installed localy not server side, would be great to have one of your plugins to show what you can do for free. Would be nice to see some examples aswell, as previously stated by the previous poster. I used to use your SecureFormMailer for sometime and would like to give back some love. ATB George

  9. Could u plz show some examples how can this plugin be used in what ways?

Leave a Comment

Before you comment: If you are having an issue with a script, please make sure you have read the entire article. Also, please read through the comments because most common issues have already been discussed many times. Thanks.


Be sure to wrap all code in <code></code> tags.