Skip to content

Instantly share code, notes, and snippets.

@xnau
Last active March 25, 2017 18:30
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/23776d1ce69ec35a307a6ac972daf918 to your computer and use it in GitHub Desktop.
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
<?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