1
|
|
|
<?php |
|
|
|
|
2
|
|
|
namespace GV; |
3
|
|
|
|
4
|
|
|
/** If this file is called directly, abort. */ |
5
|
|
|
if ( ! defined( 'GRAVITYVIEW_DIR' ) ) { |
6
|
|
|
die(); |
7
|
|
|
} |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Load up the Gamajo Template Loader. |
11
|
|
|
* |
12
|
|
|
* @see https://github.com/GaryJones/Gamajo-Template-Loader |
13
|
|
|
*/ |
14
|
|
|
if ( ! class_exists( 'Gamajo_Template_Loader' ) ) { |
15
|
|
|
require gravityview()->plugin->dir( 'future/lib/class-gamajo-template-loader.php' ); |
16
|
|
|
} |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* The Field Template class. |
20
|
|
|
* |
21
|
|
|
* Attached to a \GV\Field and used by a \GV\Field_Renderer. |
22
|
|
|
*/ |
23
|
|
|
abstract class Field_Template extends Template { |
24
|
|
|
/** |
25
|
|
|
* Prefix for filter names. |
26
|
|
|
* @var string |
27
|
|
|
*/ |
28
|
|
|
protected $filter_prefix = 'gravityview/template/fields'; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Directory name where custom templates for this plugin should be found in the theme. |
32
|
|
|
* @var string |
33
|
|
|
*/ |
34
|
|
|
protected $theme_template_directory = 'gravityview/fields/'; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Directory name where the default templates for this plugin are found. |
38
|
|
|
* @var string |
39
|
|
|
*/ |
40
|
|
|
protected $plugin_template_directory = 'templates/fields/'; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @var \GV\Field The field connected to this template. |
44
|
|
|
*/ |
45
|
|
|
public $field; |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @var \GV\View The view context. |
49
|
|
|
*/ |
50
|
|
|
public $view; |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @var \GV\Source The source context. |
54
|
|
|
*/ |
55
|
|
|
public $source; |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @var \GV\Entry The entry context. |
59
|
|
|
*/ |
60
|
|
|
public $entry; |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @var \GV\Request The request context. |
64
|
|
|
*/ |
65
|
|
|
public $request; |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @var string The template slug to be loaded (like "table", "list") |
69
|
|
|
*/ |
70
|
|
|
public static $slug; |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* Initializer. |
74
|
|
|
* |
75
|
|
|
* @param \GV\Field $field The field about to be rendered. |
76
|
|
|
* @param \GV\View $view The view in this context, if applicable. |
77
|
|
|
* @param \GV\Source $source The source (form) in this context, if applicable. |
78
|
|
|
* @param \GV\Entry $entry The entry in this context, if applicable. |
79
|
|
|
* @param \GV\Request $request The request in this context, if applicable. |
80
|
|
|
*/ |
81
|
49 |
|
public function __construct( Field $field, View $view = null, Source $source = null, Entry $entry = null, Request $request = null ) { |
82
|
49 |
|
$this->field = $field; |
83
|
49 |
|
$this->view = $view; |
84
|
49 |
|
$this->source = $source; |
85
|
49 |
|
$this->entry = $entry; |
86
|
49 |
|
$this->request = $request; |
87
|
|
|
|
88
|
|
|
/** Add granular overrides. */ |
89
|
49 |
|
add_filter( $this->filter_prefix . '_get_template_part', $this->_add_id_specific_templates_callback = self::add_id_specific_templates( $this ), 10, 3 ); |
|
|
|
|
90
|
|
|
|
91
|
49 |
|
parent::__construct(); |
92
|
49 |
|
} |
93
|
|
|
|
94
|
49 |
|
public function __destruct() { |
95
|
49 |
|
remove_filter( $this->filter_prefix . '_get_template_part', $this->_add_id_specific_templates_callback );; |
96
|
49 |
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* Enable granular template overrides based on current post, view, form, field types, etc. |
100
|
|
|
* |
101
|
|
|
* Why? See https://github.com/gravityview/GravityView/issues/1024 |
102
|
|
|
* |
103
|
|
|
* @param \GV\Field_Template $template The template instance. |
104
|
|
|
* @return callable The callback bound to `get_template_part`. See `\GV\Field_Template::__construct` |
105
|
|
|
*/ |
106
|
49 |
|
public static function add_id_specific_templates( $template ) { |
107
|
|
|
|
108
|
49 |
|
$inputType = null; |
109
|
49 |
|
$field_type = null; |
110
|
49 |
|
$field_id = null; |
111
|
49 |
|
$view_id = null; |
112
|
49 |
|
$form_id = null; |
113
|
49 |
|
$is_view = $template->request && $template->request->is_view(); |
114
|
|
|
|
115
|
49 |
|
if ( $template->field ) { |
116
|
49 |
|
$inputType = $template->field->inputType; |
|
|
|
|
117
|
49 |
|
$field_type = $template->field->type; |
|
|
|
|
118
|
49 |
|
$field_id = $template->field->ID; |
119
|
|
|
} |
120
|
|
|
|
121
|
49 |
|
if ( $template->view ) { |
122
|
49 |
|
$view_id = $template->view->ID; |
|
|
|
|
123
|
49 |
|
$form_id = $template->view->form ? $template->view->form->ID : null; |
124
|
|
|
} |
125
|
|
|
|
126
|
49 |
|
$class = get_class( $template ); |
127
|
|
|
|
128
|
|
|
/** |
129
|
|
|
* Enable granular template overrides based on current post, view, form, field types, etc. |
130
|
|
|
* |
131
|
|
|
* The hierarchy is as follows: |
132
|
|
|
* |
133
|
|
|
* - post-[ID of post of page where view is embedded]-view-[View ID]-field-[Field type]-html.php |
134
|
|
|
* - post-[ID of post of page where view is embedded]-view-[View ID]-field-[Field inputType]-html.php |
135
|
|
|
* - post-[ID of post of page where view is embedded]-view-[View ID]-field-html.php |
136
|
|
|
* - post-[ID of post of page where view is embedded]-field-[Field type]-html.php |
137
|
|
|
* - post-[ID of post of page where view is embedded]-field-[Field inputType]-html.php |
138
|
|
|
* - post-[ID of post of page where view is embedded]-field-html.php |
139
|
|
|
* - post-[ID of post of page where view is embedded]-view-[View ID]-field-[Field type].php |
140
|
|
|
* - post-[ID of post of page where view is embedded]-view-[View ID]-field-[Field inputType].php |
141
|
|
|
* - post-[ID of post of page where view is embedded]-view-[View ID]-field.php |
142
|
|
|
* - post-[ID of post of page where view is embedded]-field-[Field type].php |
143
|
|
|
* - post-[ID of post of page where view is embedded]-field-[Field inputType].php |
144
|
|
|
* - post-[ID of post of page where view is embedded]-field.php |
145
|
|
|
* - form-[Form ID]-field-[Field ID]-html.php |
146
|
|
|
* - form-[Form ID]-field-[Field ID].php |
147
|
|
|
* - form-[Form ID]-field-[Field type]-html.php |
148
|
|
|
* - form-[Form ID]-field-[Field inputType]-html.php |
149
|
|
|
* - form-[Form ID]-field-[Field type].php |
150
|
|
|
* - form-[Form ID]-field-[Field inputType].php |
151
|
|
|
* - view-[View ID]-field-[Field type]-html.php |
152
|
|
|
* - view-[View ID]-field-[Field inputType]-html.php |
153
|
|
|
* - view-[View ID]-field-[Field type].php |
154
|
|
|
* - view-[View ID]-field-[Field inputType].php |
155
|
|
|
* - field-[Field type]-html.php |
156
|
|
|
* - field-[Field inputType]-html.php |
157
|
|
|
* - field-[Field type].php |
158
|
|
|
* - field-[Field inputType].php |
159
|
|
|
* - field-html.php |
160
|
|
|
* - field.php |
161
|
|
|
* |
162
|
|
|
* @see Gamajo_Template_Loader::get_template_file_names() Where the filter is |
163
|
|
|
* @param array $templates Existing list of templates. |
164
|
|
|
* @param string $slug Name of the template base, example: `html`, `json`, `xml` |
165
|
|
|
* @param string $name Name of the template part. |
166
|
|
|
* |
167
|
|
|
* @return array $templates Modified template array, merged with existing $templates values |
168
|
|
|
*/ |
169
|
49 |
|
return function( $templates, $slug, $name ) use ( $class, $inputType, $field_type, $view_id, $is_view, $form_id, $field_id ) { |
170
|
49 |
|
$specifics = array(); |
171
|
|
|
|
172
|
49 |
|
list( $slug_dir, $slug_name ) = $class::split_slug( $slug, $name ); |
173
|
|
|
|
174
|
49 |
|
global $post; |
|
|
|
|
175
|
|
|
|
176
|
49 |
|
if ( $is_view && $post ) { |
177
|
5 |
|
if ( $field_type ) { |
178
|
5 |
|
$specifics []= sprintf( '%spost-%d-view-%d-field-%s-%s.php', $slug_dir, $post->ID, $view_id, $field_type, $slug_name ); |
|
|
|
|
179
|
5 |
|
$inputType && $specifics []= sprintf( '%spost-%d-view-%d-field-%s-%s.php', $slug_dir, $post->ID, $view_id, $inputType, $slug_name ); |
|
|
|
|
180
|
5 |
|
$specifics []= sprintf( '%spost-%d-view-%d-field-%s.php', $slug_dir, $post->ID, $view_id, $field_type ); |
|
|
|
|
181
|
5 |
|
$inputType && $specifics []= sprintf( '%spost-%d-view-%d-field-%s.php', $slug_dir, $post->ID, $view_id, $inputType ); |
|
|
|
|
182
|
5 |
|
$specifics []= sprintf( '%spost-%d-field-%s-%s.php', $slug_dir, $post->ID, $field_type, $slug_name ); |
|
|
|
|
183
|
5 |
|
$inputType && $specifics []= sprintf( '%spost-%d-field-%s-%s.php', $slug_dir, $post->ID, $inputType, $slug_name ); |
|
|
|
|
184
|
5 |
|
$specifics []= sprintf( '%spost-%d-field-%s.php', $slug_dir, $post->ID, $field_type ); |
|
|
|
|
185
|
5 |
|
$inputType && $specifics []= sprintf( '%spost-%d-field-%s.php', $slug_dir, $post->ID, $inputType ); |
|
|
|
|
186
|
|
|
} |
187
|
|
|
|
188
|
5 |
|
$specifics []= sprintf( '%spost-%d-view-%d-field-%s.php', $slug_dir, $post->ID, $view_id, $slug_name ); |
|
|
|
|
189
|
5 |
|
$specifics []= sprintf( '%spost-%d-view-%d-field.php', $slug_dir, $post->ID, $view_id ); |
|
|
|
|
190
|
5 |
|
$specifics []= sprintf( '%spost-%d-field-%s.php', $slug_dir, $post->ID, $slug_name ); |
|
|
|
|
191
|
5 |
|
$specifics []= sprintf( '%spost-%d-field.php', $slug_dir, $post->ID ); |
|
|
|
|
192
|
|
|
} |
193
|
|
|
|
194
|
|
|
/** Field-specific */ |
195
|
49 |
|
if ( $field_id && $form_id ) { |
|
|
|
|
196
|
|
|
|
197
|
49 |
|
if ( $field_id ) { |
198
|
49 |
|
$specifics []= sprintf( '%sform-%d-field-%d-%s.php', $slug_dir, $form_id, $field_id, $slug_name ); |
|
|
|
|
199
|
49 |
|
$specifics []= sprintf( '%sform-%d-field-%d.php', $slug_dir, $form_id, $field_id ); |
|
|
|
|
200
|
|
|
} |
201
|
|
|
|
202
|
49 |
|
if ( $field_type ) { |
203
|
49 |
|
$specifics []= sprintf( '%sform-%d-field-%s-%s.php', $slug_dir, $form_id, $field_type, $slug_name ); |
|
|
|
|
204
|
49 |
|
$inputType && $specifics []= sprintf( '%sform-%d-field-%s-%s.php', $slug_dir, $form_id, $inputType, $slug_name ); |
|
|
|
|
205
|
49 |
|
$specifics []= sprintf( '%sform-%d-field-%s.php', $slug_dir, $form_id, $field_type ); |
|
|
|
|
206
|
49 |
|
$inputType && $specifics []= sprintf( '%sform-%d-field-%s.php', $slug_dir, $form_id, $inputType ); |
|
|
|
|
207
|
|
|
|
208
|
49 |
|
$specifics []= sprintf( '%sview-%d-field-%s-%s.php', $slug_dir, $view_id, $field_type, $slug_name ); |
|
|
|
|
209
|
49 |
|
$inputType && $specifics []= sprintf( '%sview-%d-field-%s-%s.php', $slug_dir, $view_id, $inputType, $slug_name ); |
|
|
|
|
210
|
49 |
|
$specifics []= sprintf( '%sview-%d-field-%s.php', $slug_dir, $view_id, $field_type ); |
|
|
|
|
211
|
49 |
|
$inputType && $specifics []= sprintf( '%sview-%d-field-%s.php', $slug_dir, $view_id, $inputType ); |
|
|
|
|
212
|
|
|
|
213
|
49 |
|
$specifics []= sprintf( '%sfield-%s-%s.php', $slug_dir, $field_type, $slug_name ); |
|
|
|
|
214
|
49 |
|
$inputType && $specifics []= sprintf( '%sfield-%s-%s.php', $slug_dir, $inputType, $slug_name ); |
|
|
|
|
215
|
49 |
|
$specifics []= sprintf( '%sfield-%s.php', $slug_dir, $field_type ); |
|
|
|
|
216
|
49 |
|
$inputType && $specifics []= sprintf( '%sfield-%s.php', $slug_dir, $inputType ); |
|
|
|
|
217
|
|
|
} |
218
|
|
|
} |
219
|
|
|
|
220
|
49 |
|
if ( $form_id ) { |
|
|
|
|
221
|
|
|
/** Generic field templates */ |
222
|
49 |
|
$specifics []= sprintf( '%sview-%d-field-%s.php', $slug_dir, $view_id, $slug_name ); |
|
|
|
|
223
|
49 |
|
$specifics []= sprintf( '%sform-%d-field-%s.php', $slug_dir, $form_id, $slug_name ); |
|
|
|
|
224
|
|
|
|
225
|
49 |
|
$specifics []= sprintf( '%sview-%d-field.php', $slug_dir, $view_id ); |
|
|
|
|
226
|
49 |
|
$specifics []= sprintf( '%sform-%d-field.php', $slug_dir, $form_id ); |
|
|
|
|
227
|
|
|
} |
228
|
|
|
|
229
|
49 |
|
$specifics []= sprintf( '%sfield-%s.php', $slug_dir, $slug_name ); |
|
|
|
|
230
|
49 |
|
$specifics []= sprintf( '%sfield.php', $slug_dir ); |
|
|
|
|
231
|
|
|
|
|
|
|
|
232
|
|
|
|
233
|
49 |
|
return array_merge( $specifics, $templates ); |
234
|
49 |
|
}; |
235
|
|
|
} |
236
|
|
|
|
237
|
|
|
/** |
238
|
|
|
* Output some HTML. |
239
|
|
|
* |
240
|
|
|
* @todo Move to \GV\Field_HTML_Template, but call filters here? |
241
|
|
|
* |
242
|
|
|
* @return void |
243
|
|
|
*/ |
244
|
49 |
|
public function render() { |
245
|
|
|
|
246
|
|
|
/** Retrieve the value. */ |
247
|
49 |
|
$display_value = $value = $this->field->get_value( $this->view, $this->source, $this->entry ); |
248
|
|
|
|
249
|
49 |
|
$source = $this->source; |
250
|
49 |
|
$source_backend = $source ? $source::$backend : null; |
251
|
|
|
|
252
|
|
|
/** Alter the display value according to Gravity Forms. */ |
253
|
49 |
|
if ( $source_backend == \GV\Source::BACKEND_GRAVITYFORMS ) { |
254
|
|
|
/** Prevent any PHP warnings that may be generated. */ |
255
|
38 |
|
ob_start(); |
256
|
|
|
|
257
|
38 |
|
$display_value = \GFCommon::get_lead_field_display( $this->field->field, $value, $this->entry['currency'], false, 'html' ); |
|
|
|
|
258
|
|
|
|
259
|
38 |
|
if ( $errors = ob_get_clean() ) { |
260
|
|
|
gravityview()->log->error( 'Errors when calling GFCommon::get_lead_field_display()', array( 'data' => $errors ) ); |
261
|
|
|
} |
262
|
|
|
|
263
|
|
|
/** Call the Gravity Forms field value filter. */ |
264
|
38 |
|
$display_value = apply_filters( 'gform_entry_field_value', $display_value, $this->field->field, $this->entry->as_entry(), $this->source->form ); |
|
|
|
|
265
|
|
|
|
266
|
|
|
/** Replace merge tags for admin-only fields. */ |
267
|
38 |
|
if ( ! empty( $this->field->field->adminOnly ) ) { |
|
|
|
|
268
|
|
|
$display_value = \GravityView_API::replace_variables( $display_value, $this->form->form, $this->entry->as_entry() ); |
|
|
|
|
269
|
|
|
} |
270
|
|
|
} |
271
|
|
|
|
272
|
49 |
|
$context = Template_Context::from_template( $this, compact( 'display_value', 'value' ) ); |
273
|
|
|
|
274
|
|
|
/** |
275
|
|
|
* Make various pieces of data available to the template |
276
|
|
|
* under the $gravityview scoped variable. |
277
|
|
|
* |
278
|
|
|
* @filter `gravityview/template/field/context` |
279
|
|
|
* @param \GV\Template_Context $context The context for this template. |
280
|
|
|
* @since 2.0 |
281
|
|
|
*/ |
282
|
49 |
|
$this->push_template_data( apply_filters( 'gravityview/template/field/context', $context ), 'gravityview' ); |
283
|
|
|
|
284
|
|
|
/** Bake the template. */ |
285
|
49 |
|
ob_start(); |
286
|
49 |
|
$this->located_template = $this->get_template_part( static::$slug ); |
287
|
49 |
|
$output = ob_get_clean(); |
288
|
|
|
|
289
|
49 |
|
if ( empty( $output ) ) { |
290
|
|
|
/** |
291
|
|
|
* @filter `gravityview_empty_value` What to display when a field is empty |
292
|
|
|
* @deprecated Use the `gravityview/field/value/empty` filter instead |
293
|
|
|
* @param string $value (empty string) |
294
|
|
|
*/ |
295
|
17 |
|
$output = apply_filters( 'gravityview_empty_value', $output ); |
296
|
|
|
|
297
|
|
|
/** |
298
|
|
|
* @filter `gravityview/field/value/empty` What to display when this field is empty. |
299
|
|
|
* @param string $value The value to display (Default: empty string) |
300
|
|
|
* @param \GV\Template_Context The template context this is being called from. |
301
|
|
|
*/ |
302
|
17 |
|
$output = apply_filters( 'gravityview/field/value/empty', $output, Template_Context::from_template( $this ) ); |
303
|
|
|
|
304
|
17 |
|
$context = Template_Context::from_template( $this, compact( 'display_value', 'value' ) ); |
305
|
|
|
} |
306
|
|
|
|
307
|
49 |
|
gravityview()->log->info( 'Field template for field #{field_id} loaded: {located_template}', array( 'field_id' => $this->field->ID, 'located_template' => $this->located_template ) ); |
308
|
|
|
|
309
|
49 |
|
$this->pop_template_data( 'gravityview' ); |
310
|
|
|
|
311
|
|
|
/** A compatibility array that's required by some of the deprecated filters. */ |
312
|
|
|
$field_compat = array( |
313
|
49 |
|
'form' => $source_backend == \GV\Source::BACKEND_GRAVITYFORMS ? $this->source->form : null, |
314
|
49 |
|
'field_id' => $this->field->ID, |
315
|
49 |
|
'field' => $this->field->field, |
|
|
|
|
316
|
49 |
|
'field_settings' => $this->field->as_configuration(), |
317
|
49 |
|
'value' => $value, |
318
|
49 |
|
'display_value' => $display_value, |
319
|
49 |
|
'format' => 'html', |
320
|
49 |
|
'entry' => $this->entry->as_entry(), |
321
|
49 |
|
'field_type' => $this->field->type, |
|
|
|
|
322
|
49 |
|
'field_path' => $this->located_template, |
323
|
|
|
); |
324
|
|
|
|
325
|
49 |
|
$pre_link_compat_callback = function( $output, $context ) use ( $field_compat ) { |
326
|
49 |
|
$field = $context->field; |
327
|
|
|
|
328
|
|
|
/** |
329
|
|
|
* @filter `gravityview_field_entry_value_{$field_type}_pre_link` Modify the field value output for a field type before Show As Link setting is applied. Example: `gravityview_field_entry_value_number_pre_link` |
330
|
|
|
* @since 1.16 |
331
|
|
|
* @param string $output HTML value output |
332
|
|
|
* @param array $entry The GF entry array |
333
|
|
|
* @param array $field_settings Settings for the particular GV field |
334
|
|
|
* @param array $field Field array, as fetched from GravityView_View::getCurrentField() |
335
|
|
|
* |
336
|
|
|
* @deprecated Use the `gravityview/field/{$field_type}/output` or `gravityview/field/output` filters instead. |
337
|
|
|
*/ |
338
|
49 |
|
$output = apply_filters( "gravityview_field_entry_value_{$field->type}_pre_link", $output, $context->entry->as_entry(), $field->as_configuration(), $field_compat ); |
339
|
|
|
|
340
|
49 |
|
$output = apply_filters( 'gravityview_field_entry_value_pre_link', $output, $context->entry->as_entry(), $field->as_configuration(), $field_compat ); |
341
|
|
|
|
342
|
|
|
/** |
343
|
|
|
* Link to the single entry by wrapping the output in an anchor tag |
344
|
|
|
* |
345
|
|
|
* Fields can override this by modifying the field data variable inside the field. See /templates/fields/post_image.php for an example. |
346
|
|
|
*/ |
347
|
49 |
|
if ( ! empty( $field->show_as_link ) && ! \gv_empty( $output, false, false ) ) { |
348
|
2 |
|
$link_atts = empty( $field->new_window ) ? array() : array( 'target' => '_blank' ); |
349
|
|
|
|
350
|
2 |
|
$permalink = $context->entry->get_permalink( $context->view, $context->request ); |
351
|
2 |
|
$output = \gravityview_get_link( $permalink, $output, $link_atts ); |
352
|
|
|
|
353
|
|
|
/** |
354
|
|
|
* @filter `gravityview_field_entry_link` Modify the link HTML |
355
|
|
|
* @param string $link HTML output of the link |
356
|
|
|
* @param string $href URL of the link |
357
|
|
|
* @param array $entry The GF entry array |
358
|
|
|
* @param array $field_settings Settings for the particular GV field |
359
|
|
|
* @deprecated Use `gravityview/template/field/entry_link` |
360
|
|
|
*/ |
361
|
2 |
|
$output = apply_filters( 'gravityview_field_entry_link', $output, $permalink, $context->entry->as_entry(), $field->as_configuration() ); |
362
|
|
|
|
363
|
|
|
/** |
364
|
|
|
* @filter `gravityview/template/field/entry_link` Modify the link HTML |
365
|
|
|
* @since 2.0 |
366
|
|
|
* @param string $link HTML output of the link |
367
|
|
|
* @param string $href URL of the link |
368
|
|
|
* @param \GV\Template_Context $context The context |
369
|
|
|
*/ |
370
|
2 |
|
$output = apply_filters( 'gravityview/template/field/entry_link', $output, $permalink, $context ); |
371
|
|
|
} |
372
|
|
|
|
373
|
49 |
|
return $output; |
374
|
49 |
|
}; |
375
|
|
|
|
376
|
49 |
|
$post_link_compat_callback = function( $output, $context ) use ( $field_compat ) { |
377
|
49 |
|
$field = $context->field; |
378
|
|
|
|
379
|
|
|
/** |
380
|
|
|
* @filter `gravityview_field_entry_value_{$field_type}` Modify the field value output for a field type. Example: `gravityview_field_entry_value_number` |
381
|
|
|
* @since 1.6 |
382
|
|
|
* @param string $output HTML value output |
383
|
|
|
* @param array $entry The GF entry array |
384
|
|
|
* @param array $field_settings Settings for the particular GV field |
385
|
|
|
* @param array $field Current field being displayed |
386
|
|
|
* |
387
|
|
|
* @deprecated Use the `gravityview/field/{$field_type}/output` or `gravityview/field/output` filters instead. |
388
|
|
|
*/ |
389
|
49 |
|
$output = apply_filters( "gravityview_field_entry_value_{$field->type}", $output, $context->entry->as_entry(), $field->as_configuration(), $field_compat ); |
390
|
|
|
|
391
|
|
|
/** |
392
|
|
|
* @filter `gravityview_field_entry_value` Modify the field value output for all field types |
393
|
|
|
* @param string $output HTML value output |
394
|
|
|
* @param array $entry The GF entry array |
395
|
|
|
* @param array $field_settings Settings for the particular GV field |
396
|
|
|
* @param array $field_data {@since 1.6} |
397
|
|
|
* |
398
|
|
|
* @deprecated Use the `gravityview/field/{$field_type}/output` or `gravityview/field/output` filters instead. |
399
|
|
|
*/ |
400
|
49 |
|
$output = apply_filters( 'gravityview_field_entry_value', $output, $context->entry->as_entry(), $field->as_configuration(), $field_compat ); |
401
|
|
|
|
402
|
|
|
/** |
403
|
|
|
* @filter `gravityview/template/field/{$field_type}/output` Modify the field output for a field type. |
404
|
|
|
* |
405
|
|
|
* @since 2.0 |
406
|
|
|
* |
407
|
|
|
* @param string $output The current output. |
408
|
|
|
* @param \GV\Template_Context The template context this is being called from. |
409
|
|
|
*/ |
410
|
49 |
|
return apply_filters( "gravityview/template/field/{$field->type}/output", $output, $context ); |
411
|
49 |
|
}; |
412
|
|
|
|
413
|
|
|
/** |
414
|
|
|
* Okay, what's this whole pre/post_link compat deal, huh? |
415
|
|
|
* |
416
|
|
|
* Well, the `gravityview_field_entry_value_{$field_type}_pre_link` filter |
417
|
|
|
* is expected to be applied before the value is turned into an entry link. |
418
|
|
|
* |
419
|
|
|
* And then `gravityview_field_entry_value_{$field_type}` and `gravityview_field_entry_value` |
420
|
|
|
* are called afterwards. |
421
|
|
|
* |
422
|
|
|
* So we're going to use filter priorities to make sure this happens inline with |
423
|
|
|
* our new filters, in the correct sequence. Pre-link called with priority 5 and |
424
|
|
|
* post-link called with priority 9. Then everything else. |
425
|
|
|
* |
426
|
|
|
* If a new code wants to alter the value before it is hyperlinked (hyperlinkified?), |
427
|
|
|
* it should hook into a priority between -inf. and 8. Afterwards: 10 to +inf. |
428
|
|
|
*/ |
429
|
|
|
add_filter( 'gravityview/template/field/output', $pre_link_compat_callback, 5, 2 ); |
430
|
|
|
add_filter( 'gravityview/template/field/output', $post_link_compat_callback, 9, 2 ); |
431
|
|
|
|
432
|
|
|
/** |
433
|
|
|
* @filter `gravityview/template/field/output` Modify the field output for a field. |
434
|
|
|
* |
435
|
|
|
* @since 2.0 |
436
|
|
|
* |
437
|
|
|
* @param string $output The current output. |
438
|
|
|
* @param \GV\Template_Context The template this is being called from. |
439
|
|
|
*/ |
440
|
|
|
echo apply_filters( "gravityview/template/field/output", $output, $context ); |
|
|
|
|
441
|
|
|
|
442
|
|
|
remove_filter( 'gravityview/template/field/output', $pre_link_compat_callback, 5 ); |
443
|
|
|
remove_filter( 'gravityview/template/field/output', $post_link_compat_callback, 9 ); |
444
|
|
|
} |
445
|
|
|
} |
446
|
|
|
|
447
|
|
|
/** Load implementations. */ |
448
|
|
|
require gravityview()->plugin->dir( 'future/includes/class-gv-template-field-html.php' ); |
449
|
|
|
|
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.