|
1
|
|
|
<?php |
|
|
|
|
|
|
2
|
|
|
/** |
|
3
|
|
|
* @file class-gravityview-field-password.php |
|
4
|
|
|
* @package GravityView |
|
5
|
|
|
* @subpackage includes\fields |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
class GravityView_Field_Password extends GravityView_Field { |
|
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
|
|
|
$field['label'] = $field['parent']->label; |
|
87
|
|
|
$field['adminOnly'] = $field['parent']->adminOnly; |
|
88
|
|
|
$field['adminLabel'] = $field['parent']->adminLabel; |
|
89
|
|
|
|
|
90
|
|
|
// Don't show as a child input |
|
91
|
|
|
unset( $field['parent'] ); |
|
92
|
|
|
|
|
93
|
|
|
$fields[ $key ] = $field; |
|
94
|
|
|
} else { |
|
95
|
|
|
// The Confirm Password input |
|
96
|
|
|
unset( $fields[ $key ] ); |
|
97
|
|
|
} |
|
98
|
|
|
} |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
return $fields; |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
new GravityView_Field_Password; |
|
107
|
|
|
|
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.