Archive for September, 2011

Convert eregi_replace to preg_replace in old class.phpmailer.php scripts

Problem: I have lots of legacy php code on old sites that uses eregi_replace to format up an HTML email body. As eregi_replace is now depreciated it can be replaced with preg_replace. This is tricky sometimes because the formatting is quite different. Fix: Here’s a common line from class.phpmailer.php scripts: $emailBody = eregi_replace("[\]",”,$emailBody); To convert that you’ll need to do this: [...]

WordPress replaces double and triple hyphens (– or —)

Problem: The other day I was trying to type two hypens (–) in a post, and when I saved/published the post, WordPress reformatted the hypens to display as an ‘en dash‘ (–). More Info: After some searching about, and some helpful info provided in the WordPress Codex, I found out about a WP function called ‘wptexturize’ which is applied each [...]

Batch rename file extensions from .jpg to .png in terminal

Problem: A client sent me 164 images with incorrect extensions on them. I needed to change them all from .jpg to .png. Fix: Open up terminal, navigate to the directory containing all the images and type: ls *.jpg | awk ‘{print("mv "$1" "$1)}’ | sed ‘s/jpg/png/2′ | /bin/sh ..that should do it! This one-liner makes [...]

Add ‘Drafts’ sorting to Shopp Products list

Problem: There is no ‘drafts’ view filter in the Shopp (>1.1.9) Product Manager, i.e you can’t quickly list all the products that have ‘draft’ status in one go. Fix: I made this mod to answer a question in the Shopp Helpdesk forum, it’s not very tested, but seems to work perfectly! Open ‘wp-content/plugins/shopp/core/flow/Warehouse.php’ and replace [...]