Regardless of how you feel about trigger warnings, you have to appreciate that someone has taken the time to investigate their origins on their own terms, rather than simply tut-tutting them.

Want to get bent about “PC culture run amok”? How about, don’t?

It’s about how one professor coming under Title IX investigation for an article containing a veiled attack on a student is part of the “political correctness gone mad” narrative but another professor straight-up losing his job for negative tweets about Israel is not. It’s about how conservatives get to revise the AP U.S. history exam and kill a Smithsonian exhibit about the Hiroshima bombing because they both contain facts that make them uncomfortable, but this isn’t labeled as “political correctness.” It’s about how Mel Gibson kills his Hollywood career with a rambling anti-Semitic rant and Rose McGowan gets blacklisted for a single snarky tweet about sexist casting notices–but only the former is “censorious p.c. culture,” the latter is just Hollywood businessmen protecting the feelings of the people who sign their checks.

What happens to affective teaching labor when it runs up against robots, against automation? Even the tasks that education technology purports to now be able to automate – teaching, testing, grading – are shot through with emotion when done by humans, or at least when done by a person who’s supposed to have a caring, supportive relationship with their students. Grading essays isn’t necessarily burdensome because it’s menial, for example; grading essays is burdensome because it is affective labor; it is emotionally and intellectually exhausting.

Audrey Watters, Hack Education

“IF ONLY WE WE ALL NICER TO EACH OTHER!” – Jeb Bush

“When my son steps out every day, I don’t know if he’s gonna step back in because of racial tension,” one woman says, before asking, “How do you relate to that?”

“I relate to it by, as president, trying to create a society where there is civility and understanding,” Bush responds. “And to encourage mayors, leaders at the local level, to engage so that there’s not despair and isolation in communities.”

Rookie mistakes.

A Better WordPress Singleton

If you look at any WordPress plugin of significant size, you’ll probably find most of them boot the same way. From BuddyPress, to PressForward, to JetPack, all of these boot the same way: with singletons. JetPack in particular is interesting, as many of its modules are also singletons themselves. It’s an extremely common pattern in WordPress plugin development, wrapping the main plugin class in a singleton and instantiating it through a static method, which then enforces only a single instance of the class exists and can ever exist. The prototypical example looks like this in PHP:

class PluginClass
{
    public static $instance = null;
    
    public static function init()
    {
        if ( null === self::$instance ) {
            self::$instance = new PluginClass();
            self::$instance->boot();
        }

        return self::$instance;
    }
    
    protected function __construct()
    {
        // Startup
    }
    
    protected function boot()
    {
        // Boot
    }
}

PluginClass::init();

Note the protected constructor: This means that the class can only be instantiated by itself (in this case, by the static init method), so no other code can create a new instance of the class. That same init method saves the . The second time, the instance already exists statically and is returned directly.

Singletons are generally an anti-pattern in wider object-oriented development. The biggest issue is if you ever find yourself needing two instances of the object, you’re screwed; it’ll take a ton of refactoring to undo all the locations in which the singleton static method is called.

Singletons are generally much worse in other languages, like Java, where the application is long-running and there is a shared memory space. The drawbacks often encountered in those languages are not encountered in PHP, with its stateless, single-thread, fire-and-die approach to web development.

Even though I’m a big fan of WordPress generally, it’s full of anti-patterns (omg the globals!), so I’m not really that bothered by the idea of plugin developers adding another one onto the heap, and in this case, it actually solves a lot more problems than it causes because in WordPress, you don’t want multiple instance of your main plugin class floating about. However, the singleton pattern does still have an issue in WordPress:

You’ve completely locked yourself off from your constructor.

This generally isn’t a huge issue in WordPress plugins, as most plugins don’t do any kind of unit testing, but if you’re interested in doing unit testing and your main plugin class has any dependencies at all, being unable to access your constructor means you’re unable to mock any of those dependencies, or pass in anything at all.

I’ve spent a little bit of time playing around with Laravel, Pimple, and some of the other dependency injection containers out in the wider PHP world, because I wanted to more effectively unit test my plugins, and in addition to the singleton pattern, many of those main singleton classes also function effectively as containers as well. PressForward sets up all its dependencies there and uses them throughout the application, so I wanted to build something that fits with the pattern many WordPress plugin developers are already familiar with. That means the main application container class should be a singleton.

Instead of through static methods, you can enforce the class’s singleton-ness the class’s constructor:

class PluginClass
{
    protected static $instance = null;
    
    public function __construct($file)
    {
        if (static::$instance !== null) {
            throw new Exception;
        }

        static::$instance = $this;
    }

    public static function get()
    {
        return static::$instance;
    }
}

Now, if an instance already exists, an Exception is thrown, so another developer would not be able to instantiate a new instance of the main plugin class. The constructor its is now exposed, so any dependencies, even if it’s just the boot file location, can be passed into the main class, and the class’s singleton-ness is still maintained.

Now, you might think you just throw $app = new PluginClass(__FILE__); into your main plugin file and you’re good to go, but you’d be wrong. We’re doing all this work to minimize the number of global variables, so that would be a bad idea. You could wrap it in a function so no global variables are leaked, but then you’ve added a global function (less of a problem, but still a problem). So there’s one more trick I’d like to share:

call_user_func(array(new PluginClass(__FILE__), 'boot'));

This was pulled from a suggestion in a pull request on the WordPress Plugin Boilerplate, so I can’t claim credit for it, but it is a great way of solving the global problem. Now, the class is instantiated, its boot method is run, access to its constructor is preserved, no globals are leaked, and you still enforce it as a singleton.

This singleton design is implemented in the WordPress plugin framework I’m building, jaxion, so you can see the current implementation here. The boot method will be the default startup for jaxion-boostrap, the plugin boilerplate built on jaxion. You can see the current implementation here.

What do you think? Will you start using this singleton pattern in your WordPress plugins?

This post is part of the thread: Project: wppb-mod - an ongoing story on this site. View the thread timeline for more context on this post.

Trump is not a troll but exactly the result we should expect from our political and media systems:

Trump is called a troll because he’s said to not be a real candidate running a real campaign, that he’s not playing by the standard rules and not engaging in politics and democracy in good faith. But this is what makes Trump like the rest of the candidates and campaigns. That Trump is gaming the election coverage isn’t some kind of unsolvable problem but what such coverage asks for. As the Diana Christensen character says in the film Network (1976), “If you’re going to hustle, at least do it right.” The “Trump problem” for journalists is solved the moment we stop presupposing that the rest of the candidates and news coverage is real and in good faith.

Keep screwing up like this, WordPress, and you won’t own 24% of the web for long.

At a time when the Republicans are beclowning themselves, liberal Democrats need only to remain cohesive and even-keeled while the right hangs itself politically. But when it appears as if even the most liberal of the Democratic candidates are out of touch with African-American activists, and when it appears as if the progressive base is caught in the throes of in-fighting, it exposes political weaknesses to be exploited.