To store the user defined value into the DB you can use the update_user_meta()
function. And retrieve back the info with get_user_meta()
. You could update the the user meta key with an AJAX call on your select
change or put your select
in a form and update on form submit either with $_GET
or $_POST
method. Your choice here would influence if you need to build a function that listens on a $_POST
, $_GET
or AJAX
request to update your user metadata.
You would also need to use wp_get_current_user
to know the ID of the user to be supplied to the update_user_meta()
and get_user_meta()
functions.
Finally, using wp_login
action hook, you could reinitialise to the default value of the current year by calling update_user_meta()
again. Alternatively, you could do some actions on the wp_logout
hook
Note that it is ok to use update_user_meta
even if the key doesn’t exists, as the function will create it, if it doesn’t find a matching key for that user.
Check the wp_ajax_(action)
hook to learn how to create your handler for your AJAX requests.