Remove Links menu item in WordPress

Problem: I’m customising a WP install for a client, adding some Custom Post Types and wotnot, and they aren’t going to have any need for the Links thing.

Fix: Adding this to your theme’s (or child-theme’s) functions.php removes the page and the menu link:

function nuke_menu_items(){
remove_menu_page( 'link-manager.php');
//remove_menu_page( 'upload.php'); //remove other items etc etc
}
add_action('admin_menu', 'nuke_menu_items', 999 );

Cheap & simple fix for a leaking fermenting bin (homebrew)

Problem: I’ve just put a brew on using some cheap equipment from an online retailer. The lid of the fermenting bin is loose fitting so the beer is gassing around the lid or through the airlock grommet and not through the airlock / bubbler itself. This is not really a problem while the Krausen is building and lots of gas is being produced, but can be a problem when things slow down, and air gets in.

Lid Fix: The loose lid can be fixed by liberally applying Petroleum Jelly around the lid. Vaseline the company make Petroleum jelly readily available in chemists and supermarkets, and it’s commonly used on babies apparently for some reason or other (no idea).

Baggy Grommet Fix: Place some PVC tape around the bottom tube of the airlock where it passes through the grommet. Use about 5-8CM of tape to start with, wrapped on in a cone moving towards the top of the trap so that it gets thicker. Then when the trap is re-inserted into the grommet, it will expand the rubber more and make a better seal.

Note: This has only been a problem with cheap kit that uses rubber grommets and press on lids. Better fermenting bins have screw tops and large rubber bungs to place the airtrap in.

Searching between dates in GMail

Problem: I’m doing my tax return :( And need to frequently look for emails sent and received in the 2010/11 tax year.

Fix: Gmail is really powerful when the text search box is used. There are various advanced search operators but the ones that help here are ‘before:’ and ‘after:’. When twinned with ‘from:’ or ‘to:’ it returns exactly what you want.

Examples:
A certain date range:

after:2010/03/31 before:2011/04/01

The phrase “invoice” in a certain date range:

after:2010/03/31 before:2011/04/01 invoice

From an individual in a range:

after:2010/03/31 before:2011/04/01 from:wave@thesea.com

Adding category depth tag to Shopp 1.1.*

Problem: I needed to display sub categories of a category in category.php but only one level deep. Using:

<?php if(shopp('category','hascategories')): ?>
  <?php while(shopp('category','subcategories')): ?>
    //display stuff
  <?php endwhile; ?>
<?php endif; ?>

…displays all subcast AND their subcats.

Fix: I decided to add a new tag, called shopp(‘subcategory’, ‘depth’) that would return the category depth. That way in the loop above this would show only immediate children:

<?php if(shopp('category','hascategories')): ?>
  <?php while(shopp('category','subcategories')):
    $depth = shopp('subcategory', 'depth', 'return=true');
    if($depth!=0):
      continue;
    endif; ?>
   //else display stuff
<?php endwhile; ?>
<?php endif; ?>

Adding the new tag: Open the theme’s functions.php file and add this:

add_filter('shopp_tag_category_depth','return_cat_depth',10, 3);
add_filter('shopp_tag_subcategory_depth','return_cat_depth',10, 3);
function return_cat_depth($result, $options, $Category) {return $Category->depth;}

…once that’s added, shopp(‘subcategory’, ‘depth’) can be used anywhere in the Shopp templates.

Note: In Shopp 1.2 the hook is created differently. Thanks to Jon Davies for pointing out that the hook would now be shopp_themeapi_{object name}_{property} and defined in defined in shopp/api/theme.php.

Getting subcategory totals [shopp('subcategory','total')] to work in Shopp Plugin 1.1.*

Problem: Pulling the total number of products from a subcat in Shopp doesn’t seem to work out the box. For example, this code WON’T return the total even though the correct tag shopp(‘subcategory’,'total’) is used:

<?php while(shopp('category','subcategories')): ?>
    <?php shopp('subcategory','name'); ?> (<?php shopp('subcategory','total'); ?>)
<?php endwhile; ?>

Fix: For the products to be countable, the ‘hasproducts‘ tag has to be called with the ‘load’ option like so:

<?php while(shopp('category','subcategories')): ?>
    <?php if(shopp('subcategory','hasproducts','load=prices,images')): ?>
        <?php shopp('subcategory','name'); ?> (<?php shopp('subcategory','total'); ?>)
    <?php endif; ?>
<?php endwhile; ?>

Note: The docs refer to ‘category’ tags. Each category tag has an ideantical subcategory tag. For example and both work when used in the correct context.

Remove prices from Variation drop-downs in Shopp WordPress plugin

Problem: In Shopp (1.1.9) the default variations drop-down list shows prices. This isn’t always desired. This is the default usage:

<ul class="variations">
  <?php shopp('product', 'variations', 'mode=multiple&label=true&defaults=Select an option&before_menu=<li>&after_menu=</li>'); ?>
</ul>

And this outputs a list that shows options as “Option Label (price)”.

Fix: The code above can be replaced with this code to manually create the same thing, giving complete control over output:

<ul class="variations">
    <li>
    <label for="options-1">Quantity</label>
    <select name="products[<?php shopp('product', 'id'); ?>][options][]" class="category-catalog product<?php shopp('product', 'id'); ?> options" id="options-1">
    <option value="">Select an option</option>
    <?php
        $i=1;
        while (shopp('product', 'variations')): ?>
        <option value="<?php echo $i;$i++; ?>"><?php shopp('product', 'variation', 'label'); ?></option>
    <?php endwhile; ?>
    </select>
    </li>
</ul>

The $i;$i++ was a bit of a work-around as I couldn’t get it to work with variation ID, so if you know a better way, please tell us below!

Capture last viewed category in product view in Shopp Plugin for WordPress

Problem: I’m using the Shopp 1.1.9 ecommerce plugin for WordPress, and my client wanted to display specific background images while showing certain products. Shopp is very complete, but one thing that is missing in the current version ‘out of the box’ is the ability to pull the ‘last viewed’ category name when viewing a product. Obviously a product can belong to more than one cat, so it can’t know which one to display…

Fix: There is however a breadcrumb template tag that stores the category name that a user us currently viewing, so that if they then click on a product, the hierarchical parent category can be displayed in the breadcrumb.

This functionality can be used in a new custom tag. Jon Davis the lead developer of Shopp helped me a lot today as I was barking up the wrong tree going about it the wrong way.

Add this to your theme’s functions.php:

add_filter('shopp_tag_catalog_lastcat','get_last_cat');
function get_last_cat ($result,$options,$Object) {
    $Storefront = ShoppStorefront();
    if (false === $Storefront) return false;
    $category = $Storefront->breadcrumb;
    return $category;
}

Then anywhere in your Shopp templates you can do this to return the category part of the current breadcrumb e.g “Smalls” in Home > Smalls > Purple Pants :

<?php
//echo it out straight away..
shopp('catalog','lastcat');
 
// return it for use..
$lastcat = shopp('catalog','lastcat','return=true');
?>

Hope that helps someone, props go to JD for getting it working!

What is Notice: unserialize() [function.unserialize]: Error at offset then?

Problem: While doing some Shopp Plugin support work earlier, one customer was getting this error…

Notice: unserialize() [function.unserialize]: Error at offset 111 of 118 bytes in /home/maxwell4/public_html/main/wp-content/plugins/shopp/core/model/Settings.php on line 228

…she had done a ‘find and replace’ in a SQL DB dump to change her domain name, boogered it up accidentally, and needed an explanation. The answer I gave applies any time that error occurs in PHP, so i thought it was worth posting here!

Reason: Arrays are often serialized so that they can be stored in a database text field. If you change the data within a serialized array, without changing the character count, you will get the error above.

For example, try this:

1
2
3
4
<?php
$thing = array('one','two');
echo serialize($thing);
?>

This will echo out the following: a:2:{i:0;s:3:”one”;i:1;s:3:”two”;}
Now… if you stored that in a database, you could then retrieve it later and unserialize() it to get your array back. wohoo!

In that serialized data, s:3:”one” means that the first element in the array is a string, and that it’s 3 characters long. Now.. if you manually changed “one” to “otherone” like this a:2:{i:0;s:3:”otherone”;i:1;s:3:”two”;} then when you ran it through unserialize() to retrieve your array, you would get the error were talking about.

Fix: To correct this you would need to update the string length also like so: a:2:{i:0;s:8:”otherone”;i:1;s:3:”two”;} because “otherone” is actually 8 characters long. See? Good!

Any questions, please leave a message below.

.htaccess hidden on Rackspace Cloud Sites (in FTP, with Filezilla)

Problem: When connecting to a Rackspace Cloud site via FTP, hidden files are.. uh.. hidden. Usually Filezilla shows everything.

Fix: There is a setting in Filezilla called ‘Force showing hidden files’ that does exactly that. To activate that, go to the ‘Server’ menu item and select it. Like this:

Force show hidden files in Filezilla

When you click that, you should be shown a warning/dialogue box about why it needs to be done. Interesting what they say about ‘broken’ servers!

Remove pistons from brake calipers without fluid/tools

Project: I want to restore my old GT6 brake calipers and the old chipped paint us very VERY tough so I plan to use paint stripper. To do this without harming the seals and soft alloys I need to split each caliper and remove pistons.

Problem: The pistons are stuck in, and will only come out under pressure.

Fix: I took an old piece of copper-nickel brake line and re-attached it to each caliper with the bleed nipple closed. The other end of the brake line has a flared end and tube-nut which just happens to perfectly fit into the Schrader adaptor on my bicycle Track Pump. Once attached I pumped the.. uh.. pump and watched the pistons move out of the calipers. They both popped out at around 20-30 PSI. Of course if you want to do this spectacularly and potentially damage the pistons, use a compressor :)

Important: When you pump the pistons out, you don’t want them to fire out and spray residual DOT 4 everywhere, you also don’t want the pistons to lock together, so it’s important to find a peice of wood slightly thinner than the brake discs and place it between the pistons.

Wood spacer inserted...

Brake line attached again...

Pump attached to brake line...

Pistons popped out...