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 | add_action( 'save_post', array( $this, 'save_postdata' ) ); |
||
| 25 | |||
| 26 | // set the blacklist field types across the entire plugin |
||
| 27 | add_filter( 'gravityview_blacklist_field_types', array( $this, 'default_field_blacklist' ), 10, 2 ); |
||
| 28 | |||
| 29 | // Tooltips |
||
| 30 | add_filter( 'gform_tooltips', array( $this, 'tooltips') ); |
||
| 31 | |||
| 32 | // adding styles and scripts |
||
| 33 | add_action( 'admin_enqueue_scripts', array( 'GravityView_Admin_Views', 'add_scripts_and_styles'), 999 ); |
||
| 34 | add_filter( 'gform_noconflict_styles', array( $this, 'register_no_conflict') ); |
||
| 35 | add_filter( 'gform_noconflict_scripts', array( $this, 'register_no_conflict') ); |
||
| 36 | add_filter( 'gravityview_noconflict_styles', array( $this, 'register_no_conflict') ); |
||
| 37 | add_filter( 'gravityview_noconflict_scripts', array( $this, 'register_no_conflict') ); |
||
| 38 | |||
| 39 | add_action( 'gravityview_render_directory_active_areas', array( $this, 'render_directory_active_areas'), 10, 4 ); |
||
| 40 | add_action( 'gravityview_render_widgets_active_areas', array( $this, 'render_widgets_active_areas'), 10, 3 ); |
||
| 41 | add_action( 'gravityview_render_field_pickers', array( $this, 'render_field_pickers') ); |
||
| 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 | add_action( 'gform_form_actions', array( 'GravityView_Admin_Views', 'gform_toolbar_menu' ), 10, 2 ); |
||
| 54 | |||
| 55 | add_action( 'manage_gravityview_posts_custom_column', array( $this, 'add_custom_column_content'), 10, 2 ); |
||
| 56 | |||
| 57 | add_action( 'restrict_manage_posts', array( $this, 'add_view_dropdown' ) ); |
||
| 58 | |||
| 59 | add_action( 'pre_get_posts', array( $this, 'filter_pre_get_posts_by_gravityview_form_id' ) ); |
||
| 60 | |||
| 61 | add_filter( 'gravityview/support_port/localization_data', array( $this, 'suggest_support_articles' ) ); |
||
| 62 | |||
| 63 | } |
||
| 64 | |||
| 65 | /** |
||
| 66 | * When on the Add/Edit View screen, suggest most popular articles related to that |
||
| 67 | * |
||
| 68 | * @param array $localization_data Data to be passed to the Support Port JS |
||
| 69 | * |
||
| 70 | * @return array |
||
| 71 | */ |
||
| 72 | function suggest_support_articles( $localization_data = array() ) { |
||
| 73 | |||
| 74 | if( ! gravityview()->request->is_view() ) { |
||
| 75 | return $localization_data; |
||
| 76 | } |
||
| 77 | |||
| 78 | $localization_data['suggest'] = array( |
||
| 79 | '57ef23539033602e61d4a560', |
||
| 80 | '54c67bb9e4b0512429885513', |
||
| 81 | '54c67bb9e4b0512429885512', |
||
| 82 | '54c67bbbe4b07997ea3f3f6b', |
||
| 83 | '54d1a33ae4b086c0c0964ce9', |
||
| 84 | '57ef253c9033602e61d4a563', |
||
| 85 | '552355bfe4b0221aadf2572b', |
||
| 86 | '54c67bcde4b051242988553e', |
||
| 87 | ); |
||
| 88 | |||
| 89 | return $localization_data; |
||
| 90 | } |
||
| 91 | |||
| 92 | /** |
||
| 93 | * @since 1.15 |
||
| 94 | * @param WP_Query $query |
||
| 95 | */ |
||
| 96 | public function filter_pre_get_posts_by_gravityview_form_id( &$query ) { |
||
| 97 | global $pagenow; |
||
| 98 | |||
| 99 | if ( !is_admin() ) { |
||
| 100 | return; |
||
| 101 | } |
||
| 102 | |||
| 103 | $form_id = isset( $_GET['gravityview_form_id'] ) ? (int) $_GET['gravityview_form_id'] : false; |
||
| 104 | |||
| 105 | if( 'edit.php' !== $pagenow || ! $form_id || ! isset( $query->query_vars[ 'post_type' ] ) ) { |
||
| 106 | return; |
||
| 107 | } |
||
| 108 | |||
| 109 | if ( $query->query_vars[ 'post_type' ] == 'gravityview' ) { |
||
| 110 | $query->set( 'meta_query', array( |
||
| 111 | array( |
||
| 112 | 'key' => '_gravityview_form_id', |
||
| 113 | 'value' => $form_id, |
||
| 114 | ) |
||
| 115 | ) ); |
||
| 116 | } |
||
| 117 | } |
||
| 118 | |||
| 119 | function add_view_dropdown() { |
||
| 120 | $current_screen = get_current_screen(); |
||
| 121 | |||
| 122 | if( 'gravityview' !== $current_screen->post_type ) { |
||
| 123 | return; |
||
| 124 | } |
||
| 125 | |||
| 126 | $forms = gravityview_get_forms(); |
||
| 127 | $current_form = \GV\Utils::_GET( 'gravityview_form_id' ); |
||
| 128 | // If there are no forms to select, show no forms. |
||
| 129 | if( !empty( $forms ) ) { ?> |
||
| 130 | <select name="gravityview_form_id" id="gravityview_form_id"> |
||
| 131 | <option value="" <?php selected( '', $current_form, true ); ?>><?php esc_html_e( 'All forms', 'gravityview' ); ?></option> |
||
| 132 | <?php foreach( $forms as $form ) { ?> |
||
| 133 | <option value="<?php echo $form['id']; ?>" <?php selected( $form['id'], $current_form, true ); ?>><?php echo esc_html( $form['title'] ); ?></option> |
||
| 134 | <?php } ?> |
||
| 135 | </select> |
||
| 136 | <?php } |
||
| 137 | } |
||
| 138 | |||
| 139 | |||
| 140 | /** |
||
| 141 | * @deprecated since 1.2 |
||
| 142 | * Start using GravityView_Render_Settings::render_setting_row |
||
| 143 | */ |
||
| 144 | public static function render_setting_row( $key = '', $current_settings = array(), $override_input = null, $name = 'template_settings[%s]', $id = 'gravityview_se_%s' ) { |
||
| 148 | |||
| 149 | /** |
||
| 150 | * @deprecated since 1.2 |
||
| 151 | * Start using GravityView_Render_Settings::render_field_option |
||
| 152 | */ |
||
| 153 | public static function render_field_option( $name = '', $option, $curr_value = NULL ) { |
||
| 154 | _deprecated_function( 'GravityView_Admin_Views::render_field_option', '1.1.7', 'GravityView_Render_Settings::render_field_option' ); |
||
| 155 | return GravityView_Render_Settings::render_field_option( $name, $option, $curr_value ); |
||
| 156 | } |
||
| 157 | |||
| 158 | |||
| 159 | /** |
||
| 160 | * Add a GravityView menu to the Form Toolbar with connected views |
||
| 161 | * @param array $menu_items Menu items, as set in GFForms::top_toolbar() |
||
| 162 | * @param int $id ID of the current Gravity form |
||
| 163 | * @return array Modified array |
||
| 164 | */ |
||
| 165 | public static function gform_toolbar_menu( $menu_items = array(), $id = NULL ) { |
||
| 166 | |||
| 167 | // Don't show on Trashed forms |
||
| 168 | if( 'trash' === rgget( 'filter') ) { |
||
| 169 | return $menu_items; |
||
| 170 | } |
||
| 171 | |||
| 172 | $connected_views = gravityview_get_connected_views( $id, array( 'post_status' => 'any' ) ); |
||
| 173 | |||
| 174 | $priority = 0; |
||
| 175 | |||
| 176 | if( 'form_list' === GFForms::get_page() ) { |
||
| 177 | $priority = 790; |
||
| 178 | } |
||
| 179 | |||
| 180 | if( empty( $connected_views ) ) { |
||
| 181 | |||
| 182 | $menu_items['gravityview'] = array( |
||
| 183 | 'label' => esc_attr__( 'Create a View', 'gravityview' ), |
||
| 184 | 'icon' => '<i class="fa fa-lg gv-icon-astronaut-head gv-icon"></i>', |
||
| 185 | 'title' => esc_attr__( 'Create a View using this form as a data source', 'gravityview' ), |
||
| 186 | 'url' => admin_url( 'post-new.php?post_type=gravityview&form_id=' . $id ), |
||
| 187 | 'menu_class' => 'gv_connected_forms gf_form_toolbar_settings', |
||
| 188 | 'priority' => $priority, |
||
| 189 | 'capabilities' => array( 'edit_gravityviews' ), |
||
| 190 | ); |
||
| 191 | |||
| 192 | return $menu_items; |
||
| 193 | } |
||
| 194 | |||
| 195 | $sub_menu_items = array(); |
||
| 196 | foreach ( (array)$connected_views as $view ) { |
||
| 197 | |||
| 198 | if( ! GVCommon::has_cap( 'edit_gravityview', $view->ID ) ) { |
||
| 199 | continue; |
||
| 200 | } |
||
| 201 | |||
| 202 | $label = empty( $view->post_title ) ? sprintf( __('No Title (View #%d)', 'gravityview' ), $view->ID ) : $view->post_title; |
||
| 203 | |||
| 204 | $sub_menu_items[] = array( |
||
| 205 | 'label' => esc_attr( $label ), |
||
| 206 | 'url' => admin_url( 'post.php?action=edit&post='.$view->ID ), |
||
| 207 | ); |
||
| 208 | } |
||
| 209 | |||
| 210 | // If there were no items added, then let's create the parent menu |
||
| 211 | if( $sub_menu_items ) { |
||
| 212 | |||
| 213 | $sub_menu_items[] = array( |
||
| 214 | 'label' => esc_attr__( 'Create a View', 'gravityview' ), |
||
| 215 | 'link_class' => 'gv-create-view', |
||
| 216 | 'title' => esc_attr__( 'Create a View using this form as a data source', 'gravityview' ), |
||
| 217 | 'url' => admin_url( 'post-new.php?post_type=gravityview&form_id=' . $id ), |
||
| 218 | 'capabilities' => array( 'edit_gravityviews' ), |
||
| 219 | ); |
||
| 220 | |||
| 221 | // Make sure Gravity Forms uses the submenu; if there's only one item, it uses a link instead of a dropdown |
||
| 222 | $sub_menu_items[] = array( |
||
| 223 | 'url' => '#', |
||
| 224 | 'label' => '', |
||
| 225 | 'menu_class' => 'hidden', |
||
| 226 | 'capabilities' => '', |
||
| 227 | ); |
||
| 228 | |||
| 229 | $menu_items['gravityview'] = array( |
||
| 230 | 'label' => __( 'Connected Views', 'gravityview' ), |
||
| 231 | 'icon' => '<i class="fa fa-lg gv-icon-astronaut-head gv-icon"></i>', |
||
| 232 | 'title' => __( 'GravityView Views using this form as a data source', 'gravityview' ), |
||
| 233 | 'url' => '#', |
||
| 234 | 'onclick' => 'return false;', |
||
| 235 | 'menu_class' => 'gv_connected_forms gf_form_toolbar_settings', |
||
| 236 | 'sub_menu_items' => $sub_menu_items, |
||
| 237 | 'priority' => $priority, |
||
| 238 | 'capabilities' => array( 'edit_gravityviews' ), |
||
| 239 | ); |
||
| 240 | } |
||
| 241 | |||
| 242 | return $menu_items; |
||
| 243 | } |
||
| 244 | |||
| 245 | /** |
||
| 246 | * List the field types without presentation properties (on a View context) |
||
| 247 | * |
||
| 248 | * @param array $array Existing field types to add to a blacklist |
||
| 249 | * @param string|null $context Context for the blacklist. Default: NULL. |
||
| 250 | * @access public |
||
| 251 | * @return array Default blacklist fields merged with existing blacklist fields |
||
| 252 | */ |
||
| 253 | function default_field_blacklist( $array = array(), $context = NULL ) { |
||
| 266 | |||
| 267 | /** |
||
| 268 | * Add tooltip text for use throughout the UI |
||
| 269 | * @param array $tooltips Array of Gravity Forms tooltips |
||
| 270 | * @return array Modified tooltips array |
||
| 271 | */ |
||
| 272 | public function tooltips( $tooltips = array() ) { |
||
| 273 | |||
| 274 | $gv_tooltips = array(); |
||
| 275 | |||
| 276 | // Generate tooltips for View settings |
||
| 277 | $default_args = \GV\View_Settings::defaults( true ); |
||
| 278 | |||
| 279 | foreach ( $default_args as $key => $arg ) { |
||
| 280 | |||
| 281 | // If an arg has `tooltip` defined, but it's false, don't display a tooltip |
||
| 282 | if( isset( $arg['tooltip'] ) && empty( $arg['tooltip'] ) ) { continue; } |
||
| 283 | |||
| 284 | // By default, use `tooltip` if defined. |
||
| 285 | $tooltip = empty( $arg['tooltip'] ) ? NULL : $arg['tooltip']; |
||
| 286 | |||
| 287 | // Otherwise, use the description as a tooltip. |
||
| 288 | if( empty( $tooltip ) && !empty( $arg['desc'] ) ) { |
||
| 289 | $tooltip = $arg['desc']; |
||
| 290 | } |
||
| 291 | |||
| 292 | // If there's no tooltip set, continue |
||
| 293 | if( empty( $tooltip ) ) { |
||
| 294 | continue; |
||
| 295 | } |
||
| 296 | |||
| 297 | // Add the tooltip |
||
| 298 | $gv_tooltips[ 'gv_'.$key ] = array( |
||
| 299 | 'title' => $arg['label'], |
||
| 300 | 'value' => $tooltip, |
||
| 301 | ); |
||
| 302 | |||
| 303 | } |
||
| 304 | |||
| 305 | $gv_tooltips['gv_css_merge_tags'] = array( |
||
| 306 | 'title' => __('CSS Merge Tags', 'gravityview'), |
||
| 307 | 'value' => sprintf( __( 'Developers: The CSS classes will be sanitized using the %ssanitize_title_with_dashes()%s function.', 'gravityview'), '<code>', '</code>' ) |
||
| 308 | ); |
||
| 309 | |||
| 310 | /** |
||
| 311 | * @filter `gravityview_tooltips` The tooltips GravityView adds to the Gravity Forms tooltip array |
||
| 312 | * @param array $gv_tooltips Associative array with unique keys containing array of `title` and `value` keys, as expected by `gform_tooltips` filter |
||
| 313 | * @deprecated Renamed to `gravityview/metaboxes/tooltips` |
||
| 314 | */ |
||
| 315 | $gv_tooltips = apply_filters( 'gravityview_tooltips', $gv_tooltips ); |
||
| 316 | |||
| 317 | /** |
||
| 318 | * @filter `gravityview/metaboxes/tooltips` The tooltips GravityView adds to the Gravity Forms tooltip array |
||
| 319 | * @param array $gv_tooltips Associative array with unique keys containing array of `title` and `value` keys, as expected by `gform_tooltips` filter |
||
| 320 | */ |
||
| 321 | $gv_tooltips = apply_filters( 'gravityview/metaboxes/tooltips', $gv_tooltips ); |
||
| 322 | |||
| 323 | foreach ( $gv_tooltips as $key => $tooltip ) { |
||
| 324 | |||
| 325 | $title = empty( $tooltip['title'] ) ? '' : '<h6>'.esc_html( $tooltip['title'] ) .'</h6>'; |
||
| 326 | |||
| 327 | $tooltips[ $key ] = $title . wpautop( esc_html( $tooltip['value'] ) ); |
||
| 328 | } |
||
| 329 | |||
| 330 | return $tooltips; |
||
| 331 | } |
||
| 332 | |||
| 333 | /** |
||
| 334 | * Add the Data Source information |
||
| 335 | * |
||
| 336 | * @param null $column_name |
||
| 337 | * @param $post_id |
||
| 338 | * |
||
| 339 | * @return void |
||
| 340 | */ |
||
| 341 | public function add_custom_column_content( $column_name = NULL, $post_id ) { |
||
| 342 | |||
| 343 | $output = ''; |
||
| 344 | |||
| 345 | switch ( $column_name ) { |
||
| 346 | case 'gv_template': |
||
| 347 | |||
| 348 | $template_id = gravityview_get_template_id( $post_id ); |
||
| 349 | |||
| 350 | // All Views should have a connected form. If it doesn't, that's not right. |
||
| 351 | if ( empty( $template_id ) ) { |
||
| 352 | gravityview()->log->error( 'View ID {view_id} does not have a connected template.', array( 'view_id' => $post_id ) ); |
||
| 353 | break; |
||
| 354 | } |
||
| 355 | |||
| 356 | $templates = gravityview_get_registered_templates(); |
||
| 357 | |||
| 358 | $template = isset( $templates[ $template_id ] ) ? $templates[ $template_id ] : false; |
||
| 359 | |||
| 360 | // Generate backup if label doesn't exist: `example_name` => `Example Name` |
||
| 361 | $template_id_pretty = ucwords( implode( ' ', explode( '_', $template_id ) ) ); |
||
| 362 | |||
| 363 | $output = $template ? $template['label'] : $template_id_pretty; |
||
| 364 | |||
| 365 | break; |
||
| 366 | |||
| 367 | case 'gv_connected_form': |
||
| 368 | |||
| 369 | $form_id = gravityview_get_form_id( $post_id ); |
||
| 370 | |||
| 371 | // All Views should have a connected form. If it doesn't, that's not right. |
||
| 372 | if ( empty( $form_id ) ) { |
||
| 373 | gravityview()->log->error( 'View ID {view_id} does not have a connected GF form.', array( 'view_id' => $post_id ) ); |
||
| 374 | $output = __( 'Not connected.', 'gravityview' ); |
||
| 375 | break; |
||
| 376 | } |
||
| 377 | |||
| 378 | $form = gravityview_get_form( $form_id ); |
||
| 379 | |||
| 380 | if ( ! $form ) { |
||
| 381 | gravityview()->log->error( 'Connected form not found: Form #{form_id}', array( 'form_id' => $form_id ) ); |
||
| 382 | |||
| 383 | $output = __( 'The connected form can not be found; it may no longer exist.', 'gravityview' ); |
||
| 384 | } else { |
||
| 385 | $output = self::get_connected_form_links( $form ); |
||
| 386 | } |
||
| 387 | |||
| 388 | break; |
||
| 389 | } |
||
| 390 | |||
| 391 | echo $output; |
||
| 392 | } |
||
| 393 | |||
| 394 | |||
| 395 | /** |
||
| 396 | * Get HTML links relating to a connected form, like Edit, Entries, Settings, Preview |
||
| 397 | * @param array|int $form Gravity Forms forms array, or the form ID |
||
| 398 | * @param boolean $include_form_link Whether to include the bold name of the form in the output |
||
| 399 | * @return string HTML links |
||
| 400 | */ |
||
| 401 | static public function get_connected_form_links( $form, $include_form_link = true ) { |
||
| 402 | |||
| 403 | // Either the form is empty or the form ID is 0, not yet set. |
||
| 404 | if( empty( $form ) ) { |
||
| 405 | return ''; |
||
| 406 | } |
||
| 407 | |||
| 408 | // The $form is passed as the form ID |
||
| 409 | if( !is_array( $form ) ) { |
||
| 410 | $form = gravityview_get_form( $form ); |
||
| 411 | } |
||
| 412 | |||
| 413 | $form_id = $form['id']; |
||
| 414 | $links = array(); |
||
| 415 | |||
| 416 | if( GVCommon::has_cap( 'gravityforms_edit_forms' ) ) { |
||
| 417 | $form_url = admin_url( sprintf( 'admin.php?page=gf_edit_forms&id=%d', $form_id ) ); |
||
| 418 | $form_link = '<strong class="gv-form-title">'.gravityview_get_link( $form_url, $form['title'], 'class=row-title' ).'</strong>'; |
||
| 419 | $links[] = '<span>'.gravityview_get_link( $form_url, __('Edit Form', 'gravityview') ).'</span>'; |
||
| 420 | } else { |
||
| 421 | $form_link = '<strong class="gv-form-title">'. esc_html( $form['title'] ). '</strong>'; |
||
| 422 | } |
||
| 423 | |||
| 424 | if( GVCommon::has_cap( 'gravityforms_view_entries' ) ) { |
||
| 425 | $entries_url = admin_url( sprintf( 'admin.php?page=gf_entries&id=%d', $form_id ) ); |
||
| 426 | $links[] = '<span>'.gravityview_get_link( $entries_url, __('Entries', 'gravityview') ).'</span>'; |
||
| 427 | } |
||
| 428 | |||
| 429 | if( GVCommon::has_cap( array( 'gravityforms_edit_settings', 'gravityview_view_settings' ) ) ) { |
||
| 430 | $settings_url = admin_url( sprintf( 'admin.php?page=gf_edit_forms&view=settings&id=%d', $form_id ) ); |
||
| 431 | $links[] = '<span>'.gravityview_get_link( $settings_url, __('Settings', 'gravityview'), 'title='.__('Edit settings for this form', 'gravityview') ).'</span>'; |
||
| 432 | } |
||
| 433 | |||
| 434 | if( GVCommon::has_cap( array("gravityforms_edit_forms", "gravityforms_create_form", "gravityforms_preview_forms") ) ) { |
||
| 435 | $preview_url = site_url( sprintf( '?gf_page=preview&id=%d', $form_id ) ); |
||
| 436 | $links[] = '<span>'.gravityview_get_link( $preview_url, __('Preview Form', 'gravityview'), 'title='.__('Preview this form', 'gravityview') ).'</span>'; |
||
| 437 | } |
||
| 438 | |||
| 439 | $output = ''; |
||
| 440 | |||
| 441 | if( !empty( $include_form_link ) ) { |
||
| 442 | $output .= $form_link; |
||
| 443 | } |
||
| 444 | |||
| 445 | /** |
||
| 446 | * @filter `gravityview_connected_form_links` Modify the links shown in the Connected Form links |
||
| 447 | * @since 1.6 |
||
| 448 | * @param array $links Links to show |
||
| 449 | * @param array $form Gravity Forms form array |
||
| 450 | */ |
||
| 451 | $links = apply_filters( 'gravityview_connected_form_links', $links, $form ); |
||
| 452 | |||
| 453 | $output .= '<div class="row-actions">'. implode( ' | ', $links ) .'</div>'; |
||
| 454 | |||
| 455 | return $output; |
||
| 456 | } |
||
| 457 | |||
| 458 | /** |
||
| 459 | * Add the Data Source column to the Views page |
||
| 460 | * @param array $columns Columns array |
||
| 461 | */ |
||
| 462 | public function add_post_type_columns( $columns ) { |
||
| 463 | |||
| 464 | // Get the date column and save it for later to add back in. |
||
| 465 | // This adds it after the Data Source column. |
||
| 466 | // This way, we don't need to do array_slice, array_merge, etc. |
||
| 467 | $date = $columns['date']; |
||
| 468 | unset( $columns['date'] ); |
||
| 469 | |||
| 470 | $data_source_required_caps = array( |
||
| 471 | 'gravityforms_edit_forms', |
||
| 472 | 'gravityforms_view_entries', |
||
| 473 | 'gravityforms_edit_settings', |
||
| 474 | 'gravityview_view_settings', |
||
| 475 | 'gravityforms_create_form', |
||
| 476 | 'gravityforms_preview_forms', |
||
| 477 | ); |
||
| 478 | |||
| 479 | if( GVCommon::has_cap( $data_source_required_caps ) ) { |
||
| 480 | $columns['gv_connected_form'] = __( 'Data Source', 'gravityview' ); |
||
| 481 | } |
||
| 482 | |||
| 483 | $columns['gv_template'] = _x( 'Template', 'Column title that shows what template is being used for Views', 'gravityview' ); |
||
| 484 | |||
| 485 | // Add the date back in. |
||
| 486 | $columns['date'] = $date; |
||
| 487 | |||
| 488 | return $columns; |
||
| 489 | } |
||
| 490 | |||
| 491 | /** |
||
| 492 | * Save View configuration |
||
| 493 | * |
||
| 494 | * @access public |
||
| 495 | * @param int $post_id Currently saved Post ID |
||
| 496 | * @return void |
||
| 497 | */ |
||
| 498 | function save_postdata( $post_id ) { |
||
| 499 | |||
| 500 | if( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ){ |
||
| 501 | return; |
||
| 502 | } |
||
| 503 | |||
| 504 | // validate post_type |
||
| 505 | if ( ! isset( $_POST['post_type'] ) || 'gravityview' != $_POST['post_type'] ) { |
||
| 506 | return; |
||
| 507 | } |
||
| 508 | |||
| 509 | // validate user can edit and save View |
||
| 510 | if ( ! GVCommon::has_cap( 'edit_gravityview', $post_id ) ) { |
||
| 511 | gravityview()->log->error( 'Current user does not have the capability to edit View {view_id}', array( 'view_id' => $post_id, 'data' => wp_get_current_user() ) ); |
||
| 512 | return; |
||
| 513 | } |
||
| 514 | |||
| 515 | gravityview()->log->debug( '[save_postdata] Saving View post type.', array( 'data' => $_POST ) ); |
||
| 516 | |||
| 517 | $statii = array(); |
||
| 518 | |||
| 519 | // check if this is a start fresh View |
||
| 520 | if ( isset( $_POST['gravityview_select_form_nonce'] ) && wp_verify_nonce( $_POST['gravityview_select_form_nonce'], 'gravityview_select_form' ) ) { |
||
| 521 | |||
| 522 | $form_id = !empty( $_POST['gravityview_form_id'] ) ? $_POST['gravityview_form_id'] : ''; |
||
| 523 | // save form id |
||
| 524 | $statii['form_id'] = update_post_meta( $post_id, '_gravityview_form_id', $form_id ); |
||
| 525 | |||
| 526 | } |
||
| 527 | |||
| 528 | if( false === GVCommon::has_cap( 'gravityforms_create_form' ) && empty( $statii['form_id'] ) ) { |
||
| 529 | gravityview()->log->error( 'Current user does not have the capability to create a new Form.', array( 'data' => wp_get_current_user() ) ); |
||
| 530 | return; |
||
| 531 | } |
||
| 532 | |||
| 533 | // Was this a start fresh? |
||
| 534 | if ( ! empty( $_POST['gravityview_form_id_start_fresh'] ) ) { |
||
| 535 | $statii['start_fresh'] = add_post_meta( $post_id, '_gravityview_start_fresh', 1 ); |
||
| 536 | } else { |
||
| 537 | $statii['start_fresh'] = delete_post_meta( $post_id, '_gravityview_start_fresh' ); |
||
| 538 | } |
||
| 539 | |||
| 540 | // Check if we have a template id |
||
| 541 | if ( isset( $_POST['gravityview_select_template_nonce'] ) && wp_verify_nonce( $_POST['gravityview_select_template_nonce'], 'gravityview_select_template' ) ) { |
||
| 542 | |||
| 543 | $template_id = !empty( $_POST['gravityview_directory_template'] ) ? $_POST['gravityview_directory_template'] : ''; |
||
| 544 | |||
| 545 | // now save template id |
||
| 546 | $statii['directory_template'] = update_post_meta( $post_id, '_gravityview_directory_template', $template_id ); |
||
| 547 | } |
||
| 548 | |||
| 549 | |||
| 550 | // save View Configuration metabox |
||
| 551 | if ( isset( $_POST['gravityview_view_configuration_nonce'] ) && wp_verify_nonce( $_POST['gravityview_view_configuration_nonce'], 'gravityview_view_configuration' ) ) { |
||
| 552 | |||
| 553 | // template settings |
||
| 554 | if( empty( $_POST['template_settings'] ) ) { |
||
| 555 | $_POST['template_settings'] = array(); |
||
| 556 | } |
||
| 557 | $statii['template_settings'] = update_post_meta( $post_id, '_gravityview_template_settings', $_POST['template_settings'] ); |
||
| 558 | |||
| 559 | // guard against unloaded View configuration page |
||
| 560 | if ( isset( $_POST['gv_fields'] ) && isset( $_POST['gv_fields_done'] ) ) { |
||
| 561 | $fields = array(); |
||
| 562 | |||
| 563 | if ( ! empty( $_POST['gv_fields'] ) ) { |
||
| 564 | $fields = _gravityview_process_posted_fields(); |
||
| 565 | } |
||
| 566 | |||
| 567 | $fields = wp_slash( $fields ); |
||
| 568 | |||
| 569 | $statii['directory_fields'] = update_post_meta( $post_id, '_gravityview_directory_fields', $fields ); |
||
| 570 | } |
||
| 571 | |||
| 572 | // Directory Visible Widgets |
||
| 573 | if( empty( $_POST['widgets'] ) ) { |
||
| 574 | $_POST['widgets'] = array(); |
||
| 575 | } |
||
| 576 | $statii['directory_widgets'] = gravityview_set_directory_widgets( $post_id, $_POST['widgets'] ); |
||
| 577 | |||
| 578 | } // end save view configuration |
||
| 579 | |||
| 580 | /** |
||
| 581 | * @action `gravityview_view_saved` After a View has been saved in the admin |
||
| 582 | * @param int $post_id ID of the View that has been saved |
||
| 583 | * @param array $statii Array of statuses of the post meta saving processes. If saving worked, each key should be mapped to a value of the post ID (`directory_widgets` => `124`). If failed (or didn't change), the value will be false. |
||
| 584 | * @since 1.17.2 |
||
| 585 | */ |
||
| 586 | do_action('gravityview_view_saved', $post_id, $statii ); |
||
| 587 | |||
| 588 | gravityview()->log->debug( '[save_postdata] Update Post Meta Statuses (also returns false if nothing changed)', array( 'data' => array_map( 'intval', $statii ) ) ); |
||
| 589 | } |
||
| 590 | |||
| 591 | /** |
||
| 592 | * @deprecated 1.1.6 |
||
| 593 | */ |
||
| 594 | function render_label() { |
||
| 597 | |||
| 598 | /** |
||
| 599 | * Render html for displaying available fields based on a Form ID |
||
| 600 | * $blacklist_field_types - contains the field types which are not proper to be shown in a directory. |
||
| 601 | * |
||
| 602 | * @see GravityView_Ajax::get_available_fields_html() Triggers `gravityview_render_available_fields` action |
||
| 603 | * @access public |
||
| 604 | * |
||
| 605 | * @param int $form Gravity Forms Form ID (default: '') |
||
| 606 | * @param string $context (default: 'single') |
||
| 607 | * |
||
| 608 | * @return void |
||
| 609 | */ |
||
| 610 | function render_available_fields( $form = 0, $context = 'single' ) { |
||
| 657 | |||
| 658 | /** |
||
| 659 | * Render html for displaying additional fields based on a Form ID |
||
| 660 | * |
||
| 661 | * @access public |
||
| 662 | * @param int $form Gravity Forms Form ID (default: '') |
||
| 663 | * @param string $context (default: 'single') |
||
| 664 | * @return void |
||
| 665 | */ |
||
| 666 | public function render_additional_fields( $form = 0, $context = 'single' ) { |
||
| 710 | |||
| 711 | /** |
||
| 712 | * Retrieve the default fields id, label and type |
||
| 713 | * @param string|array $form form_ID or form object |
||
| 714 | * @param string $zone Either 'single', 'directory', 'header', 'footer' |
||
| 715 | * @return array |
||
| 716 | */ |
||
| 717 | function get_entry_default_fields($form, $zone) { |
||
| 797 | |||
| 798 | /** |
||
| 799 | * Calculate the available fields |
||
| 800 | * @param string|array $form form_ID or form object |
||
| 801 | * @param string $zone Either 'single', 'directory', 'header', 'footer' |
||
| 802 | * @return array fields |
||
| 803 | */ |
||
| 804 | function get_available_fields( $form = '', $zone = NULL ) { |
||
| 838 | |||
| 839 | |||
| 840 | /** |
||
| 841 | * Render html for displaying available widgets |
||
| 842 | * @return string html |
||
| 843 | */ |
||
| 844 | function render_available_widgets() { |
||
| 858 | |||
| 859 | /** |
||
| 860 | * Get the list of registered widgets. Each item is used to instantiate a GravityView_Admin_View_Widget object |
||
| 861 | * @deprecated Use \GV\Widget::registered() |
||
| 862 | * @since 1.13.1 |
||
| 863 | * @return array |
||
| 864 | */ |
||
| 865 | function get_registered_widgets() { |
||
| 868 | |||
| 869 | /** |
||
| 870 | * Generic function to render rows and columns of active areas for widgets & fields |
||
| 871 | * @param string $template_id The current slug of the selected View template |
||
| 872 | * @param string $type Either 'widget' or 'field' |
||
| 873 | * @param string $zone Either 'single', 'directory', 'header', 'footer' |
||
| 874 | * @param array $rows The layout structure: rows, columns and areas |
||
| 875 | * @param array $values Saved objects |
||
| 876 | * @return void |
||
| 877 | */ |
||
| 878 | function render_active_areas( $template_id, $type, $zone, $rows, $values ) { |
||
| 990 | |||
| 991 | /** |
||
| 992 | * Render the widget active areas |
||
| 993 | * @param string $template_id The current slug of the selected View template |
||
| 994 | * @param string $zone Either 'header' or 'footer' |
||
| 995 | * @param string $post_id Current Post ID (view) |
||
| 996 | * @return string html |
||
| 997 | */ |
||
| 998 | function render_widgets_active_areas( $template_id = '', $zone = '', $post_id = '' ) { |
||
| 1065 | |||
| 1066 | /** |
||
| 1067 | * Renders "Add Field" tooltips |
||
| 1068 | * |
||
| 1069 | * @since 2.0.11 |
||
| 1070 | * |
||
| 1071 | * @param string $context "directory", "single", or "edit" |
||
| 1072 | * |
||
| 1073 | * @return void |
||
| 1074 | */ |
||
| 1075 | function render_field_pickers( $context = 'directory' ) { |
||
| 1101 | |||
| 1102 | /** |
||
| 1103 | * Render the Template Active Areas and configured active fields for a given template id and post id |
||
| 1104 | * |
||
| 1105 | * @access public |
||
| 1106 | * @param string $template_id (default: '') Template ID, like `default_list`, `default_table`, `preset_business_data`, etc. {@see GravityView_Template::__construct()} |
||
| 1107 | * @param string $post_id (default: '') |
||
| 1108 | * @param string $context (default: 'single') |
||
| 1109 | * @return string HTML of the active areas |
||
| 1110 | */ |
||
| 1111 | function render_directory_active_areas( $template_id = '', $context = 'single', $post_id = '', $echo = false ) { |
||
| 1152 | |||
| 1153 | /** |
||
| 1154 | * Enqueue scripts and styles at Views editor |
||
| 1155 | * |
||
| 1156 | * @access public |
||
| 1157 | * @param mixed $hook |
||
| 1158 | * @return void |
||
| 1159 | */ |
||
| 1160 | static function add_scripts_and_styles( $hook ) { |
||
| 1210 | |||
| 1211 | /** |
||
| 1212 | * Enqueue Gravity Forms scripts, needed for Merge Tags |
||
| 1213 | * |
||
| 1214 | * @since 1.0.5-beta |
||
| 1215 | * |
||
| 1216 | * @return void |
||
| 1217 | */ |
||
| 1218 | static function enqueue_gravity_forms_scripts() { |
||
| 1235 | |||
| 1236 | /** |
||
| 1237 | * Add GravityView scripts and styles to Gravity Forms and GravityView No-Conflict modes |
||
| 1238 | * |
||
| 1239 | * @param array $registered Existing scripts or styles that have been registered (array of the handles) |
||
| 1240 | * |
||
| 1241 | * @return array |
||
| 1242 | */ |
||
| 1243 | function register_no_conflict( $registered ) { |
||
| 1283 | |||
| 1284 | |||
| 1285 | } |
||
| 1286 | |||
| 1288 |
Adding explicit visibility (
private,protected, orpublic) is generally recommend to communicate to other developers how, and from where this method is intended to be used.