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 Mobile Web 2.0

The Office of Web Communications is pleased to announce the next iteration of UA Mobile Web. The newest version offers several improvements in speed, function, and design.

Speed

Significant improvements to load times have been made with the iPhone and Android versions.  I have exchanged 90% of the images with CSS3 gradients and border radius.  File sizes for the CSS and JavaScript files have also been pared down and minified to save as much space as possible.  For some pages, loading times have been decreased by 40%.

Function

In addition to quicker load times, the new version adds the following features:

  • News is now more fully integrated into UA Mobile Web.  You may now browse UA News, Dialog, and Research stories before leaving the site.
  • Video adds an instant streaming option.  Using the HTML5 <video> tag, all UA News videos will play seamlessly in the browser (currently iPhone only).
  • Social Media is a new section that brings our official Facebook and Twitter status updates to your browser.

Design

Users of UA Mobile Web on the iPhone and Android will now notice a crimson header bar with The University of Alabama nameplate.  This bar is on every page and further brands this site as part of the UA Home Page.

Also, a few of the home screen icons have been updated to give greater separation between services.  iPhone and Android users will also notice a new “action” symbol for items:  the external link.  As arrows have symbolized going to the next page within UA Mobile Web and phones have symbolized a phone number, the external link symbol is a visual cue that the item you are about to touch will load a page outside of UA Mobile Web.

I hope all of these additions and changes make for a better experience with UA Mobile Web.  If you have any feedback or discover a bug I didn’t catch, please let me know!

Improvements to Mobile Events Calendar

Yesterday, a major update to the UAMobileWeb Events Calendar was made.  This update is significant in that there is not only an update functionally, but visually as well.

The previous version of the mobile Events Calendar only allowed browsing by Day and Month views.  The new version adds a Week view, Category and Calendar Type browsing.  Also, there are even more details available: descriptions, contact information, links to categories and calendar types, and additional information (if available).

In addition to the new views and details, a visual upgrade has been pushed out to the browsing views for the iPhone and Android themes.  The older version used a layout akin to the iPhone’s Calendar app where the times were listed on the left side and the events were in colored blocks to the right.  This looks fine for one or two events but can start to get messy with many events and time slots.  Now, you will see a nice, colored separator with either the time or date inserted, depending on the view you have selected.

Hopefully, the UA mobile community will find these upgrades useful.  The UAMobileWeb Events Calendar should now be faster, more functional, and easier to browse.  Please let me know what you think or if you discover any bugs/problems that need to be addressed.

IE9 Details Begin to Emerge

Since there is beginning to be a fair amount of buzz surrounding some of the upcoming browser releases, I thought I would take a moment to share some of the recent news that has begun spilling out on the Internet Explorer front since PDC.

IE general manager Dean Hachamovitch reports Microsoft is “…focusing on three very specific areas: performance, interoperability standards, and hardware acceleration.”

What does this mean?

Well, on the performance front at least some of the slated rendering-speed increases will be due to new technology which allows IE’s browser engine, Trident, to pipe text and graphics rendering through DirectX (older IE versions have used GDI). This means IE will be able to make use of the hardware acceleration in a computer’s GPU to ramp up things like streaming video performance and flash-based interfaces. Of course there is also javascript-parsing-speed increases, but all of the cool kids on Browser Street have been working on this front for quite some time – so this news hardly warrants dwelling on.

Regarding interoperability, there will reportedly be increased support for CSS3 selectors (yay!) as well as pledged support for the evolving technologies outlined in the HTML5 preliminary spec (audio/video/canvas support?).

More detailed information can be found at the following links:

Update: And now a word straight from the horse’s mouth – IE Blog: An Early Look At IE9 for Developers

Announcing the launch of UA Mobile Web (beta version)

As part of an ongoing strategic process to optimize our web presence for all users, the Office of Web Communications has completed the initial development and rollout of a UA Mobile Web site for The University of Alabama.  This site is a custom web site and suite of applications which deliver top-level content, services, and features from UA to your iPhone, Blackberry, PDA, or other smartphone.  UA Mobile Web optimizes web services and content specifically for mobile devices, making them immediately available to users any time from anywhere.  The beta version of UA Mobile Web includes functionality and content such as: 

  • News
  • Events Calendar
  • Campus Map
  • Faculty/Staff Directory
  • Video
  • UA Web Sites
  • CrimsonRide
  • Contact UA
  • Search

UA Mobile Web is now part of the UA Home Page, so that visitors who navigate to www.ua.edu on mobile devices will automatically be redirected to the appropriate mobile version for their device, including separate versions for iPhone and other devices such as Blackberry, Android, Windows Mobile, etc.  Users will always have the option of viewing the full UA Home Page (as it appears in a web browser) via a link on the mobile site if desired.  The UA Mobile Web site can also be accessed directly at http://m.ua.edu/.

UA Mobile Web was developed in-house by the Office of Web Communications using open source code and platforms.  As this is a “beta” release, we plan to grow and expand its functionality and content in the near future and over time.  Also, we are treating this platform as an open one, so there is certainly the opportunity to add to the mobile site with additional pieces and applications developed elsewhere or by other groups.  We’ll be reaching out to other areas on campus to make this option known and available.

We believe this effort represents a significant step forward in making our content and services available to all audiences in as many platforms as possible.  If you have any questions, feedback or comments, please don’t hesitate to let us know.

Commenting on Code in Code

commentimage

Ever wonder how web designers keep everything in order when they’re typing out their code? Well, commenting helps a lot in organizing. By using comments, you can also signal out things you want to fix, make note of, or even just keep track of. So how do you keep the comments from messing up the 18 hours of coding you just did? Well, there are different options for different languages.

HTML

Below is the style for your basic html web page which really shouldn’t have too many comments- just nice clean code.

<!-- Comment Here -->

CSS

For organizing your styles and your main boxes- or whatever else you need- this commenting style works for single line or block quotes.

/* Comment Here */

JavaScript or jQuery

For JavaScript or jQuery, this method comments out the entire line starting from behind the back slashes. It is used as an end of line comment. CSS style is used as a short single line comment.

// Comment Here

/* Comment Here */

For block comments the code looks like CSS, but remember to keep an asterisk on each line.

/*
* Comment Here
*/

PHP

PHP can use the JavaScript method, or the pound symbol to comment out a line.

// Comment Here

# Comment Here

For multiple lines, the comment code is like the CSS code but unlike the JavaScript, no further asterisks are needed.

/* Comment
Here */

Ajax

To comment in Ajax, use the same method as in JavaScript.

// Comment Here

ActionScript

When working with flash, you might want to use these to comment on your action script. The first works for multiple lines and single lines while the second is just used for single lined short comments.

/* Comment Here */

// Comment Here

New UA Web Templates are now available

Web templates based on the design and functionality of the current UA Home Page are available for usage by any official unit of The University of Alabama. There are three basic versions of the templates available, each of which offers numerous options for customization and arrangement of content. The template packages are organized into three different navigation types — one-level horizontal navigation, two-level horizontal navigation, and no horizontal navigation.

Also, new this time around is the release of a significant “how-to guide” for explaining how the templates work and best practices and techniques for customizing them to specific needs.  The UA Templates Guide explains the basic design elements of the templates, details the grid structure upon which the templates are built, describes the process of customizing the templates, explains how to create content to fit within the templates, and provides further resources for learning how to build highly-functional and visually-engaging web sites. This guide is intended to be a primer for working with the templates, and we encourage all users of the templates to read it carefully before beginning any design work.

By using these templates, units of The University of Alabama ensure that their web site is closely tied to the University’s top-level web sites and help build a cohesive and effective overall institutional web presence.  Please feel free to use the templates as needed, and to share this information with anyone you think would benefit from knowing about it.  And as always, please let us know if you have questions, comments or feedback regarding these templates. 

Strategic iPhone/Mobile development for key UA web sites

I’d like to share the outcome of a project we’ve been working on that positively impacts our top-level strategic web sites.  Below is a high-level summary of the project.  If you have any questions about this, please ask them in the comments section and we’ll be glad to answer.

Background/Challenge

We have recently been working to optimize our key strategic web sites for mobile devices, in order to ensure maximum accessibility and compatibility with all mobile platforms.

The challenge here is that manufacturers of mobile devices use a variety of platforms for mobile web browsing – some very “web-like”, and some not so much.  So taking the content of a web site and making it work in all of the major mobile platforms requires dedicated design processes that target specific devices, and deliver content to those devices based on their capabilities.  By doing so, we optimize the experience of browsing our sites on mobile devices without overwhelming the device beyond its capabilities, and we ensure that the mobile user experience for browsing our sites is of the highest quality.

Incidentally, we have always designed our web sites with mobile platforms in mind, as the process of building web standards-based web sites makes these sites mostly accessible in almost any platform.  But in order to improve the experience for our users, we have undertaken the task of optimizing our key web sites for mobile devices, separate from our standard development practices.

The Results

The results of this process are that we have successfully optimized our key strategic content-related web sites – UA News Center (http://uanews.ua.edu), Research Magazine (http://research.ua.edu), and Dialog (http://dialog.ua.edu) – for all of the major mobile platforms, so that the content on these sites is easily accessible and navigable on all devices.

Of particular interest and focus during this process was development for the iPhone platform, which is growing in popularity and market share.  We have built alternate versions of these web sites that are specifically tailored for the iPhone’s functionality using open source plug-ins that work with our content management system, WordPress, and the functionality of these sites is now very high for the iPhone.

Also, the UA Home Page (http://www.ua.edu) displays very well on the iPhone as well, as it has the exact look and functionality as it does in a web browser.  It also displays well in a stripped-down format in many older mobile devices, but we will be working to further advance its mobile functionality by fine-tuning its mobile capabilties.

Examples

Below are some screenshots of each site in various mobile devices so that you can see how they now appear in these devices.  We will continue to work to optimize and fine-tune these mobile versions of our sites and look for further opportunities to expand our reach to these mediums.  These steps represent a significant upgrade in the mobile browsing experience for visitors to our web sites, and will help us continue to spread our messages to new audiences while staying at the forefront of technology trends.

Click for larger version

Click for larger version

iphone_uanews

iphone_uanews_story

iphone_research

iphone_research_story

More: