Tag Archives: WordPress

Modifying the existing WordPress login/registration/lost password form

I wanted to make a few changes to the WordPress login page (wp-login.php) but keep all existing functionality.  I didn’t want to mess around with any core WP files.  Sounds like it should be easy…unfortunately not.

Here’s how you can make a copy of the existing wp-login.php, put it in your own theme, and make it useable so you can then go on to modify it however you like.

  1. copy wp-login.php to your theme directory, call it whatever you like
  2. replace the following lines:
      2 /**
      3  * WordPress User Page
      4  *
      5  * Handles authentication, registering, resetting passwords, forgot password,
      6  * and other user handling.
      7  *
      8  * @package WordPress
      9  */
     10
     11 /** Make sure that the WordPress bootstrap has run before continuing. */
     12 require( dirname(__FILE__) . ‘/wp-load.php’ );
    with:
      2 /*
      3 Template Name: Your Custom Login/Registration Page
      4 */
  3. If you’re using the vim editor, use the following two lines:
    :%s/$_REQUEST[‘action’]/$_REQUEST[‘do’]/g
    :%s/?action/?do/g
    Otherwise, use whatever find and replace function your editor has to replace $_REQUEST[‘action’] with $_REQUEST[‘do’], and ?action with ?do
  4. Create a page on your site, select the new template, and note down the page ID and slug
  5. Back to the custom login file, do the following in vim (where 591 is your page ID, and ‘login-register’ is your page slug):
    :%s/wp_login_url()/get_permalink(591)/g
    :%s/wp-login.php/login-register/g
    :%s/wp_lostpassword_url()/get_permalink(591).’?do=lostpassword’/g
    Or if not using vim, replace wp_login_url() with get_permalink(<your page ID>), replace wp-login.php with <your page slug>, and wp_lost_password_url() with get_permalink(<your page ID>).?do=lostpassword

That should be it.  If you now go to that page it should show you the normal WP login form, and the links for registering and lost passwords should also go to your custom page.  The lost password feature will also direct the user back to the custom page to reset their password.

 

You can now edit the page however you like!

 

NB: point 3 may seem a bit unenecessary; we’re changing the ?action= to ?do=, however, wierdly, if you leave as-is and post new user registration data to http://yoursite.com/customlogin?action=register, WP calls the register_post action (which registers new users) before it even loads your custom template, and then it calls it again during your template.  Very bizarre, but changing it works fine.

Transparent tiled watermark using GD with PHP

This is a basic method for dynamically adding tiled watermarks to images on your site.  It uses the .htaccess file to give the images to the PHP script which returns the image plus watermarking.

1) Create the image you want to be the watermark as a png with the opacity you want to be used (we’re not lowering the opacity later), and make sure to add extra space around the image according to how big you want the tiles.

2) Add this script to your site as watermark.php:
[sourcecode]
<?php

$watermark = imagecreatefrompng(‘/path/to/your/watermark.png’);
$imagesrc = ‘/path/to/image/’ . $_GET[‘src’];
$type = mime_content_type($imagesrc);
switch($type){
  case ‘image/jpeg’:
    $image = imagecreatefromjpeg($imagesrc);
    break;
  case ‘image/png’:
    $image = imagecreatefrompng($imagesrc);
    break;
  case ‘image/gif’:
    $image = imagecreatefromgif($imagesrc);
    break;
  default:
    $image = null;
}
if($image){
  # set dimensions
  $image_width = imagesx($image);
  $image_height = imagesy($image);
  imagealphablending($watermark, TRUE);

  # create the tile and overlay
  imagesettile($image,$watermark);
  imagefilledrectangle($image,0,0,$image_width,$image_height,IMG_COLOR_TILED);

  # output image
  header(‘content-type: image/jpeg’);
  imagejpeg($image);

  #clean up
  imagedestroy($image);
  imagedestroy($watermark);
}

?>
[/sourcecode]

3) Add rewrite rules in .htaccess.  Notice the $_GET[‘src’] in the script above; we need to hand this variable to the script.  In this example, anything in my gallery folder, or with the filename starting with wmark- will be passed to the script:
[sourcecode]
RewriteRule ^(.*)wp-content/uploads/wmark-(.*) $1path/to/watermark.php?src=wp-content/uploads/wmark-$2
RewriteRule ^(.*)wp-content/uploads/image-gallery/main_gallery/(.*) $1path/to/watermark.php?src=wp-content/uploads/image-gallery/main_gallery/$2

# If you want to exclude a particular image (excludeme.jpg), add this ABOVE the other rules.  The [L] tells it to ignore other rules
RewriteRule ^wp-content/uploads/excludeme\.jpg$ – [L]

[/sourcecode]

The script will only handle jpg/gif/png file types; if it’s possible that your rewrite rules will pass any other file types to the script, make sure to use (.*\.(gif|jpg|jpeg|png)) if it’s possible instead of just the basic (.*) in your rewrite rules.

WordPress Google Calendar Events plugin notes

I’ve just installed this awesome plugin onto a WP blog: http://www.rhanney.co.uk/plugins/google-calendar-events/

Had two issues I want to note:

1) Use the XML feed from Google, not the iCAL feed, or it will give errors

2) The timezone wasn’t working properly using default settings (it uses WP’s time); I realised this problem actually lies with WP – by default WP was using UTC+0 for my timezone (London), which is wrong, as now we’re on DST, which is UTC+1, changed it to London rather than the UTC offset and it’s working fine.
(Suprised I haven’t noticed this before, although I can’t actually think of any WP sites I’ve made where the post time is displayed – except this one at the moment, as I haven’t modified it at all yet – so it’s never been a problem.)

Custom WP plugin ‘Do not have sufficient permissions’ when accessing options page

If you’re using, for example, this tutorial from NetTuts: http://net.tutsplus.com/tutorials/wordpress/creating-a-custom-wordpress-plugin-from-scratch/

Beware this bit of code:

[sourcecode]
function oscimp_admin_actions() {
add_options_page(“OSCommerce Product Display”, “OSCommerce Product Display”, 1, “OSCommerce Product Display”, “oscimp_admin”);
}
[/sourcecode]

The fourth option in the array is the URI of the page; the spaces are taken out automatically by WordPress, but the case remains, so if you’re using a case-sensitive web server you’ll get permissions errors when trying to access the page.

Change it to something like ‘oscommerce_product_display’ and you should be fine.