Using a custom query parameter to dynamically specify a user ID for editing with Advanced Forms Pro.
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_filter( 'af/form/args', 'afp_demo_support_dynamic_user_editing', 10, 2 ); | |
/** | |
* @param array $args | |
* @param array $form | |
* | |
* @return array | |
*/ | |
function afp_demo_support_dynamic_user_editing( $args, $form ) { | |
// If there is no query arg, return early. | |
if ( ! isset( $_GET['afp_edit_user'] ) ) { | |
return $args; | |
} | |
// You should consider adding capability checks here to ensure the | |
// current logged in user is allowed to edit the requested user. | |
// Extract the user ID from the custom query arg and add it to the | |
// form args. | |
$args['user'] = intval( $_GET['afp_edit_user'] ); | |
return $args; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment