Cleverness – WordPress Resources

Coming Soon: WPCodeDB

As the final project of a PHP/MySQL 3 course I’m taking, we have to create a social web application.

There are many code snippet repositories out there, but none that I found that are specific to WordPress. I thought it’d be great to have them all in one spot, so I decided to create one as my final project (which needs to be done before the end of this month).

I hope that once it launches, other people will use it besides myself so it will become a great WordPress resource.

In July I’m planning on resuming development on the To-Do List plugin. I’ve tested it in single user mode with 3.2RC1 but not in group or master mode yet. Single user with or without categories is working fine.


Development, bug fixes, and support will be very limited until July

This year I have been planning lots of improvements to the plugin, especially adding Ajax. This past winter and early spring was not good to me health-wise. I have chronic medical conditions plus I had bronchitis a few times. And a couple ER visits. Now that my health is stable for the moment, I was looking forward to getting back into development. But, it is not to be yet.

The company I work for received a grant last July for training. Unfortunately, the company owner did not approve the training until February. All the training has to be completed by June 30. With me being sick and it being busy at work, I still have 1 class to finish and one to complete (there were three). I’m taking them through O’Reilly. I took Javascript 2: Ajax first. The assignments were not overwhelming and took a reasonable amount of time to complete. Then, I started PHP/MySQL 2: Relational and Logical Database Design. Wow. This class has been a lot of work. The assignments take forever, it seems. I still have PHP/MySQL 3 to complete, which sounds like it will be even more work. So, from now until the end of June I will be spending a good amount of free time working on these courses and between that and coding at work, I won’t be up to working on the plugin.


To-Do List Plugin Issue with Multi-site

There’s a problem with the plugin with version 3.1+, multi-site, and network activation.

I haven’t figured out why yet it’s happened with mine, but apparently this isn’t the only plugin that developed that problem with 3.1.

The temporary work-around is to use individual activation rather than network activation. I will get a bug fix update as soon as I can.


Professional WordPress Plugin Development Book Review

If you develop WordPress plugins, you need to read Professional WordPress Plugin Development by Brad Williams, Ozh Richard, and Justin Tadlock.

Professional WordPress Plugin Development Review

I first read this book around the beginning of April. I learned a lot of new things. And then promptly forgot it all. So yesterday and today I went through the book again and took notes. This book is around 500 pages and covers pretty much any topic you could wish for. I made sure to pay special attention to the security section since that is probably the most important feature of plugin development.

I found things that I want to do to improve my To-Do List plugin (and wrote them down this time) and things that I will keep in mind for my next plugin.

You need to know PHP to understand the code in this book (you can’t develop a plugin without knowing PHP anyway). I’m already familiar with a lot of WordPress’s hooks and functions and how WP works. I felt that this book was right at my skill level.

I recommend this book 100%.


My Top WordPress Plugins

There are many top ten lists of WordPress plugins out there. They all seem to contain the same thing, with one or two variations. Contact Form 7, Google XML Sitemaps, All-in-one SEO, etc. They are great plugins and I use them as well, but I really love when they list a lesser known plugin that ends up being useful to me.

These are some of the other plugins I use.

  • Cleverness To-Do List Plugin: Yep, my own plugin. I install it on every one of my sites and I adopted it after it was abandoned because I found it so useful.
  • Greg’s High Performance SEO: This is the SEO plugin that I prefer to use. I like it better than All-in-one SEO
  • Syntax Highlighting Evolved: This is the plugin that I use to display PHP and other code on this site. I tried out several syntax highlighters and I found this one to be the best. There are several color schemes you can choose from as well.
  • Theme Test Drive: I use this whenever I’m designing a new theme for one of my sites. It allows you to work on a theme without anyone else being able to see it.
  • Slideshow Gallery Pro: Lots of clients want slideshows on their page and I’ve found this to be the best plugin for them.
  • Advanced Excerpt: This plugin gives you much more control over how an excerpt looks.
  • Subscribe to Comments Reloaded: I don’t know how many users subscribe to comments, but I wanted to give people that option.
  • Relevanssi: The default search is not very good. This will provide more relevant search results.
  • Custom Field Template: This makes it easy to provide nice graphical interfaces to enter custom fields in posts.
  • WP-PageNavi: I sometimes like to have numbers at the bottom of pages rather than previous and next links.
  • jQuery Lightbox For Native Galleries: I’ve used several different lightbox plugins through the years and I’ve found this to be one of the better ones.
  • WP Maintenance Mode: This works great for new sites you’re working on or sites you’re redoing. It displays a coming soon/maintenance mode page for non-logged in users.

Updated BuddyPress User Roles Code

My post on adding user types to WordPress and Buddypress has been very popular.

This code will soon be available as a plugin.

I’ve updated the code so it’s cleaner and easier to implement. This code also works with or without allowing users to add new sites.

This only works for BuddyPress running on the multisite version of WordPress.
If you’re using the regular version, someone else has a plugin available for that: WP Roles at Registration. It works for BuddyPress (but not the multisite version).

Instructions

Set up your custom WordPress roles using Capability Manager or a similar plugin.
Place the following code into the functions.php file in your theme.
Edit the section titled Define User Roles and replace the values with your own.

<?php
/*------ Adding User Types to BuddyPress - http://cleverness.org ------*/

/**** == Define User Roles == ****/
/*
Replace usertypea with the name of the WordPress Role.
Replace User Type A with the label that you want to display on the registration form.
Repeat for the other roles.
Add or remove lines as needed, using this format:
'myrole' => 'My Role',
*/
 $customroles = array(
	'usertypea' => 'User Type A',
	'usertypeb' => 'User Type B',
	'usertypec' => 'User Type C',
	);
/**** == end Define User Roles == ****/

add_filter( 'bp_signup_usermeta', 'customroles_user_signup_field' );
add_filter( 'bp_core_activate_account', 'customroles_user_activate_field' );
add_action( 'wpmu_activate_user', 'customroles_register_role', 10, 3 );
add_action( 'wpmu_new_blog', 'customroles_register_role_blog', 10, 6 );
add_action( 'bp_after_account_details_fields', 'customroles_registration_fields' );

/* Add sign-up field to BuddyPress sign-up array */
function customroles_user_signup_field( $usermeta ) {
	$usermeta['signup_type'] = $_POST['signup_type'];
	return $usermeta;
}

/* Add sign-up field to usermeta on user activation */
function customroles_user_activate_field( $signup ) {
	update_usermeta( $signup['user_id'], 'signup_type', $signup['meta']['signup_type'] );
	return $signup;
}

/* Update the user's WP role and user meta */
function customroles_register_role($user_id, $password, $meta) {
	global $bp, $wpdb, $customroles;
   	$userdata = array();
   	$userdata['ID'] = $user_id;
   	$userdata['role'] = $meta['signup_type'];
	$type = $meta['signup_type'];

   	//only allow if user role is one of the allowed roles
   	if ( array_key_exists( $userdata['role'], $customroles ) ) {
      	wp_update_user($userdata);
		update_usermeta( $user_id, 'signup_type', $type );
   	}
}

/* Updates the user's WP role for when a new user creates a blog */
function customroles_register_role_blog($blog_id, $user_id, $domain, $path, $site_id, $meta) {
	global $bp, $wpdb, $customroles;
   	$userdata = array();
   	$userdata['ID'] = $user_id;
   	$userdata['role'] = $meta['signup_type'];
	$type = $meta['signup_type'];

   	//only allow if user role is one of the allowed roles
   	if ( array_key_exists( $userdata['role'], $customroles ) ) {
      	wp_update_user($userdata);
		update_usermeta( $user_id, 'signup_type', $type );
   	}
}

/* Add user type fields to registration form */
function customroles_registration_fields() {
	global $customroles;
	echo '
		<!-- Begin User Type code -->
		<div class="register-section" id="usertype-details-section">
		<div class="editfield">
			<label for="signup_type">Account Type:</label>
			<p><select id="signup_type" name="signup_type">';
			foreach ( $customroles as $key => $value ) {
				echo '<option value="'.$key.'">'.$value.'</option>';
				}
		echo'</select></p>
		</div></div>
	<!-- end of User Type code -->';
}
/*------ end Adding User Types to BuddyPress ------*/
?>

You can use get_user_meta() in your theme files to show different things to different user types.

<?php
global $bp;
if ( get_user_meta($bp->displayed_user->id, 'signup_type') == 'usertypea' ) : ?>
    Put your HTML code here
<?php endif; ?>

JavaScript and AJAX for Dummies Review

I just finished reading JavaScript and AJAX For Dummies by Andy Harris.

I like the Dummies and Idiots books. I think they’re great if you don’t know much about a subject and want to get an introduction to it.

I took a course at college about JavaScript ten years ago. Back before jQuery and all that. The knowledge didn’t really stick with me and I’ve always felt uncomfortable using JS and tried to avoid it. I want to be able to use AJAX (which I know nothing about) so I need to update my JS skills.

One of the things I like best about this book is that it covers debugging. I use Firebug in Firefox, but all I really know how to do is the CSS stuff. The Inspect Element menu item is the BEST THING EVER. It’s so helpful in fixing CSS problems. Anyway, I never bothered reading more about Firebug and what it can do. Now I know how to use it and Aptana to debug JavaScript. The author is a fan of using Aptana for JS and it seems to me that it’s good.

The first JavaScript section goes over the fundamentals. Variables, loops, arrays. But it also covers objects and JSON. I hadn’t used objects before in JavaScript, only PHP and C++. I had no idea what JSON was. Now I know that it stands for JavaScript Object Notation and what it is.

I don’t know how easy this section would be to understand if you didn’t have a programming background, but I thought he explained everything clearly and with good examples. But I don’t think too many people without a programming background would be or should be reading a book that involves AJAX anyway.

The second JavaScript section talks about actually changing elements on a page with JavaScript, using the DOM. There’s a small section on regular expressions, which I didn’t expect. This section was interesting but I can’t really think of anything to say about it.

The third part covers jQuery and AJAX. I was expecting a little more than two chapters about AJAX, but maybe more isn’t really necessary. After the first chapter in this section, he uses jQuery for all the examples. He mentions other JS libraries but recommends jQuery. I’ve “used” jQuery before, adding image galleries and things, but not modifying it or writing it myself. I was surprised at how easy it is to use jQuery and AJAX to interact with PHP.

I think this book was a good introduction to JavaScript and AJAX and would recommend it. I can’t come up with any cons to this book except the example that consisted of the ants song.

This book is not for complete beginners. You need to know HTML and CSS. It would be best if you’ve at least fooled around with JavaScript before and are familiar with PHP.


2011

Thank you to those who have donated to me for the To-Do List plugin in the past few months. I really appreciate any donations. They motivate me to improve my plugin.

One recent donation and feature suggestion was to implement AJAX so things like the dashboard widget will not reload the page when updated. I tried briefly to do this back in the summer but didn’t get it working.

I purchased the WordPress & AJAX ebook today so I can learn how to do that. I also plan to add new features and fix anything that isn’t working correctly on the plugin.

Aside from that, some of my plans for 2011 include a new design for this site, major revisions to my base theme, a free complete theme, developing new plugins, and continuing to share WordPress knowledge.


To-Do List Plugin Bug Fix 2.2.8

Download To-Do List Plugin v3.1.7Last Updated 05-10-2012

I’ve fixed an issue with the To-Do List plugin where completed items were not showing up using list view in the shortcode.


I will be unavailable in November

I’m participating in NaNoWriMo next month, so I won’t be responding to any comments or emails. There will also be no plugin updates during this time.

I will be back in December.