Bxcft_Field_Type_Image

The BuddyPress Xprofile Custom Fields Type Bxcft Field Type Image class.

Defined (1)

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

/classes/Bxcft_Field_Type_Image.php  
  1. class Bxcft_Field_Type_Image extends BP_XProfile_Field_Type 
  2. public function __construct() { 
  3. parent::__construct(); 
  4.  
  5. $this->name = _x( 'Image', 'xprofile field type', 'bxcft' ); 
  6.  
  7. $this->set_format( '/^.+$/', 'replace' ); 
  8. do_action( 'bp_xprofile_field_type_image', $this ); 
  9.  
  10. public function admin_field_html (array $raw_properties = array ()) 
  11. $html = $this->get_edit_field_html_elements( array_merge( 
  12. array( 'type' => 'file' ),  
  13. $raw_properties 
  14. ) ); 
  15. ?> 
  16. <input <?php echo $html; ?>> 
  17. <?php 
  18.  
  19. public function edit_field_html (array $raw_properties = array ()) 
  20. if ( isset( $raw_properties['user_id'] ) ) { 
  21. unset( $raw_properties['user_id'] ); 
  22. $html = $this->get_edit_field_html_elements( array_merge( 
  23. array( 
  24. 'type' => 'file',  
  25. ),  
  26. $raw_properties 
  27. ) ); 
  28.  
  29. $uploads = wp_upload_dir(); 
  30.  
  31. // Label. 
  32. $label = sprintf('<label for="%s">%s%s</label>',  
  33. bp_get_the_profile_field_input_name(),  
  34. bp_get_the_profile_field_name(),  
  35. (bp_get_the_profile_field_is_required()) ? 
  36. esc_html( '(required)', 'buddypress') : ''); 
  37. // Input file. 
  38. $input = sprintf('<input type="hidden" name="%1$s" id="%1$s" value="%2$s" /><input %3$s />',  
  39. bp_get_the_profile_field_input_name(),  
  40. (bp_get_the_profile_field_edit_value() != '' && bp_get_the_profile_field_edit_value() != '-') ? 
  41. bp_get_the_profile_field_edit_value() : '-',  
  42. $html); 
  43. // Actual image. 
  44. if (bp_get_the_profile_field_edit_value() != '' && bp_get_the_profile_field_edit_value() != '-') { 
  45. $actual_image = sprintf('<img src="%1$s" alt="%2$s" /><label for="%2$s_deleteimg"><input type="checkbox" name="%2$s_deleteimg" id="%2$s_deleteimg" value="1" /> %3$s</label><input type="hidden" name="%2$s_hiddenimg" id="%2$s_hiddenimg" value="%4$s" />',  
  46. $uploads['baseurl'].bp_get_the_profile_field_edit_value(),  
  47. bp_get_the_profile_field_input_name(),  
  48. __('Check this to delete this image', 'bxcft'),  
  49. bp_get_the_profile_field_edit_value()); 
  50. } elseif (bp_get_profile_field_data(array('field' => bp_get_the_profile_field_id())) != '' && 
  51. bp_get_profile_field_data(array('field' => bp_get_the_profile_field_id())) != '-') { 
  52. $actual_image = sprintf('%1$s<label for="%2$s_deleteimg"><input type="checkbox" name="%2$s_deleteimg" id="%2$s_deleteimg" value="1" /> %3$s</label><input type="hidden" name="%2$s_hiddenimg" id="%2$s_hiddenimg" value="%4$s" />',  
  53. strip_tags(bp_get_profile_field_data(array('field' => bp_get_the_profile_field_id()))),  
  54. bp_get_the_profile_field_input_name(),  
  55. __('Check this to delete this image', 'bxcft'),  
  56. (isset($_POST['field_'.bp_get_the_profile_field_id().'_hiddenimg']))?$_POST['field_'.bp_get_the_profile_field_id().'_hiddenimg']:''); 
  57. } else { 
  58. $actual_image = ''; 
  59.  
  60. echo apply_filters( 'bxcft_field_label', $label, bp_get_the_profile_field_id(), bp_get_the_profile_field_type(), bp_get_the_profile_field_input_name(), bp_get_the_profile_field_name(), bp_get_the_profile_field_is_required() ); 
  61. do_action( bp_get_the_profile_field_errors_action() ); 
  62. echo apply_filters( 'bxcft_field_input', $input, bp_get_the_profile_field_id(), bp_get_the_profile_field_type(), bp_get_the_profile_field_input_name(), bp_get_the_profile_field_is_required() ); 
  63. echo apply_filters('bxcft_field_actual_image', $actual_image, bp_get_the_profile_field_id(), bp_get_the_profile_field_type(), bp_get_the_profile_field_input_name(), bp_get_the_profile_field_edit_value()); 
  64. ?> 
  65. <script type="text/javascript"> 
  66. if (jQuery('#profile-edit-form').length > 0) { 
  67. jQuery('#profile-edit-form').attr('enctype', 'multipart/form-data'); 
  68. if (jQuery('#your-profile').length > 0) { 
  69. jQuery('#your-profile').attr('enctype', 'multipart/form-data'); 
  70. <?php if (bp_get_the_profile_field_edit_value() != '' && bp_get_the_profile_field_edit_value() != '-'): ?> 
  71. jQuery('#field_<?php echo bp_get_the_profile_field_id(); ?>_deleteimg').change(function() { 
  72. if (jQuery(this).is(':checked') && jQuery('input#field_<?php echo bp_get_the_profile_field_id(); ?>[type=file]').val() === '') { 
  73. jQuery('input#field_<?php echo bp_get_the_profile_field_id(); ?>[type=hidden]').val(''); 
  74. } else { 
  75. jQuery('input#field_<?php echo bp_get_the_profile_field_id(); ?>[type=hidden]').val('<?php echo bp_get_the_profile_field_edit_value(); ?>'); 
  76. }); 
  77. <?php endif; ?> 
  78. jQuery('input#field_<?php echo bp_get_the_profile_field_id(); ?>[type=file]').change(function() { 
  79. if (jQuery(this).val() !== '') { 
  80. jQuery('input#field_<?php echo bp_get_the_profile_field_id(); ?>[type=hidden]').val('-'); 
  81. } else { 
  82. jQuery('input#field_<?php echo bp_get_the_profile_field_id(); ?>[type=hidden]').val(''); 
  83. }); 
  84. </script> 
  85. <?php 
  86.  
  87. public function admin_new_field_html( BP_XProfile_Field $current_field, $control_type = '' ) {} 
  88.  
  89. /** 
  90. * Modify the appearance of value. No autolink feature for Image type. 
  91. * @param string $value Original value of field 
  92. * @param int $field_id Id of field 
  93. * @return string Value formatted 
  94. */ 
  95. public static function display_filter($field_value, $field_id = '') { 
  96.  
  97. $new_field_value = $field_value; 
  98.  
  99. if (!empty($field_value)) { 
  100. $uploads = wp_upload_dir(); 
  101. if (strpos($field_value, $uploads['baseurl']) === false) { 
  102. $new_field_value = $uploads['baseurl'] . $field_value; 
  103. $new_field_value = sprintf('<img src="%s" alt="" />', $new_field_value); 
  104.  
  105. /** 
  106. * bxcft_image_display_filter 
  107. * Use this filter to modify the appearance of Image 
  108. * field value. 
  109. * @param $new_field_value Value of field 
  110. * @param $field_id Id of field. 
  111. * @return Filtered value of field. 
  112. */ 
  113. return apply_filters('bxcft_image_display_filter',  
  114. $new_field_value, $field_id);