First page of the WordPress archive.

Just __return_* It

Posted by The Doctor on Apr 4, 2012 with No Comments | Short Link
in Functions, Tips
as , , , , ,

WordPress has a lot of helper functions built into its core. Some of these functions are obvious and some are obscure … and almost every one of them can be easily put to use.

A chat group I was in the other day lead me to looking for a set of these helper functions in the code we were discussing … I didn’t find them. Well, I did find them in use but I did not find where they were defined. Next stop, the WordPress core … and there they were.

Now, as the title may suggest I am referring to the following WordPress core functions:

  • __return_true() – returns the Boolean state of true
  • __return_false() – returns the Boolean state of false
  • __return_zero() – returns a value of zero (0)
  • __return_empty_array() – returns an empty array, as in array()
  • __return_null() – returns null (or void)

All of these functions have a very similar structure and were implemented at WordPress version 3.0.0, with the exception of `__return_null` which will be introduced at WordPress version 3.4 per their definitions in ‘../wp-includes/functions.php‘. For example, here is the code for `__return_true`:

function __return_true() {
	return true;
}

Why are these great helper functions? Simple really … they provide easy to remember, and very useful, callback functions for filters. You should not need to write your own return functions now, just __return_* it instead.

Tri-Account Security

Posted by The Doctor on Mar 16, 2012 with No Comments | Short Link
Last modified by The Doctor on March 26, 2012
in Tips
as , , ,

I seem to keep coming across various and sundry tweets, posts, and other references to security issues and attempts to “brute-force” access to self-hosted WordPress installations. The following is something I recommend if you have any concerns … or maybe just feeling a bit paranoid.

I call it Tri-Account Security ™. The idea is actually very simple and quite easy to implement. All it really requires is forming the habit of using three (3) separate accounts, each with their own specific purposes.

Let me break them down for you:

  1. The Primary Administrator
  2. The Primary Editor
  3. The Primary Contributor

To see the Note click here.To hide the Note click here.
NB: You will need three (3) email addresses for this … remember to set them up before following this idea through.

Actually you can have as many contributor accounts as you like with this system, but you should have at least one for this to work best. Let me explain how I recommend using these accounts.

The first account, The Primary Administrator, is the installation account. This account is just for the purpose of doing the installation. This account is also the one to use for upgrading; adding new themes; or, adding new plugins. Make the name relatively obscure; and, make the password very, very strong (not too strong to forget, but very difficult to guess … by human or machine). Also, never post with this account … ever!

The second account, The Primary Editor, is your publishing account. I would suggest a more common user name with a strong password; this account will be used to actually post content to your site. Although you shouldn’t normally need to actually post with the account it’s generally fine to do so.

The third account, The Primary Contributor, is your public facing account. Use a simple username, one that makes sense to see in the post meta details, such as the commonly used “posted by …” text. Also note this username, like all usernames in a default installation will appear as part of the author URL in a browser’s address bar. The password for this account can be simple, but should still be “strong” … but if someone breaks into it they really will not have that much access to anything so you can feel secure in making it very easy to remember.

Aside from the “strength” of the passwords recommended for each account above, I will not be going any further into their creation in this post (but maybe I’ll write one down the road) except to make one final suggestion for creating a strong password: use an appropriate amount of common words, or phrase, (without spaces) perhaps five (5) for the Administrator, four (4) for the Editor, and three (3) for the Contributor.

Now that we have the three accounts with a basic premise for each set out, let’s have a look at actually putting them to use in a couple of examples.

Example 1

Log in with your Contributor account and write the greatest post ever written … no really, go for it! I’ll wait …

OK, now that we have the post written, and you have clicked the “Submit for Review” button (notice how it does not say “Publish”); log out and log back in with your Editor account. Once logged in with your editor account, navigate to the Posts > All Posts Administration Panel and locate your greatest post ever (it should be at or near the top of the list, remember it’s great; you would expect it to be lost at the bottom of the page?!)

Now either using “Edit” or “Quick Edit” you can change the post from “pending review” to “published”… and now the greatest post ever written is available for the world of the Internet to read. Congratulations!

You may also notice the only author information readily available will be your Contributor ID; or in other words, your pen name … and therefore protecting the identity of both your Administrator account and your Editor account.

Example 2

You are about to write the second greatest post ever written (you did follow Example 1, right?) but notice there is an update that needs to be addressed. As a Contributor you really have no control whatsoever over the WordPress installation, its management, or its administration.

Oh, administration … we have an account for that. Simply log out of your Contributor (or Editor) account, and log back in with your Administrator account. Perform any updates and/or maintenance. Log out. Done!

Now, log back into your Contributor account and get back to writing the second greatest post ever written …

Remove Comment Form Website Section

Posted by The Doctor on Jan 17, 2012 with 1 Comment | Short Link
in Functions, Tips
as , , ,

From time to time an interesting Five-Minute-FixTM comes along that sparks a great reason to add another WordPress Tips post. The idea for this tip started with this comment at BuyNowShop.com: … how to remove the website section when leaving a reply/comment … The solution may be obvious to some and can be readily derived [...]

No-Title Sticky Post-Format Posts?!

Posted by The Doctor on Dec 9, 2011 with No Comments | Short Link
in Tips
as , , , ,

Making sure to test all of the combinations these three items can create.

Filtering WP Title

Posted by The Doctor on Nov 30, 2011 with No Comments | Short Link
Last modified by The Doctor on April 26, 2012
in Tips
as , , , , , ,

A recent recommendation, starting with WordPress 3.3, from the WordPress Theme Review Team reads: Themes are REQUIRED to use wp_title filter to filter wp_title() (RECOMMENDED), or pass argument to wp_title() (OPTIONALLY), in order to modify document title content This has been discussed, worked through, and for the most part sorted out … but there doesn’t [...]

Enqueue Plugin Custom Stylesheet

Posted by The Doctor on Nov 15, 2011 with No Comments | Short Link
in Tips
as , , , , , , ,

Now that is a bit of a handful to grab onto … but the code and concept is relatively straight forward and easy to implement. As I was recently updating some of my plugins in preparation for WordPress 3.3 I decided to better implement the style elements being used in these plugins. The current best-practice [...]

Start Using WordPress Beta

Posted by The Doctor on Oct 12, 2011 with 2 Comments | Short Link
Last modified by The Doctor on April 12, 2012
in Tips
as , ,

The basics, as a general guideline, on how to start using the latest WordPress beta version.

Do Not Display Comments HTML Tags

Posted by The Doctor on Aug 7, 2011 with 18 Comments | Short Link
in Functions
as , ,

A standard function found in many themes is the comment_form. This is a core function of WordPress that produces a standard comment form generally consisting of text fields for the name and email address and a textarea for the actual comment. You will also find there are some standard text outputs produced by this function [...]

Dynamic Copyright Revisited

Posted by The Doctor on Jun 13, 2011 with No Comments | Short Link
in Tips
as , , ,

An updated version of the dynamic copyright function found in BuyNowShop.com themes by Cais.

Reset Your WordPress Test Site

Posted by The Doctor on Jan 23, 2011 with 5 Comments | Short Link
Last modified by The Doctor on March 22, 2011
in Tips
as , , ,

How to reset your WordPress test site in three easy steps.