1 | <?php |
||
8 | class GravityView_Field_Is_Approved extends GravityView_Field { |
||
9 | |||
10 | public $name = 'is_approved'; |
||
11 | |||
12 | public $search_operators = array( 'is', 'isnot' ); |
||
13 | |||
14 | public $contexts = array( 'single', 'multiple' ); |
||
15 | |||
16 | public $group = 'meta'; |
||
17 | |||
18 | public $is_sortable = true; |
||
19 | |||
20 | public $is_numeric = true; |
||
21 | |||
22 | public $is_searchable = true; |
||
23 | |||
24 | /** |
||
25 | * @var string Approval status is stored in entry meta under this key |
||
26 | * @since 1.18 |
||
27 | */ |
||
28 | var $entry_meta_key = 'is_approved'; |
||
29 | |||
30 | /** |
||
31 | * @var bool Don't add to the "columns to display" list; GravityView adds our own approval column |
||
32 | * @since 1.18 |
||
33 | */ |
||
34 | var $entry_meta_is_default_column = false; |
||
35 | |||
36 | public $_custom_merge_tag = 'approval_status'; |
||
37 | |||
38 | public function __construct() { |
||
48 | |||
49 | private function add_hooks() { |
||
54 | |||
55 | /** |
||
56 | * Convert entry approval status value to label in the field output. Uses labels from the field setting. |
||
57 | * |
||
58 | * @since 1.18 |
||
59 | * |
||
60 | * @param string $output HTML value output |
||
61 | * @param array $entry The GF entry array |
||
62 | * @param array $field_settings Settings for the particular GV field |
||
63 | * @param array $field Field array, as fetched from GravityView_View::getCurrentField() |
||
64 | * |
||
65 | * @return string The field setting label for the current status. Uses defaults, if not configured. |
||
66 | */ |
||
67 | 1 | public function filter_field_value( $output = '', $entry = array(), $field_settings = array(), $gv_field_output = array() ) { |
|
84 | |||
85 | /** |
||
86 | * |
||
87 | * |
||
88 | * @filter `gravityview_entry_default_fields` |
||
89 | * |
||
90 | * @param array $entry_default_fields Array of fields shown by default |
||
91 | * @param string|array $form form_ID or form object |
||
92 | * @param string $zone Either 'single', 'directory', 'header', 'footer' |
||
93 | * |
||
94 | * @return array |
||
95 | */ |
||
96 | function add_default_field( $entry_default_fields, $form, $zone ) { |
||
108 | |||
109 | /** |
||
110 | * Add custom merge tags to merge tag options |
||
111 | * |
||
112 | * @since 1.16 |
||
113 | * |
||
114 | * @param array $form GF Form array |
||
115 | * @param GF_Field[] $fields Array of fields in the form |
||
116 | * |
||
117 | * @return array Modified merge tags |
||
118 | */ |
||
119 | protected function custom_merge_tags( $form = array(), $fields = array() ) { |
||
130 | |||
131 | /** |
||
132 | * Display the approval status of an entry |
||
133 | * |
||
134 | * @see https://docs.gravityview.co/article/389-approvalstatus-merge-tag Read how to use the `{approval_status}` merge tag |
||
135 | * |
||
136 | * @since 1.18 |
||
137 | * |
||
138 | * @param array $matches Array of Merge Tag matches found in text by preg_match_all |
||
139 | * @param string $text Text to replace |
||
140 | * @param array $form Gravity Forms form array |
||
141 | * @param array $entry Entry array |
||
142 | * @param bool $url_encode Whether to URL-encode output |
||
143 | * @param bool $esc_html Whether to apply `esc_html()` to output |
||
144 | * |
||
145 | * @return string Text, with user variables replaced, if they existed |
||
146 | */ |
||
147 | public function replace_merge_tag( $matches = array(), $text = '', $form = array(), $entry = array(), $url_encode = false, $esc_html = false ) { |
||
171 | |||
172 | function field_options( $field_options, $template_id, $field_id, $context, $input_type ) { |
||
197 | |||
198 | } |
||
199 | |||
200 | new GravityView_Field_Is_Approved; |
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.