Category Archives: Wordpress

Wordpress coding

Broken French

Hier, j’ai mis à jour à WordPress 3.0 et remarqué que, malgré les avertissements sur le Web, mon fidèle AHCommentCentral travaillait encore sur OK. Je n’ai pas fait quelque chose pour les sources depuis, peut-être il ya 4 ans.

J’ai vu aussi que j’ai encore une ancienne version du thème actuel («Simplish): J’ai été réfléchir si je dois faire une mise à jour: cela nécessite une certaine concentration avant et en arrière que le thème actuel eu quelques modifications personnalisées. Pas vraiment ce que je trouve que je ferais tout de suite.

Sinon, je pourrais mettre mon thème xvisionaryx, qui est un thème que j’ai utilisé pour une courte période (moins d’une semaine) après beaucoup personnaliser le thème d’origine visionnaire. Je ne pouvais convertir en un «Wordpress 3.0″ thème, mais une fois de plus, je suis hésitant faire car elle nécessite la création d’un environnement de test. Mon serveur linux («Elsie») a été hors service depuis que je suis éloigné de NS.

Ainsi, le résultat net semble être le «statu quo», ce qui n’est pas l’évolution future prévue, les mises à jour de prudence et de lumière annonce. Sonne comme l’étoffe ordinaire.

update: Google Translate is the new Translate.

A public service announcement

So, yesterday, I noticed that the WordPress download site was already seeded with the new 2.7 version, while the official blog was still yawning about the RC2 of that version. For no particular reason I decided to deploy it. I’m proud to announce that AHCommentCentral still works as promises, although (thanks to the different styles used in the Settings screens), it looks a kind of boring. I thought the ‘zebra-ed’ row look, was a lot more interesting.

The UI is an improvement: it does remind me of NucleusCMS at times. The graphics, and particular the colour scheme seem to be taken from that other software I used a long while ago. There was never a real reason to move to WordPress, except that at one time (a long time ago), when Alfons hosted this on Doubtful, MovableType became less of an option.

And if time will serve me right, I might even look into updating AHCommentCentral. Who knows.

Oh. Yeah: with a new WordPress, I thought it was also time to move on from Varchar, the other theme heavily based on the excellent PlainText theme (screenshot) by Scott Wallick. I thought Simplish looked excellent on mobile devices like the iPod Touch and even on your regular wide-screen monitor for your Windows, Linux and Mac freaks. Have fun and on for the 6th year. If you’re curious about the previous layouts: 2003 (a customized MovableType theme (handcrafted: look at that 2 column section), 2004, 2005(last year Doubtful-hosted), 2005 (self-hosted) (Theme: GreyAll), 2006 (PlainText-modified) and 2007 (Varchar, heavily based on PlainText).

Update 1: Some minor cleanup in the categories section.

Update 2: I see that WP 2.7 now supports automatically closing of posts. This was a feature I was planning for AHCommentCentral but which I decided against to because I didn’t see a use for it.

Do Update Now;

Just a couple of minutes ago, I was looking through the wp_posts table and thought enough was enough. There’s a thread over at WordPress where users have been complaining about the bloat and where developers have shrug it off with ‘Space is cheap’. Or, ‘You can delete it easily’. Think of the queries, think of the queries!

First off, there’s a setting you should set in your wp-config file:

define('WP_POST_REVISIONS', false);

To check (and compare) how many revision entries your wp_posts table has:

select
count(*),
post_status,
post_type
from wp_posts group
by post_status, post_type;

You can delete the bloat by issuing:

delete from wp_posts where post_type = 'revision';

If you have access to SSH, you should check the main wordpress folder: since moving to version 2.4, I’ve seen files called ‘core’ in that directory. These are (literally) core dumps and they are huge. Obviously, WP crashes the server at times (I feel sorry for my host): so much for ‘light-weight’ or ‘state of the art’. Oh wait, I can hear the punch-line, what is it?

Oh yes: “Code is Poetry”.

A stump

Earlier, A Tree stumpI upgraded this blog to the latest WordPress version and found out that it’s not entirely bugless (that is, besides the validation problems of some portions of the generated output, as pointed out by Shelley). Some general notes follow:

The Media Library is indeed a welcome change: in previous WP versions, managing your files was a pain in the rear-end. However, the upload “dialog” (which is a JavaScript ‘modal’ screen) has ‘update/refresh/invalidate’ issues. Many times, the screen shows garbage1. File uploads don’t appear to be working on Opera, at all, showing cryptic errors like ‘Specified file failed upload test’. Before you upload any images, be aware that you may wish to change the default width/height for generating thumbnails, particularly the checkbox, obscurely named ‘Crop thumbnail to exact dimensions (normally thumbnails are proportional)’. [You want to uncheck this option if you don’t want ugly re-sized thumbnails].

The admin interface overhaul, purportedly done to make it easier to find your posts and settings, is still as unfriendly as it was before. For example, it makes no sense to save the ‘visual editor’ setting in a user’s profile (you should be able to set it in the general Writing settings and then allow users to override it in their own profile). The same is true for settings for some of the Media Library stuff: the option to use link ‘URL’ vs. ‘Page/Post’ for images and that, should definitely somewhere in the Writing section (You may notice that all my mp3 samples and images redirect to a page/post first). And while we’re at it, I can’t stand the ‘autosave’ of posts and of course, you can’t turn it off in the settings.

On the overall, the release feels ‘patchy’ and rough at the edges: from what it appears, the only good change that this release brings is an excellent media-manager. Things still look unorganized: for example, how come you (still) can’t tag images and pages? I have the impression that this will require a rewrite of the codebase. Meh.

1 That is, using Firefox 3. On FF2 things seem to go OK.

Me count(*)

I just finished upgrading to WordPress 2.3: so, curious as any developer would be, I took a look in the WordPress database definitions and noticed that three new tables were added. All of them take care of categories and (the new) tagging system. This means, Wp_Cat is out and has been replaced with wp_terms: the actual distinction (i.e., which terms is a category and which one is a tag) is now made in the the wp_term_taxonomy table.

I have issues with that last table because it has a count column (to track the number of posts). This is the second table that has a count column (earlier): I mentioned before that version 2.0 introduced a comment_count in the wp_posts table. Why not make use of the regular aggregate functions (like the standard COUNT(*))? After all, these aggregates are generally highly optimized functions (written in C) for tables with the same primary key(s). Also, as a good database designer, during database design you should take the use of aggregate functions in account when setting up your tables structure.

Notice that count of posts for a tag/category can be done simply by:

select count(*),
p.term_taxonomy_id,
q.taxonomy,
t.name
from wp_term_relationships p,
wp_term_taxonomy q,
wp_terms t
where p.term_taxonomy_id
= q.term_taxonomy_id
and q.term_id = t.term_id
group by p.term_taxonomy_id,
q.taxonomy, t.name

Sure: a query on that same table with that count column may look as easy as ‘select count from wp_term_taxonomy’, but remember, it (always) takes an extra write to put a number in that table (via a regular UPDATE). If your transaction on that table ever failed, your fancy report will most likely report wrong numbers.

I forget

I forgot that there was an update for WordPress, followed the regular procedure. I forgot more: while copying data over from one directory to the other I noticed that I missed too many files: Uh, I missed the -R.

Then after logging in I saw I had forgotten to turn off the plug-ins, something that is highly recommended before you even do the upgrade. I think I forgot this the last time too, to find out that it doesn’t really harm anything to leave them on. I guess, it depends on the scripts you use.

And last but not least: there are so many new things in 2.2 that even I haven’t found them yet (that is, unless you look at WP’s bugtraq pages). Don’t ask me to update CommentCentral just yet.

Abug.

There’s a bug in the latest WP version that apparently puts extremely low numbers in the ‘attachment’s’ post_parent field: I haven’t figured out why this happens, but my suspicion is that the defect is in the update query in either a post or attachment1.

That said, it makes totally no sense to tie attachments to posts.

1A-Ha. It’s the Autosave.

WP 2.1

Right: I did a WP 2.1 update on a test site on one of my servers at home and, looking at all these superlative comments how WP 2.1 is going to change your life, I’m going to say it: I’m underwhelmed. The good news is that AHCommentCentral appears to be working quite OK, and I’ve updated the plug-in’s page accordingly.

  • WordPress 2.1 feels slow and bulkish.
  • The Dashboard page now appears to be loading the ‘WordPress RSS feeds’ after an ‘x’ amount of seconds, which is still not good enough and more or less makes this feature look like a 16-year old programmer’s trick. You either allow people to turn it off or (at least) allow them to set their own intervals.
  • Links is now called ‘Blogroll’.
  • You can now finally manage the individual uploads.
  • Some extra import and export functionality.
  • And some new plug-in development hooks, like for example the pseudo-cron.

That’s it. Nothing to really get excited about.

So?

I was doing a quick trial update to move Alfons to the latest known WordPress version locally (on the server called Elsie). Yesterday, I had to download an older version of WordPress to see how my plug-in behaved (it behaves nicely, thank you for asking). Upgrading was a breeze: the only roadblock was actually to update his WordPress database information to fit my settings. This procedure I described in my posting called ‘How to install your online WordPress locally’. (As a reference, my thoughts on upgrading your WordPress the right way)

That said, I’ll be preparing mine probably in a couple of hours. That is right, after the messages.

Update at 9:31 PM: And it’s done.

Databases

I updated the plug-in accordingly but want to issue a warning before you download it: I’m not sure which version of MySQL does or does not support ‘left outer joins’. I think versions > 3.23 should be able to do so. If not, you’re out of luck.

(I discussed outer joins here and here)

I am surprised (once again) about the database design in WordPress. Version 2.0 included ‘major changes’, like adding the comment count in the Posts table. If correctly designed (as in true ‘one-to-many’ relationship), you can just fish out the comment count using an outer join without any performance loss (after all, one-to-many relationships depend on identical keys in both tables, which are generally indexed anyways!). Here’s a reminder for people who start to look around the corner, or who are just dipping their toes in SQL: you do not treat a one-to-many relationship as a ‘one-to-one’ relationship. Trust me: you’ll miss out.

W10x!

Earlier, It's an active one!I uploaded ‘AHCommentCentral’, which is a plug-in that is supposed to help closing/opening comments and ping/trackbacks in your post sections. For now, you’ll find the initial release right over here. That is, for the daring people who experiment. It’s GPL-ed too, which is (only) natural for ‘non-compilable’ sources1.

I left out certain options (you’ll find references to them in the sources): the ‘auto close feature’ (see PrintAutoForm) and the Post Exceptions list (see call to get_options to retrieve data from the ‘ahi_cc_excluded_posts’ options field). In earlier versions, I actually had that ‘auto-close feature’ working, but I decided against adding it to the initial code.

There are couple of things I don’t like about creating WordPress plugins: Designing screens is obnoxious. Here’s a tip for you lazy programmers: grab the ‘wp-admin.css’ file dump it in a directory and then install NVU. Yes, NVU is buggy like crazy, but proofed to be quite the help while racing through all these HTML form elements (A couple of years I was thinking about creating a form-designer). We need XFORMS. Direly.

Another thing that is annoying (when creating these plug-ins) is that the current plug-in structure forces you to start globalizing’ certain variables. I won’t do a rant about globals. There are plenty of them. Global variables kill cats. Somehow, PHP forces programmers to write bad code. You know, poetry is one thing, but comparing PHP code with written literature is a joke. It’s like giving a kid 2 notes (A and B minor) and tell him or her to write 80 melody lines out of those notes. The problem is not in creating 80 of ‘em. The problem is that the eighty tunes will always sound alike. But OK, I admit: PHP is not as bad as ASP (which is just a fancy name for Visual Basic for Applications [cough] and servers!).

As for the name: I think I was watching Comedy Central the other day and the name got stuck somehow in the nether regions of my brain. I considered renaming it to something absurd like, ‘W10x’ (which you pronounce as ‘What The Funk’) or better yet, ‘W09y’ (you pronounce that as that typical Eigthties greeting ‘See You Later, Aligator’). I’m actually dreaming of an ‘EP01BF’, which is the abbreviation for Peanut Buster Parfait. OK. Comment Central.

1 What’s the point of releasing ‘closed sourced’ PHP applications? [that’s a joke]

UPDATE: I just updated the plug-in.
UPDATE#2: Older versions of WordPress

W09

After Comments In Progressmany moons of bickering and looking around, I decided to take up the gloves and do it myself. Currently I’m using a slightly altered script that ‘automatically’ folds and closes comments after 10 days. This generally works good and has stopped the flow of sapm directed at the comments. However, I’m lacking precise control, that is, I’d like to have some posts to keep their comments available for a longer time.

You’ll find some of these plugins in the WordPress repository, but most of them make no sense and work rather not really good1.

I also noticed something funny in queries of existing plugins where in the code roundabout attempts are made to make a selection first and then pass the resultset to an ‘update’ statement: hey rookies, the following statement is ‘legal’ SQL:

update wp_posts
set ping_status = 'closed'
where post_date < DATE_ADD( DATE_SUB(CURDATE(), INTERVAL 4 month), INTERVAL 1 DAY);

On the other hand, using subselects in MySQL should generally be avoided. There's no real consensus around which MySQL version supports subselects. 4.xx maybe. 3.23 maybe. Who knows!

On a related note, I see that there's a new WP version out.

1 That is an understatement.