I’ve been adding a couple of new features to Post Ideas+ over the past few days. One feature in particular required knowing the ID’s of users with the role of ‘administrator’. Now usually you can assume that the ID will be 1, as that’s what the initial adimin account setup by WordPress on install gets assigned. But as the code is going to be used in a plug-in you can’t really assume that.
Some people may have deleted the default account for security reasons (very good idea) or they have more that one administrator account. After hunting about on the WordPress forums for a while I managed to piece together a little snippet of code to do this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
| //Get all admin user ID's in the DB
function admin_user_ids(){
//Grab wp DB
global $wpdb;
//Get all users in the DB
$wp_user_search = $wpdb->get_results("SELECT ID, display_name FROM $wpdb->users ORDER BY ID");
//Blank array
$adminArray = array();
//Loop through all users
foreach ( $wp_user_search as $userid ) {
//Current user ID we are looping through
$curID = $userid->ID;
//Grab the user info of current ID
$curuser = get_userdata($curID);
//Current user level
$user_level = $curuser->user_level;
//Only look for admins
if($user_level >= 8){//levels 8, 9 and 10 are admin
//Push user ID into array
$adminArray[] = $curID;
}
}
return $adminArray;
}
//Usage
$adminIdArray = $this->admin_user_ids(); |
I placed it into it’s own function within my plug-in Class so it can be called whenever needed. It could also be used for finding users with different levels in WordPress if needed. If you wanted you could modify the function to accept an argument admin_user_ids($the_user_level_i_need); allowing you to get the IDs of users at whatever level you like.
There seemed to be a few ways of doing this on the forums, but this one works for me at the moment.
Over the weekend I was working working on a small website build that required a simple CMS so I decided to put Frog CMS to use again; it continues to impress me. What at first looks like a very simple CMS actually has a powerful API behind it.
First thing I had to do (for my own sanity) was move the layout template outside of the CMS and into an external file. This gives you 2 advantages, you get to use whatever code editor you usually use to edit the template, and the file is then exposed so it can be committed to version control like any other file. It is simple to do with some very basic PHP:
1 2 3
| <?php
include($_SERVER['DOCUMENT_ROOT'] . "/public/themes/yout-theme-directory/layout-template.inc.php");
?> |
Paste that code in to your layout with a content type of “text/html” and you are done.
The second code snippet allows you to generate a specific ID and class for every page; great if you need some CSS style / JavaScript hooks on different pages.
1 2 3 4 5 6 7 8 9 10 11 12 13
| <?php
if(url_match('/')):
$bodyID = "home";
else:
$bodyID = "page-". $this->slug();
endif;
if($this->parent() && $this->parent->slug()=="services"):
$bodyClass = "event";
else:
$bodyClass = "";
endif;
?> |
The first if else statement simply sets the home ID to “home” then every other page to “page-slug-name-here” (slug is set in the ‘Meta’ tab). The second one I use on ‘article’ pages; it simply says if the current page has a parent and its parent is the services page add a class of “event”. So now I can style every article page in the same way, and it’s safe for a client to add event pages themselves.
You may ask why the “$this->parent()”; this is to stop the site breaking when you hit the home page since the homepage has no parent, it is the parent of all other pages.
You often find that most small websites that require a CMS don’t require all the features that some of larger solutions offer. While the likes of MODx, Expression Engine and even WordPress are amazing platforms to work from, they can be a little overkill for very small sites. (WordPress isn’t strictly a CMS, but it can be hacked to perform similar actions).
I decided to look for a simple solution; that’s when FrogCMS popped up. It’s free, open-source and very simple to setup. Upload to your server, create your MySQL database with relevant privileges, run the install script and there you go. A big plus point with Frog is the administration page is very straight forward to use, so even the most technophobic client shouldn’t have a problem editing their pages.

Clean and simple administration area.
The templating system is a breeze to use if you know a bit of basic PHP. For example say you want to add a main navigation that automatically updates as you add pages:
1 2 3 4 5 6
| <ul id="mainNav">
<li id="first"><a<?php echo url_match('/') ? ' class="active"': ''; ?> href="<?php echo URL_PUBLIC; ?>">Home</a></li>
<?php foreach($this->find('/')->children() as $menu): ?>
<li><?php echo $menu->link($menu->title, (in_array($menu->slug, explode('/', $this->url)) ? ' class="active"': null)); ?></li>
<?php endforeach; ?>
</ul> |
The ‘foreach’ just loops through the children off the main site route and generates the navigation as an unordered list. Defining editable areas in a layout is just as simple:
1 2 3 4 5 6 7 8 9 10 11
| //Add a snippet
<?php $this->includeSnippet('top-navigation'); ?>
//Add your main page content
<?php echo $this->content(); ?>
//Add another area of content called 'sidebar'; Controlled via a tab on the page admin.
<?php echo $this->content('sidebar'); ?>
//Test to see if we have content, then show
<?php if ($this->hasContent('sidebar')) echo $this->content('sidebar'); ?> |
Even with just those simple lines of code it is possible to create a dynamic user managed website. If it doesn’t do exactly what you want you could always write a plugin to fill the gap.
The only negative point I have to say is that it doesn’t seem to get updated very often, but for most projects that shouldn’t be a problem as it’s already has a solid code base with lots of support and docs available.
For a while now I’ve been using a great little plug-in for WordPress called ‘Post Ideas’ by Aaron Robbins. It was released in early 2008 but unfortunately hasn’t been updated since. Aaron’s website now seems to be a bog standard install of WordPress that hasn’t been updated so there was no way of getting in contact with him.
So I decided to update the plug-in myself. I’ve updated the admin area and added 2 dashboard widgets; A widget to view your latest ‘X’ number of post ideas and a widget to quickly add a post idea to the database. Both can be disabled from the “Screen options” menu above the dashboard.
The plug-in stores a title, description, tags, links and priority associated with the post. Easy to update, write and delete from the admin menu or dashboard widget.

The admin menu under 'Tools'.

Post Idea+ widgets on the dashboard
Installation is the same as with any other WordPress plugin:
- Download the zip file and extract. Upload all files to the ‘/wp-content/plugins/’. Make sure you upload in the correct folder structure e.g. /wp-content/plugins/post-ideas-plus/.
- Activate the Post Ideas+ plugin through the ‘Plugins’ menu in WordPress.
- Under ‘Tools’ you should see an new option ‘Post Ideas+’. You can add / edit / delete ideas from this page.
- You should also see 2 new dashboard widgets ‘Add post idea’ & ‘Latest post idea’. These can be disabled via the screen options.
- If the script fails to install the required mysql table please use the included wp_piplus.sql file and import it to your wordpress database using phpMyAdmin (if your table prefix is not wp_ you will need to change it in the sql file)
If you have any questions, comments or suggestions please leave a comment or get in contact and I’ll see what I can do.
Download from the WordPress plug-in repository or from my server (version 2.1.0.5 – updated 16th Apr 2010).
While writing a plug-in for WordPress recently I came across a very strange error message:
Are you sure you want to do this?
Now my initial reaction was “Well yes, I do want to do this!”. Unfortunately that wasn’t an option. It just told me to try again… same message… ad nauseam. What I was actually trying to do was pass some form information from the plug-in dashboard panel to the plug-in tables in the database.
After searching the web for a while and not having much luck I decided to ‘view source’ on the Quickpress widget which was doing a similar function. I noticed these two hidden inputs:
1 2
| <input type="hidden" id="_wpnonce" name="_wpnonce" value="[random code here]" />
<input type="hidden" name="_wp_http_referer" value="/wp-admin/" /> |
After a brief search in google about ‘Cryptographic nonce‘ it occurred to me that’s what was missing. A vital security feature that WordPress uses to validate that the form information came from the current site rather than an external source. Very clever, but quite frustrating if you don’t know about it.
Adding the following to the form code fixed the issue.
1 2 3 4 5
| $content = '<form name="formname" method="post" action="'.$url.'">';
if (function_exists('wp_nonce_field')){
$content .= wp_nonce_field('hidden_input_name_here');
}
$content .= '...'; |
Simple when you know about it! The ‘wp_nonce_field‘ function is documented in the WordPress codex.
Update: Just to make it a bit clearer I added the code to the plug-in file that was generating my form. So for example:
1 2 3 4 5 6 7 8
| <form name="our_form" method="post" action="http://oururl.com/action">
<?php
if (function_exists('wp_nonce_field')){
$content .= wp_nonce_field('hidden_input_name_here');
}
?>
<!-- Other relevent code for the generated form -->
</form> |
The hidden inputs are inserted into the form allowing WordPress to validate where the request came from.