Here's a very simple plugin, which I drop into mu_plugins in my multisite installation:
<?php
/*
Plugin Name: Test
*/
class myclass {
function __construct() {
error_log("I just punched myself in the head.");
}
} // end of class definition
/* start of plugin functions */
function run_plugin() {
static $counter = 0;
if (0 === $counter++)
$i = new myclass();
}
/* start of execution code */
add_action('init','run_plugin');
OK - I log into WP admin, and I switch pages twice -- go to media library then themes. Counting the first landing on index.php there are three page renderings total.
Output of this plugin:
I just punched myself in the head.
I just punched myself in the head.
I just punched myself in the head.
So, given the static counter in the calling function - why is the constructor getting called three times? Or, is WP destroying my plugin and reloading it with every page load?
I'm very confused.