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

  • Turn off WP_DEBUG_LOG and turn on WP_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. – kaiser Mar 1 '16 at 14:38
  • @Kaiser, done as you say, still seeing a white page and no logged errors after submitting registration form using the permalinks redirect code, – MartinJJ Mar 1 '16 at 14:54
  • I can rule out this redirect: wp_redirect ('agent-profile/' . $agent_permalink($user_id)); exit; (error-log says it must be a string), this: wp_redirect (agent_permalink($user_id)); exit; still gives a white page and no error – MartinJJ Mar 1 '16 at 15:07
  • Why would you use $agent_permalink when it is a function and not a variable ? – kaiser Mar 1 '16 at 15:17
  • I guess i'm trying to run before i can walk, its been a long long time since i did any coding whatsoever and i seem to have forgotten more than i knew in the first place, the good news is your comment pointed me in the right direction, i scrapped the agent_permalink function and went back to basics, this redirect works, although its a bit long: wp_redirect (home_url('agents/agent-profile/' . ($user_id))); exit; – MartinJJ Mar 1 '16 at 16:06

Thanks to Kaiser for pointing me in the right direction:

I scrapped the agents_permalinks function and went for this for the redirect and it works as intended:

wp_redirect (home_url('agents/agent-profile/' . ($user_id))); exit;  

Your Answer

 
discard

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.