@@ -6,17 +6,17 @@ |
||
6 | 6 | */ |
7 | 7 | $gravityview_view = GravityView_View::getInstance(); |
8 | 8 | $view_id = $gravityview_view->getViewId(); |
9 | -$value = $gravityview_view->search_field['value']; |
|
10 | -$label = $gravityview_view->search_field['label']; |
|
9 | +$value = $gravityview_view->search_field[ 'value' ]; |
|
10 | +$label = $gravityview_view->search_field[ 'label' ]; |
|
11 | 11 | |
12 | 12 | ?> |
13 | 13 | |
14 | 14 | <div class="gv-search-box gv-search-date gv-search-date-range gv-search-field-entry_date"> |
15 | - <?php if (!gv_empty($label, false, false)) { ?> |
|
16 | - <label for="gv_start_date_<?php echo $view_id; ?>"><?php echo esc_html($label); ?></label> |
|
15 | + <?php if ( ! gv_empty( $label, false, false ) ) { ?> |
|
16 | + <label for="gv_start_date_<?php echo $view_id; ?>"><?php echo esc_html( $label ); ?></label> |
|
17 | 17 | <?php } ?> |
18 | 18 | <p> |
19 | - <input name="gv_start" id="gv_start_date_<?php echo $view_id; ?>" type="text" class="<?php echo esc_attr($gravityview_view->datepicker_class); ?>" placeholder="<?php esc_attr_e('Start date', 'gravityview'); ?>" value="<?php echo $value['start']; ?>"> |
|
20 | - <input name="gv_end" id="gv_end_date_<?php echo $view_id; ?>" type="text" class="<?php echo esc_attr($gravityview_view->datepicker_class); ?>" placeholder="<?php esc_attr_e('End date', 'gravityview'); ?>" value="<?php echo $value['end']; ?>"> |
|
19 | + <input name="gv_start" id="gv_start_date_<?php echo $view_id; ?>" type="text" class="<?php echo esc_attr( $gravityview_view->datepicker_class ); ?>" placeholder="<?php esc_attr_e( 'Start date', 'gravityview' ); ?>" value="<?php echo $value[ 'start' ]; ?>"> |
|
20 | + <input name="gv_end" id="gv_end_date_<?php echo $view_id; ?>" type="text" class="<?php echo esc_attr( $gravityview_view->datepicker_class ); ?>" placeholder="<?php esc_attr_e( 'End date', 'gravityview' ); ?>" value="<?php echo $value[ 'end' ]; ?>"> |
|
21 | 21 | </p> |
22 | 22 | </div> |
23 | 23 | \ No newline at end of file |
@@ -6,4 +6,4 @@ |
||
6 | 6 | */ |
7 | 7 | $gravityview_view = GravityView_View::getInstance(); |
8 | 8 | $search_field = $gravityview_view->search_field; |
9 | -?><div><input type="hidden" name="<?php echo esc_attr($search_field['name']); ?>" value="<?php echo esc_attr($search_field['value']); ?>"></div> |
|
10 | 9 | \ No newline at end of file |
10 | +?><div><input type="hidden" name="<?php echo esc_attr( $search_field[ 'name' ] ); ?>" value="<?php echo esc_attr( $search_field[ 'value' ] ); ?>"></div> |
|
11 | 11 | \ No newline at end of file |
@@ -10,9 +10,9 @@ |
||
10 | 10 | |
11 | 11 | // Make sure that there are choices to display |
12 | 12 | if (empty($search_field['choices'])) { |
13 | - gravityview()->log->debug('search-field-checkbox.php - No choices for field'); |
|
13 | + gravityview()->log->debug('search-field-checkbox.php - No choices for field'); |
|
14 | 14 | |
15 | - return; |
|
15 | + return; |
|
16 | 16 | } |
17 | 17 | |
18 | 18 | ?> |
@@ -9,23 +9,23 @@ |
||
9 | 9 | $search_field = $gravityview_view->search_field; |
10 | 10 | |
11 | 11 | // Make sure that there are choices to display |
12 | -if (empty($search_field['choices'])) { |
|
13 | - gravityview()->log->debug('search-field-checkbox.php - No choices for field'); |
|
12 | +if ( empty( $search_field[ 'choices' ] ) ) { |
|
13 | + gravityview()->log->debug( 'search-field-checkbox.php - No choices for field' ); |
|
14 | 14 | |
15 | 15 | return; |
16 | 16 | } |
17 | 17 | |
18 | 18 | ?> |
19 | 19 | <div class="gv-search-box gv-search-field-checkbox"> |
20 | - <?php if (!gv_empty($search_field['label'], false, false)) { ?> |
|
21 | - <label for=search-box-<?php echo esc_attr($search_field['name']); ?>><?php echo esc_html($search_field['label']); ?></label> |
|
20 | + <?php if ( ! gv_empty( $search_field[ 'label' ], false, false ) ) { ?> |
|
21 | + <label for=search-box-<?php echo esc_attr( $search_field[ 'name' ] ); ?>><?php echo esc_html( $search_field[ 'label' ] ); ?></label> |
|
22 | 22 | <?php } ?> |
23 | 23 | <p> |
24 | - <?php foreach ($search_field['choices'] as $choice) { ?> |
|
24 | + <?php foreach ( $search_field[ 'choices' ] as $choice ) { ?> |
|
25 | 25 | |
26 | - <label for="search-box-<?php echo sanitize_html_class($search_field['name'].$choice['value'].$choice['text']); ?>" class="gv-check-radio"> |
|
27 | - <input type="checkbox" name="<?php echo esc_attr($search_field['name']); ?>[]" value="<?php echo esc_attr($choice['value']); ?>" id="search-box-<?php echo sanitize_html_class($search_field['name'].$choice['value'].$choice['text']); ?>" <?php gv_selected($choice['value'], $search_field['value'], true, 'checked'); ?>> |
|
28 | - <?php echo esc_html($choice['text']); ?> |
|
26 | + <label for="search-box-<?php echo sanitize_html_class( $search_field[ 'name' ] . $choice[ 'value' ] . $choice[ 'text' ] ); ?>" class="gv-check-radio"> |
|
27 | + <input type="checkbox" name="<?php echo esc_attr( $search_field[ 'name' ] ); ?>[]" value="<?php echo esc_attr( $choice[ 'value' ] ); ?>" id="search-box-<?php echo sanitize_html_class( $search_field[ 'name' ] . $choice[ 'value' ] . $choice[ 'text' ] ); ?>" <?php gv_selected( $choice[ 'value' ], $search_field[ 'value' ], true, 'checked' ); ?>> |
|
28 | + <?php echo esc_html( $choice[ 'text' ] ); ?> |
|
29 | 29 | </label> |
30 | 30 | |
31 | 31 | <?php } ?> |
@@ -14,7 +14,7 @@ |
||
14 | 14 | <label for="search-box-<?php echo esc_attr($search_field['name']); ?>" class="gv-check-radio"> |
15 | 15 | <input type="checkbox" name="<?php echo esc_attr($search_field['name']); ?>" value="1" id="search-box-<?php echo esc_attr($search_field['name']); ?>" <?php checked('1', $search_field['value'], true); ?>> |
16 | 16 | <?php if (!gv_empty($search_field['label'], false, false)) { |
17 | - echo esc_html($search_field['label']); |
|
17 | + echo esc_html($search_field['label']); |
|
18 | 18 | } ?> |
19 | 19 | </label> |
20 | 20 | </div> |
21 | 21 | \ No newline at end of file |
@@ -11,10 +11,10 @@ |
||
11 | 11 | ?> |
12 | 12 | |
13 | 13 | <div class="gv-search-box gv-search-field-single_checkbox"> |
14 | - <label for="search-box-<?php echo esc_attr($search_field['name']); ?>" class="gv-check-radio"> |
|
15 | - <input type="checkbox" name="<?php echo esc_attr($search_field['name']); ?>" value="1" id="search-box-<?php echo esc_attr($search_field['name']); ?>" <?php checked('1', $search_field['value'], true); ?>> |
|
16 | - <?php if (!gv_empty($search_field['label'], false, false)) { |
|
17 | - echo esc_html($search_field['label']); |
|
14 | + <label for="search-box-<?php echo esc_attr( $search_field[ 'name' ] ); ?>" class="gv-check-radio"> |
|
15 | + <input type="checkbox" name="<?php echo esc_attr( $search_field[ 'name' ] ); ?>" value="1" id="search-box-<?php echo esc_attr( $search_field[ 'name' ] ); ?>" <?php checked( '1', $search_field[ 'value' ], true ); ?>> |
|
16 | + <?php if ( ! gv_empty( $search_field[ 'label' ], false, false ) ) { |
|
17 | + echo esc_html( $search_field[ 'label' ] ); |
|
18 | 18 | } ?> |
19 | 19 | </label> |
20 | 20 | </div> |
21 | 21 | \ No newline at end of file |
@@ -11,103 +11,103 @@ discard block |
||
11 | 11 | */ |
12 | 12 | class Page_Size extends \GV\Widget |
13 | 13 | { |
14 | - public $icon = 'dashicons-admin-settings'; |
|
15 | - |
|
16 | - /** |
|
17 | - * Does this get displayed on a single entry? |
|
18 | - * |
|
19 | - * @var bool |
|
20 | - */ |
|
21 | - protected $show_on_single = false; |
|
22 | - |
|
23 | - protected $widget_id = 'page_size'; |
|
24 | - |
|
25 | - public function __construct() |
|
26 | - { |
|
27 | - $this->widget_description = __('Allow users to modify the number of results shown per page.', 'gravityview'); |
|
28 | - |
|
29 | - $default_values = [ |
|
30 | - 'header' => 1, |
|
31 | - 'footer' => 1, |
|
32 | - ]; |
|
33 | - |
|
34 | - $settings = []; |
|
35 | - |
|
36 | - if (!$this->is_registered()) { |
|
37 | - add_action('gravityview/view/get', [$this, 'override_view_page_size']); |
|
38 | - } |
|
39 | - |
|
40 | - parent::__construct(__('Page Size', 'gravityview'), $this->widget_id, $default_values, $settings); |
|
41 | - } |
|
42 | - |
|
43 | - /** |
|
44 | - * Get an array of page sizes. |
|
45 | - * |
|
46 | - * @param \GV\Template_Context|string $context The context, if available |
|
47 | - * |
|
48 | - * @return array The page sizes in an array with `value` and `text` keys. |
|
49 | - */ |
|
50 | - public static function get_page_sizes($context) |
|
51 | - { |
|
52 | - $default_size = 25; |
|
53 | - |
|
54 | - if ($context instanceof \GV\Template_Context) { |
|
55 | - $default_size = (int) $context->view->settings->get('page_size'); |
|
56 | - } |
|
57 | - |
|
58 | - $sizes = [10, 25, $default_size, 50, 100]; |
|
59 | - |
|
60 | - $sizes = array_unique(array_filter($sizes)); |
|
61 | - |
|
62 | - sort($sizes); |
|
63 | - |
|
64 | - $page_sizes = []; |
|
65 | - foreach ($sizes as $size) { |
|
66 | - $page_sizes[] = [ |
|
67 | - 'value' => $size, |
|
68 | - 'text' => $size, |
|
69 | - ]; |
|
70 | - } |
|
71 | - |
|
72 | - /** |
|
73 | - * @filter `gravityview/widget/page_size/page_sizes` Filter the available page sizes as needed |
|
74 | - * |
|
75 | - * @param array $sizes The sizes, with `value` and `text` keys. `text` key used as HTML option label. |
|
76 | - * @param \GV\Template_Context $context The context. |
|
77 | - */ |
|
78 | - $page_sizes = apply_filters('gravityview/widget/page_size/page_sizes', $page_sizes, $context); |
|
79 | - |
|
80 | - return $page_sizes; |
|
81 | - } |
|
82 | - |
|
83 | - /** |
|
84 | - * Render the page size widget. |
|
85 | - * |
|
86 | - * @param array $widget_args The Widget shortcode args. |
|
87 | - * @param string $content The content. |
|
88 | - * @param string|\GV\Template_Context $context The context, if available. |
|
89 | - */ |
|
90 | - public function render_frontend($widget_args, $content = '', $context = null) |
|
91 | - { |
|
92 | - if (!$this->pre_render_frontend()) { |
|
93 | - return; |
|
94 | - } |
|
95 | - |
|
96 | - $page_size = (int) \GV\Utils::_GET('page_size', $context->view->settings->get('page_size')); |
|
97 | - |
|
98 | - $settings = shortcode_atts([ |
|
99 | - 'label' => __('Page Size', 'gravityview'), |
|
100 | - 'choices' => self::get_page_sizes($context), |
|
101 | - 'default_choice_text' => __('Results Per Page', 'gravityview'), |
|
102 | - ], $widget_args, 'gravityview_widget_page_size'); |
|
103 | - |
|
104 | - /** |
|
105 | - * @filter `gravityview/widget/page_size/settings` Filter the settings for the widget |
|
106 | - * |
|
107 | - * @param array $settings Configuration for how output will display, with `label`, `choices`, `default_choice_text` keys |
|
108 | - * @param \GV\Template_Context $context The context. |
|
109 | - */ |
|
110 | - $settings = apply_filters('gravityview/widget/page_size/settings', $settings, $context); ?> |
|
14 | + public $icon = 'dashicons-admin-settings'; |
|
15 | + |
|
16 | + /** |
|
17 | + * Does this get displayed on a single entry? |
|
18 | + * |
|
19 | + * @var bool |
|
20 | + */ |
|
21 | + protected $show_on_single = false; |
|
22 | + |
|
23 | + protected $widget_id = 'page_size'; |
|
24 | + |
|
25 | + public function __construct() |
|
26 | + { |
|
27 | + $this->widget_description = __('Allow users to modify the number of results shown per page.', 'gravityview'); |
|
28 | + |
|
29 | + $default_values = [ |
|
30 | + 'header' => 1, |
|
31 | + 'footer' => 1, |
|
32 | + ]; |
|
33 | + |
|
34 | + $settings = []; |
|
35 | + |
|
36 | + if (!$this->is_registered()) { |
|
37 | + add_action('gravityview/view/get', [$this, 'override_view_page_size']); |
|
38 | + } |
|
39 | + |
|
40 | + parent::__construct(__('Page Size', 'gravityview'), $this->widget_id, $default_values, $settings); |
|
41 | + } |
|
42 | + |
|
43 | + /** |
|
44 | + * Get an array of page sizes. |
|
45 | + * |
|
46 | + * @param \GV\Template_Context|string $context The context, if available |
|
47 | + * |
|
48 | + * @return array The page sizes in an array with `value` and `text` keys. |
|
49 | + */ |
|
50 | + public static function get_page_sizes($context) |
|
51 | + { |
|
52 | + $default_size = 25; |
|
53 | + |
|
54 | + if ($context instanceof \GV\Template_Context) { |
|
55 | + $default_size = (int) $context->view->settings->get('page_size'); |
|
56 | + } |
|
57 | + |
|
58 | + $sizes = [10, 25, $default_size, 50, 100]; |
|
59 | + |
|
60 | + $sizes = array_unique(array_filter($sizes)); |
|
61 | + |
|
62 | + sort($sizes); |
|
63 | + |
|
64 | + $page_sizes = []; |
|
65 | + foreach ($sizes as $size) { |
|
66 | + $page_sizes[] = [ |
|
67 | + 'value' => $size, |
|
68 | + 'text' => $size, |
|
69 | + ]; |
|
70 | + } |
|
71 | + |
|
72 | + /** |
|
73 | + * @filter `gravityview/widget/page_size/page_sizes` Filter the available page sizes as needed |
|
74 | + * |
|
75 | + * @param array $sizes The sizes, with `value` and `text` keys. `text` key used as HTML option label. |
|
76 | + * @param \GV\Template_Context $context The context. |
|
77 | + */ |
|
78 | + $page_sizes = apply_filters('gravityview/widget/page_size/page_sizes', $page_sizes, $context); |
|
79 | + |
|
80 | + return $page_sizes; |
|
81 | + } |
|
82 | + |
|
83 | + /** |
|
84 | + * Render the page size widget. |
|
85 | + * |
|
86 | + * @param array $widget_args The Widget shortcode args. |
|
87 | + * @param string $content The content. |
|
88 | + * @param string|\GV\Template_Context $context The context, if available. |
|
89 | + */ |
|
90 | + public function render_frontend($widget_args, $content = '', $context = null) |
|
91 | + { |
|
92 | + if (!$this->pre_render_frontend()) { |
|
93 | + return; |
|
94 | + } |
|
95 | + |
|
96 | + $page_size = (int) \GV\Utils::_GET('page_size', $context->view->settings->get('page_size')); |
|
97 | + |
|
98 | + $settings = shortcode_atts([ |
|
99 | + 'label' => __('Page Size', 'gravityview'), |
|
100 | + 'choices' => self::get_page_sizes($context), |
|
101 | + 'default_choice_text' => __('Results Per Page', 'gravityview'), |
|
102 | + ], $widget_args, 'gravityview_widget_page_size'); |
|
103 | + |
|
104 | + /** |
|
105 | + * @filter `gravityview/widget/page_size/settings` Filter the settings for the widget |
|
106 | + * |
|
107 | + * @param array $settings Configuration for how output will display, with `label`, `choices`, `default_choice_text` keys |
|
108 | + * @param \GV\Template_Context $context The context. |
|
109 | + */ |
|
110 | + $settings = apply_filters('gravityview/widget/page_size/settings', $settings, $context); ?> |
|
111 | 111 | <div class="gv-widget-page-size"> |
112 | 112 | <form method="get" action="<?php echo esc_url(add_query_arg([])); ?>" onchange="this.submit();"> |
113 | 113 | <div> |
@@ -117,67 +117,67 @@ discard block |
||
117 | 117 | <select name="page_size" id="gv-page_size"> |
118 | 118 | <option value=""><?php echo esc_html($settings['default_choice_text']); ?></option> |
119 | 119 | <?php |
120 | - foreach ($settings['choices'] as $choice) { ?> |
|
120 | + foreach ($settings['choices'] as $choice) { ?> |
|
121 | 121 | <option value='<?php echo esc_attr($choice['value']); ?>'<?php gv_selected(esc_attr($choice['value']), esc_attr($page_size), true); ?>><?php echo esc_html($choice['text']); ?></option> |
122 | 122 | <?php } ?> |
123 | 123 | </select> |
124 | 124 | <input type="submit" value="Submit" style="visibility: hidden; position: absolute;" /><?php |
125 | - if (!empty($_GET)) { |
|
126 | - $get = $_GET; |
|
127 | - unset($get['page_size']); |
|
128 | - foreach ($get as $key => $value) { |
|
129 | - if (is_array($value)) { |
|
130 | - foreach ($value as $_key => $_value) { |
|
131 | - printf('<input type="hidden" name="%s[%s]" value="%s" />', esc_attr($key), esc_attr($_key), esc_attr($_value)); |
|
132 | - } |
|
133 | - } else { |
|
134 | - printf('<input type="hidden" name="%s" value="%s" />', esc_attr($key), esc_attr($value)); |
|
135 | - } |
|
136 | - } |
|
137 | - } ?> |
|
125 | + if (!empty($_GET)) { |
|
126 | + $get = $_GET; |
|
127 | + unset($get['page_size']); |
|
128 | + foreach ($get as $key => $value) { |
|
129 | + if (is_array($value)) { |
|
130 | + foreach ($value as $_key => $_value) { |
|
131 | + printf('<input type="hidden" name="%s[%s]" value="%s" />', esc_attr($key), esc_attr($_key), esc_attr($_value)); |
|
132 | + } |
|
133 | + } else { |
|
134 | + printf('<input type="hidden" name="%s" value="%s" />', esc_attr($key), esc_attr($value)); |
|
135 | + } |
|
136 | + } |
|
137 | + } ?> |
|
138 | 138 | </div> |
139 | 139 | </form> |
140 | 140 | </div> |
141 | 141 | <?php |
142 | - } |
|
143 | - |
|
144 | - /** |
|
145 | - * Override the View settings and inject the needed page size. |
|
146 | - * |
|
147 | - * This might be too early, seeing that there's lack of full context, but we should |
|
148 | - * be fine for now. |
|
149 | - * |
|
150 | - * @param \GV\View $view The View. |
|
151 | - */ |
|
152 | - public function override_view_page_size(&$view) |
|
153 | - { |
|
154 | - if (!$view->widgets->by_id('page_size')->count()) { |
|
155 | - return; |
|
156 | - } |
|
157 | - |
|
158 | - $page_size = \GV\Utils::_GET('page_size'); |
|
159 | - |
|
160 | - if (empty($page_size)) { |
|
161 | - return; |
|
162 | - } |
|
163 | - |
|
164 | - // Already overridden |
|
165 | - if ((int) $page_size === (int) $view->settings->get('page_size')) { |
|
166 | - return; |
|
167 | - } |
|
168 | - |
|
169 | - $context = \GV\Template_Context::from_template([ |
|
170 | - 'view' => $view, |
|
171 | - ]); |
|
172 | - |
|
173 | - if (!in_array((int) $page_size, wp_list_pluck(self::get_page_sizes($context), 'value'), true)) { |
|
174 | - gravityview()->log->warning('The passed page size is not allowed: {page_size}. Not modifying result.', ['page_size' => $page_size]); |
|
175 | - |
|
176 | - return; |
|
177 | - } |
|
178 | - |
|
179 | - $view->settings->update(['page_size' => $page_size]); |
|
180 | - } |
|
142 | + } |
|
143 | + |
|
144 | + /** |
|
145 | + * Override the View settings and inject the needed page size. |
|
146 | + * |
|
147 | + * This might be too early, seeing that there's lack of full context, but we should |
|
148 | + * be fine for now. |
|
149 | + * |
|
150 | + * @param \GV\View $view The View. |
|
151 | + */ |
|
152 | + public function override_view_page_size(&$view) |
|
153 | + { |
|
154 | + if (!$view->widgets->by_id('page_size')->count()) { |
|
155 | + return; |
|
156 | + } |
|
157 | + |
|
158 | + $page_size = \GV\Utils::_GET('page_size'); |
|
159 | + |
|
160 | + if (empty($page_size)) { |
|
161 | + return; |
|
162 | + } |
|
163 | + |
|
164 | + // Already overridden |
|
165 | + if ((int) $page_size === (int) $view->settings->get('page_size')) { |
|
166 | + return; |
|
167 | + } |
|
168 | + |
|
169 | + $context = \GV\Template_Context::from_template([ |
|
170 | + 'view' => $view, |
|
171 | + ]); |
|
172 | + |
|
173 | + if (!in_array((int) $page_size, wp_list_pluck(self::get_page_sizes($context), 'value'), true)) { |
|
174 | + gravityview()->log->warning('The passed page size is not allowed: {page_size}. Not modifying result.', ['page_size' => $page_size]); |
|
175 | + |
|
176 | + return; |
|
177 | + } |
|
178 | + |
|
179 | + $view->settings->update(['page_size' => $page_size]); |
|
180 | + } |
|
181 | 181 | } |
182 | 182 | |
183 | 183 | new Page_Size(); |
@@ -24,20 +24,20 @@ discard block |
||
24 | 24 | |
25 | 25 | public function __construct() |
26 | 26 | { |
27 | - $this->widget_description = __('Allow users to modify the number of results shown per page.', 'gravityview'); |
|
27 | + $this->widget_description = __( 'Allow users to modify the number of results shown per page.', 'gravityview' ); |
|
28 | 28 | |
29 | 29 | $default_values = [ |
30 | 30 | 'header' => 1, |
31 | 31 | 'footer' => 1, |
32 | 32 | ]; |
33 | 33 | |
34 | - $settings = []; |
|
34 | + $settings = [ ]; |
|
35 | 35 | |
36 | - if (!$this->is_registered()) { |
|
37 | - add_action('gravityview/view/get', [$this, 'override_view_page_size']); |
|
36 | + if ( ! $this->is_registered() ) { |
|
37 | + add_action( 'gravityview/view/get', [ $this, 'override_view_page_size' ] ); |
|
38 | 38 | } |
39 | 39 | |
40 | - parent::__construct(__('Page Size', 'gravityview'), $this->widget_id, $default_values, $settings); |
|
40 | + parent::__construct( __( 'Page Size', 'gravityview' ), $this->widget_id, $default_values, $settings ); |
|
41 | 41 | } |
42 | 42 | |
43 | 43 | /** |
@@ -47,23 +47,23 @@ discard block |
||
47 | 47 | * |
48 | 48 | * @return array The page sizes in an array with `value` and `text` keys. |
49 | 49 | */ |
50 | - public static function get_page_sizes($context) |
|
50 | + public static function get_page_sizes( $context ) |
|
51 | 51 | { |
52 | 52 | $default_size = 25; |
53 | 53 | |
54 | - if ($context instanceof \GV\Template_Context) { |
|
55 | - $default_size = (int) $context->view->settings->get('page_size'); |
|
54 | + if ( $context instanceof \GV\Template_Context ) { |
|
55 | + $default_size = (int)$context->view->settings->get( 'page_size' ); |
|
56 | 56 | } |
57 | 57 | |
58 | - $sizes = [10, 25, $default_size, 50, 100]; |
|
58 | + $sizes = [ 10, 25, $default_size, 50, 100 ]; |
|
59 | 59 | |
60 | - $sizes = array_unique(array_filter($sizes)); |
|
60 | + $sizes = array_unique( array_filter( $sizes ) ); |
|
61 | 61 | |
62 | - sort($sizes); |
|
62 | + sort( $sizes ); |
|
63 | 63 | |
64 | - $page_sizes = []; |
|
65 | - foreach ($sizes as $size) { |
|
66 | - $page_sizes[] = [ |
|
64 | + $page_sizes = [ ]; |
|
65 | + foreach ( $sizes as $size ) { |
|
66 | + $page_sizes[ ] = [ |
|
67 | 67 | 'value' => $size, |
68 | 68 | 'text' => $size, |
69 | 69 | ]; |
@@ -75,7 +75,7 @@ discard block |
||
75 | 75 | * @param array $sizes The sizes, with `value` and `text` keys. `text` key used as HTML option label. |
76 | 76 | * @param \GV\Template_Context $context The context. |
77 | 77 | */ |
78 | - $page_sizes = apply_filters('gravityview/widget/page_size/page_sizes', $page_sizes, $context); |
|
78 | + $page_sizes = apply_filters( 'gravityview/widget/page_size/page_sizes', $page_sizes, $context ); |
|
79 | 79 | |
80 | 80 | return $page_sizes; |
81 | 81 | } |
@@ -87,19 +87,19 @@ discard block |
||
87 | 87 | * @param string $content The content. |
88 | 88 | * @param string|\GV\Template_Context $context The context, if available. |
89 | 89 | */ |
90 | - public function render_frontend($widget_args, $content = '', $context = null) |
|
90 | + public function render_frontend( $widget_args, $content = '', $context = null ) |
|
91 | 91 | { |
92 | - if (!$this->pre_render_frontend()) { |
|
92 | + if ( ! $this->pre_render_frontend() ) { |
|
93 | 93 | return; |
94 | 94 | } |
95 | 95 | |
96 | - $page_size = (int) \GV\Utils::_GET('page_size', $context->view->settings->get('page_size')); |
|
96 | + $page_size = (int)\GV\Utils::_GET( 'page_size', $context->view->settings->get( 'page_size' ) ); |
|
97 | 97 | |
98 | - $settings = shortcode_atts([ |
|
99 | - 'label' => __('Page Size', 'gravityview'), |
|
100 | - 'choices' => self::get_page_sizes($context), |
|
101 | - 'default_choice_text' => __('Results Per Page', 'gravityview'), |
|
102 | - ], $widget_args, 'gravityview_widget_page_size'); |
|
98 | + $settings = shortcode_atts( [ |
|
99 | + 'label' => __( 'Page Size', 'gravityview' ), |
|
100 | + 'choices' => self::get_page_sizes( $context ), |
|
101 | + 'default_choice_text' => __( 'Results Per Page', 'gravityview' ), |
|
102 | + ], $widget_args, 'gravityview_widget_page_size' ); |
|
103 | 103 | |
104 | 104 | /** |
105 | 105 | * @filter `gravityview/widget/page_size/settings` Filter the settings for the widget |
@@ -107,31 +107,31 @@ discard block |
||
107 | 107 | * @param array $settings Configuration for how output will display, with `label`, `choices`, `default_choice_text` keys |
108 | 108 | * @param \GV\Template_Context $context The context. |
109 | 109 | */ |
110 | - $settings = apply_filters('gravityview/widget/page_size/settings', $settings, $context); ?> |
|
110 | + $settings = apply_filters( 'gravityview/widget/page_size/settings', $settings, $context ); ?> |
|
111 | 111 | <div class="gv-widget-page-size"> |
112 | - <form method="get" action="<?php echo esc_url(add_query_arg([])); ?>" onchange="this.submit();"> |
|
112 | + <form method="get" action="<?php echo esc_url( add_query_arg( [ ] ) ); ?>" onchange="this.submit();"> |
|
113 | 113 | <div> |
114 | - <?php if (!empty($settings['label'])) { ?> |
|
115 | - <label for="gv-page_size"><?php echo esc_html($settings['label']); ?></label> |
|
114 | + <?php if ( ! empty( $settings[ 'label' ] ) ) { ?> |
|
115 | + <label for="gv-page_size"><?php echo esc_html( $settings[ 'label' ] ); ?></label> |
|
116 | 116 | <?php } ?> |
117 | 117 | <select name="page_size" id="gv-page_size"> |
118 | - <option value=""><?php echo esc_html($settings['default_choice_text']); ?></option> |
|
118 | + <option value=""><?php echo esc_html( $settings[ 'default_choice_text' ] ); ?></option> |
|
119 | 119 | <?php |
120 | - foreach ($settings['choices'] as $choice) { ?> |
|
121 | - <option value='<?php echo esc_attr($choice['value']); ?>'<?php gv_selected(esc_attr($choice['value']), esc_attr($page_size), true); ?>><?php echo esc_html($choice['text']); ?></option> |
|
120 | + foreach ( $settings[ 'choices' ] as $choice ) { ?> |
|
121 | + <option value='<?php echo esc_attr( $choice[ 'value' ] ); ?>'<?php gv_selected( esc_attr( $choice[ 'value' ] ), esc_attr( $page_size ), true ); ?>><?php echo esc_html( $choice[ 'text' ] ); ?></option> |
|
122 | 122 | <?php } ?> |
123 | 123 | </select> |
124 | 124 | <input type="submit" value="Submit" style="visibility: hidden; position: absolute;" /><?php |
125 | - if (!empty($_GET)) { |
|
125 | + if ( ! empty( $_GET ) ) { |
|
126 | 126 | $get = $_GET; |
127 | - unset($get['page_size']); |
|
128 | - foreach ($get as $key => $value) { |
|
129 | - if (is_array($value)) { |
|
130 | - foreach ($value as $_key => $_value) { |
|
131 | - printf('<input type="hidden" name="%s[%s]" value="%s" />', esc_attr($key), esc_attr($_key), esc_attr($_value)); |
|
127 | + unset( $get[ 'page_size' ] ); |
|
128 | + foreach ( $get as $key => $value ) { |
|
129 | + if ( is_array( $value ) ) { |
|
130 | + foreach ( $value as $_key => $_value ) { |
|
131 | + printf( '<input type="hidden" name="%s[%s]" value="%s" />', esc_attr( $key ), esc_attr( $_key ), esc_attr( $_value ) ); |
|
132 | 132 | } |
133 | 133 | } else { |
134 | - printf('<input type="hidden" name="%s" value="%s" />', esc_attr($key), esc_attr($value)); |
|
134 | + printf( '<input type="hidden" name="%s" value="%s" />', esc_attr( $key ), esc_attr( $value ) ); |
|
135 | 135 | } |
136 | 136 | } |
137 | 137 | } ?> |
@@ -149,34 +149,34 @@ discard block |
||
149 | 149 | * |
150 | 150 | * @param \GV\View $view The View. |
151 | 151 | */ |
152 | - public function override_view_page_size(&$view) |
|
152 | + public function override_view_page_size( &$view ) |
|
153 | 153 | { |
154 | - if (!$view->widgets->by_id('page_size')->count()) { |
|
154 | + if ( ! $view->widgets->by_id( 'page_size' )->count() ) { |
|
155 | 155 | return; |
156 | 156 | } |
157 | 157 | |
158 | - $page_size = \GV\Utils::_GET('page_size'); |
|
158 | + $page_size = \GV\Utils::_GET( 'page_size' ); |
|
159 | 159 | |
160 | - if (empty($page_size)) { |
|
160 | + if ( empty( $page_size ) ) { |
|
161 | 161 | return; |
162 | 162 | } |
163 | 163 | |
164 | 164 | // Already overridden |
165 | - if ((int) $page_size === (int) $view->settings->get('page_size')) { |
|
165 | + if ( (int)$page_size === (int)$view->settings->get( 'page_size' ) ) { |
|
166 | 166 | return; |
167 | 167 | } |
168 | 168 | |
169 | - $context = \GV\Template_Context::from_template([ |
|
169 | + $context = \GV\Template_Context::from_template( [ |
|
170 | 170 | 'view' => $view, |
171 | - ]); |
|
171 | + ] ); |
|
172 | 172 | |
173 | - if (!in_array((int) $page_size, wp_list_pluck(self::get_page_sizes($context), 'value'), true)) { |
|
174 | - gravityview()->log->warning('The passed page size is not allowed: {page_size}. Not modifying result.', ['page_size' => $page_size]); |
|
173 | + if ( ! in_array( (int)$page_size, wp_list_pluck( self::get_page_sizes( $context ), 'value' ), true ) ) { |
|
174 | + gravityview()->log->warning( 'The passed page size is not allowed: {page_size}. Not modifying result.', [ 'page_size' => $page_size ] ); |
|
175 | 175 | |
176 | 176 | return; |
177 | 177 | } |
178 | 178 | |
179 | - $view->settings->update(['page_size' => $page_size]); |
|
179 | + $view->settings->update( [ 'page_size' => $page_size ] ); |
|
180 | 180 | } |
181 | 181 | } |
182 | 182 |
@@ -22,8 +22,7 @@ discard block |
||
22 | 22 | |
23 | 23 | protected $widget_id = 'page_size'; |
24 | 24 | |
25 | - public function __construct() |
|
26 | - { |
|
25 | + public function __construct() { |
|
27 | 26 | $this->widget_description = __('Allow users to modify the number of results shown per page.', 'gravityview'); |
28 | 27 | |
29 | 28 | $default_values = [ |
@@ -47,8 +46,7 @@ discard block |
||
47 | 46 | * |
48 | 47 | * @return array The page sizes in an array with `value` and `text` keys. |
49 | 48 | */ |
50 | - public static function get_page_sizes($context) |
|
51 | - { |
|
49 | + public static function get_page_sizes($context) { |
|
52 | 50 | $default_size = 25; |
53 | 51 | |
54 | 52 | if ($context instanceof \GV\Template_Context) { |
@@ -87,8 +85,7 @@ discard block |
||
87 | 85 | * @param string $content The content. |
88 | 86 | * @param string|\GV\Template_Context $context The context, if available. |
89 | 87 | */ |
90 | - public function render_frontend($widget_args, $content = '', $context = null) |
|
91 | - { |
|
88 | + public function render_frontend($widget_args, $content = '', $context = null) { |
|
92 | 89 | if (!$this->pre_render_frontend()) { |
93 | 90 | return; |
94 | 91 | } |
@@ -149,8 +146,7 @@ discard block |
||
149 | 146 | * |
150 | 147 | * @param \GV\View $view The View. |
151 | 148 | */ |
152 | - public function override_view_page_size(&$view) |
|
153 | - { |
|
149 | + public function override_view_page_size(&$view) { |
|
154 | 150 | if (!$view->widgets->by_id('page_size')->count()) { |
155 | 151 | return; |
156 | 152 | } |
@@ -7,147 +7,147 @@ |
||
7 | 7 | */ |
8 | 8 | class GravityView_Widget_Gravity_Forms extends \GV\Widget |
9 | 9 | { |
10 | - public $icon = 'data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTAwJSIgaGVpZ2h0PSIxMDAlIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCA1MDguMyA1NTkuNSIgZm9jdXNhYmxlPSJmYWxzZSIgYXJpYS1oaWRkZW49InRydWUiIGNsYXNzPSJkYXNoaWNvbiBkYXNoaWNvbi1ncmF2aXR5Zm9ybXMiIHJvbGU9ImltZyI+PGc+PHBhdGggY2xhc3M9InN0MCIgZD0iTTQ2OCwxMDkuOEwyOTQuNCw5LjZjLTIyLjEtMTIuOC01OC40LTEyLjgtODAuNSwwTDQwLjMsMTA5LjhDMTguMiwxMjIuNiwwLDE1NCwwLDE3OS41VjM4MAljMCwyNS42LDE4LjEsNTYuOSw0MC4zLDY5LjdsMTczLjYsMTAwLjJjMjIuMSwxMi44LDU4LjQsMTIuOCw4MC41LDBMNDY4LDQ0OS44YzIyLjItMTIuOCw0MC4zLTQ0LjIsNDAuMy02OS43VjE3OS42CUM1MDguMywxNTQsNDkwLjIsMTIyLjYsNDY4LDEwOS44eiBNMzk5LjMsMjQ0LjRsLTE5NS4xLDBjLTExLDAtMTkuMiwzLjItMjUuNiwxMGMtMTQuMiwxNS4xLTE4LjIsNDQuNC0xOS4zLDYwLjdIMzQ4di0yNi40aDQ5LjkJdjc2LjNIMTExLjNsLTEuOC0yM2MtMC4zLTMuMy01LjktODAuNywzMi44LTEyMS45YzE2LjEtMTcuMSwzNy4xLTI1LjgsNjIuNC0yNS44aDE5NC43VjI0NC40eiI+PC9wYXRoPjwvZz48L3N2Zz4='; |
|
11 | - |
|
12 | - /** |
|
13 | - * Does this get displayed on a single entry? |
|
14 | - * |
|
15 | - * @var bool |
|
16 | - */ |
|
17 | - protected $show_on_single = true; |
|
18 | - |
|
19 | - public function __construct() |
|
20 | - { |
|
21 | - // Initialize widget in the frontend or when editing a View/performing widget AJAX action |
|
22 | - $doing_ajax = defined('DOING_AJAX') && DOING_AJAX && 'gv_field_options' === \GV\Utils::_POST('action'); |
|
23 | - $editing_view = 'edit' === \GV\Utils::_GET('action') && 'gravityview' === get_post_type(\GV\Utils::_GET('post')); |
|
24 | - $is_frontend = gravityview()->request->is_frontend(); |
|
25 | - |
|
26 | - if (!$doing_ajax && !$editing_view && !$is_frontend) { |
|
27 | - return; |
|
28 | - } |
|
29 | - |
|
30 | - $this->widget_description = __('Display a Gravity Forms form.', 'gravityview'); |
|
31 | - |
|
32 | - $default_values = [ |
|
33 | - 'header' => 1, |
|
34 | - 'footer' => 1, |
|
35 | - ]; |
|
36 | - |
|
37 | - $settings = [ |
|
38 | - 'widget_form_id' => [ |
|
39 | - 'type' => 'select', |
|
40 | - 'label' => __('Form to display', 'gravityview'), |
|
41 | - 'value' => '', |
|
42 | - 'options' => $this->_get_form_choices(), |
|
43 | - ], |
|
44 | - 'title' => [ |
|
45 | - 'type' => 'checkbox', |
|
46 | - 'label' => __('Show form title?', 'gravityview'), |
|
47 | - 'value' => 1, |
|
48 | - ], |
|
49 | - 'description' => [ |
|
50 | - 'type' => 'checkbox', |
|
51 | - 'label' => __('Show form description?', 'gravityview'), |
|
52 | - 'value' => 1, |
|
53 | - ], |
|
54 | - 'ajax' => [ |
|
55 | - 'type' => 'checkbox', |
|
56 | - 'label' => __('Enable AJAX', 'gravityview'), |
|
57 | - 'desc' => '', |
|
58 | - 'value' => 1, |
|
59 | - ], |
|
60 | - 'field_values' => [ |
|
61 | - 'type' => 'text', |
|
62 | - 'class' => 'code widefat', |
|
63 | - 'label' => __('Field value parameters', 'gravityview'), |
|
64 | - 'desc' => '<a href="https://docs.gravityforms.com/using-dynamic-population/" rel="external">'.esc_html__('Learn how to dynamically populate a field.', 'gravityview').'</a>', |
|
65 | - 'value' => '', |
|
66 | - ], |
|
67 | - ]; |
|
68 | - |
|
69 | - add_filter('gravityview/widget/hide_until_searched/allowlist', [$this, 'add_to_allowlist']); |
|
70 | - |
|
71 | - parent::__construct(__('Gravity Forms', 'gravityview'), 'gravityforms', $default_values, $settings); |
|
72 | - } |
|
73 | - |
|
74 | - /** |
|
75 | - * Returns an array of active forms to show as choices for the widget. |
|
76 | - * |
|
77 | - * @since 2.9.0.1 |
|
78 | - * |
|
79 | - * @return array Array with key set to Form ID => Form Title, with `0` as default placeholder. |
|
80 | - */ |
|
81 | - private function _get_form_choices() |
|
82 | - { |
|
83 | - $choices = [ |
|
84 | - 0 => '— '.esc_html__('list of forms', 'gravityview').'—', |
|
85 | - ]; |
|
86 | - |
|
87 | - if (!class_exists('GFAPI')) { |
|
88 | - return $choices; |
|
89 | - } |
|
90 | - |
|
91 | - global $wpdb; |
|
92 | - |
|
93 | - $table = GFFormsModel::get_form_table_name(); |
|
94 | - |
|
95 | - $results = $wpdb->get_results("SELECT id, title FROM ${table} WHERE is_active = 1"); |
|
96 | - |
|
97 | - if (!empty($results)) { |
|
98 | - foreach ($results as $form) { |
|
99 | - $choices[$form->id] = $form->title; |
|
100 | - } |
|
101 | - } |
|
102 | - |
|
103 | - return $choices; |
|
104 | - } |
|
105 | - |
|
106 | - /** |
|
107 | - * Add widget to a list of allowed "Hide Until Searched" items. |
|
108 | - * |
|
109 | - * @param array $allowlist Array of widgets to show before a search is performed, if the setting is enabled. |
|
110 | - * |
|
111 | - * @return array |
|
112 | - */ |
|
113 | - public function add_to_allowlist($allowlist) |
|
114 | - { |
|
115 | - $allowlist[] = 'gravityforms'; |
|
116 | - |
|
117 | - return $allowlist; |
|
118 | - } |
|
119 | - |
|
120 | - /** |
|
121 | - * @param array $widget_args |
|
122 | - * @param string $content |
|
123 | - * @param string $context |
|
124 | - */ |
|
125 | - public function render_frontend($widget_args, $content = '', $context = '') |
|
126 | - { |
|
127 | - if (!$this->pre_render_frontend()) { |
|
128 | - return; |
|
129 | - } |
|
130 | - |
|
131 | - $form_id = \GV\Utils::get($widget_args, 'widget_form_id', \GV\Utils::get($widget_args, 'form_id')); |
|
132 | - |
|
133 | - if (empty($form_id)) { |
|
134 | - return; |
|
135 | - } |
|
136 | - |
|
137 | - $title = \GV\Utils::get($widget_args, 'title'); |
|
138 | - $description = \GV\Utils::get($widget_args, 'description'); |
|
139 | - $field_values = \GV\Utils::get($widget_args, 'field_values'); |
|
140 | - $ajax = \GV\Utils::get($widget_args, 'ajax'); |
|
141 | - |
|
142 | - gravity_form($form_id, !empty($title), !empty($description), false, $field_values, $ajax); |
|
143 | - |
|
144 | - // If the form has been submitted, show the confirmation above the form, then show the form again below. |
|
145 | - if (isset(GFFormDisplay::$submission[$form_id])) { |
|
146 | - unset(GFFormDisplay::$submission[$form_id]); |
|
147 | - |
|
148 | - gravity_form($form_id, !empty($title), !empty($description), false, $field_values, $ajax); |
|
149 | - } |
|
150 | - } |
|
10 | + public $icon = 'data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTAwJSIgaGVpZ2h0PSIxMDAlIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCA1MDguMyA1NTkuNSIgZm9jdXNhYmxlPSJmYWxzZSIgYXJpYS1oaWRkZW49InRydWUiIGNsYXNzPSJkYXNoaWNvbiBkYXNoaWNvbi1ncmF2aXR5Zm9ybXMiIHJvbGU9ImltZyI+PGc+PHBhdGggY2xhc3M9InN0MCIgZD0iTTQ2OCwxMDkuOEwyOTQuNCw5LjZjLTIyLjEtMTIuOC01OC40LTEyLjgtODAuNSwwTDQwLjMsMTA5LjhDMTguMiwxMjIuNiwwLDE1NCwwLDE3OS41VjM4MAljMCwyNS42LDE4LjEsNTYuOSw0MC4zLDY5LjdsMTczLjYsMTAwLjJjMjIuMSwxMi44LDU4LjQsMTIuOCw4MC41LDBMNDY4LDQ0OS44YzIyLjItMTIuOCw0MC4zLTQ0LjIsNDAuMy02OS43VjE3OS42CUM1MDguMywxNTQsNDkwLjIsMTIyLjYsNDY4LDEwOS44eiBNMzk5LjMsMjQ0LjRsLTE5NS4xLDBjLTExLDAtMTkuMiwzLjItMjUuNiwxMGMtMTQuMiwxNS4xLTE4LjIsNDQuNC0xOS4zLDYwLjdIMzQ4di0yNi40aDQ5LjkJdjc2LjNIMTExLjNsLTEuOC0yM2MtMC4zLTMuMy01LjktODAuNywzMi44LTEyMS45YzE2LjEtMTcuMSwzNy4xLTI1LjgsNjIuNC0yNS44aDE5NC43VjI0NC40eiI+PC9wYXRoPjwvZz48L3N2Zz4='; |
|
11 | + |
|
12 | + /** |
|
13 | + * Does this get displayed on a single entry? |
|
14 | + * |
|
15 | + * @var bool |
|
16 | + */ |
|
17 | + protected $show_on_single = true; |
|
18 | + |
|
19 | + public function __construct() |
|
20 | + { |
|
21 | + // Initialize widget in the frontend or when editing a View/performing widget AJAX action |
|
22 | + $doing_ajax = defined('DOING_AJAX') && DOING_AJAX && 'gv_field_options' === \GV\Utils::_POST('action'); |
|
23 | + $editing_view = 'edit' === \GV\Utils::_GET('action') && 'gravityview' === get_post_type(\GV\Utils::_GET('post')); |
|
24 | + $is_frontend = gravityview()->request->is_frontend(); |
|
25 | + |
|
26 | + if (!$doing_ajax && !$editing_view && !$is_frontend) { |
|
27 | + return; |
|
28 | + } |
|
29 | + |
|
30 | + $this->widget_description = __('Display a Gravity Forms form.', 'gravityview'); |
|
31 | + |
|
32 | + $default_values = [ |
|
33 | + 'header' => 1, |
|
34 | + 'footer' => 1, |
|
35 | + ]; |
|
36 | + |
|
37 | + $settings = [ |
|
38 | + 'widget_form_id' => [ |
|
39 | + 'type' => 'select', |
|
40 | + 'label' => __('Form to display', 'gravityview'), |
|
41 | + 'value' => '', |
|
42 | + 'options' => $this->_get_form_choices(), |
|
43 | + ], |
|
44 | + 'title' => [ |
|
45 | + 'type' => 'checkbox', |
|
46 | + 'label' => __('Show form title?', 'gravityview'), |
|
47 | + 'value' => 1, |
|
48 | + ], |
|
49 | + 'description' => [ |
|
50 | + 'type' => 'checkbox', |
|
51 | + 'label' => __('Show form description?', 'gravityview'), |
|
52 | + 'value' => 1, |
|
53 | + ], |
|
54 | + 'ajax' => [ |
|
55 | + 'type' => 'checkbox', |
|
56 | + 'label' => __('Enable AJAX', 'gravityview'), |
|
57 | + 'desc' => '', |
|
58 | + 'value' => 1, |
|
59 | + ], |
|
60 | + 'field_values' => [ |
|
61 | + 'type' => 'text', |
|
62 | + 'class' => 'code widefat', |
|
63 | + 'label' => __('Field value parameters', 'gravityview'), |
|
64 | + 'desc' => '<a href="https://docs.gravityforms.com/using-dynamic-population/" rel="external">'.esc_html__('Learn how to dynamically populate a field.', 'gravityview').'</a>', |
|
65 | + 'value' => '', |
|
66 | + ], |
|
67 | + ]; |
|
68 | + |
|
69 | + add_filter('gravityview/widget/hide_until_searched/allowlist', [$this, 'add_to_allowlist']); |
|
70 | + |
|
71 | + parent::__construct(__('Gravity Forms', 'gravityview'), 'gravityforms', $default_values, $settings); |
|
72 | + } |
|
73 | + |
|
74 | + /** |
|
75 | + * Returns an array of active forms to show as choices for the widget. |
|
76 | + * |
|
77 | + * @since 2.9.0.1 |
|
78 | + * |
|
79 | + * @return array Array with key set to Form ID => Form Title, with `0` as default placeholder. |
|
80 | + */ |
|
81 | + private function _get_form_choices() |
|
82 | + { |
|
83 | + $choices = [ |
|
84 | + 0 => '— '.esc_html__('list of forms', 'gravityview').'—', |
|
85 | + ]; |
|
86 | + |
|
87 | + if (!class_exists('GFAPI')) { |
|
88 | + return $choices; |
|
89 | + } |
|
90 | + |
|
91 | + global $wpdb; |
|
92 | + |
|
93 | + $table = GFFormsModel::get_form_table_name(); |
|
94 | + |
|
95 | + $results = $wpdb->get_results("SELECT id, title FROM ${table} WHERE is_active = 1"); |
|
96 | + |
|
97 | + if (!empty($results)) { |
|
98 | + foreach ($results as $form) { |
|
99 | + $choices[$form->id] = $form->title; |
|
100 | + } |
|
101 | + } |
|
102 | + |
|
103 | + return $choices; |
|
104 | + } |
|
105 | + |
|
106 | + /** |
|
107 | + * Add widget to a list of allowed "Hide Until Searched" items. |
|
108 | + * |
|
109 | + * @param array $allowlist Array of widgets to show before a search is performed, if the setting is enabled. |
|
110 | + * |
|
111 | + * @return array |
|
112 | + */ |
|
113 | + public function add_to_allowlist($allowlist) |
|
114 | + { |
|
115 | + $allowlist[] = 'gravityforms'; |
|
116 | + |
|
117 | + return $allowlist; |
|
118 | + } |
|
119 | + |
|
120 | + /** |
|
121 | + * @param array $widget_args |
|
122 | + * @param string $content |
|
123 | + * @param string $context |
|
124 | + */ |
|
125 | + public function render_frontend($widget_args, $content = '', $context = '') |
|
126 | + { |
|
127 | + if (!$this->pre_render_frontend()) { |
|
128 | + return; |
|
129 | + } |
|
130 | + |
|
131 | + $form_id = \GV\Utils::get($widget_args, 'widget_form_id', \GV\Utils::get($widget_args, 'form_id')); |
|
132 | + |
|
133 | + if (empty($form_id)) { |
|
134 | + return; |
|
135 | + } |
|
136 | + |
|
137 | + $title = \GV\Utils::get($widget_args, 'title'); |
|
138 | + $description = \GV\Utils::get($widget_args, 'description'); |
|
139 | + $field_values = \GV\Utils::get($widget_args, 'field_values'); |
|
140 | + $ajax = \GV\Utils::get($widget_args, 'ajax'); |
|
141 | + |
|
142 | + gravity_form($form_id, !empty($title), !empty($description), false, $field_values, $ajax); |
|
143 | + |
|
144 | + // If the form has been submitted, show the confirmation above the form, then show the form again below. |
|
145 | + if (isset(GFFormDisplay::$submission[$form_id])) { |
|
146 | + unset(GFFormDisplay::$submission[$form_id]); |
|
147 | + |
|
148 | + gravity_form($form_id, !empty($title), !empty($description), false, $field_values, $ajax); |
|
149 | + } |
|
150 | + } |
|
151 | 151 | } |
152 | 152 | |
153 | 153 | new GravityView_Widget_Gravity_Forms(); |
@@ -19,15 +19,15 @@ discard block |
||
19 | 19 | public function __construct() |
20 | 20 | { |
21 | 21 | // Initialize widget in the frontend or when editing a View/performing widget AJAX action |
22 | - $doing_ajax = defined('DOING_AJAX') && DOING_AJAX && 'gv_field_options' === \GV\Utils::_POST('action'); |
|
23 | - $editing_view = 'edit' === \GV\Utils::_GET('action') && 'gravityview' === get_post_type(\GV\Utils::_GET('post')); |
|
22 | + $doing_ajax = defined( 'DOING_AJAX' ) && DOING_AJAX && 'gv_field_options' === \GV\Utils::_POST( 'action' ); |
|
23 | + $editing_view = 'edit' === \GV\Utils::_GET( 'action' ) && 'gravityview' === get_post_type( \GV\Utils::_GET( 'post' ) ); |
|
24 | 24 | $is_frontend = gravityview()->request->is_frontend(); |
25 | 25 | |
26 | - if (!$doing_ajax && !$editing_view && !$is_frontend) { |
|
26 | + if ( ! $doing_ajax && ! $editing_view && ! $is_frontend ) { |
|
27 | 27 | return; |
28 | 28 | } |
29 | 29 | |
30 | - $this->widget_description = __('Display a Gravity Forms form.', 'gravityview'); |
|
30 | + $this->widget_description = __( 'Display a Gravity Forms form.', 'gravityview' ); |
|
31 | 31 | |
32 | 32 | $default_values = [ |
33 | 33 | 'header' => 1, |
@@ -37,38 +37,38 @@ discard block |
||
37 | 37 | $settings = [ |
38 | 38 | 'widget_form_id' => [ |
39 | 39 | 'type' => 'select', |
40 | - 'label' => __('Form to display', 'gravityview'), |
|
40 | + 'label' => __( 'Form to display', 'gravityview' ), |
|
41 | 41 | 'value' => '', |
42 | 42 | 'options' => $this->_get_form_choices(), |
43 | 43 | ], |
44 | 44 | 'title' => [ |
45 | 45 | 'type' => 'checkbox', |
46 | - 'label' => __('Show form title?', 'gravityview'), |
|
46 | + 'label' => __( 'Show form title?', 'gravityview' ), |
|
47 | 47 | 'value' => 1, |
48 | 48 | ], |
49 | 49 | 'description' => [ |
50 | 50 | 'type' => 'checkbox', |
51 | - 'label' => __('Show form description?', 'gravityview'), |
|
51 | + 'label' => __( 'Show form description?', 'gravityview' ), |
|
52 | 52 | 'value' => 1, |
53 | 53 | ], |
54 | 54 | 'ajax' => [ |
55 | 55 | 'type' => 'checkbox', |
56 | - 'label' => __('Enable AJAX', 'gravityview'), |
|
56 | + 'label' => __( 'Enable AJAX', 'gravityview' ), |
|
57 | 57 | 'desc' => '', |
58 | 58 | 'value' => 1, |
59 | 59 | ], |
60 | 60 | 'field_values' => [ |
61 | 61 | 'type' => 'text', |
62 | 62 | 'class' => 'code widefat', |
63 | - 'label' => __('Field value parameters', 'gravityview'), |
|
64 | - 'desc' => '<a href="https://docs.gravityforms.com/using-dynamic-population/" rel="external">'.esc_html__('Learn how to dynamically populate a field.', 'gravityview').'</a>', |
|
63 | + 'label' => __( 'Field value parameters', 'gravityview' ), |
|
64 | + 'desc' => '<a href="https://docs.gravityforms.com/using-dynamic-population/" rel="external">' . esc_html__( 'Learn how to dynamically populate a field.', 'gravityview' ) . '</a>', |
|
65 | 65 | 'value' => '', |
66 | 66 | ], |
67 | 67 | ]; |
68 | 68 | |
69 | - add_filter('gravityview/widget/hide_until_searched/allowlist', [$this, 'add_to_allowlist']); |
|
69 | + add_filter( 'gravityview/widget/hide_until_searched/allowlist', [ $this, 'add_to_allowlist' ] ); |
|
70 | 70 | |
71 | - parent::__construct(__('Gravity Forms', 'gravityview'), 'gravityforms', $default_values, $settings); |
|
71 | + parent::__construct( __( 'Gravity Forms', 'gravityview' ), 'gravityforms', $default_values, $settings ); |
|
72 | 72 | } |
73 | 73 | |
74 | 74 | /** |
@@ -81,10 +81,10 @@ discard block |
||
81 | 81 | private function _get_form_choices() |
82 | 82 | { |
83 | 83 | $choices = [ |
84 | - 0 => '— '.esc_html__('list of forms', 'gravityview').'—', |
|
84 | + 0 => '— ' . esc_html__( 'list of forms', 'gravityview' ) . '—', |
|
85 | 85 | ]; |
86 | 86 | |
87 | - if (!class_exists('GFAPI')) { |
|
87 | + if ( ! class_exists( 'GFAPI' ) ) { |
|
88 | 88 | return $choices; |
89 | 89 | } |
90 | 90 | |
@@ -92,11 +92,11 @@ discard block |
||
92 | 92 | |
93 | 93 | $table = GFFormsModel::get_form_table_name(); |
94 | 94 | |
95 | - $results = $wpdb->get_results("SELECT id, title FROM ${table} WHERE is_active = 1"); |
|
95 | + $results = $wpdb->get_results( "SELECT id, title FROM ${table} WHERE is_active = 1" ); |
|
96 | 96 | |
97 | - if (!empty($results)) { |
|
98 | - foreach ($results as $form) { |
|
99 | - $choices[$form->id] = $form->title; |
|
97 | + if ( ! empty( $results ) ) { |
|
98 | + foreach ( $results as $form ) { |
|
99 | + $choices[ $form->id ] = $form->title; |
|
100 | 100 | } |
101 | 101 | } |
102 | 102 | |
@@ -110,9 +110,9 @@ discard block |
||
110 | 110 | * |
111 | 111 | * @return array |
112 | 112 | */ |
113 | - public function add_to_allowlist($allowlist) |
|
113 | + public function add_to_allowlist( $allowlist ) |
|
114 | 114 | { |
115 | - $allowlist[] = 'gravityforms'; |
|
115 | + $allowlist[ ] = 'gravityforms'; |
|
116 | 116 | |
117 | 117 | return $allowlist; |
118 | 118 | } |
@@ -122,30 +122,30 @@ discard block |
||
122 | 122 | * @param string $content |
123 | 123 | * @param string $context |
124 | 124 | */ |
125 | - public function render_frontend($widget_args, $content = '', $context = '') |
|
125 | + public function render_frontend( $widget_args, $content = '', $context = '' ) |
|
126 | 126 | { |
127 | - if (!$this->pre_render_frontend()) { |
|
127 | + if ( ! $this->pre_render_frontend() ) { |
|
128 | 128 | return; |
129 | 129 | } |
130 | 130 | |
131 | - $form_id = \GV\Utils::get($widget_args, 'widget_form_id', \GV\Utils::get($widget_args, 'form_id')); |
|
131 | + $form_id = \GV\Utils::get( $widget_args, 'widget_form_id', \GV\Utils::get( $widget_args, 'form_id' ) ); |
|
132 | 132 | |
133 | - if (empty($form_id)) { |
|
133 | + if ( empty( $form_id ) ) { |
|
134 | 134 | return; |
135 | 135 | } |
136 | 136 | |
137 | - $title = \GV\Utils::get($widget_args, 'title'); |
|
138 | - $description = \GV\Utils::get($widget_args, 'description'); |
|
139 | - $field_values = \GV\Utils::get($widget_args, 'field_values'); |
|
140 | - $ajax = \GV\Utils::get($widget_args, 'ajax'); |
|
137 | + $title = \GV\Utils::get( $widget_args, 'title' ); |
|
138 | + $description = \GV\Utils::get( $widget_args, 'description' ); |
|
139 | + $field_values = \GV\Utils::get( $widget_args, 'field_values' ); |
|
140 | + $ajax = \GV\Utils::get( $widget_args, 'ajax' ); |
|
141 | 141 | |
142 | - gravity_form($form_id, !empty($title), !empty($description), false, $field_values, $ajax); |
|
142 | + gravity_form( $form_id, ! empty( $title ), ! empty( $description ), false, $field_values, $ajax ); |
|
143 | 143 | |
144 | 144 | // If the form has been submitted, show the confirmation above the form, then show the form again below. |
145 | - if (isset(GFFormDisplay::$submission[$form_id])) { |
|
146 | - unset(GFFormDisplay::$submission[$form_id]); |
|
145 | + if ( isset( GFFormDisplay::$submission[ $form_id ] ) ) { |
|
146 | + unset( GFFormDisplay::$submission[ $form_id ] ); |
|
147 | 147 | |
148 | - gravity_form($form_id, !empty($title), !empty($description), false, $field_values, $ajax); |
|
148 | + gravity_form( $form_id, ! empty( $title ), ! empty( $description ), false, $field_values, $ajax ); |
|
149 | 149 | } |
150 | 150 | } |
151 | 151 | } |
@@ -16,8 +16,7 @@ discard block |
||
16 | 16 | */ |
17 | 17 | protected $show_on_single = true; |
18 | 18 | |
19 | - public function __construct() |
|
20 | - { |
|
19 | + public function __construct() { |
|
21 | 20 | // Initialize widget in the frontend or when editing a View/performing widget AJAX action |
22 | 21 | $doing_ajax = defined('DOING_AJAX') && DOING_AJAX && 'gv_field_options' === \GV\Utils::_POST('action'); |
23 | 22 | $editing_view = 'edit' === \GV\Utils::_GET('action') && 'gravityview' === get_post_type(\GV\Utils::_GET('post')); |
@@ -78,8 +77,7 @@ discard block |
||
78 | 77 | * |
79 | 78 | * @return array Array with key set to Form ID => Form Title, with `0` as default placeholder. |
80 | 79 | */ |
81 | - private function _get_form_choices() |
|
82 | - { |
|
80 | + private function _get_form_choices() { |
|
83 | 81 | $choices = [ |
84 | 82 | 0 => '— '.esc_html__('list of forms', 'gravityview').'—', |
85 | 83 | ]; |
@@ -110,8 +108,7 @@ discard block |
||
110 | 108 | * |
111 | 109 | * @return array |
112 | 110 | */ |
113 | - public function add_to_allowlist($allowlist) |
|
114 | - { |
|
111 | + public function add_to_allowlist($allowlist) { |
|
115 | 112 | $allowlist[] = 'gravityforms'; |
116 | 113 | |
117 | 114 | return $allowlist; |
@@ -122,8 +119,7 @@ discard block |
||
122 | 119 | * @param string $content |
123 | 120 | * @param string $context |
124 | 121 | */ |
125 | - public function render_frontend($widget_args, $content = '', $context = '') |
|
126 | - { |
|
122 | + public function render_frontend($widget_args, $content = '', $context = '') { |
|
127 | 123 | if (!$this->pre_render_frontend()) { |
128 | 124 | return; |
129 | 125 | } |
@@ -14,48 +14,48 @@ |
||
14 | 14 | */ |
15 | 15 | class GravityView_Post_Types |
16 | 16 | { |
17 | - public function __construct() |
|
18 | - { |
|
19 | - } |
|
17 | + public function __construct() |
|
18 | + { |
|
19 | + } |
|
20 | 20 | |
21 | - /** |
|
22 | - * Init plugin components such as register own custom post types. |
|
23 | - * |
|
24 | - * @deprecated |
|
25 | - * @see \GV\View::register_post_type |
|
26 | - * |
|
27 | - * @return void |
|
28 | - */ |
|
29 | - public static function init_post_types() |
|
30 | - { |
|
31 | - \GV\View::register_post_type(); |
|
32 | - } |
|
21 | + /** |
|
22 | + * Init plugin components such as register own custom post types. |
|
23 | + * |
|
24 | + * @deprecated |
|
25 | + * @see \GV\View::register_post_type |
|
26 | + * |
|
27 | + * @return void |
|
28 | + */ |
|
29 | + public static function init_post_types() |
|
30 | + { |
|
31 | + \GV\View::register_post_type(); |
|
32 | + } |
|
33 | 33 | |
34 | - /** |
|
35 | - * Register rewrite rules to capture the single entry view. |
|
36 | - * |
|
37 | - * @deprecated |
|
38 | - * @see \GV\Entry::add_rewrite_endpoint |
|
39 | - * |
|
40 | - * @return void |
|
41 | - */ |
|
42 | - public static function init_rewrite() |
|
43 | - { |
|
44 | - \GV\Entry::add_rewrite_endpoint(); |
|
45 | - } |
|
34 | + /** |
|
35 | + * Register rewrite rules to capture the single entry view. |
|
36 | + * |
|
37 | + * @deprecated |
|
38 | + * @see \GV\Entry::add_rewrite_endpoint |
|
39 | + * |
|
40 | + * @return void |
|
41 | + */ |
|
42 | + public static function init_rewrite() |
|
43 | + { |
|
44 | + \GV\Entry::add_rewrite_endpoint(); |
|
45 | + } |
|
46 | 46 | |
47 | - /** |
|
48 | - * Return the query var / end point name for the entry. |
|
49 | - * |
|
50 | - * @deprecated |
|
51 | - * @see \GV\Entry::get_endpoint_name |
|
52 | - * |
|
53 | - * @return string Default: "entry" |
|
54 | - */ |
|
55 | - public static function get_entry_var_name() |
|
56 | - { |
|
57 | - return \GV\Entry::get_endpoint_name(); |
|
58 | - } |
|
47 | + /** |
|
48 | + * Return the query var / end point name for the entry. |
|
49 | + * |
|
50 | + * @deprecated |
|
51 | + * @see \GV\Entry::get_endpoint_name |
|
52 | + * |
|
53 | + * @return string Default: "entry" |
|
54 | + */ |
|
55 | + public static function get_entry_var_name() |
|
56 | + { |
|
57 | + return \GV\Entry::get_endpoint_name(); |
|
58 | + } |
|
59 | 59 | } |
60 | 60 | |
61 | 61 | new GravityView_Post_Types(); |
@@ -12,10 +12,8 @@ discard block |
||
12 | 12 | * @deprecated |
13 | 13 | * @since 1.0.9 |
14 | 14 | */ |
15 | -class GravityView_Post_Types |
|
16 | -{ |
|
17 | - public function __construct() |
|
18 | - { |
|
15 | +class GravityView_Post_Types { |
|
16 | + public function __construct() { |
|
19 | 17 | } |
20 | 18 | |
21 | 19 | /** |
@@ -26,8 +24,7 @@ discard block |
||
26 | 24 | * |
27 | 25 | * @return void |
28 | 26 | */ |
29 | - public static function init_post_types() |
|
30 | - { |
|
27 | + public static function init_post_types() { |
|
31 | 28 | \GV\View::register_post_type(); |
32 | 29 | } |
33 | 30 | |
@@ -39,8 +36,7 @@ discard block |
||
39 | 36 | * |
40 | 37 | * @return void |
41 | 38 | */ |
42 | - public static function init_rewrite() |
|
43 | - { |
|
39 | + public static function init_rewrite() { |
|
44 | 40 | \GV\Entry::add_rewrite_endpoint(); |
45 | 41 | } |
46 | 42 | |
@@ -52,8 +48,7 @@ discard block |
||
52 | 48 | * |
53 | 49 | * @return string Default: "entry" |
54 | 50 | */ |
55 | - public static function get_entry_var_name() |
|
56 | - { |
|
51 | + public static function get_entry_var_name() { |
|
57 | 52 | return \GV\Entry::get_endpoint_name(); |
58 | 53 | } |
59 | 54 | } |
@@ -4,40 +4,40 @@ |
||
4 | 4 | */ |
5 | 5 | class GravityView_Field_Quiz_Score extends GravityView_Field |
6 | 6 | { |
7 | - public $name = 'quiz_score'; |
|
7 | + public $name = 'quiz_score'; |
|
8 | 8 | |
9 | - public $group = 'advanced'; |
|
9 | + public $group = 'advanced'; |
|
10 | 10 | |
11 | - public $is_searchable = true; |
|
11 | + public $is_searchable = true; |
|
12 | 12 | |
13 | - public $search_operators = ['is', 'isnot', 'greater_than', 'less_than']; |
|
13 | + public $search_operators = ['is', 'isnot', 'greater_than', 'less_than']; |
|
14 | 14 | |
15 | - public $icon = 'dashicons-forms'; |
|
15 | + public $icon = 'dashicons-forms'; |
|
16 | 16 | |
17 | - public function __construct() |
|
18 | - { |
|
19 | - $this->label = esc_html__('Quiz Score', 'gravityview'); |
|
20 | - parent::__construct(); |
|
21 | - } |
|
17 | + public function __construct() |
|
18 | + { |
|
19 | + $this->label = esc_html__('Quiz Score', 'gravityview'); |
|
20 | + parent::__construct(); |
|
21 | + } |
|
22 | 22 | |
23 | - public function field_options($field_options, $template_id, $field_id, $context, $input_type, $form_id) |
|
24 | - { |
|
25 | - if ('edit' === $context) { |
|
26 | - return $field_options; |
|
27 | - } |
|
23 | + public function field_options($field_options, $template_id, $field_id, $context, $input_type, $form_id) |
|
24 | + { |
|
25 | + if ('edit' === $context) { |
|
26 | + return $field_options; |
|
27 | + } |
|
28 | 28 | |
29 | - $new_fields = [ |
|
30 | - 'quiz_use_max_score' => [ |
|
31 | - 'type' => 'checkbox', |
|
32 | - 'label' => __('Show Max Score?', 'gravityview'), |
|
33 | - 'desc' => __('Display score as the a fraction: "[score]/[max score]". If unchecked, will display score.', 'gravityview'), |
|
34 | - 'value' => true, |
|
35 | - 'merge_tags' => false, |
|
36 | - ], |
|
37 | - ]; |
|
29 | + $new_fields = [ |
|
30 | + 'quiz_use_max_score' => [ |
|
31 | + 'type' => 'checkbox', |
|
32 | + 'label' => __('Show Max Score?', 'gravityview'), |
|
33 | + 'desc' => __('Display score as the a fraction: "[score]/[max score]". If unchecked, will display score.', 'gravityview'), |
|
34 | + 'value' => true, |
|
35 | + 'merge_tags' => false, |
|
36 | + ], |
|
37 | + ]; |
|
38 | 38 | |
39 | - return $new_fields + $field_options; |
|
40 | - } |
|
39 | + return $new_fields + $field_options; |
|
40 | + } |
|
41 | 41 | } |
42 | 42 | |
43 | 43 | new GravityView_Field_Quiz_Score(); |
@@ -10,27 +10,27 @@ |
||
10 | 10 | |
11 | 11 | public $is_searchable = true; |
12 | 12 | |
13 | - public $search_operators = ['is', 'isnot', 'greater_than', 'less_than']; |
|
13 | + public $search_operators = [ 'is', 'isnot', 'greater_than', 'less_than' ]; |
|
14 | 14 | |
15 | 15 | public $icon = 'dashicons-forms'; |
16 | 16 | |
17 | 17 | public function __construct() |
18 | 18 | { |
19 | - $this->label = esc_html__('Quiz Score', 'gravityview'); |
|
19 | + $this->label = esc_html__( 'Quiz Score', 'gravityview' ); |
|
20 | 20 | parent::__construct(); |
21 | 21 | } |
22 | 22 | |
23 | - public function field_options($field_options, $template_id, $field_id, $context, $input_type, $form_id) |
|
23 | + public function field_options( $field_options, $template_id, $field_id, $context, $input_type, $form_id ) |
|
24 | 24 | { |
25 | - if ('edit' === $context) { |
|
25 | + if ( 'edit' === $context ) { |
|
26 | 26 | return $field_options; |
27 | 27 | } |
28 | 28 | |
29 | 29 | $new_fields = [ |
30 | 30 | 'quiz_use_max_score' => [ |
31 | 31 | 'type' => 'checkbox', |
32 | - 'label' => __('Show Max Score?', 'gravityview'), |
|
33 | - 'desc' => __('Display score as the a fraction: "[score]/[max score]". If unchecked, will display score.', 'gravityview'), |
|
32 | + 'label' => __( 'Show Max Score?', 'gravityview' ), |
|
33 | + 'desc' => __( 'Display score as the a fraction: "[score]/[max score]". If unchecked, will display score.', 'gravityview' ), |
|
34 | 34 | 'value' => true, |
35 | 35 | 'merge_tags' => false, |
36 | 36 | ], |
@@ -2,8 +2,7 @@ discard block |
||
2 | 2 | /** |
3 | 3 | * @file class-gravityview-field-gquiz_score.php |
4 | 4 | */ |
5 | -class GravityView_Field_Quiz_Score extends GravityView_Field |
|
6 | -{ |
|
5 | +class GravityView_Field_Quiz_Score extends GravityView_Field { |
|
7 | 6 | public $name = 'quiz_score'; |
8 | 7 | |
9 | 8 | public $group = 'advanced'; |
@@ -14,14 +13,12 @@ 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__('Quiz Score', 'gravityview'); |
20 | 18 | parent::__construct(); |
21 | 19 | } |
22 | 20 | |
23 | - public function field_options($field_options, $template_id, $field_id, $context, $input_type, $form_id) |
|
24 | - { |
|
21 | + public function field_options($field_options, $template_id, $field_id, $context, $input_type, $form_id) { |
|
25 | 22 | if ('edit' === $context) { |
26 | 23 | return $field_options; |
27 | 24 | } |
@@ -4,81 +4,81 @@ |
||
4 | 4 | */ |
5 | 5 | class GravityView_Field_Hidden extends GravityView_Field |
6 | 6 | { |
7 | - public $name = 'hidden'; |
|
8 | - |
|
9 | - public $is_searchable = true; |
|
10 | - |
|
11 | - public $search_operators = ['contains', 'is', 'isnot', 'starts_with', 'ends_with']; |
|
12 | - |
|
13 | - public $_gf_field_class_name = 'GF_Field_Hidden'; |
|
14 | - |
|
15 | - public $group = 'standard'; |
|
16 | - |
|
17 | - public $icon = 'dashicons-hidden'; |
|
18 | - |
|
19 | - public function __construct() |
|
20 | - { |
|
21 | - $this->label = esc_html__('Hidden', 'gravityview'); |
|
22 | - |
|
23 | - $this->edit_entry_add_hooks(); |
|
24 | - |
|
25 | - parent::__construct(); |
|
26 | - } |
|
27 | - |
|
28 | - /** |
|
29 | - * Add Edit Entry hooks. |
|
30 | - * |
|
31 | - * @since 1.17 |
|
32 | - * |
|
33 | - * @return void |
|
34 | - */ |
|
35 | - private function edit_entry_add_hooks() |
|
36 | - { |
|
37 | - add_filter('gravityview/edit_entry/form_fields', [$this, 'edit_entry_fix_hidden_fields']); |
|
38 | - } |
|
39 | - |
|
40 | - /** |
|
41 | - * Convert Hidden fields to be Text fields in Edit Entry. |
|
42 | - * |
|
43 | - * @since 1.9.2 |
|
44 | - * @since 1.17 Moved to GravityView_Field_Hidden class |
|
45 | - * |
|
46 | - * @param GF_Field[] $fields Array of fields to be shown on the Edit Entry screen |
|
47 | - * |
|
48 | - * @return GF_Field[] Array of fields, with any hidden fields replaced with text fields |
|
49 | - */ |
|
50 | - public function edit_entry_fix_hidden_fields($fields) |
|
51 | - { |
|
52 | - |
|
53 | - /** @var GF_Field $field */ |
|
54 | - foreach ($fields as &$field) { |
|
55 | - if ('hidden' === $field->type) { |
|
56 | - |
|
57 | - /** |
|
58 | - * @filter `gravityview/edit_entry/reveal_hidden_field` Convert Hidden fields into Text fields on Edit Entry |
|
59 | - * |
|
60 | - * @since 1.22.6 |
|
61 | - * @since 2.7 Changed default value to `false` from `true` |
|
62 | - * |
|
63 | - * @param bool $reveal_hidden_field True: Convert the hidden field to text; False: Leave hidden |
|
64 | - * @param GF_Field_Hidden $field The field in question |
|
65 | - */ |
|
66 | - $reveal_hidden_field = apply_filters('gravityview/edit_entry/reveal_hidden_field', false, $field); |
|
67 | - |
|
68 | - if (!$reveal_hidden_field) { |
|
69 | - continue; |
|
70 | - } |
|
71 | - |
|
72 | - // Replace GF_Field_Hidden with GF_Field_Text, copying all the data from $field |
|
73 | - $field = new GF_Field_Text($field); |
|
74 | - |
|
75 | - // Everything is copied from $field, so we need to manually set the type |
|
76 | - $field->type = 'text'; |
|
77 | - } |
|
78 | - } |
|
79 | - |
|
80 | - return $fields; |
|
81 | - } |
|
7 | + public $name = 'hidden'; |
|
8 | + |
|
9 | + public $is_searchable = true; |
|
10 | + |
|
11 | + public $search_operators = ['contains', 'is', 'isnot', 'starts_with', 'ends_with']; |
|
12 | + |
|
13 | + public $_gf_field_class_name = 'GF_Field_Hidden'; |
|
14 | + |
|
15 | + public $group = 'standard'; |
|
16 | + |
|
17 | + public $icon = 'dashicons-hidden'; |
|
18 | + |
|
19 | + public function __construct() |
|
20 | + { |
|
21 | + $this->label = esc_html__('Hidden', 'gravityview'); |
|
22 | + |
|
23 | + $this->edit_entry_add_hooks(); |
|
24 | + |
|
25 | + parent::__construct(); |
|
26 | + } |
|
27 | + |
|
28 | + /** |
|
29 | + * Add Edit Entry hooks. |
|
30 | + * |
|
31 | + * @since 1.17 |
|
32 | + * |
|
33 | + * @return void |
|
34 | + */ |
|
35 | + private function edit_entry_add_hooks() |
|
36 | + { |
|
37 | + add_filter('gravityview/edit_entry/form_fields', [$this, 'edit_entry_fix_hidden_fields']); |
|
38 | + } |
|
39 | + |
|
40 | + /** |
|
41 | + * Convert Hidden fields to be Text fields in Edit Entry. |
|
42 | + * |
|
43 | + * @since 1.9.2 |
|
44 | + * @since 1.17 Moved to GravityView_Field_Hidden class |
|
45 | + * |
|
46 | + * @param GF_Field[] $fields Array of fields to be shown on the Edit Entry screen |
|
47 | + * |
|
48 | + * @return GF_Field[] Array of fields, with any hidden fields replaced with text fields |
|
49 | + */ |
|
50 | + public function edit_entry_fix_hidden_fields($fields) |
|
51 | + { |
|
52 | + |
|
53 | + /** @var GF_Field $field */ |
|
54 | + foreach ($fields as &$field) { |
|
55 | + if ('hidden' === $field->type) { |
|
56 | + |
|
57 | + /** |
|
58 | + * @filter `gravityview/edit_entry/reveal_hidden_field` Convert Hidden fields into Text fields on Edit Entry |
|
59 | + * |
|
60 | + * @since 1.22.6 |
|
61 | + * @since 2.7 Changed default value to `false` from `true` |
|
62 | + * |
|
63 | + * @param bool $reveal_hidden_field True: Convert the hidden field to text; False: Leave hidden |
|
64 | + * @param GF_Field_Hidden $field The field in question |
|
65 | + */ |
|
66 | + $reveal_hidden_field = apply_filters('gravityview/edit_entry/reveal_hidden_field', false, $field); |
|
67 | + |
|
68 | + if (!$reveal_hidden_field) { |
|
69 | + continue; |
|
70 | + } |
|
71 | + |
|
72 | + // Replace GF_Field_Hidden with GF_Field_Text, copying all the data from $field |
|
73 | + $field = new GF_Field_Text($field); |
|
74 | + |
|
75 | + // Everything is copied from $field, so we need to manually set the type |
|
76 | + $field->type = 'text'; |
|
77 | + } |
|
78 | + } |
|
79 | + |
|
80 | + return $fields; |
|
81 | + } |
|
82 | 82 | } |
83 | 83 | |
84 | 84 | new GravityView_Field_Hidden(); |
@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | |
9 | 9 | public $is_searchable = true; |
10 | 10 | |
11 | - public $search_operators = ['contains', 'is', 'isnot', 'starts_with', 'ends_with']; |
|
11 | + public $search_operators = [ 'contains', 'is', 'isnot', 'starts_with', 'ends_with' ]; |
|
12 | 12 | |
13 | 13 | public $_gf_field_class_name = 'GF_Field_Hidden'; |
14 | 14 | |
@@ -18,7 +18,7 @@ discard block |
||
18 | 18 | |
19 | 19 | public function __construct() |
20 | 20 | { |
21 | - $this->label = esc_html__('Hidden', 'gravityview'); |
|
21 | + $this->label = esc_html__( 'Hidden', 'gravityview' ); |
|
22 | 22 | |
23 | 23 | $this->edit_entry_add_hooks(); |
24 | 24 | |
@@ -34,7 +34,7 @@ discard block |
||
34 | 34 | */ |
35 | 35 | private function edit_entry_add_hooks() |
36 | 36 | { |
37 | - add_filter('gravityview/edit_entry/form_fields', [$this, 'edit_entry_fix_hidden_fields']); |
|
37 | + add_filter( 'gravityview/edit_entry/form_fields', [ $this, 'edit_entry_fix_hidden_fields' ] ); |
|
38 | 38 | } |
39 | 39 | |
40 | 40 | /** |
@@ -47,12 +47,12 @@ discard block |
||
47 | 47 | * |
48 | 48 | * @return GF_Field[] Array of fields, with any hidden fields replaced with text fields |
49 | 49 | */ |
50 | - public function edit_entry_fix_hidden_fields($fields) |
|
50 | + public function edit_entry_fix_hidden_fields( $fields ) |
|
51 | 51 | { |
52 | 52 | |
53 | 53 | /** @var GF_Field $field */ |
54 | - foreach ($fields as &$field) { |
|
55 | - if ('hidden' === $field->type) { |
|
54 | + foreach ( $fields as &$field ) { |
|
55 | + if ( 'hidden' === $field->type ) { |
|
56 | 56 | |
57 | 57 | /** |
58 | 58 | * @filter `gravityview/edit_entry/reveal_hidden_field` Convert Hidden fields into Text fields on Edit Entry |
@@ -63,14 +63,14 @@ discard block |
||
63 | 63 | * @param bool $reveal_hidden_field True: Convert the hidden field to text; False: Leave hidden |
64 | 64 | * @param GF_Field_Hidden $field The field in question |
65 | 65 | */ |
66 | - $reveal_hidden_field = apply_filters('gravityview/edit_entry/reveal_hidden_field', false, $field); |
|
66 | + $reveal_hidden_field = apply_filters( 'gravityview/edit_entry/reveal_hidden_field', false, $field ); |
|
67 | 67 | |
68 | - if (!$reveal_hidden_field) { |
|
68 | + if ( ! $reveal_hidden_field ) { |
|
69 | 69 | continue; |
70 | 70 | } |
71 | 71 | |
72 | 72 | // Replace GF_Field_Hidden with GF_Field_Text, copying all the data from $field |
73 | - $field = new GF_Field_Text($field); |
|
73 | + $field = new GF_Field_Text( $field ); |
|
74 | 74 | |
75 | 75 | // Everything is copied from $field, so we need to manually set the type |
76 | 76 | $field->type = 'text'; |
@@ -2,8 +2,7 @@ discard block |
||
2 | 2 | /** |
3 | 3 | * @file class-gravityview-field-hidden.php |
4 | 4 | */ |
5 | -class GravityView_Field_Hidden extends GravityView_Field |
|
6 | -{ |
|
5 | +class GravityView_Field_Hidden extends GravityView_Field { |
|
7 | 6 | public $name = 'hidden'; |
8 | 7 | |
9 | 8 | public $is_searchable = true; |
@@ -16,8 +15,7 @@ discard block |
||
16 | 15 | |
17 | 16 | public $icon = 'dashicons-hidden'; |
18 | 17 | |
19 | - public function __construct() |
|
20 | - { |
|
18 | + public function __construct() { |
|
21 | 19 | $this->label = esc_html__('Hidden', 'gravityview'); |
22 | 20 | |
23 | 21 | $this->edit_entry_add_hooks(); |
@@ -32,8 +30,7 @@ discard block |
||
32 | 30 | * |
33 | 31 | * @return void |
34 | 32 | */ |
35 | - private function edit_entry_add_hooks() |
|
36 | - { |
|
33 | + private function edit_entry_add_hooks() { |
|
37 | 34 | add_filter('gravityview/edit_entry/form_fields', [$this, 'edit_entry_fix_hidden_fields']); |
38 | 35 | } |
39 | 36 | |
@@ -47,8 +44,7 @@ discard block |
||
47 | 44 | * |
48 | 45 | * @return GF_Field[] Array of fields, with any hidden fields replaced with text fields |
49 | 46 | */ |
50 | - public function edit_entry_fix_hidden_fields($fields) |
|
51 | - { |
|
47 | + public function edit_entry_fix_hidden_fields($fields) { |
|
52 | 48 | |
53 | 49 | /** @var GF_Field $field */ |
54 | 50 | foreach ($fields as &$field) { |