creating custom function to log actions in plugin

This is my first go at WordPress plugin development and any help you folks can give me would be appreciated.

This plugin needs to keep careful track of how users interact with certain areas of it. I have a table to log the data. I have written this function (defined in the plugin’s class):

public function update_history($userid,$idevent,$eventdesc,$log){
//get a database object
echo “we got here”;
global $wpdb;
$table_name = $wpdb->prefix . ‘pw_history_log’;
//values to write to database
$item = array(‘iduser’ => $userid,’ieventcode’ => $idevent,’dtevent’ => date(“Y-m-d H:i:s”),’szactiondesc’ => $eventdesc,’siteid’ => $log);
// format values
$format = array(‘%d’,’%d’,’%s’,’%s’,’%d’);
// Insert the data
$wpdb->insert($table_name, $item, $format );

I’m trying to call it elsewhere like this:

do_action(‘update_history’, 333, 2001, “test event”, 1);
add_action( ‘init’, ‘update_history’, 10, 4);

I’m not getting errors. I’m not getting data in the database. I’m not getting any sign of the silly echo statement I tossed in, either. So…the function isn’t running.

Can anyone point me in the right direction? I’m feeling really stupid here.

Read more here:: creating custom function to log actions in plugin

Leave a Reply

Your email address will not be published. Required fields are marked *