Last active
October 14, 2017 18:30
-
-
Save xnau/c63c9424d8b660f1f93ee3e003644de8 to your computer and use it in GitHub Desktop.
Shows how to record the user ID of the person editing a Participants Database record
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_update', 'xnau_record_last_user' ); | |
/** | |
* record the user who created or edited a record in the backend | |
* | |
* @see https://codex.wordpress.org/Function_Reference/wp_get_current_user | |
* | |
* @param array $record the record data | |
*/ | |
function xnau_record_last_user( $record ) | |
{ | |
$current_user = wp_get_current_user(); | |
if ( $current_user->ID != '0' ) { | |
$user_id_field = 'user_id'; // name of the PDB field where the user's ID is stored | |
global $wpdb; | |
// you could also record the user's login or name...see the link above for what you can get from $surrent_user | |
$data = array( $user_id_field => $current_user->ID ); // get the user's ID 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