acf_field_tab::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 16

Duplication

Lines 16
Ratio 100 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 16
loc 16
rs 9.7333
c 0
b 0
f 0
1
<?php
2
3
/*
4
*  ACF Tab Field Class
5
*
6
*  All the logic for this field type
7
*
8
*  @class 		acf_field_tab
9
*  @extends		acf_field
10
*  @package		ACF
11
*  @subpackage	Fields
12
*/
13
14
if( ! class_exists('acf_field_tab') ) :
15
16
class acf_field_tab extends acf_field {
17
	
18
	
19
	/*
20
	*  __construct
21
	*
22
	*  This function will setup the field type data
23
	*
24
	*  @type	function
25
	*  @date	5/03/2014
26
	*  @since	5.0.0
27
	*
28
	*  @param	n/a
29
	*  @return	n/a
30
	*/
0 ignored issues
show
Documentation introduced by
The doc-type n/a could not be parsed: Unknown type name "n/a" at position 0. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
31
	
32 View Code Duplication
	function __construct() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
33
		
34
		// vars
35
		$this->name = 'tab';
36
		$this->label = __("Tab",'acf');
0 ignored issues
show
Bug introduced by
The property label does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
37
		$this->category = 'layout';
38
		$this->defaults = array(
39
			'value'		=> false, // prevents acf_render_fields() from attempting to load value
40
			'placement'	=> 'top',
41
			'endpoint'	=> 0 // added in 5.2.8
42
		);
43
		
44
		
45
		// do not delete!
46
    	parent::__construct();
47
	}
48
	
49
	
50
	/*
51
	*  prepare_field
52
	*
53
	*  description
54
	*
55
	*  @type	function
56
	*  @date	9/07/2015
57
	*  @since	5.2.3
58
	*
59
	*  @param	$post_id (int)
60
	*  @return	$post_id (int)
61
	*/
62
	
63
/*
64
	function prepare_field( $field ) {
65
		
66
		// append class
67
		if( $field['endpoint'] ) {
68
			
69
			$field['wrapper']['class'] .= ' acf-field-tab-endpoint';
70
			
71
		}
72
		
73
		
74
		// return
75
		return $field;
76
		
77
	}
78
*/
79
	
80
	
81
	/*
82
	*  render_field()
83
	*
84
	*  Create the HTML interface for your field
85
	*
86
	*  @param	$field - an array holding all the field's data
87
	*
88
	*  @type	action
89
	*  @since	3.6
90
	*  @date	23/01/13
91
	*/
92
	
93
	function render_field( $field ) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
94
		
95
		// vars
96
		$atts = array(
97
			'class'				=> 'acf-tab',
98
			'data-placement'	=> $field['placement'],
99
			'data-endpoint'		=> $field['endpoint']
100
		);
101
		
102
		?>
103
		<div <?php acf_esc_attr_e( $atts ); ?>><?php echo $field['label']; ?></div>
104
		<?php
105
		
106
		
107
	}
108
	
109
	
110
	
111
	/*
112
	*  render_field_settings()
113
	*
114
	*  Create extra options for your field. This is rendered when editing a field.
115
	*  The value of $field['name'] can be used (like bellow) to save extra data to the $field
116
	*
117
	*  @param	$field	- an array holding all the field's data
118
	*
119
	*  @type	action
120
	*  @since	3.6
121
	*  @date	23/01/13
122
	*/
123
	
124
	function render_field_settings( $field ) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
125
		
126
		// message
127
		$message = '';
128
		$message .= '<span class="acf-error-message"><p>' . __("The tab field will display incorrectly when added to a Table style repeater field or flexible content field layout", 'acf') . '</p></span>';
129
		$message .= '<p>' . __( 'Use "Tab Fields" to better organize your edit screen by grouping fields together.', 'acf') . '</p>';
130
		$message .= '<p>' . __( 'All fields following this "tab field" (or until another "tab field" is defined) will be grouped together using this field\'s label as the tab heading.','acf') . '</p>';
131
		
132
		// default_value
133
		acf_render_field_setting( $field, array(
134
			'label'			=> __('Instructions','acf'),
135
			'instructions'	=> '',
136
			'type'			=> 'message',
137
			'message'		=> $message,
138
			'new_lines'		=> ''
139
		));
140
		
141
		
142
		// preview_size
143
		acf_render_field_setting( $field, array(
144
			'label'			=> __('Placement','acf'),
145
			'type'			=> 'select',
146
			'name'			=> 'placement',
147
			'choices' 		=> array(
148
				'top'			=>	__("Top aligned",'acf'),
149
				'left'			=>	__("Left Aligned",'acf'),
150
			)
151
		));
152
		
153
		
154
		// endpoint
155
		acf_render_field_setting( $field, array(
156
			'label'			=> __('End-point','acf'),
157
			'instructions'	=> __('Use this field as an end-point and start a new group of tabs','acf'),
158
			'type'			=> 'radio',
159
			'name'			=> 'endpoint',
160
			'choices'		=> array(
161
				1				=> __("Yes",'acf'),
162
				0				=> __("No",'acf'),
163
			),
164
			'layout'	=>	'horizontal',
165
		));
166
				
167
	}
168
	
169
}
170
171
new acf_field_tab();
172
173
endif;
174
175
?>
176