So it became apparent to me as I kept asking people and searching the WordPress Codex where such and such function was defined or used. Now, I have a process that I have refined over time that I want to share. It may not be the best process but it works and works well.
First, as with any web design or development, you need a good text editor. I use Notepad++ since I haven't forked over for a Mac (anyone who wishes to buy me one, please feel free!). Plus Notepad++ is free!
So for example, say I am looking over nav-menus.php from the WordPress core. On line 67, I come across a function called wp_get_object_terms(); So if I want to know what this is, I do one of two things or sometimes both.
- First, search the WordPress Codex.
- Second, search the WordPress Core Code (online or off).
In this example, the Codex has good information. However, sometimes (though rare) you will see that the Codex is not completely filled out or brought up-to-date or easy to understand without seeing the function.
With the second option, I typically used Yoast's PHPXref (ensuring that I am searching the correct WordPress version) until I was on a plane recently and refused to pay the $10 bucks for wifi since I had everything on my laptop. So then I turned to my text editor. (In the past, I used Windows XP with indexing to find such files; however, I'm now running Windows 7 and the search functions are horrible [and I haven't taken the time to try to figure out what's wrong with Windows 7 search ability or how to improve it]).
So if you open Notepad++, the third menu item is Search. If you click Find in Files a search menu will appear.
If you hit Ctrl+F as I often do, then select the tab that says Find in Files. Fill in function wp_get_object_terms in the Find what: input box, since I want to find where it's defined to see its accepted variables so I can use it. Then I select the file structure that I want it to search, so you could select the entire WordPress install so it searches wp-admin, wp-includes, and wp-content or just pick one of those folders.
A quick search reveals that this function is defined in taxonomy.php in the wp-includes folder. The great thing about the search is that it typically returns the entire line that its found, so NotePad++ told me what I was looking for:
function wp_get_object_terms($object_ids, $taxonomies, $args = array()) {
.
So if I want to see the entire function to try to determine what the function does or returns if anything, I need to open the file. While Notepad++ finds the function, it's not a simple click and open that file. So I have to navigate to the file, open it and go to line 1778 to see the full function. One of the great things about WordPress is that there are a lot of comments informing the user what the function does. For this one particular function, there are 30 lines about this function including the following vital information:
* @package WordPress * @subpackage Taxonomy * @since 2.3.0 * @uses $wpdb * * @param int|array $object_ids The ID(s) of the object(s) to retrieve. * @param string|array $taxonomies The taxonomies to retrieve terms from. * @param array|string $args Change what is returned * @return array|WP_Error The requested term data or empty array if no terms found. WP_Error if $taxonomy does not exist.
This tells me that $object_ids is either an integer or an array of integers; $taxonomies is a string or an array of strings, and $args is an array of strings that can affect what is returned. It also tells me that this function returns an array or a WP_Error message.
So now, there's an offline version or way to search your WordPress files for function calls, function definitions, etc.