wooccmupload_handler

The WooCommerce Checkout Manager wooccmupload handler function.

Description

wooccmupload_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( 'wooccmupload_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 = wooccmupload_handler($field, $key, $args, $value); 
  18.  

Defined (1)

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

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