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.

Pages: [5] 4 3 2 1 » Show All

  1. Thank you very much for plugin..

  2. Hi I have been using this plugin for awhile now. I love it and it adds some nice features to my site. However recently it stopped working perhaps with one of the WP updates. Now it only shows the first character of the text file its trying to read. Here is a link to a page. http://ofchant.com/wp/?page_id=68
    All you can see is “STaTus: ??C”
    Any help would be great! Thanks!

  3. More fields are recognized and It is to be useful in work

  4. 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.

Pages: [5] 4 3 2 1 » Show All

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.