2015-06-08 65 views
0

我有一個工作網站,但我想設置下拉角色我有2個角色的候選人和僱主,所以我想設置下拉選擇他們的角色我使用woocommerce註冊和登錄我想要整合下拉與該角色的註冊和登錄woocommerce。如何添加用戶角色下拉註冊和登錄woocommerce wordpress

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; 
} 

回答

0

試試這個:

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; 

} 
+0

不工作,你可以檢查 – madu