Tweaking BatCache to play nicely with Woocommerce

Are you caching your WordPress sites with MemCache object cache and BatCache advanced cache? Well you should be.
Here’s a tweak to stop the advanced cache caching dynamic WooCommerce pages like the cart and checkout. Continue reading “Tweaking BatCache to play nicely with Woocommerce”

Truncate WordPress SEO breadcrumb length

Yoast’s SEO Plugin for WordPress is great. It’s the only SEO plugin I’ve used for years. However there is no control over the length of breadcrumbs it will create. Imagine a long page title breaking your design as the area dedicated to breadcrumbs is notoriously small and narrow.

Here’s how to limit the length in Yoast’s WordPress SEO plugin.

add_filter('wp_seo_get_bc_title', 'truncate_bc_title');
function truncate_bc_title() {
	$title = get_the_title();
 
	$title_length = strlen( $title );
	$limit = 30;
	$truncated = substr( $title, 0, $limit );
 
	if ( $title_length > $limit ) {
		$truncated .= '...';
	}
 
	$link['text'] = $truncated;
 
	return $link['text'];
}

[Snippet] Adding a class to get_gravatar

WordPress’ get_gravatar seems very neglected to most other functions. No $args, no $classes. No anything useful.
Luckily we can add a filter to add extra classes to get_gravatar.

function add_class_to_gravatar($class) {
    $class = str_replace("class='avatar", "class='avatar new-class", $class);
    return $class;
}
add_filter('get_avatar','add_class_to_gravatar');

 

WP-Facebook-Auth Launched on GitHub

I’ve launched my (super scruffy) WP-Facebook-Auth code on GitHub . It is a WordPress Authentication Wrapper for Facebook.

Use it when you have an application that reads or writes from Facebook.

This wrapper allows WordPress admins to (semi) automatically authenicate with Facebook for use with the Facebook API. If you use the Facebook API to pull data, you’ll find that you need to authenticate with Facebook using OAUTH. These tokens don’t last forever and need to be renewed every so often. (3 monnths). This code will update the OAUTH token whenever an administrator logs into the WordPress Admin interface, which hopefully will be more than once every 3 months.

 

[Snippet] Restrict user to a particular folder

By default in Linux, an SSH can freely navigate around your file system. I recently needed to restrict an SSH user to their home directory. You need rbash.

CentOS doesn’t ship with rbash enabled as default. It was easy enough to solve.

[codesyntax lang=”bash”]
ln -s /bin/bash /bin/rbash

Then change /etc/passwd so that the user’s shell is /bin/rbash.

OpenCart is slow with many categories – 2013 Edition

As an update to my 2012 post on OpenCart being slow with many categories, there have been many discussions, 2 , 3. There have been a few solutions offered, all of which have been rejected by the OpenCart developers for some strange reason.

i don’t believe this. i think you have mis understood something.

you shoudl be using indexes and not making new primary keys!

@ChrisAtomix has released OpenCart Turbo. A run-once script that speeds up your OpenCart store, applying the fixes I discussed in 2012 and few other speed up changes.
I’d recommend running this on any OC site, not just sites that are slow right now.