• I allow users to sign up with their first name, last name and e-mail addresses. I want to make their first name and last name as slug. For example user first name is “John” and last name is “James”. The slug should be example.com/users/john-james/ I do not want to use any plugin.

    Edit:

    There are already 300 registered members on the website and i want to change their slug too.

    • This topic was modified 5 years, 8 months ago by jsima.
    • This topic was modified 5 years, 8 months ago by jsima.
Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    There are two aspects to deal with: the current users, and any new users. To update current users, you need to run a SQL UPDATE query on the users table, pulling data from user meta. There is no handy way to do this in WP. Depending on how comfortable you are with PHP or SQL, either approach will work. You could create a one time use PHP script to do this, or compose a SQL query that is run in phpMyAdmin. In either case, test thoroughly on a limited subset of users before turning it loose in all users. Also be sure to make a DB backup before making any changes.

    For new users, you can use the “sanitize_user” filter to force a particular login be used for new users. This doesn’t remove the login field from the registration form though. I believe you can just hide the field with CSS. AFAIK WP will not yet kick out an empty username field submission as long as something valid comes back from “sanitize_user”.

    The sanitize_user filter fires before anything is saved, so you must rely upon submitted data in $_POST to compose the login name. Since these values are not yet sanitized, you must do your own sanitation and validation of such values. Check out the source code for sanitize_user() to see how WP sanitizes usernames and to see how the filter is applied.

Viewing 1 replies (of 1 total)
  • The topic ‘How do i make/change user’s first and last name as user slug’ is closed to new replies.