How to add user roles dropdown in registration and login woocommerce wordpress

madu

I have a job site but i want to set drop down with roles i have 2 roles candidate and employer so i want to set a drop down select they roles i am using woocommerce registration and login i want to integrate dropdown with that roles for registration and login woocommerce.

function wp_dropdown_roles( $selected = '' ) {
    $p = '';
    $r = '';

    $editable_roles = array_reverse( get_editable_roles() );

    foreach ( $editable_roles as $role => $details ) {
        $name = translate_user_role($details['name'] );
        if ( $selected == $role ) // preselect specified role
            $p = "\n\t<option selected='selected' value='" . esc_attr($role) . "'>$name</option>";
        else
            $r .= "\n\t<option value='" . esc_attr($role) . "'>$name</option>";
    }
    echo $p . $r;
}
TechnoSpace

Try this :

function ts_wp_dropdown_roles( $selected = '' ) {
    $p = '';
    $r = '';

    $editable_roles = array_reverse( ts_get_editable_roles() );

    foreach ( $editable_roles as $role => $details ) {
        $name = translate_user_role($details['name'] );
        if ( $selected == $role ) // preselect specified role
            $p = "\n\t<option selected='selected' value='" . esc_attr($role) . "'>$name</option>";
        else
            $r .= "\n\t<option value='" . esc_attr($role) . "'>$name</option>";
    }
    echo $p . $r;
}

// Custom editable_roles function to be used by "ts_wp_dropdown_roles" function
function ts_get_editable_roles() {
    global $wp_roles;

    $all_roles = $wp_roles->roles;

    /**
     * Filter the list of editable roles.
     *
     * @since 2.8.0
     *
     * @param array $all_roles List of roles.
     */
    $editable_roles = apply_filters( 'ts_editable_roles', $all_roles );

    return $editable_roles;
}

add_filter("ts_editable_roles" , "ts_filter_roles", 10 ,1);

function ts_filter_roles($all_roles){
    foreach($all_roles as $key=>$value){
        if($key !== "employer" && $key !== "candidate"){
            unset($all_roles[$key]);
        }
    }
    return $all_roles;

}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to add claims during user registration

From Dev

How to assign roles on successful registration?

From Dev

How to Auto Login After Registration in WordPress with core php

From Dev

How to assign different user roles during registration?

From Dev

Add to wordpress registration page

From Dev

Django: How to login user directly after registration using generic CreateView

From Dev

how to Assign Multiple Roles for a user in wordpress?

From Dev

Woocommerce - How to add the new Google "no Captcha" reCaptcha into frontend registration form

From Dev

Wordpress - How to login user to frontend programmatically

From Dev

Creating different user roles on the basis of account registration parameters with Woocommerce

From Dev

How to add product sorting dropdown in WooCommerce?

From Dev

Wordpress | Woocommerce custom registration form

From Dev

How to add custom user roles for a GitHub organisation?

From Dev

How to create end user login page in WordPress?

From Dev

Wordpress - How to login user to frontend programmatically

From Dev

Creating different user roles on the basis of account registration parameters with Woocommerce

From Dev

How to add product sorting dropdown in WooCommerce?

From Dev

How to assign Multiple roles to a single user in wordpress

From Dev

Android User Login and Registration

From Dev

How to login user in both WordPress and custom website?

From Dev

How to Add Confirm Password Field In WooCommerce Registration Page?

From Dev

How to Login, Logout and User Registration through in build Authentication method?

From Dev

how to add class to the wordpress primary dropdown menu

From Dev

How to customise drupal 7 user registration, login, password reset form

From Dev

Custom Login Registration in wordpress

From Dev

Show roles dropdown list in registration form FOSUser

From Dev

How to add hook on submit registration in wordpress to drupal?

From Dev

How to restrict specific pages in WordPress website by login registration form?

From Dev

How to create a WordPress blog with user Registration?

Related Related

  1. 1

    How to add claims during user registration

  2. 2

    How to assign roles on successful registration?

  3. 3

    How to Auto Login After Registration in WordPress with core php

  4. 4

    How to assign different user roles during registration?

  5. 5

    Add to wordpress registration page

  6. 6

    Django: How to login user directly after registration using generic CreateView

  7. 7

    how to Assign Multiple Roles for a user in wordpress?

  8. 8

    Woocommerce - How to add the new Google "no Captcha" reCaptcha into frontend registration form

  9. 9

    Wordpress - How to login user to frontend programmatically

  10. 10

    Creating different user roles on the basis of account registration parameters with Woocommerce

  11. 11

    How to add product sorting dropdown in WooCommerce?

  12. 12

    Wordpress | Woocommerce custom registration form

  13. 13

    How to add custom user roles for a GitHub organisation?

  14. 14

    How to create end user login page in WordPress?

  15. 15

    Wordpress - How to login user to frontend programmatically

  16. 16

    Creating different user roles on the basis of account registration parameters with Woocommerce

  17. 17

    How to add product sorting dropdown in WooCommerce?

  18. 18

    How to assign Multiple roles to a single user in wordpress

  19. 19

    Android User Login and Registration

  20. 20

    How to login user in both WordPress and custom website?

  21. 21

    How to Add Confirm Password Field In WooCommerce Registration Page?

  22. 22

    How to Login, Logout and User Registration through in build Authentication method?

  23. 23

    how to add class to the wordpress primary dropdown menu

  24. 24

    How to customise drupal 7 user registration, login, password reset form

  25. 25

    Custom Login Registration in wordpress

  26. 26

    Show roles dropdown list in registration form FOSUser

  27. 27

    How to add hook on submit registration in wordpress to drupal?

  28. 28

    How to restrict specific pages in WordPress website by login registration form?

  29. 29

    How to create a WordPress blog with user Registration?

HotTag

Archive