Skip to content

Instantly share code, notes, and snippets.

@xnau
Last active March 1, 2017 08:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xnau/174b808857600b0b3fa6aed0712556e0 to your computer and use it in GitHub Desktop.
Save xnau/174b808857600b0b3fa6aed0712556e0 to your computer and use it in GitHub Desktop.
Record the user who created or edited a record in the backend
<?php
add_action( 'pdb-after_submit_add', 'xnau_record_backend_user' );
add_action( 'pdb-after_submit_update', 'xnau_record_backend_user' );
/**
* record the user who created or edited a record in the backend
*
* @param array $record the record data
*/
function xnau_record_backend_user( $record )
{
$user_id_field = 'user_id'; // name of the PDB field where the user's ID is stored
if ( is_admin() ) {
global $wpdb, $current_user;
$data = array( $user_id_field => $current_user->user_login ); // get the user's login name and place it in the ID field
$wpdb->update( Participants_Db::$participants_table, $data, array( 'id' => $record['id'] ) );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment