Convert directory of images on the command line
I had a need, well I always have a need but I finally got around to figuring this out, to resize a directory of images. I finally broke up with Adobe and had historically used the Photoshop batch functionality which was always wonky at best so that’s no longer possible. I’ve done some digging and discovered yet again that Linux just does everything better. So without further adieu the command:
$ mogrify -path ./webp_images/ -format webp -quality 80 -resize 1200x1200\> *.jpg
Everything here is straightforward aside from the ‘\>’ after the resize flag. This extra bit prevents smaller images from being upscaled. FYI, you’ll need imagemagick installed to run the mogrify command.
Extra credit, here’s a command to mogrify a directory of images no matter the file type:
for img in *.{jpg,jpeg,png,bmp}; do [ -e "$img" ] && mogrify -path ./webp_images/ -format webp -quality 80 -resize 1200x1200\> "$img" donePublished on August 5, 2025
Me on a bike 2024
Converting Windows line endings to UNIX
Especially in the case of writing shell scripts. It’s imperative to move from CRLF (Win) to LF (*nix) so they will run.
Try this:
$ dos2unix FILE_NAME.EXT
if that doesn’t work, then try this.
$ sed -i 's/\r$//' FILE_NAME.EXT
Also, make sure you’ve set the permission bits so they can execute.
$ chmod 770 FILE_NAME.EXTPublished on September 3, 2024
Issue with register_post_type with custom capability type(s)
I have a plugin for a site that creates multiple custom post types (CPT). Each with their own custom capability specified via the capability_type
attribute of the register_post_type()
function. I copy-and-pasted the code block for each register_post_type()
from the first one, which includes the capability_type
as an array, ie. array('type' , 'types')
. Some of the subsequent CPT didn’t need multiple capability types so I was receiving the warning ‘Notice: Undefined offset: 1 in post.php’ due to a single item in the array. The fix was to remove the array wrapping the single value, et voila, no more warning.
Disable New User Notification Emails in WordPress
I use this when doing bulk imports of users in dev environments.
add_filter( 'wp_new_user_notification_email', '__return_false', 10, 3 );
Add that to functions.php
and you’re set. Users will not be notified.
Delete post revisions in WordPress with wp-cli
Easily remove revisions using wp-cli. First, get a list of revisions with:
$ wp post list --post_type='revision' --format=ids
This command will provide a list of revisions by post ID.
To remove those revisions, use to following command:
$ wp post delete $(wp post list --post_type='revision' --format=ids) --force
This command will provide feedback to stdout as Success: Deleted post XXX.
Where XXX is the post ID of the deleted post. The --force
flag may not be necessary, but was in my case since the command failed with the warning: Warning: Posts of type 'revision' do not support being sent to trash.
Me on a bike (Winter/Spring 2023)
CES Northstar Enduro – Truckee, CA
SET Redemption Enduro – Eureka Springs, AR
SET O’Rock Enduro – Ouachita National Forest, OK
SET Dino Enduro – Dinosaur State Park, Glen Rose, TX
SET Return of the Zombie Goat Enduro – Flat Rock Ranch, Comfort, TX
Published on January 24, 2023Me on a bike (Fall 2022)
TTP TEXAS ENDURO CUP – Spider Mountain, Burnet, TX
TTP TEXAS ENDURO CUP – Reveille Peak Ranch, Burnet, TX
Published on October 31, 2022More Yard Birds
More birds that have hatched and/or fledged in my yard.
Great Horned Owls
Published on March 21, 2022Change WordPress user ID
This is usually needed in order to secure the default admin user which has a user_id of 1.
Run these two mysql queries via your favorite interface.
UPDATE wp_users SET ID = 666 WHERE ID = 1;
then…
UPDATE wp_usermeta SET user_id = 666 WHERE user_id = 1;
Please note: you can use any number you want for the user_id as long as it doesn’t correspond to that of an existing user. I just chose the most metal user_id for this example. 🤘.
Published on February 24, 2022