About Matthew Muro

A University of Alabama web developer. I dig WordPress, PHP, and Jets to Brazil.

Visual Form Builder

Those of you familiar with the UA WordPress Theme have probably seen the contact form shortcode. It’s a basic contact form with a couple of customizations.  For most people looking to add a contact form to a web page, the shortcode does the job.  However, when you want a custom form things can get more complicated.  I have recently built a new plugin that I hope will make things a bit simpler.

Visual Form Builder is a free WordPress plugin that lets you dynamically build forms using a simple interface. Every form includes jQuery validation and a basic logic verification system as well as entry tracking.

A simple script

This plugin started out not as a plugin, but as a relatively simple PHP script that programmatically output the appropriate form code based on what fields and requirements I needed.  This first attempt wasn’t a failure by any means, but it did use some convoluted methods to construct the form.  If I had stopped here, I could have used the tool for a while and been happy with it because it was significantly faster than manually building a form.

The problem with this script was that it was something that really only I would be able to use and my goal was to create something that my co-workers at Web Communications and perhaps others within the UA web community could use.

With that in mind, I decided to turn the script into a form builder plugin for WordPress.

Building a form builder

Having released several other plugins in the last year, getting this one started was fairly straightforward.  Before I began building, I mapped out the requirements I hoped to meet:

  1. Use WordPress HTML/CSS for the admin panel to reduce design maintenance and present familiarity to the user.
  2. Make it easy to add form fields.
  3. Include support for fieldsets.
  4. Order form fields using a drag-and-drop interface.
  5. Use jQuery Form Validation to validate clientside.
  6. Don’t use a CAPTCHA system for anit-SPAM verification.
  7. Log all form submissions in the database.
  8. Export entries to a CSV.

With these features in mind, I began coding.  Not all of these features made it into the first version, but they are there now.

Certainly there are some other form builder plugins available for WordPress, including some commercial tools that offer a wide range of features.  The idea behind Visual Form Builder was to provide a quality, free alternative to the UA web community (or anyone else who finds it useful).

How do I use Visual Form Builder?

I’ve tried to make it as easy as possible to add and customize a form and have even added some help text to the contextual help tab at the top of the plugin page.  Here’s a quick primer on creating your first form.

  1. After downloading, installing, and activating the plugin, go to Settings→Visual Form Builder.
  2. Click on the + tab, give your form a name and click Create Form.
  3. Click the form fields from the box on the left called Form Items to add it to your form.
  4. Edit the information for each form field by clicking on the down arrow.
  5. Drag and drop the elements to put them in order.
  6. Customize the Email Details and Confirmation
  7. Click Save Form to save your changes.
  8. Copy the shortcode from the box on the left called Form Output
  9. Paste into any Post or Page and save your changes

If you have other questions, you can check the FAQ or leave me a comment.

Download it now and let me know if you have any suggestions, bug reports, or feedback.

WordPress Plugin SVN Tip: How to Resolve the ‘Last Updated’ Issue

One of the recurring issues that seems to pop up for WordPress plugin developers as of late is the “Last Updated” problem. For those of you that don’t release your plugins on the WordPress plugin repository or haven’t noticed when downloading a plugin, there is a bit of information right below the download button called “Last Updated.”

Essentially, this date is an indicator of the last time a version of the plugin was released. A big issue for a lot of developers lately is when releasing a new version of their plugin, this date will not update and continue to use the previous version’s date.

Now, this isn’t really a huge deal because users who have a plugin installed will be notified when there is a new version through their site’s admin panel. However, what most plugin authors want, though, is to be listed in the Recently Updated section on WordPress.org. This equals exposure, which equals downloads and more active users.

To solve this problem is pretty simple, but something that isn’t clear because of the lack of communication from whomever controls the Plugin Repository.

With each plugin SVN, you should have three folders: branches, tags, and trunk. Typically, when uploading a new version of your plugin you will place everything into the trunk folder. In addition, you will also copy these files into a new folder under tags with the appropriate version number. The problem lies in how you actually commit your updates.

The Wrong Way

  1. Update your plugin and commit the changes to trunk
  2. Copy these files into a new folder under tags and commit

The reason this is wrong is because the “Last Updated” date reflects whatever is in the tags folder. If the new version’s tags folder does not exist when you update your trunk, it will not be able to find the most recent date. I can’t be sure on this part and it’s only a guess, but I think committing your tags folder at this point causes a bug in the SVN to never look for it.

The Right Way

  1. Update your plugin in the trunk folder
  2. Copy these files into a new folder under tags
  3. Commit ALL changes (trunk and tags) at once

This kind of commit should indicate to the SVN that there is a new version.  From here, it will build the download, update the information (including the Last Updated date), and populate the Recently Updated section.

If there’s some SVN guru out there that can explain to me why it needs to happen this way, please do. All I know is that this needs to be the process a plugin developer must take if they want their work to be hosted on the Plugin Directory.

UPDATE: Otto officially responds on WordPress StackExchange with an answer.  Basically, there is a problem and he’s been trying to fix it.

Programming 101: How to Create Groupings

If you are new to programming, there may be certain solutions that escape you completely, depending on the problem you are trying to solve.  Sometimes it’s as simple as not knowing of a function or syntax.  Other times, it’s a little more complex because it involves logic.

What is Programming Logic?

Before we dive into code, I want to briefly explain what I mean when I say logicProgramming is essentially using code to creatively solve a problem.  Throughout your code could be a logical set of instructions that determines when to execute certain pieces. This is conditional logic.

Many times, the logic to solve a problem is pretty simple:

<?php 
if ( x == 2 ){
    echo 'This is the second record';  
}
?>

Using this kind of conditional logic is essential when you are learning how to program and, over time, will allow you to perform more complex statements.

What is a Grouping?

A grouping is where you sort a set of data into logical sections.  A great example of this is when you see an events calendar that is sorted by date.  There is a single heading for the date and each record that matches that date is listed underneath.

December 10, 2011

  • 12/10/2011 10:00 am – Mary’s Recital
  • 12/10/2011 12:00 pm – Bob’s Cookout

December 11, 2011

  • 12/11/2011 2:00 pm – Computer Science Meetup
  • 12/11/2011 5:00 pm – Art Festival

This sort of breakdown continues on until you get to the end of your data.

How do I make a Grouping automatically?

The above list is easy to create manually, but what do you do when you have hundreds or even thousands of events in a database?  Of course, that’s where programming is going to help us.

Here’s our pseudo code:

  • Query our events database – get all records for the current week
  • Loop through each record and print our information out to the screen
  • If this event’s date is not the same as the previous event’s date, print out our new date heading and continue

Here’s our actual code:

<!--?php<br /-->/* Setup our query - assuming we've already connected to our database */
$query = 'SELECT Title, StartDate, StartTime
FROM events
WHERE WEEK(StartDate) = "12-11-2011"
ORDER BY StartDate ASC, StartTime ASC';

$result = mysql_query( $query );

echo '
<ul>';

/* Loop through our events data */
while ( $row = mysql_fetch_array( $result ) ) {

    /* Assign each row to a variable */
    $title = $row['Title'];
    $date = $row['StartDate'];
    $time = $row['StartTime'];

    /* Handles the date grouping */
    if ( $last != $date ) {
        echo '
	<li class="date_heading">' . date( 'D M d, Y', strtotime( $date ) ) . '</li>
';

        $last = $date;
    }

    /* Output the event name and time below */
    echo '
	<li>' . $title . '-' . $time . '</li>
';
}

echo ';
?>

As you can see, with very little code, we can group our data. What’s even better is that the method can apply to any kind of grouping you need, not just dates! For example, you could have a directory of people and want to group alphabetically by last name (if ( $last != $last_name )). Or, you could have a blog archive page with categories grouped by name and the posts underneath (if ( $last != $category )). There are tons of possibilities.

If you plan to work with a lot of data that needs to be grouped into common headers, save this little snippet of code because it could come in handy.

Restrict Categories – My Experience Writing a WordPress Plugin

Two months ago today I released my first WordPress plugin, Restrict Categories, and in that short time it has already reached over 1,000 downloads.  I thought this milestone was a good chance to write about my experiences developing a plugin.

Background

A couple of months ago, I was doing some research for a project here at Web Communications and it needed to have a particular functionality within WordPress.  We needed to control which categories certain users would be able to edit and post.  At first, I had hope this was possible because I discovered several plugins that appeared to accomplish what I wanted.  However, I quickly realized that none of them worked or didn’t really do what I wanted them to do.  My options were slim: 1) fix one of the broken plugins or, 2) write my own.  After trying to fix a couple of the plugins that had promise, but failing to do so, I started the process of developing my own.

Where to start?

The first place I looked was the WordPress Codex and leaned on it heavily in the early goings.  Specifically, I looked at the Plugin Development pages.  The pages I relied on the most were Writing a Plugin, Adding Administration Menus, Creating Options Pages, and the always helpful Function Reference.

I also think it’s beneficial to check out WordPress Coding Standards, Inline Documentation, Internationalization, and Data Validation.

Initial Development

In very basic terms, this is what I needed my plugin to do:

  • Display a list of all user roles (Administrator, Editor, Author, etc)
  • Display a list of all categories next to each role
  • Allow the plugin user some way to select categories and assign them to that author
  • On the Posts screen, display only those posts with categories from those selected above

Tackling development on this went in pieces.

  1. Create the basics of what I need to get my settings page to show up in the WordPress menu
  2. Get a list of user roles
  3. Get a list of all categories
  4. Combine all of these things on my plugin page and have a process that saves the information to the database
  5. Use that information to filter the Posts screen for restricted user roles

Some of these steps were easier than others and there were many days where I tried one thing, thinking it was the solution, only to be deterred and abandon it for a different route.  But, after a week and a half of trial and error, I finally had a working plugin.

Getting my plugin in the WordPress Plugin Directory

If you’ve ever wondered how people get their plugin on the WordPress.org site, you first start with the Plugin Developer Center.  I signed up and then began my learning process with SVN (Subversion).  Having never used SVN before, I was a bit unfamiliar with where to start or what program to use!  If you are on a Mac, your best bet is to use Terminal.  There are some graphical interfaces that are supposed to make it easier, but I then found it hard to follow the SVN directions from the WordPress documentation.

Anyway, once I figured that out, my plugin was soon live and being displayed in the “Newest Plugins” section.  Very cool.

Improvements

In many ways, Version 1.o had many of the pitfalls that most newbie WordPress plugin developers fall victim to.  In fact, I’m pretty sure I was committing a couple of these Top 10 mistakes.  I was also getting some users with errors.  So, I began troubleshooting my code as well as looking into how to make my plugin better.

For the first couple of revisions, the updates were mainly bug fixes.  Then, I decided to test it in the alpha version of WordPress 3.1.  One of the changes they made to the Posts screen inadvertently would allow a restricted user to bypass all restriction and they could get to a post they weren’t allowed to view.  What was even worse was that I couldn’t figure out how to fix my code to make it work with new Posts screen.  Uh oh.

So, I reached out to the WordPress community asking for a solution.  I asked a question on the wp-hackers mailing list and, when I couldn’t get a workable solution there, headed towards the WordPress Stack Exchange.  Luckily, someone responded with an answer.

I was resistant to the “solution” presented to me at first because I felt I was so close to the answer and was getting the run-around.  What I was really doing was not wanting to do the work to change my code.  However, once I actually took the time to work this solution into my code, I realized it was better.  This wasn’t the last time that asking a question in the community led me to a better solution.

It took two months and 1,000+ downloads to make me a better WordPress developer and a better PHP coder.

Changing the URL of your WordPress site

A question often asked is how to change the URL of their WordPress site.

Here’s a common scenario:  you install WordPress into a sub-directory on your web server so you can create a theme, upload content, and test it without interrupting your current site.  There’s nothing wrong with doing it this way.  In fact, this is how a lot of people develop and test websites before launching, myself included.  One problem many people run into after switching their homepage to point to the sub-directory you installed WordPress is that many of the URLs still use the sub-directory instead of the root.

Let’s look at an example.

At some point development stops and you are ready to switch your homepage so that it’s using the /wordpress/ directory.  However, you notice that something isn’t quite right.  Perhaps the links to your posts are going to the old development URL?  Perhaps your theme was dependent on the old URL and the header image is broken?

This is fixable in two easy steps.

Update URL in WordPress admin panel

The first step is to login to the admin and go to Settings -> General.  Update the WordPress address (URL) and Site Address (URL) options from http://mywebsite.com/wordpress to http://mywebsite.com.

Run MySQL query to update content

The next step is to run a MySQL query.  If you aren’t familiar with SQL, contact your host or IT support to see if they can run it for you.

UPDATE wp_posts SET guid = REPLACE (guid,'http://mywebsite.com/wordpress','http://mywebsite.com');
UPDATE wp_posts SET post_content = REPLACE (post_content,'http://mywebsite.com/wordpress','http://mywebsite.com');

Once you have completed these steps, all URLs should be updated.

If you are performing more complex moves such as moving the database to a different server or moving the WordPress files around, check out these articles on the WordPress Codex: Moving WordPress and Changing The Site URL.

UA WordPress Theme: Update Notifications

One problem with using a custom WordPress theme that doesn’t reside in the WordPress.org Themes Directory is that you don’t have many options for notifying users there is an update available.  If you installed a theme from the directory, WordPress uses a built-in function to inform you that updates are available (see Dashboard Updates SubPanel on the Codex).

So, how does an external theme or plug-in notify a user?  Perhaps you maintain a blog and post your updates there.  Or, you could hope that your blog RSS feed is enough.  You could also have people subscribe to an email list and let them know that way.   All of these are fine methods and some we even use here.  But, the fundamental problem is that it assumes a user of your theme actively follows or is subscribed, in some way, to your blog.  Ideally, the best way to inform a user is through the WordPress Dashboard.

Since we presently cannot hook into the core WordPress function for theme/plug-in updates, the only way is to code your own method.  Luckily, this isn’t as hard as it might seem.

The add_dashboard_page function allows you to easily add a sub-level page under the top-level Dashboard menu item.  From this page, you can read in data from a file on your server (this file can be RSS, XML, TXT, or whatever) and perform a check against the installed theme.  If you are running an out-of-date theme, an update notification will appear in the sidebar and the page offers a download button to grab the latest version.

Here’s what that looks like:

Hopefully, WordPress will open up their API for theme/plug-in updates to externally hosted files in the future.  Until that time, though, this will have to do.

UA WordPress Theme: Contact Form Shortcode

A minor update has been pushed out to the UA WordPress Theme that adds a bit of new functionality as well as an update to the form HTML/CSS.

The first major difference is the addition of two new shortcodes: [linksbox] and [uaform].  If you are unfamiliar with shortcodes, they are custom WordPress tags that allow you to add things which normally require lots of code.  Please refer to the UA WordPress Theme page on WebGuide for more information on the [linksbox] shortcode.

The shortcode I want to focus on today is [uaform].  By adding [uaform] to your post/page, you will have a fully functional contact form.

Here are some of the features:

  • Shortcode attributes to control form name/email subject and email(s) it sends to
  • JS validation using the jQuery Form Validation plugin
  • Logic verification question
  • SPAM honey pot field

The main reasons I chose to write my own shortcode and not use a plugin to process my data is twofold:

  1. I wanted an integrated shortcode to ship with our UA WordPress Theme
  2. I scoured the Internet in search of a similar solution and was never able to find anything

With that in mind and before we get to the code, here is how to customize the shortcode, should you want to.

Customization Options

Option Description Choices Default Setting
form_name The name of the form and subject of email Any string of text Contact Us
to Email(s) the message will be sent to. Single or Multiple emails. If using multiple emails, separate each with a comma Administrator’s email

Here are several examples how you would use some of those attributes:

[uaform to="nottheadmin@test.com"]

[uaform form_name="Website Feedback"]

[uaform form_name="Ask Us a Question" to="firstperson@test.com,secondperson@test.com"]

PHP

Before you can use the shortcode, you will need to add the following PHP to your functions.php file.  If you are using the UA WordPress Theme, you do not have to do this.

<?php

/************************************
Smart Jquery Inclusion
************************************/
if(!is_admin()){
wp_deregister_script('jquery');
wp_register_script('jquery', ("http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"), false, '1.4.2');
wp_enqueue_script('jquery');
wp_enqueue_script('jquery-form-validation', 'http://ajax.microsoft.com/ajax/jquery.validate/1.7/jquery.validate.pack.js', '' , '1.7', true);
}

/************************************
Contact Form shortcode

form_name - name of form, also used as subject of email. DEFAULT is Contact Us
to - email(s) the message will be sent to.  Multiple emails can be used; separate each email with a comma. DEFAULT is the Administrator's email address
************************************/
function ua_form($atts){
if(($_SESSION['contact_form_success'])){
$contact_form_success = '<p id="form_success">Thank you for your inquiry. We will contact you shortly to answer your questions.</p>';
unset($_SESSION['contact_form_success']);
}

$admin_email = get_bloginfo('admin_email');

extract(shortcode_atts(array(
'form_name' => 'Contact Us',
'to' => $admin_email
), $atts));

$_SESSION['ua_form_subject'] = $form_name;
$_SESSION['ua_form_to'] = $to;

$output .= $contact_form_success . '<form method="post" action="' . get_permalink() . '" id="contactform">
<fieldset>
<div>
<h3>' . $form_name . '</h3>
</div>
<ul>
<li>
<label>Name <span>*</span></label>
<div>
<input type="text" name="name" maxlength="100" id="name" />
</div>
</li>
<li>
<label>Department/Organization</label>
<div>
<input type="text" name="department" maxlength="150" id="dept" />
</div>
</li>
<li>
<label>Telephone Number</label>
<div>
<input type="text" name="phone" maxlength="50" id="phone" />
</div>
</li>
<li>
<label>E-mail Address <span>*</span></label>
<div>
<input type="text" name="email" maxlength="150" id="email" />
</div>
</li>
<li>
<label>Enter your question, comment, or issue report <span>*</span></label>
<div>
<textarea name="question" cols="50" rows="10" id="question"></textarea>
</div>
</li>
<li>
<label>Please enter any two digits with <strong>no</strong> spaces (Example: 12) <span>*</span></label>
<div>
<input type="text" name="secret" id="secret" />
</div>
</li>
<div style="display:none;">
<li>
<label for="spam">This box is for spam protection - <strong>please leave it blank</strong>:</label>
<div>
<input name="spam" id="spam" />
</div>
</li>
</div>
<li>
<input type="submit" name="submit" value="Submit" id="sendmail" />
</li>
<input type="hidden" name="contact_form_submitted" value="true">
</ul>
</fieldset>
</form>';
return $output;
}
add_shortcode('uaform', 'ua_form');

function ua_form_process() {
session_start();

if(!isset($_POST['contact_form_submitted'])) return;

foreach($_POST as $key=>$value){
$key = strtolower(str_replace('_', ' ', $key));
$form_fields[$key] = $value;

$value = strip_tags(htmlentities($value));

if($key == "spam" || $key == "secret" || $key == "submit" || $key == "contact form submitted"){
//do nothing
}
else{
$message .= ucwords($key) . ": $value\n";
}
}

//Test for spam and verification, then email
//"secret" is a REQUIRED field name in order for this script to work
if($form_fields["spam"] == '' && is_numeric($form_fields["secret"]) && strlen($form_fields["secret"]) == 2){
$to = $_SESSION['ua_form_to'];
$subject = $_SESSION['ua_form_subject'];

$mail_sent = mail($to, $subject, $message, "From: " . $form_fields["name"] . "<" . $form_fields["email"] . ">");
}

if(!$mail_sent) wp_die("Error: <strong>verification failed</strong>.  Your form was not submitted due to an incorrect answer for the verification question. Please be sure to enter the answer carefully.", "Verification Failed");

$_SESSION['contact_form_success'] = 1;

header('Location: ' . $_SERVER['HTTP_REFERER']);
exit();
}
add_action('init', 'ua_form_process');

function ua_form_validation(){
echo '<script>
jQuery(document).ready(function(){
jQuery("#contactform").validate({
rules:{
secret:{
maxlength:2
}
},
errorPlacement: function(error, element) {
if(element.is(":radio") || element.is(":checkbox")){
error.appendTo(element.parent().parent());
}
else{
error.insertAfter(element);
}
}
});
});
</script>';
}
add_action('wp_footer', 'ua_form_validation');

?>

CSS

Here is the CSS that we use to get a nice looking form (thanks to WuFoo for their rock solid form CSS/HTML).

/*********************************************************
 Form Styles
 *********************************************************/
 form.uaform{
 font-family:"Lucida Sans",Lucida Sans Unicode,Verdana,Arial,sans-serif;
 margin:20px 0;
 }
 form.uaform li{width:auto !important;}
 .uaform ul{
 list-style:none;
 margin:0 14px;
 padding:0;
 font-size:1.2em;
 }
 .uaform li{
 clear:both;
 margin:0;
 padding:6px 1% 9px;
 width:64%;
 }
 .uaform li div span, span.full input, span.full select{
 display:block;
 float:left;
 width:100%;
 }
 .uaform span.left{
 float:left;
 width:48%;
 }
 .uaform span.right{
 float:right;
 width:48%;
 }
 .uaform span.right input, .uaform span.right select, .uaform span.left input, .uaform span.left select{width:100%;}
 .uaform li div label, .uaform li span label{font-size:90%;}
 .uaform fieldset{
 background-color:#eeeeee;
 -webkit-box-shadow:2px 2px 10px #ADADAD;
 -moz-box-shadow:2px 2px 10px #ADADAD;
 box-shadow:2px 2px 10px #ADADAD;
 margin:15px 0;
 clear:both;
 }
 .uaform legend{
 font-size:1.4em;
 font-weight:bold;
 color:#990000;
 margin-left:5px;
 }
 .uaform .legend{
 margin:5px 14px;
 padding:0 6px;
 color:#990000;
 border-bottom:1px dotted #CCCCCC;
 }
 .uaform label, label.desc{
 display:block;
 margin:0;
 padding-bottom:3px;
 color:#000;
 }
 label.desc{font-weight:bold;}
 .uaform label.choice{
 font-size:100%;
 line-height:150%;
 margin:-17px 0 0 23px;
 padding:0 0 5px;
 width:88%;
 }
 .uaform label span{
 color:#BC1212;
 vertical-align:middle;
 }
 input.text, textarea.textarea, select.select{
 font-size:100%;
 font-family:"Lucida Sans",Lucida Sans Unicode,Verdana,Arial,sans-serif;
 margin:0;
 padding:2px 0;
 }
 input.medium, select.medium{width:50%;}
 input.large, select.large, textarea.textarea{width:100%;}
 textarea.medium{height:10em;}
 .submit{font-size:1.1em;}
 input.checkbox, input.radio{
 font-size:1.1em;
 display:block;
 height:13px;
 width:13px;
 margin:4px 0 0;
 }
 label.error{
 color:red;
 font-weight:bold;
 }
 input.error, select.error, textarea.error{border:1px solid red;}
 p#form_success{
 color:green;
 font-weight:bold;
 }

After adding all of that code to your theme and inserting the [uaform] shortcode into a post or page, you should see something like this:

I hope this proves useful to those who just need a simple contact form.  If you have any feedback, suggestions, problems with the code, or spot any bugs please let me know!

How to use the Members plugin to restrict access to WordPress 3.0 Custom Post Type

WordPress 3.0 introduces an easy way to add Custom Post Types to your site.  It’s super easy to do and has been explained in plenty of tutorials already.

However, not many have explained how to restrict this Custom Post Type to users with certain permissions.  In this tutorial, I will show you how to use the excellent Members plugin to restrict your newly created Custom Post Type to only be available for Administrators.

By default, when registering a post type, it inherits the same permissions as Posts.  This is fine if you want all users that can publish a Post to be able to publish your Custom Post Type.  In my case, though, I only wanted Admins to publish.

Register Post Type

The first step is to add the following code to your functions.php file.  If you want to know more about register_post_type, check out the Codex or various tutorials on the subject.

register_post_type('podcasts',
 array(
 'label' => __('Podcasts'),
 'singular_label' => __('Podcast'),
 'public' => true,
 'supports' => array('title', 'editor', 'custom-fields'),
 'capability_type' => 'podcast'
 )
 );

The last argument ‘capability_type’ is what we are most interested in for this tutorial.  I am using ‘podcast’ to be consistent with the post type, but it can be anything you want.  If you were to refresh your site, you will notice that Podcasts doesn’t display.  This is because we have not created or assigned the correct capabilities to the Admin role.

Create and Assign Capabilities

Before continuing, make sure you have enabled the “Edit Roles” Members Component and assigned the “edit_roles” capability to the Administrator role.

On the screen where you edit the Administrator role, scroll to the bottom to the New Capabilities section and add the following capabilities:

  • edit_podcasts
  • edit_podcast
  • edit_others_podcasts
  • publish_podcasts
  • read_podcast
  • read_private_podcasts
  • delete_podcast

After you add those capabilities and Update Role, you should now see the Podcasts section is displayed underneath Comments on the left column.  Podcasts will only be displayed for users with Administrator access.

Why not create a new Role?

I’m sure there are some of you that are saying “Why not just create a new role and assign the capabilities to that?”  Well, you can do that if you want!  But, I didn’t want to go to the trouble of reassigning Admin users to my new role just so they could manage the Podcasts.  For my purposes, it was a lot easier and faster to edit an existing role.

Role Inheritance coming with WordPress 3.1

Andrew Nacin, a lead WordPress developer, commented on Justin Tadlock’s Meta capabilities for custom post types (a similar tutorial to this one) that register_post_type in WordPress 3.1 will probably have the ability to map to a particular role’s capabilities and you won’t have to follow the steps in this tutorial.  But, there’s no hard time line on 3.1 and, until then, you will need to follow the steps outlined in this tutorial.

Hopefully, this makes working with WordPress 3.0 Custom Post Types a little bit easier.  Questions or comments welcome.

UA WordPress Theme: How to Control the Width of your Menu Items

In last week’s announcement of our new UA WordPress Theme, I mentioned there would be several tutorials to introduce you to the new features of our theme.  This week’s tutorial will cover how to control the width of your menu items in the Primary Navigation area.

Before we get into the technical how-to, lets backup and look at what’s going on and why we would even need to change the width.

Default Fixed Width

With CSS, we are allowed to define the exact width of an element.  The new UA WordPress theme will automatically assign the appropriate menu class based on the number of menu items you have in your Primary Navigation menu.  This allows us to assign a default width to each list item in order to distribute evenly across the navigation bar.

Variable Length Names

The trouble with using a default fixed width for each menu item is that, often, it leaves no room for contracting or expanding.  So let’s say you have chosen six menu items for your web site, and the words chosen for those menu items are variable length, so that some are much longer than others.

  • About the College
  • Academic Programs
  • Giving
  • News
  • Resources and Links
  • Contact

Because the list items are of equal length by default, but the words inside the list items are of different length, the menu may appear unevenly distributed, as shown here:


Notice the extra space around the shorter items “Giving” and “News”, and then how little space there is between the items “About the College” and “Academic Programs”. This method certainly works, but may not be ideal for the visual appeal of your site, since the variable length of the words make the menu appear to be unevenly distributed.

Recognizing the Problem

With the Dreamweaver templates, we were able to control the CSS IDs using “item1″, “item2″, etc.

HTML Code generated from UA Dreamweaver templates

<div id="main-nav">
<ul class="menu_6">
<li id="item1"><a href="#">About the College</a></li>
<li id="item2"><a href="#">Academic Programs</a></li>
<li id="item3"><a href="#">Giving</a></li>
<li id="item4"><a href="#">News</a></li>
<li id="item5"><a href="#">Resources & Links</a></li>
<li id="item6"><a href="#">Contact</a></li>
</ul>
</div>

However, because the UA Theme is now using the WordPress Menus functionality, we lose the custom CSS IDs and are instead replaced by automatically generated IDs created by WordPress.

HTML Code generated from UA WordPress Theme

<div id="main-nav" class="menu-custom-menu-container">
<ul id="menu-custom-menu-1" class="menu_6">
<li id="menu-item-4" class="menu-item menu-item-type-custom"><a href="#">About the College</a></li>
<li id="menu-item-5" class="menu-item menu-item-type-post_type"><a href="#">Academic Programs</a></li>
<li id="menu-item-9" class="menu-item menu-item-type-custom"><a href="#">Giving</a></li>
<li id="menu-item-10" class="menu-item menu-item-type-custom"><a href="#">News</a></li>
<li id="menu-item-42" class="menu-item menu-item-type-custom"><a href="#">Resources & Links</a></li>
<li id="menu-item-43" class="menu-item menu-item-type-custom"><a href="#">Contact</a></li>
</ul>
</div>

As you can see, WordPress changes quite a bit from the original code.

Fixing the Problem

Now that we know what is going, how do we go about fixing it?  Luckily, it’s as simple as checking out the generated HTML code from your site and adding a few lines to the CSS file!

  1. Go to the home page of your site and, using your browser, View the Source.  In Firefox, this is done by going to View->Page Source.
  2. Scroll down until you come to the “main-nav” section (examine the code from above if you aren’t exactly sure).
  3. Each <li> will have an associated ID.  Using the code from above, the IDs are
    • menu-item-4
    • menu-item-5
    • menu-item-9
    • menu-item-10
    • menu-item-42
    • menu-item-43
  4. Now, open style.css in the ua_theme folder and add the IDs.
  5. Add custom widths for each menu item until you find the right mixture.
  6. IMPORTANT: the width of all of the items must total no more than 972px.
#menu-item-4{width:197px;}
#menu-item-5{width:201px;}
#menu-item-9{width:130px;}
#menu-item-10{width:130px;}
#menu-item-42{width:172px;}
#menu-item-43{width:142px;}


As you can see, the menu now appears much better visually because the list items appear to be evenly distributed across the menu. And the total width of the menu is equal to 972px, so the code is correct. Certainly, this is a subjective process to find “what looks right”, but that is a process with which all web designers should be quite familiar.

If you have any questions about this tutorial, please leave a comment.

Introducing the new UA WordPress Theme

Exactly two months ago, we launched the first versions of our UA WordPress Themes. These themes provided web designers and developers with easy way to implement our web templates into a CMS.

However, in that time since launch, there have been great advances in functionality for WordPress, namely WordPress 3.0. In anticipation of this launch, Web Communications have been developing a newly unified and dynamic theme to take advantage of some of these features.

The first thing you will notice is that we have managed to reduce the number of themes or folders from 12 to 1. This is a huge step in improving the simplicity of using WordPress for a UA site and installing/choosing a theme.

What’s New

  • UA Theme Options panel
  • Dynamically generated navigation theme
  • Navigation menu creation directly within WordPress
  • Widget capable sidebars
  • Selectable content layout within WordPress

UA Theme Options panel

Probably one of the most noticeable differences with this theme is the addition of a UA Theme Options panel. Thanks to an open source framework for creating theme options WordPress users with admin rights will be able to control major design aspects of their theme without ever touching the code. Such theme options include:

  • Search box in header: select whether or not to include the search box in the header
  • Navigation type: controls the type of horizontal navigation you want (one level, two level, or none)
  • Content layout: controls the layout of your content and sidebar locationBy configuring these options, you will be able to create all the variations of our original UA Web Templates. Once you save these options, you will be able to instantly preview the live site and view the changes.

Menus

With WordPress 3.0, we were able to include the new Menus feature into our theme. You are now able to create and manage your primary, secondary, sidebar, and footer navigation all within the WordPress admin.

Widgets

The UA WordPress Theme now supports widgets in the sidebar. Each UA “linksbox” style is included to give you the greatest number of options to uniquely style your site.

I believe that this theme will allow the average user to easily make their site unique while still conforming to the UA look and feel. In some respects, we are taking the “design” out of the hands of the coder and into the hands of the user. Needless to say, I think this is a huge step forward. Detailed tutorials on many of the new features of the UA WordPress Theme will follow in the coming weeks.

For more detailed information on the UA WordPress Theme, please read our WordPress guide on WebGuide.

Download

Go here to download the new UA WordPress Theme.

As always, comments and feedback are welcome.