WordPress MultiSite, Plugins and Activation

WordPress offers for normal Plugins the hook register_activation_hook();. This is active right after the activation of a Plugin, so you can start small installation scripts. But if we are in a MultiSite environment (old: MultiUser) and put the Plugin in the folder wp-content/mu-plugins, then the hook doesn't do anything, because the Plugin is automatically activated. But there are few ways you can still have a kind of activation hook. One is this option:

if ( ! class_exists( 'my_mu_plugin' ) ) {

    if ( function_exists( 'add_action' ) ) {
        add_action( 'plugins_loaded' ,  array( 'my_mu_plugin', 'get_object' ) );
    class my_mu_plugin {

        static private $classobj = NULL;

        public function get_object () {
            if ( NULL === self :: $classobj ) {
                self :: $classobj = new self;
            return self :: $classobj;
        public function __construct () {
            // Fake-Activation-Hook
        private function activation () {
            if ( 'activated' == get_blog_option( 1, 'my_mu_plugin_activated' ) ) {
                // Do Stuff during activation
                // Update Option
                update_blog_option( 1, 'my_mu_plugin_activated', 'activated' );



We are doing the following: We check whether a certain option is set in blog 1, if not, then run through an activation function, otherwise do nothing - Blog 1 simple so that the install script is only in blog 1 in use. If you want to use it in all the blogs then simply use the function get_option(). Easy, right?

Guest Post

This post is written by Thomas Herzog - hughwillfayle.de and is a guest post on WP Engineer about WordPress.
Thank you very much from my part to Thomas. Please see his nice plugins on the official WordPress repository.
If you also like to have your interesting post published on our website, please let us know on our contact page. Of course we will appreciate your contribution!

Localization with JavaScript in WordPress

Creating Plugins and Theme functions with multilanguage capability has been established knowadays.Especially for us as German developers it is a must have. But there are some difficulties if you are using JavaScript, the question is how to provide it multilingual or provide option values in different languages. WordPress offers some possibilities and I like to show them, since this question was asked by many and developers are searching for solutions. The following little example should show the realization and the easy output of strings demonstrates it. Wether strings for multilanguage or providing options values, it doesn't matter.
Continue reading …

Adding Input Fields To Comment Form

Most comment forms contain the same input fields: Name, Email, URL and the comment text field. This is sufficient for most use cases but there are situations where you might want to know a bit more about your commenter: their age, the city they live in, or the color of their underwear. This article explains how to add an input field, store the data in the database and how to display the additional data in your blog if your theme uses the comment_form() function provided by WordPress. Continue reading …

Comment Form Hooks Visualized

Most themes (e.g. TwentyTen) use the comment_form() function to insert the comment form after posts. There are quite some hooks inside the function but they are hard to localize. The codex documentation isn't too helpful, neither.
To give you an easy overview the following diagrams visualize the points where the various hooks are anchored. The number of available hooks depend on the discussion settings and the user's capabilities.

In the most common scenario the user is not logged in, is allowed to comment on the article and the comments are not closed:

There are six hooks available:

  • comment_form_before
  • comment_form_top
  • comment_form_before_fields
  • comment_form_after_fields
  • comment_form
  • comment_form_after

You might have noticed that the hooks comment_form and comment_form_after seem to be anchored almost at the same point but depending on the user's role and discussion settings they are not always available so you should take care which hook you are using in your code.

User logged in
If you are logged in you have fewer hooks available since the name, email and URL input fields are not needed. The missing hooks are

  • form_comment_before_fields
  • form_comment_after fields

User is not logged and "Users must be registered and logged in to comment" activated
If your blog is configured that only registered users can comment, an unregistered user will see this comment form and additionally the hook comment_form_must_log_in_after is available. Please notice that in this case the hook comment_form is left out.

Comments closed
If the comments on the post are closed you have only one hook left (comment_form_closed) since the form is not displayed at all:

php-Console with Chrome and WordPress

Google Browser Chrome and their Chromium project are becoming more popular. Initially it was the speed of Chrome, which made it so popular but now also the extensions are getting in the focus of the users. Nowadays the extension market of Chrome is full of very useful extensions. Of course there are also many enhancements in the context of web development that have helped Firefox to fame.

In the field of PHP development, I've always looked at several solutions, played with different options and in the end I'm sitting in front of a browser with IDE, XDebug or some of my own extensions. In Firefox I have used FirePHP in various areas, more information about it can be found in this article. Alternatively I also wrote about the debugConsole. Therefore it was natural to browse for a solution in the environment of Chromium. You will be able to find some interesting topics about it and I would like to introduce php-console and show how to integrate it in WordPress via Plugin.
Continue reading …