Now that I have a plugin that can be activated and deactivated, it might be nice to know when the plugin has completed loading.

In the code below, I have added a function for this (line 43) , and an action hook (line 48). I’ve also added some comments to help explain things better. Also notice the echo statement (line 44). It’s only there for development of course, but it proves that the function is being called.

<?php
/*
Plugin Name: My Plugin
Plugin URI: http://blog.kennyray.com
Description: This is a plugin
Version: 1.0
Author: Kenny Ray
Author URI: http://blog.kennyray.com
License: GPL2
*/

/*  Copyright 2013  Kenny Ray  (email : kenny@blog.kennyray.com)

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License, version 2, as 
    published by the Free Software Foundation.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
*/

// Runs upon plugin activation
function activate_my_plugin(){

}

// Runs upon plugin deactivation
function deactivate_my_plugin(){

}

// Registers the plugin activation and deactivation hooks
register_activation_hook( __FILE__, 'activate_my_plugin' );
register_deactivation_hook(__FILE__, 'deactivate_my_plugin' );

// Runs after all activated plugins have completed loading
function my_plugin_finished_loading() {
    echo "My Plugin Finished Loading";
}

// Causes the function above to run after all activated plugins finish loading
add_action( 'plugins_loaded', 'my_plugin_finished_loading' );

?>

It is interesting to note that this action fires after *all* activated functions are finished loading. This could come in handy if you need to reference a different plugin from this one.

API reference: http://codex.wordpress.org/Plugin_API/Action_Reference/plugins_loaded

WordPress Plugin Hooks: Plugin Finished Loading