GravityView  1.19.4
The best, easiest way to display Gravity Forms entries on your website.
class-gravityview-field-password.php
Go to the documentation of this file.
1 <?php
2 /**
3  * @file class-gravityview-field-password.php
4  * @package GravityView
5  * @subpackage includes\fields
6  */
7 
9 
10  var $name = 'password';
11 
12  var $is_searchable = false;
13 
14  /** @see GF_Field_Password */
15  var $_gf_field_class_name = 'GF_Field_Password';
16 
17  var $group = 'advanced';
18 
19  public function __construct() {
20  $this->label = esc_html__( 'Password', 'gravityview' );
21 
22  $this->add_hooks();
23 
24  parent::__construct();
25  }
26 
27  /**
28  * Add filters to modify the front-end label and the Add Field label
29  *
30  * @since 1.17
31  *
32  * @return void
33  */
34  function add_hooks() {
35  add_filter( 'gravityview/common/get_form_fields', array( $this, 'add_form_fields' ), 10, 3 );
36 
37  add_filter( 'gravityview/template/field_label', array( $this, 'field_label' ), 10, 4 );
38  }
39 
40  /**
41  * Use the GV Admin Field label for the Password field instead of the per-input setting
42  *
43  * @since 1.17
44  *
45  * @param string $label Field label HTML
46  * @param array $field GravityView field array
47  * @param array $form Gravity Forms form array
48  * @param array $entry Gravity Forms entry array
49  *
50  * @return string If a custom field label isn't set, return the field label for the password field
51  */
52  function field_label( $label = '', $field = array(), $form = array(), $entry = array() ){
53 
54  // If using a custom label, no need to fetch the parent label
55  if( ! is_numeric( $field['id'] ) || ! empty( $field['custom_label'] ) ) {
56  return $label;
57  }
58 
59  $field_object = GFFormsModel::get_field( $form, $field['id'] );
60 
61  if( $field_object && 'password' === $field_object->type ) {
62  $label = $field['label'];
63  }
64 
65  return $label;
66  }
67 
68  /**
69  * If a form has list fields, add the columns to the field picker
70  *
71  * @since 1.17
72  *
73  * @param array $fields Associative array of fields, with keys as field type
74  * @param array $form GF Form array
75  * @param bool $include_parent_field Whether to include the parent field when getting a field with inputs
76  *
77  * @return array $fields with list field columns added, if exist. Unmodified if form has no list fields.
78  */
79  function add_form_fields( $fields = array(), $form = array(), $include_parent_field = true ) {
80 
81  foreach ( $fields as $key => $field ) {
82  if( 'password' === $field['type'] ) {
83 
84  // The Enter Password input
85  if( floor( $key ) === floatval( $key ) ) {
86 
87  if( ! empty( $field['parent'] ) ) {
88  $field['label'] = $field['parent']->label;
89  $field['adminOnly'] = $field['parent']->adminOnly;
90  $field['adminLabel'] = $field['parent']->adminLabel;
91  // Don't show as a child input
92  unset( $field['parent'] );
93  }
94 
95  $fields[ $key ] = $field;
96  } else {
97  // The Confirm Password input
98  unset( $fields[ $key ] );
99  }
100  }
101  }
102 
103  return $fields;
104  }
105 
106 }
107 
Modify field settings by extending this class.
add_form_fields($fields=array(), $form=array(), $include_parent_field=true)
If a form has list fields, add the columns to the field picker.
add_hooks()
Add filters to modify the front-end label and the Add Field label.
field_label($label= '', $field=array(), $form=array(), $entry=array())
Use the GV Admin Field label for the Password field instead of the per-input setting.
$entry
Definition: notes.php:27
$field
Definition: gquiz_grade.php:11