Execute a SQL Statement on WordPress Login

This is probably a simple question for someone who knows wordpress well.

I’m trying to execute a sql statement that updates a field every time a user logs in. Rather than create a whole plugin I thought I could just amend the login script to execute the SQL statement, but I am having trouble finding/deciding what file I should edit.

Read More

Should I edit the template file? Something like header.php check if the user is logged in and then execute or should I add it to the actual wp-login.php file?

Any thoughts are appreciated as I am new to wordpress and don’t know what the best practices are yet.

Related posts

Leave a Reply

1 comment

  1. WordPress has many so-called action hooks that allow you to do thing when certain events occur. There is one called wp_login that fires whenever someone logs in.

    You can add the following to your functions.php file:

    function log_login() {
    // update what you want in the database
    }
    add_action('wp_login', 'log_login');
    

    This will get called whenever someone logs in.