Complex classes like GravityView_Widget_Search often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use GravityView_Widget_Search, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
16 | class GravityView_Widget_Search extends GravityView_Widget { |
||
17 | |||
18 | public static $file; |
||
19 | public static $instance; |
||
20 | |||
21 | private $search_filters = array(); |
||
22 | |||
23 | /** |
||
24 | * whether search method is GET or POST ( default: GET ) |
||
25 | * @since 1.16.4 |
||
26 | * @var string |
||
27 | */ |
||
28 | private $search_method = 'get'; |
||
29 | |||
30 | public function __construct() { |
||
31 | |||
32 | $this->widget_description = esc_html__( 'Search form for searching entries.', 'gravityview' ); |
||
33 | |||
34 | self::$instance = &$this; |
||
35 | |||
36 | self::$file = plugin_dir_path( __FILE__ ); |
||
37 | |||
38 | $default_values = array( 'header' => 0, 'footer' => 0 ); |
||
39 | |||
40 | $settings = array( |
||
41 | 'search_layout' => array( |
||
42 | 'type' => 'radio', |
||
43 | 'full_width' => true, |
||
44 | 'label' => esc_html__( 'Search Layout', 'gravityview' ), |
||
45 | 'value' => 'horizontal', |
||
46 | 'options' => array( |
||
47 | 'horizontal' => esc_html__( 'Horizontal', 'gravityview' ), |
||
48 | 'vertical' => esc_html__( 'Vertical', 'gravityview' ), |
||
49 | ), |
||
50 | ), |
||
51 | 'search_clear' => array( |
||
52 | 'type' => 'checkbox', |
||
53 | 'label' => __( 'Show Clear button', 'gravityview' ), |
||
54 | 'value' => false, |
||
55 | ), |
||
56 | 'search_fields' => array( |
||
57 | 'type' => 'hidden', |
||
58 | 'label' => '', |
||
59 | 'class' => 'gv-search-fields-value', |
||
60 | 'value' => '[{"field":"search_all","input":"input_text"}]', // Default: Search Everything text box |
||
61 | ), |
||
62 | 'search_mode' => array( |
||
63 | 'type' => 'radio', |
||
64 | 'full_width' => true, |
||
65 | 'label' => esc_html__( 'Search Mode', 'gravityview' ), |
||
66 | 'desc' => __('Should search results match all search fields, or any?', 'gravityview'), |
||
67 | 'value' => 'any', |
||
68 | 'class' => 'hide-if-js', |
||
69 | 'options' => array( |
||
70 | 'any' => esc_html__( 'Match Any Fields', 'gravityview' ), |
||
71 | 'all' => esc_html__( 'Match All Fields', 'gravityview' ), |
||
72 | ), |
||
73 | ), |
||
74 | ); |
||
75 | parent::__construct( esc_html__( 'Search Bar', 'gravityview' ), 'search_bar', $default_values, $settings ); |
||
76 | |||
77 | // frontend - filter entries |
||
78 | add_filter( 'gravityview_fe_search_criteria', array( $this, 'filter_entries' ), 10, 1 ); |
||
79 | |||
80 | // frontend - add template path |
||
81 | add_filter( 'gravityview_template_paths', array( $this, 'add_template_path' ) ); |
||
82 | |||
83 | // Add hidden fields for "Default" permalink structure |
||
84 | add_filter( 'gravityview_widget_search_filters', array( $this, 'add_no_permalink_fields' ), 10, 3 ); |
||
85 | |||
86 | // admin - add scripts - run at 1100 to make sure GravityView_Admin_Views::add_scripts_and_styles() runs first at 999 |
||
87 | add_action( 'admin_enqueue_scripts', array( $this, 'add_scripts_and_styles' ), 1100 ); |
||
88 | add_action( 'wp_enqueue_scripts', array( $this, 'register_scripts') ); |
||
89 | add_filter( 'gravityview_noconflict_scripts', array( $this, 'register_no_conflict' ) ); |
||
90 | |||
91 | // ajax - get the searchable fields |
||
92 | add_action( 'wp_ajax_gv_searchable_fields', array( 'GravityView_Widget_Search', 'get_searchable_fields' ) ); |
||
93 | |||
94 | // calculate the search method (POST / GET) |
||
95 | $this->set_search_method(); |
||
96 | |||
97 | } |
||
98 | |||
99 | /** |
||
100 | * @return GravityView_Widget_Search |
||
101 | */ |
||
102 | public static function getInstance() { |
||
108 | |||
109 | /** |
||
110 | * Sets the search method to GET (default) or POST |
||
111 | * @since 1.16.4 |
||
112 | */ |
||
113 | private function set_search_method() { |
||
126 | |||
127 | /** |
||
128 | * Returns the search method |
||
129 | * @since 1.16.4 |
||
130 | * @return string |
||
131 | */ |
||
132 | public function get_search_method() { |
||
135 | |||
136 | |||
137 | /** |
||
138 | * Add script to Views edit screen (admin) |
||
139 | * @param mixed $hook |
||
140 | */ |
||
141 | public function add_scripts_and_styles( $hook ) { |
||
142 | global $pagenow; |
||
143 | |||
144 | // Don't process any scripts below here if it's not a GravityView page or the widgets screen |
||
145 | if ( ! gravityview_is_admin_page( $hook ) && ( 'widgets.php' !== $pagenow ) ) { |
||
146 | return; |
||
147 | } |
||
148 | |||
149 | $script_min = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min'; |
||
150 | $script_source = empty( $script_min ) ? '/source' : ''; |
||
151 | |||
152 | wp_enqueue_script( 'gravityview_searchwidget_admin', plugins_url( 'assets/js'.$script_source.'/admin-search-widget'.$script_min.'.js', __FILE__ ), array( 'jquery', 'gravityview_views_scripts' ), GravityView_Plugin::version ); |
||
153 | |||
154 | |||
155 | /** |
||
156 | * Input Type labels l10n |
||
157 | * @see admin-search-widget.js (getSelectInput) |
||
158 | * @var array |
||
159 | */ |
||
160 | $input_labels = array( |
||
161 | 'input_text' => esc_html__( 'Text', 'gravityview' ), |
||
162 | 'date' => esc_html__( 'Date', 'gravityview' ), |
||
163 | 'select' => esc_html__( 'Select', 'gravityview' ), |
||
164 | 'multiselect' => esc_html__( 'Select (multiple values)', 'gravityview' ), |
||
165 | 'radio' => esc_html__( 'Radio', 'gravityview' ), |
||
166 | 'checkbox' => esc_html__( 'Checkbox', 'gravityview' ), |
||
167 | 'single_checkbox' => esc_html__( 'Checkbox', 'gravityview' ), |
||
168 | 'link' => esc_html__( 'Links', 'gravityview' ), |
||
169 | 'date_range' => esc_html__( 'Date range', 'gravityview' ), |
||
170 | ); |
||
171 | |||
172 | /** |
||
173 | * Input Type groups |
||
174 | * @see admin-search-widget.js (getSelectInput) |
||
175 | * @var array |
||
176 | */ |
||
177 | $input_types = array( |
||
178 | 'text' => array( 'input_text' ), |
||
179 | 'address' => array( 'input_text' ), |
||
180 | 'number' => array( 'input_text' ), |
||
181 | 'date' => array( 'date', 'date_range' ), |
||
182 | 'boolean' => array( 'single_checkbox' ), |
||
183 | 'select' => array( 'select', 'radio', 'link' ), |
||
184 | 'multi' => array( 'select', 'multiselect', 'radio', 'checkbox', 'link' ), |
||
185 | ); |
||
186 | |||
187 | wp_localize_script( 'gravityview_searchwidget_admin', 'gvSearchVar', array( |
||
188 | 'nonce' => wp_create_nonce( 'gravityview_ajaxsearchwidget' ), |
||
189 | 'label_nofields' => esc_html__( 'No search fields configured yet.', 'gravityview' ), |
||
190 | 'label_addfield' => esc_html__( 'Add Search Field', 'gravityview' ), |
||
191 | 'label_label' => esc_html__( 'Label', 'gravityview' ), |
||
192 | 'label_searchfield' => esc_html__( 'Search Field', 'gravityview' ), |
||
193 | 'label_inputtype' => esc_html__( 'Input Type', 'gravityview' ), |
||
194 | 'label_ajaxerror' => esc_html__( 'There was an error loading searchable fields. Save the View or refresh the page to fix this issue.', 'gravityview' ), |
||
195 | 'input_labels' => json_encode( $input_labels ), |
||
196 | 'input_types' => json_encode( $input_types ), |
||
197 | ) ); |
||
198 | |||
199 | } |
||
200 | |||
201 | /** |
||
202 | * Add admin script to the no-conflict scripts whitelist |
||
203 | * @param array $allowed Scripts allowed in no-conflict mode |
||
204 | * @return array Scripts allowed in no-conflict mode, plus the search widget script |
||
205 | */ |
||
206 | public function register_no_conflict( $allowed ) { |
||
207 | $allowed[] = 'gravityview_searchwidget_admin'; |
||
208 | return $allowed; |
||
209 | } |
||
210 | |||
211 | /** |
||
212 | * Ajax |
||
213 | * Returns the form fields ( only the searchable ones ) |
||
214 | * |
||
215 | * @access public |
||
216 | * @return void |
||
217 | */ |
||
218 | public static function get_searchable_fields() { |
||
246 | |||
247 | /** |
||
248 | * Generates html for the available Search Fields dropdown |
||
249 | * @param int $form_id |
||
250 | * @param string $current (for future use) |
||
251 | * @return string |
||
252 | */ |
||
253 | public static function render_searchable_fields( $form_id = null, $current = '' ) { |
||
254 | |||
255 | if ( is_null( $form_id ) ) { |
||
256 | return ''; |
||
257 | } |
||
258 | |||
259 | // start building output |
||
260 | |||
261 | $output = '<select class="gv-search-fields">'; |
||
262 | |||
263 | $custom_fields = array( |
||
264 | 'search_all' => array( |
||
265 | 'text' => esc_html__( 'Search Everything', 'gravityview' ), |
||
266 | 'type' => 'text', |
||
267 | ), |
||
268 | 'entry_date' => array( |
||
269 | 'text' => esc_html__( 'Entry Date', 'gravityview' ), |
||
270 | 'type' => 'date', |
||
271 | ), |
||
272 | 'entry_id' => array( |
||
273 | 'text' => esc_html__( 'Entry ID', 'gravityview' ), |
||
274 | 'type' => 'text', |
||
275 | ), |
||
276 | 'created_by' => array( |
||
277 | 'text' => esc_html__( 'Entry Creator', 'gravityview' ), |
||
278 | 'type' => 'select', |
||
279 | ) |
||
280 | ); |
||
281 | |||
282 | foreach( $custom_fields as $custom_field_key => $custom_field ) { |
||
283 | $output .= sprintf( '<option value="%s" %s data-inputtypes="%s" data-placeholder="%s">%s</option>', $custom_field_key, selected( $custom_field_key, $current, false ), $custom_field['type'], self::get_field_label( array('field' => $custom_field_key ) ), $custom_field['text'] ); |
||
284 | } |
||
285 | |||
286 | // Get fields with sub-inputs and no parent |
||
287 | $fields = gravityview_get_form_fields( $form_id, true, true ); |
||
288 | |||
289 | /** |
||
290 | * @filter `gravityview/search/searchable_fields` Modify the fields that are displayed as searchable in the Search Bar dropdown\n |
||
291 | * @since 1.17 |
||
292 | * @see gravityview_get_form_fields() Used to fetch the fields |
||
293 | * @see GravityView_Widget_Search::get_search_input_types See this method to modify the type of input types allowed for a field |
||
294 | * @param array $fields Array of searchable fields, as fetched by gravityview_get_form_fields() |
||
295 | * @param int $form_id |
||
296 | */ |
||
297 | $fields = apply_filters( 'gravityview/search/searchable_fields', $fields, $form_id ); |
||
298 | |||
299 | if ( ! empty( $fields ) ) { |
||
300 | |||
301 | $blacklist_field_types = apply_filters( 'gravityview_blacklist_field_types', array( 'fileupload', 'post_image', 'post_id', 'section' ), null ); |
||
302 | |||
303 | foreach ( $fields as $id => $field ) { |
||
304 | |||
305 | if ( in_array( $field['type'], $blacklist_field_types ) ) { |
||
306 | continue; |
||
307 | } |
||
308 | |||
309 | $types = self::get_search_input_types( $id, $field['type'] ); |
||
310 | |||
311 | $output .= '<option value="'. $id .'" '. selected( $id, $current, false ).'data-inputtypes="'. esc_attr( $types ) .'">'. esc_html( $field['label'] ) .'</option>'; |
||
312 | } |
||
313 | } |
||
314 | |||
315 | $output .= '</select>'; |
||
316 | |||
317 | return $output; |
||
318 | |||
319 | } |
||
320 | |||
321 | /** |
||
322 | * Assign an input type according to the form field type |
||
323 | * @see admin-search-widget.js |
||
324 | * |
||
325 | * @param int $id Gravity Forms field ID |
||
326 | * @param string $field_type Gravity Forms field type (also the `name` parameter of GravityView_Field classes) |
||
327 | * |
||
328 | * @return string GV field search input type ('multi', 'boolean', 'select', 'date', 'text') |
||
329 | */ |
||
330 | public static function get_search_input_types( $id = '', $field_type = null ) { |
||
357 | |||
358 | /** |
||
359 | * Display hidden fields to add support for sites using Default permalink structure |
||
360 | * |
||
361 | * @since 1.8 |
||
362 | * @return array Search fields, modified if not using permalinks |
||
363 | */ |
||
364 | public function add_no_permalink_fields( $search_fields, $object, $widget_args = array() ) { |
||
397 | |||
398 | |||
399 | /** --- Frontend --- */ |
||
400 | |||
401 | /** |
||
402 | * Calculate the search criteria to filter entries |
||
403 | * @param array $search_criteria |
||
404 | * @return array |
||
405 | */ |
||
406 | public function filter_entries( $search_criteria ) { |
||
522 | |||
523 | /** |
||
524 | * Prepare the field filters to GFAPI |
||
525 | * |
||
526 | * The type post_category, multiselect and checkbox support multi-select search - each value needs to be separated in an independent filter so we could apply the ANY search mode. |
||
527 | * |
||
528 | * Format searched values |
||
529 | * @param string $key $_GET/$_POST search key |
||
530 | * @param string $value $_GET/$_POST search value |
||
531 | * @return array 1 or 2 deph levels |
||
532 | */ |
||
533 | public function prepare_field_filter( $key, $value ) { |
||
682 | |||
683 | /** |
||
684 | * Get the Field Format form GravityForms |
||
685 | * |
||
686 | * @param GF_Field_Date $field The field object |
||
687 | * @since 1.10 |
||
688 | * |
||
689 | * @return string Format of the date in the database |
||
690 | */ |
||
691 | public static function get_date_field_format( GF_Field_Date $field ) { |
||
709 | |||
710 | /** |
||
711 | * Format a date value |
||
712 | * |
||
713 | * @param string $value Date value input |
||
714 | * @param string $format Wanted formatted date |
||
715 | * @return string |
||
716 | */ |
||
717 | public static function get_formatted_date( $value = '', $format = 'Y-m-d' ) { |
||
725 | |||
726 | |||
727 | /** |
||
728 | * Include this extension templates path |
||
729 | * @param array $file_paths List of template paths ordered |
||
730 | */ |
||
731 | public function add_template_path( $file_paths ) { |
||
732 | |||
733 | // Index 100 is the default GravityView template path. |
||
734 | $file_paths[102] = self::$file . 'templates/'; |
||
735 | |||
736 | return $file_paths; |
||
737 | } |
||
738 | |||
739 | /** |
||
740 | * Renders the Search Widget |
||
741 | * @param array $widget_args |
||
742 | * @param string $content |
||
743 | * @param string $context |
||
744 | * |
||
745 | * @return void |
||
746 | */ |
||
747 | public function render_frontend( $widget_args, $content = '', $context = '' ) { |
||
748 | /** @var GravityView_View $gravityview_view */ |
||
749 | $gravityview_view = GravityView_View::getInstance(); |
||
750 | |||
751 | if ( empty( $gravityview_view ) ) { |
||
752 | do_action( 'gravityview_log_debug', sprintf( '%s[render_frontend]: $gravityview_view not instantiated yet.', get_class( $this ) ) ); |
||
753 | return; |
||
754 | } |
||
755 | |||
756 | // get configured search fields |
||
757 | $search_fields = ! empty( $widget_args['search_fields'] ) ? json_decode( $widget_args['search_fields'], true ) : ''; |
||
758 | |||
759 | if ( empty( $search_fields ) || ! is_array( $search_fields ) ) { |
||
760 | do_action( 'gravityview_log_debug', sprintf( '%s[render_frontend] No search fields configured for widget:', get_class( $this ) ), $widget_args ); |
||
761 | return; |
||
762 | } |
||
763 | |||
764 | $has_date = false; |
||
765 | |||
766 | // prepare fields |
||
767 | foreach ( $search_fields as $k => $field ) { |
||
768 | |||
769 | $updated_field = $field; |
||
770 | |||
771 | if ( in_array( $field['input'], array( 'date', 'date_range' ) ) ) { |
||
772 | $has_date = true; |
||
773 | } |
||
774 | |||
775 | $updated_field = $this->get_search_filter_details( $updated_field ); |
||
776 | |||
777 | switch ( $field['field'] ) { |
||
778 | |||
779 | case 'search_all': |
||
780 | $updated_field['key'] = 'search_all'; |
||
781 | $updated_field['input'] = 'search_all'; |
||
782 | $updated_field['value'] = $this->rgget_or_rgpost( 'gv_search' ); |
||
783 | break; |
||
784 | |||
785 | case 'entry_date': |
||
786 | $updated_field['key'] = 'entry_date'; |
||
787 | $updated_field['input'] = 'entry_date'; |
||
788 | $updated_field['value'] = array( |
||
789 | 'start' => $this->rgget_or_rgpost( 'gv_start' ), |
||
790 | 'end' => $this->rgget_or_rgpost( 'gv_end' ), |
||
791 | ); |
||
792 | $has_date = true; |
||
793 | break; |
||
794 | |||
795 | case 'entry_id': |
||
796 | $updated_field['key'] = 'entry_id'; |
||
797 | $updated_field['input'] = 'entry_id'; |
||
798 | $updated_field['value'] = $this->rgget_or_rgpost( 'gv_id' ); |
||
799 | break; |
||
800 | |||
801 | case 'created_by': |
||
802 | $updated_field['key'] = 'created_by'; |
||
803 | $updated_field['name'] = 'gv_by'; |
||
804 | $updated_field['value'] = $this->rgget_or_rgpost( 'gv_by' ); |
||
805 | $updated_field['choices'] = self::get_created_by_choices(); |
||
806 | break; |
||
807 | } |
||
808 | |||
809 | $search_fields[ $k ] = $updated_field; |
||
810 | } |
||
811 | |||
812 | do_action( 'gravityview_log_debug', sprintf( '%s[render_frontend] Calculated Search Fields: ', get_class( $this ) ), $search_fields ); |
||
813 | |||
814 | /** |
||
815 | * @filter `gravityview_widget_search_filters` Modify what fields are shown. The order of the fields in the $search_filters array controls the order as displayed in the search bar widget. |
||
816 | * @param array $search_fields Array of search filters with `key`, `label`, `value`, `type` keys |
||
817 | * @param GravityView_Widget_Search $this Current widget object |
||
818 | * @param array $widget_args Args passed to this method. {@since 1.8} |
||
819 | * @var array |
||
820 | */ |
||
821 | $gravityview_view->search_fields = apply_filters( 'gravityview_widget_search_filters', $search_fields, $this, $widget_args ); |
||
822 | |||
823 | $gravityview_view->search_layout = ! empty( $widget_args['search_layout'] ) ? $widget_args['search_layout'] : 'horizontal'; |
||
824 | |||
825 | /** @since 1.14 */ |
||
826 | $gravityview_view->search_mode = ! empty( $widget_args['search_mode'] ) ? $widget_args['search_mode'] : 'any'; |
||
827 | |||
828 | $custom_class = ! empty( $widget_args['custom_class'] ) ? $widget_args['custom_class'] : ''; |
||
829 | |||
830 | $gravityview_view->search_class = self::get_search_class( $custom_class ); |
||
831 | |||
832 | $gravityview_view->search_clear = ! empty( $widget_args['search_clear'] ) ? $widget_args['search_clear'] : false; |
||
833 | |||
834 | if ( $has_date ) { |
||
835 | // enqueue datepicker stuff only if needed! |
||
836 | $this->enqueue_datepicker(); |
||
837 | } |
||
838 | |||
839 | $this->maybe_enqueue_flexibility(); |
||
840 | |||
841 | $gravityview_view->render( 'widget', 'search', false ); |
||
842 | } |
||
843 | |||
844 | /** |
||
845 | * Get the search class for a search form |
||
846 | * |
||
847 | * @since 1.5.4 |
||
848 | * |
||
849 | * @return string Sanitized CSS class for the search form |
||
850 | */ |
||
851 | public static function get_search_class( $custom_class = '' ) { |
||
852 | $gravityview_view = GravityView_View::getInstance(); |
||
853 | |||
854 | $search_class = 'gv-search-'.$gravityview_view->search_layout; |
||
855 | |||
856 | if ( ! empty( $custom_class ) ) { |
||
857 | $search_class .= ' '.$custom_class; |
||
858 | } |
||
859 | |||
860 | /** |
||
861 | * @filter `gravityview_search_class` Modify the CSS class for the search form |
||
862 | * @param string $search_class The CSS class for the search form |
||
863 | */ |
||
864 | $search_class = apply_filters( 'gravityview_search_class', $search_class ); |
||
865 | |||
866 | // Is there an active search being performed? Used by fe-views.js |
||
867 | $search_class .= GravityView_frontend::getInstance()->isSearch() ? ' gv-is-search' : ''; |
||
868 | |||
869 | return gravityview_sanitize_html_class( $search_class ); |
||
870 | } |
||
871 | |||
872 | |||
873 | /** |
||
874 | * Calculate the search form action |
||
875 | * @since 1.6 |
||
876 | * |
||
877 | * @return string |
||
878 | */ |
||
879 | public static function get_search_form_action() { |
||
888 | |||
889 | /** |
||
890 | * Get the label for a search form field |
||
891 | * @param array $field Field setting as sent by the GV configuration - has `field`, `input` (input type), and `label` keys |
||
892 | * @param array $form_field Form field data, as fetched by `gravityview_get_field()` |
||
893 | * @return string Label for the search form |
||
894 | */ |
||
895 | private static function get_field_label( $field, $form_field = array() ) { |
||
947 | |||
948 | /** |
||
949 | * Prepare search fields to frontend render with other details (label, field type, searched values) |
||
950 | * |
||
951 | * @param array $field |
||
952 | * @return array |
||
953 | */ |
||
954 | private function get_search_filter_details( $field ) { |
||
992 | |||
993 | /** |
||
994 | * Calculate the search choices for the users |
||
995 | * |
||
996 | * @since 1.8 |
||
997 | * |
||
998 | * @return array Array of user choices (value = ID, text = display name) |
||
999 | */ |
||
1000 | private static function get_created_by_choices() { |
||
1018 | |||
1019 | |||
1020 | /** |
||
1021 | * Output the Clear Search Results button |
||
1022 | * @since 1.5.4 |
||
1023 | */ |
||
1024 | public static function the_clear_search_button() { |
||
1035 | |||
1036 | /** |
||
1037 | * Based on the search method, fetch the value for a specific key |
||
1038 | * |
||
1039 | * @since 1.16.4 |
||
1040 | * |
||
1041 | * @param string $name Name of the request key to fetch the value for |
||
1042 | * |
||
1043 | * @return mixed|string Value of request at $name key. Empty string if empty. |
||
1044 | */ |
||
1045 | private function rgget_or_rgpost( $name ) { |
||
1056 | |||
1057 | |||
1058 | /** |
||
1059 | * Require the datepicker script for the frontend GV script |
||
1060 | * @param array $js_dependencies Array of existing required scripts for the fe-views.js script |
||
1061 | * @return array Array required scripts, with `jquery-ui-datepicker` added |
||
1062 | */ |
||
1063 | public function add_datepicker_js_dependency( $js_dependencies ) { |
||
1069 | |||
1070 | /** |
||
1071 | * Modify the array passed to wp_localize_script() |
||
1072 | * |
||
1073 | * @param array $js_localization The data padded to the Javascript file |
||
1074 | * @param array $view_data View data array with View settings |
||
1075 | * |
||
1076 | * @return array |
||
1077 | */ |
||
1078 | public function add_datepicker_localization( $localizations = array(), $view_data = array() ) { |
||
1114 | |||
1115 | /** |
||
1116 | * Register search widget scripts, including Flexibility |
||
1117 | * |
||
1118 | * @see https://github.com/10up/flexibility |
||
1119 | * |
||
1120 | * @since TODO |
||
1121 | * |
||
1122 | * @return void |
||
1123 | */ |
||
1124 | public function register_scripts() { |
||
1129 | |||
1130 | /** |
||
1131 | * If the current visitor is running IE 8 or 9, enqueue Flexibility |
||
1132 | * |
||
1133 | * @since TODO |
||
1134 | * |
||
1135 | * @return void |
||
1136 | */ |
||
1137 | private function maybe_enqueue_flexibility() { |
||
1142 | |||
1143 | /** |
||
1144 | * Enqueue the datepicker script |
||
1145 | * |
||
1146 | * It sets the $gravityview->datepicker_class parameter |
||
1147 | * |
||
1148 | * @todo Use own datepicker javascript instead of GF datepicker.js - that way, we can localize the settings and not require the changeMonth and changeYear pickers. |
||
1149 | * @return void |
||
1150 | */ |
||
1151 | public function enqueue_datepicker() { |
||
1180 | |||
1181 | |||
1182 | } // end class |
||
1183 | |||
1184 | new GravityView_Widget_Search; |
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.