password.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. <?php if ( ! defined( 'ABSPATH' ) ) exit;
  2. function ninja_forms_register_field_profile_pass(){
  3. $args = array(
  4. 'name' => __( 'Password', 'ninja-forms' ),
  5. 'display_function' => 'ninja_forms_field_profile_pass_display',
  6. 'group' => 'standard_fields',
  7. 'edit_label' => true,
  8. 'edit_label_pos' => false,
  9. 'default_label_pos' => 'left',
  10. 'edit_req' => true,
  11. 'edit_custom_class' => true,
  12. 'edit_help' => true,
  13. 'edit_meta' => false,
  14. 'sidebar' => 'template_fields',
  15. 'edit_conditional' => true,
  16. 'conditional' => array(
  17. 'value' => array(
  18. 'type' => 'text',
  19. ),
  20. ),
  21. //'limit' => 1,
  22. 'save_sub' => false,
  23. 'pre_process' => 'ninja_forms_field_profile_pass_pre_process',
  24. 'edit_options' => array(
  25. array(
  26. 'name' => 'reg_password',
  27. 'type' => 'checkbox',
  28. 'label' => __( 'Use this as a registration password field', 'ninja-forms' ),
  29. 'default' => 1,
  30. 'desc' => '<br>'.__( 'If this box is checked, both password and re-password textboxes will be output.', 'ninja-forms' ),
  31. 'width' => 'wide',
  32. ),
  33. array(
  34. 'name' => 're_pass',
  35. 'type' => 'text',
  36. 'label' => __( 'Re-enter Password Label', 'ninja-forms' ),
  37. 'class' => 'widefat reg-password',
  38. 'default' => __( 'Re-enter Password', 'ninja-forms' ),
  39. 'width' => 'wide',
  40. ),
  41. array(
  42. 'name' => 'adv_pass',
  43. 'type' => 'checkbox',
  44. 'label' => __( 'Show Password Strength Indicator', 'ninja-forms' ),
  45. 'default' => 1,
  46. 'class' => 'reg-password',
  47. ),
  48. ),
  49. );
  50. if( function_exists( 'ninja_forms_register_field' ) ){
  51. ninja_forms_register_field('_profile_pass', $args);
  52. }
  53. }
  54. add_action( 'init', 'ninja_forms_register_field_profile_pass' );
  55. function ninja_forms_field_profile_pass_display( $field_id, $data, $form_id = '' ){
  56. global $current_user;
  57. $field_class = ninja_forms_get_field_class( $field_id, $form_id );
  58. if( isset( $data['default_value'] ) ){
  59. $default_value = $data['default_value'];
  60. }else{
  61. $default_value = '';
  62. }
  63. if( isset( $data['adv_pass'] ) ){
  64. $adv_pass = $data['adv_pass'];
  65. }else{
  66. $adv_pass = 0;
  67. }
  68. $default_value_re = '';
  69. if( isset( $data['label_pos'] ) ){
  70. $label_pos = $data['label_pos'];
  71. }else{
  72. $label_pos = "left";
  73. }
  74. if( isset( $data['label'] ) ){
  75. $label = $data['label'];
  76. }else{
  77. $label = '';
  78. }
  79. if( isset( $data['re_pass'] ) ){
  80. $re_pass = $data['re_pass'];
  81. }else{
  82. $re_pass = '';
  83. }
  84. if( $label_pos == 'inside' ){
  85. $default_value = $label;
  86. $default_value_re = $re_pass;
  87. }
  88. if( isset( $data['reg_password'] ) ){
  89. $reg_password = $data['reg_password'];
  90. }else{
  91. $reg_password = 1;
  92. }
  93. if( $reg_password == 1 ){
  94. ?>
  95. <input id="pass1_<?php echo $field_id;?>" title="" name="ninja_forms_field_<?php echo $field_id;?>" type="password" class="<?php echo $field_class;?> pass1" value="<?php echo $default_value;?>" rel="<?php echo $field_id;?>" />
  96. </div>
  97. <div class="ninja-forms-pass2">
  98. <?php
  99. if( $label_pos == 'left' OR $label_pos == 'above' ){
  100. ?>
  101. <label><?php echo $re_pass;?></label>
  102. <?php
  103. }
  104. ?>
  105. <input id="pass2_<?php echo $field_id;?>" title="" name="_pass_<?php echo $field_id;?>" type="password" class="<?php echo $field_class;?> pass2" value="<?php echo $default_value_re;?>" />
  106. <?php
  107. if( $label_pos == 'right' OR $label_pos == 'below' ){
  108. ?>
  109. <label><?php echo $re_pass;?></label>
  110. <?php
  111. }
  112. echo '</div>';
  113. if( $adv_pass == 1 ){
  114. $class = apply_filters( 'ninja_forms_display_field_desc_class', 'description indicator-hint', $field_id );
  115. ?>
  116. <div id="pass-strength-result"><?php _e( 'Strength indicator', 'ninja-forms' ); ?></div>
  117. <p class="<?php echo $class; ?>"><?php _e( 'Hint: The password should be at least seven characters long. To make it stronger, use upper and lower case letters, numbers and symbols like ! " ? $ % ^ &amp; ).', 'ninja-forms' ); ?></p>
  118. <?php
  119. }
  120. }else{
  121. ?>
  122. <input id="ninja_forms_field_<?php echo $field_id;?>" title="" name="ninja_forms_field_<?php echo $field_id;?>" type="password" class="<?php echo $field_class;?>" value="<?php echo $default_value;?>" rel="<?php echo $field_id;?>" /></div>
  123. <?php
  124. }
  125. }
  126. function ninja_forms_field_profile_pass_pre_process( $field_id, $user_value ){
  127. global $ninja_forms_processing;
  128. $field_row = $ninja_forms_processing->get_field_settings( $field_id );
  129. $field_data = $field_row['data'];
  130. if( isset( $field_data['reg_password'] ) AND $field_data['reg_password'] == 1 ){
  131. if( $user_value != $ninja_forms_processing->get_extra_value( '_pass_'.$field_id ) ){
  132. $ninja_forms_processing->add_error( 'mismatch-'.$field_id, __( 'Passwords do not match', 'ninja-forms' ), $field_id );
  133. }else{
  134. $ninja_forms_processing->update_extra_value( '_password', $user_value );
  135. }
  136. }
  137. }
  138. function ninja_forms_field_profile_add_open_wrapper( $field_id, $data ) {
  139. $field_row = ninja_forms_get_field_by_id( $field_id );
  140. if ( '_profile_pass' == $field_row['type'] ) {
  141. echo '<div class="ninja-forms-pass1">';
  142. }
  143. }
  144. add_action( 'ninja_forms_display_after_opening_field_wrap', 'ninja_forms_field_profile_add_open_wrapper', 10, 2 );
  145. function ninja_forms_field_profile_add_close_wrapper( $field_id, $data ) {
  146. $field_row = ninja_forms_get_field_by_id( $field_id );
  147. if ( '_profile_pass' == $field_row['type'] ) {
  148. //echo '</div>';
  149. }
  150. }
  151. add_action( 'ninja_forms_display_before_closing_field_wrap', 'ninja_forms_field_profile_add_close_wrapper', 10, 2 );