Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Using a custom query parameter to dynamically specify a user ID for editing with Advanced Forms Pro.
<?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