/deprecated/includes/fields/desc.php

  1. <?php if ( ! defined( 'ABSPATH' ) ) exit; 
  2. function ninja_forms_register_field_desc() { 
  3. $args = array( 
  4. 'name' => __( 'Text', 'ninja-forms' ),  
  5. 'sidebar' => 'layout_fields',  
  6. 'edit_function' => '',  
  7. 'edit_options' => array( 
  8. array( 
  9. 'type' => 'rte',  
  10. 'name' => 'default_value',  
  11. 'label' => __( 'Default Value', 'ninja-forms' ),  
  12. 'width' => 'wide',  
  13. 'class' => 'widefat',  
  14. ),  
  15. array( 
  16. 'type' => 'select',  
  17. 'name' => 'desc_el',  
  18. 'label' => __( 'Text Element', 'ninja-forms' ),  
  19. 'width' => 'thin',  
  20. 'class' => '',  
  21. 'options' => array( 
  22. array('name' => 'div', 'value' => 'div'),  
  23. array('name' => 'h1', 'value' => 'h1'),  
  24. array('name' => 'h2', 'value' => 'h2'),  
  25. array('name' => 'h3', 'value' => 'h3'),  
  26. array('name' => 'h4', 'value' => 'h4'),  
  27. array('name' => 'h5', 'value' => 'h5'),  
  28. array('name' => 'h6', 'value' => 'h6'),  
  29. array('name' => 'p', 'value' => 'p'),  
  30. array('name' => 'span', 'value' => 'span'),  
  31. ),  
  32. ),  
  33. ),  
  34. 'display_function' => 'ninja_forms_field_desc_display',  
  35. 'group' => 'layout_elements',  
  36. 'display_label' => false,  
  37. 'display_wrap' => false,  
  38. 'edit_label' => true,  
  39. 'edit_label_pos' => false,  
  40. 'edit_req' => false,  
  41. 'edit_custom_class' => true,  
  42. 'edit_help' => false,  
  43. 'edit_meta' => false,  
  44. 'edit_conditional' => true,  
  45. 'process_field' => false,  
  46. 'pre_process' => 'ninja_forms_field_desc_pre_process',  
  47. 'esc_html' => false,  
  48. ); 
  49.  
  50. ninja_forms_register_field('_desc', $args); 
  51.  
  52. add_action('init', 'ninja_forms_register_field_desc'); 
  53.  
  54. function ninja_forms_field_desc_display( $field_id, $data, $form_id = '' ) { 
  55.  
  56. if(isset($data['desc_el'])) { 
  57. $desc_el = $data['desc_el']; 
  58. }else{ 
  59. $desc_el = "p"; 
  60.  
  61. if(isset($data['default_value'])) { 
  62. $default_value = $data['default_value']; 
  63. }else{ 
  64. $default_value = ''; 
  65.  
  66. $default_value = html_entity_decode( $default_value, ENT_COMPAT, "UTF-8" ); 
  67.  
  68. if($desc_el == "div") { 
  69. $default_value = wpautop( $default_value );  
  70. }else{  
  71. $default_value = nl2br( $default_value ); 
  72.  
  73. if( isset( $data['display_style'] ) ) { 
  74. $display_style = $data['display_style']; 
  75. }else{ 
  76. $display_style = ''; 
  77. $default_value = do_shortcode( $default_value ); 
  78. $field_class = ninja_forms_get_field_class( $field_id, $form_id ); 
  79. $field_class .= ' nf-desc'; 
  80. ?> 
  81. <<?php echo $desc_el;?> class="<?php echo $field_class;?>" id="ninja_forms_field_<?php echo $field_id;?>_div_wrap" style="<?php echo $display_style;?>" rel="<?php echo $field_id;?>"><?php echo $default_value;?></<?php echo $desc_el;?>> 
  82. <?php 
  83.  
  84. /** 
  85. * 
  86. * Function that adds the $data['default_value'] to the $ninja_forms_processing. 
  87. * 
  88. * @since 2.2.30 
  89. * @returns void 
  90. */ 
  91.  
  92. function ninja_forms_field_desc_pre_process( $field_id, $user_value ) { 
  93. global $ninja_forms_processing; 
  94. $field = ninja_forms_get_field_by_id( $field_id ); 
  95. $default_value = isset( $field['data']['default_value'] ) ? $field['data']['default_value'] : ''; 
  96. $ninja_forms_processing->update_field_value( $field_id, $default_value ); 
.