Learning WordPress : files and database

There are a numerous blog posts and forum discussion about WordPress.  However you can read all of them back and forward and still not know how the system works.  If you seek the real understanding of WordPress, there are two and two things only that you need to go through : its database scheme and its source code files.  And it’s not as hard as it might seem.

While you can download WordPress source code and go through each file using your preferred text editor or programming IDE, that might not be the best of fastest way to learn it.  Instead, I’d recommend a web-based interface available at PHPXref.com .  It might not necessarily have the latest version of WordPress, but usually it’s not that far behind.  For example, it currently features WordPress 2.7, with WordPress 2.8.1 being the latest version available for download.

WordPress at PHPXref.com
WordPress at PHPXref.com

The coolest things about such an interface are syntax highlighting and cross-reference within WordPress source code, as well as links to PHP manual for native functions.

WordPress database scheme (ERD)
WordPress database scheme (ERD)

As for the database, you have three things going for you here.  Firstly, WordPress database scheme is very small, simple and straightforward. It’s only 10 tables with just a few fields each.  Secondly, it’s very well documented.  And thirdly, when you do a fresh installation of WordPress, you have some sample data in your database, which helps to understand what goes where.  You’ll find one post and one page (to see the difference), one comment (to see how those are linked to posts), one category, one user, and a few links in the blogroll.  Just inspecting that fresh database will clear up your head and sort things out.

Spending a few minutes going through the source code and understanding the database scheme is very worth it.  Firstly, you’ll better understand what WordPress can and cannot do.  Secondly, you’ll get inspired (that I can pretty much guarantee you).  Thirdly, you will automatically get the understanding of how almost each and every WordPress plugin works.  Not in details, but you’ll be able to reverse engineer them in your head easily.  And fourthly, you’ll become much more efficient with WordPress customizations – you’ll just know where to put things and how to better change stuff.

Forget the URL

Just yesterday I was talking with a few people about the Web and how things are changing, and the subject of URLs came up.  And I shared my opinion on the matter – URLs don’t matter.  Before you start arguing, I want to make it clear that I do understand that there are exceptions to every rule and no assumption stays true forever.  But on the other hand, that’s what I believe.

I think every Web surfer answers this question to himself at certain point in time.  Are all these URLs that I visited, searched for, and bookmarked over the years matter?  And I suspect that quite a few of those people will answer as I do – “no”.  I had a sneaky suspicion for some time, but it was delicious social bookmarks web service that made me confident about this.

The thing with delicious is that initially it was available at http://del.icio.us .  And as you might guess, there quite a few problems with this URL.  Firstly, the word “delicious” is not in the active vocabulary of most non-native English speakers.  Secondly, even those who know the word, have troubles spelling it correctly.  Thirdly, those who know how to spell it, never seem to guess where to put the dots.  And fourthly, the logical line between the meaning of the word “delicious” and a social bookmarking web site is vague at best.

However, that didn’t stop del.icio.us from becoming the most popular social bookmarking web site on the Web.  And that was when I became confident in that the URLs don’t matter any more.  Very few people will remember them.  Most people will find the site with the help of a search engine.  And those who are really interested in getting back to it, will bookmark it.  It’s that simple.

What about brand names, you ask?  Brand names are important.  But you can avoid linking brand names to URLs.  What about people’s names?  Only a few will remember them.  What about original, non-standard domain names?  Only few of those will be remembered, the rest will search and bookmark.  Why do I have mamchenkov.net domain name then?  Because it was available and because it links to my name nicely.  If it wasn’t there, I’d use something else.  And, in fact, I did use a couple of other domains before I registered mamchenkov.net .

Why all of a sudden I started talking about it?  Because today I came across someone else saying practically the same thing – “Do URLs matter anymore?” article over at CNET News, and I quote:

People still try to trade the most simple URLs for hopeful hundreds of thousands. They will still line up in the hope of getting a vanity URL from Facebook.  But don’t most people simply go to the little search box, type in the name of what they’re looking for, and search?  If it’s something they want to go back to, they’ll bookmark it. But they won’t remember what the URL is. For the simple reason that they don’t need to.

WordPress 2.9 media features poll

Check out this poll for media-related features for the upcoming WordPress 2.9.  This is your chance to influence the priorities.  Features on the menu are:

  • Additional Media Filters, which would help you pick media that was used recently, or more often, or is your favourite, etc.  I don’t find it very important for my usage scenarios, because I rarely re-use media files in other posts.
  • Basic Image Editing, which will allow things like crop, rotate, and resize.  Even though I can use standalone image editors, I know of quite a few non-technical people who would appreciate basic image controls.
  • Better Media Settings, which will provide more defaults and more options to change for each upload.  I have enough options for my media usage already, so I don’t find this to be of high importance.
  • Bulk Media Import API, which will be appreciated by web development companies and such.  Anything that helps automation and bulk processing is A Good Thing.  Also, with more attention to media functionality in WordPress, I suspect some people would prefer to host their own images and videos, rather than to use third-party services (YouTube, Flickr, and such).  Moving all that content into WordPress with API is a dream come true.
  • Custom Image Sizes, which will allow for more and truly customized image sizes.  While I can understand the importance of this for some people, I suspect that most are satisfied with what is there now.   Plus there is a range of plugins, and workarounds available that make this problem of less importance.
  • Easier Embeds, for content coming from third-party services like Flickr, YouTube, and such.  This is something I’d really love to see done.  Currently, there are plugins to cover most cases, but I believe a built-in way is in order.  Plus plugins often miss important parts of the site, such as feeds.  And plugins rarely work well with other plugins.  If this functionality is in the core, or in a plugin, which is a part of main download, extending and re-using such functionality would be easier.
  • Media albums, as in standalone galleries, rather than media galleries attached to a post.  That’s something that a lot of people would find useful.  For example, bringing all YouTube videos from all your posts into a single gallery would be awesome.
  • Media metadata, which is adding categories and tags to media files.  Well, while it sounds cool, I think it will add more confusion to people.  With such functionality, WordPress will become more of a generic content management system.  For example, together with media albums, you’d be able to use WordPress as a pure image gallery application.
  • Post thumbnails, which would associate an image with your post.  I think this functionality is only useful to a small bunch of people, and it is currently available via plugins.  I don’t think it’s worth putting it in the core.
  • Revised Media User Interface, which would improve the experience in the media editor.  I don’t know how many people find it difficult to use actually, because it works like a charm for me, and I find it easy to explain to non-technical users as well.  But if there are ideas on how it could be much improved, then why not.

If you have any opinions on the above, please vote in the poll first, and then share them in the comments second.

Running simultaneous Firefox sessions with different profiles

The more and more I use Firefox, the more add-ons I install, and the heavier it becomes.  Recently I got to the point where I am annoyed by all the heavy weight functionality, but cannot remove it complete because I need it occasionally.

The solution to my problem turned out to be pretty simple, even if it required some Google searching and IRC chatting – multiple profiles.

By default, when you run Firefox for the first time, it created a default profile to store all your stuff – saved passwords, bookmarks, add-ons, etc.  However it is possible to create more profiles and separate things a bit.  For example, I currently have three profiles:

  • Browser.  I use this one for generic browsing stuff, such news reading, email, etc.  Firefox add-ons for Gmail, Google Calendar, YouTube, Flickr, and other major sites I used frequently are installed under this profile.
  • WebDev.  I use this one for my web development needs.  Web Developer, Firebug, Live HTTP Headers, and any other add-ons that help me do my job are installed under this profile.
  • Default.  I keep this one clean and empty.  Sometimes I want to see how  site behaves in the browser with default settings – for this I use the Default profile.

Creating this profiles in very easy.  As per Firefox documentation, all you need to do is close all current Firefox windows, and then run Firefox from command line with -ProfileManager parameter.  A small window will popup that will give you options to create, rename, and delete profiles, as well as select with which profile to start the new session.

The problem that I came across was running several Firefox sessions in parallel, each with its own profile selected.  I could easily select the profile for the first session, but when I was starting up the second session, it would just reuse the same profile from the first session.

The solution to this problem is either setting MOZ_NO_REMOTE environment variable to 1, or specifying -no-remote parameter on the command line.  The -no-remote parameter on the command line seems to be a recent addition to Firefox, so if it doesn’t work yet for your version of the browser, you’ll need to fall back on to the MOZ_NO_REMOTE environment variable.

So, if you have a recent Firefox version, you need to run (updating your desktop and menu shortcuts seems like a good idea):

[user@host dir]$ MOZ_NO_REMOTE=1 firefox -ProfileManager

If you want to start Firefox with specific profile (e.g.: DesiredProfile), you can do so with

[user@host dir]$ MOZ_NO_REMOTE=1 firefox -P DesiredProfile

Alternatively, you can export the variable globally, by adding the following line to your .bashrc file

export MOZ_NO_REMOTE=1

If you have a recent version of Firefox, then the command changes to:

[user@host dir]$ firefox -no-remote -P DesiredProfile

Other things that you might want to keep in mind are:

  • Some add-ons will be common between your different profiles.  For example, I want to have my delicious bookmarks available to me everywhere.  For these cases, you’ll need to install the same Firefox add-on to every profile that you will need it at.
  • Some bits of configuration (such as custom keyboard shortcuts, for example), will need to be configured in each profile separately.
  • You might want to have a different Firefox theme for each of your profiles, so that it’s easier to see where you are visually.

WordPress dynamic sidebars : take it easy with widget control

One of the coolest things about WordPress is a dynamic sidebar. Dynamic sidebar is a special are defined by a WordPress theme, where widgets (blogroll links, recent comments, related posts, etc.) can go.  The beauty of it is how simple it is for the theme author to define and style such an area, and how simple it is for the theme user to configure which widgets go where.  One line of code for the theme designer, and a user-friendly administration interface with drag-and-drop support for the end user.

As simple as it is, I’ve seen it abused by theme authors one too many times.  Consider an example (borrowed from a really nice theme in the wild, which I won’t name):



What happens here is the following: in line 3 we check if this version of WordPress supports dynamic sidebars (these were added in WordPress 2.2.0, if I remember correctly). If they are supported, we insert all widgets that were dragged and dropped into ‘east_sidebar’ dynamic sidebar, using WordPress administration.

Now for the tricky bit. If the function does not exist or something went wrong while displaying the widgets, we fall back onto some defaults. In this case we show the list of categories.

What’s so tricky about it? The trick bit about it is the return value of the dynamic_sidebar() function. It returns a boolean value. True if the sidebar was found and called, and false if sidebar was not found or was not called. This “was not called” actually means “failed to find at least one proper widget”.

What happens in practice is this. You find this nice theme that you want to use for your blog. You install and preview your site. Everything looks good. The sidebar looks good too, but you don’t particularly like the selection or the order of the widgets. So you go to the administration interface and what do you see there? An empty sidebar. Instinctively, you drag-and-drop a widget into the sidebar. Refresh your site and you see something totally unexpected. The sidebar that had a bunch of widgets now only has one – the one you drag-and-dropped. Weird.

That is because when you installed the theme, it registered a new sidebar, which is by default empty. When the sidebar of your site is displayed, dynamic_sidebar() function returns false and the theme falls back onto default widgets in the theme. Once you have at least one widget dropped into sidebar, that doesn’t happen any more and your lonely widget is displayed now.

That’s not a big problem with simple themes, which have only one or two dynamic sidebars. However, more complex themes with four, five, six, and more sidebars become annoying. Because there is usually some default pre-selection of widgets for each of those sidebars, and in case you don’t like it, you’ll need to do a lot of work in that administration.

Even worse, if you want to leave some of those sidebars empty. If there are defaults set in the theme, the only way for you to silence the sidebar is edit the theme source code. In the example above that would removing everything from line 4 to line 12. If you have more than one sidebar that you want to silent, you’ll need to repeat the procedure for every one of them.

So, what’s the solution? What’s the right way? To be honest, I don’t know. From the point of view of somewhat experienced end-user, I’d prefer no default widgets in the theme source code. Let them come up empty by default – I’ll drag-and-drop whatever I want using the user-friendly administration. On the other hand, from the point of view of non-experienced end-user, empty sidebars might confuse the heck out of me. I need to know about widgets to solve the problem, and unfortunately not all WordPress users do. Also, I guess it’s a bit harder for the theme authors to promote their themes if they come up with empty sidebars once installed.

One solution that might work is a theme option. Show default widgets by default, but allow to silence them all from the theme controls. That would work as a compromise and avoid unnecessary source code editing. Also, I think it would be pretty straight forward to implement (check for the value of the theme option instead of the return value of the dynamic_sidebar()).

What do you think?