Conditions | 8 |
Paths | 14 |
Total Lines | 124 |
Code Lines | 73 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
133 | public function form( $instance ) { |
||
134 | |||
135 | // @todo Make compatible with Customizer |
||
136 | if( $this->is_preview() ) { |
||
137 | |||
138 | $warning = sprintf( esc_html__( 'This widget is not configurable from this screen. Please configure it on the %sWidgets page%s.', 'gravityview' ), '<a href="'.admin_url('widgets.php').'">', '</a>' ); |
||
139 | |||
140 | echo wpautop( GravityView_Admin::get_floaty() . $warning ); |
||
141 | |||
142 | return; |
||
143 | } |
||
144 | |||
145 | $instance = wp_parse_args( (array) $instance, self::get_defaults() ); |
||
146 | |||
147 | $title = $instance['title']; |
||
148 | $view_id = $instance['view_id']; |
||
149 | $post_id = $instance['post_id']; |
||
150 | $search_fields = $instance['search_fields']; |
||
151 | $search_clear = $instance['search_clear']; |
||
152 | $search_mode = $instance['search_mode']; |
||
153 | |||
154 | $views = GVCommon::get_all_views(); |
||
155 | |||
156 | // If there are no views set up yet, we get outta here. |
||
157 | if( empty( $views ) ) { ?> |
||
158 | <div id="select_gravityview_view"> |
||
159 | <div class="wrap"><?php echo GravityView_Post_Types::no_views_text(); ?></div> |
||
160 | </div> |
||
161 | <?php return; |
||
162 | } |
||
163 | ?> |
||
164 | |||
165 | <p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:', 'gravityview'); ?> <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo esc_attr( $title ); ?>" /></label></p> |
||
166 | |||
167 | <?php |
||
168 | /** |
||
169 | * Display errors generated for invalid embed IDs |
||
170 | * @see GravityView_View_Data::is_valid_embed_id |
||
171 | */ |
||
172 | if( isset( $instance['updated'] ) && empty( $instance['view_id'] ) ) { |
||
173 | ?> |
||
174 | <div class="error inline hide-on-view-change"> |
||
175 | <p><?php esc_html_e('Please select a View to search.', 'gravityview'); ?></p> |
||
176 | </div> |
||
177 | <?php |
||
178 | unset ( $error ); |
||
179 | } |
||
180 | ?> |
||
181 | |||
182 | <p> |
||
183 | <label for="gravityview_view_id"><?php _e( 'View:', 'gravityview' ); ?></label> |
||
184 | <select id="gravityview_view_id" name="<?php echo $this->get_field_name('view_id'); ?>" class="widefat"> |
||
185 | <option value=""><?php esc_html_e( '— Select a View —', 'gravityview' ); ?></option> |
||
186 | <?php |
||
187 | foreach( $views as $view_option ) { |
||
188 | $title = empty( $view_option->post_title ) ? __('(no title)', 'gravityview') : $view_option->post_title; |
||
189 | echo '<option value="'. $view_option->ID .'" ' . selected( esc_attr( $view_id ), $view_option->ID, false ) . '>'. esc_html( sprintf('%s #%d', $title, $view_option->ID ) ) .'</option>'; |
||
190 | } |
||
191 | ?> |
||
192 | </select> |
||
193 | |||
194 | </p> |
||
195 | |||
196 | <?php |
||
197 | /** |
||
198 | * Display errors generated for invalid embed IDs |
||
199 | * @see GravityView_View_Data::is_valid_embed_id |
||
200 | */ |
||
201 | if( !empty( $instance['error_post_id'] ) ) { |
||
202 | ?> |
||
203 | <div class="error inline"> |
||
204 | <p><?php echo $instance['error_post_id']; ?></p> |
||
205 | </div> |
||
206 | <?php |
||
207 | unset ( $error ); |
||
208 | } |
||
209 | ?> |
||
210 | |||
211 | <p> |
||
212 | <label for="<?php echo $this->get_field_id('post_id'); ?>"><?php esc_html_e( 'If Embedded, Page ID:', 'gravityview' ); ?></label> |
||
213 | <input class="code" size="3" id="<?php echo $this->get_field_id('post_id'); ?>" name="<?php echo $this->get_field_name('post_id'); ?>" type="text" value="<?php echo esc_attr( $post_id ); ?>" /> |
||
214 | <span class="howto"><?php |
||
215 | esc_html_e('To have a search performed on an embedded View, enter the ID of the post or page where the View is embedded.', 'gravityview' ); |
||
216 | echo ' '.gravityview_get_link('http://docs.gravityview.co/article/222-the-search-widget', __('Learn more…', 'gravityview' ), 'target=_blank' ); |
||
217 | ?></span> |
||
218 | </p> |
||
219 | |||
220 | <p> |
||
221 | <label for="<?php echo $this->get_field_id('search_clear'); ?>"><?php esc_html_e( 'Show Clear button', 'gravityview' ); ?>:</label> |
||
222 | <input name="<?php echo $this->get_field_name('search_clear'); ?>" type="hidden" value="0"> |
||
223 | <input id="<?php echo $this->get_field_id('search_clear'); ?>" name="<?php echo $this->get_field_name('search_clear'); ?>" type="checkbox" class="checkbox" value="1" <?php checked( $search_clear, 1, true ); ?>> |
||
224 | </p> |
||
225 | |||
226 | <p> |
||
227 | <label><?php esc_html_e( 'Search Mode', 'gravityview' ); ?>:</label> |
||
228 | <label for="<?php echo $this->get_field_id('search_mode'); ?>_any"> |
||
229 | <input id="<?php echo $this->get_field_id('search_mode'); ?>_any" name="<?php echo $this->get_field_name('search_mode'); ?>" type="radio" class="radio" value="any" <?php checked( $search_mode, 'any', true ); ?>> |
||
230 | <?php esc_html_e( 'Match Any Fields', 'gravityview' ); ?> |
||
231 | </label> |
||
232 | <label for="<?php echo $this->get_field_id('search_mode'); ?>_all"> |
||
233 | <input id="<?php echo $this->get_field_id('search_mode'); ?>_all" name="<?php echo $this->get_field_name('search_mode'); ?>" type="radio" class="radio" value="all" <?php checked( $search_mode, 'all', true ); ?>> |
||
234 | <?php esc_html_e( 'Match All Fields', 'gravityview' ); ?> |
||
235 | </label> |
||
236 | <span class="howto"><?php esc_html_e('Should search results match all search fields, or any?', 'gravityview' ); ?></span |
||
237 | </p> |
||
238 | |||
239 | <hr /> |
||
240 | |||
241 | <?php // @todo: move style to CSS ?> |
||
242 | <div style="margin-bottom: 1em;"> |
||
243 | <label class="screen-reader-text" for="<?php echo $this->get_field_id('search_fields'); ?>"><?php _e( 'Searchable fields:', 'gravityview' ); ?></label> |
||
244 | <div class="gv-widget-search-fields" title="<?php esc_html_e('Search Fields', 'gravityview'); ?>"> |
||
245 | <input id="<?php echo $this->get_field_id('search_fields'); ?>" name="<?php echo $this->get_field_name('search_fields'); ?>" type="hidden" value="<?php echo esc_attr( $search_fields ); ?>" class="gv-search-fields-value"> |
||
246 | </div> |
||
247 | |||
248 | </div> |
||
249 | |||
250 | <script> |
||
251 | // When the widget is saved or added, refresh the Merge Tags (here for backward compatibility) |
||
252 | // WordPress 3.9 added widget-added and widget-updated actions |
||
253 | jQuery('#<?php echo $this->get_field_id( 'view_id' ); ?>').trigger( 'change' ); |
||
254 | </script> |
||
255 | <?php |
||
256 | } |
||
257 | |||
258 | } |