Codex

Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

Talk:WordPress Coding Standards

Ternary operatory

The ternary operator example is confusing. I'd say we simplify it like:

$alert = ("1.0.1" == $version) ? "The version is 1.0.1" : "The version is NOT 1.0.1";

Jalenack 08:09, 16 Jul 2005 (UTC)

You people and your real world examples. :) I say let's. -Kaf 01:08, 17 Jul 2005 (UTC)


include_once vs. require_once 
Learn the difference between  include_once and require_once and use each as appropriate.

I've never understood the big difference, and the two manual pages referenced are nearly identical. Woud the author care to elaborate?

From http://us3.php.net/manual/en/function.include.php - " include() produces a Warning while require() results in a Fatal Error." - Therefore the basic difference is that if you use require_once then processing will stop at that point if the file is not found, if you use include_once then processing will continue and a Warning will be output. --Westi 09:45, 20 Jul 2005 (UTC)

Ah, thank you. Maybe it would be helpful to just say that on the main page. Actually, I guess I'll just go ahead and do that.--Axlotl 18:58, 11 Sep 2005 (GMT)

Tabs vs Spaces

I prefer spaces to real tabs. jwz convinced me some time ago. Matthewsim 20:03, 8 Feb 2006 (GMT)

Me too. In fact I set typically set the vim hint
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
to make my tabs into spaces. I haven't looked into it closely as a theoretical debate but if we're voting, I vote for spaces. - Godblessthefreaks 05:49, 20 Jun 2006 (GMT)

Long blocks / comments best practices

I'm new here so if Wikipediesque boldness doesn't apply, forgive me. The page did said it wanted to be edited! While commenting long blocks is good practice, I consider breaking them into smaller blocks to be even better practice, so I edited the text to reflect that. Also I softened the warning against overcommenting because I've rarely if ever seen PHP code that I thought was too commented. (My own code occasionally is, I'm sure.)

Speaking of comments, I notice they're not mentioned. Could we paraphrase The Pragmatic Programmer, something to the effect that comments telling what the code does are rarely helpful, but comments explaining why something was written the way it was written are pure gold? - Godblessthefreaks 05:53, 20 Jun 2006 (GMT)


Single and double quotes

New here, so pardon the noise. The articles states that you need not escape quotes in HTML as you may alternate single and double quotes. Would it be better to stick with escaping double quotes to prevent PHP from trying to interpolate variables?--ScottPlumlee 18:12, 12 Sep 2006 (GMT)

Ok, scratch that, did some more reading and realized it's not really worth it.--ScottPlumlee 18:34, 12 Sep 2006 (GMT)

Welcome to Codex. Questions of that nature will get more attention if addressed to the wp-hackers email list. Thanks for the follow-up.
MichaelH (talk) 18:38, 12 Sep 2006 (GMT)

This link is referenced as stating that single quotes are valid yet there is no explicit mention of single quotes in the document. Mikeschinkel 06:56, 29 October 2010 (UTC)

Use braces to keep code maintainable

Lately I've been encountering more and more WP plugin code not using braces. Making chances or refactoring code becomes very annoying due to this lack of braces. This might seem trivial, but I've had several times in which somekind of bug was related to the lack of braces. So I took a quick look at the coding guidelines and noticed that it mentions the following: "single line blocks can omit braces for brevity"

Sure brevity is nice, but code will and shall change. By omitting braces refactoring or adding / removing code becomes a PITA and I would like to suggest to change this in the codex, so that my fellow developers are made aware of this issue as well. BjornW 2009-04-06

Class Names

The Coding Standards explicitly suggest lower case for function and variable names. It is silent on Class Names. Since 2.8 Classes are rather important, and the Coding Standards should reflect that. Jonknight73 10:40, 12 March 2010 (UTC)

Automated advice on code style and quality

Please also promote the use of tools as is proposed in http://wordpress.org/extend/ideas/topic/list-plugin-and-theme-quality Discuss each of them and with which parameter to run them on your code. Pander 11:46, 25 June 2010 (UTC)