I am looking for a little advice regarding wp_redirect after successful registration, the plan is a new user registers and is then re-directed on success to a custom post type page 'Agent' wp stackexchange question asked here two years ago. The agent page is a profile page containing info entered entered at registration and will be updated with more info by the user after registration.
1) WP_DEBUG is enabled, also enabled is WP_DEBUG_LOG. 2) The bottom of my registration has the redirect as this:
wp_redirect (agent_permalink($user_id)); exit;
also trying this:
wp_redirect ('agent-profile/' . $agent_permalink($user_id)); exit;
Both these (and others i have tried) fail, with a white screen, no WP_DEBUG errors onscreen or written to log. On refreshing the screen it shows the user as registered but stays on registration page.
Using this:
wp_redirect ('agent-profile'); exit;
Gives successful redirection to the custom post type profile page (i can see the "single" CPT classes written in the page source body tag, no 404).
To save WPSE members flicking from this page to the link provided this is the function that covers the member permalink:
function agent_permalink ( $user = '' ) {
if ( ! empty($user) ) {
if ( is_numeric($user) ) { // user id
$userObj = get_user($user);
} else { // user nicename
$userObj = -1;
}
} else {
$userObj = wp_get_current_user();
$name = isset($userObj->user_nicename) ? $userObj->user_nicename : '';
}
if ( ! isset($name) ) $name = $userObj == -1 ? $user : $userObj->user_nicename;
global $wpdb;
$id = $wpdb->get_var( $wpdb->prepare(
"SELECT ID FROM $wpdb->posts WHERE post_name = %s AND post_type = 'agent' AND post_status = 'publish'",
$name
) );
return $id ? get_permalink($id) : '';
}
Qoute from gmazzap This function is flexible, you can use it like: agent_permalink($user_id) also you can use it like agent_permalink($user_nicename).
If the current logged in user is a member, you can use the function like agent_permalink() to retrieve the url of the current logged-in member
The end result that i am trying to achieve is a url structured something like this:
anywebsite.com/agent/agent-profile/username
any help pointing me in the right direction would be appreciated
WP_DEBUG_LOG
and turn onWP_DEBUG_DISPLAY
. More info on debugging in the Codex. tl;dr Log turns Display off per default, in case it's not explicitly stated to stay on – at least IIRC.$agent_permalink
when it is a function and not a variable ?