Updating a Plugin in the WordPress.org Repository

As of this writing, I have only two plugins in the WordPress.org repository. I periodically update these plugins, but not often enough to memorize all the steps required to get things right on the first try. So for my own future reference (and maybe yours as well) here are all the steps laid out in order.

(more…)

WordPress Plugin Template

WordPress Plugin Template

Please note: this plugin template is no longer maintained.

I’ve started developing WordPress plugins from scratch too many times. I don’t enjoy repeating the setup process for every plugin I develop, so I’ve created a default plugin template that has all the basics included. Enjoy!

Download Plugin Template 1.1

  • PublishedJune 15, 2011
  • UpdatedFebruary 28, 2012
  • Posted InPlugins
  • DifficultyAdvanced
  • Tested With3.0 +

Easy Embed WordPress Plugin

The WordPress editor doesn’t always play nice with HTML (especially if you switch back and forth between the Visual and HTML editor). This problem has bugged me for a while, and I finally sat down and built a simple plugin to solve it. There are other solutions out there, but I find this method to be the easiest to use. After installing the plugin, all that is required is to create a custom field (you can name it anything), place your code in the new custom field. This could be HTML, video embed codes, Paypal forms, etc. Then place the following shortcode into your post where you want your special code to go:

[easyembed field="name-of-custom-field"]

The field property should be the name of the custom field you created. The shortcode above would display the contents of a custom field with the name “easy”

Download Easy Embed from the WordPress plugin directory.

View the code below:

<?php

/*
Plugin Name: Easy Embed
Plugin URI: http://wordpress.org/#
Description: Allows the embedding of any code and protects it from being modified by the WordPress editor
Author: Alex Mansfield
Version: 1.0
Author URI: http://alexmansfield.com/
*/

function am_easy_embed($array) {
extract(shortcode_atts(array('field' => 'custom'), $array));
global $post;
$html = get_post_meta($post->ID, $field, true);
return $html;
}
add_shortcode('easyembed', 'am_easy_embed');

?>
  • PublishedJuly 29, 2010
  • UpdatedJanuary 16, 2011
  • Posted InPlugins
  • Tested With3.0

WordPress Plugin: Latest Posts by Author

Update: The plugin has gone through a number of revisions since I first published this post. See: http://wordpress.org/extend/plugins/latest-posts-by-author/ for the latest versions. The code posted below is from version 0.6.

I just posted my first plugin to wordpress.org. It creates an unordered list of the most recent posts by a given author. It can be called both from within a post using a shortcode or from within a theme file. Check out Latest Posts by Author at wordpress.org for more details.

To demonstrate just how easy it is to create a plugin for WordPress, I’m posting the plugin code below.

<?php

/*
Plugin Name: Latest Posts by Author
Plugin URI: http://wordpress.org/#
Description: Displays a list of recent posts by the specified author
Author: Alex Mansfield
Version: 0.6
Author URI: http://alexmansfield.com/
*/

function latest_posts_by_author($array) {
 extract(shortcode_atts(array('author' => 'admin', 'show' => 5, 'excerpt' => 'false'), $array));

 global $wpdb;
 $table = $wpdb->prefix . 'users';
 $result = $wpdb->get_results('SELECT ID FROM '.$table.' WHERE user_login = "'.$author.'"');
 $id = $result[0]->ID;
 $table = $wpdb->prefix . 'posts';
 $result = $wpdb->get_results('SELECT * FROM '.$table.' WHERE post_author = '.$id.' AND post_status = "publish" AND post_type = "post" ORDER BY post_date DESC');
 $i = 0;
 $html = '<ul>';
 foreach ($result as $numpost) {
 $html .= '<li><a href="'.get_permalink($numpost->ID).'">'.$numpost->post_title.'</a>';
 if($excerpt == 'true'){
 $html .= '<p>'.$numpost->post_excerpt.'</p>';
 }
 $html .= '</li>';
 $i++;
 if($i == $show){
 break;
 }
 }
 $html .= '</ul>';

 return $html;
}

add_shortcode('latestbyauthor', 'latest_posts_by_author');

?>
  • PublishedAugust 11, 2009
  • UpdatedFebruary 16, 2012
  • Posted InPlugins, Wordpress
  • DifficultyAdvanced
  • Tested With2.8 - 3.3