WordPress - Help Reading php Code

WordPress is written in You will need to know some of each of these to reverse engineer much of anything. This page deals with php.

I have been programming for a number of years and, basically, I can read almost anything. To write "new" code, I normally just look around, copy something that looks close, and make a few mods. However, I have found WordPress particularly challenging. Normal php is pretty easy (it is almost c-like), but ... well, that is why this page exits.

Basics | Arrays | Functions | WordPress specific conventions | if statements | Objects


echo writes a string to the "current output" which is the newly created web page. Unfortunately, the "current" web page is frequently replaced with another page before you are able to read your debug messages.

Careful - single and double quotes give different results.

String concatenation is always a problem.

As far as I can tell, spaces are never required before or after the period.

All php code is enclosed between tags, any text not between those tags is copied directly to the web page

If you want to stop a function, use return, not exit.


Arrays have their own rules and a number of functions.

To remove a single element from an array, use the following


By default, all parameters are passed by value (meaning that a copy is passed). If you want to be able to edit the variable, then it must be passed by reference (meaning that you want to pass a pointer). In php, an ampersand (&) indicates that the reference to (address of) the variable is being passed.

The ampersand (&) can be used in either the calling statement, or in the function definition (preferred).

For instance, if you want to be able to edit an array's contents, then it must be passed by reference.

Additional info: Function arguments Returning values

WordPress specific conventions

There are a few very confusing commands used everywhere. After a while, I discovered that they are a part of the WordPress library.

These functions translate the text into the appropriate language.

These are how the functions are implemented There are a lot more, but these are the ones I saw everywhere.

* if * statements

Most of the php code I've seen uses standard c-syntax for if statements. While that works, I suggest ALWAYS using the block format. Either else if () or elseif () can be used.

Some files use an alternate colon syntax (instead of curly braces)

This immediate or in-line syntax is also used a lot - a value is returned based on the conditional statement (inside the parentheses). The first element is returned (or executed) if the condition is true, otherwise the second element is returned.


In most of the code I've seen, all the function names are global. However, objects allow you to encapsulate those and leave only the instance name as a global. In most object oriented languages, the member methods can call each other without any special syntax. However, php requires $this-> When calling a member function from outside the instance, use

Author: Robert Clemenzi
URL: http:// mc-computing.com / ISPs / WordPress / php_code.html