Complex classes like GravityView_Admin_Views 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_Admin_Views, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
19 | class GravityView_Admin_Views { |
||
20 | |||
21 | |||
22 | |||
23 | function __construct() { |
||
24 | |||
25 | add_action( 'save_post', array( $this, 'save_postdata' ) ); |
||
26 | |||
27 | // set the blacklist field types across the entire plugin |
||
28 | add_filter( 'gravityview_blacklist_field_types', array( $this, 'default_field_blacklist' ), 10, 2 ); |
||
29 | |||
30 | // Tooltips |
||
31 | add_filter( 'gform_tooltips', array( $this, 'tooltips') ); |
||
32 | |||
33 | // adding styles and scripts |
||
34 | add_action( 'admin_enqueue_scripts', array( 'GravityView_Admin_Views', 'add_scripts_and_styles'), 999 ); |
||
35 | add_filter( 'gform_noconflict_styles', array( $this, 'register_no_conflict') ); |
||
36 | add_filter( 'gform_noconflict_scripts', array( $this, 'register_no_conflict') ); |
||
37 | add_filter( 'gravityview_noconflict_styles', array( $this, 'register_no_conflict') ); |
||
38 | add_filter( 'gravityview_noconflict_scripts', array( $this, 'register_no_conflict') ); |
||
39 | |||
40 | add_action( 'gravityview_render_directory_active_areas', array( $this, 'render_directory_active_areas'), 10, 4 ); |
||
41 | add_action( 'gravityview_render_widgets_active_areas', array( $this, 'render_widgets_active_areas'), 10, 3 ); |
||
42 | add_action( 'gravityview_render_available_fields', array( $this, 'render_available_fields'), 10, 2 ); |
||
43 | add_action( 'gravityview_render_available_widgets', array( $this, 'render_available_widgets') ); |
||
44 | add_action( 'gravityview_render_active_areas', array( $this, 'render_active_areas'), 10, 5 ); |
||
45 | |||
46 | // @todo check if this hook is needed.. |
||
47 | //add_action( 'gravityview_render_field_options', array( $this, 'render_field_options'), 10, 9 ); |
||
48 | |||
49 | // Add Connected Form column |
||
50 | add_filter('manage_gravityview_posts_columns' , array( $this, 'add_post_type_columns' ) ); |
||
51 | |||
52 | add_filter( 'gform_toolbar_menu', array( 'GravityView_Admin_Views', 'gform_toolbar_menu' ), 10, 2 ); |
||
53 | |||
54 | add_action( 'manage_gravityview_posts_custom_column', array( $this, 'add_custom_column_content'), 10, 2 ); |
||
55 | |||
56 | add_action( 'restrict_manage_posts', array( $this, 'add_view_dropdown' ) ); |
||
57 | |||
58 | add_action( 'pre_get_posts', array( $this, 'filter_pre_get_posts_by_gravityview_form_id' ) ); |
||
59 | |||
60 | } |
||
61 | |||
62 | /** |
||
63 | * @since 1.15 |
||
64 | * @param WP_Query $query |
||
65 | */ |
||
66 | public function filter_pre_get_posts_by_gravityview_form_id( &$query ) { |
||
67 | global $pagenow; |
||
68 | |||
69 | if ( !is_admin() ) { |
||
70 | return; |
||
71 | } |
||
72 | |||
73 | if( 'edit.php' !== $pagenow || ! rgget( 'gravityview_form_id' ) || ! isset( $query->query_vars[ 'post_type' ] ) ) { |
||
74 | return; |
||
75 | } |
||
76 | |||
77 | if ( $query->query_vars[ 'post_type' ] == 'gravityview' ) { |
||
78 | $query->set( 'meta_query', array( |
||
79 | array( |
||
80 | 'key' => '_gravityview_form_id', |
||
81 | 'value' => rgget( 'gravityview_form_id' ), |
||
82 | ) |
||
83 | ) ); |
||
84 | } |
||
85 | } |
||
86 | |||
87 | function add_view_dropdown() { |
||
88 | $current_screen = get_current_screen(); |
||
89 | |||
90 | if( 'gravityview' !== $current_screen->post_type ) { |
||
91 | return; |
||
92 | } |
||
93 | |||
94 | $forms = gravityview_get_forms(); |
||
95 | $current_form = rgget( 'gravityview_form_id' ); |
||
96 | // If there are no forms to select, show no forms. |
||
97 | if( !empty( $forms ) ) { ?> |
||
98 | <select name="gravityview_form_id" id="gravityview_form_id"> |
||
99 | <option value="" <?php selected( '', $current_form, true ); ?>><?php esc_html_e( 'All forms', 'gravityview' ); ?></option> |
||
100 | <?php foreach( $forms as $form ) { ?> |
||
101 | <option value="<?php echo $form['id']; ?>" <?php selected( $form['id'], $current_form, true ); ?>><?php echo esc_html( $form['title'] ); ?></option> |
||
102 | <?php } ?> |
||
103 | </select> |
||
104 | <?php } |
||
105 | } |
||
106 | |||
107 | |||
108 | /** |
||
109 | * @deprecated since 1.2 |
||
110 | * Start using GravityView_Render_Settings::render_setting_row |
||
111 | */ |
||
112 | public static function render_setting_row( $key = '', $current_settings = array(), $override_input = null, $name = 'template_settings[%s]', $id = 'gravityview_se_%s' ) { |
||
113 | _deprecated_function( 'GravityView_Admin_Views::render_setting_row', '1.1.7', 'GravityView_Render_Settings::render_setting_row' ); |
||
114 | GravityView_Render_Settings::render_setting_row( $key, $current_settings, $override_input, $name , $id ); |
||
115 | } |
||
116 | |||
117 | /** |
||
118 | * @deprecated since 1.2 |
||
119 | * Start using GravityView_Render_Settings::render_field_option |
||
120 | */ |
||
121 | public static function render_field_option( $name = '', $option, $curr_value = NULL ) { |
||
122 | _deprecated_function( 'GravityView_Admin_Views::render_field_option', '1.1.7', 'GravityView_Render_Settings::render_field_option' ); |
||
123 | return GravityView_Render_Settings::render_field_option( $name, $option, $curr_value ); |
||
124 | } |
||
125 | |||
126 | |||
127 | /** |
||
128 | * Add a GravityView menu to the Form Toolbar with connected views |
||
129 | * @param array $menu_items Menu items, as set in GFForms::top_toolbar() |
||
130 | * @param int $id ID of the current Gravity form |
||
131 | * @return array Modified array |
||
132 | */ |
||
133 | static function gform_toolbar_menu( $menu_items = array(), $id = NULL ) { |
||
134 | |||
135 | $connected_views = gravityview_get_connected_views( $id ); |
||
136 | |||
137 | if( empty( $connected_views ) ) { |
||
138 | return $menu_items; |
||
139 | } |
||
140 | |||
141 | $sub_menu_items = array(); |
||
142 | foreach ( (array)$connected_views as $view ) { |
||
143 | |||
144 | if( ! GVCommon::has_cap( 'edit_gravityview', $view->ID ) ) { |
||
145 | continue; |
||
146 | } |
||
147 | |||
148 | $label = empty( $view->post_title ) ? sprintf( __('No Title (View #%d)', 'gravityview' ), $view->ID ) : $view->post_title; |
||
149 | |||
150 | $sub_menu_items[] = array( |
||
151 | 'label' => esc_attr( $label ), |
||
152 | 'url' => admin_url( 'post.php?action=edit&post='.$view->ID ), |
||
153 | ); |
||
154 | } |
||
155 | |||
156 | // If there were no items added, then let's create the parent menu |
||
157 | if( $sub_menu_items ) { |
||
158 | |||
159 | // Make sure Gravity Forms uses the submenu; if there's only one item, it uses a link instead of a dropdown |
||
160 | $sub_menu_items[] = array( |
||
161 | 'url' => '#', |
||
162 | 'label' => '', |
||
163 | 'menu_class' => 'hidden', |
||
164 | 'capabilities' => '', |
||
165 | ); |
||
166 | |||
167 | $menu_items['gravityview'] = array( |
||
168 | 'label' => __( 'Connected Views', 'gravityview' ), |
||
169 | 'icon' => '<i class="fa fa-lg gv-icon-astronaut-head gv-icon"></i>', |
||
170 | 'title' => __( 'GravityView Views using this form as a data source', 'gravityview' ), |
||
171 | 'url' => '#', |
||
172 | 'onclick' => 'return false;', |
||
173 | 'menu_class' => 'gv_connected_forms gf_form_toolbar_settings', |
||
174 | 'link_class' => ( 1 === 1 ? '' : 'gf_toolbar_disabled' ), |
||
175 | 'sub_menu_items' => $sub_menu_items, |
||
176 | 'priority' => 0, |
||
177 | 'capabilities' => array( 'edit_gravityviews' ), |
||
178 | ); |
||
179 | } |
||
180 | |||
181 | return $menu_items; |
||
182 | } |
||
183 | |||
184 | /** |
||
185 | * List the field types without presentation properties (on a View context) |
||
186 | * |
||
187 | * @param array $array Existing field types to add to a blacklist |
||
188 | * @param string|null $context Context for the blacklist. Default: NULL. |
||
189 | * @access public |
||
190 | * @return array Default blacklist fields merged with existing blacklist fields |
||
191 | */ |
||
192 | function default_field_blacklist( $array = array(), $context = NULL ) { |
||
193 | |||
194 | $add = array( 'captcha', 'page' ); |
||
195 | |||
196 | // Don't allowing editing the following values: |
||
197 | if( $context === 'edit' ) { |
||
198 | $add[] = 'post_id'; |
||
199 | } |
||
200 | |||
201 | $return = array_merge( $array, $add ); |
||
202 | |||
203 | return $return; |
||
204 | } |
||
205 | |||
206 | /** |
||
207 | * Add tooltip text for use throughout the UI |
||
208 | * @param array $tooltips Array of Gravity Forms tooltips |
||
209 | * @return array Modified tooltips array |
||
210 | */ |
||
211 | public function tooltips( $tooltips = array() ) { |
||
212 | |||
213 | $gv_tooltips = array(); |
||
214 | |||
215 | // Generate tooltips for View settings |
||
216 | $default_args = GravityView_View_Data::get_default_args( true ); |
||
217 | |||
218 | foreach ( $default_args as $key => $arg ) { |
||
219 | |||
220 | // If an arg has `tooltip` defined, but it's false, don't display a tooltip |
||
221 | if( isset( $arg['tooltip'] ) && empty( $arg['tooltip'] ) ) { continue; } |
||
222 | |||
223 | // By default, use `tooltip` if defined. |
||
224 | $tooltip = empty( $arg['tooltip'] ) ? NULL : $arg['tooltip']; |
||
225 | |||
226 | // Otherwise, use the description as a tooltip. |
||
227 | if( empty( $tooltip ) && !empty( $arg['desc'] ) ) { |
||
228 | $tooltip = $arg['desc']; |
||
229 | } |
||
230 | |||
231 | // If there's no tooltip set, continue |
||
232 | if( empty( $tooltip ) ) { |
||
233 | continue; |
||
234 | } |
||
235 | |||
236 | // Add the tooltip |
||
237 | $gv_tooltips[ 'gv_'.$key ] = array( |
||
238 | 'title' => $arg['label'], |
||
239 | 'value' => $tooltip, |
||
240 | ); |
||
241 | |||
242 | } |
||
243 | |||
244 | $gv_tooltips['gv_css_merge_tags'] = array( |
||
245 | 'title' => __('CSS Merge Tags', 'gravityview'), |
||
246 | 'value' => sprintf( __( 'Developers: The CSS classes will be sanitized using the %ssanitize_title_with_dashes()%s function.', 'gravityview'), '<code>', '</code>' ) |
||
247 | ); |
||
248 | |||
249 | /** |
||
250 | * @filter `gravityview_tooltips` The tooltips GravityView adds to the Gravity Forms tooltip array |
||
251 | * @param array $gv_tooltips Associative array with unique keys containing array of `title` and `value` keys, as expected by `gform_tooltips` filter |
||
252 | */ |
||
253 | $gv_tooltips = apply_filters( 'gravityview_tooltips', $gv_tooltips ); |
||
254 | |||
255 | foreach ( $gv_tooltips as $key => $tooltip ) { |
||
256 | |||
257 | $title = empty( $tooltip['title'] ) ? '' : '<h6>'.esc_html( $tooltip['title'] ) .'</h6>'; |
||
258 | |||
259 | $tooltips[ $key ] = $title . wpautop( esc_html( $tooltip['value'] ) ); |
||
260 | } |
||
261 | |||
262 | return $tooltips; |
||
263 | } |
||
264 | |||
265 | /** |
||
266 | * Add the Data Source information |
||
267 | * |
||
268 | * @param null $column_name |
||
269 | * @param $post_id |
||
270 | * |
||
271 | * @return void |
||
272 | */ |
||
273 | public function add_custom_column_content( $column_name = NULL, $post_id ) { |
||
274 | |||
275 | $output = ''; |
||
276 | |||
277 | switch ( $column_name ) { |
||
278 | case 'gv_template': |
||
279 | |||
280 | $template_id = gravityview_get_template_id( $post_id ); |
||
281 | |||
282 | // All Views should have a connected form. If it doesn't, that's not right. |
||
283 | if ( empty( $template_id ) ) { |
||
284 | do_action( 'gravityview_log_error', sprintf( __METHOD__ . ' View ID %s does not have a connected template.', $post_id ) ); |
||
285 | break; |
||
286 | } |
||
287 | |||
288 | $templates = gravityview_get_registered_templates(); |
||
289 | |||
290 | $template = isset( $templates[ $template_id ] ) ? $templates[ $template_id ] : false; |
||
291 | |||
292 | // Generate backup if label doesn't exist: `example_name` => `Example Name` |
||
293 | $template_id_pretty = ucwords( implode( ' ', explode( '_', $template_id ) ) ); |
||
294 | |||
295 | $output = $template ? $template['label'] : $template_id_pretty; |
||
296 | |||
297 | break; |
||
298 | |||
299 | case 'gv_connected_form': |
||
300 | |||
301 | $form_id = gravityview_get_form_id( $post_id ); |
||
302 | |||
303 | // All Views should have a connected form. If it doesn't, that's not right. |
||
304 | if ( empty( $form_id ) ) { |
||
305 | do_action( 'gravityview_log_error', sprintf( '[add_data_source_column_content] View ID %s does not have a connected GF form.', $post_id ) ); |
||
306 | $output = __( 'Not connected.', 'gravityview' ); |
||
307 | break; |
||
308 | } |
||
309 | |||
310 | $form = gravityview_get_form( $form_id ); |
||
311 | |||
312 | if ( ! $form ) { |
||
313 | do_action( 'gravityview_log_error', sprintf( '[add_data_source_column_content] Connected form not found: Form #%d', $form_id ) ); |
||
314 | |||
315 | $output = __( 'The connected form can not be found; it may no longer exist.', 'gravityview' ); |
||
316 | } else { |
||
317 | $output = self::get_connected_form_links( $form ); |
||
318 | } |
||
319 | |||
320 | break; |
||
321 | } |
||
322 | |||
323 | echo $output; |
||
324 | } |
||
325 | |||
326 | |||
327 | /** |
||
328 | * Get HTML links relating to a connected form, like Edit, Entries, Settings, Preview |
||
329 | * @param array|int $form Gravity Forms forms array, or the form ID |
||
330 | * @param boolean $include_form_link Whether to include the bold name of the form in the output |
||
331 | * @return string HTML links |
||
332 | */ |
||
333 | static public function get_connected_form_links( $form, $include_form_link = true ) { |
||
334 | |||
335 | // Either the form is empty or the form ID is 0, not yet set. |
||
336 | if( empty( $form ) ) { |
||
337 | return ''; |
||
338 | } |
||
339 | |||
340 | // The $form is passed as the form ID |
||
341 | if( !is_array( $form ) ) { |
||
342 | $form = gravityview_get_form( $form ); |
||
343 | } |
||
344 | |||
345 | $form_id = $form['id']; |
||
346 | $links = array(); |
||
347 | |||
348 | if( GVCommon::has_cap( 'gravityforms_edit_forms' ) ) { |
||
349 | $form_url = admin_url( sprintf( 'admin.php?page=gf_edit_forms&id=%d', $form_id ) ); |
||
350 | $form_link = '<strong class="gv-form-title">'.gravityview_get_link( $form_url, $form['title'], 'class=row-title' ).'</strong>'; |
||
351 | $links[] = '<span>'.gravityview_get_link( $form_url, __('Edit Form', 'gravityview') ).'</span>'; |
||
352 | } else { |
||
353 | $form_link = '<strong class="gv-form-title">'. esc_html( $form['title'] ). '</strong>'; |
||
354 | } |
||
355 | |||
356 | if( GVCommon::has_cap( 'gravityforms_view_entries' ) ) { |
||
357 | $entries_url = admin_url( sprintf( 'admin.php?page=gf_entries&id=%d', $form_id ) ); |
||
358 | $links[] = '<span>'.gravityview_get_link( $entries_url, __('Entries', 'gravityview') ).'</span>'; |
||
359 | } |
||
360 | |||
361 | if( GVCommon::has_cap( array( 'gravityforms_edit_settings', 'gravityview_view_settings' ) ) ) { |
||
362 | $settings_url = admin_url( sprintf( 'admin.php?page=gf_edit_forms&view=settings&id=%d', $form_id ) ); |
||
363 | $links[] = '<span>'.gravityview_get_link( $settings_url, __('Settings', 'gravityview'), 'title='.__('Edit settings for this form', 'gravityview') ).'</span>'; |
||
364 | } |
||
365 | |||
366 | if( GVCommon::has_cap( array("gravityforms_edit_forms", "gravityforms_create_form", "gravityforms_preview_forms") ) ) { |
||
367 | $preview_url = site_url( sprintf( '?gf_page=preview&id=%d', $form_id ) ); |
||
368 | $links[] = '<span>'.gravityview_get_link( $preview_url, __('Preview Form', 'gravityview'), 'title='.__('Preview this form', 'gravityview') ).'</span>'; |
||
369 | } |
||
370 | |||
371 | $output = ''; |
||
372 | |||
373 | if( !empty( $include_form_link ) ) { |
||
374 | $output .= $form_link; |
||
375 | } |
||
376 | |||
377 | /** |
||
378 | * @filter `gravityview_connected_form_links` Modify the links shown in the Connected Form links |
||
379 | * @since 1.6 |
||
380 | * @param array $links Links to show |
||
381 | * @param array $form Gravity Forms form array |
||
382 | */ |
||
383 | $links = apply_filters( 'gravityview_connected_form_links', $links, $form ); |
||
384 | |||
385 | $output .= '<div class="row-actions">'. implode( ' | ', $links ) .'</div>'; |
||
386 | |||
387 | return $output; |
||
388 | } |
||
389 | |||
390 | /** |
||
391 | * Add the Data Source column to the Views page |
||
392 | * @param array $columns Columns array |
||
393 | */ |
||
394 | public function add_post_type_columns( $columns ) { |
||
395 | |||
396 | // Get the date column and save it for later to add back in. |
||
397 | // This adds it after the Data Source column. |
||
398 | // This way, we don't need to do array_slice, array_merge, etc. |
||
399 | $date = $columns['date']; |
||
400 | unset( $columns['date'] ); |
||
401 | |||
402 | $data_source_required_caps = array( |
||
403 | 'gravityforms_edit_forms', |
||
404 | 'gravityforms_view_entries', |
||
405 | 'gravityforms_edit_settings', |
||
406 | 'gravityview_view_settings', |
||
407 | 'gravityforms_create_form', |
||
408 | 'gravityforms_preview_forms', |
||
409 | ); |
||
410 | |||
411 | if( GVCommon::has_cap( $data_source_required_caps ) ) { |
||
412 | $columns['gv_connected_form'] = __( 'Data Source', 'gravityview' ); |
||
413 | } |
||
414 | |||
415 | $columns['gv_template'] = _x( 'Template', 'Column title that shows what template is being used for Views', 'gravityview' ); |
||
416 | |||
417 | // Add the date back in. |
||
418 | $columns['date'] = $date; |
||
419 | |||
420 | return $columns; |
||
421 | } |
||
422 | |||
423 | /** |
||
424 | * Save View configuration |
||
425 | * |
||
426 | * @access public |
||
427 | * @param int $post_id Currently saved Post ID |
||
428 | * @return void |
||
429 | */ |
||
430 | function save_postdata( $post_id ) { |
||
514 | |||
515 | /** |
||
516 | * @deprecated 1.1.6 |
||
517 | */ |
||
518 | function render_label() { |
||
521 | |||
522 | /** |
||
523 | * Render html for displaying available fields based on a Form ID |
||
524 | * $blacklist_field_types - contains the field types which are not proper to be shown in a directory. |
||
525 | * |
||
526 | * @access public |
||
527 | * @param int $form Gravity Forms Form ID (default: '') |
||
528 | * @param string $context (default: 'single') |
||
529 | * @return void |
||
530 | */ |
||
531 | function render_available_fields( $form = 0, $context = 'single' ) { |
||
532 | |||
533 | /** |
||
534 | * @filter `gravityview_blacklist_field_types` Modify the types of fields that shouldn't be shown in a View. |
||
535 | * @param[in,out] array $blacklist_field_types Array of field types to block for this context. |
||
536 | * @param[in] string $context View context ('single', 'directory', or 'edit') |
||
537 | */ |
||
538 | $blacklist_field_types = apply_filters( 'gravityview_blacklist_field_types', array(), $context ); |
||
539 | |||
540 | $fields = $this->get_available_fields( $form, $context ); |
||
541 | |||
542 | $output = ''; |
||
543 | |||
544 | if( !empty( $fields ) ) { |
||
545 | |||
546 | foreach( $fields as $id => $details ) { |
||
547 | |||
548 | if( in_array( $details['type'], $blacklist_field_types ) ) { |
||
549 | continue; |
||
550 | } |
||
551 | |||
552 | // Edit mode only allows editing the parent fields, not single inputs. |
||
553 | if( $context === 'edit' && !empty( $details['parent'] ) ) { |
||
554 | continue; |
||
555 | } |
||
556 | |||
557 | $output .= new GravityView_Admin_View_Field( $details['label'], $id, $details ); |
||
558 | |||
559 | } // End foreach |
||
560 | } |
||
561 | |||
562 | echo $output; |
||
563 | |||
564 | // For the EDIT view we only want to allow the form fields. |
||
565 | if( $context === 'edit' ) { |
||
566 | return; |
||
567 | } |
||
568 | |||
569 | $this->render_additional_fields( $form, $context ); |
||
570 | } |
||
571 | |||
572 | /** |
||
573 | * Render html for displaying additional fields based on a Form ID |
||
574 | * |
||
575 | * @access public |
||
576 | * @param int $form Gravity Forms Form ID (default: '') |
||
577 | * @param string $context (default: 'single') |
||
578 | * @return void |
||
579 | */ |
||
580 | public function render_additional_fields( $form = 0, $context = 'single' ) { |
||
624 | |||
625 | /** |
||
626 | * Retrieve the default fields id, label and type |
||
627 | * @param string|array $form form_ID or form object |
||
628 | * @param string $zone Either 'single', 'directory', 'header', 'footer' |
||
629 | * @return array |
||
630 | */ |
||
631 | function get_entry_default_fields($form, $zone) { |
||
632 | |||
633 | $entry_default_fields = array(); |
||
634 | |||
635 | if( in_array( $zone, array( 'directory', 'single' ) ) ) { |
||
636 | |||
637 | $entry_default_fields = array( |
||
638 | 'id' => array( |
||
639 | 'label' => __('Entry ID', 'gravityview'), |
||
640 | 'type' => 'id', |
||
641 | 'desc' => __('The unique ID of the entry.', 'gravityview'), |
||
642 | ), |
||
643 | 'date_created' => array( |
||
644 | 'label' => __('Entry Date', 'gravityview'), |
||
645 | 'desc' => __('The date the entry was created.', 'gravityview'), |
||
646 | 'type' => 'date_created', |
||
647 | ), |
||
648 | 'source_url' => array( |
||
649 | 'label' => __('Source URL', 'gravityview'), |
||
650 | 'type' => 'source_url', |
||
651 | 'desc' => __('The URL of the page where the form was submitted.', 'gravityview'), |
||
652 | ), |
||
653 | 'ip' => array( |
||
654 | 'label' => __('User IP', 'gravityview'), |
||
655 | 'type' => 'ip', |
||
656 | 'desc' => __('The IP Address of the user who created the entry.', 'gravityview'), |
||
657 | ), |
||
658 | 'created_by' => array( |
||
659 | 'label' => __('User', 'gravityview'), |
||
660 | 'type' => 'created_by', |
||
661 | 'desc' => __('Details of the logged-in user who created the entry (if any).', 'gravityview'), |
||
662 | ), |
||
663 | |||
664 | /** |
||
665 | * @since 1.2 |
||
666 | */ |
||
667 | 'custom' => array( |
||
668 | 'label' => __('Custom Content', 'gravityview'), |
||
669 | 'type' => 'custom', |
||
670 | 'desc' => __('Insert custom text or HTML.', 'gravityview'), |
||
671 | ), |
||
672 | |||
673 | /** |
||
674 | * @since 1.7.2 |
||
675 | */ |
||
676 | 'other_entries' => array( |
||
677 | 'label' => __('Other Entries', 'gravityview'), |
||
678 | 'type' => 'other_entries', |
||
679 | 'desc' => __('Display other entries created by the entry creator.', 'gravityview'), |
||
680 | ), |
||
681 | |||
682 | /** |
||
683 | * @since 1.14 |
||
684 | */ |
||
685 | 'notes' => array( |
||
686 | 'label' => __('Entry Notes', 'gravityview'), |
||
687 | 'type' => 'notes', |
||
688 | 'desc' => __('Entry notes (if any).', 'gravityview'), |
||
689 | ), |
||
690 | ); |
||
691 | |||
692 | if( 'single' !== $zone) { |
||
693 | |||
694 | $entry_default_fields['entry_link'] = array( |
||
695 | 'label' => __('Link to Entry', 'gravityview'), |
||
696 | 'desc' => __('A dedicated link to the single entry with customizable text.', 'gravityview'), |
||
697 | 'type' => 'entry_link', |
||
698 | ); |
||
699 | } |
||
1 ignored issue
–
show
|
|||
700 | |||
701 | } // if not zone directory or single |
||
702 | |||
703 | |||
704 | /** |
||
705 | * @filter `gravityview_entry_default_fields` Modify the default fields for each zone and context |
||
706 | * @param array $entry_default_fields Array of fields shown by default |
||
707 | * @param string|array $form form_ID or form object |
||
708 | * @param string $zone Either 'single', 'directory', 'header', 'footer' |
||
709 | */ |
||
710 | return apply_filters( 'gravityview_entry_default_fields', $entry_default_fields, $form, $zone); |
||
711 | } |
||
712 | |||
713 | /** |
||
714 | * Calculate the available fields |
||
715 | * @param string|array $form form_ID or form object |
||
716 | * @param string $zone Either 'single', 'directory', 'header', 'footer' |
||
717 | * @return array fields |
||
718 | */ |
||
719 | function get_available_fields( $form = '', $zone = NULL ) { |
||
744 | |||
745 | |||
746 | /** |
||
747 | * Render html for displaying available widgets |
||
748 | * @return string html |
||
749 | */ |
||
750 | function render_available_widgets() { |
||
764 | |||
765 | /** |
||
766 | * Get the list of registered widgets. Each item is used to instantiate a GravityView_Admin_View_Widget object |
||
767 | * @since 1.13.1 |
||
768 | * @return array |
||
769 | */ |
||
770 | function get_registered_widgets() { |
||
779 | |||
780 | /** |
||
781 | * Generic function to render rows and columns of active areas for widgets & fields |
||
782 | * @param string $template_id The current slug of the selected View template |
||
783 | * @param string $type Either 'widget' or 'field' |
||
784 | * @param string $zone Either 'single', 'directory', 'header', 'footer' |
||
785 | * @param array $rows The layout structure: rows, columns and areas |
||
786 | * @param array $values Saved objects |
||
787 | * @return void |
||
788 | */ |
||
789 | function render_active_areas( $template_id, $type, $zone, $rows, $values ) { |
||
891 | |||
892 | /** |
||
893 | * Render the widget active areas |
||
894 | * @param string $zone Either 'header' or 'footer' |
||
895 | * @param string $post_id Current Post ID (view) |
||
896 | * @return string html |
||
897 | */ |
||
898 | function render_widgets_active_areas( $template_id = '', $zone, $post_id = '' ) { |
||
922 | |||
923 | /** |
||
924 | * Render the Template Active Areas and configured active fields for a given template id and post id |
||
925 | * |
||
926 | * @access public |
||
927 | * @param string $template_id (default: '') |
||
928 | * @param string $post_id (default: '') |
||
929 | * @param string $context (default: 'single') |
||
930 | * @return string HTML of the active areas |
||
931 | */ |
||
932 | function render_directory_active_areas( $template_id = '', $context = 'single', $post_id = '', $echo = false ) { |
||
967 | |||
968 | /** |
||
969 | * Enqueue scripts and styles at Views editor |
||
970 | * |
||
971 | * @access public |
||
972 | * @param mixed $hook |
||
973 | * @return void |
||
974 | */ |
||
975 | static function add_scripts_and_styles( $hook ) { |
||
1020 | |||
1021 | static function enqueue_gravity_forms_scripts() { |
||
1022 | GFForms::register_scripts(); |
||
1023 | |||
1024 | $scripts = array( |
||
1025 | 'sack', |
||
1026 | 'gform_gravityforms', |
||
1027 | 'gform_forms', |
||
1028 | 'gform_form_admin', |
||
1029 | 'jquery-ui-autocomplete' |
||
1030 | ); |
||
1031 | |||
1032 | if ( wp_is_mobile() ) { |
||
1033 | $scripts[] = 'jquery-touch-punch'; |
||
1034 | } |
||
1035 | |||
1036 | foreach ($scripts as $script) { |
||
1037 | wp_enqueue_script( $script ); |
||
1038 | } |
||
1039 | } |
||
1040 | |||
1041 | function register_no_conflict( $registered ) { |
||
1056 | |||
1057 | |||
1058 | } |
||
1059 | |||
1061 |
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.