Stop WordPress from outputting the canonical link tag

I had a page whose content varied depending on the query string parameters you gave it, so I definitely needed to remove the canonical tag.

Amplify’d from pixelpunk.co.uk

You can do this quite simply by adding the following to your theme’s functions.php:

# Remove WordPress' canonical links
remove_action('wp_head', 'rel_canonical');

Read more at pixelpunk.co.uk

 

Posted in Development, Uncategorized | Tagged , , , , | Comments Off on Stop WordPress from outputting the canonical link tag

Turn on WP_DEBUG to have WordPress kick out error messages

I’m troubleshooting a White Screen of Death (WSOD) problem in my project’s plug-in right now, so this is especially relevant.

Amplify’d from codex.wordpress.org
  • Eliminate PHP errors in your plugin. Add define('WP_DEBUG', true); to your wp-config.php file, try all of your plugin functionality, and check to see if there are any errors or warnings. Fix any that occur, and continue in debug mode until they have all been eliminated.

Read more at codex.wordpress.org

Update: It worked! WSOD solved! Activating WP_DEBUG only showed Notices, but I went and fixed every one of them and we’re rolling again! I think the culprit was actually some old nasty code that used to put the wp_query into a temp variable and back. That pattern had gotten mangled across several commits. I ended up ripping it out entirely.

I isolated the cause of my WSOD using the advice from this post: http://jaredheinrichs.com/how-to-troubleshoot-wordpress-white-screen-of-death.html

Basically, it says disable all your plug-ins, then re-enable them one at a time until you hit the WSOD. The plug-in that you last enabled is your suspect.

Posted in Development, Uncategorized | Tagged , | Comments Off on Turn on WP_DEBUG to have WordPress kick out error messages

By default, get_posts only returns posts of type ‘post’

The WordPress project I work on uses a custom post type of ‘Product’ because we use WordPress as an ecommerce solution. I was trying to get a list of those products, but get_posts refused to display them. After consulting the Codex entry for get_posts, I found that by default, get_posts only shows the posts with type ‘post’. My solution was to use this query:

    get_posts('post_type=product');
Posted in Development, Uncategorized | Tagged , | Comments Off on By default, get_posts only returns posts of type ‘post’

Keep the feedback loop velocity high

After working at large companies for so long, it’s refreshing to be able to take ideas directly to the CEO. It’s important to remember that he’s still the CEO, though, so ideas need to be thought out.

Amplify’d from lyndit.com

Having developers and customer service sit together is empowering. They both hear what is going on with customers, hear what is going on in the development process. Teams spend time producing quality, investing in thier own education and being proud to be apart of the Cheezburger community. It is obvious that the leadership sees teams working together as essential. The leadership removes barriers, empowers employees, sets up mentors and nurtures a culture that is focused on quality and fun; these are the key ingredients to destroying to-do lists and moving a business forward.

Read more at lyndit.com

 

Posted in Uncategorized | Tagged , , , | Comments Off on Keep the feedback loop velocity high

Firefox Plugins I Use

Firebug

Best. Web. Development. Tool. Ever. Just install it.

Firecookie

This add on to Firebug allows you to view, manipulate, and delete cookies. This really should just be in Firebug, anyway.

Screen Capture Elite

Very nice screen shot tool. It can also do full page screen shots.

Adblock Plus

As a developer for a company that gets it’s revenue primarily from ads, I don’t encourage you to use an ad blocker. However, sometimes I just need them all to go away while I test some JavaScript.

Xmarks Sync

Bookmark syncing across computers and browsers. I personally use it to sync my bookmarks between Firefox and Chrome.

Html Validator

Displays validation errors for any page when you view source.

Posted in Development, Uncategorized | Tagged | Comments Off on Firefox Plugins I Use

WordPress Plugins I Use

Posted in Development, Uncategorized | Tagged | Comments Off on WordPress Plugins I Use

Moq can’t mock internal methods

Today I was trying to mock a concrete class that had an internal method that I wanted to set the return value for. After much frustration, I discovered that (Google’s) Moq 4.0.10827.0 won’t intercept internal methods.

Consider the code below, the WorksGreat() test calls the Explode() method which is intercepted properly and doesn’t actually call the Bomb.Explode() method.

The ThrowsTheBOOMException() method, even though I’ve told Moq that when InternalExplode is called that it should return 1, it still calls InternalExplode and it does throw the exception.

using System;
using Moq;
using NUnit.Framework;

namespace MoqTester
{
    [TestFixture]
    public class InternalMethodsTest
    {
        [Test]
        public void WorksGreat()
        {
            var bombMock = new Mock<Bomb>();
            var bomber = new Bomber(bombMock.Object);

            bomber.PushTrigger();
            bombMock.Verify(b => b.Explode(), Times.Once());
        }

        [Test]
        public void ThrowsTheBOOMException()
        {
            var bombMock = new Mock<Bomb>();
            bombMock.Setup(b => b.InternalExplode()).Returns(1);
            var bomber = new Bomber(bombMock.Object);

            bomber.InternalPushTrigger();
            bombMock.Verify(b => b.InternalExplode(), Times.Once());
        }
    }

    public class Bomb
    {
        public virtual int Explode()
        {
            return InternalExplode();
        }

        internal virtual int InternalExplode()
        {
            throw new Exception("BOOM!");
        }
    }

    public class Bomber
    {
        private readonly Bomb _bomb;

        public Bomber(Bomb bomb)
        {
            _bomb = bomb;
        }

        public void PushTrigger()
        {
            _bomb.Explode();
        }

        public void InternalPushTrigger()
        {
            _bomb.InternalExplode();
        }
    }
}
Posted in Development, Uncategorized | Tagged | Comments Off on Moq can’t mock internal methods

How to get WP-Super-Cache working on WordPress MU

(I know it’s not called MU anymore, but lets just roll with it.)

At the time of this article I was working with:
WP-Super-Cache version: 0.9.9.6
WordPress version: 3.0.1

I fought for over an hour trying to get WP-Super-Cache working properly on my WordPress install, I hope that this can help you fix yours sooner than I did.

I followed the instructions on WP-Super-Cache’s installation page, but had to do one thing from their troubleshooting section in the FAQs page, too.

  1. I did have to download the plugin manually. Don’t attempt to use the built in plugin installers because they’ll put it in the wrong place.
  2. When you install the plugin, you’ll need to put it into the /wp-content/mu-plugins/ directory. You don’t install anything into the /wp-content/plugins/ directory.
  3. Copy the wp-cache-config-sample.php from the /wp-content/mu-plugins/wp-super-cache/ directory into the /wp-content/ directory. Rename it to wp-cache-config.php. On line 19, change the path from “/plugins/wp-super-cache/” to “/mu-plugins/wp-super-cache/”.
  4. Copy the advanced-cache.php from the /wp-content/mu-plugins/wp-super-cache/ directory into the /wp-content/ directory. On lines 8 and 9, change ‘CACHEHOME’ to  the path of your wp-super-cache directory where the path is the complete path from the root. Mine was ‘/home/<site name>/public_html/wp-content/mu-plugins/wp-super-cache/’

That should help you along your way. WP-Super-Cache was very good at guiding me through the troubleshooting process. There was guidance on editing .htaccess files and setting permissions.

I used the FileZilla ftp client to handle the file transfers and file editing. (I actually use FileZillaPortable) You can view hidden files by clicking on Server -> Force showing hidden files from the menu bar; this allows you to see the .htaccess files. You can also change file and folder permissions from inside FileZilla just as WP-Super-Cache asks you to.

Another semi-helpful post I found was Austin Gulati’s Using the WP Super Cache Plugin.

Posted in Development, Uncategorized | Tagged , | Comments Off on How to get WP-Super-Cache working on WordPress MU

Learning PHP: ISSET() vs. IS_NULL()

I found this little gem while looking into how to determine is a variable is usable; in my case, if it’s been set:

http://php.net/manual/en/function.is-null.php#90782

claude dot pache at gmail dot com
09-May-2009 04:38
A small but important difference between “is_null” and “isset” is the following: “is_null” tests if an *expression* (not a *variable*) is null, while “isset” tests if a *variable* has null value or is undefined. The difference is manifested in the two following experiments:

Experiment 1:

<?php
function test() { return null; }
var_dump(is_null(test())); // displays "true"
var_dump(isset(test())); // parse error, because "test()" is not a variable
?>

Experiment 2:

<?php
error_reporting(E_ALL);
var_dump(isset($an_undefined_variable)); // displays "false" since "$an_undefined_variable" is not defined
var_dump(is_null($an_undefined_variable)); // displays "true" (as expected), but throws a notice because "$an_undefined_variable" is not defined.
?>
Posted in Uncategorized | Tagged | Comments Off on Learning PHP: ISSET() vs. IS_NULL()

Poor Man’s C# Profiling

I needed to time a method in production and needed some context about which methods called it, but didn’t have any great ways to do it. I came up with an idea and I’ll share it here soon. It’s not the best, but it is currently useful and maybe in time it’ll become slicker.

Posted in Uncategorized | Leave a comment