Contest: 3 free copies of the WordPress Bible [UPDATE]

Today marked the drop of WordPress 3.5 and I want to celebrate.

Tomorrow, I’m going to give away three autographed copies of the WordPress Bible. You have to be on Twitter. I apologize to those who have chosen to abandon Twitter, or have chosen not to participate, but it is the defacto communications medium of the 21st century and how I operate.

The book is a mix of advanced and beginner content. Therefore, I will do trivia. Trivia will have a beginner round, an advanced round and an intermediate round. All WordPress oriented. The winner is in my sole discretion and you will be required to provide your mailing address if you are selected.

WordPress core contributors are not allowed to participate in the beginner or intermediate round. If your name is on “the list” of 3.5 contributors, you cannot win those rounds. You can, however, participate in the advanced round.

The beginner round will consist of questions surrounding theme and plugin management with possible questions around usability and interface.

The advanced round (the only round open to core contributors) will be based on WordPress APIs, hooks and advanced WordPress development.

The intermediate round will mix both but the developer-oriented questions will be more common and basic and user questions will be more difficult.

You must hashtag your answers with #wpbibletrivia. Failure to do so disqualifies you for an answer.

The first answer I see that is correct is a correct answer. My judgement solely.

There will be 10 questions per round so pay attention.

The beginner round begins at 11am Central Time.

Share this on Facebook, Twitter or whatever your social media channel of choice is. The questions will be asked on my Twitter feed: @technosailor.

Good luck!

Update

The winners of the trivia contest were David Peralty for the beginner round, Kim Parsell for the intermediate round and Kailey Lampert for the Advance round. Well done, everyone!

Read More

rewrites

TUTORIAL: Building Custom Rewrite Endpoints in WordPress

Recently I concluded a sizable project that involved deep integration with an external API. I was responsible for creating content pages based outside of WordPress. To be clear, the pages would use an internal WP template, but all the content was generated using this external API.

In order to make this work within the WordPress Rewrite system and serve pages that WordPress knew how to handle in a non-traditional way, I had to tackle this in a multi-prong way: using the template_redirect as well as the built in Rewrite API.

Note: I’m not giving away the full sauce here as the project is non-open source. As well, I’ll be abstracting some stuff a bit. If you’re smart, you can fill in all the blanks regarding how to fully implement this.

First we need a base class:

1
2
3
4
5
6
7
8
9
10
11
12
13
<?php

class Base_Class {

  public function __construct() {
    $this->hooks();
  }

  public function hooks() {
  }
}

new Base_Class;

This is the base of pretty much every class I write as part of a plugin in WordPress. If you don’t follow Object Oriented coding practices, start now.

The next step is to register some variables with WordPress. Because WordPress is using the template_redirect hook to get the proper template files, you will often lose necessary query string variables, and you definitely can’t use them in an endpoint (i.e. /foo/bar) without WordPress knowing about them.

So let’s register them using the query_vars filter.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<?php
class Base_Class {

  public function __construct() {
    $this->hooks();
  }

  public function hooks() {
    add_filter( 'query_vars', array( $this, 'query_vars' ) );
  }

  public function query_vars( $qv )
  {
    $qv[] = 'foo';
    $qv[] = 'bar';
    return $qv;
  }
}

new Base_Class;

After this, we want to actually create some rewrite endpoints. In this example, I want to allow permalinks like /foo/content-slug/ and /bar/content-slug. With the following code that adds a rewrites() method to the class, and hooks on the generate_rewrite_rules filter, we can create these two endpoints. In our imaginary template, we would use get_query_var() function to handle logic for display purposes, but that’s outside of this article scope.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
<?php
class Base_Class {

  public function __construct() {
    $this->hooks();
  }

  public function hooks() {
    add_filter( 'query_vars', array( $this, 'query_vars' ) );
    add_filter( 'generate_rewrite_rules', array( $this, 'rewrites' ) );
  }

  public function query_vars( $qv )
  {
    $qv[] = 'foo';
    $qv[] = 'bar';
    return $qv;
  }

  public function rewrites( $rules )
  {
    global $wp_rewrite;

    $new_rules = array(
        'foo/([a-z]+)/?$' => 'index.php?pagename=wppage-holder&foo=' . $wp_rewrite->preg_index(1),
        'bar/([a-z]+)/?$' => 'index.php?pagename=wppage-holder&bar=' . $wp_rewrite->preg_index(1),
    );
   
    $wp_rewrite->rules = $new_rules + $wp_rewrite->rules;
    return $wp_rewrite->rules;
  }
}

new Base_Class;

Specifically, note the new rewrite rules and how they are structured. If those permalink structures identified above match these new rules, then we will pass the request on and use the template file designated for a page (that you do have to create in WordPress, by the way) with the slug ‘wppage-holder’. This can be done by designating a template file on the page edit screen or by naming the template as page-wppage-holder.php in your theme – again, outside the scope of this article.

If the permalink matches foo, we pass the foo variable on. If it matches bar, we pass the bar variable on. Logic on the other end left to you.

This is where I have to stop using this example, for client confidentiality purposes, but imagine what is possible now if you extend this and use the template_redirect hook to handle some custom redirects leveraging wp_redirect()?

Imagine. :)

Read More

Photo used under Creative Commons and taken by photologue_np

My Three Tiered System to Job Searching

Photo used under Creative Commons and taken by photologue_np
Over the past months, since I parted with WP Engine, I have entertained many inquiries about my availability for other full-time roles. And I literally mean many. It’s been a great problem to have, frankly, and I consider myself blessed to have these inquiries while so many others continue to struggle to find work.

I also consider myself blessed to work in a specialty field. WordPress consulting, you would think, is something that is extremely saturated. To a degree you’d be right. As a consultant, I turn away a great number of projects because, frankly, they amount to building sites with WordPress. There is certainly nothing wrong with that kind of work, but I’ve found over years of consulting that it’s important to be a specialist. To not be a specialist means to compete with everyone else on the same level and that reduces the quality and quantity of projects I can work on.

Instead, I focus on high-end WordPress integrations and plugin development. Complex things. I make a reasonable living doing things that there are only a proverbial handful of people who have the ability to do.

At the same time, I continue to entertain full-time job offers. There are some great ones out there, but many just don’t interest me. I have a three-tier (God, as a beer advocate, I hate that term but in this case it fits) filtering process I go through when entertaining job offers. I think this three-tier system should apply to anyone and everyone looking to work in any field, and so I’ve decided to share it.

Is the money right?

We all need to live, and I’m not one who believes the starving artist mantra is necessary a healthy one. If you’re good at what you do, you should be compensated appropriately. Personally, I don’t think anyone would have an argument in this area. A seasoned DBA should not be making $50k, for instance.

As a consultant, I’ve come to have a lifestyle that I’ve worked very hard to achieve. I’m going to be 36 soon and I’ve been married, had a kid, worked on startups, lived in expensive areas of the country and cheaper areas of the country. I’ve built a lifestyle that no job should ever take away.

We all have our “number”. Know for yourself what that number is and stick to your guns when determining if you want to work for someone. Simply not enjoying your current job is not a valid reason to take less than what you’re worth.

Does the job make you want to jump out of your chair and SQUEEEE?

IF it doesn’t, walk away. You should love every minute of what you do and jump out of bed in the morning (after a reasonable period of off-time) eager to see what new innovations, products, ideas and relationships can be achieved.

To do less is selling yourself short. Never settle for anything less than awesome. Some inquiries, for me, have been awesome on the money side but I feel so dull and want to pull each fingernail out of it’s socket just thinking about it. Read my lips! I will never work in a cubicle again! Ever! Don’t ask!

Recently, I spoke with a company who demoed some of their products (WordPress-based) they were working on. They showed me tools that they had built in that allowed their 300some entities they managed to do amazing things (things I tried at b5media years ago [and failed]) in easy, intuitive ways. All I wanted to do was scream “OMGYESPLEASE!” through the phone.

If you don’t have that reaction, think really hard about whether you want to commit.

What’s the social impact?

I’m not a tree-hugger, but one thing I can say is that consulting is both awesome and terrible. I get a lot of benefits by working for myself. But that’s kind of it. I get lots of benefits from working for myself. No one else does. Just me. My world isn’t a better place because of my work. My wallet is happier, but the world around me still sucks.

So when I talk to companies about working for them, I want to know that my work has a positive effect on the world around me. Whether it’s education or environmental; sustainability or fitness; empowering others or enabling positive social change – it’s an important facet in what I look for.

Does the company reward employees for not wasting energy and taking the bus or riding a bike to work? Does the company offer some sort of subsidy or reward for green energy consumption? How many women are employed as engineers?

How does working for Company X positively affect the world around me?

I think these three things are co-equally important for anyone, not just me. I hope so, anyway. We shouldn’t hate what we do, ever. We choose what we do. Choose wisely.

Read More