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 ); | |
} | |
); | |
} | |
Hi,
I'm sorry but I think there is a problem in your php file. When I try to activate this plugin as you told me (after modification and without modification) here is the message I get:
https://user-images.githubusercontent.com/36070788/35727689-437d6a16-0809-11e8-9f31-33c205b3f7ce.png
Please can you help me ? :)
Thanks
Yes, you're right, the function should have the "public" keyword. I fixed it.
I had to make a couple of changes to this script...there were a few errors...but it's tested working now.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can install this as a plugin, just download the .zip and use the WP plugin installer to upload the zip file.
Of course, you will have to modify this to your particular setup and needs.
You'll want to test this with your php error log set up. It will throw an error if the defined record values are not found so that you can make sure you've got it working correctly.