xmouse

grabcode documentation

Well, it looks like my code-snippet plugin (which I’m calling ‘grabcode’, by the way) is gaining some popularity. So I thought it was really time to start documenting it.

Installation

  1. Download the plugin in a text file
  2. Move this file to your WordPress plugins folder (normally /wp-content/plugins/)
  3. Get rid of the .txt extension
  4. Go into your WordPress admin section (log in), go to Plugins, and activate ‘grabcode’.

Usage

When you want to include a code-snippet in one of your weblog entries, there are several things you need to do:

  1. Create a text file with the code snippet in, and upload it to a folder called ‘code-snippets’ in the wp-content folder of your WordPress installation. Each code snippet you create needs to have a unique filename. I advocate the notation of ‘sanitized-post-name-1.txt‘ where ’sanitized-post-name’ is the sanitized post name (the value stored in post_name for each entry; the post slug) and ‘1′ is the number of this snippet in that particular post (ie: the first snippet to be used in sanitized-post-name would be ’sanitized-post-name-1.txt’, the second ’sanitized-post-name-2.txt’ etc.)
  2. Insert a little bit of XML into your post, in this format: <code-snippet src="sanitized-post-name-1" />. The value in src needs to be the identifier of the code-snippet file, minus the .txt extension. The code in that file will then be pulled and displayed on the fly by the plugin.

Other Notes

  • As this post pulls these snippets on the fly, this plugin will not work if you have Staticize running.

Updates

  1. Revision 1.01: Now with a config section, you are not limited to .txt extensions and a folder called /code-snippets/. If you wish to change these, change the values on line 12 and 13 in version 1.01.
  2. Revision 1.02: changed default code snippets directory to /wp-content/code-snippets
  3. Revision 1.03: basic error reporting now implemented; function will not grind to a halt if one file can’t be opened — it carries on and looks for further matches.