Insert an image into a WordPress Post with a plugin.

So in a project I’m working on I need to use a normal form to insert a post into the database. My client wanted the form to also add an image to the post. Furthermore, the image must be inserted using normal WordPress methods. The code below is the minimum required to insert an image into the database and attach it to a specific post.

include_once(ABSPATH.'/wp-admin/includes/media.php');
	include_once(ABSPATH.'/wp-admin/includes/file.php');
	include_once(ABSPATH.'/wp-admin/includes/image.php');
	
//	$id is the id of the post being inserted
//	$name is actually the name of the form input that uploaded the file so WP can access it using $_FILE[$name]
	media_handle_upload($name,$id);

If you are inserting a new post, it makes sense to have the line $id = wp_insert_post($post_data); before this.

WordPress Dashboard Editor

Of the entire website the Dashboard is seen by administrators the most, but it is the hardest part of WordPress to customize. Well not anymore. This plugin allows you to add whatever you want to the Dashboard through PHP and HTML and allows you to even add Sidebar Widgets. You may also wipe the entire dashboard or individually remove some of the more irritating sections like the Dev news, Planet WordPress and the getting started section.

In WordPress 2.5, the code is cleaner, the plugin is more responsive and you can add both “real” sidebar widgets, or add “fake” ones to match the dashboard.

This plugin is currently intended for 2.5, but it also works in WordPress 2.1 – 2.3 and can work in WordPress 2.0.x if you use the Completely Wipe Dashboard option.

Installation is a breeze:

  1. Download the zip file for WordPress Dashboard Editor
  2. Unzip and upload dashboard.php to your wp-content/plugins/ folder.
  3. Go to your dashboard. There will be a new sub-menu item.
  4. Select any options you want and add any PHP or HTML code that you want to the textbox.

Code Examples:

To add a sidebar widget to your dashboard (after selecting the option from the Dashboard management page) use the code:
<?php dynamic_sidebar('admin');?>
The Admin sidebar is modified and controlled the exact same way as any other sidebar.

If you use the WP-UserOnline plugin you can use:
<?php echo useronline_page();?>

In WordPress 2.1-2.3 f you find that your new content doesn’t align nicely you can add:

<div style="float:left; width:460px;">
//
//Add all other content here
//
</div>

Any code that can be used in your WordPress Theme can be used in the dashboard. This means that you can have different information appear for the different user roles among other things.

A friday in my newsreader: Febuary 22.

Occasionally, so many wonderful posts appear in the lull between the Thursday doldrums and the Friday excitation (pun much?) that I have to “link it up…er…mott”.

  1. It turns out that you can see the effects of trawling for fish from space. Do we need any more evidence against it?
  2. Uncertain Principles posts about the backlash from the Virginia Tech shootings: turns out stage plays with fake wooden weapons endanger students…according to some college administrators.
  3. Uncertain principles also wonders if there is any realistic nanotechnology in SciFi writing.
  4. That encrypted hard drive you might have? Worthless now that the encryption can be broken…easily.

Oh and as a side note, anyone else watch one of my favorite video blogs: http://tv.winelibrary.com/?

image credit: Pulpolux !!!

Tag Management for WordPress 2.3

Now that you have gotten used to WP 2.3 and had time to fiddle around with all those tags, you are probably finding that you need to edit, rename or delete tags. While I was going to write my own Plugins for this for a while, I found the perfect Plugins to do the work for me — and by perfect I mean really good, so I take no responsibility if they eat your dog.

The Simple Tags has been around for a long time, but now it works perfectly with WordPress tagging. What does it do? Most everything you could want (I could retype the list, but I’m going to borrow it straight from the Simple Tags website):

  • type-ahead input tags
  • auto suggestion of tags
  • tags management (rename, delete, amalgamate, search and add tags, edit tags ID)
  • List of non tagged contents
  • Edit mass tags
  • Possibility to tag pages (not only posts) and include them inside the tags results
  • Related content since common tags
  • Possibility to add related posts inside RSS
  • Dynamic Tag Clouds with colors with Widgets
  • Tags inside your header’s blog
  • Embedded tags ([tags]tag1, tag2[/tags]) for retro compatibility

I use a lot of Plugins and write a lot of Plugins, so the fact that I even use one usually means it is really well made or very useful, but this one is one of the very few that I thought was good enough to promote. Remember, if you have a favorite Plugin, do the author a favor and mention it once or twice.

Oh and what would be really nice is if it had a feature that would suggest related keywords based on the text (there used to be a Yahoo API that did this.) Wink Wink.

INAP and feed problems

If you use INAP and have noticed oddness with your full-text feeds lately, it may have been caused by INAP. Users that had the “custom options” selected would have their feeds trimmed as if it were a post. INAP 2.4.3 fixes this.

In other news, INAP is in the process of a major overhaul including a complete rewrite of most of its antiquated structure. When this process is complete it will be rebranded to demonstrate the totality of its features (it won’t be called INAP anymore because the name is too restrictive), but will be released as version 3.0

INAP listed on Mashable

Inline Ajax Page was listed on Mashable as one of “30 good [AJAX wordpress plugins].” While I’m thankful for the publicity (it seems half the internet is scraping Mashable’s feed which resulted in a huge Technorati boost), as always, it was described as “Allow[ing] readers to see a snippet of a post, click a button and the remainder will appear without going to another page.”

I almost cried. That description fits only the 1.0 version of INAP that was released over a year ago–now it does so much more than that that it is almost like saying Google is just a search engine. Oh well, the traffic generated was good quality.

In other news, version 2.4.25 was released a couple days ago to fix a bug that occurs when submitting a comment using the jQuery library under IE6. I think bugfixes this specific really showcase how mature the plugin has become, so if you have used it in the past, but stopped because of bugs, why not try it again?