Last active
March 25, 2017 18:30
-
-
Save xnau/23776d1ce69ec35a307a6ac972daf918 to your computer and use it in GitHub Desktop.
demonstrates how to reset the private ID after it is used to open a record edit page
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 | |
/* | |
* 3-20-17 updated to run on pdb-before_submit_update filer | |
* | |
*/ | |
add_filter( 'pdb-before_submit_update', 'pdb_otu_regenerate_pid' ); | |
/** | |
* regenerates the private id for the current record | |
* | |
* @param array $post the posted data | |
* @return array the post data | |
*/ | |
function pdb_otu_regenerate_pid( $post ) | |
{ | |
// check if the record ID is already in the session | |
$record_id = Participants_Db::$session->get('pdbid'); | |
if ( | |
! is_admin() && | |
! $record_id | |
) { | |
global $wpdb; | |
$wpdb->update( | |
Participants_Db::$participants_table, | |
array('private_id' => Participants_Db::generate_pid() ), | |
array('id' => $post['id']) | |
); | |
/* | |
* this is so the user will continue to have access to the record page and | |
* the private ID won't get renewed again | |
*/ | |
Participants_Db::$session->set( 'pdbid', $post['id'] ); | |
} | |
return $post; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment