Completed
Push — master ( 2cfa6f...8927a4 )
by Zack
10:00 queued 06:05
created

add_hooks()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 19 and the first side effect is on line 69.

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.

Loading history...
2
/**
3
 * Fix Gravity Perks conflicts with GravityView
4
 *
5
 * @file      class-gravityview-plugin-hooks-gravity-perks.php
6
 * @package   GravityView
7
 * @license   GPL2+
8
 * @author    Katz Web Services, Inc.
9
 * @link      https://gravityview.co
10
 * @copyright Copyright 2016, Katz Web Services, Inc.
11
 *
12
 * @since 1.17.5
13
 */
14
15
/**
16
 * @inheritDoc
17
 * @since 1.17.5
18
 */
19
class GravityView_Plugin_Hooks_Gravity_Perks extends GravityView_Plugin_and_Theme_Hooks {
20
21
	/**
22
	 * @var string Check for the Gravity Perks class
23
	 */
24
	protected $class_name = 'GravityPerks';
25
26
27
	/**
28
	 * Filter the values shown in GravityView frontend
29
	 *
30
	 * @since 1.17
31
	 */
32
	protected function add_hooks() {
33
34
		parent::add_hooks();
35
36
		add_filter( 'gravityview/edit_entry/form_fields', array( $this, 'edit_entry_fix_uid_fields' ) );
37
38
	}
39
40
41
	/**
42
	 * Convert Unique ID fields to be Text fields in Edit Entry
43
	 *
44
	 * @since 1.17.4
45
	 *
46
	 * @param GF_Field[] $fields Array of fields to be shown on the Edit Entry screen
47
	 *
48
	 * @return GF_Field[] Array of fields, with any hidden fields replaced with text fields
49
	 */
50
	public function edit_entry_fix_uid_fields( $fields ) {
51
52
		/** @var GF_Field $field */
53
		foreach( $fields as &$field ) {
54
			if ( 'uid' === $field->type ) {
55
56
				// Replace GF_Field with GF_Field_Text, copying all the data from $field
57
				$field = new GF_Field_Text( $field );
58
59
				// Everything is copied from $field, so we need to manually set the type
60
				$field->type = 'text';
61
			}
62
		}
63
64
		return $fields;
65
	}
66
67
}
68
69
new GravityView_Plugin_Hooks_Gravity_Perks;