Snippets

Debugging with WP_DEBUG_LOG

The constant WP_DEBUG_LOG is something I’ve only recently discovered — when added to wp-config.php it enables a log of WordPress errors and notices to be saved to wp-content/debug.log.

define( WP_DEBUG_LOG, true );

This is very handy when debugging plugin errors, especially hidden ones like those which occur on plugin activation.

WooCommerce: Output a printable list of processing orders

screen-capture

Someone requested a way to print out a list of their processing orders for WooCommerce so I came up with a snippet to do so 🙂

The code below can be added as a page template in your theme. Once added to your template, just create a page in WordPress admin and assign it the “Print processing orders” page template.

Theres a check at the top of the page to only let admin users in, and when viewed the page will give you a nice list of processing orders which you can then print out.

Getting comments of a certain post type

Whilst looking for a method to get comments from one of my post types in WordPress I stumbled across some undocumented parameters for the get_comments function. Simply state the name of the post type in the undocumented post_type parameter:

$comments = get_comments( array( 'number' => 5, 'status' => 'approve', 'post_status' => 'publish', 'post_type' => 'product' ) );

Very handy!

Give WordPress page’s excerpts

A handy snippet to have to hand, for WordPress 3.0+:

function enable_page_excerpt() {
add_post_type_support( 'page', 'excerpt' );
}
add_action('init', 'enable_page_excerpt');

Add that to your theme’s functions.php file and your good; pages will now show an excerpt panel.

CSS3 scale and rotate animation (webkit only)

Have you tried hovering over my logo (up top) in webkit? The animation is a nice effect and is really easy to implement as a progressive enhancement.


#logo a:hover {
    -webkit-animation-name: rotateThis;
    -webkit-animation-duration:2s;
    -webkit-animation-iteration-count: 1;
    -webkit-animation-timing-function:ease-in-out;
}
@-webkit-keyframes rotateThis {
    0% { -webkit-transform:scale(1) rotate(0deg); }
    10% { -webkit-transform:scale(1.1) rotate(0deg); }
    100% {-webkit-transform:scale(1.1) rotate(360deg); }
}

The important part is the ‘keyframes’ chunk – this tells the browser what to animate, and at what point. In my example we start off (0%) with a non-scaled, non-rotated element. We then (at 10%) make it larger, and finally we make it finish (100%) fully enlarged and rotated 360 degrees.