Archive by Author

Overriding pluggable functions in a plugin

21 Dec

There is a small detail you need to remember when trying to override a pluggable function in a wordpress plugin – The original function will not be overridden in plugin activation time, which means that the following code will make the plugin activation to fail with a redeclaration error message


function override() {
...
}

What you actually have to do to take care of this situation is to protect the function declaration by checking whether the function is already declared


if (!function_exists('override') {

function override() {
...
}

}

Author slug plugin

5 Nov

The author slug wordpress plugin adds the ability to control the slug associated with an author, in a similar way in which you can control the slug of a category.

It is not compatible with wordpress MU.

Usage

After activation a new field titled “Slug” will be added in the user profile page when an administrator is editing the profile. To change the slug just enter the new slug and submit.

If the requested slug already exists, a slug will be generated in the form slug-n.

if the slug field is empty, the slug will be reset to the wordpress defualt.

If you find it useful, don’t be to shy to

License

GPLv3

WordPress version compatibility

Was tested against 2.8, but should work with earlier versions

Installation

1. Download the plugin and unzip it (or not, if you are going to use the built in wordpress plugin installer)
2. Upload the unzipped folder authorslug to your plugins directory.
3. Activate the plugin through the ‘Plugins’ menu in WordPress

Changelog

  • 1.0

Initial release.

How to remove_action which activates an object method

24 Oct

add_action/add_filter can accept either a function name or an object and a method name as the ‘function’ parameter. The problem is that remove_action/remove_filter can remove only actions which use a function name or a static class methos as their ‘function’, object methods type of ‘function’ can not be removed at least in the 2.8 version.

There is no official way to remove, but if needed you can apply the following hack which tries to find the ‘function’ in the internal structures, by looping over all the functions while trying to find the best match and remove it.


// assuming this was the add_action being used

$f =& new Custom_Image_Header();
add_action('admin_menu', array(&$f, 'init'));

// this code will remove it

foreach ($GLOBALS['wp_filter']['admin_menu'][10] as $f => $v) {
  if (substr($f, 0, 23) == 'Custom_Image_Headerinit') {
    remove_action('admin_menu', $f);
  }
}

This code has two important drawbacks

  1. It may remove the wrong object if more then one object of the same class ware added as a function
  2. Similar class names might confuse the code. In this case it might remove call to the ‘nit’ method of the ‘Custom_Image_Headeri’ class

Are child themes the answer to the task of maintaining wordpress mu themes

20 Oct

Being between projects, I am amusing myself by trying to revive the deprecated “almost spring” theme as a child theme of k2. While working on it, suddenly it occurred to me that it might actually be a great idea to convert all the themes that I have at this wordpress mu installation to be children of the k2 theme. Done right it will mean that there is only one theme to upgrade and check when there is a new version of mu, and it will be a lot easier to write plugins which affect all the themes.

write a lot of code, add multitude of options, spice up the interface and win prize?

29 Sep

No disrespect to the efforts of the developers, and the solid reasoning of the judges, but in my humble opinion the winner of the 2009 wordpress plugin competition – the section widget which

provides a way to display section specific content on your WordPress sidebar with an easy to use interface. This new version comes with tabs support, so creating your tabbed section widget is just a few clicks away.

is not good enough to receive the prize.

I only needed to look at the screen shots to decide that I’m not going to recommend this plugin to any one

Who are going to be the users of this plugin? This screenshot alone displays more hardcore wordpress buzzwords than the “all I want is a simple blog” crowd understands, while it might be easier for the WP focused developers to simply add new sidebar for the places where the normal one is not good enough.

Oh, it even worse than that. When I want to hide a widget from the sidebar at a specific page, I just use CSS. It might not be the ideal solution as it wastes some bandwidth and CPU cycles, but your time is probably much more expensive than the cost of bandwidth and CPU.

In my opinion this type of contest should be decided on mainly two factors:

  • Does it solve a real life problem for many WP users
  • Can a non geek teenager use the plugin successfully without help

Based on this criteria, my favorites were

  • Advanced Export for WP and WPMU which solves the problem of exporting big blogs from shared hosting were you don’t have a direct access to the DB. I only wish there was also a simple way to automate the process.
  • One time password. In a world were we blog from a coffee shop via unsecured WiFi it is actually a security madness to use our password (which we probably use at other sites as well). A one time password is probably the best solution after installing an SSL for the blog. I wish it could have been integrated with the FTP server.

Searchbox plugin – Add search to posts and pages

28 Sep

The searchbox wordpress plugin adds a seachbox short code which generates a search form when the page or post is displayed.

It is wordpress MU compatible both when used as regular plugin and as an MU plugin.

Typical usage: [searchbox]

If you find it useful, don’t be to shy to

Parameters

  • class

    Can be used to add a name of a CSS class for the form
    Example: [searchbox class=search]

  • plugins

    Can be used to apply the get_search_form filter to the form. Might be useful if you have some plugins which add extra functionality to the search widget.
    Example: [searchbox plugins=1]

  • Full shortcode format

    Can be used to inser text (or any HTML) in the form above the input fields. Usefull if you want that text to be styled differently.
    Example: [searchbox]Use the search Lok[/searchbox]

styling

The form do not reuse the id’s of the normal seach form and therefor it should result in a bare form for most themes.
If you wish to style the form you should specify your own class for the form with the class attribute.

The classes specified for the different sections of the form are

  • searchtext – The class of the text
  • searchbox – The class of the input box
  • searchsubmit – The class of the submit bottun

Installation

1. Download the plugin and unzip it (or not, if you are going to use the built in wordpress plugin installer)
2. Upload the unzipped folder searchbox to your plugins directory.
3. Activate the plugin through the ‘Plugins’ menu in WordPress

Changelog

  • 1.0

Initial release.

Suprising things no one bothered to tell me about custom 404 pages

27 Sep

I thought that 404 pages, which indicates that no content was found at the specified address, are about the most trivial aspect of the web, turns out I was wrong. A couple of weeks ago  a client asked me to add a 404 page to his WordPress theme, and since I like to leave as much control as I can at the hands of the site owner (reduces my headaches) I had to figure out how to integrate it into WordPress, and today I read one of the Firefox developers mentioning that he works on how Firefox should handle 404 pages.

I was surprised to learn that internet explorer and chrome will simply ignore your custom 404 page if it is shorter than 512 bytes, assuming that such a small message was automatically generated by the server and do not contain any useful information to the user. Therefor, if your 4040 page is shorter than 512, you should add some HTML comments to it to make it bigger.

Somewhat less surprising, but very interesting, is an article in a list apart which suggests that the 404 page should be dynamic with different pages served in different 404 contexts.

BTW: most WordPress themes serves what should be 404 pages as a 200 (success) pages. My solution fell into this trap too :(

Control Outbound RSS plugin for wordpress

18 Sep

This plugin will handle several aspects of RSS feeds generated by wordpress

  1. Reduce the amount of bandwidth required to transmit the RSS by sending only the items which were had not being already sent to the specific RSS reader.
  2. Better control on the amount of items which are included in the feed. For sites with very frequent posts or comments the default of 10 might not be enough.
  3. If it is possible at all, add a feed per a comment thread.

The first version handles only the bandwidth reduction issue. Just download it, put it into your wordpress plugin directory, if you use it for a stand alone wordpress, or at the mu-plugins directory for wordpressmu.

It was tested in wordpress 2.8, but it should work for wordpress 2.2 and above.

Is there a proper moral way to treat wordpress related abandonware?

18 Sep

The ease with which you may create wordpress plugins and themes, combined with relatively long time of existence of wordpress, created a growing wave of abandonware (software which is not maintained by their legal owner, and sometimes it is not clear if they have one).

The bigger part of this abandonware are plugins and themes which were rarely used, and probably not many people are actually missing them, but one of my favorite themes “Almost Spring” have gone the way of the dodo and not only that it was not updated for a very long time, but now the blog of its creator has vanished as well.

I keep the source code of the theme and I would like to update it and release to the public, the question is how much should I follow the original licensing terms of the theme (even worse, there is no explicit license in the source files).  I prefer to release my code under a sort of BSD license, and I would like to remove the link to the creators site, as I don’t see any real reason to provide SEO for some unknown domain squatter.

The law is quite clear about it, and under the law I should preserve the original license. Yet I wonder, if there is no one to care enough to complain about me breaking the law, can I practically do whatever I wish with the code?

Preventing php/perl script execution of a user uploaded files while keeping them downloadable

16 Sep

You wrote a rather large PHP script which you would like to share with the world, lets say a small wordpress plugin. If you just upload it via the wordpress post publishing interface, you will find out that when you click the link in order to download it, instead of getting the browser’s download interface, the script is actually being executed on the server.\

This is why even small scripts are usually distributed as ZIP files, but if your site is running over an Apache web server there is a small and fast cure for the problem – just add the following line to the .htaccess file (you might need to create it) at the root of your uploaded file directory hierarchy ( [wordpress installation path]/wp-content/uploads in wordpress) :

AddType application/octet-stream .pl .cgi .php

This line will make Apache know that the PHP/PERL/CGI files at that directory should be treated as a simple stream of bytes and it will not try to execute them. On the other hand, the browser will know that it should not try to display the files, and will start a download process.

This is actually a kind of security feature. If you are running a site which lets other users upload files (a wordpress with multiple authors), you don’t want them to be able to upload executable scripts.

Page 1 of 3123»