Archive for 'WordPress'

What do add_action and do_action do in WordPress?

add_action('foo','bar');
do_action('foo');
function bar(){
    echo "this is the bar function";
}

This would cause “this is the bar function” to be echoed to the browser. This is WordPress implementation of the Observer design pattern. In other words, the call to add_action as stated above tells the WP engine to listen for the action “foo” to be called, when it is, any function added through add_action will be called “Or notified as is the case with the Observer design pattern)

Drupal vs. WordPress, why I’m having second thoughts

I’ve been working on a CRUD plugin for WordPress for about a week. I’ve got most of what I want in there, but I hit a road block. You see, I want my content to be searchable, so I used the wp_posts table to store the header for the record, and I stored additional data in another table. In wp_posts, I changed the post_type to “contacts” for my records so as to differentiate my data from posts and pages. This is effective, and it’s searchable, however I couldn’t find a way to display my data on the front end.

What I realized is that WordPress would be great if it could load a template according to post_type. Right now, the WordPress theme hierarchy does that for Posts and Pages, but doesn’t allow programmers to add their own entries to the theme hierarchy. It would be great if I could add my own entry to the theme hierarchy that says for the post_type = “contacts” use the theme page called “contacts.php” if that doesn’t exist, use “index.php” just like it does for posts and pages.

Maybe you can do this. I’ve been unable to.

So now I’m thinking… well Drupal does that already. Based on your node type, it’ll load the content using code in your module. In fact, across the board, Drupal is made to be extensible so much more than WordPress. So I’ll make this bold statement, at the risk of sounding naive… WordPress is made for Blogging. Period. It’s designers do not want programmers to make it into anything more than a blog. As such, it does blogging better than any other blogging engine available commercially or openly.

On the flip side, Drupal is a CMS, it’s meant to be open and extensible. However, it takes quite a bit of work to get it to do anything useful. A standard install with no additional modules will leave you wanting more. For example, Drupal doesn’t even have a WYSIWYG editor by default. Recently I’ve discovered a great module for that, but it still doesn’t have the file management (i.e. uploading files and placing links into an article) capabilities that WordPress has. Furthermore, there are NO good themes for Drupal at an affordable price. Granted, I purchased the theme that I use for this blog, it wasn’t free. However it didn’t cost me a fortune either. I’ve found no such theme for Drupal. If you know of one, please do tell.

WordPress CRUD Plugin

I’ve finally decided to create a CRUD (Create Read Update Delete) plugin for WordPress. In my experience, it seems that the WordPress plugin architecture is very limited in scope. In fact, I’m so much more impressed by Drupal for it’s expandability, it’s permissions system and it’s menu system. However, WordPress has something that Drupal doesn’t have: an easy to use interface for creating pages and posts. Usability is what won me over to WordPress (For the time being anyway). So I’m going to spend my time making it do what I want it to do.

To start a CRUD system, I have a few requirements.

1. It must list items in the same format as the default Posts, Pages and Links interface. That means it’ll use the same skin and it’ll show the Edit and Delete buttons on RollOver

2. It must use separate pages for List and Edit screens. What I didn’t want is a single file plugin that has 12,000 lines of code.

3. It must be installable and uninstallable, plus it has to support upgrades.

I’ve already started, and figured out a way to use WordPresses menu system as a Router for page requests. This did require a hack to the menu-header.php file, but the hack was only 2 lines of code (1 statement, split onto 2 lines for readability). More to come…