Introduction

Since 1.1.0, developers can add custom steps to the sign-up flow. On version 1.4.0, the process of expanding the sign-up became much more flexible and easier to use.

Step 1: Add a Custom Step

To add a new step to your sign-up flow, you’ll need to use the function wu_add_signup_step. The sign-up flows load pretty early in during the WordPress startup, so we need to hook into the ‘init’ action hook.

This code can be placed inside the functions.php file of your main site’s active theme. Let’s say we want to add a User Information step, where we’ll collect the user’s first and last name.

/**
 * We need to hook as soon as we can, to make sure we
 * modify the steps before they get used
 */
add_action('init', function() {
 
    /**
     * First, we add a new step. The ID of this step is customer-info
     * We also pass a order value of 33, that means that our custom step will sit between
     * the third (order 30) and forth (order 40) steps.
     */
wu_add_signup_step('customer-info', 33, array(
'name' => 'User Information',
));

});

Step 2: Adding Fields to your Step (or any other step, really)

After creating our step, we should be able to add fields to it. To add fields, we’ll make use of the function wu_add_signup_field().

Inside the same hook, we’ll add three fields: First Name, Last Name, and a submit button for that step.

/**
 * We need to hook as soon as we can, to make sure we
 * modify the steps before they get used
 */
add_action('init', function() {

    /**
     * First, we add a new step. The ID of this step is customer-info
     * We also pass a order value of 33, that means that our custom step will sit between
     * the third (order 30) and forth (order 40) steps.
     */
wu_add_signup_step('customer-info', 33, array(
'name' => 'User Information',
));

    /**
     * Now we add the fields
     * The first argument tells the API the step we want to add fields to, in our case, customer-info
     * The type argument tells which type of field we should render, we currently support
     * text, number, password, email, url, html, submit
     */
wu_add_signup_field('customer-info', 'first_name', 10, array(
'name'    => 'First Name',
'tooltip' => "Tooltip text to give the user tips about the field (optional)",
'type'    => 'text',
));

wu_add_signup_field('customer-info', 'last_name', 20, array(
'name'    => 'Last Name',
'tooltip' => "Tooltip text to give the user tips about the field (optional)",
'type'    => 'text',
));

    /**
     * Lastly, we add a submit button for that step
     */
wu_add_signup_field('customer-info', 'submit', 100, array(
'name'    => 'Go to next step',
'type'    => 'submit',
));

});

Note that the first value the function takes is the id of the step we want to add that field to, and the third value the function takes refers to the order of the fields.

When adding new fields. you are limited to custom steps you created. You can also add fields to every step that has a form display (like the domain and account steps). Use the order attribute to include your custom fields in the right positions.

Field Types

WP Ultimo currently supports the following field types: text, number, password, email, url, select, html, and submit. 

The select field takes an ‘options’ argument, that should contain an array with key => values.

The HTML field takes a ‘content’ argument that takes pretty much everything you would like to put in there.

Take a look at the file /inc/class-wu-signup.php to have a better feeling of how the fields array should be structured.

Retrieving the data

All the extra fields added to the sign-up flow get saved as default WordPress user meta data. That means that you don’t have to do anything else in order to save the contents of the extra fields you’ve added to the sign-up. It just works. This data can then be retrieved using standard WordPress functions like get_user_meta.

We also added a handy shortcode to display that information on the front-end: [wu_user_meta]. It takes a user_id argument (which you can leave blank as it defaults to the current site’s owner id) and meta_name, which describes the name of the meta info you want to retrieve. To get the user’s last name, for example, you would simply add a [wu_user_meta meta_name=”last_name”].

Another advantage of this approach is that WordPress already uses meta data to store major information about the user. If you create fields that match the specific keys used by WordPress, that information will get automatically updated. This means that in order to update the First and Last Name fields on the user profile’s page, you can just create two fields with the ids of first_name and last_name, like in the example above.

Did this answer your question?