Skip to:

Re: Plugin: Avatar Upload



Ok, I’ve now looked at the code and can see how it can be included without needing to branch the plugin too much (and all the maintenance issues involved with that!).

First of all I removed the identicon functions from the bb-avatar-upload.php file and placed them at the bottom of the identicon.php file, to keep them all together.

Secondly, I moved the if($_POST['identicon']){...} code from the avatar-upload.php file to the bottom of identicon.php and made it a function called by the ‘bb_head’ hook (I might eventually do this for the main upload functions too). Note: Is there a pre-head hook that fires before any headers are sent?

function useidenticon()
global $user;
//fel identicon
if( $_POST['identicon'] )
felapplyidenticon( $user->ID );

add_action( 'bb_head', 'useidenticon' );

You then only need to supply and maintain two files for the “branch”.

- my-plugins/identicon.php
- my-templates/avatar.php

The avatar.php template is the least likely file to change (it’s been modified slightly since version 0.1).

I’ve made the modifications and zipped them up for you to examine:

Identar Modified (this is minus my files, except the template file)

You will also need the updated version of Avatar Upload: Avatar Upload (version 0.2)

By keeping the Identicon and Avatar parts of the code separate, it should be easier to use Subversion to merge in – or simply replace – changes I make to the trunk code.

Regarding filename storage in the database – there are two reasons for this. The first is that I prefer to store the image dimensions along with the current avatar. The maximum width and height of the avatar is just that, maximums; the actual dimensions could be any size and any aspect ratio within that limit. I then include the height and width attributes in the <img> tag – it’s good practise because the browser makes space for the image when loading the page, instead of shifting everything after the page has loaded.

The second reason is more exciting – future proofing. A future version of this plugin will allow multiple file uploads, allowing users to upload more than one avatar image and select which one to use.

Since releasing version 0.1 of the plugin, I have reduced the number of DB calls in the profile pages and in the avatar-upload.php file by making use of the $user object and calling $user->avatar_file when I need to access the avatar info.

Although, when adding avatars to a user’s posts you still have to do a DB query. If I used your suggested method, it is still going to involve at least one call to the DB, either to get the user_login from the get_post_author_id() (and then grab the avatar file), or to get the avatar itself from the get_post_author_id().

Skip to toolbar