1
|
|
|
<?php |
|
|
|
|
2
|
|
|
/** |
3
|
|
|
* @file class-gravityview-field-hidden.php |
4
|
|
|
* @package GravityView |
5
|
|
|
* @subpackage includes\fields |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
class GravityView_Field_Hidden extends GravityView_Field { |
9
|
|
|
|
10
|
|
|
var $name = 'hidden'; |
|
|
|
|
11
|
|
|
|
12
|
|
|
var $is_searchable = true; |
|
|
|
|
13
|
|
|
|
14
|
|
|
var $search_operators = array( 'contains', 'is', 'isnot', 'starts_with', 'ends_with' ); |
|
|
|
|
15
|
|
|
|
16
|
|
|
var $_gf_field_class_name = 'GF_Field_Hidden'; |
|
|
|
|
17
|
|
|
|
18
|
|
|
var $group = 'standard'; |
|
|
|
|
19
|
|
|
|
20
|
|
|
public function __construct() { |
21
|
|
|
$this->label = esc_html__( 'Hidden', 'gravityview' ); |
22
|
|
|
|
23
|
|
|
$this->edit_entry_add_hooks(); |
24
|
|
|
|
25
|
|
|
parent::__construct(); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Add Edit Entry hooks |
30
|
|
|
* |
31
|
|
|
* @since 1.17 |
32
|
|
|
* |
33
|
|
|
* @return void |
34
|
|
|
*/ |
35
|
|
|
private function edit_entry_add_hooks() { |
36
|
|
|
add_filter( 'gravityview/edit_entry/form_fields', array( $this, 'edit_entry_fix_hidden_fields' ) ); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Convert Hidden fields to be Text fields in Edit Entry |
41
|
|
|
* |
42
|
|
|
* @since 1.9.2 |
43
|
|
|
* @since 1.17 Moved to GravityView_Field_Hidden class |
44
|
|
|
* |
45
|
|
|
* @param GF_Field[] $fields Array of fields to be shown on the Edit Entry screen |
46
|
|
|
* |
47
|
|
|
* @return GF_Field[] Array of fields, with any hidden fields replaced with text fields |
48
|
|
|
*/ |
49
|
|
|
function edit_entry_fix_hidden_fields( $fields ) { |
|
|
|
|
50
|
|
|
|
51
|
|
|
/** @var GF_Field $field */ |
52
|
|
|
foreach( $fields as &$field ) { |
53
|
|
|
if ( 'hidden' === $field->type ) { |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @filter `gravityview/edit_entry/reveal_hidden_field` Convert Hidden fields into Text fields on Edit Entry |
57
|
|
|
* @since 1.22.6 |
58
|
|
|
* @param bool $reveal_hidden_field True: Convert the hidden field to text; False: Leave hidden |
59
|
|
|
* @param GF_Field_Hidden $field The field in question |
60
|
|
|
*/ |
61
|
|
|
$reveal_hidden_field = apply_filters( 'gravityview/edit_entry/reveal_hidden_field', true, $field ); |
62
|
|
|
|
63
|
|
|
if( ! $reveal_hidden_field ) { |
64
|
|
|
continue; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
// Replace GF_Field_Hidden with GF_Field_Text, copying all the data from $field |
68
|
|
|
$field = new GF_Field_Text( $field ); |
69
|
|
|
|
70
|
|
|
// Everything is copied from $field, so we need to manually set the type |
71
|
|
|
$field->type = 'text'; |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
return $fields; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
new GravityView_Field_Hidden; |
81
|
|
|
|
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.