Last active
February 6, 2018 18:30
-
-
Save xnau/6b9b703b719978d3fe2c9f990d8a2b3b to your computer and use it in GitHub Desktop.
Demonstrates how to alter the redirect according to a value in the user's record when using the PDB Login add-on
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 | |
/* | |
Plugin Name: Redirect PDB Login | |
Description: Alters the redirect according to a value in the user's record when using the PDB Login add-on | |
*/ | |
add_action( 'pdb-login_after_validate_submission', 'xnau_setup_pdb_login_redirect', 10, 2 ); | |
/** | |
* sets up the redirect filter | |
* | |
* this checks the newly-logged-in user's record and | |
* sets up the redirect accodingly | |
* | |
* this example inspects the user's record for a field named "type" | |
* and redirects the user according to the value found: 'red' or 'green' | |
* | |
* @param object $record the user's record | |
* @param bool $validated true if the user's login was validated | |
* @return null | |
*/ | |
function xnau_setup_pdb_login_redirect( $record, $validated ) | |
{ | |
if ( ! $validated ) { | |
// skip if not validated | |
return; | |
} | |
switch ( $record->type ) { | |
case 'red': | |
// set the redirect to the page slug | |
$redirect = 'red-record-edit'; | |
break; | |
case 'green': | |
$redirect = 'green-record-edit'; | |
break; | |
} | |
/* | |
* this filter uses an anonymous function, we pass the $redirect value | |
* into that function with 'use' | |
*/ | |
add_filter( 'pdb-login_redirect', function ($default_redirect) use ( $redirect ) { | |
return Participants_Db::find_permalink( $redirect ); | |
} | |
); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I had to make a couple of changes to this script...there were a few errors...but it's tested working now.