Last active
March 1, 2017 08:39
-
-
Save xnau/174b808857600b0b3fa6aed0712556e0 to your computer and use it in GitHub Desktop.
Record the user who created or edited a record in the backend
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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