wooccmpassword_handler

The WooCommerce Checkout Manager wooccmpassword handler function.

Description

wooccmpassword_handler( $field, $key, $args, $value ); 

Parameters (4)

0. $field
The field.
1. $key
The key.
2. $args
The args.
3. $value
The value.

Usage

  1. if ( !function_exists( 'wooccmpassword_handler' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'woocommerce-checkout-manager/includes/classes/field_filters.php'; 
  3.  
  4. // The field. 
  5. $field = null; 
  6.  
  7. // The key. 
  8. $key = null; 
  9.  
  10. // The args. 
  11. $args = null; 
  12.  
  13. // The value. 
  14. $value = null; 
  15.  
  16. // NOTICE! Understand what this does before running. 
  17. $result = wooccmpassword_handler($field, $key, $args, $value); 
  18.  

Defined (1)

The function is defined in the following location(s).

/includes/classes/field_filters.php  
  1. function wooccmpassword_handler( $field = '', $key, $args, $value ) {  
  2. global $current_user; 
  3. $user_roles = $current_user->roles; 
  4. $user_role = array_shift($user_roles); 
  5.  
  6. if( !empty($args['user_role']) && (!empty($args['role_options']) || !empty($args['role_options2'])) ) { 
  7. $rolekeys = explode('||', $args['role_options']); 
  8. $rolekeys2 = explode('||', $args['role_options2']); 
  9. if (!empty($args['role_options']) && !in_array($user_role, $rolekeys)) { 
  10. return; 
  11. if (!empty($args['role_options2']) && in_array($user_role, $rolekeys2)) { 
  12. return; 
  13.  
  14. if ( ( ! empty( $args['clear'] ) ) ) { 
  15. $after = '<div class="clear"></div>'; 
  16. } else { 
  17. $after = ''; 
  18.  
  19. if ( $args['wooccm_required'] ) { 
  20. $args['class'][] = 'validate-required'; 
  21. $required = ' <abbr class="required" title="' . esc_attr__( 'required', 'woocommerce' ) . '">*</abbr>'; 
  22. } else { 
  23. $required = ''; 
  24.  
  25. $args['maxlength'] = ( $args['maxlength'] ) ? 'maxlength="' . absint( $args['maxlength'] ) . '"' : ''; 
  26.  
  27. if ( is_string( $args['label_class'] ) ) { 
  28. $args['label_class'] = array( $args['label_class'] ); 
  29.  
  30. if ( is_null( $value ) ) { 
  31. $value = $args['default']; 
  32.  
  33. // Custom attribute handling 
  34. $custom_attributes = array(); 
  35.  
  36. if ( ! empty( $args['custom_attributes'] ) && is_array( $args['custom_attributes'] ) ) { 
  37. foreach ( $args['custom_attributes'] as $attribute => $attribute_value ) { 
  38. $custom_attributes[] = esc_attr( $attribute ) . '="' . esc_attr( $attribute_value ) . '"'; 
  39.  
  40. if ( ! empty( $args['validate'] ) ) { 
  41. foreach( $args['validate'] as $validate ) { 
  42. $args['class'][] = 'validate-' . $validate; 
  43.  
  44. $field = '<p class="form-row ' . esc_attr( implode( ' ', $args['class'] ) ) .'" id="' . esc_attr( $args['id'] ) . '_field">'; 
  45.  
  46. if ( $args['label'] ) { 
  47. $field .= '<label for="' . esc_attr( $args['id'] ) . '" class="' . esc_attr( implode( ' ', $args['label_class'] ) ) .'">' . $args['label']. $required . '</label>'; 
  48.  
  49. $field .= '<input type="password" class="input-text ' . esc_attr( implode( ' ', $args['input_class'] ) ) .'" name="' . esc_attr( $key ) . '" id="' . esc_attr( $args['id'] ) . '" placeholder="' . esc_attr( $args['placeholder'] ) . '" value="' . esc_attr( $value ) . '" ' . implode( ' ', $custom_attributes ) . ' />'; 
  50.  
  51. if ( $args['description'] ) { 
  52. $field .= '<span class="description">' . esc_attr( $args['description'] ) . '</span>'; 
  53.  
  54. $field .= '</p>' . $after; 
  55.  
  56. return $field;