Archive | wordpress RSS feed for this section

How to remove the width and height attribute from images in wordpress

16 Jun

I run into a problem with fitting big images into a single post page. I thought that just using a max-width in a CSS file to limit the image width will be enough, and the browsers will automajically scale the image to a proper dimension which will fit the available space.

I was wrong. The result was images which which where in the proper width but look stretched in their height. It took some time to figure out that the cause of it is that the height attribute set for the image with the original height.

It took some poking into the wordpress code to understand that the width and height attributes are set when the images are inserted into the editor, so I just wrote some lines of code to remove the attributes when the image is being inserted in its full size.

Too lazy to do a proper plugin out of this, but here is the code


add_filter( 'get_image_tag', 'bg_image_downsize',10,6);

function bg_image_downsize($html, $id, $alt, $title, $align, $size) {

 if ($size=='full') {
$pattern = '#width="([a-zA-Z0-9]+)"#';
$html = preg_replace($pattern, '', $html);
$pattern = '#height="([a-zA-Z0-9]+)"#';
$html = preg_replace($pattern, '', $html);
 }

 return $html;
}

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.

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.

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.

Never, ever blame your users – learn from their mistakes

14 Sep

The worm attack on pre 2.8.3 wordpress versions started a blame game between wordpress users and wordpress developers and core community.  While the users claim that although wordpress is great piece of blogging software, it is not the center of their lives, and it is ridiculous to expect them to check every day if there is a new version available, and dedicate instantly the time to perform an upgrade. The developers on the other hand, claim that it is the user’s responsibility to keep their wordpress updated whenever it is needed.

As I am a great believer in personal responsibility, I sympathize with the developer’s position – If a user can not spare the time to maintain their wordpress, they should consider opening a blog at wordpress.com, or other service of the same kind.  But then I think about how wordpress is being marketed, with its 5 minutes install, central repository of plugins and themes with a one-click install, and other very user friendly features. But surely this set of features attracts users which are less technically savvy and if they complain about the upgrade process it probably means that it is relatively complex, especially when comparing to other features of wordpress.

My understanding is that the main complaint is that the upgrade process might fail due to a plugin or theme which are not compatible with the new version. It is actually a serious problem when the development team wants to push out a new version every three months, which practically means that users have to spend time on upgrading and testing every three months. For non technical bloggers this might be a real pain.

What wordpress need is an upgrade path that is by definition more stable then upgrading to a new release. Maybe there should be support for older version for a year, in which a new minor update will be released for any security related problem. This way the users will be assured that the security upgrade will not break their plugins and themes, and they will be able to plan in advance when to upgrade to the latest and greatest release, when it is comfortable for them, and not when some wordpress dude says that you have to upgrade right now.

Even if it happens, there would be users which will not upgrade, but you can not force everyone to do the right thing ….

Page 1 of 212»