Skip to content

Instantly share code, notes, and snippets.

@mishterk
Last active October 21, 2020 00:58
Show Gist options
  • Save mishterk/a932172e356576b59ee2e34fe0849008 to your computer and use it in GitHub Desktop.
Save mishterk/a932172e356576b59ee2e34fe0849008 to your computer and use it in GitHub Desktop.
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