wordpress

Wufoo Forms WordPress Embed Shortcode

I tossed this together a while ago, and it even made it in to bSuite for a time, but I don’t have a need for it anymore, and I’m cleaning house.

function shortcode_wufoo( $arg ){
 // [wufoo id=z7x4m0 domain=place.wufoo.com]

 $arg = shortcode_atts( array(
 'id' => FALSE,
 'domain' => FALSE,
 'height' => 500,
 ), $arg );

 if( !$arg['id'] || !$arg['domain'] )
 return( FALSE );

 return( str_replace( array( '%%id%%','%%domain%%','%%height%%' ), array( $arg['id'], $arg['domain'], $arg['height'] ), '<iframe height="%%height%%" allowTransparency="true" frameborder="0" scrolling="no" style="width:100%; border:none" src="https://%%domain%%/embed/%%id%%/"><a href="http://%%domain%%/forms/%%id%%/">Fill out my Wufoo form!</a></iframe>' ));
}
add_shortcode( 'wufoo', 'shortcode_wufoo' );

Download the simple plugin here: wufoo_shortcode.php. Save it as wufoo_shortcode.php, upload it to your WordPress’ wp-content/plugins/ directory, then activate it.

To use it you’ll have to have a Wufoo account and forms. Then simple put in a shortcode like this [wufoo id=z7x4m0 domain=place.wufoo.com] in one of your posts or pages. The result will look like this.

Slideshare WordPress Embed Shortcode

I’m cleaning house in [bSuite][1], and I’ve decided that this shortcode function for embedding Slideshare items in WordPress needs to go. Rather than totally toss it away, however, I’m posting it here in case somebody else finds it useful.

``` function shortcode_slideshare( $arg ){ // [slideshare id=211578&doc=misty-holland-1198496990903941-2&w=425]   $arg = shortcode_atts( array( 'id' =&gt; FALSE, ), $arg );   if( ! $arg['id'] ) return( FALSE );   return( str_replace( '%%id%%', $arg['id'], '
'

)); }   add_shortcode(‘slideshare’, array(&amp;$this, ‘shortcode_slideshare’));

      </td>
    </tr>
  </table>
</div>

 [1]: http://maisonbisson.com/bsuite/

Usability vs. Open Source

This article comparing the usability of Joomla vs. WordPress has already been linked by everybody’s uncle, but it’s still worth a look.

I find it amusing, however, that none of the comments so far on that blog post mention the commitment that the core WordPress team appears to have on making blogging fun. If you start with the goal of making something fun, then add sophistication to make it flexible without being complex, you’ll get a very different result than you would if you started with different goals.

Scriblio 2.7 Released

My slides for my presentation yesterday at code4lib are available both as a 2.7MB QuickTime and a 7.8 MB PDF, while the gist of talk went something like this: Scriblio is an open source WordPress plugin that adds the ability to search, browse, and create structured data to the the popular blog/content management platform. And […] » about 500 words

Plugin Options Pages in WordPress 2.7

WordPress 2.7 requires that plugins explicitly white list their options using a couple new functions. WordPress MU has required this security measure for a while, and it’s nice to see an evolved form of it brought to the core code. [Migrating Plugins and Themes to 2.7][1] article in the codex offers some guidance, but here’s how it works:

First, register each option for your plugin during the admin_init action:

``` function myplugin_admin_init(){ register_setting( 'my-options-group', 'my-option-name-1', 'absint' ); register_setting( 'my-options-group', 'my-option-name-2', 'wp_filter_nohtml_kses' ); } add_action( 'admin_init', 'myplugin_admin_init' ); ```

In the example above, the value for my-option-name-1 will be filtered by absint before being saved to the options table. my-option-name-2 will be stripped of any HTML by wp_filter_nohtml_kses.

Then build a form like this prototype:

```
      </td>
    </tr>
  </table>
</div>

Easy.

 [1]: http://codex.wordpress.org/Migrating_Plugins_and_Themes_to_2.7#Plugins "Migrating Plugins and Themes to 2.7 « WordPress Codex"

Tricky Uses of bSuite

After writing the project page for wpSMS I didn’t have much more to say in a blog post announcing it. The cool thing about writing Pages in WordPress is that I can create a taxonomy like /projects/wpsms/ to place them in. The downside is that new pages never appear in the RSS feed.

So I need both the page and a blog post to announce it. I could have simply copied the content from the wpSMS page into a blog post, but that creates confusion and splits the audience between the two pages. Instead, I’m using two bSuite features: the [inclu``de] shortcode and the post redirection support.

  1. Create the page.
  2. Start a new post.
    1. In the post body put the include shortcode like this: [inclu``de post_id="123" field="post_content"].
    2. In the custom fields put an entry with the key: “redirect” and the full URL to to your page.
  3. Relax, you’re done.

The include shortcode will copy all the content from the page (so you don’t have to manage it twice), and the redirect custom field will tell bSuite to redirect anybody trying to read that post to your page.

Using WordPress With External SMTP Server

I really don’t like having sendmail running on a webserver, but some features of WordPress just don’t work if it can’t send email (user registration, for example). Still, WordPress offers support to send email through external SMTP servers instead if a local mailer.

In <a href="http://trac.wordpress.org/browser/tags/2.6.3/wp-includes/pluggable.php">/wp-includes/pluggable.php</a> around line 377, change

``` $phpmailer->isMail(); ```

to

``` $phpmailer->isSMTP(); ```

Then, in <a title="/tags/2.6.3/wp-includes/class-phpmailer.php - WordPress Trac - Trac" href="http://trac.wordpress.org/browser/tags/2.6.3/wp-includes/class-phpmailer.php">/wp-includes/class-phpmailer.php</a> around line 155, set your SMTP host:

``` var $Host = "my.smtphost.com"; ```

You may also need to set a username and password, and tell WP to attempt authentication. You’ll see those in the lines below the hostname variable.

``` var $SMTPAuth = true; var $Username = "username"; var $Password = "password"; ```

On the other hand, you could do this via a plugin, perhaps even Callum McDonald’s WP Mail SMTP.

Uploading .docx Files In WordPress

It may be a sign that none of the core WordPress developers much likes or uses Microsoft Office, but the core code hasn’t been updated to recognize the Office 2007 file extensions like .docx, .pptx, or .xlsx. It’s no criticism, wouldn’t have discovered it if a user hadn’t complained, and I stewed a bit before deciding it was a bug.

It’s now ticket #8194 in the WordPress.org Trac. It only affects my MU users now, though, and the same patch works there.

You’ll find a few mentions of doc, ppt, and xls in wp-includes/functions.php (around lines 1613-1615 and 1651-1654 in 2.6.3). Once corrected, those lines should look something like this:

``` 'document' => array('doc','docx','pages','odt','rtf','pdf'), 'spreadsheet' => array('xls','xlsx','numbers','ods'), 'interactive' => array('ppt','pptx','key','odp','swf'), ```
``` 'doc|docx' => 'application/msword', 'pot|pps|ppt|pptx' => 'application/vnd.ms-powerpoint', 'wri' => 'application/vnd.ms-write', 'xla|xls|xlsx|xlt|xlw' => 'application/vnd.ms-excel', ```

Update: Sweet! It’s been accepted and should be in the WP2.7 release.

Determining Paths and URLs In WordPress 2.6+

WP 2.6 allows sites to move the wp-content directory around, so plugin developers like me can’t depend on them being in a predictable location. We can look to the WP_CONTENT_DIR and WP_PLUGIN_DIR constants for answers, but a better solution is likely to use the X_url() functions. The most useful of those is likely to be plugins_url(). Even better, you can give these functions a relative path and they’ll return a fully qualified URL to the item.

WordPress Bug: Duplicate post_meta Entries

I just submitted a trac ticket about this:

The update_post_meta() and delete_post_meta() functions don’t know how to deal with post revision IDs. add_post_meta() does, it uses the following block of code to make sure the passed $post_id is a real post, not a revision:

``` if ( $the_post = wp_is_post_revision($post_id) ) $post_id = $the_post; ```

This is important because the global $post_id when a post is being saved is for the revision, not the real post. If you pass that to these functions, update_post_meta() and delete_post_meta() will try to update or delete the records related to the revision. When update_post_meta() fails to find any records for the post_id you submitted, it calls add_post_meta(). Each attempt at updating the meta will actually create a new row in the table.

For now I’m checking with wp_is_post_revision() before making any calls to the post_meta functions.

Updated: Mark Jaquith committed the patch less than two hours after I submitted it! I love WP.

WordPress Event Calendaring Plugins

I actually use Event Calendar, which has been abandoned for some time. Looking at the alternatives listed in the Plugin Directory, Calendar, Events Calendar, and Gigs Calendar add full calendar management features to WordPress. While ICS Calendar, iCal Events, and Upcoming Events, simply offer the ability to display calendar data from elsewhere.

What I liked about the old Event Calendar plugin is how events were posts. Creating an event started with creating a new post. Searching and browsing events was the same as for posts. I haven’t yet tried any of the alternatives, but if none of them treat events as posts, I may find myself re-working the old plugin for better compatibility with current WordPress.

Do WordPress Pages Better With bSuite

WordPress‘ Pages feature makes the popular blogging platform a sophisticated CMS. bSuite adds a few features to make it even better. Write excerpts, tag, and categorize your pages WordPress excerpts are an underused but powerful feature that allow you to explain to your readers why they should read the page you wrote. Tagging and categorization […] » about 300 words

My DevCamp Lightning Talk

Hi, I’m Casey. I developed Scriblio, which is really just a faceted search and browse plugin for WordPress that allows you to use it as a library catalog or digital library system (or both). I’m not the only one to misuse WordPress that way. Viddler is a cool YouTube competitor built atop WordPress that allows […] » about 400 words

Michael Stephens Teaching on WordPress MU

Michael Stephens is now using WordPress MU to host his classes online, and that opening page is really sweet. It’s hardly the first time somebody’s used a blog to host course content, but I like where he’s going with it. We’re significantly expanding our use of WordPress at Plymouth, and using it to replace WebCT/Blackboard […] » about 300 words

WordPress CAS Integration Plugin

CAS — Central Authentication Service — has no logo, but it’s still cool. Heterogeneous environments like mine offer hundreds of different online services or applications that each need to authenticate the user. Instead of throwing our passwords around like confetti, CAS allows those applications to identify their users based on session information managed by the […] » about 300 words