Dougal Campbell's geek ramblings

WordPress, web development, and world domination.

WordPress Code Spelunking

Earlier today, I finished up a WordPress plugin that I’ve been working on for a client.  Without divulging too many details, I’ll say that it wasn’t a huge project, nor was it overly complicated, but it was interesting. One fun thing about working on projects for clients, is that it often gives you a chance to explore areas that you might not have looked too closely at on your own.

For example, some of the areas of WordPress (and PHP in general) that I researched and learned more about were:

I used a combination of the links above, other articles I found, plus some good old exploration in the WordPress core to learn more about these topics. Exploring the core code was most helpful in learning about WP_Http, wp_upload_bits(), and some extras for wp_insert_post() that aren’t documented on the Codex page.

Digging around in these corners of the code can be much like spelunking. You’re digging down into places never seen by most people, and often finding little gems that you suspected might exist, but you weren’t sure until you actually saw them. If you haven’t poked around in the core code lately, maybe you should. I usually prefer to use command-line tools like grep and a text editor. But the online WordPress phpdoc xref is a nice way to look at the code, too.

About Dougal Campbell

Dougal is a web developer, and a "Developer Emeritus" for the WordPress platform. When he's not coding PHP, Perl, CSS, JavaScript, or whatnot, he spends time with his wife, three children, a dog, and a cat in their Atlanta area home.
This entry was posted in WordPress and tagged , , , , , , , , , , , , , , , , , , , . Bookmark the permalink.

14 Responses to WordPress Code Spelunking

  1. Otto says:

    grep kills small animals.
    ack kills and eats them.

    For straight speed coding, generally I use a text editor with a global directory search built into it. TextPad on Windows, for example.

    When doing more involved PHP development, I use an IDE. I’ve been liking Eclipse with PDT lately. Very handy to be able to point at a function call, press a button, and have the IDE take you straight to that function, even in another file. Far less typing and searching that way.

    • Dave Doolin says:

      Otto, I’ve been using Aptana Studio, which is built on Eclipse.

      I have a love/hate relationship with Eclipse, going back at least 10 years. Aptana seems to configure everything about how I like. v2 has the PDT built in, looking forward to checking it out (more spelunking).

      Also, I ran across your blog a month or so ago. Very nice. On my hit list for digging around in.

  2. Dave Doolin says:

    Nice.

    I’ve been caving off and on since 1977. Totally agree that poking around in code is like caving.

    Need to do a little WP code exploration myself.

  3. Anne says:

    What is the plugin used for? Your mind is intuitive judging from the “… often finding little gems that you suspected might exist, but you weren’t sure until you actually saw them.“. I always enjoy when such matters happen to me, like a wake up call sometimes. A new one for me: spelunking.

    • Dougal says:

      I can’t divulge details of the plugin right now. For one thing, it’s not quite finished yet (I have to make some enhancements/fixes based on feedback from the initial review). Plus, it’s work for a client, and though I’m not technically under NDA, they own the code by contract, so I’d rather have their blessing before discussing it.

      And while I understand curiosity about what the plugin might be for, it was really just a backdrop to the main point of my post, which is that working on someone else’s project often leads you to explore interesting areas that you might not have looked at otherwise.

      While this particular project lead to me to investigate the things I mentioned above, other projects have similarly lead me to other areas. For example, I could have talked about a project that had me digging deep into the WordPress eXtended RSS (WXR) export file format and parsing HTML using phpQuery. Or a non-WordPress project that had me creating a lightweight MVC PHP backend, with a jQuery frontend, and AJAX in-between (plus a lot of RSS parsing with SimplePie).

      It’s not the specifics of this particular project that are important. The important part is that it lead me to once again step out of my comfort zone, expand my horizons a little bit, and learn something new. :)

      • Joel says:

        Using many of the same pieces you’ve mentioned here, so could guess at the type of project. Thanks for bringing some new functions to my attention too.

        Regarding the XML-RPC, would you recommend using this as a mechanism for secure data delivery to paying customers? Can’t think of a better person to ask.

      • Anne says:

        I like very much your last sentence (in your reply to my comment.) I surely rely to that too. And if it’s a unique/custom work for a valued client then the privacy can be expected…

  4. Donncha says:

    I don’t think “apt-get install ack” is the same ack talked about above is it? Man page says it’s a “Kanji code converter”, nothing to do with grep or killing animals!

    • Dougal says:

      The package they’re talking about is named “ack-grep”. I made the same mistake :)

      Description: grep-like program specifically for large source trees.
      Ack is designed as a replacement for 99% of the uses of grep. ack is intelligent about the files it searches. It knows about certain file types, based on both the extension on the file and, in some cases, the contents of the file.

      Ack ignores backup files and files under CVS and .svn directories. It also highlights matches to help you see where the match was. Ack uses perl regular expressions.

      • Donncha says:

        Thank you! Just installed it and will give it a go!

        BTW – I clicked the comments link from the “new comment” email and didn’t see your reply. I had to reload the page. Unfortunately I don’t know if the page was cached by Chromium or your server but I had closed the page after I left the comment yesterday.

Leave a Reply

%d bloggers like this: