Completed
Push — develop ( e2ac27...b5f4d0 )
by Zack
04:24
created

GravityView_Field_Custom::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 3

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 4
rs 10
cc 1
eloc 3
nc 1
nop 0
1
<?php
2
3
/**
4
 * Add custom options for Code field
5
 * @since 1.2
6
 */
7
class GravityView_Field_Custom extends GravityView_Field {
8
9
	var $name = 'custom';
10
11
	var $contexts = array( 'single', 'multiple', 'edit' );
12
13
	/**
14
	 * @var bool
15
	 * @since 1.15.3
16
	 */
17
	var $is_sortable = false;
18
19
	/**
20
	 * @var bool
21
	 * @since 1.15.3
22
	 */
23
	var $is_searchable = false;
24
25
	var $group = 'gravityview';
26
27
	public function __construct() {
28
		$this->label = esc_attr__( 'Custom Content', 'gravityview' );
0 ignored issues
show
Bug introduced by
The property label cannot be accessed from this context as it is declared private in class GravityView_Field.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
29
		parent::__construct();
30
	}
31
32
	function field_options( $field_options, $template_id, $field_id, $context, $input_type ) {
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...
33
34
		unset ( $field_options['search_filter'], $field_options['show_as_link'] );
35
36
		if( 'edit' === $context ) {
37
			return $field_options;
38
		}
39
40
		$new_fields = array(
41
			'content' => array(
42
				'type' => 'textarea',
43
				'label' => __( 'Custom Content', 'gravityview' ),
44
				'desc' => sprintf( __( 'Enter text or HTML. Also supports shortcodes. You can show or hide data using the %s shortcode (%slearn more%s).', 'gravityview' ), '<code>[gvlogic]</code>', '<a href="http://docs.gravityview.co/article/252-gvlogic-shortcode">', '</a>' ),
45
				'value' => '',
46
				'class'	=> 'code',
47
				'merge_tags' => 'force',
48
				'show_all_fields' => true, // Show the `{all_fields}` and `{pricing_fields}` merge tags
49
			),
50
			'wpautop' => array(
51
				'type' => 'checkbox',
52
				'label' => __( 'Automatically add paragraphs to content', 'gravityview' ),
53
				'tooltip' => __( 'Wrap each block of text in an HTML paragraph tag (recommended for text).', 'gravityview' ),
54
				'value' => '',
55
			),
56
		);
57
58
		return $new_fields + $field_options;
59
	}
60
61
}
62
63
new GravityView_Field_Custom;
64