@@ -8,37 +8,37 @@ |
||
8 | 8 | */ |
9 | 9 | class GravityView_Field_Post_Title extends GravityView_Field |
10 | 10 | { |
11 | - public $name = 'post_title'; |
|
11 | + public $name = 'post_title'; |
|
12 | 12 | |
13 | - public $is_searchable = true; |
|
13 | + public $is_searchable = true; |
|
14 | 14 | |
15 | - public $search_operators = ['is', 'isnot', 'contains', 'starts_with', 'ends_with']; |
|
15 | + public $search_operators = ['is', 'isnot', 'contains', 'starts_with', 'ends_with']; |
|
16 | 16 | |
17 | - /** @see GF_Field_Post_Title */ |
|
18 | - public $_gf_field_class_name = 'GF_Field_Post_Title'; |
|
17 | + /** @see GF_Field_Post_Title */ |
|
18 | + public $_gf_field_class_name = 'GF_Field_Post_Title'; |
|
19 | 19 | |
20 | - public $group = 'post'; |
|
20 | + public $group = 'post'; |
|
21 | 21 | |
22 | - public $icon = 'dashicons-edit'; |
|
22 | + public $icon = 'dashicons-edit'; |
|
23 | 23 | |
24 | - public function __construct() |
|
25 | - { |
|
26 | - $this->label = esc_html__('Post Title', 'gravityview'); |
|
27 | - parent::__construct(); |
|
28 | - } |
|
24 | + public function __construct() |
|
25 | + { |
|
26 | + $this->label = esc_html__('Post Title', 'gravityview'); |
|
27 | + parent::__construct(); |
|
28 | + } |
|
29 | 29 | |
30 | - public function field_options($field_options, $template_id, $field_id, $context, $input_type, $form_id) |
|
31 | - { |
|
32 | - if ('edit' === $context) { |
|
33 | - return $field_options; |
|
34 | - } |
|
30 | + public function field_options($field_options, $template_id, $field_id, $context, $input_type, $form_id) |
|
31 | + { |
|
32 | + if ('edit' === $context) { |
|
33 | + return $field_options; |
|
34 | + } |
|
35 | 35 | |
36 | - $this->add_field_support('link_to_post', $field_options); |
|
36 | + $this->add_field_support('link_to_post', $field_options); |
|
37 | 37 | |
38 | - $this->add_field_support('dynamic_data', $field_options); |
|
38 | + $this->add_field_support('dynamic_data', $field_options); |
|
39 | 39 | |
40 | - return $field_options; |
|
41 | - } |
|
40 | + return $field_options; |
|
41 | + } |
|
42 | 42 | } |
43 | 43 | |
44 | 44 | new GravityView_Field_Post_Title(); |
@@ -12,7 +12,7 @@ discard block |
||
12 | 12 | |
13 | 13 | public $is_searchable = true; |
14 | 14 | |
15 | - public $search_operators = ['is', 'isnot', 'contains', 'starts_with', 'ends_with']; |
|
15 | + public $search_operators = [ 'is', 'isnot', 'contains', 'starts_with', 'ends_with' ]; |
|
16 | 16 | |
17 | 17 | /** @see GF_Field_Post_Title */ |
18 | 18 | public $_gf_field_class_name = 'GF_Field_Post_Title'; |
@@ -23,19 +23,19 @@ discard block |
||
23 | 23 | |
24 | 24 | public function __construct() |
25 | 25 | { |
26 | - $this->label = esc_html__('Post Title', 'gravityview'); |
|
26 | + $this->label = esc_html__( 'Post Title', 'gravityview' ); |
|
27 | 27 | parent::__construct(); |
28 | 28 | } |
29 | 29 | |
30 | - public function field_options($field_options, $template_id, $field_id, $context, $input_type, $form_id) |
|
30 | + public function field_options( $field_options, $template_id, $field_id, $context, $input_type, $form_id ) |
|
31 | 31 | { |
32 | - if ('edit' === $context) { |
|
32 | + if ( 'edit' === $context ) { |
|
33 | 33 | return $field_options; |
34 | 34 | } |
35 | 35 | |
36 | - $this->add_field_support('link_to_post', $field_options); |
|
36 | + $this->add_field_support( 'link_to_post', $field_options ); |
|
37 | 37 | |
38 | - $this->add_field_support('dynamic_data', $field_options); |
|
38 | + $this->add_field_support( 'dynamic_data', $field_options ); |
|
39 | 39 | |
40 | 40 | return $field_options; |
41 | 41 | } |
@@ -6,8 +6,7 @@ discard block |
||
6 | 6 | /** |
7 | 7 | * Add custom options for date fields. |
8 | 8 | */ |
9 | -class GravityView_Field_Post_Title extends GravityView_Field |
|
10 | -{ |
|
9 | +class GravityView_Field_Post_Title extends GravityView_Field { |
|
11 | 10 | public $name = 'post_title'; |
12 | 11 | |
13 | 12 | public $is_searchable = true; |
@@ -21,14 +20,12 @@ discard block |
||
21 | 20 | |
22 | 21 | public $icon = 'dashicons-edit'; |
23 | 22 | |
24 | - public function __construct() |
|
25 | - { |
|
23 | + public function __construct() { |
|
26 | 24 | $this->label = esc_html__('Post Title', 'gravityview'); |
27 | 25 | parent::__construct(); |
28 | 26 | } |
29 | 27 | |
30 | - public function field_options($field_options, $template_id, $field_id, $context, $input_type, $form_id) |
|
31 | - { |
|
28 | + public function field_options($field_options, $template_id, $field_id, $context, $input_type, $form_id) { |
|
32 | 29 | if ('edit' === $context) { |
33 | 30 | return $field_options; |
34 | 31 | } |
@@ -8,52 +8,52 @@ |
||
8 | 8 | */ |
9 | 9 | class GravityView_Field_Source_URL extends GravityView_Field |
10 | 10 | { |
11 | - public $name = 'source_url'; |
|
12 | - |
|
13 | - public $is_searchable = true; |
|
14 | - |
|
15 | - public $search_operators = ['is', 'isnot', 'contains', 'starts_with', 'ends_with']; |
|
16 | - |
|
17 | - public $group = 'meta'; |
|
18 | - |
|
19 | - public $icon = 'dashicons-admin-links'; |
|
20 | - |
|
21 | - public function __construct() |
|
22 | - { |
|
23 | - $this->label = esc_html__('Source URL', 'gravityview'); |
|
24 | - $this->description = esc_html__('The URL of the page where the form was submitted.', 'gravityview'); |
|
25 | - parent::__construct(); |
|
26 | - } |
|
27 | - |
|
28 | - public function field_options($field_options, $template_id, $field_id, $context, $input_type, $form_id) |
|
29 | - { |
|
30 | - |
|
31 | - // Don't link to entry; doesn't make sense. |
|
32 | - unset($field_options['show_as_link']); |
|
33 | - |
|
34 | - if ('edit' === $context) { |
|
35 | - return $field_options; |
|
36 | - } |
|
37 | - |
|
38 | - $add_options = []; |
|
39 | - $add_options['link_to_source'] = [ |
|
40 | - 'type' => 'checkbox', |
|
41 | - 'label' => __('Link to URL:', 'gravityview'), |
|
42 | - 'desc' => __('Display as a link to the Source URL', 'gravityview'), |
|
43 | - 'value' => false, |
|
44 | - 'merge_tags' => false, |
|
45 | - ]; |
|
46 | - $add_options['source_link_text'] = [ |
|
47 | - 'type' => 'text', |
|
48 | - 'label' => __('Link Text:', 'gravityview'), |
|
49 | - 'desc' => __('Customize the link text. If empty, the link text will be the URL.', 'gravityview'), |
|
50 | - 'value' => null, |
|
51 | - 'merge_tags' => true, |
|
52 | - 'requires' => 'link_to_source', |
|
53 | - ]; |
|
54 | - |
|
55 | - return $add_options + $field_options; |
|
56 | - } |
|
11 | + public $name = 'source_url'; |
|
12 | + |
|
13 | + public $is_searchable = true; |
|
14 | + |
|
15 | + public $search_operators = ['is', 'isnot', 'contains', 'starts_with', 'ends_with']; |
|
16 | + |
|
17 | + public $group = 'meta'; |
|
18 | + |
|
19 | + public $icon = 'dashicons-admin-links'; |
|
20 | + |
|
21 | + public function __construct() |
|
22 | + { |
|
23 | + $this->label = esc_html__('Source URL', 'gravityview'); |
|
24 | + $this->description = esc_html__('The URL of the page where the form was submitted.', 'gravityview'); |
|
25 | + parent::__construct(); |
|
26 | + } |
|
27 | + |
|
28 | + public function field_options($field_options, $template_id, $field_id, $context, $input_type, $form_id) |
|
29 | + { |
|
30 | + |
|
31 | + // Don't link to entry; doesn't make sense. |
|
32 | + unset($field_options['show_as_link']); |
|
33 | + |
|
34 | + if ('edit' === $context) { |
|
35 | + return $field_options; |
|
36 | + } |
|
37 | + |
|
38 | + $add_options = []; |
|
39 | + $add_options['link_to_source'] = [ |
|
40 | + 'type' => 'checkbox', |
|
41 | + 'label' => __('Link to URL:', 'gravityview'), |
|
42 | + 'desc' => __('Display as a link to the Source URL', 'gravityview'), |
|
43 | + 'value' => false, |
|
44 | + 'merge_tags' => false, |
|
45 | + ]; |
|
46 | + $add_options['source_link_text'] = [ |
|
47 | + 'type' => 'text', |
|
48 | + 'label' => __('Link Text:', 'gravityview'), |
|
49 | + 'desc' => __('Customize the link text. If empty, the link text will be the URL.', 'gravityview'), |
|
50 | + 'value' => null, |
|
51 | + 'merge_tags' => true, |
|
52 | + 'requires' => 'link_to_source', |
|
53 | + ]; |
|
54 | + |
|
55 | + return $add_options + $field_options; |
|
56 | + } |
|
57 | 57 | } |
58 | 58 | |
59 | 59 | new GravityView_Field_Source_URL(); |
@@ -12,7 +12,7 @@ discard block |
||
12 | 12 | |
13 | 13 | public $is_searchable = true; |
14 | 14 | |
15 | - public $search_operators = ['is', 'isnot', 'contains', 'starts_with', 'ends_with']; |
|
15 | + public $search_operators = [ 'is', 'isnot', 'contains', 'starts_with', 'ends_with' ]; |
|
16 | 16 | |
17 | 17 | public $group = 'meta'; |
18 | 18 | |
@@ -20,33 +20,33 @@ discard block |
||
20 | 20 | |
21 | 21 | public function __construct() |
22 | 22 | { |
23 | - $this->label = esc_html__('Source URL', 'gravityview'); |
|
24 | - $this->description = esc_html__('The URL of the page where the form was submitted.', 'gravityview'); |
|
23 | + $this->label = esc_html__( 'Source URL', 'gravityview' ); |
|
24 | + $this->description = esc_html__( 'The URL of the page where the form was submitted.', 'gravityview' ); |
|
25 | 25 | parent::__construct(); |
26 | 26 | } |
27 | 27 | |
28 | - public function field_options($field_options, $template_id, $field_id, $context, $input_type, $form_id) |
|
28 | + public function field_options( $field_options, $template_id, $field_id, $context, $input_type, $form_id ) |
|
29 | 29 | { |
30 | 30 | |
31 | 31 | // Don't link to entry; doesn't make sense. |
32 | - unset($field_options['show_as_link']); |
|
32 | + unset( $field_options[ 'show_as_link' ] ); |
|
33 | 33 | |
34 | - if ('edit' === $context) { |
|
34 | + if ( 'edit' === $context ) { |
|
35 | 35 | return $field_options; |
36 | 36 | } |
37 | 37 | |
38 | - $add_options = []; |
|
39 | - $add_options['link_to_source'] = [ |
|
38 | + $add_options = [ ]; |
|
39 | + $add_options[ 'link_to_source' ] = [ |
|
40 | 40 | 'type' => 'checkbox', |
41 | - 'label' => __('Link to URL:', 'gravityview'), |
|
42 | - 'desc' => __('Display as a link to the Source URL', 'gravityview'), |
|
41 | + 'label' => __( 'Link to URL:', 'gravityview' ), |
|
42 | + 'desc' => __( 'Display as a link to the Source URL', 'gravityview' ), |
|
43 | 43 | 'value' => false, |
44 | 44 | 'merge_tags' => false, |
45 | 45 | ]; |
46 | - $add_options['source_link_text'] = [ |
|
46 | + $add_options[ 'source_link_text' ] = [ |
|
47 | 47 | 'type' => 'text', |
48 | - 'label' => __('Link Text:', 'gravityview'), |
|
49 | - 'desc' => __('Customize the link text. If empty, the link text will be the URL.', 'gravityview'), |
|
48 | + 'label' => __( 'Link Text:', 'gravityview' ), |
|
49 | + 'desc' => __( 'Customize the link text. If empty, the link text will be the URL.', 'gravityview' ), |
|
50 | 50 | 'value' => null, |
51 | 51 | 'merge_tags' => true, |
52 | 52 | 'requires' => 'link_to_source', |
@@ -6,8 +6,7 @@ discard block |
||
6 | 6 | /** |
7 | 7 | * Add custom options for source_url fields. |
8 | 8 | */ |
9 | -class GravityView_Field_Source_URL extends GravityView_Field |
|
10 | -{ |
|
9 | +class GravityView_Field_Source_URL extends GravityView_Field { |
|
11 | 10 | public $name = 'source_url'; |
12 | 11 | |
13 | 12 | public $is_searchable = true; |
@@ -18,15 +17,13 @@ discard block |
||
18 | 17 | |
19 | 18 | public $icon = 'dashicons-admin-links'; |
20 | 19 | |
21 | - public function __construct() |
|
22 | - { |
|
20 | + public function __construct() { |
|
23 | 21 | $this->label = esc_html__('Source URL', 'gravityview'); |
24 | 22 | $this->description = esc_html__('The URL of the page where the form was submitted.', 'gravityview'); |
25 | 23 | parent::__construct(); |
26 | 24 | } |
27 | 25 | |
28 | - public function field_options($field_options, $template_id, $field_id, $context, $input_type, $form_id) |
|
29 | - { |
|
26 | + public function field_options($field_options, $template_id, $field_id, $context, $input_type, $form_id) { |
|
30 | 27 | |
31 | 28 | // Don't link to entry; doesn't make sense. |
32 | 29 | unset($field_options['show_as_link']); |
@@ -4,65 +4,65 @@ |
||
4 | 4 | */ |
5 | 5 | class GravityView_Field_MultiSelect extends GravityView_Field |
6 | 6 | { |
7 | - public $name = 'multiselect'; |
|
7 | + public $name = 'multiselect'; |
|
8 | 8 | |
9 | - /** |
|
10 | - * @see GFCommon::get_field_filter_settings Gravity Forms suggests checkboxes should just be "contains" |
|
11 | - * |
|
12 | - * @var array |
|
13 | - */ |
|
14 | - public $search_operators = ['is', 'in', 'not in', 'isnot', 'contains']; |
|
9 | + /** |
|
10 | + * @see GFCommon::get_field_filter_settings Gravity Forms suggests checkboxes should just be "contains" |
|
11 | + * |
|
12 | + * @var array |
|
13 | + */ |
|
14 | + public $search_operators = ['is', 'in', 'not in', 'isnot', 'contains']; |
|
15 | 15 | |
16 | - public $is_searchable = true; |
|
16 | + public $is_searchable = true; |
|
17 | 17 | |
18 | - /** @see GF_Field_MultiSelect */ |
|
19 | - public $_gf_field_class_name = 'GF_Field_MultiSelect'; |
|
18 | + /** @see GF_Field_MultiSelect */ |
|
19 | + public $_gf_field_class_name = 'GF_Field_MultiSelect'; |
|
20 | 20 | |
21 | - public $group = 'standard'; |
|
21 | + public $group = 'standard'; |
|
22 | 22 | |
23 | - public $icon = 'dashicons-editor-ul'; |
|
23 | + public $icon = 'dashicons-editor-ul'; |
|
24 | 24 | |
25 | - public function __construct() |
|
26 | - { |
|
27 | - $this->label = esc_html__('Multi Select', 'gravityview'); |
|
28 | - parent::__construct(); |
|
29 | - } |
|
25 | + public function __construct() |
|
26 | + { |
|
27 | + $this->label = esc_html__('Multi Select', 'gravityview'); |
|
28 | + parent::__construct(); |
|
29 | + } |
|
30 | 30 | |
31 | - /** |
|
32 | - * Add `choice_display` setting to the field. |
|
33 | - * |
|
34 | - * @param array $field_options |
|
35 | - * @param string $template_id |
|
36 | - * @param string $field_id |
|
37 | - * @param string $context |
|
38 | - * @param string $input_type |
|
39 | - * |
|
40 | - * @since 2.0 |
|
41 | - * |
|
42 | - * @return array |
|
43 | - */ |
|
44 | - public function field_options($field_options, $template_id, $field_id, $context, $input_type, $form_id) |
|
45 | - { |
|
31 | + /** |
|
32 | + * Add `choice_display` setting to the field. |
|
33 | + * |
|
34 | + * @param array $field_options |
|
35 | + * @param string $template_id |
|
36 | + * @param string $field_id |
|
37 | + * @param string $context |
|
38 | + * @param string $input_type |
|
39 | + * |
|
40 | + * @since 2.0 |
|
41 | + * |
|
42 | + * @return array |
|
43 | + */ |
|
44 | + public function field_options($field_options, $template_id, $field_id, $context, $input_type, $form_id) |
|
45 | + { |
|
46 | 46 | |
47 | - // Set the $_field_id var |
|
48 | - $field_options = parent::field_options($field_options, $template_id, $field_id, $context, $input_type, $form_id); |
|
47 | + // Set the $_field_id var |
|
48 | + $field_options = parent::field_options($field_options, $template_id, $field_id, $context, $input_type, $form_id); |
|
49 | 49 | |
50 | - if ($this->is_choice_value_enabled()) { |
|
51 | - $field_options['choice_display'] = [ |
|
52 | - 'type' => 'radio', |
|
53 | - 'value' => 'value', |
|
54 | - 'label' => __('What should be displayed:', 'gravityview'), |
|
55 | - 'desc' => __('This input has a label and a value. What should be displayed?', 'gravityview'), |
|
56 | - 'choices' => [ |
|
57 | - 'value' => __('Value of the input', 'gravityview'), |
|
58 | - 'label' => __('Label of the input', 'gravityview'), |
|
59 | - ], |
|
60 | - 'group' => 'display', |
|
61 | - ]; |
|
62 | - } |
|
50 | + if ($this->is_choice_value_enabled()) { |
|
51 | + $field_options['choice_display'] = [ |
|
52 | + 'type' => 'radio', |
|
53 | + 'value' => 'value', |
|
54 | + 'label' => __('What should be displayed:', 'gravityview'), |
|
55 | + 'desc' => __('This input has a label and a value. What should be displayed?', 'gravityview'), |
|
56 | + 'choices' => [ |
|
57 | + 'value' => __('Value of the input', 'gravityview'), |
|
58 | + 'label' => __('Label of the input', 'gravityview'), |
|
59 | + ], |
|
60 | + 'group' => 'display', |
|
61 | + ]; |
|
62 | + } |
|
63 | 63 | |
64 | - return $field_options; |
|
65 | - } |
|
64 | + return $field_options; |
|
65 | + } |
|
66 | 66 | } |
67 | 67 | |
68 | 68 | new GravityView_Field_MultiSelect(); |
@@ -11,7 +11,7 @@ discard block |
||
11 | 11 | * |
12 | 12 | * @var array |
13 | 13 | */ |
14 | - public $search_operators = ['is', 'in', 'not in', 'isnot', 'contains']; |
|
14 | + public $search_operators = [ 'is', 'in', 'not in', 'isnot', 'contains' ]; |
|
15 | 15 | |
16 | 16 | public $is_searchable = true; |
17 | 17 | |
@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | |
25 | 25 | public function __construct() |
26 | 26 | { |
27 | - $this->label = esc_html__('Multi Select', 'gravityview'); |
|
27 | + $this->label = esc_html__( 'Multi Select', 'gravityview' ); |
|
28 | 28 | parent::__construct(); |
29 | 29 | } |
30 | 30 | |
@@ -41,21 +41,21 @@ discard block |
||
41 | 41 | * |
42 | 42 | * @return array |
43 | 43 | */ |
44 | - public function field_options($field_options, $template_id, $field_id, $context, $input_type, $form_id) |
|
44 | + public function field_options( $field_options, $template_id, $field_id, $context, $input_type, $form_id ) |
|
45 | 45 | { |
46 | 46 | |
47 | 47 | // Set the $_field_id var |
48 | - $field_options = parent::field_options($field_options, $template_id, $field_id, $context, $input_type, $form_id); |
|
48 | + $field_options = parent::field_options( $field_options, $template_id, $field_id, $context, $input_type, $form_id ); |
|
49 | 49 | |
50 | - if ($this->is_choice_value_enabled()) { |
|
51 | - $field_options['choice_display'] = [ |
|
50 | + if ( $this->is_choice_value_enabled() ) { |
|
51 | + $field_options[ 'choice_display' ] = [ |
|
52 | 52 | 'type' => 'radio', |
53 | 53 | 'value' => 'value', |
54 | - 'label' => __('What should be displayed:', 'gravityview'), |
|
55 | - 'desc' => __('This input has a label and a value. What should be displayed?', 'gravityview'), |
|
54 | + 'label' => __( 'What should be displayed:', 'gravityview' ), |
|
55 | + 'desc' => __( 'This input has a label and a value. What should be displayed?', 'gravityview' ), |
|
56 | 56 | 'choices' => [ |
57 | - 'value' => __('Value of the input', 'gravityview'), |
|
58 | - 'label' => __('Label of the input', 'gravityview'), |
|
57 | + 'value' => __( 'Value of the input', 'gravityview' ), |
|
58 | + 'label' => __( 'Label of the input', 'gravityview' ), |
|
59 | 59 | ], |
60 | 60 | 'group' => 'display', |
61 | 61 | ]; |
@@ -2,8 +2,7 @@ discard block |
||
2 | 2 | /** |
3 | 3 | * @file class-gravityview-field-multiselect.php |
4 | 4 | */ |
5 | -class GravityView_Field_MultiSelect extends GravityView_Field |
|
6 | -{ |
|
5 | +class GravityView_Field_MultiSelect extends GravityView_Field { |
|
7 | 6 | public $name = 'multiselect'; |
8 | 7 | |
9 | 8 | /** |
@@ -22,8 +21,7 @@ discard block |
||
22 | 21 | |
23 | 22 | public $icon = 'dashicons-editor-ul'; |
24 | 23 | |
25 | - public function __construct() |
|
26 | - { |
|
24 | + public function __construct() { |
|
27 | 25 | $this->label = esc_html__('Multi Select', 'gravityview'); |
28 | 26 | parent::__construct(); |
29 | 27 | } |
@@ -41,8 +39,7 @@ discard block |
||
41 | 39 | * |
42 | 40 | * @return array |
43 | 41 | */ |
44 | - public function field_options($field_options, $template_id, $field_id, $context, $input_type, $form_id) |
|
45 | - { |
|
42 | + public function field_options($field_options, $template_id, $field_id, $context, $input_type, $form_id) { |
|
46 | 43 | |
47 | 44 | // Set the $_field_id var |
48 | 45 | $field_options = parent::field_options($field_options, $template_id, $field_id, $context, $input_type, $form_id); |
@@ -6,37 +6,37 @@ |
||
6 | 6 | */ |
7 | 7 | class GravityView_Field_ID extends GravityView_Field |
8 | 8 | { |
9 | - public $name = 'id'; |
|
9 | + public $name = 'id'; |
|
10 | 10 | |
11 | - public $is_searchable = true; |
|
11 | + public $is_searchable = true; |
|
12 | 12 | |
13 | - public $search_operators = ['is', 'isnot', 'greater_than', 'less_than', 'in', 'not_in']; |
|
13 | + public $search_operators = ['is', 'isnot', 'greater_than', 'less_than', 'in', 'not_in']; |
|
14 | 14 | |
15 | - public $group = 'meta'; |
|
15 | + public $group = 'meta'; |
|
16 | 16 | |
17 | - public $icon = 'dashicons-code-standards'; |
|
17 | + public $icon = 'dashicons-code-standards'; |
|
18 | 18 | |
19 | - public $is_numeric = true; |
|
19 | + public $is_numeric = true; |
|
20 | 20 | |
21 | - public function __construct() |
|
22 | - { |
|
23 | - $this->label = esc_html__('Entry ID', 'gravityview'); |
|
24 | - $this->description = __('The unique ID of the entry.', 'gravityview'); |
|
25 | - parent::__construct(); |
|
26 | - } |
|
21 | + public function __construct() |
|
22 | + { |
|
23 | + $this->label = esc_html__('Entry ID', 'gravityview'); |
|
24 | + $this->description = __('The unique ID of the entry.', 'gravityview'); |
|
25 | + parent::__construct(); |
|
26 | + } |
|
27 | 27 | |
28 | - public function field_options($field_options, $template_id, $field_id, $context, $input_type, $form_id) |
|
29 | - { |
|
30 | - if ('edit' === $context) { |
|
31 | - return $field_options; |
|
32 | - } |
|
28 | + public function field_options($field_options, $template_id, $field_id, $context, $input_type, $form_id) |
|
29 | + { |
|
30 | + if ('edit' === $context) { |
|
31 | + return $field_options; |
|
32 | + } |
|
33 | 33 | |
34 | - if ('single' === $context) { |
|
35 | - unset($field_options['new_window']); |
|
36 | - } |
|
34 | + if ('single' === $context) { |
|
35 | + unset($field_options['new_window']); |
|
36 | + } |
|
37 | 37 | |
38 | - return $field_options; |
|
39 | - } |
|
38 | + return $field_options; |
|
39 | + } |
|
40 | 40 | } |
41 | 41 | |
42 | 42 | new GravityView_Field_ID(); |
@@ -10,7 +10,7 @@ discard block |
||
10 | 10 | |
11 | 11 | public $is_searchable = true; |
12 | 12 | |
13 | - public $search_operators = ['is', 'isnot', 'greater_than', 'less_than', 'in', 'not_in']; |
|
13 | + public $search_operators = [ 'is', 'isnot', 'greater_than', 'less_than', 'in', 'not_in' ]; |
|
14 | 14 | |
15 | 15 | public $group = 'meta'; |
16 | 16 | |
@@ -20,19 +20,19 @@ discard block |
||
20 | 20 | |
21 | 21 | public function __construct() |
22 | 22 | { |
23 | - $this->label = esc_html__('Entry ID', 'gravityview'); |
|
24 | - $this->description = __('The unique ID of the entry.', 'gravityview'); |
|
23 | + $this->label = esc_html__( 'Entry ID', 'gravityview' ); |
|
24 | + $this->description = __( 'The unique ID of the entry.', 'gravityview' ); |
|
25 | 25 | parent::__construct(); |
26 | 26 | } |
27 | 27 | |
28 | - public function field_options($field_options, $template_id, $field_id, $context, $input_type, $form_id) |
|
28 | + public function field_options( $field_options, $template_id, $field_id, $context, $input_type, $form_id ) |
|
29 | 29 | { |
30 | - if ('edit' === $context) { |
|
30 | + if ( 'edit' === $context ) { |
|
31 | 31 | return $field_options; |
32 | 32 | } |
33 | 33 | |
34 | - if ('single' === $context) { |
|
35 | - unset($field_options['new_window']); |
|
34 | + if ( 'single' === $context ) { |
|
35 | + unset( $field_options[ 'new_window' ] ); |
|
36 | 36 | } |
37 | 37 | |
38 | 38 | return $field_options; |
@@ -4,8 +4,7 @@ discard block |
||
4 | 4 | * |
5 | 5 | * @since 2.10 |
6 | 6 | */ |
7 | -class GravityView_Field_ID extends GravityView_Field |
|
8 | -{ |
|
7 | +class GravityView_Field_ID extends GravityView_Field { |
|
9 | 8 | public $name = 'id'; |
10 | 9 | |
11 | 10 | public $is_searchable = true; |
@@ -18,15 +17,13 @@ discard block |
||
18 | 17 | |
19 | 18 | public $is_numeric = true; |
20 | 19 | |
21 | - public function __construct() |
|
22 | - { |
|
20 | + public function __construct() { |
|
23 | 21 | $this->label = esc_html__('Entry ID', 'gravityview'); |
24 | 22 | $this->description = __('The unique ID of the entry.', 'gravityview'); |
25 | 23 | parent::__construct(); |
26 | 24 | } |
27 | 25 | |
28 | - public function field_options($field_options, $template_id, $field_id, $context, $input_type, $form_id) |
|
29 | - { |
|
26 | + public function field_options($field_options, $template_id, $field_id, $context, $input_type, $form_id) { |
|
30 | 27 | if ('edit' === $context) { |
31 | 28 | return $field_options; |
32 | 29 | } |
@@ -4,136 +4,136 @@ |
||
4 | 4 | */ |
5 | 5 | class GravityView_Field_Survey extends GravityView_Field |
6 | 6 | { |
7 | - public $name = 'survey'; |
|
8 | - |
|
9 | - public $_gf_field_class_name = 'GF_Field_Survey'; |
|
10 | - |
|
11 | - public $is_searchable = false; |
|
12 | - |
|
13 | - public $group = 'advanced'; |
|
14 | - |
|
15 | - public $icon = 'dashicons-forms'; |
|
16 | - |
|
17 | - public function __construct() |
|
18 | - { |
|
19 | - $this->label = esc_html__('Survey', 'gravityview'); |
|
20 | - parent::__construct(); |
|
21 | - } |
|
22 | - |
|
23 | - /** |
|
24 | - * Returns the score for a choice at $value. |
|
25 | - * |
|
26 | - * A sister method to {@see RGFormsModel::get_choice_text} |
|
27 | - * |
|
28 | - * @since 2.11 |
|
29 | - * |
|
30 | - * @param GF_Field_Likert $field |
|
31 | - * @param string|array $value |
|
32 | - * @param int|string $input_id ID of the field or input (for example, 7.3 or 7) |
|
33 | - * |
|
34 | - * @return mixed|string |
|
35 | - */ |
|
36 | - public static function get_choice_score($field, $value, $input_id = 0) |
|
37 | - { |
|
38 | - if (!$field->gsurveyLikertEnableScoring) { |
|
39 | - return ''; |
|
40 | - } |
|
41 | - |
|
42 | - if (!is_array($field->choices)) { |
|
43 | - return $value; |
|
44 | - } |
|
45 | - |
|
46 | - foreach ($field->choices as $choice) { |
|
47 | - if (is_array($value) && RGFormsModel::choice_value_match($field, $choice, $value[$input_id])) { |
|
48 | - return $choice['score']; |
|
49 | - } elseif (!is_array($value) && RGFormsModel::choice_value_match($field, $choice, $value)) { |
|
50 | - return $choice['score']; |
|
51 | - } |
|
52 | - } |
|
53 | - |
|
54 | - return is_array($value) ? '' : $value; |
|
55 | - } |
|
56 | - |
|
57 | - public function field_options($field_options, $template_id, $field_id, $context, $input_type, $form_id) |
|
58 | - { |
|
59 | - unset($field_options['search_filter']); |
|
60 | - |
|
61 | - if ('edit' === $context) { |
|
62 | - return $field_options; |
|
63 | - } |
|
64 | - |
|
65 | - $field = \GV\GF_Field::by_id(\GV\GF_Form::by_id($form_id), $field_id); |
|
66 | - $input_id = gravityview_get_input_id_from_id($field_id); |
|
67 | - $add_options = []; |
|
68 | - |
|
69 | - $glue = apply_filters('gravityview/template/field/survey/glue', '; '); |
|
70 | - $multiple_rows_suffix = sprintf(_x(' (separated by %s)', 'text added to a label if multiple rows are enabled for the field)', 'gravityview'), esc_html(trim($glue))); |
|
71 | - |
|
72 | - if ('likert' === $field->field->inputType) { |
|
73 | - $show_suffix = $input_id || empty($field->field->gsurveyLikertEnableMultipleRows); |
|
74 | - |
|
75 | - $likert_display_options = [ |
|
76 | - 'default' => __('A table (default Gravity Forms formatting)', 'gravityview'), |
|
77 | - 'text' => __('Text value of the selected choice', 'gravityview').($show_suffix ? '' : $multiple_rows_suffix), |
|
78 | - ]; |
|
79 | - |
|
80 | - if ($field->field->gsurveyLikertEnableScoring) { |
|
81 | - $likert_display_options['score'] = __('Score value of the selected choice', 'gravityview').($show_suffix ? '' : $multiple_rows_suffix); |
|
82 | - } |
|
83 | - |
|
84 | - // Maintain for back-compatibility |
|
85 | - $add_options['score'] = [ |
|
86 | - 'type' => 'hidden', |
|
87 | - 'value' => '', |
|
88 | - 'group' => 'display', |
|
89 | - ]; |
|
90 | - |
|
91 | - $add_options['choice_display'] = [ |
|
92 | - 'type' => 'radio', |
|
93 | - 'label' => __('What should be displayed:', 'gravityview'), |
|
94 | - 'options' => $likert_display_options, |
|
95 | - 'desc' => '', |
|
96 | - 'group' => 'display', |
|
97 | - 'class' => 'block', |
|
98 | - 'value' => 'default', |
|
99 | - 'merge_tags' => false, |
|
100 | - ]; |
|
101 | - } |
|
102 | - |
|
103 | - if ('checkbox' === $field->field->inputType && $input_id) { |
|
104 | - $field_options['choice_display'] = [ |
|
105 | - 'type' => 'radio', |
|
106 | - 'class' => 'vertical', |
|
107 | - 'label' => __('What should be displayed:', 'gravityview'), |
|
108 | - 'value' => 'tick', |
|
109 | - 'desc' => '', |
|
110 | - 'choices' => [ |
|
111 | - 'tick' => __('A check mark, if the input is checked', 'gravityview'), |
|
112 | - 'text' => __('Text value of the selected choice', 'gravityview'), |
|
113 | - ], |
|
114 | - 'group' => 'display', |
|
115 | - 'priority' => 100, |
|
116 | - ]; |
|
117 | - } |
|
118 | - |
|
119 | - if ('rating' === $field->field->inputType) { |
|
120 | - $field_options['choice_display'] = [ |
|
121 | - 'type' => 'radio', |
|
122 | - 'class' => 'vertical', |
|
123 | - 'label' => __('What should be displayed:', 'gravityview'), |
|
124 | - 'value' => 'default', |
|
125 | - 'desc' => '', |
|
126 | - 'choices' => [ |
|
127 | - 'default' => __('Text value of the selected choice', 'gravityview'), |
|
128 | - 'stars' => __('Stars (default Gravity Forms formatting)', 'gravityview'), |
|
129 | - ], |
|
130 | - 'group' => 'display', |
|
131 | - 'priority' => 100, |
|
132 | - ]; |
|
133 | - } |
|
134 | - |
|
135 | - return $add_options + $field_options; |
|
136 | - } |
|
7 | + public $name = 'survey'; |
|
8 | + |
|
9 | + public $_gf_field_class_name = 'GF_Field_Survey'; |
|
10 | + |
|
11 | + public $is_searchable = false; |
|
12 | + |
|
13 | + public $group = 'advanced'; |
|
14 | + |
|
15 | + public $icon = 'dashicons-forms'; |
|
16 | + |
|
17 | + public function __construct() |
|
18 | + { |
|
19 | + $this->label = esc_html__('Survey', 'gravityview'); |
|
20 | + parent::__construct(); |
|
21 | + } |
|
22 | + |
|
23 | + /** |
|
24 | + * Returns the score for a choice at $value. |
|
25 | + * |
|
26 | + * A sister method to {@see RGFormsModel::get_choice_text} |
|
27 | + * |
|
28 | + * @since 2.11 |
|
29 | + * |
|
30 | + * @param GF_Field_Likert $field |
|
31 | + * @param string|array $value |
|
32 | + * @param int|string $input_id ID of the field or input (for example, 7.3 or 7) |
|
33 | + * |
|
34 | + * @return mixed|string |
|
35 | + */ |
|
36 | + public static function get_choice_score($field, $value, $input_id = 0) |
|
37 | + { |
|
38 | + if (!$field->gsurveyLikertEnableScoring) { |
|
39 | + return ''; |
|
40 | + } |
|
41 | + |
|
42 | + if (!is_array($field->choices)) { |
|
43 | + return $value; |
|
44 | + } |
|
45 | + |
|
46 | + foreach ($field->choices as $choice) { |
|
47 | + if (is_array($value) && RGFormsModel::choice_value_match($field, $choice, $value[$input_id])) { |
|
48 | + return $choice['score']; |
|
49 | + } elseif (!is_array($value) && RGFormsModel::choice_value_match($field, $choice, $value)) { |
|
50 | + return $choice['score']; |
|
51 | + } |
|
52 | + } |
|
53 | + |
|
54 | + return is_array($value) ? '' : $value; |
|
55 | + } |
|
56 | + |
|
57 | + public function field_options($field_options, $template_id, $field_id, $context, $input_type, $form_id) |
|
58 | + { |
|
59 | + unset($field_options['search_filter']); |
|
60 | + |
|
61 | + if ('edit' === $context) { |
|
62 | + return $field_options; |
|
63 | + } |
|
64 | + |
|
65 | + $field = \GV\GF_Field::by_id(\GV\GF_Form::by_id($form_id), $field_id); |
|
66 | + $input_id = gravityview_get_input_id_from_id($field_id); |
|
67 | + $add_options = []; |
|
68 | + |
|
69 | + $glue = apply_filters('gravityview/template/field/survey/glue', '; '); |
|
70 | + $multiple_rows_suffix = sprintf(_x(' (separated by %s)', 'text added to a label if multiple rows are enabled for the field)', 'gravityview'), esc_html(trim($glue))); |
|
71 | + |
|
72 | + if ('likert' === $field->field->inputType) { |
|
73 | + $show_suffix = $input_id || empty($field->field->gsurveyLikertEnableMultipleRows); |
|
74 | + |
|
75 | + $likert_display_options = [ |
|
76 | + 'default' => __('A table (default Gravity Forms formatting)', 'gravityview'), |
|
77 | + 'text' => __('Text value of the selected choice', 'gravityview').($show_suffix ? '' : $multiple_rows_suffix), |
|
78 | + ]; |
|
79 | + |
|
80 | + if ($field->field->gsurveyLikertEnableScoring) { |
|
81 | + $likert_display_options['score'] = __('Score value of the selected choice', 'gravityview').($show_suffix ? '' : $multiple_rows_suffix); |
|
82 | + } |
|
83 | + |
|
84 | + // Maintain for back-compatibility |
|
85 | + $add_options['score'] = [ |
|
86 | + 'type' => 'hidden', |
|
87 | + 'value' => '', |
|
88 | + 'group' => 'display', |
|
89 | + ]; |
|
90 | + |
|
91 | + $add_options['choice_display'] = [ |
|
92 | + 'type' => 'radio', |
|
93 | + 'label' => __('What should be displayed:', 'gravityview'), |
|
94 | + 'options' => $likert_display_options, |
|
95 | + 'desc' => '', |
|
96 | + 'group' => 'display', |
|
97 | + 'class' => 'block', |
|
98 | + 'value' => 'default', |
|
99 | + 'merge_tags' => false, |
|
100 | + ]; |
|
101 | + } |
|
102 | + |
|
103 | + if ('checkbox' === $field->field->inputType && $input_id) { |
|
104 | + $field_options['choice_display'] = [ |
|
105 | + 'type' => 'radio', |
|
106 | + 'class' => 'vertical', |
|
107 | + 'label' => __('What should be displayed:', 'gravityview'), |
|
108 | + 'value' => 'tick', |
|
109 | + 'desc' => '', |
|
110 | + 'choices' => [ |
|
111 | + 'tick' => __('A check mark, if the input is checked', 'gravityview'), |
|
112 | + 'text' => __('Text value of the selected choice', 'gravityview'), |
|
113 | + ], |
|
114 | + 'group' => 'display', |
|
115 | + 'priority' => 100, |
|
116 | + ]; |
|
117 | + } |
|
118 | + |
|
119 | + if ('rating' === $field->field->inputType) { |
|
120 | + $field_options['choice_display'] = [ |
|
121 | + 'type' => 'radio', |
|
122 | + 'class' => 'vertical', |
|
123 | + 'label' => __('What should be displayed:', 'gravityview'), |
|
124 | + 'value' => 'default', |
|
125 | + 'desc' => '', |
|
126 | + 'choices' => [ |
|
127 | + 'default' => __('Text value of the selected choice', 'gravityview'), |
|
128 | + 'stars' => __('Stars (default Gravity Forms formatting)', 'gravityview'), |
|
129 | + ], |
|
130 | + 'group' => 'display', |
|
131 | + 'priority' => 100, |
|
132 | + ]; |
|
133 | + } |
|
134 | + |
|
135 | + return $add_options + $field_options; |
|
136 | + } |
|
137 | 137 | } |
138 | 138 | |
139 | 139 | new GravityView_Field_Survey(); |
@@ -16,7 +16,7 @@ discard block |
||
16 | 16 | |
17 | 17 | public function __construct() |
18 | 18 | { |
19 | - $this->label = esc_html__('Survey', 'gravityview'); |
|
19 | + $this->label = esc_html__( 'Survey', 'gravityview' ); |
|
20 | 20 | parent::__construct(); |
21 | 21 | } |
22 | 22 | |
@@ -33,64 +33,64 @@ discard block |
||
33 | 33 | * |
34 | 34 | * @return mixed|string |
35 | 35 | */ |
36 | - public static function get_choice_score($field, $value, $input_id = 0) |
|
36 | + public static function get_choice_score( $field, $value, $input_id = 0 ) |
|
37 | 37 | { |
38 | - if (!$field->gsurveyLikertEnableScoring) { |
|
38 | + if ( ! $field->gsurveyLikertEnableScoring ) { |
|
39 | 39 | return ''; |
40 | 40 | } |
41 | 41 | |
42 | - if (!is_array($field->choices)) { |
|
42 | + if ( ! is_array( $field->choices ) ) { |
|
43 | 43 | return $value; |
44 | 44 | } |
45 | 45 | |
46 | - foreach ($field->choices as $choice) { |
|
47 | - if (is_array($value) && RGFormsModel::choice_value_match($field, $choice, $value[$input_id])) { |
|
48 | - return $choice['score']; |
|
49 | - } elseif (!is_array($value) && RGFormsModel::choice_value_match($field, $choice, $value)) { |
|
50 | - return $choice['score']; |
|
46 | + foreach ( $field->choices as $choice ) { |
|
47 | + if ( is_array( $value ) && RGFormsModel::choice_value_match( $field, $choice, $value[ $input_id ] ) ) { |
|
48 | + return $choice[ 'score' ]; |
|
49 | + } elseif ( ! is_array( $value ) && RGFormsModel::choice_value_match( $field, $choice, $value ) ) { |
|
50 | + return $choice[ 'score' ]; |
|
51 | 51 | } |
52 | 52 | } |
53 | 53 | |
54 | - return is_array($value) ? '' : $value; |
|
54 | + return is_array( $value ) ? '' : $value; |
|
55 | 55 | } |
56 | 56 | |
57 | - public function field_options($field_options, $template_id, $field_id, $context, $input_type, $form_id) |
|
57 | + public function field_options( $field_options, $template_id, $field_id, $context, $input_type, $form_id ) |
|
58 | 58 | { |
59 | - unset($field_options['search_filter']); |
|
59 | + unset( $field_options[ 'search_filter' ] ); |
|
60 | 60 | |
61 | - if ('edit' === $context) { |
|
61 | + if ( 'edit' === $context ) { |
|
62 | 62 | return $field_options; |
63 | 63 | } |
64 | 64 | |
65 | - $field = \GV\GF_Field::by_id(\GV\GF_Form::by_id($form_id), $field_id); |
|
66 | - $input_id = gravityview_get_input_id_from_id($field_id); |
|
67 | - $add_options = []; |
|
65 | + $field = \GV\GF_Field::by_id( \GV\GF_Form::by_id( $form_id ), $field_id ); |
|
66 | + $input_id = gravityview_get_input_id_from_id( $field_id ); |
|
67 | + $add_options = [ ]; |
|
68 | 68 | |
69 | - $glue = apply_filters('gravityview/template/field/survey/glue', '; '); |
|
70 | - $multiple_rows_suffix = sprintf(_x(' (separated by %s)', 'text added to a label if multiple rows are enabled for the field)', 'gravityview'), esc_html(trim($glue))); |
|
69 | + $glue = apply_filters( 'gravityview/template/field/survey/glue', '; ' ); |
|
70 | + $multiple_rows_suffix = sprintf( _x( ' (separated by %s)', 'text added to a label if multiple rows are enabled for the field)', 'gravityview' ), esc_html( trim( $glue ) ) ); |
|
71 | 71 | |
72 | - if ('likert' === $field->field->inputType) { |
|
73 | - $show_suffix = $input_id || empty($field->field->gsurveyLikertEnableMultipleRows); |
|
72 | + if ( 'likert' === $field->field->inputType ) { |
|
73 | + $show_suffix = $input_id || empty( $field->field->gsurveyLikertEnableMultipleRows ); |
|
74 | 74 | |
75 | 75 | $likert_display_options = [ |
76 | - 'default' => __('A table (default Gravity Forms formatting)', 'gravityview'), |
|
77 | - 'text' => __('Text value of the selected choice', 'gravityview').($show_suffix ? '' : $multiple_rows_suffix), |
|
76 | + 'default' => __( 'A table (default Gravity Forms formatting)', 'gravityview' ), |
|
77 | + 'text' => __( 'Text value of the selected choice', 'gravityview' ) . ( $show_suffix ? '' : $multiple_rows_suffix ), |
|
78 | 78 | ]; |
79 | 79 | |
80 | - if ($field->field->gsurveyLikertEnableScoring) { |
|
81 | - $likert_display_options['score'] = __('Score value of the selected choice', 'gravityview').($show_suffix ? '' : $multiple_rows_suffix); |
|
80 | + if ( $field->field->gsurveyLikertEnableScoring ) { |
|
81 | + $likert_display_options[ 'score' ] = __( 'Score value of the selected choice', 'gravityview' ) . ( $show_suffix ? '' : $multiple_rows_suffix ); |
|
82 | 82 | } |
83 | 83 | |
84 | 84 | // Maintain for back-compatibility |
85 | - $add_options['score'] = [ |
|
85 | + $add_options[ 'score' ] = [ |
|
86 | 86 | 'type' => 'hidden', |
87 | 87 | 'value' => '', |
88 | 88 | 'group' => 'display', |
89 | 89 | ]; |
90 | 90 | |
91 | - $add_options['choice_display'] = [ |
|
91 | + $add_options[ 'choice_display' ] = [ |
|
92 | 92 | 'type' => 'radio', |
93 | - 'label' => __('What should be displayed:', 'gravityview'), |
|
93 | + 'label' => __( 'What should be displayed:', 'gravityview' ), |
|
94 | 94 | 'options' => $likert_display_options, |
95 | 95 | 'desc' => '', |
96 | 96 | 'group' => 'display', |
@@ -100,32 +100,32 @@ discard block |
||
100 | 100 | ]; |
101 | 101 | } |
102 | 102 | |
103 | - if ('checkbox' === $field->field->inputType && $input_id) { |
|
104 | - $field_options['choice_display'] = [ |
|
103 | + if ( 'checkbox' === $field->field->inputType && $input_id ) { |
|
104 | + $field_options[ 'choice_display' ] = [ |
|
105 | 105 | 'type' => 'radio', |
106 | 106 | 'class' => 'vertical', |
107 | - 'label' => __('What should be displayed:', 'gravityview'), |
|
107 | + 'label' => __( 'What should be displayed:', 'gravityview' ), |
|
108 | 108 | 'value' => 'tick', |
109 | 109 | 'desc' => '', |
110 | 110 | 'choices' => [ |
111 | - 'tick' => __('A check mark, if the input is checked', 'gravityview'), |
|
112 | - 'text' => __('Text value of the selected choice', 'gravityview'), |
|
111 | + 'tick' => __( 'A check mark, if the input is checked', 'gravityview' ), |
|
112 | + 'text' => __( 'Text value of the selected choice', 'gravityview' ), |
|
113 | 113 | ], |
114 | 114 | 'group' => 'display', |
115 | 115 | 'priority' => 100, |
116 | 116 | ]; |
117 | 117 | } |
118 | 118 | |
119 | - if ('rating' === $field->field->inputType) { |
|
120 | - $field_options['choice_display'] = [ |
|
119 | + if ( 'rating' === $field->field->inputType ) { |
|
120 | + $field_options[ 'choice_display' ] = [ |
|
121 | 121 | 'type' => 'radio', |
122 | 122 | 'class' => 'vertical', |
123 | - 'label' => __('What should be displayed:', 'gravityview'), |
|
123 | + 'label' => __( 'What should be displayed:', 'gravityview' ), |
|
124 | 124 | 'value' => 'default', |
125 | 125 | 'desc' => '', |
126 | 126 | 'choices' => [ |
127 | - 'default' => __('Text value of the selected choice', 'gravityview'), |
|
128 | - 'stars' => __('Stars (default Gravity Forms formatting)', 'gravityview'), |
|
127 | + 'default' => __( 'Text value of the selected choice', 'gravityview' ), |
|
128 | + 'stars' => __( 'Stars (default Gravity Forms formatting)', 'gravityview' ), |
|
129 | 129 | ], |
130 | 130 | 'group' => 'display', |
131 | 131 | 'priority' => 100, |
@@ -2,8 +2,7 @@ discard block |
||
2 | 2 | /** |
3 | 3 | * @file class-gravityview-field-survey.php |
4 | 4 | */ |
5 | -class GravityView_Field_Survey extends GravityView_Field |
|
6 | -{ |
|
5 | +class GravityView_Field_Survey extends GravityView_Field { |
|
7 | 6 | public $name = 'survey'; |
8 | 7 | |
9 | 8 | public $_gf_field_class_name = 'GF_Field_Survey'; |
@@ -14,8 +13,7 @@ discard block |
||
14 | 13 | |
15 | 14 | public $icon = 'dashicons-forms'; |
16 | 15 | |
17 | - public function __construct() |
|
18 | - { |
|
16 | + public function __construct() { |
|
19 | 17 | $this->label = esc_html__('Survey', 'gravityview'); |
20 | 18 | parent::__construct(); |
21 | 19 | } |
@@ -33,8 +31,7 @@ discard block |
||
33 | 31 | * |
34 | 32 | * @return mixed|string |
35 | 33 | */ |
36 | - public static function get_choice_score($field, $value, $input_id = 0) |
|
37 | - { |
|
34 | + public static function get_choice_score($field, $value, $input_id = 0) { |
|
38 | 35 | if (!$field->gsurveyLikertEnableScoring) { |
39 | 36 | return ''; |
40 | 37 | } |
@@ -54,8 +51,7 @@ discard block |
||
54 | 51 | return is_array($value) ? '' : $value; |
55 | 52 | } |
56 | 53 | |
57 | - public function field_options($field_options, $template_id, $field_id, $context, $input_type, $form_id) |
|
58 | - { |
|
54 | + public function field_options($field_options, $template_id, $field_id, $context, $input_type, $form_id) { |
|
59 | 55 | unset($field_options['search_filter']); |
60 | 56 | |
61 | 57 | if ('edit' === $context) { |
@@ -8,68 +8,68 @@ |
||
8 | 8 | */ |
9 | 9 | class GravityView_Field_Website extends GravityView_Field |
10 | 10 | { |
11 | - public $name = 'website'; |
|
12 | - |
|
13 | - public $is_searchable = true; |
|
14 | - |
|
15 | - public $search_operators = ['is', 'isnot', 'contains', 'starts_with', 'ends_with']; |
|
16 | - |
|
17 | - /** @see GF_Field_Website */ |
|
18 | - public $_gf_field_class_name = 'GF_Field_Website'; |
|
19 | - |
|
20 | - public $group = 'advanced'; |
|
21 | - |
|
22 | - public $icon = 'dashicons-admin-links'; |
|
23 | - |
|
24 | - public function __construct() |
|
25 | - { |
|
26 | - $this->label = esc_html__('Website', 'gravityview'); |
|
27 | - parent::__construct(); |
|
28 | - } |
|
29 | - |
|
30 | - public function field_options($field_options, $template_id, $field_id, $context, $input_type, $form_id) |
|
31 | - { |
|
32 | - |
|
33 | - // It makes no sense to use this as the link. |
|
34 | - unset($field_options['show_as_link']); |
|
35 | - |
|
36 | - if ('edit' === $context) { |
|
37 | - return $field_options; |
|
38 | - } |
|
39 | - |
|
40 | - /** |
|
41 | - * @since 1.8 |
|
42 | - */ |
|
43 | - $field_options['anchor_text'] = [ |
|
44 | - 'type' => 'text', |
|
45 | - 'label' => __('Link Text:', 'gravityview'), |
|
46 | - 'desc' => __('Define custom link text. Leave blank to display the URL', 'gravityview'), |
|
47 | - 'value' => '', |
|
48 | - 'merge_tags' => 'force', |
|
49 | - 'priority' => 1000, |
|
50 | - ]; |
|
51 | - |
|
52 | - $field_options['truncatelink'] = [ |
|
53 | - 'type' => 'checkbox', |
|
54 | - 'value' => true, |
|
55 | - 'label' => __('Shorten Link Display', 'gravityview'), |
|
56 | - 'tooltip' => __('Only show the domain for a URL instead of the whole link.', 'gravityview'), |
|
57 | - 'desc' => __('Don’t show the full URL, only show the domain.', 'gravityview'), |
|
58 | - 'priority' => 1500, |
|
59 | - ]; |
|
60 | - |
|
61 | - $this->add_field_support('new_window', $field_options); |
|
62 | - |
|
63 | - /** |
|
64 | - * Set default to opening in new links for back-compatibility with Version 1.5.1. |
|
65 | - * |
|
66 | - * @link https://github.com/gravityview/GravityView/commit/e12e76e2d032754227728d41e65103042d4f75ec |
|
67 | - */ |
|
68 | - $field_options['new_window']['value'] = true; |
|
69 | - $field_options['new_window']['priority'] = 2000; |
|
70 | - |
|
71 | - return $field_options; |
|
72 | - } |
|
11 | + public $name = 'website'; |
|
12 | + |
|
13 | + public $is_searchable = true; |
|
14 | + |
|
15 | + public $search_operators = ['is', 'isnot', 'contains', 'starts_with', 'ends_with']; |
|
16 | + |
|
17 | + /** @see GF_Field_Website */ |
|
18 | + public $_gf_field_class_name = 'GF_Field_Website'; |
|
19 | + |
|
20 | + public $group = 'advanced'; |
|
21 | + |
|
22 | + public $icon = 'dashicons-admin-links'; |
|
23 | + |
|
24 | + public function __construct() |
|
25 | + { |
|
26 | + $this->label = esc_html__('Website', 'gravityview'); |
|
27 | + parent::__construct(); |
|
28 | + } |
|
29 | + |
|
30 | + public function field_options($field_options, $template_id, $field_id, $context, $input_type, $form_id) |
|
31 | + { |
|
32 | + |
|
33 | + // It makes no sense to use this as the link. |
|
34 | + unset($field_options['show_as_link']); |
|
35 | + |
|
36 | + if ('edit' === $context) { |
|
37 | + return $field_options; |
|
38 | + } |
|
39 | + |
|
40 | + /** |
|
41 | + * @since 1.8 |
|
42 | + */ |
|
43 | + $field_options['anchor_text'] = [ |
|
44 | + 'type' => 'text', |
|
45 | + 'label' => __('Link Text:', 'gravityview'), |
|
46 | + 'desc' => __('Define custom link text. Leave blank to display the URL', 'gravityview'), |
|
47 | + 'value' => '', |
|
48 | + 'merge_tags' => 'force', |
|
49 | + 'priority' => 1000, |
|
50 | + ]; |
|
51 | + |
|
52 | + $field_options['truncatelink'] = [ |
|
53 | + 'type' => 'checkbox', |
|
54 | + 'value' => true, |
|
55 | + 'label' => __('Shorten Link Display', 'gravityview'), |
|
56 | + 'tooltip' => __('Only show the domain for a URL instead of the whole link.', 'gravityview'), |
|
57 | + 'desc' => __('Don’t show the full URL, only show the domain.', 'gravityview'), |
|
58 | + 'priority' => 1500, |
|
59 | + ]; |
|
60 | + |
|
61 | + $this->add_field_support('new_window', $field_options); |
|
62 | + |
|
63 | + /** |
|
64 | + * Set default to opening in new links for back-compatibility with Version 1.5.1. |
|
65 | + * |
|
66 | + * @link https://github.com/gravityview/GravityView/commit/e12e76e2d032754227728d41e65103042d4f75ec |
|
67 | + */ |
|
68 | + $field_options['new_window']['value'] = true; |
|
69 | + $field_options['new_window']['priority'] = 2000; |
|
70 | + |
|
71 | + return $field_options; |
|
72 | + } |
|
73 | 73 | } |
74 | 74 | |
75 | 75 | new GravityView_Field_Website(); |
@@ -12,7 +12,7 @@ discard block |
||
12 | 12 | |
13 | 13 | public $is_searchable = true; |
14 | 14 | |
15 | - public $search_operators = ['is', 'isnot', 'contains', 'starts_with', 'ends_with']; |
|
15 | + public $search_operators = [ 'is', 'isnot', 'contains', 'starts_with', 'ends_with' ]; |
|
16 | 16 | |
17 | 17 | /** @see GF_Field_Website */ |
18 | 18 | public $_gf_field_class_name = 'GF_Field_Website'; |
@@ -23,50 +23,50 @@ discard block |
||
23 | 23 | |
24 | 24 | public function __construct() |
25 | 25 | { |
26 | - $this->label = esc_html__('Website', 'gravityview'); |
|
26 | + $this->label = esc_html__( 'Website', 'gravityview' ); |
|
27 | 27 | parent::__construct(); |
28 | 28 | } |
29 | 29 | |
30 | - public function field_options($field_options, $template_id, $field_id, $context, $input_type, $form_id) |
|
30 | + public function field_options( $field_options, $template_id, $field_id, $context, $input_type, $form_id ) |
|
31 | 31 | { |
32 | 32 | |
33 | 33 | // It makes no sense to use this as the link. |
34 | - unset($field_options['show_as_link']); |
|
34 | + unset( $field_options[ 'show_as_link' ] ); |
|
35 | 35 | |
36 | - if ('edit' === $context) { |
|
36 | + if ( 'edit' === $context ) { |
|
37 | 37 | return $field_options; |
38 | 38 | } |
39 | 39 | |
40 | 40 | /** |
41 | 41 | * @since 1.8 |
42 | 42 | */ |
43 | - $field_options['anchor_text'] = [ |
|
43 | + $field_options[ 'anchor_text' ] = [ |
|
44 | 44 | 'type' => 'text', |
45 | - 'label' => __('Link Text:', 'gravityview'), |
|
46 | - 'desc' => __('Define custom link text. Leave blank to display the URL', 'gravityview'), |
|
45 | + 'label' => __( 'Link Text:', 'gravityview' ), |
|
46 | + 'desc' => __( 'Define custom link text. Leave blank to display the URL', 'gravityview' ), |
|
47 | 47 | 'value' => '', |
48 | 48 | 'merge_tags' => 'force', |
49 | 49 | 'priority' => 1000, |
50 | 50 | ]; |
51 | 51 | |
52 | - $field_options['truncatelink'] = [ |
|
52 | + $field_options[ 'truncatelink' ] = [ |
|
53 | 53 | 'type' => 'checkbox', |
54 | 54 | 'value' => true, |
55 | - 'label' => __('Shorten Link Display', 'gravityview'), |
|
56 | - 'tooltip' => __('Only show the domain for a URL instead of the whole link.', 'gravityview'), |
|
57 | - 'desc' => __('Don’t show the full URL, only show the domain.', 'gravityview'), |
|
55 | + 'label' => __( 'Shorten Link Display', 'gravityview' ), |
|
56 | + 'tooltip' => __( 'Only show the domain for a URL instead of the whole link.', 'gravityview' ), |
|
57 | + 'desc' => __( 'Don’t show the full URL, only show the domain.', 'gravityview' ), |
|
58 | 58 | 'priority' => 1500, |
59 | 59 | ]; |
60 | 60 | |
61 | - $this->add_field_support('new_window', $field_options); |
|
61 | + $this->add_field_support( 'new_window', $field_options ); |
|
62 | 62 | |
63 | 63 | /** |
64 | 64 | * Set default to opening in new links for back-compatibility with Version 1.5.1. |
65 | 65 | * |
66 | 66 | * @link https://github.com/gravityview/GravityView/commit/e12e76e2d032754227728d41e65103042d4f75ec |
67 | 67 | */ |
68 | - $field_options['new_window']['value'] = true; |
|
69 | - $field_options['new_window']['priority'] = 2000; |
|
68 | + $field_options[ 'new_window' ][ 'value' ] = true; |
|
69 | + $field_options[ 'new_window' ][ 'priority' ] = 2000; |
|
70 | 70 | |
71 | 71 | return $field_options; |
72 | 72 | } |
@@ -6,8 +6,7 @@ discard block |
||
6 | 6 | /** |
7 | 7 | * Add custom options for date fields. |
8 | 8 | */ |
9 | -class GravityView_Field_Website extends GravityView_Field |
|
10 | -{ |
|
9 | +class GravityView_Field_Website extends GravityView_Field { |
|
11 | 10 | public $name = 'website'; |
12 | 11 | |
13 | 12 | public $is_searchable = true; |
@@ -21,14 +20,12 @@ discard block |
||
21 | 20 | |
22 | 21 | public $icon = 'dashicons-admin-links'; |
23 | 22 | |
24 | - public function __construct() |
|
25 | - { |
|
23 | + public function __construct() { |
|
26 | 24 | $this->label = esc_html__('Website', 'gravityview'); |
27 | 25 | parent::__construct(); |
28 | 26 | } |
29 | 27 | |
30 | - public function field_options($field_options, $template_id, $field_id, $context, $input_type, $form_id) |
|
31 | - { |
|
28 | + public function field_options($field_options, $template_id, $field_id, $context, $input_type, $form_id) { |
|
32 | 29 | |
33 | 30 | // It makes no sense to use this as the link. |
34 | 31 | unset($field_options['show_as_link']); |
@@ -8,143 +8,143 @@ |
||
8 | 8 | */ |
9 | 9 | class GravityView_Field_Post_Image extends GravityView_Field |
10 | 10 | { |
11 | - public $name = 'post_image'; |
|
12 | - |
|
13 | - public $_gf_field_class_name = 'GF_Field_Post_Image'; |
|
14 | - |
|
15 | - public $group = 'post'; |
|
16 | - |
|
17 | - public $icon = 'dashicons-format-image'; |
|
18 | - |
|
19 | - public function __construct() |
|
20 | - { |
|
21 | - $this->label = esc_html__('Post Image', 'gravityview'); |
|
22 | - parent::__construct(); |
|
23 | - } |
|
24 | - |
|
25 | - public function field_options($field_options, $template_id, $field_id, $context, $input_type, $form_id) |
|
26 | - { |
|
27 | - unset($field_options['search_filter']); |
|
28 | - |
|
29 | - if ('edit' === $context) { |
|
30 | - return $field_options; |
|
31 | - } |
|
32 | - |
|
33 | - $this->add_field_support('link_to_post', $field_options); |
|
34 | - |
|
35 | - // @since 1.5.4 |
|
36 | - $this->add_field_support('dynamic_data', $field_options); |
|
37 | - |
|
38 | - return $field_options; |
|
39 | - } |
|
40 | - |
|
41 | - /** |
|
42 | - * Convert Gravity Forms `|:|`-separated image data into an array. |
|
43 | - * |
|
44 | - * If passed something other than a string, returns the passed value. |
|
45 | - * |
|
46 | - * @since 1.16.2 |
|
47 | - * @since 1.19.2 Converted from private to static public method |
|
48 | - * |
|
49 | - * @param string $value The stored value of an image, impoded with `|:|` values |
|
50 | - * |
|
51 | - * @return array with `url`, `title`, `caption` and `description` values |
|
52 | - */ |
|
53 | - public static function explode_value($value) |
|
54 | - { |
|
55 | - |
|
56 | - // Already is an array, perhaps? |
|
57 | - if (!is_string($value)) { |
|
58 | - return $value; |
|
59 | - } |
|
60 | - |
|
61 | - $url = $title = $caption = $description = ''; |
|
62 | - |
|
63 | - // If there's a |:| match, process. Otherwise, empty array! |
|
64 | - if (preg_match('/\|\:\|/', $value)) { |
|
65 | - list($url, $title, $caption, $description) = array_pad(explode('|:|', $value), 4, false); |
|
66 | - } |
|
67 | - |
|
68 | - return [ |
|
69 | - 'url' => $url, |
|
70 | - 'title' => $title, |
|
71 | - 'caption' => $caption, |
|
72 | - 'description' => $description, |
|
73 | - ]; |
|
74 | - } |
|
75 | - |
|
76 | - /** |
|
77 | - * Returns the field inner markup. |
|
78 | - * |
|
79 | - * Overriding GF_Field_Post_Image is necessary because they don't check for existing post image values, because |
|
80 | - * GF only creates, not updates. |
|
81 | - * |
|
82 | - * @since 1.16.2 |
|
83 | - * |
|
84 | - * @param array $form The Form Object currently being processed. |
|
85 | - * @param string|array $value The field value. From default/dynamic population, $_POST, or a resumed incomplete submission. |
|
86 | - * @param null|array $entry Null or the Entry Object currently being edited. |
|
87 | - * @param GF_Field_Post_Image $field |
|
88 | - * |
|
89 | - * @return string |
|
90 | - */ |
|
91 | - public function get_field_input($form, $value = '', $entry = null, GF_Field_Post_Image $field) |
|
92 | - { |
|
93 | - $id = (int) $field->id; |
|
94 | - $form_id = $form['id']; |
|
95 | - $input_name = "input_{$id}"; |
|
96 | - $field_id = sprintf('input_%d_%d', $form_id, $id); |
|
97 | - $img_name = null; |
|
98 | - |
|
99 | - // Convert |:| to associative array |
|
100 | - $img_array = self::explode_value($value); |
|
101 | - |
|
102 | - if (!empty($img_array['url'])) { |
|
103 | - $img_name = basename($img_array['url']); |
|
104 | - |
|
105 | - /** |
|
106 | - * Set the $uploaded_files value so that the .ginput_preview renders, and the file upload is hidden. |
|
107 | - * |
|
108 | - * @see GF_Field_Post_Image::get_field_input See the `<span class='ginput_preview'>` code |
|
109 | - * @see GFFormsModel::get_temp_filename See the `rgget( $input_name, self::$uploaded_files[ $form_id ] );` code |
|
110 | - */ |
|
111 | - if (empty(GFFormsModel::$uploaded_files[$form_id][$input_name])) { |
|
112 | - GFFormsModel::$uploaded_files[$form_id][$input_name] = $img_name; |
|
113 | - } |
|
114 | - } |
|
115 | - |
|
116 | - // Tell Gravity Forms we're not in the Admin |
|
117 | - add_filter('gform_is_entry_detail', '__return_false'); |
|
118 | - add_filter('gform_is_form_editor', '__return_false'); |
|
119 | - |
|
120 | - $input_value = [ |
|
121 | - "{$id}.1" => \GV\Utils::get($img_array, 'title'), |
|
122 | - "{$id}.4" => \GV\Utils::get($img_array, 'caption'), |
|
123 | - "{$id}.7" => \GV\Utils::get($img_array, 'description'), |
|
124 | - ]; |
|
125 | - |
|
126 | - // Get the field HTML output |
|
127 | - $gf_post_image_field_output = $field->get_field_input($form, $input_value); |
|
128 | - |
|
129 | - // Clean up our own filters |
|
130 | - remove_filter('gform_is_entry_detail', '__return_false'); |
|
131 | - remove_filter('gform_is_form_editor', '__return_false'); |
|
132 | - |
|
133 | - /** |
|
134 | - * Insert a hidden field into the output that is used to store the image URL. |
|
135 | - * |
|
136 | - * @var string $current_file We need to have a reference of whether same file is being updated, or user wants to remove the image. |
|
137 | - * |
|
138 | - * @see \GravityView_Edit_Entry_Render::maybe_update_post_fields |
|
139 | - * @hack |
|
140 | - */ |
|
141 | - if (null !== $img_name) { |
|
142 | - $current_file = sprintf("<input name='%s' id='%s' type='hidden' value='%s' />", $input_name, $field_id, esc_url_raw($img_array['url'])); |
|
143 | - $gf_post_image_field_output = str_replace('<span class=\'ginput_preview\'>', '<span class=\'ginput_preview\'>'.$current_file, $gf_post_image_field_output); |
|
144 | - } |
|
145 | - |
|
146 | - return $gf_post_image_field_output; |
|
147 | - } |
|
11 | + public $name = 'post_image'; |
|
12 | + |
|
13 | + public $_gf_field_class_name = 'GF_Field_Post_Image'; |
|
14 | + |
|
15 | + public $group = 'post'; |
|
16 | + |
|
17 | + public $icon = 'dashicons-format-image'; |
|
18 | + |
|
19 | + public function __construct() |
|
20 | + { |
|
21 | + $this->label = esc_html__('Post Image', 'gravityview'); |
|
22 | + parent::__construct(); |
|
23 | + } |
|
24 | + |
|
25 | + public function field_options($field_options, $template_id, $field_id, $context, $input_type, $form_id) |
|
26 | + { |
|
27 | + unset($field_options['search_filter']); |
|
28 | + |
|
29 | + if ('edit' === $context) { |
|
30 | + return $field_options; |
|
31 | + } |
|
32 | + |
|
33 | + $this->add_field_support('link_to_post', $field_options); |
|
34 | + |
|
35 | + // @since 1.5.4 |
|
36 | + $this->add_field_support('dynamic_data', $field_options); |
|
37 | + |
|
38 | + return $field_options; |
|
39 | + } |
|
40 | + |
|
41 | + /** |
|
42 | + * Convert Gravity Forms `|:|`-separated image data into an array. |
|
43 | + * |
|
44 | + * If passed something other than a string, returns the passed value. |
|
45 | + * |
|
46 | + * @since 1.16.2 |
|
47 | + * @since 1.19.2 Converted from private to static public method |
|
48 | + * |
|
49 | + * @param string $value The stored value of an image, impoded with `|:|` values |
|
50 | + * |
|
51 | + * @return array with `url`, `title`, `caption` and `description` values |
|
52 | + */ |
|
53 | + public static function explode_value($value) |
|
54 | + { |
|
55 | + |
|
56 | + // Already is an array, perhaps? |
|
57 | + if (!is_string($value)) { |
|
58 | + return $value; |
|
59 | + } |
|
60 | + |
|
61 | + $url = $title = $caption = $description = ''; |
|
62 | + |
|
63 | + // If there's a |:| match, process. Otherwise, empty array! |
|
64 | + if (preg_match('/\|\:\|/', $value)) { |
|
65 | + list($url, $title, $caption, $description) = array_pad(explode('|:|', $value), 4, false); |
|
66 | + } |
|
67 | + |
|
68 | + return [ |
|
69 | + 'url' => $url, |
|
70 | + 'title' => $title, |
|
71 | + 'caption' => $caption, |
|
72 | + 'description' => $description, |
|
73 | + ]; |
|
74 | + } |
|
75 | + |
|
76 | + /** |
|
77 | + * Returns the field inner markup. |
|
78 | + * |
|
79 | + * Overriding GF_Field_Post_Image is necessary because they don't check for existing post image values, because |
|
80 | + * GF only creates, not updates. |
|
81 | + * |
|
82 | + * @since 1.16.2 |
|
83 | + * |
|
84 | + * @param array $form The Form Object currently being processed. |
|
85 | + * @param string|array $value The field value. From default/dynamic population, $_POST, or a resumed incomplete submission. |
|
86 | + * @param null|array $entry Null or the Entry Object currently being edited. |
|
87 | + * @param GF_Field_Post_Image $field |
|
88 | + * |
|
89 | + * @return string |
|
90 | + */ |
|
91 | + public function get_field_input($form, $value = '', $entry = null, GF_Field_Post_Image $field) |
|
92 | + { |
|
93 | + $id = (int) $field->id; |
|
94 | + $form_id = $form['id']; |
|
95 | + $input_name = "input_{$id}"; |
|
96 | + $field_id = sprintf('input_%d_%d', $form_id, $id); |
|
97 | + $img_name = null; |
|
98 | + |
|
99 | + // Convert |:| to associative array |
|
100 | + $img_array = self::explode_value($value); |
|
101 | + |
|
102 | + if (!empty($img_array['url'])) { |
|
103 | + $img_name = basename($img_array['url']); |
|
104 | + |
|
105 | + /** |
|
106 | + * Set the $uploaded_files value so that the .ginput_preview renders, and the file upload is hidden. |
|
107 | + * |
|
108 | + * @see GF_Field_Post_Image::get_field_input See the `<span class='ginput_preview'>` code |
|
109 | + * @see GFFormsModel::get_temp_filename See the `rgget( $input_name, self::$uploaded_files[ $form_id ] );` code |
|
110 | + */ |
|
111 | + if (empty(GFFormsModel::$uploaded_files[$form_id][$input_name])) { |
|
112 | + GFFormsModel::$uploaded_files[$form_id][$input_name] = $img_name; |
|
113 | + } |
|
114 | + } |
|
115 | + |
|
116 | + // Tell Gravity Forms we're not in the Admin |
|
117 | + add_filter('gform_is_entry_detail', '__return_false'); |
|
118 | + add_filter('gform_is_form_editor', '__return_false'); |
|
119 | + |
|
120 | + $input_value = [ |
|
121 | + "{$id}.1" => \GV\Utils::get($img_array, 'title'), |
|
122 | + "{$id}.4" => \GV\Utils::get($img_array, 'caption'), |
|
123 | + "{$id}.7" => \GV\Utils::get($img_array, 'description'), |
|
124 | + ]; |
|
125 | + |
|
126 | + // Get the field HTML output |
|
127 | + $gf_post_image_field_output = $field->get_field_input($form, $input_value); |
|
128 | + |
|
129 | + // Clean up our own filters |
|
130 | + remove_filter('gform_is_entry_detail', '__return_false'); |
|
131 | + remove_filter('gform_is_form_editor', '__return_false'); |
|
132 | + |
|
133 | + /** |
|
134 | + * Insert a hidden field into the output that is used to store the image URL. |
|
135 | + * |
|
136 | + * @var string $current_file We need to have a reference of whether same file is being updated, or user wants to remove the image. |
|
137 | + * |
|
138 | + * @see \GravityView_Edit_Entry_Render::maybe_update_post_fields |
|
139 | + * @hack |
|
140 | + */ |
|
141 | + if (null !== $img_name) { |
|
142 | + $current_file = sprintf("<input name='%s' id='%s' type='hidden' value='%s' />", $input_name, $field_id, esc_url_raw($img_array['url'])); |
|
143 | + $gf_post_image_field_output = str_replace('<span class=\'ginput_preview\'>', '<span class=\'ginput_preview\'>'.$current_file, $gf_post_image_field_output); |
|
144 | + } |
|
145 | + |
|
146 | + return $gf_post_image_field_output; |
|
147 | + } |
|
148 | 148 | } |
149 | 149 | |
150 | 150 | new GravityView_Field_Post_Image(); |
@@ -18,22 +18,22 @@ discard block |
||
18 | 18 | |
19 | 19 | public function __construct() |
20 | 20 | { |
21 | - $this->label = esc_html__('Post Image', 'gravityview'); |
|
21 | + $this->label = esc_html__( 'Post Image', 'gravityview' ); |
|
22 | 22 | parent::__construct(); |
23 | 23 | } |
24 | 24 | |
25 | - public function field_options($field_options, $template_id, $field_id, $context, $input_type, $form_id) |
|
25 | + public function field_options( $field_options, $template_id, $field_id, $context, $input_type, $form_id ) |
|
26 | 26 | { |
27 | - unset($field_options['search_filter']); |
|
27 | + unset( $field_options[ 'search_filter' ] ); |
|
28 | 28 | |
29 | - if ('edit' === $context) { |
|
29 | + if ( 'edit' === $context ) { |
|
30 | 30 | return $field_options; |
31 | 31 | } |
32 | 32 | |
33 | - $this->add_field_support('link_to_post', $field_options); |
|
33 | + $this->add_field_support( 'link_to_post', $field_options ); |
|
34 | 34 | |
35 | 35 | // @since 1.5.4 |
36 | - $this->add_field_support('dynamic_data', $field_options); |
|
36 | + $this->add_field_support( 'dynamic_data', $field_options ); |
|
37 | 37 | |
38 | 38 | return $field_options; |
39 | 39 | } |
@@ -50,19 +50,19 @@ discard block |
||
50 | 50 | * |
51 | 51 | * @return array with `url`, `title`, `caption` and `description` values |
52 | 52 | */ |
53 | - public static function explode_value($value) |
|
53 | + public static function explode_value( $value ) |
|
54 | 54 | { |
55 | 55 | |
56 | 56 | // Already is an array, perhaps? |
57 | - if (!is_string($value)) { |
|
57 | + if ( ! is_string( $value ) ) { |
|
58 | 58 | return $value; |
59 | 59 | } |
60 | 60 | |
61 | 61 | $url = $title = $caption = $description = ''; |
62 | 62 | |
63 | 63 | // If there's a |:| match, process. Otherwise, empty array! |
64 | - if (preg_match('/\|\:\|/', $value)) { |
|
65 | - list($url, $title, $caption, $description) = array_pad(explode('|:|', $value), 4, false); |
|
64 | + if ( preg_match( '/\|\:\|/', $value ) ) { |
|
65 | + list( $url, $title, $caption, $description ) = array_pad( explode( '|:|', $value ), 4, false ); |
|
66 | 66 | } |
67 | 67 | |
68 | 68 | return [ |
@@ -88,19 +88,19 @@ discard block |
||
88 | 88 | * |
89 | 89 | * @return string |
90 | 90 | */ |
91 | - public function get_field_input($form, $value = '', $entry = null, GF_Field_Post_Image $field) |
|
91 | + public function get_field_input( $form, $value = '', $entry = null, GF_Field_Post_Image $field ) |
|
92 | 92 | { |
93 | - $id = (int) $field->id; |
|
94 | - $form_id = $form['id']; |
|
93 | + $id = (int)$field->id; |
|
94 | + $form_id = $form[ 'id' ]; |
|
95 | 95 | $input_name = "input_{$id}"; |
96 | - $field_id = sprintf('input_%d_%d', $form_id, $id); |
|
96 | + $field_id = sprintf( 'input_%d_%d', $form_id, $id ); |
|
97 | 97 | $img_name = null; |
98 | 98 | |
99 | 99 | // Convert |:| to associative array |
100 | - $img_array = self::explode_value($value); |
|
100 | + $img_array = self::explode_value( $value ); |
|
101 | 101 | |
102 | - if (!empty($img_array['url'])) { |
|
103 | - $img_name = basename($img_array['url']); |
|
102 | + if ( ! empty( $img_array[ 'url' ] ) ) { |
|
103 | + $img_name = basename( $img_array[ 'url' ] ); |
|
104 | 104 | |
105 | 105 | /** |
106 | 106 | * Set the $uploaded_files value so that the .ginput_preview renders, and the file upload is hidden. |
@@ -108,27 +108,27 @@ discard block |
||
108 | 108 | * @see GF_Field_Post_Image::get_field_input See the `<span class='ginput_preview'>` code |
109 | 109 | * @see GFFormsModel::get_temp_filename See the `rgget( $input_name, self::$uploaded_files[ $form_id ] );` code |
110 | 110 | */ |
111 | - if (empty(GFFormsModel::$uploaded_files[$form_id][$input_name])) { |
|
112 | - GFFormsModel::$uploaded_files[$form_id][$input_name] = $img_name; |
|
111 | + if ( empty( GFFormsModel::$uploaded_files[ $form_id ][ $input_name ] ) ) { |
|
112 | + GFFormsModel::$uploaded_files[ $form_id ][ $input_name ] = $img_name; |
|
113 | 113 | } |
114 | 114 | } |
115 | 115 | |
116 | 116 | // Tell Gravity Forms we're not in the Admin |
117 | - add_filter('gform_is_entry_detail', '__return_false'); |
|
118 | - add_filter('gform_is_form_editor', '__return_false'); |
|
117 | + add_filter( 'gform_is_entry_detail', '__return_false' ); |
|
118 | + add_filter( 'gform_is_form_editor', '__return_false' ); |
|
119 | 119 | |
120 | 120 | $input_value = [ |
121 | - "{$id}.1" => \GV\Utils::get($img_array, 'title'), |
|
122 | - "{$id}.4" => \GV\Utils::get($img_array, 'caption'), |
|
123 | - "{$id}.7" => \GV\Utils::get($img_array, 'description'), |
|
121 | + "{$id}.1" => \GV\Utils::get( $img_array, 'title' ), |
|
122 | + "{$id}.4" => \GV\Utils::get( $img_array, 'caption' ), |
|
123 | + "{$id}.7" => \GV\Utils::get( $img_array, 'description' ), |
|
124 | 124 | ]; |
125 | 125 | |
126 | 126 | // Get the field HTML output |
127 | - $gf_post_image_field_output = $field->get_field_input($form, $input_value); |
|
127 | + $gf_post_image_field_output = $field->get_field_input( $form, $input_value ); |
|
128 | 128 | |
129 | 129 | // Clean up our own filters |
130 | - remove_filter('gform_is_entry_detail', '__return_false'); |
|
131 | - remove_filter('gform_is_form_editor', '__return_false'); |
|
130 | + remove_filter( 'gform_is_entry_detail', '__return_false' ); |
|
131 | + remove_filter( 'gform_is_form_editor', '__return_false' ); |
|
132 | 132 | |
133 | 133 | /** |
134 | 134 | * Insert a hidden field into the output that is used to store the image URL. |
@@ -138,9 +138,9 @@ discard block |
||
138 | 138 | * @see \GravityView_Edit_Entry_Render::maybe_update_post_fields |
139 | 139 | * @hack |
140 | 140 | */ |
141 | - if (null !== $img_name) { |
|
142 | - $current_file = sprintf("<input name='%s' id='%s' type='hidden' value='%s' />", $input_name, $field_id, esc_url_raw($img_array['url'])); |
|
143 | - $gf_post_image_field_output = str_replace('<span class=\'ginput_preview\'>', '<span class=\'ginput_preview\'>'.$current_file, $gf_post_image_field_output); |
|
141 | + if ( null !== $img_name ) { |
|
142 | + $current_file = sprintf( "<input name='%s' id='%s' type='hidden' value='%s' />", $input_name, $field_id, esc_url_raw( $img_array[ 'url' ] ) ); |
|
143 | + $gf_post_image_field_output = str_replace( '<span class=\'ginput_preview\'>', '<span class=\'ginput_preview\'>' . $current_file, $gf_post_image_field_output ); |
|
144 | 144 | } |
145 | 145 | |
146 | 146 | return $gf_post_image_field_output; |
@@ -6,8 +6,7 @@ discard block |
||
6 | 6 | /** |
7 | 7 | * Add custom options for Post Image fields. |
8 | 8 | */ |
9 | -class GravityView_Field_Post_Image extends GravityView_Field |
|
10 | -{ |
|
9 | +class GravityView_Field_Post_Image extends GravityView_Field { |
|
11 | 10 | public $name = 'post_image'; |
12 | 11 | |
13 | 12 | public $_gf_field_class_name = 'GF_Field_Post_Image'; |
@@ -16,14 +15,12 @@ discard block |
||
16 | 15 | |
17 | 16 | public $icon = 'dashicons-format-image'; |
18 | 17 | |
19 | - public function __construct() |
|
20 | - { |
|
18 | + public function __construct() { |
|
21 | 19 | $this->label = esc_html__('Post Image', 'gravityview'); |
22 | 20 | parent::__construct(); |
23 | 21 | } |
24 | 22 | |
25 | - public function field_options($field_options, $template_id, $field_id, $context, $input_type, $form_id) |
|
26 | - { |
|
23 | + public function field_options($field_options, $template_id, $field_id, $context, $input_type, $form_id) { |
|
27 | 24 | unset($field_options['search_filter']); |
28 | 25 | |
29 | 26 | if ('edit' === $context) { |
@@ -50,8 +47,7 @@ discard block |
||
50 | 47 | * |
51 | 48 | * @return array with `url`, `title`, `caption` and `description` values |
52 | 49 | */ |
53 | - public static function explode_value($value) |
|
54 | - { |
|
50 | + public static function explode_value($value) { |
|
55 | 51 | |
56 | 52 | // Already is an array, perhaps? |
57 | 53 | if (!is_string($value)) { |
@@ -88,8 +84,7 @@ discard block |
||
88 | 84 | * |
89 | 85 | * @return string |
90 | 86 | */ |
91 | - public function get_field_input($form, $value = '', $entry = null, GF_Field_Post_Image $field) |
|
92 | - { |
|
87 | + public function get_field_input($form, $value = '', $entry = null, GF_Field_Post_Image $field) { |
|
93 | 88 | $id = (int) $field->id; |
94 | 89 | $form_id = $form['id']; |
95 | 90 | $input_name = "input_{$id}"; |
@@ -4,64 +4,64 @@ |
||
4 | 4 | */ |
5 | 5 | class GravityView_Field_Select extends GravityView_Field |
6 | 6 | { |
7 | - public $name = 'select'; |
|
7 | + public $name = 'select'; |
|
8 | 8 | |
9 | - public $is_searchable = true; |
|
9 | + public $is_searchable = true; |
|
10 | 10 | |
11 | - /** |
|
12 | - * @see GFCommon::get_field_filter_settings |
|
13 | - * |
|
14 | - * @var array |
|
15 | - */ |
|
16 | - public $search_operators = ['is', 'isnot', 'contains']; |
|
11 | + /** |
|
12 | + * @see GFCommon::get_field_filter_settings |
|
13 | + * |
|
14 | + * @var array |
|
15 | + */ |
|
16 | + public $search_operators = ['is', 'isnot', 'contains']; |
|
17 | 17 | |
18 | - public $_gf_field_class_name = 'GF_Field_Select'; |
|
18 | + public $_gf_field_class_name = 'GF_Field_Select'; |
|
19 | 19 | |
20 | - public $group = 'standard'; |
|
20 | + public $group = 'standard'; |
|
21 | 21 | |
22 | - public $icon = 'dashicons-arrow-down'; |
|
22 | + public $icon = 'dashicons-arrow-down'; |
|
23 | 23 | |
24 | - public function __construct() |
|
25 | - { |
|
26 | - $this->label = esc_html__('Select', 'gravityview'); |
|
27 | - parent::__construct(); |
|
28 | - } |
|
24 | + public function __construct() |
|
25 | + { |
|
26 | + $this->label = esc_html__('Select', 'gravityview'); |
|
27 | + parent::__construct(); |
|
28 | + } |
|
29 | 29 | |
30 | - /** |
|
31 | - * Add `choice_display` setting to the field. |
|
32 | - * |
|
33 | - * @param array $field_options |
|
34 | - * @param string $template_id |
|
35 | - * @param string $field_id |
|
36 | - * @param string $context |
|
37 | - * @param string $input_type |
|
38 | - * |
|
39 | - * @since 1.17 |
|
40 | - * |
|
41 | - * @return array |
|
42 | - */ |
|
43 | - public function field_options($field_options, $template_id, $field_id, $context, $input_type, $form_id) |
|
44 | - { |
|
30 | + /** |
|
31 | + * Add `choice_display` setting to the field. |
|
32 | + * |
|
33 | + * @param array $field_options |
|
34 | + * @param string $template_id |
|
35 | + * @param string $field_id |
|
36 | + * @param string $context |
|
37 | + * @param string $input_type |
|
38 | + * |
|
39 | + * @since 1.17 |
|
40 | + * |
|
41 | + * @return array |
|
42 | + */ |
|
43 | + public function field_options($field_options, $template_id, $field_id, $context, $input_type, $form_id) |
|
44 | + { |
|
45 | 45 | |
46 | - // Set the $_field_id var |
|
47 | - $field_options = parent::field_options($field_options, $template_id, $field_id, $context, $input_type, $form_id); |
|
46 | + // Set the $_field_id var |
|
47 | + $field_options = parent::field_options($field_options, $template_id, $field_id, $context, $input_type, $form_id); |
|
48 | 48 | |
49 | - if ($this->is_choice_value_enabled()) { |
|
50 | - $field_options['choice_display'] = [ |
|
51 | - 'type' => 'radio', |
|
52 | - 'value' => 'value', |
|
53 | - 'label' => __('What should be displayed:', 'gravityview'), |
|
54 | - 'desc' => __('This input has a label and a value. What should be displayed?', 'gravityview'), |
|
55 | - 'choices' => [ |
|
56 | - 'value' => __('Value of the input', 'gravityview'), |
|
57 | - 'label' => __('Label of the input', 'gravityview'), |
|
58 | - ], |
|
59 | - 'group' => 'display', |
|
60 | - ]; |
|
61 | - } |
|
49 | + if ($this->is_choice_value_enabled()) { |
|
50 | + $field_options['choice_display'] = [ |
|
51 | + 'type' => 'radio', |
|
52 | + 'value' => 'value', |
|
53 | + 'label' => __('What should be displayed:', 'gravityview'), |
|
54 | + 'desc' => __('This input has a label and a value. What should be displayed?', 'gravityview'), |
|
55 | + 'choices' => [ |
|
56 | + 'value' => __('Value of the input', 'gravityview'), |
|
57 | + 'label' => __('Label of the input', 'gravityview'), |
|
58 | + ], |
|
59 | + 'group' => 'display', |
|
60 | + ]; |
|
61 | + } |
|
62 | 62 | |
63 | - return $field_options; |
|
64 | - } |
|
63 | + return $field_options; |
|
64 | + } |
|
65 | 65 | } |
66 | 66 | |
67 | 67 | new GravityView_Field_Select(); |
@@ -13,7 +13,7 @@ discard block |
||
13 | 13 | * |
14 | 14 | * @var array |
15 | 15 | */ |
16 | - public $search_operators = ['is', 'isnot', 'contains']; |
|
16 | + public $search_operators = [ 'is', 'isnot', 'contains' ]; |
|
17 | 17 | |
18 | 18 | public $_gf_field_class_name = 'GF_Field_Select'; |
19 | 19 | |
@@ -23,7 +23,7 @@ discard block |
||
23 | 23 | |
24 | 24 | public function __construct() |
25 | 25 | { |
26 | - $this->label = esc_html__('Select', 'gravityview'); |
|
26 | + $this->label = esc_html__( 'Select', 'gravityview' ); |
|
27 | 27 | parent::__construct(); |
28 | 28 | } |
29 | 29 | |
@@ -40,21 +40,21 @@ discard block |
||
40 | 40 | * |
41 | 41 | * @return array |
42 | 42 | */ |
43 | - public function field_options($field_options, $template_id, $field_id, $context, $input_type, $form_id) |
|
43 | + public function field_options( $field_options, $template_id, $field_id, $context, $input_type, $form_id ) |
|
44 | 44 | { |
45 | 45 | |
46 | 46 | // Set the $_field_id var |
47 | - $field_options = parent::field_options($field_options, $template_id, $field_id, $context, $input_type, $form_id); |
|
47 | + $field_options = parent::field_options( $field_options, $template_id, $field_id, $context, $input_type, $form_id ); |
|
48 | 48 | |
49 | - if ($this->is_choice_value_enabled()) { |
|
50 | - $field_options['choice_display'] = [ |
|
49 | + if ( $this->is_choice_value_enabled() ) { |
|
50 | + $field_options[ 'choice_display' ] = [ |
|
51 | 51 | 'type' => 'radio', |
52 | 52 | 'value' => 'value', |
53 | - 'label' => __('What should be displayed:', 'gravityview'), |
|
54 | - 'desc' => __('This input has a label and a value. What should be displayed?', 'gravityview'), |
|
53 | + 'label' => __( 'What should be displayed:', 'gravityview' ), |
|
54 | + 'desc' => __( 'This input has a label and a value. What should be displayed?', 'gravityview' ), |
|
55 | 55 | 'choices' => [ |
56 | - 'value' => __('Value of the input', 'gravityview'), |
|
57 | - 'label' => __('Label of the input', 'gravityview'), |
|
56 | + 'value' => __( 'Value of the input', 'gravityview' ), |
|
57 | + 'label' => __( 'Label of the input', 'gravityview' ), |
|
58 | 58 | ], |
59 | 59 | 'group' => 'display', |
60 | 60 | ]; |
@@ -2,8 +2,7 @@ discard block |
||
2 | 2 | /** |
3 | 3 | * @file class-gravityview-field-select.php |
4 | 4 | */ |
5 | -class GravityView_Field_Select extends GravityView_Field |
|
6 | -{ |
|
5 | +class GravityView_Field_Select extends GravityView_Field { |
|
7 | 6 | public $name = 'select'; |
8 | 7 | |
9 | 8 | public $is_searchable = true; |
@@ -21,8 +20,7 @@ discard block |
||
21 | 20 | |
22 | 21 | public $icon = 'dashicons-arrow-down'; |
23 | 22 | |
24 | - public function __construct() |
|
25 | - { |
|
23 | + public function __construct() { |
|
26 | 24 | $this->label = esc_html__('Select', 'gravityview'); |
27 | 25 | parent::__construct(); |
28 | 26 | } |
@@ -40,8 +38,7 @@ discard block |
||
40 | 38 | * |
41 | 39 | * @return array |
42 | 40 | */ |
43 | - public function field_options($field_options, $template_id, $field_id, $context, $input_type, $form_id) |
|
44 | - { |
|
41 | + public function field_options($field_options, $template_id, $field_id, $context, $input_type, $form_id) { |
|
45 | 42 | |
46 | 43 | // Set the $_field_id var |
47 | 44 | $field_options = parent::field_options($field_options, $template_id, $field_id, $context, $input_type, $form_id); |
@@ -6,271 +6,271 @@ |
||
6 | 6 | */ |
7 | 7 | class GravityView_Field_Unsubscribe extends GravityView_Field |
8 | 8 | { |
9 | - public $name = 'unsubscribe'; |
|
10 | - |
|
11 | - public $group = 'gravityview'; |
|
12 | - |
|
13 | - public $is_searchable = false; |
|
14 | - |
|
15 | - public $contexts = ['single', 'multiple']; |
|
16 | - |
|
17 | - public function __construct() |
|
18 | - { |
|
19 | - $this->label = esc_html__('Unsubscribe', 'gravityview'); |
|
20 | - $this->description = esc_attr__('Unsubscribe from a Payment-based entry.', 'gravityview'); |
|
21 | - |
|
22 | - $this->add_hooks(); |
|
23 | - |
|
24 | - parent::__construct(); |
|
25 | - } |
|
26 | - |
|
27 | - /** |
|
28 | - * Hooks called from constructor. |
|
29 | - * |
|
30 | - * @return void |
|
31 | - */ |
|
32 | - public function add_hooks() |
|
33 | - { |
|
34 | - add_filter('gravityview_entry_default_fields', [$this, 'filter_gravityview_entry_default_field'], 10, 3); |
|
35 | - |
|
36 | - add_filter('gravityview/field/is_visible', [$this, 'maybe_not_visible'], 10, 2); |
|
37 | - |
|
38 | - add_filter('gravityview_field_entry_value_unsubscribe', [$this, 'modify_entry_value_unsubscribe'], 10, 4); |
|
39 | - } |
|
40 | - |
|
41 | - /** |
|
42 | - * Configure the field options. |
|
43 | - * |
|
44 | - * Called from the `gravityview_entry_default_fields` filter. |
|
45 | - * |
|
46 | - * Remove the logged in, new window and show as link options. |
|
47 | - * Add the allow unsubscribe for all admins option. |
|
48 | - * |
|
49 | - * @param array $field_options The options. |
|
50 | - * @param string $template_id The template ID. |
|
51 | - * @param int|string|float $field_id The field ID. |
|
52 | - * @param string $context The configuration context (edit, single, etc.) |
|
53 | - * @param string $input_type The input type. |
|
54 | - * @param int $form_id The form ID. |
|
55 | - * |
|
56 | - * @return array The field options. |
|
57 | - */ |
|
58 | - public function field_options($field_options, $template_id, $field_id, $context, $input_type, $form_id) |
|
59 | - { |
|
60 | - unset($field_options['only_loggedin']); |
|
61 | - |
|
62 | - unset($field_options['new_window']); |
|
63 | - |
|
64 | - unset($field_options['show_as_link']); |
|
65 | - |
|
66 | - $add_options['unsub_all'] = [ |
|
67 | - 'type' => 'checkbox', |
|
68 | - 'label' => __('Allow admins to unsubscribe', 'gravityview'), |
|
69 | - 'desc' => __('Allow users with `gravityforms_edit_entries` to cancel subscriptions', 'gravityview'), |
|
70 | - 'value' => false, |
|
71 | - 'merge_tags' => false, |
|
72 | - ]; |
|
73 | - |
|
74 | - return $field_options + $add_options; |
|
75 | - } |
|
76 | - |
|
77 | - /** |
|
78 | - * Hide the field from the renderer. Perhaps. |
|
79 | - * |
|
80 | - * Called from `gravityview/field/is_visible` |
|
81 | - * |
|
82 | - * Hide the field for non-logged in users for sure. |
|
83 | - * |
|
84 | - * @param bool $visible Consider visible or not. |
|
85 | - * @param \GV\Field $field The field. |
|
86 | - * |
|
87 | - * @return bool Visible or not. |
|
88 | - */ |
|
89 | - public function maybe_not_visible($visible, $field) |
|
90 | - { |
|
91 | - if ($this->name !== $field->ID) { |
|
92 | - return $visible; |
|
93 | - } |
|
94 | - |
|
95 | - return is_user_logged_in() ? $visible : false; |
|
96 | - } |
|
97 | - |
|
98 | - /** |
|
99 | - * Add the unsubsribe to the configuration fields. |
|
100 | - * |
|
101 | - * Only if a subscription feed is active for the current form. |
|
102 | - * |
|
103 | - * Called from `gravityview_entry_default_fields` |
|
104 | - * |
|
105 | - * @param array $entry_default_fields An array of available for configuration |
|
106 | - * @param array|int $form Form ID or array |
|
107 | - * @param string $context The configuration context (edit, single, etc.) |
|
108 | - * |
|
109 | - * @return array The array of available default fields. |
|
110 | - */ |
|
111 | - public function filter_gravityview_entry_default_field($entry_default_fields, $form, $context) |
|
112 | - { |
|
113 | - if (is_array($form)) { |
|
114 | - return $entry_default_fields; |
|
115 | - } |
|
116 | - |
|
117 | - $feeds = GFAPI::get_feeds(null, $form); |
|
118 | - |
|
119 | - if (is_wp_error($feeds)) { |
|
120 | - return $entry_default_fields; |
|
121 | - } |
|
122 | - |
|
123 | - static $subscription_addons; |
|
124 | - |
|
125 | - if (is_null($subscription_addons)) { |
|
126 | - $registered = GFAddon::get_registered_addons(); |
|
127 | - |
|
128 | - foreach ($registered as $addon) { |
|
129 | - if (method_exists($addon, 'cancel_subscription') && is_callable([$addon, 'get_instance'])) { |
|
130 | - $addon = $addon::get_instance(); |
|
131 | - $subscription_addons[$addon->get_slug()] = $addon; |
|
132 | - } |
|
133 | - } |
|
134 | - } |
|
135 | - |
|
136 | - if (empty($subscription_addons)) { |
|
137 | - return $entry_default_fields; |
|
138 | - } |
|
139 | - |
|
140 | - foreach ($feeds as $feed) { |
|
141 | - if (isset($subscription_addons[$feed['addon_slug']]) && 'subscription' === \GV\Utils::get($feed, 'meta/transactionType')) { |
|
142 | - if (!isset($entry_default_fields["{$this->name}"]) && 'edit' !== $context) { |
|
143 | - $entry_default_fields["{$this->name}"] = [ |
|
144 | - 'label' => $this->label, |
|
145 | - 'desc' => $this->description, |
|
146 | - 'type' => $this->name, |
|
147 | - ]; |
|
148 | - |
|
149 | - break; // Feed found, field added |
|
150 | - } |
|
151 | - } |
|
152 | - } |
|
153 | - |
|
154 | - return $entry_default_fields; |
|
155 | - } |
|
156 | - |
|
157 | - /** |
|
158 | - * Modify the render content. |
|
159 | - * |
|
160 | - * Called from `gravityview_field_entry_value_unsubscribe` |
|
161 | - * |
|
162 | - * @param string $output The output. |
|
163 | - * @param array $entry The entry. |
|
164 | - * @param array $field_settings The field settings. |
|
165 | - * @param \GV\Field $field The field. |
|
166 | - * |
|
167 | - * @return string The content. |
|
168 | - */ |
|
169 | - public function modify_entry_value_unsubscribe($output, $entry, $field_settings, $field) |
|
170 | - { |
|
171 | - if (!is_user_logged_in() || !$entry) { |
|
172 | - return $output; |
|
173 | - } |
|
174 | - |
|
175 | - $can_current_user_edit = is_numeric($entry['created_by']) && (wp_get_current_user()->ID === intval($entry['created_by'])); |
|
176 | - |
|
177 | - if (!$can_current_user_edit) { |
|
178 | - if (empty($field_settings['unsub_all']) || !\GVCommon::has_cap('gravityforms_edit_entries', $entry['id'])) { |
|
179 | - return $output; |
|
180 | - } |
|
181 | - } |
|
182 | - |
|
183 | - if (!$status = \GV\Utils::get($entry, 'payment_status')) { |
|
184 | - return $output; |
|
185 | - } |
|
186 | - |
|
187 | - // @todo Move to init, or AJAXify, but make sure that the entry is in the View before allowing |
|
188 | - // @todo Also make sure we check caps if moved from here |
|
189 | - // @todo Also make sure test_GravityView_Field_Unsubscribe_unsubscribe_permissions is rewritten |
|
190 | - if ($entry = $this->maybe_unsubscribe($entry)) { |
|
191 | - if ($entry['payment_status'] !== $status) { |
|
192 | - // @todo Probably __( 'Unsubscribed', 'gravityview' ); |
|
193 | - return $entry['payment_status']; |
|
194 | - } |
|
195 | - } |
|
196 | - |
|
197 | - if ('active' !== mb_strtolower($entry['payment_status'])) { |
|
198 | - return $output; |
|
199 | - } |
|
200 | - |
|
201 | - global $wp; |
|
202 | - $current_url = add_query_arg($wp->query_string, '', home_url($wp->request)); |
|
203 | - |
|
204 | - $link = add_query_arg('unsubscribe', wp_create_nonce('unsubscribe_'.$entry['id']), $current_url); |
|
205 | - $link = add_query_arg('uid', $entry['id'], $link); |
|
206 | - |
|
207 | - return sprintf('<a href="%s">%s</a>', esc_url($link), esc_html__('Unsubscribe', 'gravityview')); |
|
208 | - } |
|
209 | - |
|
210 | - /** |
|
211 | - * Try to unsubscribe from the entry. |
|
212 | - * |
|
213 | - * Called during a POST request. Checks nonce, feeds, entry ID. |
|
214 | - * Does not check user permissions. This is left as an exercise for the caller. |
|
215 | - * |
|
216 | - * Entry View inclusion is checked ad-hoc during the rendering of the field. |
|
217 | - * User permissions are also checked ad-hoc during the rendering process. |
|
218 | - * |
|
219 | - * @param array $entry The entry |
|
220 | - * |
|
221 | - * @return array $entry The entry |
|
222 | - */ |
|
223 | - private function maybe_unsubscribe($entry) |
|
224 | - { |
|
225 | - if (!wp_verify_nonce(\GV\Utils::_REQUEST('unsubscribe'), 'unsubscribe_'.$entry['id'])) { |
|
226 | - return $entry; |
|
227 | - } |
|
228 | - |
|
229 | - if ((!$uid = \GV\Utils::_REQUEST('uid')) || !is_numeric($uid) || (intval($uid) !== intval($entry['id']))) { |
|
230 | - return $entry; |
|
231 | - } |
|
232 | - |
|
233 | - if (!$feeds = gform_get_meta($uid, 'processed_feeds')) { |
|
234 | - return $entry; |
|
235 | - } |
|
236 | - |
|
237 | - static $subscription_addons; |
|
238 | - |
|
239 | - if (is_null($subscription_addons)) { |
|
240 | - $registered = GFAddon::get_registered_addons(); |
|
241 | - |
|
242 | - foreach ($registered as $addon) { |
|
243 | - if (method_exists($addon, 'cancel_subscription')) { |
|
244 | - $addon = $addon::get_instance(); |
|
245 | - $subscription_addons[$addon->get_slug()] = $addon; |
|
246 | - } |
|
247 | - } |
|
248 | - } |
|
249 | - |
|
250 | - if (empty($subscription_addons)) { |
|
251 | - return $entry; |
|
252 | - } |
|
253 | - |
|
254 | - foreach ($feeds as $slug => $feed_ids) { |
|
255 | - if (!isset($subscription_addons[$slug])) { |
|
256 | - continue; |
|
257 | - } |
|
258 | - |
|
259 | - foreach ($feed_ids as $feed_id) { |
|
260 | - $feed = $subscription_addons[$slug]->get_feed($feed_id); |
|
261 | - |
|
262 | - if ($feed && 'subscription' === \GV\Utils::get($feed, 'meta/transactionType')) { |
|
263 | - if ($subscription_addons[$slug]->cancel($entry, $feed)) { |
|
264 | - $subscription_addons[$slug]->cancel_subscription($entry, $feed); |
|
265 | - |
|
266 | - return \GFAPI::get_entry($entry['id']); |
|
267 | - } |
|
268 | - } |
|
269 | - } |
|
270 | - } |
|
271 | - |
|
272 | - return $entry; |
|
273 | - } |
|
9 | + public $name = 'unsubscribe'; |
|
10 | + |
|
11 | + public $group = 'gravityview'; |
|
12 | + |
|
13 | + public $is_searchable = false; |
|
14 | + |
|
15 | + public $contexts = ['single', 'multiple']; |
|
16 | + |
|
17 | + public function __construct() |
|
18 | + { |
|
19 | + $this->label = esc_html__('Unsubscribe', 'gravityview'); |
|
20 | + $this->description = esc_attr__('Unsubscribe from a Payment-based entry.', 'gravityview'); |
|
21 | + |
|
22 | + $this->add_hooks(); |
|
23 | + |
|
24 | + parent::__construct(); |
|
25 | + } |
|
26 | + |
|
27 | + /** |
|
28 | + * Hooks called from constructor. |
|
29 | + * |
|
30 | + * @return void |
|
31 | + */ |
|
32 | + public function add_hooks() |
|
33 | + { |
|
34 | + add_filter('gravityview_entry_default_fields', [$this, 'filter_gravityview_entry_default_field'], 10, 3); |
|
35 | + |
|
36 | + add_filter('gravityview/field/is_visible', [$this, 'maybe_not_visible'], 10, 2); |
|
37 | + |
|
38 | + add_filter('gravityview_field_entry_value_unsubscribe', [$this, 'modify_entry_value_unsubscribe'], 10, 4); |
|
39 | + } |
|
40 | + |
|
41 | + /** |
|
42 | + * Configure the field options. |
|
43 | + * |
|
44 | + * Called from the `gravityview_entry_default_fields` filter. |
|
45 | + * |
|
46 | + * Remove the logged in, new window and show as link options. |
|
47 | + * Add the allow unsubscribe for all admins option. |
|
48 | + * |
|
49 | + * @param array $field_options The options. |
|
50 | + * @param string $template_id The template ID. |
|
51 | + * @param int|string|float $field_id The field ID. |
|
52 | + * @param string $context The configuration context (edit, single, etc.) |
|
53 | + * @param string $input_type The input type. |
|
54 | + * @param int $form_id The form ID. |
|
55 | + * |
|
56 | + * @return array The field options. |
|
57 | + */ |
|
58 | + public function field_options($field_options, $template_id, $field_id, $context, $input_type, $form_id) |
|
59 | + { |
|
60 | + unset($field_options['only_loggedin']); |
|
61 | + |
|
62 | + unset($field_options['new_window']); |
|
63 | + |
|
64 | + unset($field_options['show_as_link']); |
|
65 | + |
|
66 | + $add_options['unsub_all'] = [ |
|
67 | + 'type' => 'checkbox', |
|
68 | + 'label' => __('Allow admins to unsubscribe', 'gravityview'), |
|
69 | + 'desc' => __('Allow users with `gravityforms_edit_entries` to cancel subscriptions', 'gravityview'), |
|
70 | + 'value' => false, |
|
71 | + 'merge_tags' => false, |
|
72 | + ]; |
|
73 | + |
|
74 | + return $field_options + $add_options; |
|
75 | + } |
|
76 | + |
|
77 | + /** |
|
78 | + * Hide the field from the renderer. Perhaps. |
|
79 | + * |
|
80 | + * Called from `gravityview/field/is_visible` |
|
81 | + * |
|
82 | + * Hide the field for non-logged in users for sure. |
|
83 | + * |
|
84 | + * @param bool $visible Consider visible or not. |
|
85 | + * @param \GV\Field $field The field. |
|
86 | + * |
|
87 | + * @return bool Visible or not. |
|
88 | + */ |
|
89 | + public function maybe_not_visible($visible, $field) |
|
90 | + { |
|
91 | + if ($this->name !== $field->ID) { |
|
92 | + return $visible; |
|
93 | + } |
|
94 | + |
|
95 | + return is_user_logged_in() ? $visible : false; |
|
96 | + } |
|
97 | + |
|
98 | + /** |
|
99 | + * Add the unsubsribe to the configuration fields. |
|
100 | + * |
|
101 | + * Only if a subscription feed is active for the current form. |
|
102 | + * |
|
103 | + * Called from `gravityview_entry_default_fields` |
|
104 | + * |
|
105 | + * @param array $entry_default_fields An array of available for configuration |
|
106 | + * @param array|int $form Form ID or array |
|
107 | + * @param string $context The configuration context (edit, single, etc.) |
|
108 | + * |
|
109 | + * @return array The array of available default fields. |
|
110 | + */ |
|
111 | + public function filter_gravityview_entry_default_field($entry_default_fields, $form, $context) |
|
112 | + { |
|
113 | + if (is_array($form)) { |
|
114 | + return $entry_default_fields; |
|
115 | + } |
|
116 | + |
|
117 | + $feeds = GFAPI::get_feeds(null, $form); |
|
118 | + |
|
119 | + if (is_wp_error($feeds)) { |
|
120 | + return $entry_default_fields; |
|
121 | + } |
|
122 | + |
|
123 | + static $subscription_addons; |
|
124 | + |
|
125 | + if (is_null($subscription_addons)) { |
|
126 | + $registered = GFAddon::get_registered_addons(); |
|
127 | + |
|
128 | + foreach ($registered as $addon) { |
|
129 | + if (method_exists($addon, 'cancel_subscription') && is_callable([$addon, 'get_instance'])) { |
|
130 | + $addon = $addon::get_instance(); |
|
131 | + $subscription_addons[$addon->get_slug()] = $addon; |
|
132 | + } |
|
133 | + } |
|
134 | + } |
|
135 | + |
|
136 | + if (empty($subscription_addons)) { |
|
137 | + return $entry_default_fields; |
|
138 | + } |
|
139 | + |
|
140 | + foreach ($feeds as $feed) { |
|
141 | + if (isset($subscription_addons[$feed['addon_slug']]) && 'subscription' === \GV\Utils::get($feed, 'meta/transactionType')) { |
|
142 | + if (!isset($entry_default_fields["{$this->name}"]) && 'edit' !== $context) { |
|
143 | + $entry_default_fields["{$this->name}"] = [ |
|
144 | + 'label' => $this->label, |
|
145 | + 'desc' => $this->description, |
|
146 | + 'type' => $this->name, |
|
147 | + ]; |
|
148 | + |
|
149 | + break; // Feed found, field added |
|
150 | + } |
|
151 | + } |
|
152 | + } |
|
153 | + |
|
154 | + return $entry_default_fields; |
|
155 | + } |
|
156 | + |
|
157 | + /** |
|
158 | + * Modify the render content. |
|
159 | + * |
|
160 | + * Called from `gravityview_field_entry_value_unsubscribe` |
|
161 | + * |
|
162 | + * @param string $output The output. |
|
163 | + * @param array $entry The entry. |
|
164 | + * @param array $field_settings The field settings. |
|
165 | + * @param \GV\Field $field The field. |
|
166 | + * |
|
167 | + * @return string The content. |
|
168 | + */ |
|
169 | + public function modify_entry_value_unsubscribe($output, $entry, $field_settings, $field) |
|
170 | + { |
|
171 | + if (!is_user_logged_in() || !$entry) { |
|
172 | + return $output; |
|
173 | + } |
|
174 | + |
|
175 | + $can_current_user_edit = is_numeric($entry['created_by']) && (wp_get_current_user()->ID === intval($entry['created_by'])); |
|
176 | + |
|
177 | + if (!$can_current_user_edit) { |
|
178 | + if (empty($field_settings['unsub_all']) || !\GVCommon::has_cap('gravityforms_edit_entries', $entry['id'])) { |
|
179 | + return $output; |
|
180 | + } |
|
181 | + } |
|
182 | + |
|
183 | + if (!$status = \GV\Utils::get($entry, 'payment_status')) { |
|
184 | + return $output; |
|
185 | + } |
|
186 | + |
|
187 | + // @todo Move to init, or AJAXify, but make sure that the entry is in the View before allowing |
|
188 | + // @todo Also make sure we check caps if moved from here |
|
189 | + // @todo Also make sure test_GravityView_Field_Unsubscribe_unsubscribe_permissions is rewritten |
|
190 | + if ($entry = $this->maybe_unsubscribe($entry)) { |
|
191 | + if ($entry['payment_status'] !== $status) { |
|
192 | + // @todo Probably __( 'Unsubscribed', 'gravityview' ); |
|
193 | + return $entry['payment_status']; |
|
194 | + } |
|
195 | + } |
|
196 | + |
|
197 | + if ('active' !== mb_strtolower($entry['payment_status'])) { |
|
198 | + return $output; |
|
199 | + } |
|
200 | + |
|
201 | + global $wp; |
|
202 | + $current_url = add_query_arg($wp->query_string, '', home_url($wp->request)); |
|
203 | + |
|
204 | + $link = add_query_arg('unsubscribe', wp_create_nonce('unsubscribe_'.$entry['id']), $current_url); |
|
205 | + $link = add_query_arg('uid', $entry['id'], $link); |
|
206 | + |
|
207 | + return sprintf('<a href="%s">%s</a>', esc_url($link), esc_html__('Unsubscribe', 'gravityview')); |
|
208 | + } |
|
209 | + |
|
210 | + /** |
|
211 | + * Try to unsubscribe from the entry. |
|
212 | + * |
|
213 | + * Called during a POST request. Checks nonce, feeds, entry ID. |
|
214 | + * Does not check user permissions. This is left as an exercise for the caller. |
|
215 | + * |
|
216 | + * Entry View inclusion is checked ad-hoc during the rendering of the field. |
|
217 | + * User permissions are also checked ad-hoc during the rendering process. |
|
218 | + * |
|
219 | + * @param array $entry The entry |
|
220 | + * |
|
221 | + * @return array $entry The entry |
|
222 | + */ |
|
223 | + private function maybe_unsubscribe($entry) |
|
224 | + { |
|
225 | + if (!wp_verify_nonce(\GV\Utils::_REQUEST('unsubscribe'), 'unsubscribe_'.$entry['id'])) { |
|
226 | + return $entry; |
|
227 | + } |
|
228 | + |
|
229 | + if ((!$uid = \GV\Utils::_REQUEST('uid')) || !is_numeric($uid) || (intval($uid) !== intval($entry['id']))) { |
|
230 | + return $entry; |
|
231 | + } |
|
232 | + |
|
233 | + if (!$feeds = gform_get_meta($uid, 'processed_feeds')) { |
|
234 | + return $entry; |
|
235 | + } |
|
236 | + |
|
237 | + static $subscription_addons; |
|
238 | + |
|
239 | + if (is_null($subscription_addons)) { |
|
240 | + $registered = GFAddon::get_registered_addons(); |
|
241 | + |
|
242 | + foreach ($registered as $addon) { |
|
243 | + if (method_exists($addon, 'cancel_subscription')) { |
|
244 | + $addon = $addon::get_instance(); |
|
245 | + $subscription_addons[$addon->get_slug()] = $addon; |
|
246 | + } |
|
247 | + } |
|
248 | + } |
|
249 | + |
|
250 | + if (empty($subscription_addons)) { |
|
251 | + return $entry; |
|
252 | + } |
|
253 | + |
|
254 | + foreach ($feeds as $slug => $feed_ids) { |
|
255 | + if (!isset($subscription_addons[$slug])) { |
|
256 | + continue; |
|
257 | + } |
|
258 | + |
|
259 | + foreach ($feed_ids as $feed_id) { |
|
260 | + $feed = $subscription_addons[$slug]->get_feed($feed_id); |
|
261 | + |
|
262 | + if ($feed && 'subscription' === \GV\Utils::get($feed, 'meta/transactionType')) { |
|
263 | + if ($subscription_addons[$slug]->cancel($entry, $feed)) { |
|
264 | + $subscription_addons[$slug]->cancel_subscription($entry, $feed); |
|
265 | + |
|
266 | + return \GFAPI::get_entry($entry['id']); |
|
267 | + } |
|
268 | + } |
|
269 | + } |
|
270 | + } |
|
271 | + |
|
272 | + return $entry; |
|
273 | + } |
|
274 | 274 | } |
275 | 275 | |
276 | 276 | new GravityView_Field_Unsubscribe(); |
@@ -12,12 +12,12 @@ discard block |
||
12 | 12 | |
13 | 13 | public $is_searchable = false; |
14 | 14 | |
15 | - public $contexts = ['single', 'multiple']; |
|
15 | + public $contexts = [ 'single', 'multiple' ]; |
|
16 | 16 | |
17 | 17 | public function __construct() |
18 | 18 | { |
19 | - $this->label = esc_html__('Unsubscribe', 'gravityview'); |
|
20 | - $this->description = esc_attr__('Unsubscribe from a Payment-based entry.', 'gravityview'); |
|
19 | + $this->label = esc_html__( 'Unsubscribe', 'gravityview' ); |
|
20 | + $this->description = esc_attr__( 'Unsubscribe from a Payment-based entry.', 'gravityview' ); |
|
21 | 21 | |
22 | 22 | $this->add_hooks(); |
23 | 23 | |
@@ -31,11 +31,11 @@ discard block |
||
31 | 31 | */ |
32 | 32 | public function add_hooks() |
33 | 33 | { |
34 | - add_filter('gravityview_entry_default_fields', [$this, 'filter_gravityview_entry_default_field'], 10, 3); |
|
34 | + add_filter( 'gravityview_entry_default_fields', [ $this, 'filter_gravityview_entry_default_field' ], 10, 3 ); |
|
35 | 35 | |
36 | - add_filter('gravityview/field/is_visible', [$this, 'maybe_not_visible'], 10, 2); |
|
36 | + add_filter( 'gravityview/field/is_visible', [ $this, 'maybe_not_visible' ], 10, 2 ); |
|
37 | 37 | |
38 | - add_filter('gravityview_field_entry_value_unsubscribe', [$this, 'modify_entry_value_unsubscribe'], 10, 4); |
|
38 | + add_filter( 'gravityview_field_entry_value_unsubscribe', [ $this, 'modify_entry_value_unsubscribe' ], 10, 4 ); |
|
39 | 39 | } |
40 | 40 | |
41 | 41 | /** |
@@ -55,18 +55,18 @@ discard block |
||
55 | 55 | * |
56 | 56 | * @return array The field options. |
57 | 57 | */ |
58 | - public function field_options($field_options, $template_id, $field_id, $context, $input_type, $form_id) |
|
58 | + public function field_options( $field_options, $template_id, $field_id, $context, $input_type, $form_id ) |
|
59 | 59 | { |
60 | - unset($field_options['only_loggedin']); |
|
60 | + unset( $field_options[ 'only_loggedin' ] ); |
|
61 | 61 | |
62 | - unset($field_options['new_window']); |
|
62 | + unset( $field_options[ 'new_window' ] ); |
|
63 | 63 | |
64 | - unset($field_options['show_as_link']); |
|
64 | + unset( $field_options[ 'show_as_link' ] ); |
|
65 | 65 | |
66 | - $add_options['unsub_all'] = [ |
|
66 | + $add_options[ 'unsub_all' ] = [ |
|
67 | 67 | 'type' => 'checkbox', |
68 | - 'label' => __('Allow admins to unsubscribe', 'gravityview'), |
|
69 | - 'desc' => __('Allow users with `gravityforms_edit_entries` to cancel subscriptions', 'gravityview'), |
|
68 | + 'label' => __( 'Allow admins to unsubscribe', 'gravityview' ), |
|
69 | + 'desc' => __( 'Allow users with `gravityforms_edit_entries` to cancel subscriptions', 'gravityview' ), |
|
70 | 70 | 'value' => false, |
71 | 71 | 'merge_tags' => false, |
72 | 72 | ]; |
@@ -86,9 +86,9 @@ discard block |
||
86 | 86 | * |
87 | 87 | * @return bool Visible or not. |
88 | 88 | */ |
89 | - public function maybe_not_visible($visible, $field) |
|
89 | + public function maybe_not_visible( $visible, $field ) |
|
90 | 90 | { |
91 | - if ($this->name !== $field->ID) { |
|
91 | + if ( $this->name !== $field->ID ) { |
|
92 | 92 | return $visible; |
93 | 93 | } |
94 | 94 | |
@@ -108,39 +108,39 @@ discard block |
||
108 | 108 | * |
109 | 109 | * @return array The array of available default fields. |
110 | 110 | */ |
111 | - public function filter_gravityview_entry_default_field($entry_default_fields, $form, $context) |
|
111 | + public function filter_gravityview_entry_default_field( $entry_default_fields, $form, $context ) |
|
112 | 112 | { |
113 | - if (is_array($form)) { |
|
113 | + if ( is_array( $form ) ) { |
|
114 | 114 | return $entry_default_fields; |
115 | 115 | } |
116 | 116 | |
117 | - $feeds = GFAPI::get_feeds(null, $form); |
|
117 | + $feeds = GFAPI::get_feeds( null, $form ); |
|
118 | 118 | |
119 | - if (is_wp_error($feeds)) { |
|
119 | + if ( is_wp_error( $feeds ) ) { |
|
120 | 120 | return $entry_default_fields; |
121 | 121 | } |
122 | 122 | |
123 | 123 | static $subscription_addons; |
124 | 124 | |
125 | - if (is_null($subscription_addons)) { |
|
125 | + if ( is_null( $subscription_addons ) ) { |
|
126 | 126 | $registered = GFAddon::get_registered_addons(); |
127 | 127 | |
128 | - foreach ($registered as $addon) { |
|
129 | - if (method_exists($addon, 'cancel_subscription') && is_callable([$addon, 'get_instance'])) { |
|
128 | + foreach ( $registered as $addon ) { |
|
129 | + if ( method_exists( $addon, 'cancel_subscription' ) && is_callable( [ $addon, 'get_instance' ] ) ) { |
|
130 | 130 | $addon = $addon::get_instance(); |
131 | - $subscription_addons[$addon->get_slug()] = $addon; |
|
131 | + $subscription_addons[ $addon->get_slug() ] = $addon; |
|
132 | 132 | } |
133 | 133 | } |
134 | 134 | } |
135 | 135 | |
136 | - if (empty($subscription_addons)) { |
|
136 | + if ( empty( $subscription_addons ) ) { |
|
137 | 137 | return $entry_default_fields; |
138 | 138 | } |
139 | 139 | |
140 | - foreach ($feeds as $feed) { |
|
141 | - if (isset($subscription_addons[$feed['addon_slug']]) && 'subscription' === \GV\Utils::get($feed, 'meta/transactionType')) { |
|
142 | - if (!isset($entry_default_fields["{$this->name}"]) && 'edit' !== $context) { |
|
143 | - $entry_default_fields["{$this->name}"] = [ |
|
140 | + foreach ( $feeds as $feed ) { |
|
141 | + if ( isset( $subscription_addons[ $feed[ 'addon_slug' ] ] ) && 'subscription' === \GV\Utils::get( $feed, 'meta/transactionType' ) ) { |
|
142 | + if ( ! isset( $entry_default_fields[ "{$this->name}" ] ) && 'edit' !== $context ) { |
|
143 | + $entry_default_fields[ "{$this->name}" ] = [ |
|
144 | 144 | 'label' => $this->label, |
145 | 145 | 'desc' => $this->description, |
146 | 146 | 'type' => $this->name, |
@@ -166,45 +166,45 @@ discard block |
||
166 | 166 | * |
167 | 167 | * @return string The content. |
168 | 168 | */ |
169 | - public function modify_entry_value_unsubscribe($output, $entry, $field_settings, $field) |
|
169 | + public function modify_entry_value_unsubscribe( $output, $entry, $field_settings, $field ) |
|
170 | 170 | { |
171 | - if (!is_user_logged_in() || !$entry) { |
|
171 | + if ( ! is_user_logged_in() || ! $entry ) { |
|
172 | 172 | return $output; |
173 | 173 | } |
174 | 174 | |
175 | - $can_current_user_edit = is_numeric($entry['created_by']) && (wp_get_current_user()->ID === intval($entry['created_by'])); |
|
175 | + $can_current_user_edit = is_numeric( $entry[ 'created_by' ] ) && ( wp_get_current_user()->ID === intval( $entry[ 'created_by' ] ) ); |
|
176 | 176 | |
177 | - if (!$can_current_user_edit) { |
|
178 | - if (empty($field_settings['unsub_all']) || !\GVCommon::has_cap('gravityforms_edit_entries', $entry['id'])) { |
|
177 | + if ( ! $can_current_user_edit ) { |
|
178 | + if ( empty( $field_settings[ 'unsub_all' ] ) || ! \GVCommon::has_cap( 'gravityforms_edit_entries', $entry[ 'id' ] ) ) { |
|
179 | 179 | return $output; |
180 | 180 | } |
181 | 181 | } |
182 | 182 | |
183 | - if (!$status = \GV\Utils::get($entry, 'payment_status')) { |
|
183 | + if ( ! $status = \GV\Utils::get( $entry, 'payment_status' ) ) { |
|
184 | 184 | return $output; |
185 | 185 | } |
186 | 186 | |
187 | 187 | // @todo Move to init, or AJAXify, but make sure that the entry is in the View before allowing |
188 | 188 | // @todo Also make sure we check caps if moved from here |
189 | 189 | // @todo Also make sure test_GravityView_Field_Unsubscribe_unsubscribe_permissions is rewritten |
190 | - if ($entry = $this->maybe_unsubscribe($entry)) { |
|
191 | - if ($entry['payment_status'] !== $status) { |
|
190 | + if ( $entry = $this->maybe_unsubscribe( $entry ) ) { |
|
191 | + if ( $entry[ 'payment_status' ] !== $status ) { |
|
192 | 192 | // @todo Probably __( 'Unsubscribed', 'gravityview' ); |
193 | - return $entry['payment_status']; |
|
193 | + return $entry[ 'payment_status' ]; |
|
194 | 194 | } |
195 | 195 | } |
196 | 196 | |
197 | - if ('active' !== mb_strtolower($entry['payment_status'])) { |
|
197 | + if ( 'active' !== mb_strtolower( $entry[ 'payment_status' ] ) ) { |
|
198 | 198 | return $output; |
199 | 199 | } |
200 | 200 | |
201 | 201 | global $wp; |
202 | - $current_url = add_query_arg($wp->query_string, '', home_url($wp->request)); |
|
202 | + $current_url = add_query_arg( $wp->query_string, '', home_url( $wp->request ) ); |
|
203 | 203 | |
204 | - $link = add_query_arg('unsubscribe', wp_create_nonce('unsubscribe_'.$entry['id']), $current_url); |
|
205 | - $link = add_query_arg('uid', $entry['id'], $link); |
|
204 | + $link = add_query_arg( 'unsubscribe', wp_create_nonce( 'unsubscribe_' . $entry[ 'id' ] ), $current_url ); |
|
205 | + $link = add_query_arg( 'uid', $entry[ 'id' ], $link ); |
|
206 | 206 | |
207 | - return sprintf('<a href="%s">%s</a>', esc_url($link), esc_html__('Unsubscribe', 'gravityview')); |
|
207 | + return sprintf( '<a href="%s">%s</a>', esc_url( $link ), esc_html__( 'Unsubscribe', 'gravityview' ) ); |
|
208 | 208 | } |
209 | 209 | |
210 | 210 | /** |
@@ -220,50 +220,50 @@ discard block |
||
220 | 220 | * |
221 | 221 | * @return array $entry The entry |
222 | 222 | */ |
223 | - private function maybe_unsubscribe($entry) |
|
223 | + private function maybe_unsubscribe( $entry ) |
|
224 | 224 | { |
225 | - if (!wp_verify_nonce(\GV\Utils::_REQUEST('unsubscribe'), 'unsubscribe_'.$entry['id'])) { |
|
225 | + if ( ! wp_verify_nonce( \GV\Utils::_REQUEST( 'unsubscribe' ), 'unsubscribe_' . $entry[ 'id' ] ) ) { |
|
226 | 226 | return $entry; |
227 | 227 | } |
228 | 228 | |
229 | - if ((!$uid = \GV\Utils::_REQUEST('uid')) || !is_numeric($uid) || (intval($uid) !== intval($entry['id']))) { |
|
229 | + if ( ( ! $uid = \GV\Utils::_REQUEST( 'uid' ) ) || ! is_numeric( $uid ) || ( intval( $uid ) !== intval( $entry[ 'id' ] ) ) ) { |
|
230 | 230 | return $entry; |
231 | 231 | } |
232 | 232 | |
233 | - if (!$feeds = gform_get_meta($uid, 'processed_feeds')) { |
|
233 | + if ( ! $feeds = gform_get_meta( $uid, 'processed_feeds' ) ) { |
|
234 | 234 | return $entry; |
235 | 235 | } |
236 | 236 | |
237 | 237 | static $subscription_addons; |
238 | 238 | |
239 | - if (is_null($subscription_addons)) { |
|
239 | + if ( is_null( $subscription_addons ) ) { |
|
240 | 240 | $registered = GFAddon::get_registered_addons(); |
241 | 241 | |
242 | - foreach ($registered as $addon) { |
|
243 | - if (method_exists($addon, 'cancel_subscription')) { |
|
242 | + foreach ( $registered as $addon ) { |
|
243 | + if ( method_exists( $addon, 'cancel_subscription' ) ) { |
|
244 | 244 | $addon = $addon::get_instance(); |
245 | - $subscription_addons[$addon->get_slug()] = $addon; |
|
245 | + $subscription_addons[ $addon->get_slug() ] = $addon; |
|
246 | 246 | } |
247 | 247 | } |
248 | 248 | } |
249 | 249 | |
250 | - if (empty($subscription_addons)) { |
|
250 | + if ( empty( $subscription_addons ) ) { |
|
251 | 251 | return $entry; |
252 | 252 | } |
253 | 253 | |
254 | - foreach ($feeds as $slug => $feed_ids) { |
|
255 | - if (!isset($subscription_addons[$slug])) { |
|
254 | + foreach ( $feeds as $slug => $feed_ids ) { |
|
255 | + if ( ! isset( $subscription_addons[ $slug ] ) ) { |
|
256 | 256 | continue; |
257 | 257 | } |
258 | 258 | |
259 | - foreach ($feed_ids as $feed_id) { |
|
260 | - $feed = $subscription_addons[$slug]->get_feed($feed_id); |
|
259 | + foreach ( $feed_ids as $feed_id ) { |
|
260 | + $feed = $subscription_addons[ $slug ]->get_feed( $feed_id ); |
|
261 | 261 | |
262 | - if ($feed && 'subscription' === \GV\Utils::get($feed, 'meta/transactionType')) { |
|
263 | - if ($subscription_addons[$slug]->cancel($entry, $feed)) { |
|
264 | - $subscription_addons[$slug]->cancel_subscription($entry, $feed); |
|
262 | + if ( $feed && 'subscription' === \GV\Utils::get( $feed, 'meta/transactionType' ) ) { |
|
263 | + if ( $subscription_addons[ $slug ]->cancel( $entry, $feed ) ) { |
|
264 | + $subscription_addons[ $slug ]->cancel_subscription( $entry, $feed ); |
|
265 | 265 | |
266 | - return \GFAPI::get_entry($entry['id']); |
|
266 | + return \GFAPI::get_entry( $entry[ 'id' ] ); |
|
267 | 267 | } |
268 | 268 | } |
269 | 269 | } |
@@ -4,8 +4,7 @@ discard block |
||
4 | 4 | * |
5 | 5 | * @since 2.5 |
6 | 6 | */ |
7 | -class GravityView_Field_Unsubscribe extends GravityView_Field |
|
8 | -{ |
|
7 | +class GravityView_Field_Unsubscribe extends GravityView_Field { |
|
9 | 8 | public $name = 'unsubscribe'; |
10 | 9 | |
11 | 10 | public $group = 'gravityview'; |
@@ -14,8 +13,7 @@ discard block |
||
14 | 13 | |
15 | 14 | public $contexts = ['single', 'multiple']; |
16 | 15 | |
17 | - public function __construct() |
|
18 | - { |
|
16 | + public function __construct() { |
|
19 | 17 | $this->label = esc_html__('Unsubscribe', 'gravityview'); |
20 | 18 | $this->description = esc_attr__('Unsubscribe from a Payment-based entry.', 'gravityview'); |
21 | 19 | |
@@ -29,8 +27,7 @@ discard block |
||
29 | 27 | * |
30 | 28 | * @return void |
31 | 29 | */ |
32 | - public function add_hooks() |
|
33 | - { |
|
30 | + public function add_hooks() { |
|
34 | 31 | add_filter('gravityview_entry_default_fields', [$this, 'filter_gravityview_entry_default_field'], 10, 3); |
35 | 32 | |
36 | 33 | add_filter('gravityview/field/is_visible', [$this, 'maybe_not_visible'], 10, 2); |
@@ -55,8 +52,7 @@ discard block |
||
55 | 52 | * |
56 | 53 | * @return array The field options. |
57 | 54 | */ |
58 | - public function field_options($field_options, $template_id, $field_id, $context, $input_type, $form_id) |
|
59 | - { |
|
55 | + public function field_options($field_options, $template_id, $field_id, $context, $input_type, $form_id) { |
|
60 | 56 | unset($field_options['only_loggedin']); |
61 | 57 | |
62 | 58 | unset($field_options['new_window']); |
@@ -86,8 +82,7 @@ discard block |
||
86 | 82 | * |
87 | 83 | * @return bool Visible or not. |
88 | 84 | */ |
89 | - public function maybe_not_visible($visible, $field) |
|
90 | - { |
|
85 | + public function maybe_not_visible($visible, $field) { |
|
91 | 86 | if ($this->name !== $field->ID) { |
92 | 87 | return $visible; |
93 | 88 | } |
@@ -108,8 +103,7 @@ discard block |
||
108 | 103 | * |
109 | 104 | * @return array The array of available default fields. |
110 | 105 | */ |
111 | - public function filter_gravityview_entry_default_field($entry_default_fields, $form, $context) |
|
112 | - { |
|
106 | + public function filter_gravityview_entry_default_field($entry_default_fields, $form, $context) { |
|
113 | 107 | if (is_array($form)) { |
114 | 108 | return $entry_default_fields; |
115 | 109 | } |
@@ -166,8 +160,7 @@ discard block |
||
166 | 160 | * |
167 | 161 | * @return string The content. |
168 | 162 | */ |
169 | - public function modify_entry_value_unsubscribe($output, $entry, $field_settings, $field) |
|
170 | - { |
|
163 | + public function modify_entry_value_unsubscribe($output, $entry, $field_settings, $field) { |
|
171 | 164 | if (!is_user_logged_in() || !$entry) { |
172 | 165 | return $output; |
173 | 166 | } |
@@ -220,8 +213,7 @@ discard block |
||
220 | 213 | * |
221 | 214 | * @return array $entry The entry |
222 | 215 | */ |
223 | - private function maybe_unsubscribe($entry) |
|
224 | - { |
|
216 | + private function maybe_unsubscribe($entry) { |
|
225 | 217 | if (!wp_verify_nonce(\GV\Utils::_REQUEST('unsubscribe'), 'unsubscribe_'.$entry['id'])) { |
226 | 218 | return $entry; |
227 | 219 | } |