Skip to main content
simplified code
Source Link
fuxia
  • 107.1k
  • 38
  • 255
  • 459

You can hook into the action 'deactivate_plugin' to get the plugin's base name and (as second parameter) if it was deactivated network wide.

See wp-admin/includes/plugin.php function deactivate_plugins().

There seems to be no hook for plugin deletion.

Sample logging code:

add_action( 'activated_plugin', 't5_plugin_logger', 10, 2 );
add_action( 'deactivated_plugin', 't5_plugin_logger', 10, 2 );

/**
 * Log plugin activations and deactivations.
 *
 * @param  string $plugin
 * @param  bool   $network_wide
 * @return void
 */
function t5_plugin_logger( $plugin, $network_wide )
{
    $log_size = 20;
    $log      = get_option( 't5_plugin_log' );
    ! $log && $log =, array () );

    // Remove the oldest entry.
    sizeof( $log ) > $log_size and array_shift( $log );

    $plugin_data = get_plugin_data( WP_PLUGIN_DIR . '/' . $plugin );
    $date_format = get_option( 'date_format' ) . ' · ' . get_option( 'time_format' );

    $log[] = array (
        'user'    => esc_html( wp_get_current_user()->display_name ),
        'plugin'  => $plugin_data['Name'],
        'network' => $network_wide ? '✔' : '',
        'time'    => date( $date_format, time() ),
        'action'  => 'deactivated_plugin' === current_filter() ? 'deactivated' : 'activated'
    );

    update_option( 't5_plugin_log', $log );
}

Now every plugin activation or deactivation will be added to the log option field. You can use this data anywhere. I made a small dashboard widget:

enter image description here

Download as plugin from GitHub: T5 Plugin Log

You can hook into the action 'deactivate_plugin' to get the plugin's base name and (as second parameter) if it was deactivated network wide.

See wp-admin/includes/plugin.php function deactivate_plugins().

There seems to be no hook for plugin deletion.

Sample logging code:

add_action( 'activated_plugin', 't5_plugin_logger', 10, 2 );
add_action( 'deactivated_plugin', 't5_plugin_logger', 10, 2 );

/**
 * Log plugin activations and deactivations.
 *
 * @param  string $plugin
 * @param  bool   $network_wide
 * @return void
 */
function t5_plugin_logger( $plugin, $network_wide )
{
    $log_size = 20;
    $log      = get_option( 't5_plugin_log' );
    ! $log && $log = array ();

    // Remove the oldest entry.
    sizeof( $log ) > $log_size and array_shift( $log );

    $plugin_data = get_plugin_data( WP_PLUGIN_DIR . '/' . $plugin );
    $date_format = get_option( 'date_format' ) . ' · ' . get_option( 'time_format' );

    $log[] = array (
        'user'    => esc_html( wp_get_current_user()->display_name ),
        'plugin'  => $plugin_data['Name'],
        'network' => $network_wide ? '✔' : '',
        'time'    => date( $date_format, time() ),
        'action'  => 'deactivated_plugin' === current_filter() ? 'deactivated' : 'activated'
    );

    update_option( 't5_plugin_log', $log );
}

Now every plugin activation or deactivation will be added to the log option field. You can use this data anywhere. I made a small dashboard widget:

enter image description here

Download as plugin from GitHub: T5 Plugin Log

You can hook into the action 'deactivate_plugin' to get the plugin's base name and (as second parameter) if it was deactivated network wide.

See wp-admin/includes/plugin.php function deactivate_plugins().

There seems to be no hook for plugin deletion.

Sample logging code:

add_action( 'activated_plugin', 't5_plugin_logger', 10, 2 );
add_action( 'deactivated_plugin', 't5_plugin_logger', 10, 2 );

/**
 * Log plugin activations and deactivations.
 *
 * @param  string $plugin
 * @param  bool   $network_wide
 * @return void
 */
function t5_plugin_logger( $plugin, $network_wide )
{
    $log_size = 20;
    $log      = get_option( 't5_plugin_log', array () );

    // Remove the oldest entry.
    sizeof( $log ) > $log_size and array_shift( $log );

    $plugin_data = get_plugin_data( WP_PLUGIN_DIR . '/' . $plugin );
    $date_format = get_option( 'date_format' ) . ' · ' . get_option( 'time_format' );

    $log[] = array (
        'user'    => esc_html( wp_get_current_user()->display_name ),
        'plugin'  => $plugin_data['Name'],
        'network' => $network_wide ? '✔' : '',
        'time'    => date( $date_format, time() ),
        'action'  => 'deactivated_plugin' === current_filter() ? 'deactivated' : 'activated'
    );

    update_option( 't5_plugin_log', $log );
}

Now every plugin activation or deactivation will be added to the log option field. You can use this data anywhere. I made a small dashboard widget:

enter image description here

Download as plugin from GitHub: T5 Plugin Log

Added sample code and a screen shot.
Source Link
fuxia
  • 107.1k
  • 38
  • 255
  • 459

You can hook into the action 'deactivate_plugin' to get the plugin's base name and (as second parameter) if it was deactivated network wide.

See wp-admin/includes/plugin.php function deactivate_plugins().

There seems to be no hook for plugin deletion.

Sample logging code:

add_action( 'activated_plugin', 't5_plugin_logger', 10, 2 );
add_action( 'deactivated_plugin', 't5_plugin_logger', 10, 2 );

/**
 * Log plugin activations and deactivations.
 *
 * @param  string $plugin
 * @param  bool   $network_wide
 * @return void
 */
function t5_plugin_logger( $plugin, $network_wide )
{
    $log_size = 20;
    $log      = get_option( 't5_plugin_log' );
    ! $log && $log = array ();

    // Remove the oldest entry.
    sizeof( $log ) > $log_size and array_shift( $log );

    $plugin_data = get_plugin_data( WP_PLUGIN_DIR . '/' . $plugin );
    $date_format = get_option( 'date_format' ) . ' · ' . get_option( 'time_format' );

    $log[] = array (
        'user'    => esc_html( wp_get_current_user()->display_name ),
        'plugin'  => $plugin_data['Name'],
        'network' => $network_wide ? '✔' : '',
        'time'    => date( $date_format, time() ),
        'action'  => 'deactivated_plugin' === current_filter() ? 'deactivated' : 'activated'
    );

    update_option( 't5_plugin_log', $log );
}

Now every plugin activation or deactivation will be added to the log option field. You can use this data anywhere. I made a small dashboard widget:

enter image description here

Download as plugin from GitHub: T5 Plugin Log

You can hook into the action 'deactivate_plugin' to get the plugin's base name and (as second parameter) if it was deactivated network wide.

See wp-admin/includes/plugin.php function deactivate_plugins().

There seems to be no hook for plugin deletion.

You can hook into the action 'deactivate_plugin' to get the plugin's base name and (as second parameter) if it was deactivated network wide.

See wp-admin/includes/plugin.php function deactivate_plugins().

There seems to be no hook for plugin deletion.

Sample logging code:

add_action( 'activated_plugin', 't5_plugin_logger', 10, 2 );
add_action( 'deactivated_plugin', 't5_plugin_logger', 10, 2 );

/**
 * Log plugin activations and deactivations.
 *
 * @param  string $plugin
 * @param  bool   $network_wide
 * @return void
 */
function t5_plugin_logger( $plugin, $network_wide )
{
    $log_size = 20;
    $log      = get_option( 't5_plugin_log' );
    ! $log && $log = array ();

    // Remove the oldest entry.
    sizeof( $log ) > $log_size and array_shift( $log );

    $plugin_data = get_plugin_data( WP_PLUGIN_DIR . '/' . $plugin );
    $date_format = get_option( 'date_format' ) . ' · ' . get_option( 'time_format' );

    $log[] = array (
        'user'    => esc_html( wp_get_current_user()->display_name ),
        'plugin'  => $plugin_data['Name'],
        'network' => $network_wide ? '✔' : '',
        'time'    => date( $date_format, time() ),
        'action'  => 'deactivated_plugin' === current_filter() ? 'deactivated' : 'activated'
    );

    update_option( 't5_plugin_log', $log );
}

Now every plugin activation or deactivation will be added to the log option field. You can use this data anywhere. I made a small dashboard widget:

enter image description here

Download as plugin from GitHub: T5 Plugin Log

Source Link
fuxia
  • 107.1k
  • 38
  • 255
  • 459

You can hook into the action 'deactivate_plugin' to get the plugin's base name and (as second parameter) if it was deactivated network wide.

See wp-admin/includes/plugin.php function deactivate_plugins().

There seems to be no hook for plugin deletion.