Creating User API Keys with WordPress

Pro Blogging Tip: Advertising with WordPress

In the age of Professional Blogging, there are many ways to make money with your words. The most common is through advertisements. Some of the easiest way to make money are through targeted ad networks such as Google’s AdSense and Adbrite. You can guess, with the advent of advertising, came WordPress advertising plugins. I’ve got a winning combination of plugins and networks that you can use to help fund your blogging habits.

Networks

There are hundreds of advertising networks out there. Currently I use 3 modes to advertise:

  • Google’s AdSense
  • Share A Sale
  • Amazon Associates

You can consider this my full disclosure. I use all of these networks just a bit differently, and there are different plugins and widgets for each. Google’s AdSense is used for my in page/post advertisements. They are based and determined by the content and keywords for the page being viewed. This is where I use two of the plugins mentioned. I use the Share A Sale network to show the sidebar advertisements. This network pays per lead or per sale depending on the affiliate. I also use the Amazon Affiliates network for when I mention a book, dvd, or music. These pay our a percentage of each sale.

Plugins

Plugins are where the magic happens. It makes advertising with WordPress much easier than normal. I have 3 plugins I use to manage my advertisements currently:

  • Better AdSense Targeting
  • Advertising Manager
  • WP125

Better AdSense Targeting: This is one of my plugins that I use to help you target in your AdSense ads to your page’s content. What this plugin does is help you tell Google’s service know what content to pay attention to, and ignore, when determining your ads for that page. There isn’t a whole lot when it comes to configuration, just a few dropdowns and you are configured.

Advertising Manager: I have been using this plugin for quite a few years. Advertising Manager makes it easy for you to setup your ads quickly and display them even easier. In 4 steps you and have ads displaying on your site. My favorite feature is being able to call the ‘default’ ad by simply adding a shortcode in the middle of my post. View the plugin page to see more about the setup process.

WP125: This is a new plugin for me, and was pointed out by my friends over at Video Quick Tips. What this plugin allows you to do is setup an Image and Link to a 125px by 125px image for advertisement. You can also setup expiration dates, have it email you when an ad is approaching expiration, and allows people to click blank ad to contact you. So far this plugin has worked extremely well for me. I setup this plugin with my Share A Sale ads so I can rotate them in and out when I get more.

SEO Optimization

Part of using targeted advertising is having a proper SEO plugin. Currently I’m stuck on SEO Ultimate. This plugin is offering me the largest selection of tools and features to help me optimize this site for the search engines.…

Adding Featured Post Images in Thesis

Adding Featured Post Images in Thesis

You may have noticed that I have added a little bit of an enhancement to my themes lately, with the custom post thumbnails added to the to of some (soon to be all) posts. You may also be wondering how I did this. Well, you are in luck. Here’s how I did it.

First I started with a little tutorial over at ‘ThemeBig’ about Adding WordPress Post Thumbnails to Thesis. This was a great start but it had a few things added that I didn’t want like the teaser images and was missing something I found necessary which was the proper title attribute on the images. So here’s the custom_functions.php and custom.css additions you’ll need to make and what they do.

custom_functions.php

// Custom Featured Post Image code
add_theme_support( ‘post-thumbnails’ );
set_post_thumbnail_size( 700, 100, true );

function add_post_image() {
if(has_post_thumbnail()) { // Make sure we have a post thumbnail
if(is_single()) { // If this is a single blog post ?>

get_the_title())); ?>

The following two items Enable the post-thumbnails and sets the default post size.

add_theme_support( ‘post-thumbnails’ );

set_post_thumbnail_size( 700, 100, true );

Adding Featured Post Images in Thesis

The arguments you are using on the set_post_thumbnail_size are the image with, height, and ‘true’ tells WordPress to crop the image you provide. Since you are using Thesis, you should set the ‘width’ item (or the ‘700’ in this case) to the width of your content column. From here on out, the images you upload to your ‘Featured Image’ should be at least as wide as the width you have specified here to allow proper cropping.

The next thing we need to do is add some custom CSS.

custom.css

.post_image { margin-bottom: 1em; margin-left: 1em; float: right; }

The CSS is pretty self-explanatory.

Adding Featured Images

This is done from the Edit screen of a post. On the right hand side you should have a pod that is by default under the ‘Tags’ pod. It’s labeled Featured Image. Clicking that link to ‘Set featured image’ gives you a modal. Where you can either add your own new image or use and existing image from your Media Library. From here, you DO NOT want to insert into post but use a small link at the bottom that says ‘Use as featured image’. Once this is done, You can click ‘Done’ and now your post has a featured image. If you need more help on this you can visit the Post Thumbnails page in the WordPress Codex.…

Creating User API Keys with WordPress

Creating User API Keys with WordPress

After WordCamp 2012 in San Francisco, I started to realize how many people were using WordPress as a platform for their web based application. Well with web based application come API’s and with that, unique user keys. I’ve been working on such a service lately and was in need of setting up a quick script that assigns an API Key to a user when they signup on a WordPress site. Here’s the code, and a quick explanation.

user_email . timestamp();
$user_api_key = sha1( $pre_obfu );
update_user_meta( $user_id, ‘wpcronme_user_api’, $user_api_key );
}
add_action( ‘user_register’, ‘ck_assign_api_key’ );

Ok, so what we did was hook onto the user_register hook. This passes along a user ID. From there we can get all the information we need about the newly registered user.

So, what’s the next part:

$pre_obfu = $user_id . NONCE_SALT . $user_data->user_email . timestamp();

Creating User API Keys with WordPress

We’re making a string that’s unique to this user, this site, and this timestamp (important later). When creating User API Keys the important thing is that they be unique. With WordPress this is pretty easy in that, by default, an email address can only be assigned to one account. Using the user ID and the email address as part of the hash assures we don’t get a duplicate. You may be asking about the other two parts NONCE_SALT and timestamp().

If you are following best security practices you have added unique keys and salts to your wp-config.php file right? …Right?! Go do this now if you haven’t. Now, this is a unique string to your site, meaning that unless someone else has the same key as you, they can’t replicate the exact same User API Keys.

The timestamp call does one thing and it’s very important. The first 3 items are unique, and don’t typically change. If someone’s User API Key get’s missused, you need a way for the users to recreate a new key so the previous one is invalidated. This timestamp will allow the API Key to be different if you run the same function again after a user edit, or something of the likes (I’ll leave that code up to you).

So that’s it, quickly generated unique keys for new users in WordPress. Hope this helps someone out.…

WordPress Installation

WordPress Installation via Subversion

The installation process of WordPress has become easier and easier as web hosting providers create ’1-Click Installations’ for people to use, so why learn a new way to install WordPress? As a developer it’s sometimes important to use older versions during testing, or in some cases, unreleased ‘beta’ versions of WordPress to verify your plugins and themes are still compatible. WordPress makes older versions of the software available via their website, but you can save time by just using the following commands on your server.

To get a specific release version of WordPress you can use the following (replacing 3.3.1 with the version you want):

$ svn export http://core.svn.wordpress.org/tags/3.3.1 .

To explain,

svn

is the Subversion command.

export

The method allows us to get all the files without their revision history.

http://core.svn.wordpress.org/tags/3.3.1

Is the location of the source files. In Subversion ‘tags’ are major release versions.

WordPress Installation
The trailing ‘.’ character means to copy the files from the repository to the current directory.

If you want to get the source code with revision history use the ‘co’ method, instead of the export.

$ svn co http://core.svn.wordpress.org/tags/3.3.1 .

If you want to be on the ‘latest and greatest’ version of the codebase (called ‘trunk’ in subversion) you can use:

$ svn co http://core.svn.wordpress.org/trunk/ .

Choosing to use the trunk via a checkout or ‘co’ allows you to do an SVN Update to get new code changes made by the core developers (use the following while in the WordPress installation’s root directory):

$ svn update

For more information about using WordPress via Subversion you can hit up the ‘Installing/Updating WordPress with Subversion‘ page in the WordPress Codex.…