Log to DB when a plugin was activated

[ad_1]

I could find nothing on how to get this using a plugin so I wrote my own.

​

CREATE TABLE wp_activated_plugins_log ( id int(11) NOT NULL AUTO_INCREMENT, plugin varchar(255) NOT NULL, user_id int(11) NOT NULL, date_activated datetime NOT NULL, PRIMARY KEY (id) );

add_action(‘activated_plugin’, ‘log_activated_plugin’, 10, 2);

function log_activated_plugin($plugin, $network_wide) {
global $wpdb;
$table_name = $wpdb->prefix . ‘activated_plugins_log’;
$user_id = get_current_user_id();
$date_activated = current_time(‘mysql’);
$wpdb->insert(
$table_name,
array(
‘plugin’ => $plugin,
‘user_id’ => $user_id,
‘date_activated’ => $date_activated
),
array(
‘%s’,
‘%d’,
‘%s’
)
);
}

Hope this helps someone

[ad_2]
1 Comment

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer