@@ -1037,15 +1037,15 @@ |
||
| 1037 | 1037 | GFForms::register_scripts(); |
| 1038 | 1038 | |
| 1039 | 1039 | $scripts = array( |
| 1040 | - 'sack', |
|
| 1041 | - 'gform_gravityforms', |
|
| 1042 | - 'gform_forms', |
|
| 1043 | - 'gform_form_admin', |
|
| 1044 | - 'jquery-ui-autocomplete' |
|
| 1040 | + 'sack', |
|
| 1041 | + 'gform_gravityforms', |
|
| 1042 | + 'gform_forms', |
|
| 1043 | + 'gform_form_admin', |
|
| 1044 | + 'jquery-ui-autocomplete' |
|
| 1045 | 1045 | ); |
| 1046 | 1046 | |
| 1047 | 1047 | if ( wp_is_mobile() ) { |
| 1048 | - $scripts[] = 'jquery-touch-punch'; |
|
| 1048 | + $scripts[] = 'jquery-touch-punch'; |
|
| 1049 | 1049 | } |
| 1050 | 1050 | |
| 1051 | 1051 | foreach ($scripts as $script) { |
@@ -28,30 +28,30 @@ discard block |
||
| 28 | 28 | add_filter( 'gravityview_blacklist_field_types', array( $this, 'default_field_blacklist' ), 10, 2 ); |
| 29 | 29 | |
| 30 | 30 | // Tooltips |
| 31 | - add_filter( 'gform_tooltips', array( $this, 'tooltips') ); |
|
| 31 | + add_filter( 'gform_tooltips', array( $this, 'tooltips' ) ); |
|
| 32 | 32 | |
| 33 | 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 ); |
|
| 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 | 45 | |
| 46 | 46 | // @todo check if this hook is needed.. |
| 47 | 47 | //add_action( 'gravityview_render_field_options', array( $this, 'render_field_options'), 10, 9 ); |
| 48 | 48 | |
| 49 | 49 | // Add Connected Form column |
| 50 | - add_filter('manage_gravityview_posts_columns' , array( $this, 'add_post_type_columns' ) ); |
|
| 50 | + add_filter( 'manage_gravityview_posts_columns', array( $this, 'add_post_type_columns' ) ); |
|
| 51 | 51 | |
| 52 | 52 | add_filter( 'gform_toolbar_menu', array( 'GravityView_Admin_Views', 'gform_toolbar_menu' ), 10, 2 ); |
| 53 | 53 | |
| 54 | - add_action( 'manage_gravityview_posts_custom_column', array( $this, 'add_custom_column_content'), 10, 2 ); |
|
| 54 | + add_action( 'manage_gravityview_posts_custom_column', array( $this, 'add_custom_column_content' ), 10, 2 ); |
|
| 55 | 55 | |
| 56 | 56 | add_action( 'restrict_manage_posts', array( $this, 'add_view_dropdown' ) ); |
| 57 | 57 | |
@@ -66,11 +66,11 @@ discard block |
||
| 66 | 66 | public function filter_pre_get_posts_by_gravityview_form_id( &$query ) { |
| 67 | 67 | global $pagenow; |
| 68 | 68 | |
| 69 | - if ( !is_admin() ) { |
|
| 69 | + if ( ! is_admin() ) { |
|
| 70 | 70 | return; |
| 71 | 71 | } |
| 72 | 72 | |
| 73 | - if( 'edit.php' !== $pagenow || ! rgget( 'gravityview_form_id' ) || ! isset( $query->query_vars[ 'post_type' ] ) ) { |
|
| 73 | + if ( 'edit.php' !== $pagenow || ! rgget( 'gravityview_form_id' ) || ! isset( $query->query_vars[ 'post_type' ] ) ) { |
|
| 74 | 74 | return; |
| 75 | 75 | } |
| 76 | 76 | |
@@ -87,18 +87,18 @@ discard block |
||
| 87 | 87 | function add_view_dropdown() { |
| 88 | 88 | $current_screen = get_current_screen(); |
| 89 | 89 | |
| 90 | - if( 'gravityview' !== $current_screen->post_type ) { |
|
| 90 | + if ( 'gravityview' !== $current_screen->post_type ) { |
|
| 91 | 91 | return; |
| 92 | 92 | } |
| 93 | 93 | |
| 94 | 94 | $forms = gravityview_get_forms(); |
| 95 | 95 | $current_form = rgget( 'gravityview_form_id' ); |
| 96 | 96 | // If there are no forms to select, show no forms. |
| 97 | - if( !empty( $forms ) ) { ?> |
|
| 97 | + if ( ! empty( $forms ) ) { ?> |
|
| 98 | 98 | <select name="gravityview_form_id" id="gravityview_form_id"> |
| 99 | 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> |
|
| 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 | 102 | <?php } ?> |
| 103 | 103 | </select> |
| 104 | 104 | <?php } |
@@ -111,7 +111,7 @@ discard block |
||
| 111 | 111 | */ |
| 112 | 112 | public static function render_setting_row( $key = '', $current_settings = array(), $override_input = null, $name = 'template_settings[%s]', $id = 'gravityview_se_%s' ) { |
| 113 | 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 ); |
|
| 114 | + GravityView_Render_Settings::render_setting_row( $key, $current_settings, $override_input, $name, $id ); |
|
| 115 | 115 | } |
| 116 | 116 | |
| 117 | 117 | /** |
@@ -134,37 +134,37 @@ discard block |
||
| 134 | 134 | |
| 135 | 135 | $connected_views = gravityview_get_connected_views( $id ); |
| 136 | 136 | |
| 137 | - if( empty( $connected_views ) ) { |
|
| 137 | + if ( empty( $connected_views ) ) { |
|
| 138 | 138 | return $menu_items; |
| 139 | 139 | } |
| 140 | 140 | |
| 141 | 141 | $sub_menu_items = array(); |
| 142 | 142 | foreach ( (array)$connected_views as $view ) { |
| 143 | 143 | |
| 144 | - if( ! GVCommon::has_cap( 'edit_gravityview', $view->ID ) ) { |
|
| 144 | + if ( ! GVCommon::has_cap( 'edit_gravityview', $view->ID ) ) { |
|
| 145 | 145 | continue; |
| 146 | 146 | } |
| 147 | 147 | |
| 148 | - $label = empty( $view->post_title ) ? sprintf( __('No Title (View #%d)', 'gravityview' ), $view->ID ) : $view->post_title; |
|
| 148 | + $label = empty( $view->post_title ) ? sprintf( __( 'No Title (View #%d)', 'gravityview' ), $view->ID ) : $view->post_title; |
|
| 149 | 149 | |
| 150 | - $sub_menu_items[] = array( |
|
| 150 | + $sub_menu_items[ ] = array( |
|
| 151 | 151 | 'label' => esc_attr( $label ), |
| 152 | - 'url' => admin_url( 'post.php?action=edit&post='.$view->ID ), |
|
| 152 | + 'url' => admin_url( 'post.php?action=edit&post=' . $view->ID ), |
|
| 153 | 153 | ); |
| 154 | 154 | } |
| 155 | 155 | |
| 156 | 156 | // If there were no items added, then let's create the parent menu |
| 157 | - if( $sub_menu_items ) { |
|
| 157 | + if ( $sub_menu_items ) { |
|
| 158 | 158 | |
| 159 | 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( |
|
| 160 | + $sub_menu_items[ ] = array( |
|
| 161 | 161 | 'url' => '#', |
| 162 | 162 | 'label' => '', |
| 163 | 163 | 'menu_class' => 'hidden', |
| 164 | 164 | 'capabilities' => '', |
| 165 | 165 | ); |
| 166 | 166 | |
| 167 | - $menu_items['gravityview'] = array( |
|
| 167 | + $menu_items[ 'gravityview' ] = array( |
|
| 168 | 168 | 'label' => __( 'Connected Views', 'gravityview' ), |
| 169 | 169 | 'icon' => '<i class="fa fa-lg gv-icon-astronaut-head gv-icon"></i>', |
| 170 | 170 | 'title' => __( 'GravityView Views using this form as a data source', 'gravityview' ), |
@@ -194,8 +194,8 @@ discard block |
||
| 194 | 194 | $add = array( 'captcha', 'page' ); |
| 195 | 195 | |
| 196 | 196 | // Don't allowing editing the following values: |
| 197 | - if( $context === 'edit' ) { |
|
| 198 | - $add[] = 'post_id'; |
|
| 197 | + if ( $context === 'edit' ) { |
|
| 198 | + $add[ ] = 'post_id'; |
|
| 199 | 199 | } |
| 200 | 200 | |
| 201 | 201 | $return = array_merge( $array, $add ); |
@@ -218,32 +218,32 @@ discard block |
||
| 218 | 218 | foreach ( $default_args as $key => $arg ) { |
| 219 | 219 | |
| 220 | 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; } |
|
| 221 | + if ( isset( $arg[ 'tooltip' ] ) && empty( $arg[ 'tooltip' ] ) ) { continue; } |
|
| 222 | 222 | |
| 223 | 223 | // By default, use `tooltip` if defined. |
| 224 | - $tooltip = empty( $arg['tooltip'] ) ? NULL : $arg['tooltip']; |
|
| 224 | + $tooltip = empty( $arg[ 'tooltip' ] ) ? NULL : $arg[ 'tooltip' ]; |
|
| 225 | 225 | |
| 226 | 226 | // Otherwise, use the description as a tooltip. |
| 227 | - if( empty( $tooltip ) && !empty( $arg['desc'] ) ) { |
|
| 228 | - $tooltip = $arg['desc']; |
|
| 227 | + if ( empty( $tooltip ) && ! empty( $arg[ 'desc' ] ) ) { |
|
| 228 | + $tooltip = $arg[ 'desc' ]; |
|
| 229 | 229 | } |
| 230 | 230 | |
| 231 | 231 | // If there's no tooltip set, continue |
| 232 | - if( empty( $tooltip ) ) { |
|
| 232 | + if ( empty( $tooltip ) ) { |
|
| 233 | 233 | continue; |
| 234 | 234 | } |
| 235 | 235 | |
| 236 | 236 | // Add the tooltip |
| 237 | - $gv_tooltips[ 'gv_'.$key ] = array( |
|
| 238 | - 'title' => $arg['label'], |
|
| 237 | + $gv_tooltips[ 'gv_' . $key ] = array( |
|
| 238 | + 'title' => $arg[ 'label' ], |
|
| 239 | 239 | 'value' => $tooltip, |
| 240 | 240 | ); |
| 241 | 241 | |
| 242 | 242 | } |
| 243 | 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>' ) |
|
| 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 | 247 | ); |
| 248 | 248 | |
| 249 | 249 | /** |
@@ -254,9 +254,9 @@ discard block |
||
| 254 | 254 | |
| 255 | 255 | foreach ( $gv_tooltips as $key => $tooltip ) { |
| 256 | 256 | |
| 257 | - $title = empty( $tooltip['title'] ) ? '' : '<h6>'.esc_html( $tooltip['title'] ) .'</h6>'; |
|
| 257 | + $title = empty( $tooltip[ 'title' ] ) ? '' : '<h6>' . esc_html( $tooltip[ 'title' ] ) . '</h6>'; |
|
| 258 | 258 | |
| 259 | - $tooltips[ $key ] = $title . wpautop( esc_html( $tooltip['value'] ) ); |
|
| 259 | + $tooltips[ $key ] = $title . wpautop( esc_html( $tooltip[ 'value' ] ) ); |
|
| 260 | 260 | } |
| 261 | 261 | |
| 262 | 262 | return $tooltips; |
@@ -270,7 +270,7 @@ discard block |
||
| 270 | 270 | * |
| 271 | 271 | * @return void |
| 272 | 272 | */ |
| 273 | - public function add_custom_column_content( $column_name = NULL, $post_id ) { |
|
| 273 | + public function add_custom_column_content( $column_name = NULL, $post_id ) { |
|
| 274 | 274 | |
| 275 | 275 | $output = ''; |
| 276 | 276 | |
@@ -292,7 +292,7 @@ discard block |
||
| 292 | 292 | // Generate backup if label doesn't exist: `example_name` => `Example Name` |
| 293 | 293 | $template_id_pretty = ucwords( implode( ' ', explode( '_', $template_id ) ) ); |
| 294 | 294 | |
| 295 | - $output = $template ? $template['label'] : $template_id_pretty; |
|
| 295 | + $output = $template ? $template[ 'label' ] : $template_id_pretty; |
|
| 296 | 296 | |
| 297 | 297 | break; |
| 298 | 298 | |
@@ -333,44 +333,44 @@ discard block |
||
| 333 | 333 | static public function get_connected_form_links( $form, $include_form_link = true ) { |
| 334 | 334 | |
| 335 | 335 | // Either the form is empty or the form ID is 0, not yet set. |
| 336 | - if( empty( $form ) ) { |
|
| 336 | + if ( empty( $form ) ) { |
|
| 337 | 337 | return ''; |
| 338 | 338 | } |
| 339 | 339 | |
| 340 | 340 | // The $form is passed as the form ID |
| 341 | - if( !is_array( $form ) ) { |
|
| 341 | + if ( ! is_array( $form ) ) { |
|
| 342 | 342 | $form = gravityview_get_form( $form ); |
| 343 | 343 | } |
| 344 | 344 | |
| 345 | - $form_id = $form['id']; |
|
| 345 | + $form_id = $form[ 'id' ]; |
|
| 346 | 346 | $links = array(); |
| 347 | 347 | |
| 348 | - if( GVCommon::has_cap( 'gravityforms_edit_forms' ) ) { |
|
| 348 | + if ( GVCommon::has_cap( 'gravityforms_edit_forms' ) ) { |
|
| 349 | 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>'; |
|
| 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 | 352 | } else { |
| 353 | - $form_link = '<strong class="gv-form-title">'. esc_html( $form['title'] ). '</strong>'; |
|
| 353 | + $form_link = '<strong class="gv-form-title">' . esc_html( $form[ 'title' ] ) . '</strong>'; |
|
| 354 | 354 | } |
| 355 | 355 | |
| 356 | - if( GVCommon::has_cap( 'gravityforms_view_entries' ) ) { |
|
| 356 | + if ( GVCommon::has_cap( 'gravityforms_view_entries' ) ) { |
|
| 357 | 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>'; |
|
| 358 | + $links[ ] = '<span>' . gravityview_get_link( $entries_url, __( 'Entries', 'gravityview' ) ) . '</span>'; |
|
| 359 | 359 | } |
| 360 | 360 | |
| 361 | - if( GVCommon::has_cap( array( 'gravityforms_edit_settings', 'gravityview_view_settings' ) ) ) { |
|
| 361 | + if ( GVCommon::has_cap( array( 'gravityforms_edit_settings', 'gravityview_view_settings' ) ) ) { |
|
| 362 | 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>'; |
|
| 363 | + $links[ ] = '<span>' . gravityview_get_link( $settings_url, __( 'Settings', 'gravityview' ), 'title=' . __( 'Edit settings for this form', 'gravityview' ) ) . '</span>'; |
|
| 364 | 364 | } |
| 365 | 365 | |
| 366 | - if( GVCommon::has_cap( array("gravityforms_edit_forms", "gravityforms_create_form", "gravityforms_preview_forms") ) ) { |
|
| 366 | + if ( GVCommon::has_cap( array( "gravityforms_edit_forms", "gravityforms_create_form", "gravityforms_preview_forms" ) ) ) { |
|
| 367 | 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>'; |
|
| 368 | + $links[ ] = '<span>' . gravityview_get_link( $preview_url, __( 'Preview Form', 'gravityview' ), 'title=' . __( 'Preview this form', 'gravityview' ) ) . '</span>'; |
|
| 369 | 369 | } |
| 370 | 370 | |
| 371 | 371 | $output = ''; |
| 372 | 372 | |
| 373 | - if( !empty( $include_form_link ) ) { |
|
| 373 | + if ( ! empty( $include_form_link ) ) { |
|
| 374 | 374 | $output .= $form_link; |
| 375 | 375 | } |
| 376 | 376 | |
@@ -382,7 +382,7 @@ discard block |
||
| 382 | 382 | */ |
| 383 | 383 | $links = apply_filters( 'gravityview_connected_form_links', $links, $form ); |
| 384 | 384 | |
| 385 | - $output .= '<div class="row-actions">'. implode( ' | ', $links ) .'</div>'; |
|
| 385 | + $output .= '<div class="row-actions">' . implode( ' | ', $links ) . '</div>'; |
|
| 386 | 386 | |
| 387 | 387 | return $output; |
| 388 | 388 | } |
@@ -396,8 +396,8 @@ discard block |
||
| 396 | 396 | // Get the date column and save it for later to add back in. |
| 397 | 397 | // This adds it after the Data Source column. |
| 398 | 398 | // This way, we don't need to do array_slice, array_merge, etc. |
| 399 | - $date = $columns['date']; |
|
| 400 | - unset( $columns['date'] ); |
|
| 399 | + $date = $columns[ 'date' ]; |
|
| 400 | + unset( $columns[ 'date' ] ); |
|
| 401 | 401 | |
| 402 | 402 | $data_source_required_caps = array( |
| 403 | 403 | 'gravityforms_edit_forms', |
@@ -408,14 +408,14 @@ discard block |
||
| 408 | 408 | 'gravityforms_preview_forms', |
| 409 | 409 | ); |
| 410 | 410 | |
| 411 | - if( GVCommon::has_cap( $data_source_required_caps ) ) { |
|
| 412 | - $columns['gv_connected_form'] = __( 'Data Source', 'gravityview' ); |
|
| 411 | + if ( GVCommon::has_cap( $data_source_required_caps ) ) { |
|
| 412 | + $columns[ 'gv_connected_form' ] = __( 'Data Source', 'gravityview' ); |
|
| 413 | 413 | } |
| 414 | 414 | |
| 415 | - $columns['gv_template'] = _x( 'Template', 'Column title that shows what template is being used for Views', 'gravityview' ); |
|
| 415 | + $columns[ 'gv_template' ] = _x( 'Template', 'Column title that shows what template is being used for Views', 'gravityview' ); |
|
| 416 | 416 | |
| 417 | 417 | // Add the date back in. |
| 418 | - $columns['date'] = $date; |
|
| 418 | + $columns[ 'date' ] = $date; |
|
| 419 | 419 | |
| 420 | 420 | return $columns; |
| 421 | 421 | } |
@@ -429,12 +429,12 @@ discard block |
||
| 429 | 429 | */ |
| 430 | 430 | function save_postdata( $post_id ) { |
| 431 | 431 | |
| 432 | - if( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ){ |
|
| 432 | + if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) { |
|
| 433 | 433 | return; |
| 434 | 434 | } |
| 435 | 435 | |
| 436 | 436 | // validate post_type |
| 437 | - if ( ! isset( $_POST['post_type'] ) || 'gravityview' != $_POST['post_type'] ) { |
|
| 437 | + if ( ! isset( $_POST[ 'post_type' ] ) || 'gravityview' != $_POST[ 'post_type' ] ) { |
|
| 438 | 438 | return; |
| 439 | 439 | } |
| 440 | 440 | |
@@ -449,67 +449,67 @@ discard block |
||
| 449 | 449 | $statii = array(); |
| 450 | 450 | |
| 451 | 451 | // check if this is a start fresh View |
| 452 | - if ( isset( $_POST['gravityview_select_form_nonce'] ) && wp_verify_nonce( $_POST['gravityview_select_form_nonce'], 'gravityview_select_form' ) ) { |
|
| 452 | + if ( isset( $_POST[ 'gravityview_select_form_nonce' ] ) && wp_verify_nonce( $_POST[ 'gravityview_select_form_nonce' ], 'gravityview_select_form' ) ) { |
|
| 453 | 453 | |
| 454 | - $form_id = !empty( $_POST['gravityview_form_id'] ) ? $_POST['gravityview_form_id'] : ''; |
|
| 454 | + $form_id = ! empty( $_POST[ 'gravityview_form_id' ] ) ? $_POST[ 'gravityview_form_id' ] : ''; |
|
| 455 | 455 | // save form id |
| 456 | - $statii['form_id'] = update_post_meta( $post_id, '_gravityview_form_id', $form_id ); |
|
| 456 | + $statii[ 'form_id' ] = update_post_meta( $post_id, '_gravityview_form_id', $form_id ); |
|
| 457 | 457 | |
| 458 | 458 | } |
| 459 | 459 | |
| 460 | - if( false === GVCommon::has_cap( 'gravityforms_create_form' ) && empty( $statii['form_id'] ) ) { |
|
| 460 | + if ( false === GVCommon::has_cap( 'gravityforms_create_form' ) && empty( $statii[ 'form_id' ] ) ) { |
|
| 461 | 461 | do_action( 'gravityview_log_error', __METHOD__ . ' - Current user does not have the capability to create a new Form.', wp_get_current_user() ); |
| 462 | 462 | return; |
| 463 | 463 | } |
| 464 | 464 | |
| 465 | 465 | // Was this a start fresh? |
| 466 | - if ( ! empty( $_POST['gravityview_form_id_start_fresh'] ) ) { |
|
| 467 | - $statii['start_fresh'] = add_post_meta( $post_id, '_gravityview_start_fresh', 1 ); |
|
| 466 | + if ( ! empty( $_POST[ 'gravityview_form_id_start_fresh' ] ) ) { |
|
| 467 | + $statii[ 'start_fresh' ] = add_post_meta( $post_id, '_gravityview_start_fresh', 1 ); |
|
| 468 | 468 | } else { |
| 469 | - $statii['start_fresh'] = delete_post_meta( $post_id, '_gravityview_start_fresh' ); |
|
| 469 | + $statii[ 'start_fresh' ] = delete_post_meta( $post_id, '_gravityview_start_fresh' ); |
|
| 470 | 470 | } |
| 471 | 471 | |
| 472 | 472 | // Check if we have a template id |
| 473 | - if ( isset( $_POST['gravityview_select_template_nonce'] ) && wp_verify_nonce( $_POST['gravityview_select_template_nonce'], 'gravityview_select_template' ) ) { |
|
| 473 | + if ( isset( $_POST[ 'gravityview_select_template_nonce' ] ) && wp_verify_nonce( $_POST[ 'gravityview_select_template_nonce' ], 'gravityview_select_template' ) ) { |
|
| 474 | 474 | |
| 475 | - $template_id = !empty( $_POST['gravityview_directory_template'] ) ? $_POST['gravityview_directory_template'] : ''; |
|
| 475 | + $template_id = ! empty( $_POST[ 'gravityview_directory_template' ] ) ? $_POST[ 'gravityview_directory_template' ] : ''; |
|
| 476 | 476 | |
| 477 | 477 | // now save template id |
| 478 | - $statii['directory_template'] = update_post_meta( $post_id, '_gravityview_directory_template', $template_id ); |
|
| 478 | + $statii[ 'directory_template' ] = update_post_meta( $post_id, '_gravityview_directory_template', $template_id ); |
|
| 479 | 479 | } |
| 480 | 480 | |
| 481 | 481 | |
| 482 | 482 | // save View Configuration metabox |
| 483 | - if ( isset( $_POST['gravityview_view_configuration_nonce'] ) && wp_verify_nonce( $_POST['gravityview_view_configuration_nonce'], 'gravityview_view_configuration' ) ) { |
|
| 483 | + if ( isset( $_POST[ 'gravityview_view_configuration_nonce' ] ) && wp_verify_nonce( $_POST[ 'gravityview_view_configuration_nonce' ], 'gravityview_view_configuration' ) ) { |
|
| 484 | 484 | |
| 485 | 485 | // template settings |
| 486 | - if( empty( $_POST['template_settings'] ) ) { |
|
| 487 | - $_POST['template_settings'] = array(); |
|
| 486 | + if ( empty( $_POST[ 'template_settings' ] ) ) { |
|
| 487 | + $_POST[ 'template_settings' ] = array(); |
|
| 488 | 488 | } |
| 489 | - $statii['template_settings'] = update_post_meta( $post_id, '_gravityview_template_settings', $_POST['template_settings'] ); |
|
| 489 | + $statii[ 'template_settings' ] = update_post_meta( $post_id, '_gravityview_template_settings', $_POST[ 'template_settings' ] ); |
|
| 490 | 490 | |
| 491 | 491 | $fields = array(); |
| 492 | 492 | |
| 493 | 493 | // Directory&single Visible Fields |
| 494 | - if( !empty( $preset_fields ) ) { |
|
| 494 | + if ( ! empty( $preset_fields ) ) { |
|
| 495 | 495 | |
| 496 | 496 | $fields = $preset_fields; |
| 497 | 497 | |
| 498 | - } elseif( !empty( $_POST['fields'] ) ) { |
|
| 498 | + } elseif ( ! empty( $_POST[ 'fields' ] ) ) { |
|
| 499 | 499 | $fields = _gravityview_process_posted_fields(); |
| 500 | 500 | } |
| 501 | 501 | |
| 502 | - $statii['directory_fields'] = update_post_meta( $post_id, '_gravityview_directory_fields', $fields ); |
|
| 502 | + $statii[ 'directory_fields' ] = update_post_meta( $post_id, '_gravityview_directory_fields', $fields ); |
|
| 503 | 503 | |
| 504 | 504 | // Directory Visible Widgets |
| 505 | - if( empty( $_POST['widgets'] ) ) { |
|
| 506 | - $_POST['widgets'] = array(); |
|
| 505 | + if ( empty( $_POST[ 'widgets' ] ) ) { |
|
| 506 | + $_POST[ 'widgets' ] = array(); |
|
| 507 | 507 | } |
| 508 | - $statii['directory_widgets'] = update_post_meta( $post_id, '_gravityview_directory_widgets', $_POST['widgets'] ); |
|
| 508 | + $statii[ 'directory_widgets' ] = update_post_meta( $post_id, '_gravityview_directory_widgets', $_POST[ 'widgets' ] ); |
|
| 509 | 509 | |
| 510 | 510 | } // end save view configuration |
| 511 | 511 | |
| 512 | - do_action('gravityview_log_debug', '[save_postdata] Update Post Meta Statuses (also returns false if nothing changed)', array_map( 'intval', $statii ) ); |
|
| 512 | + do_action( 'gravityview_log_debug', '[save_postdata] Update Post Meta Statuses (also returns false if nothing changed)', array_map( 'intval', $statii ) ); |
|
| 513 | 513 | } |
| 514 | 514 | |
| 515 | 515 | /** |
@@ -541,20 +541,20 @@ discard block |
||
| 541 | 541 | |
| 542 | 542 | $output = ''; |
| 543 | 543 | |
| 544 | - if( !empty( $fields ) ) { |
|
| 544 | + if ( ! empty( $fields ) ) { |
|
| 545 | 545 | |
| 546 | - foreach( $fields as $id => $details ) { |
|
| 546 | + foreach ( $fields as $id => $details ) { |
|
| 547 | 547 | |
| 548 | - if( in_array( $details['type'], $blacklist_field_types ) ) { |
|
| 548 | + if ( in_array( $details[ 'type' ], $blacklist_field_types ) ) { |
|
| 549 | 549 | continue; |
| 550 | 550 | } |
| 551 | 551 | |
| 552 | 552 | // Edit mode only allows editing the parent fields, not single inputs. |
| 553 | - if( $context === 'edit' && !empty( $details['parent'] ) ) { |
|
| 553 | + if ( $context === 'edit' && ! empty( $details[ 'parent' ] ) ) { |
|
| 554 | 554 | continue; |
| 555 | 555 | } |
| 556 | 556 | |
| 557 | - $output .= new GravityView_Admin_View_Field( $details['label'], $id, $details ); |
|
| 557 | + $output .= new GravityView_Admin_View_Field( $details[ 'label' ], $id, $details ); |
|
| 558 | 558 | |
| 559 | 559 | } // End foreach |
| 560 | 560 | } |
@@ -562,7 +562,7 @@ discard block |
||
| 562 | 562 | echo $output; |
| 563 | 563 | |
| 564 | 564 | // For the EDIT view we only want to allow the form fields. |
| 565 | - if( $context === 'edit' ) { |
|
| 565 | + if ( $context === 'edit' ) { |
|
| 566 | 566 | return; |
| 567 | 567 | } |
| 568 | 568 | |
@@ -586,16 +586,16 @@ discard block |
||
| 586 | 586 | $additional_fields = apply_filters( 'gravityview_additional_fields', array( |
| 587 | 587 | array( |
| 588 | 588 | 'label_text' => __( '+ Add All Fields', 'gravityview' ), |
| 589 | - 'desc' => __('Add all the available fields at once.', 'gravityview'), |
|
| 589 | + 'desc' => __( 'Add all the available fields at once.', 'gravityview' ), |
|
| 590 | 590 | 'field_id' => 'all-fields', |
| 591 | 591 | 'label_type' => 'field', |
| 592 | 592 | 'input_type' => NULL, |
| 593 | 593 | 'field_options' => NULL, |
| 594 | 594 | 'settings_html' => NULL, |
| 595 | 595 | ) |
| 596 | - )); |
|
| 596 | + ) ); |
|
| 597 | 597 | |
| 598 | - if( !empty( $additional_fields )) { |
|
| 598 | + if ( ! empty( $additional_fields ) ) { |
|
| 599 | 599 | foreach ( (array)$additional_fields as $item ) { |
| 600 | 600 | |
| 601 | 601 | // Prevent items from not having index set |
@@ -606,16 +606,16 @@ discard block |
||
| 606 | 606 | 'input_type' => NULL, |
| 607 | 607 | 'field_options' => NULL, |
| 608 | 608 | 'settings_html' => NULL, |
| 609 | - )); |
|
| 609 | + ) ); |
|
| 610 | 610 | |
| 611 | 611 | // Backward compat. |
| 612 | - if( !empty( $item['field_options'] ) ) { |
|
| 612 | + if ( ! empty( $item[ 'field_options' ] ) ) { |
|
| 613 | 613 | // Use settings_html from now on. |
| 614 | - $item['settings_html'] = $item['field_options']; |
|
| 614 | + $item[ 'settings_html' ] = $item[ 'field_options' ]; |
|
| 615 | 615 | } |
| 616 | 616 | |
| 617 | 617 | // Render a label for each of them |
| 618 | - echo new GravityView_Admin_View_Field( $item['label_text'], $item['field_id'], $item ); |
|
| 618 | + echo new GravityView_Admin_View_Field( $item[ 'label_text' ], $item[ 'field_id' ], $item ); |
|
| 619 | 619 | |
| 620 | 620 | } |
| 621 | 621 | } |
@@ -628,64 +628,64 @@ discard block |
||
| 628 | 628 | * @param string $zone Either 'single', 'directory', 'header', 'footer' |
| 629 | 629 | * @return array |
| 630 | 630 | */ |
| 631 | - function get_entry_default_fields($form, $zone) { |
|
| 631 | + function get_entry_default_fields( $form, $zone ) { |
|
| 632 | 632 | |
| 633 | 633 | $entry_default_fields = array(); |
| 634 | 634 | |
| 635 | - if( in_array( $zone, array( 'directory', 'single' ) ) ) { |
|
| 635 | + if ( in_array( $zone, array( 'directory', 'single' ) ) ) { |
|
| 636 | 636 | |
| 637 | 637 | $entry_default_fields = array( |
| 638 | 638 | 'id' => array( |
| 639 | - 'label' => __('Entry ID', 'gravityview'), |
|
| 639 | + 'label' => __( 'Entry ID', 'gravityview' ), |
|
| 640 | 640 | 'type' => 'id', |
| 641 | - 'desc' => __('The unique ID of the entry.', 'gravityview'), |
|
| 641 | + 'desc' => __( 'The unique ID of the entry.', 'gravityview' ), |
|
| 642 | 642 | ), |
| 643 | 643 | 'date_created' => array( |
| 644 | - 'label' => __('Entry Date', 'gravityview'), |
|
| 645 | - 'desc' => __('The date the entry was created.', 'gravityview'), |
|
| 644 | + 'label' => __( 'Entry Date', 'gravityview' ), |
|
| 645 | + 'desc' => __( 'The date the entry was created.', 'gravityview' ), |
|
| 646 | 646 | 'type' => 'date_created', |
| 647 | 647 | ), |
| 648 | 648 | 'source_url' => array( |
| 649 | - 'label' => __('Source URL', 'gravityview'), |
|
| 649 | + 'label' => __( 'Source URL', 'gravityview' ), |
|
| 650 | 650 | 'type' => 'source_url', |
| 651 | - 'desc' => __('The URL of the page where the form was submitted.', 'gravityview'), |
|
| 651 | + 'desc' => __( 'The URL of the page where the form was submitted.', 'gravityview' ), |
|
| 652 | 652 | ), |
| 653 | 653 | 'ip' => array( |
| 654 | - 'label' => __('User IP', 'gravityview'), |
|
| 654 | + 'label' => __( 'User IP', 'gravityview' ), |
|
| 655 | 655 | 'type' => 'ip', |
| 656 | - 'desc' => __('The IP Address of the user who created the entry.', 'gravityview'), |
|
| 656 | + 'desc' => __( 'The IP Address of the user who created the entry.', 'gravityview' ), |
|
| 657 | 657 | ), |
| 658 | 658 | 'created_by' => array( |
| 659 | - 'label' => __('User', 'gravityview'), |
|
| 659 | + 'label' => __( 'User', 'gravityview' ), |
|
| 660 | 660 | 'type' => 'created_by', |
| 661 | - 'desc' => __('Details of the logged-in user who created the entry (if any).', 'gravityview'), |
|
| 661 | + 'desc' => __( 'Details of the logged-in user who created the entry (if any).', 'gravityview' ), |
|
| 662 | 662 | ), |
| 663 | 663 | |
| 664 | 664 | /** |
| 665 | 665 | * @since 1.2 |
| 666 | 666 | */ |
| 667 | 667 | 'custom' => array( |
| 668 | - 'label' => __('Custom Content', 'gravityview'), |
|
| 668 | + 'label' => __( 'Custom Content', 'gravityview' ), |
|
| 669 | 669 | 'type' => 'custom', |
| 670 | - 'desc' => __('Insert custom text or HTML.', 'gravityview'), |
|
| 670 | + 'desc' => __( 'Insert custom text or HTML.', 'gravityview' ), |
|
| 671 | 671 | ), |
| 672 | 672 | |
| 673 | 673 | /** |
| 674 | 674 | * @since 1.7.2 |
| 675 | 675 | */ |
| 676 | 676 | 'other_entries' => array( |
| 677 | - 'label' => __('Other Entries', 'gravityview'), |
|
| 677 | + 'label' => __( 'Other Entries', 'gravityview' ), |
|
| 678 | 678 | 'type' => 'other_entries', |
| 679 | - 'desc' => __('Display other entries created by the entry creator.', 'gravityview'), |
|
| 679 | + 'desc' => __( 'Display other entries created by the entry creator.', 'gravityview' ), |
|
| 680 | 680 | ), |
| 681 | 681 | ); |
| 682 | 682 | |
| 683 | 683 | |
| 684 | - if( 'single' !== $zone) { |
|
| 684 | + if ( 'single' !== $zone ) { |
|
| 685 | 685 | |
| 686 | - $entry_default_fields['entry_link'] = array( |
|
| 687 | - 'label' => __('Link to Entry', 'gravityview'), |
|
| 688 | - 'desc' => __('A dedicated link to the single entry with customizable text.', 'gravityview'), |
|
| 686 | + $entry_default_fields[ 'entry_link' ] = array( |
|
| 687 | + 'label' => __( 'Link to Entry', 'gravityview' ), |
|
| 688 | + 'desc' => __( 'A dedicated link to the single entry with customizable text.', 'gravityview' ), |
|
| 689 | 689 | 'type' => 'entry_link', |
| 690 | 690 | ); |
| 691 | 691 | } |
@@ -699,7 +699,7 @@ discard block |
||
| 699 | 699 | * @param string|array $form form_ID or form object |
| 700 | 700 | * @param string $zone Either 'single', 'directory', 'header', 'footer' |
| 701 | 701 | */ |
| 702 | - return apply_filters( 'gravityview_entry_default_fields', $entry_default_fields, $form, $zone); |
|
| 702 | + return apply_filters( 'gravityview_entry_default_fields', $entry_default_fields, $form, $zone ); |
|
| 703 | 703 | } |
| 704 | 704 | |
| 705 | 705 | /** |
@@ -710,7 +710,7 @@ discard block |
||
| 710 | 710 | */ |
| 711 | 711 | function get_available_fields( $form = '', $zone = NULL ) { |
| 712 | 712 | |
| 713 | - if( empty( $form ) ) { |
|
| 713 | + if ( empty( $form ) ) { |
|
| 714 | 714 | do_action( 'gravityview_log_error', '[get_available_fields] $form is empty' ); |
| 715 | 715 | return array(); |
| 716 | 716 | } |
@@ -719,7 +719,7 @@ discard block |
||
| 719 | 719 | $fields = gravityview_get_form_fields( $form, true ); |
| 720 | 720 | |
| 721 | 721 | // get meta fields ( only if form was already created ) |
| 722 | - if( !is_array( $form ) ) { |
|
| 722 | + if ( ! is_array( $form ) ) { |
|
| 723 | 723 | $meta_fields = gravityview_get_entry_meta( $form ); |
| 724 | 724 | } else { |
| 725 | 725 | $meta_fields = array(); |
@@ -743,11 +743,11 @@ discard block |
||
| 743 | 743 | |
| 744 | 744 | $widgets = $this->get_registered_widgets(); |
| 745 | 745 | |
| 746 | - if( !empty( $widgets ) ) { |
|
| 746 | + if ( ! empty( $widgets ) ) { |
|
| 747 | 747 | |
| 748 | - foreach( $widgets as $id => $details ) { |
|
| 748 | + foreach ( $widgets as $id => $details ) { |
|
| 749 | 749 | |
| 750 | - echo new GravityView_Admin_View_Widget( $details['label'], $id, $details ); |
|
| 750 | + echo new GravityView_Admin_View_Widget( $details[ 'label' ], $id, $details ); |
|
| 751 | 751 | |
| 752 | 752 | } |
| 753 | 753 | } |
@@ -781,7 +781,7 @@ discard block |
||
| 781 | 781 | function render_active_areas( $template_id, $type, $zone, $rows, $values ) { |
| 782 | 782 | global $post; |
| 783 | 783 | |
| 784 | - if( $type === 'widget' ) { |
|
| 784 | + if ( $type === 'widget' ) { |
|
| 785 | 785 | $button_label = __( 'Add Widget', 'gravityview' ); |
| 786 | 786 | } else { |
| 787 | 787 | $button_label = __( 'Add Field', 'gravityview' ); |
@@ -790,15 +790,15 @@ discard block |
||
| 790 | 790 | $available_items = array(); |
| 791 | 791 | |
| 792 | 792 | // if saved values, get available fields to label everyone |
| 793 | - if( !empty( $values ) && ( !empty( $post->ID ) || !empty( $_POST['template_id'] ) ) ) { |
|
| 793 | + if ( ! empty( $values ) && ( ! empty( $post->ID ) || ! empty( $_POST[ 'template_id' ] ) ) ) { |
|
| 794 | 794 | |
| 795 | - if( !empty( $_POST['template_id'] ) ) { |
|
| 796 | - $form = GravityView_Ajax::pre_get_form_fields( $_POST['template_id'] ); |
|
| 795 | + if ( ! empty( $_POST[ 'template_id' ] ) ) { |
|
| 796 | + $form = GravityView_Ajax::pre_get_form_fields( $_POST[ 'template_id' ] ); |
|
| 797 | 797 | } else { |
| 798 | 798 | $form = gravityview_get_form_id( $post->ID ); |
| 799 | 799 | } |
| 800 | 800 | |
| 801 | - if( 'field' === $type ) { |
|
| 801 | + if ( 'field' === $type ) { |
|
| 802 | 802 | $available_items = $this->get_available_fields( $form, $zone ); |
| 803 | 803 | } else { |
| 804 | 804 | $available_items = $this->get_registered_widgets(); |
@@ -806,39 +806,39 @@ discard block |
||
| 806 | 806 | |
| 807 | 807 | } |
| 808 | 808 | |
| 809 | - foreach( $rows as $row ) : |
|
| 810 | - foreach( $row as $col => $areas ) : |
|
| 811 | - $column = ($col == '2-2') ? '1-2' : $col; ?> |
|
| 809 | + foreach ( $rows as $row ) : |
|
| 810 | + foreach ( $row as $col => $areas ) : |
|
| 811 | + $column = ( $col == '2-2' ) ? '1-2' : $col; ?> |
|
| 812 | 812 | |
| 813 | 813 | <div class="gv-grid-col-<?php echo esc_attr( $column ); ?>"> |
| 814 | 814 | |
| 815 | - <?php foreach( $areas as $area ) : ?> |
|
| 815 | + <?php foreach ( $areas as $area ) : ?> |
|
| 816 | 816 | |
| 817 | 817 | <div class="gv-droppable-area"> |
| 818 | - <div class="active-drop active-drop-<?php echo esc_attr( $type ); ?>" data-areaid="<?php echo esc_attr( $zone .'_'. $area['areaid'] ); ?>"> |
|
| 818 | + <div class="active-drop active-drop-<?php echo esc_attr( $type ); ?>" data-areaid="<?php echo esc_attr( $zone . '_' . $area[ 'areaid' ] ); ?>"> |
|
| 819 | 819 | |
| 820 | 820 | <?php // render saved fields |
| 821 | 821 | |
| 822 | - if( !empty( $values[ $zone .'_'. $area['areaid'] ] ) ) { |
|
| 822 | + if ( ! empty( $values[ $zone . '_' . $area[ 'areaid' ] ] ) ) { |
|
| 823 | 823 | |
| 824 | - foreach( $values[ $zone .'_'. $area['areaid'] ] as $uniqid => $field ) { |
|
| 824 | + foreach ( $values[ $zone . '_' . $area[ 'areaid' ] ] as $uniqid => $field ) { |
|
| 825 | 825 | |
| 826 | 826 | $input_type = NULL; |
| 827 | - $original_item = isset( $available_items[ $field['id'] ] ) ? $available_items[ $field['id'] ] : false ; |
|
| 827 | + $original_item = isset( $available_items[ $field[ 'id' ] ] ) ? $available_items[ $field[ 'id' ] ] : false; |
|
| 828 | 828 | |
| 829 | - if( !$original_item ) { |
|
| 829 | + if ( ! $original_item ) { |
|
| 830 | 830 | |
| 831 | - do_action('gravityview_log_error', 'An item was not available when rendering the output; maybe it was added by a plugin that is now de-activated.', array('available_items' => $available_items, 'field' => $field )); |
|
| 831 | + do_action( 'gravityview_log_error', 'An item was not available when rendering the output; maybe it was added by a plugin that is now de-activated.', array( 'available_items' => $available_items, 'field' => $field ) ); |
|
| 832 | 832 | |
| 833 | 833 | $original_item = $field; |
| 834 | 834 | } else { |
| 835 | 835 | |
| 836 | - $input_type = isset( $original_item['type'] ) ? $original_item['type'] : NULL; |
|
| 836 | + $input_type = isset( $original_item[ 'type' ] ) ? $original_item[ 'type' ] : NULL; |
|
| 837 | 837 | |
| 838 | 838 | } |
| 839 | 839 | |
| 840 | 840 | // Field options dialog box |
| 841 | - $field_options = GravityView_Render_Settings::render_field_options( $type, $template_id, $field['id'], $original_item['label'], $zone .'_'. $area['areaid'], $input_type, $uniqid, $field, $zone, $original_item ); |
|
| 841 | + $field_options = GravityView_Render_Settings::render_field_options( $type, $template_id, $field[ 'id' ], $original_item[ 'label' ], $zone . '_' . $area[ 'areaid' ], $input_type, $uniqid, $field, $zone, $original_item ); |
|
| 842 | 842 | |
| 843 | 843 | $item = array( |
| 844 | 844 | 'input_type' => $input_type, |
@@ -847,16 +847,16 @@ discard block |
||
| 847 | 847 | ); |
| 848 | 848 | |
| 849 | 849 | // Merge the values with the current item to pass things like widget descriptions and original field names |
| 850 | - if( $original_item ) { |
|
| 850 | + if ( $original_item ) { |
|
| 851 | 851 | $item = wp_parse_args( $item, $original_item ); |
| 852 | 852 | } |
| 853 | 853 | |
| 854 | - switch( $type ) { |
|
| 854 | + switch ( $type ) { |
|
| 855 | 855 | case 'widget': |
| 856 | - echo new GravityView_Admin_View_Widget( $item['label'], $field['id'], $item, $field ); |
|
| 856 | + echo new GravityView_Admin_View_Widget( $item[ 'label' ], $field[ 'id' ], $item, $field ); |
|
| 857 | 857 | break; |
| 858 | 858 | default: |
| 859 | - echo new GravityView_Admin_View_Field( $item['label'], $field['id'], $item, $field ); |
|
| 859 | + echo new GravityView_Admin_View_Field( $item[ 'label' ], $field[ 'id' ], $item, $field ); |
|
| 860 | 860 | } |
| 861 | 861 | |
| 862 | 862 | |
@@ -866,11 +866,11 @@ discard block |
||
| 866 | 866 | |
| 867 | 867 | } // End if zone is not empty ?> |
| 868 | 868 | |
| 869 | - <span class="drop-message"><?php echo sprintf(esc_attr__('"+ %s" or drag existing %ss here.', 'gravityview'), $button_label, $type ); ?></span> |
|
| 869 | + <span class="drop-message"><?php echo sprintf( esc_attr__( '"+ %s" or drag existing %ss here.', 'gravityview' ), $button_label, $type ); ?></span> |
|
| 870 | 870 | </div> |
| 871 | 871 | <div class="gv-droppable-area-action"> |
| 872 | - <a href="#" class="gv-add-field button-secondary" title="" data-objecttype="<?php echo esc_attr( $type ); ?>" data-areaid="<?php echo esc_attr( $zone .'_'. $area['areaid'] ); ?>" data-context="<?php echo esc_attr( $zone ); ?>"><?php echo '+ '.esc_html( $button_label ); ?></a> |
|
| 873 | - <p class="gv-droppable-area-title"><strong><?php echo esc_html( $area['title'] ); ?></strong><?php if( !empty( $area['subtitle'] ) ) { ?><span class="gv-droppable-area-subtitle"> – <?php echo esc_html( $area['subtitle'] ); ?></span><?php } ?></p> |
|
| 872 | + <a href="#" class="gv-add-field button-secondary" title="" data-objecttype="<?php echo esc_attr( $type ); ?>" data-areaid="<?php echo esc_attr( $zone . '_' . $area[ 'areaid' ] ); ?>" data-context="<?php echo esc_attr( $zone ); ?>"><?php echo '+ ' . esc_html( $button_label ); ?></a> |
|
| 873 | + <p class="gv-droppable-area-title"><strong><?php echo esc_html( $area[ 'title' ] ); ?></strong><?php if ( ! empty( $area[ 'subtitle' ] ) ) { ?><span class="gv-droppable-area-subtitle"> – <?php echo esc_html( $area[ 'subtitle' ] ); ?></span><?php } ?></p> |
|
| 874 | 874 | </div> |
| 875 | 875 | </div> |
| 876 | 876 | |
@@ -892,7 +892,7 @@ discard block |
||
| 892 | 892 | $default_widget_areas = GravityView_Plugin::get_default_widget_areas(); |
| 893 | 893 | |
| 894 | 894 | $widgets = array(); |
| 895 | - if( !empty( $post_id ) ) { |
|
| 895 | + if ( ! empty( $post_id ) ) { |
|
| 896 | 896 | $widgets = get_post_meta( $post_id, '_gravityview_directory_widgets', true ); |
| 897 | 897 | |
| 898 | 898 | } |
@@ -923,19 +923,19 @@ discard block |
||
| 923 | 923 | */ |
| 924 | 924 | function render_directory_active_areas( $template_id = '', $context = 'single', $post_id = '', $echo = false ) { |
| 925 | 925 | |
| 926 | - if( empty( $template_id ) ) { |
|
| 926 | + if ( empty( $template_id ) ) { |
|
| 927 | 927 | do_action( 'gravityview_log_debug', '[render_directory_active_areas] $template_id is empty' ); |
| 928 | 928 | return; |
| 929 | 929 | } |
| 930 | 930 | |
| 931 | 931 | $template_areas = apply_filters( 'gravityview_template_active_areas', array(), $template_id, $context ); |
| 932 | 932 | |
| 933 | - if( empty( $template_areas ) ) { |
|
| 933 | + if ( empty( $template_areas ) ) { |
|
| 934 | 934 | |
| 935 | 935 | do_action( 'gravityview_log_debug', '[render_directory_active_areas] No areas defined. Maybe template %s is disabled.', $template_id ); |
| 936 | 936 | $output = '<div>'; |
| 937 | - $output .= '<h2 class="description" style="font-size: 16px; margin:0">'. sprintf( esc_html__( 'This View is configured using the %s View type, which is disabled.', 'gravityview' ), '<em>'.$template_id.'</em>' ) .'</h2>'; |
|
| 938 | - $output .= '<p class="description" style="font-size: 14px; margin:0 0 1em 0;padding:0">'.esc_html__('The data is not lost; re-activate the associated plugin and the configuration will re-appear.', 'gravityview').'</p>'; |
|
| 937 | + $output .= '<h2 class="description" style="font-size: 16px; margin:0">' . sprintf( esc_html__( 'This View is configured using the %s View type, which is disabled.', 'gravityview' ), '<em>' . $template_id . '</em>' ) . '</h2>'; |
|
| 938 | + $output .= '<p class="description" style="font-size: 14px; margin:0 0 1em 0;padding:0">' . esc_html__( 'The data is not lost; re-activate the associated plugin and the configuration will re-appear.', 'gravityview' ) . '</p>'; |
|
| 939 | 939 | $output .= '</div>'; |
| 940 | 940 | } else { |
| 941 | 941 | |
@@ -950,7 +950,7 @@ discard block |
||
| 950 | 950 | |
| 951 | 951 | } |
| 952 | 952 | |
| 953 | - if( $echo ) { |
|
| 953 | + if ( $echo ) { |
|
| 954 | 954 | echo $output; |
| 955 | 955 | } |
| 956 | 956 | |
@@ -970,25 +970,25 @@ discard block |
||
| 970 | 970 | $is_widgets_page = ( $pagenow === 'widgets.php' ); |
| 971 | 971 | |
| 972 | 972 | // Add the GV font (with the Astronaut) |
| 973 | - wp_enqueue_style( 'gravityview_global', plugins_url('assets/css/admin-global.css', GRAVITYVIEW_FILE), array(), GravityView_Plugin::version ); |
|
| 973 | + wp_enqueue_style( 'gravityview_global', plugins_url( 'assets/css/admin-global.css', GRAVITYVIEW_FILE ), array(), GravityView_Plugin::version ); |
|
| 974 | 974 | |
| 975 | - wp_register_script( 'gravityview-jquery-cookie', plugins_url('includes/lib/jquery-cookie/jquery_cookie.js', GRAVITYVIEW_FILE), array( 'jquery' ), GravityView_Plugin::version, true ); |
|
| 975 | + wp_register_script( 'gravityview-jquery-cookie', plugins_url( 'includes/lib/jquery-cookie/jquery_cookie.js', GRAVITYVIEW_FILE ), array( 'jquery' ), GravityView_Plugin::version, true ); |
|
| 976 | 976 | |
| 977 | 977 | // Don't process any scripts below here if it's not a GravityView page. |
| 978 | - if( !gravityview_is_admin_page($hook) && !$is_widgets_page ) { return; } |
|
| 978 | + if ( ! gravityview_is_admin_page( $hook ) && ! $is_widgets_page ) { return; } |
|
| 979 | 979 | |
| 980 | 980 | // Only enqueue the following on single pages |
| 981 | - if( gravityview_is_admin_page($hook, 'single') || $is_widgets_page ) { |
|
| 981 | + if ( gravityview_is_admin_page( $hook, 'single' ) || $is_widgets_page ) { |
|
| 982 | 982 | |
| 983 | 983 | wp_enqueue_script( 'jquery-ui-datepicker' ); |
| 984 | - wp_enqueue_style( 'gravityview_views_datepicker', plugins_url('assets/css/admin-datepicker.css', GRAVITYVIEW_FILE), GravityView_Plugin::version ); |
|
| 984 | + wp_enqueue_style( 'gravityview_views_datepicker', plugins_url( 'assets/css/admin-datepicker.css', GRAVITYVIEW_FILE ), GravityView_Plugin::version ); |
|
| 985 | 985 | |
| 986 | - $script_debug = (defined('SCRIPT_DEBUG') && SCRIPT_DEBUG) ? '' : '.min'; |
|
| 986 | + $script_debug = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min'; |
|
| 987 | 987 | |
| 988 | 988 | //enqueue scripts |
| 989 | 989 | wp_enqueue_script( 'gravityview_views_scripts', plugins_url( 'assets/js/admin-views' . $script_debug . '.js', GRAVITYVIEW_FILE ), array( 'jquery-ui-tabs', 'jquery-ui-draggable', 'jquery-ui-droppable', 'jquery-ui-sortable', 'jquery-ui-tooltip', 'jquery-ui-dialog', 'gravityview-jquery-cookie', 'jquery-ui-datepicker', 'underscore' ), GravityView_Plugin::version ); |
| 990 | 990 | |
| 991 | - wp_localize_script('gravityview_views_scripts', 'gvGlobals', array( |
|
| 991 | + wp_localize_script( 'gravityview_views_scripts', 'gvGlobals', array( |
|
| 992 | 992 | 'cookiepath' => COOKIEPATH, |
| 993 | 993 | 'nonce' => wp_create_nonce( 'gravityview_ajaxviews' ), |
| 994 | 994 | 'label_viewname' => __( 'Enter View name here', 'gravityview' ), |
@@ -1001,9 +1001,9 @@ discard block |
||
| 1001 | 1001 | 'loading_error' => esc_html__( 'There was an error loading dynamic content.', 'gravityview' ), |
| 1002 | 1002 | 'field_loaderror' => __( 'Error while adding the field. Please try again or contact GravityView support.', 'gravityview' ), |
| 1003 | 1003 | 'remove_all_fields' => __( 'Would you like to remove all fields in this zone? (You are seeing this message because you were holding down the ALT key)', 'gravityview' ), |
| 1004 | - )); |
|
| 1004 | + ) ); |
|
| 1005 | 1005 | |
| 1006 | - wp_enqueue_style( 'gravityview_views_styles', plugins_url( 'assets/css/admin-views.css', GRAVITYVIEW_FILE ), array('dashicons', 'wp-jquery-ui-dialog' ), GravityView_Plugin::version ); |
|
| 1006 | + wp_enqueue_style( 'gravityview_views_styles', plugins_url( 'assets/css/admin-views.css', GRAVITYVIEW_FILE ), array( 'dashicons', 'wp-jquery-ui-dialog' ), GravityView_Plugin::version ); |
|
| 1007 | 1007 | |
| 1008 | 1008 | self::enqueue_gravity_forms_scripts(); |
| 1009 | 1009 | |
@@ -1022,10 +1022,10 @@ discard block |
||
| 1022 | 1022 | ); |
| 1023 | 1023 | |
| 1024 | 1024 | if ( wp_is_mobile() ) { |
| 1025 | - $scripts[] = 'jquery-touch-punch'; |
|
| 1025 | + $scripts[ ] = 'jquery-touch-punch'; |
|
| 1026 | 1026 | } |
| 1027 | 1027 | |
| 1028 | - foreach ($scripts as $script) { |
|
| 1028 | + foreach ( $scripts as $script ) { |
|
| 1029 | 1029 | wp_enqueue_script( $script ); |
| 1030 | 1030 | } |
| 1031 | 1031 | } |
@@ -1034,11 +1034,11 @@ discard block |
||
| 1034 | 1034 | |
| 1035 | 1035 | $filter = current_filter(); |
| 1036 | 1036 | |
| 1037 | - if( preg_match('/script/ism', $filter ) ) { |
|
| 1037 | + if ( preg_match( '/script/ism', $filter ) ) { |
|
| 1038 | 1038 | $allow_scripts = array( 'jquery-ui-core', 'jquery-ui-dialog', 'jquery-ui-tabs', 'jquery-ui-draggable', 'jquery-ui-droppable', 'jquery-ui-sortable', 'jquery-ui-tooltip', 'gravityview_views_scripts', 'gravityview-support', 'gravityview-jquery-cookie', 'gravityview_views_datepicker', |
| 1039 | 1039 | 'sack', 'gform_gravityforms', 'gform_forms', 'gform_form_admin', 'jquery-ui-autocomplete' ); |
| 1040 | 1040 | $registered = array_merge( $registered, $allow_scripts ); |
| 1041 | - } elseif( preg_match('/style/ism', $filter ) ) { |
|
| 1041 | + } elseif ( preg_match( '/style/ism', $filter ) ) { |
|
| 1042 | 1042 | $allow_styles = array( 'dashicons', 'wp-jquery-ui-dialog', 'gravityview_views_styles', 'gravityview_global', 'gravityview_views_datepicker' ); |
| 1043 | 1043 | $registered = array_merge( $registered, $allow_styles ); |
| 1044 | 1044 | } |
@@ -1,15 +1,15 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | - * GravityView template tags API |
|
| 4 | - * |
|
| 5 | - * @package GravityView |
|
| 6 | - * @license GPL2+ |
|
| 7 | - * @author Katz Web Services, Inc. |
|
| 8 | - * @link http://gravityview.co |
|
| 9 | - * @copyright Copyright 2014, Katz Web Services, Inc. |
|
| 10 | - * |
|
| 11 | - * @since 1.0.0 |
|
| 12 | - */ |
|
| 3 | + * GravityView template tags API |
|
| 4 | + * |
|
| 5 | + * @package GravityView |
|
| 6 | + * @license GPL2+ |
|
| 7 | + * @author Katz Web Services, Inc. |
|
| 8 | + * @link http://gravityview.co |
|
| 9 | + * @copyright Copyright 2014, Katz Web Services, Inc. |
|
| 10 | + * |
|
| 11 | + * @since 1.0.0 |
|
| 12 | + */ |
|
| 13 | 13 | |
| 14 | 14 | class GravityView_API { |
| 15 | 15 | |
@@ -146,20 +146,20 @@ discard block |
||
| 146 | 146 | |
| 147 | 147 | if( !empty( $field['custom_class'] ) ) { |
| 148 | 148 | |
| 149 | - $custom_class = $field['custom_class']; |
|
| 149 | + $custom_class = $field['custom_class']; |
|
| 150 | 150 | |
| 151 | - if( !empty( $entry ) ) { |
|
| 151 | + if( !empty( $entry ) ) { |
|
| 152 | 152 | |
| 153 | - // We want the merge tag to be formatted as a class. The merge tag may be |
|
| 154 | - // replaced by a multiple-word value that should be output as a single class. |
|
| 155 | - // "Office Manager" will be formatted as `.OfficeManager`, not `.Office` and `.Manager` |
|
| 156 | - add_filter('gform_merge_tag_filter', 'sanitize_html_class'); |
|
| 153 | + // We want the merge tag to be formatted as a class. The merge tag may be |
|
| 154 | + // replaced by a multiple-word value that should be output as a single class. |
|
| 155 | + // "Office Manager" will be formatted as `.OfficeManager`, not `.Office` and `.Manager` |
|
| 156 | + add_filter('gform_merge_tag_filter', 'sanitize_html_class'); |
|
| 157 | 157 | |
| 158 | - $custom_class = self::replace_variables( $custom_class, $form, $entry); |
|
| 158 | + $custom_class = self::replace_variables( $custom_class, $form, $entry); |
|
| 159 | 159 | |
| 160 | - // And then we want life to return to normal |
|
| 161 | - remove_filter('gform_merge_tag_filter', 'sanitize_html_class'); |
|
| 162 | - } |
|
| 160 | + // And then we want life to return to normal |
|
| 161 | + remove_filter('gform_merge_tag_filter', 'sanitize_html_class'); |
|
| 162 | + } |
|
| 163 | 163 | |
| 164 | 164 | // And now we want the spaces to be handled nicely. |
| 165 | 165 | $classes[] = gravityview_sanitize_html_class( $custom_class ); |
@@ -292,7 +292,7 @@ discard block |
||
| 292 | 292 | 'format' => $format, |
| 293 | 293 | 'entry' => $entry, |
| 294 | 294 | 'field_type' => $field_type, /** {@since 1.6} */ |
| 295 | - 'field_path' => $field_path, /** {@since 1.16} */ |
|
| 295 | + 'field_path' => $field_path, /** {@since 1.16} */ |
|
| 296 | 296 | )); |
| 297 | 297 | |
| 298 | 298 | if( ! empty( $field_path ) ) { |
@@ -603,29 +603,29 @@ discard block |
||
| 603 | 603 | return sanitize_title( $slug ); |
| 604 | 604 | } |
| 605 | 605 | |
| 606 | - /** |
|
| 607 | - * If using the entry custom slug feature, make sure the new entries have the custom slug created and saved as meta |
|
| 608 | - * |
|
| 609 | - * Triggered by add_action( 'gform_entry_created', array( 'GravityView_API', 'entry_create_custom_slug' ), 10, 2 ); |
|
| 610 | - * |
|
| 611 | - * @param $entry array Gravity Forms entry object |
|
| 612 | - * @param $form array Gravity Forms form object |
|
| 613 | - */ |
|
| 614 | - public static function entry_create_custom_slug( $entry, $form ) { |
|
| 615 | - /** |
|
| 616 | - * @filter `gravityview_custom_entry_slug` On entry creation, check if we are using the custom entry slug feature and update the meta |
|
| 617 | - * @param boolean $custom Should we process the custom entry slug? |
|
| 618 | - */ |
|
| 619 | - $custom = apply_filters( 'gravityview_custom_entry_slug', false ); |
|
| 620 | - if( $custom ) { |
|
| 621 | - // create the gravityview_unique_id and save it |
|
| 606 | + /** |
|
| 607 | + * If using the entry custom slug feature, make sure the new entries have the custom slug created and saved as meta |
|
| 608 | + * |
|
| 609 | + * Triggered by add_action( 'gform_entry_created', array( 'GravityView_API', 'entry_create_custom_slug' ), 10, 2 ); |
|
| 610 | + * |
|
| 611 | + * @param $entry array Gravity Forms entry object |
|
| 612 | + * @param $form array Gravity Forms form object |
|
| 613 | + */ |
|
| 614 | + public static function entry_create_custom_slug( $entry, $form ) { |
|
| 615 | + /** |
|
| 616 | + * @filter `gravityview_custom_entry_slug` On entry creation, check if we are using the custom entry slug feature and update the meta |
|
| 617 | + * @param boolean $custom Should we process the custom entry slug? |
|
| 618 | + */ |
|
| 619 | + $custom = apply_filters( 'gravityview_custom_entry_slug', false ); |
|
| 620 | + if( $custom ) { |
|
| 621 | + // create the gravityview_unique_id and save it |
|
| 622 | 622 | |
| 623 | - // Get the entry hash |
|
| 624 | - $hash = self::get_custom_entry_slug( $entry['id'], $entry ); |
|
| 625 | - gform_update_meta( $entry['id'], 'gravityview_unique_id', $hash ); |
|
| 623 | + // Get the entry hash |
|
| 624 | + $hash = self::get_custom_entry_slug( $entry['id'], $entry ); |
|
| 625 | + gform_update_meta( $entry['id'], 'gravityview_unique_id', $hash ); |
|
| 626 | 626 | |
| 627 | - } |
|
| 628 | - } |
|
| 627 | + } |
|
| 628 | + } |
|
| 629 | 629 | |
| 630 | 630 | |
| 631 | 631 | |
@@ -889,7 +889,7 @@ discard block |
||
| 889 | 889 | |
| 890 | 890 | // If there was an error, continue to the next term. |
| 891 | 891 | if ( is_wp_error( $term_link ) ) { |
| 892 | - continue; |
|
| 892 | + continue; |
|
| 893 | 893 | } |
| 894 | 894 | |
| 895 | 895 | $output[] = gravityview_get_link( $term_link, esc_html( $term->name ) ); |
@@ -30,29 +30,29 @@ discard block |
||
| 30 | 30 | |
| 31 | 31 | $label = ''; |
| 32 | 32 | |
| 33 | - if( !empty( $field['show_label'] ) || $force_show_label ) { |
|
| 33 | + if ( ! empty( $field[ 'show_label' ] ) || $force_show_label ) { |
|
| 34 | 34 | |
| 35 | - $label = $field['label']; |
|
| 35 | + $label = $field[ 'label' ]; |
|
| 36 | 36 | |
| 37 | 37 | // Support Gravity Forms 1.9+ |
| 38 | - if( class_exists( 'GF_Field' ) ) { |
|
| 38 | + if ( class_exists( 'GF_Field' ) ) { |
|
| 39 | 39 | |
| 40 | - $field_object = RGFormsModel::get_field( $form, $field['id'] ); |
|
| 40 | + $field_object = RGFormsModel::get_field( $form, $field[ 'id' ] ); |
|
| 41 | 41 | |
| 42 | - if( $field_object ) { |
|
| 42 | + if ( $field_object ) { |
|
| 43 | 43 | |
| 44 | - $input = GFFormsModel::get_input( $field_object, $field['id'] ); |
|
| 44 | + $input = GFFormsModel::get_input( $field_object, $field[ 'id' ] ); |
|
| 45 | 45 | |
| 46 | 46 | // This is a complex field, with labels on a per-input basis |
| 47 | - if( $input ) { |
|
| 47 | + if ( $input ) { |
|
| 48 | 48 | |
| 49 | 49 | // Does the input have a custom label on a per-input basis? Otherwise, default label. |
| 50 | - $label = ! empty( $input['customLabel'] ) ? $input['customLabel'] : $input['label']; |
|
| 50 | + $label = ! empty( $input[ 'customLabel' ] ) ? $input[ 'customLabel' ] : $input[ 'label' ]; |
|
| 51 | 51 | |
| 52 | 52 | } else { |
| 53 | 53 | |
| 54 | 54 | // This is a field with one label |
| 55 | - $label = $field_object->get_field_label( true, $field['label'] ); |
|
| 55 | + $label = $field_object->get_field_label( true, $field[ 'label' ] ); |
|
| 56 | 56 | |
| 57 | 57 | } |
| 58 | 58 | |
@@ -61,9 +61,9 @@ discard block |
||
| 61 | 61 | } |
| 62 | 62 | |
| 63 | 63 | // Use Gravity Forms label by default, but if a custom label is defined in GV, use it. |
| 64 | - if ( !empty( $field['custom_label'] ) ) { |
|
| 64 | + if ( ! empty( $field[ 'custom_label' ] ) ) { |
|
| 65 | 65 | |
| 66 | - $label = self::replace_variables( $field['custom_label'], $form, $entry ); |
|
| 66 | + $label = self::replace_variables( $field[ 'custom_label' ], $form, $entry ); |
|
| 67 | 67 | |
| 68 | 68 | } |
| 69 | 69 | |
@@ -117,11 +117,11 @@ discard block |
||
| 117 | 117 | |
| 118 | 118 | $width = NULL; |
| 119 | 119 | |
| 120 | - if( !empty( $field['width'] ) ) { |
|
| 121 | - $width = absint( $field['width'] ); |
|
| 120 | + if ( ! empty( $field[ 'width' ] ) ) { |
|
| 121 | + $width = absint( $field[ 'width' ] ); |
|
| 122 | 122 | |
| 123 | 123 | // If using percentages, limit to 100% |
| 124 | - if( '%d%%' === $format && $width > 100 ) { |
|
| 124 | + if ( '%d%%' === $format && $width > 100 ) { |
|
| 125 | 125 | $width = 100; |
| 126 | 126 | } |
| 127 | 127 | |
@@ -144,39 +144,39 @@ discard block |
||
| 144 | 144 | |
| 145 | 145 | $classes = array(); |
| 146 | 146 | |
| 147 | - if( !empty( $field['custom_class'] ) ) { |
|
| 147 | + if ( ! empty( $field[ 'custom_class' ] ) ) { |
|
| 148 | 148 | |
| 149 | - $custom_class = $field['custom_class']; |
|
| 149 | + $custom_class = $field[ 'custom_class' ]; |
|
| 150 | 150 | |
| 151 | - if( !empty( $entry ) ) { |
|
| 151 | + if ( ! empty( $entry ) ) { |
|
| 152 | 152 | |
| 153 | 153 | // We want the merge tag to be formatted as a class. The merge tag may be |
| 154 | 154 | // replaced by a multiple-word value that should be output as a single class. |
| 155 | 155 | // "Office Manager" will be formatted as `.OfficeManager`, not `.Office` and `.Manager` |
| 156 | - add_filter('gform_merge_tag_filter', 'sanitize_html_class'); |
|
| 156 | + add_filter( 'gform_merge_tag_filter', 'sanitize_html_class' ); |
|
| 157 | 157 | |
| 158 | - $custom_class = self::replace_variables( $custom_class, $form, $entry); |
|
| 158 | + $custom_class = self::replace_variables( $custom_class, $form, $entry ); |
|
| 159 | 159 | |
| 160 | 160 | // And then we want life to return to normal |
| 161 | - remove_filter('gform_merge_tag_filter', 'sanitize_html_class'); |
|
| 161 | + remove_filter( 'gform_merge_tag_filter', 'sanitize_html_class' ); |
|
| 162 | 162 | } |
| 163 | 163 | |
| 164 | 164 | // And now we want the spaces to be handled nicely. |
| 165 | - $classes[] = gravityview_sanitize_html_class( $custom_class ); |
|
| 165 | + $classes[ ] = gravityview_sanitize_html_class( $custom_class ); |
|
| 166 | 166 | |
| 167 | 167 | } |
| 168 | 168 | |
| 169 | - if(!empty($field['id'])) { |
|
| 170 | - if( !empty( $form ) && !empty( $form['id'] ) ) { |
|
| 171 | - $form_id = '-'.$form['id']; |
|
| 169 | + if ( ! empty( $field[ 'id' ] ) ) { |
|
| 170 | + if ( ! empty( $form ) && ! empty( $form[ 'id' ] ) ) { |
|
| 171 | + $form_id = '-' . $form[ 'id' ]; |
|
| 172 | 172 | } else { |
| 173 | - $form_id = $gravityview_view->getFormId() ? '-'. $gravityview_view->getFormId() : ''; |
|
| 173 | + $form_id = $gravityview_view->getFormId() ? '-' . $gravityview_view->getFormId() : ''; |
|
| 174 | 174 | } |
| 175 | 175 | |
| 176 | - $classes[] = 'gv-field'.$form_id.'-'.$field['id']; |
|
| 176 | + $classes[ ] = 'gv-field' . $form_id . '-' . $field[ 'id' ]; |
|
| 177 | 177 | } |
| 178 | 178 | |
| 179 | - return esc_attr(implode(' ', $classes)); |
|
| 179 | + return esc_attr( implode( ' ', $classes ) ); |
|
| 180 | 180 | } |
| 181 | 181 | |
| 182 | 182 | /** |
@@ -193,16 +193,16 @@ discard block |
||
| 193 | 193 | */ |
| 194 | 194 | public static function field_html_attr_id( $field, $form = array(), $entry = array() ) { |
| 195 | 195 | $gravityview_view = GravityView_View::getInstance(); |
| 196 | - $id = $field['id']; |
|
| 196 | + $id = $field[ 'id' ]; |
|
| 197 | 197 | |
| 198 | 198 | if ( ! empty( $id ) ) { |
| 199 | - if ( ! empty( $form ) && ! empty( $form['id'] ) ) { |
|
| 200 | - $form_id = '-' . $form['id']; |
|
| 199 | + if ( ! empty( $form ) && ! empty( $form[ 'id' ] ) ) { |
|
| 200 | + $form_id = '-' . $form[ 'id' ]; |
|
| 201 | 201 | } else { |
| 202 | 202 | $form_id = $gravityview_view->getFormId() ? '-' . $gravityview_view->getFormId() : ''; |
| 203 | 203 | } |
| 204 | 204 | |
| 205 | - $id = 'gv-field' . $form_id . '-' . $field['id']; |
|
| 205 | + $id = 'gv-field' . $form_id . '-' . $field[ 'id' ]; |
|
| 206 | 206 | } |
| 207 | 207 | |
| 208 | 208 | return esc_attr( $id ); |
@@ -219,17 +219,17 @@ discard block |
||
| 219 | 219 | */ |
| 220 | 220 | public static function field_value( $entry, $field_settings, $format = 'html' ) { |
| 221 | 221 | |
| 222 | - if( empty( $entry['form_id'] ) || empty( $field_settings['id'] ) ) { |
|
| 222 | + if ( empty( $entry[ 'form_id' ] ) || empty( $field_settings[ 'id' ] ) ) { |
|
| 223 | 223 | return NULL; |
| 224 | 224 | } |
| 225 | 225 | |
| 226 | 226 | $gravityview_view = GravityView_View::getInstance(); |
| 227 | 227 | |
| 228 | - $field_id = $field_settings['id']; |
|
| 228 | + $field_id = $field_settings[ 'id' ]; |
|
| 229 | 229 | $form = $gravityview_view->getForm(); |
| 230 | 230 | $field = gravityview_get_field( $form, $field_id ); |
| 231 | 231 | |
| 232 | - if( $field && is_numeric( $field_id ) ) { |
|
| 232 | + if ( $field && is_numeric( $field_id ) ) { |
|
| 233 | 233 | // Used as file name of field template in GV. |
| 234 | 234 | // Don't use RGFormsModel::get_input_type( $field ); we don't care if it's a radio input; we want to know it's a 'quiz' field |
| 235 | 235 | $field_type = $field->type; |
@@ -240,12 +240,12 @@ discard block |
||
| 240 | 240 | } |
| 241 | 241 | |
| 242 | 242 | // If a Gravity Forms Field is found, get the field display |
| 243 | - if( $field ) { |
|
| 243 | + if ( $field ) { |
|
| 244 | 244 | |
| 245 | 245 | // Prevent any PHP warnings that may be generated |
| 246 | 246 | ob_start(); |
| 247 | 247 | |
| 248 | - $display_value = GFCommon::get_lead_field_display( $field, $value, $entry["currency"], false, $format ); |
|
| 248 | + $display_value = GFCommon::get_lead_field_display( $field, $value, $entry[ "currency" ], false, $format ); |
|
| 249 | 249 | |
| 250 | 250 | if ( $errors = ob_get_clean() ) { |
| 251 | 251 | do_action( 'gravityview_log_error', 'GravityView_API[field_value] Errors when calling GFCommon::get_lead_field_display()', $errors ); |
@@ -254,7 +254,7 @@ discard block |
||
| 254 | 254 | $display_value = apply_filters( "gform_entry_field_value", $display_value, $field, $entry, $form ); |
| 255 | 255 | |
| 256 | 256 | // prevent the use of merge_tags for non-admin fields |
| 257 | - if( !empty( $field->adminOnly ) ) { |
|
| 257 | + if ( ! empty( $field->adminOnly ) ) { |
|
| 258 | 258 | $display_value = self::replace_variables( $display_value, $form, $entry ); |
| 259 | 259 | } |
| 260 | 260 | } else { |
@@ -264,7 +264,7 @@ discard block |
||
| 264 | 264 | |
| 265 | 265 | // Check whether the field exists in /includes/fields/{$field_type}.php |
| 266 | 266 | // This can be overridden by user template files. |
| 267 | - $field_path = $gravityview_view->locate_template("fields/{$field_type}.php"); |
|
| 267 | + $field_path = $gravityview_view->locate_template( "fields/{$field_type}.php" ); |
|
| 268 | 268 | |
| 269 | 269 | // Set the field data to be available in the templates |
| 270 | 270 | $gravityview_view->setCurrentField( array( |
@@ -278,11 +278,11 @@ discard block |
||
| 278 | 278 | 'entry' => $entry, |
| 279 | 279 | 'field_type' => $field_type, /** {@since 1.6} */ |
| 280 | 280 | 'field_path' => $field_path, /** {@since 1.16} */ |
| 281 | - )); |
|
| 281 | + ) ); |
|
| 282 | 282 | |
| 283 | - if( ! empty( $field_path ) ) { |
|
| 283 | + if ( ! empty( $field_path ) ) { |
|
| 284 | 284 | |
| 285 | - do_action( 'gravityview_log_debug', sprintf('[field_value] Rendering %s', $field_path ) ); |
|
| 285 | + do_action( 'gravityview_log_debug', sprintf( '[field_value] Rendering %s', $field_path ) ); |
|
| 286 | 286 | |
| 287 | 287 | ob_start(); |
| 288 | 288 | |
@@ -298,7 +298,7 @@ discard block |
||
| 298 | 298 | } |
| 299 | 299 | |
| 300 | 300 | // Get the field settings again so that the field template can override the settings |
| 301 | - $field_settings = $gravityview_view->getCurrentField('field_settings'); |
|
| 301 | + $field_settings = $gravityview_view->getCurrentField( 'field_settings' ); |
|
| 302 | 302 | |
| 303 | 303 | /** |
| 304 | 304 | * @filter `gravityview_field_entry_value_{$field_type}_pre_link` Modify the field value output for a field type before Show As Link setting is applied. Example: `gravityview_field_entry_value_number_pre_link` |
@@ -316,9 +316,9 @@ discard block |
||
| 316 | 316 | * Fields can override this by modifying the field data variable inside the field. See /templates/fields/post_image.php for an example. |
| 317 | 317 | * |
| 318 | 318 | */ |
| 319 | - if( !empty( $field_settings['show_as_link'] ) && ! gv_empty( $output, false, false ) ) { |
|
| 319 | + if ( ! empty( $field_settings[ 'show_as_link' ] ) && ! gv_empty( $output, false, false ) ) { |
|
| 320 | 320 | |
| 321 | - $link_atts = empty( $field_settings['new_window'] ) ? array() : array( 'target' => '_blank' ); |
|
| 321 | + $link_atts = empty( $field_settings[ 'new_window' ] ) ? array() : array( 'target' => '_blank' ); |
|
| 322 | 322 | |
| 323 | 323 | $output = self::entry_link_html( $entry, $output, $link_atts, $field_settings ); |
| 324 | 324 | |
@@ -332,7 +332,7 @@ discard block |
||
| 332 | 332 | * @param array $field_settings Settings for the particular GV field |
| 333 | 333 | * @param array $field Current field being displayed |
| 334 | 334 | */ |
| 335 | - $output = apply_filters( 'gravityview_field_entry_value_'.$field_type, $output, $entry, $field_settings, $gravityview_view->getCurrentField() ); |
|
| 335 | + $output = apply_filters( 'gravityview_field_entry_value_' . $field_type, $output, $entry, $field_settings, $gravityview_view->getCurrentField() ); |
|
| 336 | 336 | |
| 337 | 337 | /** |
| 338 | 338 | * @filter `gravityview_field_entry_value` Modify the field value output for all field types |
@@ -361,14 +361,14 @@ discard block |
||
| 361 | 361 | */ |
| 362 | 362 | public static function entry_link_html( $entry = array(), $anchor_text = '', $passed_tag_atts = array(), $field_settings = array() ) { |
| 363 | 363 | |
| 364 | - if ( empty( $entry ) || ! is_array( $entry ) || ! isset( $entry['id'] ) ) { |
|
| 364 | + if ( empty( $entry ) || ! is_array( $entry ) || ! isset( $entry[ 'id' ] ) ) { |
|
| 365 | 365 | do_action( 'gravityview_log_debug', 'GravityView_API[entry_link_tag] Entry not defined; returning null', $entry ); |
| 366 | 366 | return NULL; |
| 367 | 367 | } |
| 368 | 368 | |
| 369 | 369 | $href = self::entry_link( $entry ); |
| 370 | 370 | |
| 371 | - if( '' === $href ) { |
|
| 371 | + if ( '' === $href ) { |
|
| 372 | 372 | return NULL; |
| 373 | 373 | } |
| 374 | 374 | |
@@ -391,19 +391,19 @@ discard block |
||
| 391 | 391 | * @param boolean $wpautop Apply wpautop() to the output? |
| 392 | 392 | * @return string HTML of "no results" text |
| 393 | 393 | */ |
| 394 | - public static function no_results($wpautop = true) { |
|
| 394 | + public static function no_results( $wpautop = true ) { |
|
| 395 | 395 | $gravityview_view = GravityView_View::getInstance(); |
| 396 | 396 | |
| 397 | 397 | $is_search = false; |
| 398 | 398 | |
| 399 | - if( $gravityview_view && ( $gravityview_view->curr_start || $gravityview_view->curr_end || $gravityview_view->curr_search ) ) { |
|
| 399 | + if ( $gravityview_view && ( $gravityview_view->curr_start || $gravityview_view->curr_end || $gravityview_view->curr_search ) ) { |
|
| 400 | 400 | $is_search = true; |
| 401 | 401 | } |
| 402 | 402 | |
| 403 | - if($is_search) { |
|
| 404 | - $output = __('This search returned no results.', 'gravityview'); |
|
| 403 | + if ( $is_search ) { |
|
| 404 | + $output = __( 'This search returned no results.', 'gravityview' ); |
|
| 405 | 405 | } else { |
| 406 | - $output = __('No entries match your request.', 'gravityview'); |
|
| 406 | + $output = __( 'No entries match your request.', 'gravityview' ); |
|
| 407 | 407 | } |
| 408 | 408 | |
| 409 | 409 | /** |
@@ -411,9 +411,9 @@ discard block |
||
| 411 | 411 | * @param string $output The existing "No Entries" text |
| 412 | 412 | * @param boolean $is_search Is the current page a search result, or just a multiple entries screen? |
| 413 | 413 | */ |
| 414 | - $output = apply_filters( 'gravitview_no_entries_text', $output, $is_search); |
|
| 414 | + $output = apply_filters( 'gravitview_no_entries_text', $output, $is_search ); |
|
| 415 | 415 | |
| 416 | - return $wpautop ? wpautop($output) : $output; |
|
| 416 | + return $wpautop ? wpautop( $output ) : $output; |
|
| 417 | 417 | } |
| 418 | 418 | |
| 419 | 419 | /** |
@@ -430,37 +430,37 @@ discard block |
||
| 430 | 430 | |
| 431 | 431 | $gravityview_view = GravityView_View::getInstance(); |
| 432 | 432 | |
| 433 | - if( empty( $post_id ) ) { |
|
| 433 | + if ( empty( $post_id ) ) { |
|
| 434 | 434 | |
| 435 | 435 | $post_id = false; |
| 436 | 436 | |
| 437 | 437 | // DataTables passes the Post ID |
| 438 | - if( defined('DOING_AJAX') && DOING_AJAX ) { |
|
| 438 | + if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) { |
|
| 439 | 439 | |
| 440 | - $post_id = isset( $_POST['post_id'] ) ? (int)$_POST['post_id'] : false; |
|
| 440 | + $post_id = isset( $_POST[ 'post_id' ] ) ? (int)$_POST[ 'post_id' ] : false; |
|
| 441 | 441 | |
| 442 | 442 | } else { |
| 443 | 443 | |
| 444 | 444 | // The Post ID has been passed via the shortcode |
| 445 | - if( !empty( $gravityview_view ) && $gravityview_view->getPostId() ) { |
|
| 445 | + if ( ! empty( $gravityview_view ) && $gravityview_view->getPostId() ) { |
|
| 446 | 446 | |
| 447 | 447 | $post_id = $gravityview_view->getPostId(); |
| 448 | 448 | |
| 449 | 449 | } else { |
| 450 | 450 | |
| 451 | 451 | // This is a GravityView post type |
| 452 | - if( GravityView_frontend::getInstance()->isGravityviewPostType() ) { |
|
| 452 | + if ( GravityView_frontend::getInstance()->isGravityviewPostType() ) { |
|
| 453 | 453 | |
| 454 | 454 | $post_id = isset( $gravityview_view ) ? $gravityview_view->getViewId() : $post->ID; |
| 455 | 455 | |
| 456 | 456 | } else { |
| 457 | 457 | |
| 458 | 458 | // This is an embedded GravityView; use the embedded post's ID as the base. |
| 459 | - if( GravityView_frontend::getInstance()->isPostHasShortcode() && is_a( $post, 'WP_Post' ) ) { |
|
| 459 | + if ( GravityView_frontend::getInstance()->isPostHasShortcode() && is_a( $post, 'WP_Post' ) ) { |
|
| 460 | 460 | |
| 461 | 461 | $post_id = $post->ID; |
| 462 | 462 | |
| 463 | - } elseif( $gravityview_view->getViewId() ) { |
|
| 463 | + } elseif ( $gravityview_view->getViewId() ) { |
|
| 464 | 464 | |
| 465 | 465 | // The GravityView has been embedded in a widget or in a template, and |
| 466 | 466 | // is not in the current content. Thus, we defer to the View's own ID. |
@@ -475,36 +475,36 @@ discard block |
||
| 475 | 475 | } |
| 476 | 476 | |
| 477 | 477 | // No post ID, get outta here. |
| 478 | - if( empty( $post_id ) ) { |
|
| 478 | + if ( empty( $post_id ) ) { |
|
| 479 | 479 | return NULL; |
| 480 | 480 | } |
| 481 | 481 | |
| 482 | 482 | // If we've saved the permalink in memory, use it |
| 483 | 483 | // @since 1.3 |
| 484 | - $link = wp_cache_get( 'gv_directory_link_'.$post_id ); |
|
| 484 | + $link = wp_cache_get( 'gv_directory_link_' . $post_id ); |
|
| 485 | 485 | |
| 486 | - if( empty( $link ) ) { |
|
| 486 | + if ( empty( $link ) ) { |
|
| 487 | 487 | |
| 488 | 488 | $link = get_permalink( $post_id ); |
| 489 | 489 | |
| 490 | 490 | // If not yet saved, cache the permalink. |
| 491 | 491 | // @since 1.3 |
| 492 | - wp_cache_set( 'gv_directory_link_'.$post_id, $link ); |
|
| 492 | + wp_cache_set( 'gv_directory_link_' . $post_id, $link ); |
|
| 493 | 493 | |
| 494 | 494 | } |
| 495 | 495 | |
| 496 | 496 | // Deal with returning to proper pagination for embedded views |
| 497 | - if( $link && $add_query_args ) { |
|
| 497 | + if ( $link && $add_query_args ) { |
|
| 498 | 498 | |
| 499 | 499 | $args = array(); |
| 500 | 500 | |
| 501 | - if( $pagenum = rgget('pagenum') ) { |
|
| 502 | - $args['pagenum'] = intval( $pagenum ); |
|
| 501 | + if ( $pagenum = rgget( 'pagenum' ) ) { |
|
| 502 | + $args[ 'pagenum' ] = intval( $pagenum ); |
|
| 503 | 503 | } |
| 504 | 504 | |
| 505 | - if( $sort = rgget('sort') ) { |
|
| 506 | - $args['sort'] = $sort; |
|
| 507 | - $args['dir'] = rgget('dir'); |
|
| 505 | + if ( $sort = rgget( 'sort' ) ) { |
|
| 506 | + $args[ 'sort' ] = $sort; |
|
| 507 | + $args[ 'dir' ] = rgget( 'dir' ); |
|
| 508 | 508 | } |
| 509 | 509 | |
| 510 | 510 | $link = add_query_arg( $args, $link ); |
@@ -527,7 +527,7 @@ discard block |
||
| 527 | 527 | private static function get_custom_entry_slug( $id, $entry = array() ) { |
| 528 | 528 | |
| 529 | 529 | // Generate an unique hash to use as the default value |
| 530 | - $slug = substr( wp_hash( $id, 'gravityview'.$id ), 0, 8 ); |
|
| 530 | + $slug = substr( wp_hash( $id, 'gravityview' . $id ), 0, 8 ); |
|
| 531 | 531 | |
| 532 | 532 | /** |
| 533 | 533 | * @filter `gravityview_entry_slug` Modify the unique hash ID generated, if you want to improve usability or change the format. This will allow for custom URLs, such as `{entryid}-{first-name}` or even, if unique, `{first-name}-{last-name}` |
@@ -538,7 +538,7 @@ discard block |
||
| 538 | 538 | $slug = apply_filters( 'gravityview_entry_slug', $slug, $id, $entry ); |
| 539 | 539 | |
| 540 | 540 | // Make sure we have something - use the original ID as backup. |
| 541 | - if( empty( $slug ) ) { |
|
| 541 | + if ( empty( $slug ) ) { |
|
| 542 | 542 | $slug = $id; |
| 543 | 543 | } |
| 544 | 544 | |
@@ -567,7 +567,7 @@ discard block |
||
| 567 | 567 | * @filter `gravityview_custom_entry_slug` Whether to enable and use custom entry slugs. |
| 568 | 568 | * @param boolean True: Allow for slugs based on entry values. False: always use entry IDs (default) |
| 569 | 569 | */ |
| 570 | - $custom = apply_filters('gravityview_custom_entry_slug', false ); |
|
| 570 | + $custom = apply_filters( 'gravityview_custom_entry_slug', false ); |
|
| 571 | 571 | |
| 572 | 572 | // If we're using custom slug... |
| 573 | 573 | if ( $custom ) { |
@@ -581,7 +581,7 @@ discard block |
||
| 581 | 581 | // If it does have a hash set, and the hash is expected, use it. |
| 582 | 582 | // This check allows users to change the hash structure using the |
| 583 | 583 | // gravityview_entry_hash filter and have the old hashes expire. |
| 584 | - if( empty( $value ) || $value !== $hash ) { |
|
| 584 | + if ( empty( $value ) || $value !== $hash ) { |
|
| 585 | 585 | |
| 586 | 586 | gform_update_meta( $id_or_string, 'gravityview_unique_id', $hash ); |
| 587 | 587 | |
@@ -609,12 +609,12 @@ discard block |
||
| 609 | 609 | * @param boolean $custom Should we process the custom entry slug? |
| 610 | 610 | */ |
| 611 | 611 | $custom = apply_filters( 'gravityview_custom_entry_slug', false ); |
| 612 | - if( $custom ) { |
|
| 612 | + if ( $custom ) { |
|
| 613 | 613 | // create the gravityview_unique_id and save it |
| 614 | 614 | |
| 615 | 615 | // Get the entry hash |
| 616 | - $hash = self::get_custom_entry_slug( $entry['id'], $entry ); |
|
| 617 | - gform_update_meta( $entry['id'], 'gravityview_unique_id', $hash ); |
|
| 616 | + $hash = self::get_custom_entry_slug( $entry[ 'id' ], $entry ); |
|
| 617 | + gform_update_meta( $entry[ 'id' ], 'gravityview_unique_id', $hash ); |
|
| 618 | 618 | |
| 619 | 619 | } |
| 620 | 620 | } |
@@ -631,14 +631,14 @@ discard block |
||
| 631 | 631 | */ |
| 632 | 632 | public static function entry_link( $entry, $post_id = NULL, $add_directory_args = true ) { |
| 633 | 633 | |
| 634 | - if( ! empty( $entry ) && ! is_array( $entry ) ) { |
|
| 634 | + if ( ! empty( $entry ) && ! is_array( $entry ) ) { |
|
| 635 | 635 | $entry = GVCommon::get_entry( $entry ); |
| 636 | - } else if( empty( $entry ) ) { |
|
| 636 | + } else if ( empty( $entry ) ) { |
|
| 637 | 637 | $entry = GravityView_frontend::getInstance()->getEntry(); |
| 638 | 638 | } |
| 639 | 639 | |
| 640 | 640 | // Second parameter used to be passed as $field; this makes sure it's not an array |
| 641 | - if( !is_numeric( $post_id ) ) { |
|
| 641 | + if ( ! is_numeric( $post_id ) ) { |
|
| 642 | 642 | $post_id = NULL; |
| 643 | 643 | } |
| 644 | 644 | |
@@ -646,15 +646,15 @@ discard block |
||
| 646 | 646 | $directory_link = self::directory_link( $post_id, false ); |
| 647 | 647 | |
| 648 | 648 | // No post ID? Get outta here. |
| 649 | - if( empty( $directory_link ) ) { |
|
| 649 | + if ( empty( $directory_link ) ) { |
|
| 650 | 650 | return ''; |
| 651 | 651 | } |
| 652 | 652 | |
| 653 | 653 | $query_arg_name = GravityView_Post_Types::get_entry_var_name(); |
| 654 | 654 | |
| 655 | - $entry_slug = self::get_entry_slug( $entry['id'], $entry ); |
|
| 655 | + $entry_slug = self::get_entry_slug( $entry[ 'id' ], $entry ); |
|
| 656 | 656 | |
| 657 | - if( get_option('permalink_structure') && !is_preview() ) { |
|
| 657 | + if ( get_option( 'permalink_structure' ) && ! is_preview() ) { |
|
| 658 | 658 | |
| 659 | 659 | $args = array(); |
| 660 | 660 | |
@@ -664,9 +664,9 @@ discard block |
||
| 664 | 664 | */ |
| 665 | 665 | $link_parts = explode( '?', $directory_link ); |
| 666 | 666 | |
| 667 | - $query = !empty( $link_parts[1] ) ? '?'.$link_parts[1] : ''; |
|
| 667 | + $query = ! empty( $link_parts[ 1 ] ) ? '?' . $link_parts[ 1 ] : ''; |
|
| 668 | 668 | |
| 669 | - $directory_link = trailingslashit( $link_parts[0] ) . $query_arg_name . '/'. $entry_slug .'/' . $query; |
|
| 669 | + $directory_link = trailingslashit( $link_parts[ 0 ] ) . $query_arg_name . '/' . $entry_slug . '/' . $query; |
|
| 670 | 670 | |
| 671 | 671 | } else { |
| 672 | 672 | |
@@ -676,18 +676,18 @@ discard block |
||
| 676 | 676 | /** |
| 677 | 677 | * @since 1.7.3 |
| 678 | 678 | */ |
| 679 | - if( $add_directory_args ) { |
|
| 679 | + if ( $add_directory_args ) { |
|
| 680 | 680 | |
| 681 | - if( !empty( $_GET['pagenum'] ) ) { |
|
| 682 | - $args['pagenum'] = intval( $_GET['pagenum'] ); |
|
| 681 | + if ( ! empty( $_GET[ 'pagenum' ] ) ) { |
|
| 682 | + $args[ 'pagenum' ] = intval( $_GET[ 'pagenum' ] ); |
|
| 683 | 683 | } |
| 684 | 684 | |
| 685 | 685 | /** |
| 686 | 686 | * @since 1.7 |
| 687 | 687 | */ |
| 688 | - if( $sort = rgget('sort') ) { |
|
| 689 | - $args['sort'] = $sort; |
|
| 690 | - $args['dir'] = rgget('dir'); |
|
| 688 | + if ( $sort = rgget( 'sort' ) ) { |
|
| 689 | + $args[ 'sort' ] = $sort; |
|
| 690 | + $args[ 'dir' ] = rgget( 'dir' ); |
|
| 691 | 691 | } |
| 692 | 692 | |
| 693 | 693 | } |
@@ -697,8 +697,8 @@ discard block |
||
| 697 | 697 | * has the view id so that Advanced Filters can be applied correctly when rendering the single view |
| 698 | 698 | * @see GravityView_frontend::get_context_view_id() |
| 699 | 699 | */ |
| 700 | - if( class_exists( 'GravityView_View_Data' ) && GravityView_View_Data::getInstance()->has_multiple_views() ) { |
|
| 701 | - $args['gvid'] = gravityview_get_view_id(); |
|
| 700 | + if ( class_exists( 'GravityView_View_Data' ) && GravityView_View_Data::getInstance()->has_multiple_views() ) { |
|
| 701 | + $args[ 'gvid' ] = gravityview_get_view_id(); |
|
| 702 | 702 | } |
| 703 | 703 | |
| 704 | 704 | return add_query_arg( $args, $directory_link ); |
@@ -716,7 +716,7 @@ discard block |
||
| 716 | 716 | } |
| 717 | 717 | |
| 718 | 718 | function gv_class( $field, $form = NULL, $entry = array() ) { |
| 719 | - return GravityView_API::field_class( $field, $form, $entry ); |
|
| 719 | + return GravityView_API::field_class( $field, $form, $entry ); |
|
| 720 | 720 | } |
| 721 | 721 | |
| 722 | 722 | /** |
@@ -738,15 +738,15 @@ discard block |
||
| 738 | 738 | |
| 739 | 739 | $default_css_class = ! empty( $view_id ) ? sprintf( 'gv-container gv-container-%d', $view_id ) : 'gv-container'; |
| 740 | 740 | |
| 741 | - if( GravityView_View::getInstance()->isHideUntilSearched() ) { |
|
| 741 | + if ( GravityView_View::getInstance()->isHideUntilSearched() ) { |
|
| 742 | 742 | $default_css_class .= ' hidden'; |
| 743 | 743 | } |
| 744 | 744 | |
| 745 | - if( 0 === GravityView_View::getInstance()->getTotalEntries() ) { |
|
| 745 | + if ( 0 === GravityView_View::getInstance()->getTotalEntries() ) { |
|
| 746 | 746 | $default_css_class .= ' gv-container-no-results'; |
| 747 | 747 | } |
| 748 | 748 | |
| 749 | - $css_class = trim( $passed_css_class . ' '. $default_css_class ); |
|
| 749 | + $css_class = trim( $passed_css_class . ' ' . $default_css_class ); |
|
| 750 | 750 | |
| 751 | 751 | /** |
| 752 | 752 | * @filter `gravityview/render/container/class` Modify the CSS class to be added to the wrapper <div> of a View |
@@ -757,7 +757,7 @@ discard block |
||
| 757 | 757 | |
| 758 | 758 | $css_class = gravityview_sanitize_html_class( $css_class ); |
| 759 | 759 | |
| 760 | - if( $echo ) { |
|
| 760 | + if ( $echo ) { |
|
| 761 | 761 | echo $css_class; |
| 762 | 762 | } |
| 763 | 763 | |
@@ -768,7 +768,7 @@ discard block |
||
| 768 | 768 | |
| 769 | 769 | $value = GravityView_API::field_value( $entry, $field ); |
| 770 | 770 | |
| 771 | - if( $value === '' ) { |
|
| 771 | + if ( $value === '' ) { |
|
| 772 | 772 | /** |
| 773 | 773 | * @filter `gravityview_empty_value` What to display when a field is empty |
| 774 | 774 | * @param string $value (empty string) |
@@ -787,7 +787,7 @@ discard block |
||
| 787 | 787 | return GravityView_API::entry_link( $entry, $post_id ); |
| 788 | 788 | } |
| 789 | 789 | |
| 790 | -function gv_no_results($wpautop = true) { |
|
| 790 | +function gv_no_results( $wpautop = true ) { |
|
| 791 | 791 | return GravityView_API::no_results( $wpautop ); |
| 792 | 792 | } |
| 793 | 793 | |
@@ -800,7 +800,7 @@ discard block |
||
| 800 | 800 | |
| 801 | 801 | $href = gv_directory_link(); |
| 802 | 802 | |
| 803 | - if( empty( $href ) ) { return NULL; } |
|
| 803 | + if ( empty( $href ) ) { return NULL; } |
|
| 804 | 804 | |
| 805 | 805 | // calculate link label |
| 806 | 806 | $gravityview_view = GravityView_View::getInstance(); |
@@ -816,7 +816,7 @@ discard block |
||
| 816 | 816 | |
| 817 | 817 | $link = gravityview_get_link( $href, esc_html( $label ), array( |
| 818 | 818 | 'data-viewid' => $gravityview_view->getViewId() |
| 819 | - )); |
|
| 819 | + ) ); |
|
| 820 | 820 | |
| 821 | 821 | return $link; |
| 822 | 822 | } |
@@ -835,7 +835,7 @@ discard block |
||
| 835 | 835 | */ |
| 836 | 836 | function gravityview_get_field_value( $entry, $field_id, $display_value ) { |
| 837 | 837 | |
| 838 | - if( floatval( $field_id ) === floor( floatval( $field_id ) ) ) { |
|
| 838 | + if ( floatval( $field_id ) === floor( floatval( $field_id ) ) ) { |
|
| 839 | 839 | |
| 840 | 840 | // For the complete field value as generated by Gravity Forms |
| 841 | 841 | return $display_value; |
@@ -865,16 +865,16 @@ discard block |
||
| 865 | 865 | |
| 866 | 866 | $terms = explode( ', ', $value ); |
| 867 | 867 | |
| 868 | - foreach ($terms as $term_name ) { |
|
| 868 | + foreach ( $terms as $term_name ) { |
|
| 869 | 869 | |
| 870 | 870 | // If we're processing a category, |
| 871 | - if( $taxonomy === 'category' ) { |
|
| 871 | + if ( $taxonomy === 'category' ) { |
|
| 872 | 872 | |
| 873 | 873 | // Use rgexplode to prevent errors if : doesn't exist |
| 874 | 874 | list( $term_name, $term_id ) = rgexplode( ':', $value, 2 ); |
| 875 | 875 | |
| 876 | 876 | // The explode was succesful; we have the category ID |
| 877 | - if( !empty( $term_id )) { |
|
| 877 | + if ( ! empty( $term_id ) ) { |
|
| 878 | 878 | $term = get_term_by( 'id', $term_id, $taxonomy ); |
| 879 | 879 | } else { |
| 880 | 880 | // We have to fall back to the name |
@@ -887,7 +887,7 @@ discard block |
||
| 887 | 887 | } |
| 888 | 888 | |
| 889 | 889 | // There's still a tag/category here. |
| 890 | - if( $term ) { |
|
| 890 | + if ( $term ) { |
|
| 891 | 891 | |
| 892 | 892 | $term_link = get_term_link( $term, $taxonomy ); |
| 893 | 893 | |
@@ -896,11 +896,11 @@ discard block |
||
| 896 | 896 | continue; |
| 897 | 897 | } |
| 898 | 898 | |
| 899 | - $output[] = gravityview_get_link( $term_link, esc_html( $term->name ) ); |
|
| 899 | + $output[ ] = gravityview_get_link( $term_link, esc_html( $term->name ) ); |
|
| 900 | 900 | } |
| 901 | 901 | } |
| 902 | 902 | |
| 903 | - return implode(', ', $output ); |
|
| 903 | + return implode( ', ', $output ); |
|
| 904 | 904 | } |
| 905 | 905 | |
| 906 | 906 | /** |
@@ -914,8 +914,8 @@ discard block |
||
| 914 | 914 | |
| 915 | 915 | $output = get_the_term_list( $post_id, $taxonomy, NULL, ', ' ); |
| 916 | 916 | |
| 917 | - if( empty( $link ) ) { |
|
| 918 | - return strip_tags( $output); |
|
| 917 | + if ( empty( $link ) ) { |
|
| 918 | + return strip_tags( $output ); |
|
| 919 | 919 | } |
| 920 | 920 | |
| 921 | 921 | return $output; |
@@ -934,7 +934,7 @@ discard block |
||
| 934 | 934 | $fe = GravityView_frontend::getInstance(); |
| 935 | 935 | |
| 936 | 936 | // Solve problem when loading content via admin-ajax.php |
| 937 | - if( ! $fe->getGvOutputData() ) { |
|
| 937 | + if ( ! $fe->getGvOutputData() ) { |
|
| 938 | 938 | |
| 939 | 939 | do_action( 'gravityview_log_debug', '[gravityview_get_current_views] gv_output_data not defined; parsing content.' ); |
| 940 | 940 | |
@@ -942,7 +942,7 @@ discard block |
||
| 942 | 942 | } |
| 943 | 943 | |
| 944 | 944 | // Make 100% sure that we're dealing with a properly called situation |
| 945 | - if( !is_a( $fe->getGvOutputData(), 'GravityView_View_Data' ) ) { |
|
| 945 | + if ( ! is_a( $fe->getGvOutputData(), 'GravityView_View_Data' ) ) { |
|
| 946 | 946 | |
| 947 | 947 | do_action( 'gravityview_log_debug', '[gravityview_get_current_views] gv_output_data not an object or get_view not callable.', $fe->getGvOutputData() ); |
| 948 | 948 | |
@@ -962,10 +962,10 @@ discard block |
||
| 962 | 962 | |
| 963 | 963 | $fe = GravityView_frontend::getInstance(); |
| 964 | 964 | |
| 965 | - if( ! $fe->getGvOutputData() ) { return array(); } |
|
| 965 | + if ( ! $fe->getGvOutputData() ) { return array(); } |
|
| 966 | 966 | |
| 967 | 967 | // If not set, grab the current view ID |
| 968 | - if( empty( $view_id ) ) { |
|
| 968 | + if ( empty( $view_id ) ) { |
|
| 969 | 969 | $view_id = $fe->get_context_view_id(); |
| 970 | 970 | } |
| 971 | 971 | |
@@ -1030,11 +1030,11 @@ discard block |
||
| 1030 | 1030 | */ |
| 1031 | 1031 | $is_edit_entry = apply_filters( 'gravityview_is_edit_entry', false ); |
| 1032 | 1032 | |
| 1033 | - if( $is_edit_entry ) { |
|
| 1033 | + if ( $is_edit_entry ) { |
|
| 1034 | 1034 | $context = 'edit'; |
| 1035 | - } else if( class_exists( 'GravityView_frontend' ) && $single = GravityView_frontend::is_single_entry() ) { |
|
| 1035 | + } else if ( class_exists( 'GravityView_frontend' ) && $single = GravityView_frontend::is_single_entry() ) { |
|
| 1036 | 1036 | $context = 'single'; |
| 1037 | - } else if( class_exists( 'GravityView_View' ) ) { |
|
| 1037 | + } else if ( class_exists( 'GravityView_View' ) ) { |
|
| 1038 | 1038 | $context = GravityView_View::getInstance()->getContext(); |
| 1039 | 1039 | } |
| 1040 | 1040 | |
@@ -1062,12 +1062,12 @@ discard block |
||
| 1062 | 1062 | function gravityview_get_files_array( $value, $gv_class = '' ) { |
| 1063 | 1063 | /** @define "GRAVITYVIEW_DIR" "../" */ |
| 1064 | 1064 | |
| 1065 | - if( !class_exists( 'GravityView_Field' ) ) { |
|
| 1066 | - include_once( GRAVITYVIEW_DIR .'includes/fields/class-gravityview-field.php' ); |
|
| 1065 | + if ( ! class_exists( 'GravityView_Field' ) ) { |
|
| 1066 | + include_once( GRAVITYVIEW_DIR . 'includes/fields/class-gravityview-field.php' ); |
|
| 1067 | 1067 | } |
| 1068 | 1068 | |
| 1069 | - if( !class_exists( 'GravityView_Field_FileUpload' ) ) { |
|
| 1070 | - include_once( GRAVITYVIEW_DIR .'includes/fields/fileupload.php' ); |
|
| 1069 | + if ( ! class_exists( 'GravityView_Field_FileUpload' ) ) { |
|
| 1070 | + include_once( GRAVITYVIEW_DIR . 'includes/fields/fileupload.php' ); |
|
| 1071 | 1071 | } |
| 1072 | 1072 | |
| 1073 | 1073 | return GravityView_Field_FileUpload::get_files_array( $value, $gv_class ); |
@@ -1145,12 +1145,12 @@ discard block |
||
| 1145 | 1145 | $args = apply_filters( 'gravityview/field_output/args', $args, $passed_args ); |
| 1146 | 1146 | |
| 1147 | 1147 | // Required fields. |
| 1148 | - if ( empty( $args['field'] ) || empty( $args['form'] ) ) { |
|
| 1148 | + if ( empty( $args[ 'field' ] ) || empty( $args[ 'form' ] ) ) { |
|
| 1149 | 1149 | do_action( 'gravityview_log_error', '[gravityview_field_output] Field or form are empty.', $args ); |
| 1150 | 1150 | return ''; |
| 1151 | 1151 | } |
| 1152 | 1152 | |
| 1153 | - $entry = empty( $args['entry'] ) ? array() : $args['entry']; |
|
| 1153 | + $entry = empty( $args[ 'entry' ] ) ? array() : $args[ 'entry' ]; |
|
| 1154 | 1154 | |
| 1155 | 1155 | /** |
| 1156 | 1156 | * Create the content variables for replacing. |
@@ -1166,37 +1166,37 @@ discard block |
||
| 1166 | 1166 | 'field_id' => '', |
| 1167 | 1167 | ); |
| 1168 | 1168 | |
| 1169 | - $context['value'] = gv_value( $entry, $args['field'] ); |
|
| 1169 | + $context[ 'value' ] = gv_value( $entry, $args[ 'field' ] ); |
|
| 1170 | 1170 | |
| 1171 | 1171 | // If the value is empty and we're hiding empty, return empty. |
| 1172 | - if ( $context['value'] === '' && ! empty( $args['hide_empty'] ) ) { |
|
| 1172 | + if ( $context[ 'value' ] === '' && ! empty( $args[ 'hide_empty' ] ) ) { |
|
| 1173 | 1173 | return ''; |
| 1174 | 1174 | } |
| 1175 | 1175 | |
| 1176 | - if ( $context['value'] !== '' && ! empty( $args['wpautop'] ) ) { |
|
| 1177 | - $context['value'] = wpautop( $context['value'] ); |
|
| 1176 | + if ( $context[ 'value' ] !== '' && ! empty( $args[ 'wpautop' ] ) ) { |
|
| 1177 | + $context[ 'value' ] = wpautop( $context[ 'value' ] ); |
|
| 1178 | 1178 | } |
| 1179 | 1179 | |
| 1180 | 1180 | // Get width setting, if exists |
| 1181 | - $context['width'] = GravityView_API::field_width( $args['field'] ); |
|
| 1181 | + $context[ 'width' ] = GravityView_API::field_width( $args[ 'field' ] ); |
|
| 1182 | 1182 | |
| 1183 | 1183 | // If replacing with CSS inline formatting, let's do it. |
| 1184 | - $context['width:style'] = GravityView_API::field_width( $args['field'], 'width:' . $context['width'] . '%;' ); |
|
| 1184 | + $context[ 'width:style' ] = GravityView_API::field_width( $args[ 'field' ], 'width:' . $context[ 'width' ] . '%;' ); |
|
| 1185 | 1185 | |
| 1186 | 1186 | // Grab the Class using `gv_class` |
| 1187 | - $context['class'] = gv_class( $args['field'], $args['form'], $entry ); |
|
| 1188 | - $context['field_id'] = GravityView_API::field_html_attr_id( $args['field'], $args['form'], $entry ); |
|
| 1187 | + $context[ 'class' ] = gv_class( $args[ 'field' ], $args[ 'form' ], $entry ); |
|
| 1188 | + $context[ 'field_id' ] = GravityView_API::field_html_attr_id( $args[ 'field' ], $args[ 'form' ], $entry ); |
|
| 1189 | 1189 | |
| 1190 | 1190 | // Get field label if needed |
| 1191 | - if ( ! empty( $args['label_markup'] ) && ! empty( $args['field']['show_label'] ) ) { |
|
| 1192 | - $context['label'] = str_replace( array( '{{label}}', '{{ label }}' ), '<span class="gv-field-label">{{ label_value }}</span>', $args['label_markup'] ); |
|
| 1191 | + if ( ! empty( $args[ 'label_markup' ] ) && ! empty( $args[ 'field' ][ 'show_label' ] ) ) { |
|
| 1192 | + $context[ 'label' ] = str_replace( array( '{{label}}', '{{ label }}' ), '<span class="gv-field-label">{{ label_value }}</span>', $args[ 'label_markup' ] ); |
|
| 1193 | 1193 | } |
| 1194 | 1194 | |
| 1195 | 1195 | // Default Label value |
| 1196 | - $context['label_value'] = gv_label( $args['field'], $entry ); |
|
| 1196 | + $context[ 'label_value' ] = gv_label( $args[ 'field' ], $entry ); |
|
| 1197 | 1197 | |
| 1198 | - if ( empty( $context['label'] ) && ! empty( $context['label_value'] ) ){ |
|
| 1199 | - $context['label'] = '<span class="gv-field-label">{{ label_value }}</span>'; |
|
| 1198 | + if ( empty( $context[ 'label' ] ) && ! empty( $context[ 'label_value' ] ) ) { |
|
| 1199 | + $context[ 'label' ] = '<span class="gv-field-label">{{ label_value }}</span>'; |
|
| 1200 | 1200 | } |
| 1201 | 1201 | |
| 1202 | 1202 | /** |
@@ -1205,7 +1205,7 @@ discard block |
||
| 1205 | 1205 | * @param string $markup The HTML for the markup |
| 1206 | 1206 | * @param array $args All args for the field output |
| 1207 | 1207 | */ |
| 1208 | - $html = apply_filters( 'gravityview/field_output/pre_html', $args['markup'], $args ); |
|
| 1208 | + $html = apply_filters( 'gravityview/field_output/pre_html', $args[ 'markup' ], $args ); |
|
| 1209 | 1209 | |
| 1210 | 1210 | /** |
| 1211 | 1211 | * @filter `gravityview/field_output/open_tag` Modify the opening tags for the template content placeholders |
@@ -1228,7 +1228,7 @@ discard block |
||
| 1228 | 1228 | foreach ( $context as $tag => $value ) { |
| 1229 | 1229 | |
| 1230 | 1230 | // If the tag doesn't exist just skip it |
| 1231 | - if ( false === strpos( $html, $open_tag . $tag . $close_tag ) && false === strpos( $html, $open_tag . ' ' . $tag . ' ' . $close_tag ) ){ |
|
| 1231 | + if ( false === strpos( $html, $open_tag . $tag . $close_tag ) && false === strpos( $html, $open_tag . ' ' . $tag . ' ' . $close_tag ) ) { |
|
| 1232 | 1232 | continue; |
| 1233 | 1233 | } |
| 1234 | 1234 | |
@@ -1,8 +1,8 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | - * Functions that don't require GravityView or Gravity Forms API access but are used in the plugin to extend PHP and WP functions |
|
| 4 | - * @since 1.12 |
|
| 5 | - */ |
|
| 3 | + * Functions that don't require GravityView or Gravity Forms API access but are used in the plugin to extend PHP and WP functions |
|
| 4 | + * @since 1.12 |
|
| 5 | + */ |
|
| 6 | 6 | |
| 7 | 7 | /** |
| 8 | 8 | * Check whether a variable is not an empty string |
@@ -341,7 +341,7 @@ discard block |
||
| 341 | 341 | ! isset( $value ) // If it's not set, it's empty! |
| 342 | 342 | || false === $value |
| 343 | 343 | || null === $value |
| 344 | - || '' === $value // Empty string |
|
| 344 | + || '' === $value // Empty string |
|
| 345 | 345 | || array() === $value // Empty array |
| 346 | 346 | || ( is_object( $value ) && ! get_object_vars( $value ) ) // Empty object |
| 347 | 347 | ) { |
@@ -36,9 +36,9 @@ discard block |
||
| 36 | 36 | |
| 37 | 37 | $parsed_permalink = parse_url( get_permalink( $id ) ); |
| 38 | 38 | |
| 39 | - $permalink_args = isset( $parsed_permalink['query'] ) ? $parsed_permalink['query'] : false; |
|
| 39 | + $permalink_args = isset( $parsed_permalink[ 'query' ] ) ? $parsed_permalink[ 'query' ] : false; |
|
| 40 | 40 | |
| 41 | - if( empty( $permalink_args ) ) { |
|
| 41 | + if ( empty( $permalink_args ) ) { |
|
| 42 | 42 | return array(); |
| 43 | 43 | } |
| 44 | 44 | |
@@ -63,15 +63,15 @@ discard block |
||
| 63 | 63 | function gv_selected( $value, $current, $echo = true, $type = 'selected' ) { |
| 64 | 64 | |
| 65 | 65 | $output = ''; |
| 66 | - if( is_array( $current ) ) { |
|
| 67 | - if( in_array( $value, $current ) ) { |
|
| 66 | + if ( is_array( $current ) ) { |
|
| 67 | + if ( in_array( $value, $current ) ) { |
|
| 68 | 68 | $output = __checked_selected_helper( true, true, false, $type ); |
| 69 | 69 | } |
| 70 | 70 | } else { |
| 71 | 71 | $output = __checked_selected_helper( $value, $current, false, $type ); |
| 72 | 72 | } |
| 73 | 73 | |
| 74 | - if( $echo ) { |
|
| 74 | + if ( $echo ) { |
|
| 75 | 75 | echo $output; |
| 76 | 76 | } |
| 77 | 77 | |
@@ -79,7 +79,7 @@ discard block |
||
| 79 | 79 | } |
| 80 | 80 | |
| 81 | 81 | |
| 82 | -if( ! function_exists( 'gravityview_sanitize_html_class' ) ) { |
|
| 82 | +if ( ! function_exists( 'gravityview_sanitize_html_class' ) ) { |
|
| 83 | 83 | |
| 84 | 84 | /** |
| 85 | 85 | * sanitize_html_class doesn't handle spaces (multiple classes). We remedy that. |
@@ -125,7 +125,7 @@ discard block |
||
| 125 | 125 | */ |
| 126 | 126 | function gravityview_strip_whitespace( $string ) { |
| 127 | 127 | $string = normalize_whitespace( $string ); |
| 128 | - return preg_replace('/[\r\n\t ]+/', ' ', $string ); |
|
| 128 | + return preg_replace( '/[\r\n\t ]+/', ' ', $string ); |
|
| 129 | 129 | } |
| 130 | 130 | |
| 131 | 131 | /** |
@@ -139,7 +139,7 @@ discard block |
||
| 139 | 139 | * @return string Included file contents |
| 140 | 140 | */ |
| 141 | 141 | function gravityview_ob_include( $file_path, $object = NULL ) { |
| 142 | - if( ! file_exists( $file_path ) ) { |
|
| 142 | + if ( ! file_exists( $file_path ) ) { |
|
| 143 | 143 | do_action( 'gravityview_log_error', __FUNCTION__ . ': File path does not exist. ', $file_path ); |
| 144 | 144 | return ''; |
| 145 | 145 | } |
@@ -155,7 +155,7 @@ discard block |
||
| 155 | 155 | */ |
| 156 | 156 | function gravityview_get_floaty() { |
| 157 | 157 | |
| 158 | - if( function_exists('is_rtl') && is_rtl() ) { |
|
| 158 | + if ( function_exists( 'is_rtl' ) && is_rtl() ) { |
|
| 159 | 159 | $style = 'margin:10px 10px 10px 0;'; |
| 160 | 160 | $class = 'alignright'; |
| 161 | 161 | } else { |
@@ -163,7 +163,7 @@ discard block |
||
| 163 | 163 | $class = 'alignleft'; |
| 164 | 164 | } |
| 165 | 165 | |
| 166 | - return '<img src="'.plugins_url( 'assets/images/astronaut-200x263.png', GRAVITYVIEW_FILE ).'" class="'.$class.'" height="87" width="66" alt="The GravityView Astronaut Says:" style="'.$style.'" />'; |
|
| 166 | + return '<img src="' . plugins_url( 'assets/images/astronaut-200x263.png', GRAVITYVIEW_FILE ) . '" class="' . $class . '" height="87" width="66" alt="The GravityView Astronaut Says:" style="' . $style . '" />'; |
|
| 167 | 167 | } |
| 168 | 168 | |
| 169 | 169 | /** |
@@ -186,9 +186,9 @@ discard block |
||
| 186 | 186 | function gravityview_number_format( $number, $decimals = '' ) { |
| 187 | 187 | global $wp_locale; |
| 188 | 188 | |
| 189 | - if( '' === $decimals ) { |
|
| 189 | + if ( '' === $decimals ) { |
|
| 190 | 190 | |
| 191 | - $decimal_point = isset( $wp_locale ) ? $wp_locale->number_format['decimal_point'] : '.'; |
|
| 191 | + $decimal_point = isset( $wp_locale ) ? $wp_locale->number_format[ 'decimal_point' ] : '.'; |
|
| 192 | 192 | |
| 193 | 193 | /** |
| 194 | 194 | * Calculate the position of the decimal point in the number |
@@ -217,7 +217,7 @@ discard block |
||
| 217 | 217 | $parts = parse_url( $value ); |
| 218 | 218 | |
| 219 | 219 | // No domain? Strange...show the original text. |
| 220 | - if( empty( $parts['host'] ) ) { |
|
| 220 | + if ( empty( $parts[ 'host' ] ) ) { |
|
| 221 | 221 | return $value; |
| 222 | 222 | } |
| 223 | 223 | |
@@ -230,16 +230,16 @@ discard block |
||
| 230 | 230 | * @param boolean $enable Whether to strip the scheme. Return false to show scheme. (default: true)\n |
| 231 | 231 | * If true: `http://example.com => example.com` |
| 232 | 232 | */ |
| 233 | - if( false === apply_filters('gravityview_anchor_text_striphttp', true) ) { |
|
| 233 | + if ( false === apply_filters( 'gravityview_anchor_text_striphttp', true ) ) { |
|
| 234 | 234 | |
| 235 | - if( isset( $parts['scheme'] ) ) { |
|
| 236 | - $return .= $parts['scheme']; |
|
| 235 | + if ( isset( $parts[ 'scheme' ] ) ) { |
|
| 236 | + $return .= $parts[ 'scheme' ]; |
|
| 237 | 237 | } |
| 238 | 238 | |
| 239 | 239 | } |
| 240 | 240 | |
| 241 | 241 | // The domain, which may contain a subdomain |
| 242 | - $domain = $parts['host']; |
|
| 242 | + $domain = $parts[ 'host' ]; |
|
| 243 | 243 | |
| 244 | 244 | /** |
| 245 | 245 | * @filter `gravityview_anchor_text_stripwww` Strip www from the domain? |
@@ -247,10 +247,10 @@ discard block |
||
| 247 | 247 | * @param boolean $enable Whether to strip www. Return false to show www. (default: true)\n |
| 248 | 248 | * If true: `www.example.com => example.com` |
| 249 | 249 | */ |
| 250 | - $strip_www = apply_filters('gravityview_anchor_text_stripwww', true ); |
|
| 250 | + $strip_www = apply_filters( 'gravityview_anchor_text_stripwww', true ); |
|
| 251 | 251 | |
| 252 | - if( $strip_www ) { |
|
| 253 | - $domain = str_replace('www.', '', $domain ); |
|
| 252 | + if ( $strip_www ) { |
|
| 253 | + $domain = str_replace( 'www.', '', $domain ); |
|
| 254 | 254 | } |
| 255 | 255 | |
| 256 | 256 | /** |
@@ -260,11 +260,11 @@ discard block |
||
| 260 | 260 | * If true: `http://demo.example.com => example.com` \n |
| 261 | 261 | * If false: `http://demo.example.com => demo.example.com` |
| 262 | 262 | */ |
| 263 | - $strip_subdomains = apply_filters('gravityview_anchor_text_nosubdomain', true); |
|
| 263 | + $strip_subdomains = apply_filters( 'gravityview_anchor_text_nosubdomain', true ); |
|
| 264 | 264 | |
| 265 | - if( $strip_subdomains ) { |
|
| 265 | + if ( $strip_subdomains ) { |
|
| 266 | 266 | |
| 267 | - $domain = _gravityview_strip_subdomain( $parts['host'] ); |
|
| 267 | + $domain = _gravityview_strip_subdomain( $parts[ 'host' ] ); |
|
| 268 | 268 | |
| 269 | 269 | } |
| 270 | 270 | |
@@ -278,12 +278,12 @@ discard block |
||
| 278 | 278 | * If true: `http://example.com/sub/directory/page.html => example.com` \n |
| 279 | 279 | * If false: `http://example.com/sub/directory/page.html => example.com/sub/directory/page.html` |
| 280 | 280 | */ |
| 281 | - $root_only = apply_filters('gravityview_anchor_text_rootonly', true); |
|
| 281 | + $root_only = apply_filters( 'gravityview_anchor_text_rootonly', true ); |
|
| 282 | 282 | |
| 283 | - if( empty( $root_only ) ) { |
|
| 283 | + if ( empty( $root_only ) ) { |
|
| 284 | 284 | |
| 285 | - if( isset( $parts['path'] ) ) { |
|
| 286 | - $return .= $parts['path']; |
|
| 285 | + if ( isset( $parts[ 'path' ] ) ) { |
|
| 286 | + $return .= $parts[ 'path' ]; |
|
| 287 | 287 | } |
| 288 | 288 | } |
| 289 | 289 | |
@@ -293,12 +293,12 @@ discard block |
||
| 293 | 293 | * @param boolean $enable Whether to enable "root only". Return false to show full path. (default: true)\n |
| 294 | 294 | * If true: `http://example.com/?query=example => example.com` |
| 295 | 295 | */ |
| 296 | - $strip_query_string = apply_filters('gravityview_anchor_text_noquerystring', true ); |
|
| 296 | + $strip_query_string = apply_filters( 'gravityview_anchor_text_noquerystring', true ); |
|
| 297 | 297 | |
| 298 | - if( empty( $strip_query_string ) ) { |
|
| 298 | + if ( empty( $strip_query_string ) ) { |
|
| 299 | 299 | |
| 300 | - if( isset( $parts['query'] ) ) { |
|
| 301 | - $return .= '?'.$parts['query']; |
|
| 300 | + if ( isset( $parts[ 'query' ] ) ) { |
|
| 301 | + $return .= '?' . $parts[ 'query' ]; |
|
| 302 | 302 | } |
| 303 | 303 | |
| 304 | 304 | } |
@@ -315,8 +315,8 @@ discard block |
||
| 315 | 315 | */ |
| 316 | 316 | function _gravityview_strip_subdomain( $string_maybe_has_subdomain ) { |
| 317 | 317 | |
| 318 | - if( preg_match("/(?P<domain>[a-z0-9][a-z0-9\-]{1,63}\.(?:com\.|co\.|net\.|org\.|firm\.|me\.|school\.|law\.|gov\.|mod\.|msk\.|irkutsks\.|sa\.|act\.|police\.|plc\.|ac\.|tm\.|asso\.|biz\.|pro\.|cg\.|telememo\.)?[a-z\.]{2,6})$/i", $string_maybe_has_subdomain, $matches ) ) { |
|
| 319 | - return $matches['domain']; |
|
| 318 | + if ( preg_match( "/(?P<domain>[a-z0-9][a-z0-9\-]{1,63}\.(?:com\.|co\.|net\.|org\.|firm\.|me\.|school\.|law\.|gov\.|mod\.|msk\.|irkutsks\.|sa\.|act\.|police\.|plc\.|ac\.|tm\.|asso\.|biz\.|pro\.|cg\.|telememo\.)?[a-z\.]{2,6})$/i", $string_maybe_has_subdomain, $matches ) ) { |
|
| 319 | + return $matches[ 'domain' ]; |
|
| 320 | 320 | } else { |
| 321 | 321 | return $string_maybe_has_subdomain; |
| 322 | 322 | } |
@@ -337,7 +337,7 @@ discard block |
||
| 337 | 337 | */ |
| 338 | 338 | function gv_empty( $value, $zero_is_empty = true, $allow_string_booleans = true ) { |
| 339 | 339 | |
| 340 | - if( |
|
| 340 | + if ( |
|
| 341 | 341 | ! isset( $value ) // If it's not set, it's empty! |
| 342 | 342 | || false === $value |
| 343 | 343 | || null === $value |
@@ -348,20 +348,20 @@ discard block |
||
| 348 | 348 | return true; |
| 349 | 349 | } |
| 350 | 350 | |
| 351 | - if( is_string( $value ) && $allow_string_booleans ) { |
|
| 351 | + if ( is_string( $value ) && $allow_string_booleans ) { |
|
| 352 | 352 | |
| 353 | 353 | $value = trim( $value ); |
| 354 | 354 | $value = strtolower( $value ); |
| 355 | 355 | |
| 356 | 356 | if ( in_array( $value, array( 'yes', 'true' ), true ) ) { |
| 357 | 357 | $value = true; |
| 358 | - } else if( in_array( $value, array( 'no', 'false' ), true ) ) { |
|
| 358 | + } else if ( in_array( $value, array( 'no', 'false' ), true ) ) { |
|
| 359 | 359 | $value = false; |
| 360 | 360 | } |
| 361 | 361 | } |
| 362 | 362 | |
| 363 | 363 | // If zero isn't empty, then if $value is a number and it's empty, it's zero. Thus, return false. |
| 364 | - if( ! $zero_is_empty && is_numeric( $value ) && empty( $value ) ) { |
|
| 364 | + if ( ! $zero_is_empty && is_numeric( $value ) && empty( $value ) ) { |
|
| 365 | 365 | return false; |
| 366 | 366 | } |
| 367 | 367 | |
@@ -383,7 +383,7 @@ discard block |
||
| 383 | 383 | function gv_map_deep( $value, $callback ) { |
| 384 | 384 | |
| 385 | 385 | // Use the original function, if exists. |
| 386 | - if( function_exists( 'map_deep') ) { |
|
| 386 | + if ( function_exists( 'map_deep' ) ) { |
|
| 387 | 387 | return map_deep( $value, $callback ); |
| 388 | 388 | } |
| 389 | 389 | |
@@ -448,7 +448,7 @@ discard block |
||
| 448 | 448 | |
| 449 | 449 | $exploded = explode( '.', "{$field_id}" ); |
| 450 | 450 | |
| 451 | - return isset( $exploded[1] ) ? intval( $exploded[1] ) : 0; |
|
| 451 | + return isset( $exploded[ 1 ] ) ? intval( $exploded[ 1 ] ) : 0; |
|
| 452 | 452 | } |
| 453 | 453 | |
| 454 | 454 | /** |
@@ -489,13 +489,13 @@ discard block |
||
| 489 | 489 | */ |
| 490 | 490 | $args = apply_filters( 'gravityview_get_terms_choices_args', $args ); |
| 491 | 491 | |
| 492 | - $terms = get_terms( $args['taxonomy'], $args ); |
|
| 492 | + $terms = get_terms( $args[ 'taxonomy' ], $args ); |
|
| 493 | 493 | |
| 494 | 494 | $choices = array(); |
| 495 | 495 | |
| 496 | 496 | if ( is_array( $terms ) ) { |
| 497 | 497 | foreach ( $terms as $term_id => $term_name ) { |
| 498 | - $choices[] = array( |
|
| 498 | + $choices[ ] = array( |
|
| 499 | 499 | 'text' => $term_name, |
| 500 | 500 | 'value' => $term_id |
| 501 | 501 | ); |
@@ -519,21 +519,21 @@ discard block |
||
| 519 | 519 | function _gravityview_process_posted_fields() { |
| 520 | 520 | $fields = array(); |
| 521 | 521 | |
| 522 | - if( !empty( $_POST['fields'] ) ) { |
|
| 523 | - if ( ! is_array( $_POST['fields'] ) ) { |
|
| 522 | + if ( ! empty( $_POST[ 'fields' ] ) ) { |
|
| 523 | + if ( ! is_array( $_POST[ 'fields' ] ) ) { |
|
| 524 | 524 | |
| 525 | 525 | // We are not using parse_str() due to max_input_vars limitation with large View configurations |
| 526 | 526 | $fields_holder = array(); |
| 527 | - GVCommon::gv_parse_str( $_POST['fields'], $fields_holder ); |
|
| 527 | + GVCommon::gv_parse_str( $_POST[ 'fields' ], $fields_holder ); |
|
| 528 | 528 | |
| 529 | - if ( isset( $fields_holder['fields'] ) ) { |
|
| 530 | - $fields = $fields_holder['fields']; |
|
| 529 | + if ( isset( $fields_holder[ 'fields' ] ) ) { |
|
| 530 | + $fields = $fields_holder[ 'fields' ]; |
|
| 531 | 531 | } else { |
| 532 | 532 | do_action( 'gravityview_log_error', '[save_postdata] No `fields` key was found after parsing $fields string', $fields_holder ); |
| 533 | 533 | } |
| 534 | 534 | |
| 535 | 535 | } else { |
| 536 | - $fields = $_POST['fields']; |
|
| 536 | + $fields = $_POST[ 'fields' ]; |
|
| 537 | 537 | } |
| 538 | 538 | } |
| 539 | 539 | |
@@ -289,8 +289,8 @@ discard block |
||
| 289 | 289 | * @param mixed $field_id Field ID or Field array |
| 290 | 290 | * @return string field type |
| 291 | 291 | */ |
| 292 | -function gravityview_get_field_type( $form = null , $field_id = '' ) { |
|
| 293 | - return GVCommon::get_field_type( $form, $field_id ); |
|
| 292 | +function gravityview_get_field_type( $form = null, $field_id = '' ) { |
|
| 293 | + return GVCommon::get_field_type( $form, $field_id ); |
|
| 294 | 294 | } |
| 295 | 295 | |
| 296 | 296 | |
@@ -303,8 +303,8 @@ discard block |
||
| 303 | 303 | * @return string HTML of the output. Empty string if $view_id is empty. |
| 304 | 304 | */ |
| 305 | 305 | function get_gravityview( $view_id = '', $atts = array() ) { |
| 306 | - if( !empty( $view_id ) ) { |
|
| 307 | - $atts['id'] = $view_id; |
|
| 306 | + if ( ! empty( $view_id ) ) { |
|
| 307 | + $atts[ 'id' ] = $view_id; |
|
| 308 | 308 | $args = wp_parse_args( $atts, GravityView_View_Data::get_default_args() ); |
| 309 | 309 | $GravityView_frontend = GravityView_frontend::getInstance(); |
| 310 | 310 | $GravityView_frontend->setGvOutputData( GravityView_View_Data::getInstance( $view_id ) ); |
@@ -347,19 +347,19 @@ discard block |
||
| 347 | 347 | */ |
| 348 | 348 | function gravityview_view_has_single_checkbox_or_radio( $form, $view_fields ) { |
| 349 | 349 | |
| 350 | - if( $form_fields = GFFormsModel::get_fields_by_type( $form, array( 'checkbox', 'radio' ) ) ) { |
|
| 350 | + if ( $form_fields = GFFormsModel::get_fields_by_type( $form, array( 'checkbox', 'radio' ) ) ) { |
|
| 351 | 351 | |
| 352 | 352 | /** @var GF_Field_Radio|GF_Field_Checkbox $form_field */ |
| 353 | - foreach( $form_fields as $form_field ) { |
|
| 353 | + foreach ( $form_fields as $form_field ) { |
|
| 354 | 354 | $field_id = $form_field->id; |
| 355 | - foreach( $view_fields as $zone ) { |
|
| 355 | + foreach ( $view_fields as $zone ) { |
|
| 356 | 356 | |
| 357 | 357 | // ACF compatibility; ACF-added fields aren't arrays |
| 358 | 358 | if ( ! is_array( $zone ) ) { continue; } |
| 359 | 359 | |
| 360 | - foreach( $zone as $field ) { |
|
| 360 | + foreach ( $zone as $field ) { |
|
| 361 | 361 | // If it's an input, not the parent and the parent ID matches a checkbox or radio |
| 362 | - if( ( strpos( $field['id'], '.' ) > 0 ) && floor( $field['id'] ) === floor( $field_id ) ) { |
|
| 362 | + if ( ( strpos( $field[ 'id' ], '.' ) > 0 ) && floor( $field[ 'id' ] ) === floor( $field_id ) ) { |
|
| 363 | 363 | return true; |
| 364 | 364 | } |
| 365 | 365 | } |
@@ -41,9 +41,9 @@ |
||
| 41 | 41 | * @return void |
| 42 | 42 | */ |
| 43 | 43 | private function fix_posted_fields() { |
| 44 | - if( is_admin() && isset( $_POST['action'] ) && isset( $_POST['post_type'] ) ) { |
|
| 45 | - if( 'editpost' === $_POST['action'] && 'gravityview' === $_POST['post_type'] ) { |
|
| 46 | - $_POST['fields'] = _gravityview_process_posted_fields(); |
|
| 44 | + if ( is_admin() && isset( $_POST[ 'action' ] ) && isset( $_POST[ 'post_type' ] ) ) { |
|
| 45 | + if ( 'editpost' === $_POST[ 'action' ] && 'gravityview' === $_POST[ 'post_type' ] ) { |
|
| 46 | + $_POST[ 'fields' ] = _gravityview_process_posted_fields(); |
|
| 47 | 47 | } |
| 48 | 48 | } |
| 49 | 49 | } |
@@ -1,6 +1,6 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -if( ! class_exists('GFAddOn') ) { |
|
| 3 | +if ( ! class_exists( 'GFAddOn' ) ) { |
|
| 4 | 4 | return; |
| 5 | 5 | } |
| 6 | 6 | |
@@ -75,7 +75,7 @@ discard block |
||
| 75 | 75 | */ |
| 76 | 76 | public function __construct( $prevent_multiple_instances = '' ) { |
| 77 | 77 | |
| 78 | - if( $prevent_multiple_instances === 'get_instance' ) { |
|
| 78 | + if ( $prevent_multiple_instances === 'get_instance' ) { |
|
| 79 | 79 | return parent::__construct(); |
| 80 | 80 | } |
| 81 | 81 | |
@@ -87,7 +87,7 @@ discard block |
||
| 87 | 87 | */ |
| 88 | 88 | public static function get_instance() { |
| 89 | 89 | |
| 90 | - if( empty( self::$instance ) ) { |
|
| 90 | + if ( empty( self::$instance ) ) { |
|
| 91 | 91 | self::$instance = new self( 'get_instance' ); |
| 92 | 92 | } |
| 93 | 93 | |
@@ -110,11 +110,11 @@ discard block |
||
| 110 | 110 | * Prevent Gravity Forms from showing the uninstall tab on the settings page |
| 111 | 111 | * @hack |
| 112 | 112 | */ |
| 113 | - if( $caps === $this->_capabilities_uninstall ) { |
|
| 113 | + if ( $caps === $this->_capabilities_uninstall ) { |
|
| 114 | 114 | return false; |
| 115 | 115 | } |
| 116 | 116 | |
| 117 | - if( empty( $caps ) ) { |
|
| 117 | + if ( empty( $caps ) ) { |
|
| 118 | 118 | $caps = array( 'gravityview_full_access' ); |
| 119 | 119 | } |
| 120 | 120 | |
@@ -137,7 +137,7 @@ discard block |
||
| 137 | 137 | add_filter( 'gform_addon_app_settings_menu_gravityview', array( $this, 'modify_app_settings_menu_title' ) ); |
| 138 | 138 | |
| 139 | 139 | /** @since 1.7.6 */ |
| 140 | - add_action('network_admin_menu', array( $this, 'add_network_menu' ) ); |
|
| 140 | + add_action( 'network_admin_menu', array( $this, 'add_network_menu' ) ); |
|
| 141 | 141 | |
| 142 | 142 | parent::init_admin(); |
| 143 | 143 | } |
@@ -151,7 +151,7 @@ discard block |
||
| 151 | 151 | */ |
| 152 | 152 | public function modify_app_settings_menu_title( $setting_tabs ) { |
| 153 | 153 | |
| 154 | - $setting_tabs[0]['label'] = __( 'GravityView Settings', 'gravityview'); |
|
| 154 | + $setting_tabs[ 0 ][ 'label' ] = __( 'GravityView Settings', 'gravityview' ); |
|
| 155 | 155 | |
| 156 | 156 | return $setting_tabs; |
| 157 | 157 | } |
@@ -168,11 +168,11 @@ discard block |
||
| 168 | 168 | */ |
| 169 | 169 | private function _load_license_handler() { |
| 170 | 170 | |
| 171 | - if( !empty( $this->License_Handler ) ) { |
|
| 171 | + if ( ! empty( $this->License_Handler ) ) { |
|
| 172 | 172 | return; |
| 173 | 173 | } |
| 174 | 174 | |
| 175 | - require_once( GRAVITYVIEW_DIR . 'includes/class-gv-license-handler.php'); |
|
| 175 | + require_once( GRAVITYVIEW_DIR . 'includes/class-gv-license-handler.php' ); |
|
| 176 | 176 | |
| 177 | 177 | $this->License_Handler = GV_License_Handler::get_instance( $this ); |
| 178 | 178 | } |
@@ -184,60 +184,60 @@ discard block |
||
| 184 | 184 | function license_key_notice() { |
| 185 | 185 | |
| 186 | 186 | // Only show on GravityView pages |
| 187 | - if( ! gravityview_is_admin_page() ) { |
|
| 187 | + if ( ! gravityview_is_admin_page() ) { |
|
| 188 | 188 | return; |
| 189 | 189 | } |
| 190 | 190 | |
| 191 | - $license_status = self::getSetting('license_key_status'); |
|
| 192 | - $license_id = self::getSetting('license_key'); |
|
| 191 | + $license_status = self::getSetting( 'license_key_status' ); |
|
| 192 | + $license_id = self::getSetting( 'license_key' ); |
|
| 193 | 193 | $license_id = empty( $license_id ) ? 'license' : $license_id; |
| 194 | 194 | |
| 195 | - $message = esc_html__('Your GravityView license %s. This means you’re missing out on updates and support! %sActivate your license%s or %sget a license here%s.', 'gravityview'); |
|
| 195 | + $message = esc_html__( 'Your GravityView license %s. This means you’re missing out on updates and support! %sActivate your license%s or %sget a license here%s.', 'gravityview' ); |
|
| 196 | 196 | |
| 197 | 197 | /** |
| 198 | 198 | * I wanted to remove the period from after the buttons in the string, |
| 199 | 199 | * but didn't want to mess up the translation strings for the translators. |
| 200 | 200 | */ |
| 201 | 201 | $message = mb_substr( $message, 0, mb_strlen( $message ) - 1 ); |
| 202 | - $title = __('Inactive License', 'gravityview'); |
|
| 202 | + $title = __( 'Inactive License', 'gravityview' ); |
|
| 203 | 203 | $status = ''; |
| 204 | 204 | $update_below = false; |
| 205 | 205 | $primary_button_link = admin_url( 'edit.php?post_type=gravityview&page=gravityview_settings' ); |
| 206 | 206 | switch ( $license_status ) { |
| 207 | 207 | case 'invalid': |
| 208 | - $title = __('Invalid License', 'gravityview'); |
|
| 209 | - $status = __('is invalid', 'gravityview'); |
|
| 208 | + $title = __( 'Invalid License', 'gravityview' ); |
|
| 209 | + $status = __( 'is invalid', 'gravityview' ); |
|
| 210 | 210 | break; |
| 211 | 211 | case 'deactivated': |
| 212 | - $status = __('is inactive', 'gravityview'); |
|
| 213 | - $update_below = __('Activate your license key below.', 'gravityview'); |
|
| 212 | + $status = __( 'is inactive', 'gravityview' ); |
|
| 213 | + $update_below = __( 'Activate your license key below.', 'gravityview' ); |
|
| 214 | 214 | break; |
| 215 | 215 | /** @noinspection PhpMissingBreakStatementInspection */ |
| 216 | 216 | case '': |
| 217 | 217 | $license_status = 'site_inactive'; |
| 218 | 218 | // break intentionally left blank |
| 219 | 219 | case 'site_inactive': |
| 220 | - $status = __('has not been activated', 'gravityview'); |
|
| 221 | - $update_below = __('Activate your license key below.', 'gravityview'); |
|
| 220 | + $status = __( 'has not been activated', 'gravityview' ); |
|
| 221 | + $update_below = __( 'Activate your license key below.', 'gravityview' ); |
|
| 222 | 222 | break; |
| 223 | 223 | } |
| 224 | - $url = 'https://gravityview.co/pricing/?utm_source=admin_notice&utm_medium=admin&utm_content='.$license_status.'&utm_campaign=Admin%20Notice'; |
|
| 224 | + $url = 'https://gravityview.co/pricing/?utm_source=admin_notice&utm_medium=admin&utm_content=' . $license_status . '&utm_campaign=Admin%20Notice'; |
|
| 225 | 225 | |
| 226 | 226 | // Show a different notice on settings page for inactive licenses (hide the buttons) |
| 227 | - if( $update_below && gravityview_is_admin_page( '', 'settings' ) ) { |
|
| 227 | + if ( $update_below && gravityview_is_admin_page( '', 'settings' ) ) { |
|
| 228 | 228 | $message = sprintf( $message, $status, '<div class="hidden">', '', '', '</div><a href="#" onclick="jQuery(\'#license_key\').focus(); return false;">' . $update_below . '</a>' ); |
| 229 | 229 | } else { |
| 230 | 230 | $message = sprintf( $message, $status, "\n\n" . '<a href="' . $primary_button_link . '" class="button button-primary">', '</a>', '<a href="' . esc_url( $url ) . '" class="button button-secondary">', '</a>' ); |
| 231 | 231 | } |
| 232 | 232 | |
| 233 | - if( !empty( $status ) ) { |
|
| 233 | + if ( ! empty( $status ) ) { |
|
| 234 | 234 | GravityView_Admin_Notices::add_notice( array( |
| 235 | 235 | 'message' => $message, |
| 236 | 236 | 'class' => 'updated', |
| 237 | 237 | 'title' => $title, |
| 238 | 238 | 'cap' => 'gravityview_edit_settings', |
| 239 | - 'dismiss' => sha1( $license_status.'_'.$license_id ), |
|
| 240 | - )); |
|
| 239 | + 'dismiss' => sha1( $license_status . '_' . $license_id ), |
|
| 240 | + ) ); |
|
| 241 | 241 | } |
| 242 | 242 | } |
| 243 | 243 | |
@@ -249,7 +249,7 @@ discard block |
||
| 249 | 249 | |
| 250 | 250 | $styles = parent::styles(); |
| 251 | 251 | |
| 252 | - $styles[] = array( |
|
| 252 | + $styles[ ] = array( |
|
| 253 | 253 | 'handle' => 'gravityview_settings', |
| 254 | 254 | 'src' => plugins_url( 'assets/css/admin-settings.css', GRAVITYVIEW_FILE ), |
| 255 | 255 | 'version' => GravityView_Plugin::version, |
@@ -272,7 +272,7 @@ discard block |
||
| 272 | 272 | * @return void |
| 273 | 273 | */ |
| 274 | 274 | public function add_network_menu() { |
| 275 | - if( GravityView_Plugin::is_network_activated() ) { |
|
| 275 | + if ( GravityView_Plugin::is_network_activated() ) { |
|
| 276 | 276 | add_menu_page( __( 'Settings', 'gravityview' ), __( 'GravityView', 'gravityview' ), $this->_capabilities_app_settings, "{$this->_slug}_settings", array( $this, 'app_tab_page' ), 'none' ); |
| 277 | 277 | } |
| 278 | 278 | } |
@@ -289,7 +289,7 @@ discard block |
||
| 289 | 289 | * If multisite and not network admin, we don't want the settings to show. |
| 290 | 290 | * @since 1.7.6 |
| 291 | 291 | */ |
| 292 | - $show_submenu = !is_multisite() || is_main_site() || !GravityView_Plugin::is_network_activated() || ( is_network_admin() && GravityView_Plugin::is_network_activated() ); |
|
| 292 | + $show_submenu = ! is_multisite() || is_main_site() || ! GravityView_Plugin::is_network_activated() || ( is_network_admin() && GravityView_Plugin::is_network_activated() ); |
|
| 293 | 293 | |
| 294 | 294 | /** |
| 295 | 295 | * Override whether to show the Settings menu on a per-blog basis. |
@@ -298,7 +298,7 @@ discard block |
||
| 298 | 298 | */ |
| 299 | 299 | $show_submenu = apply_filters( 'gravityview/show-settings-menu', $show_submenu ); |
| 300 | 300 | |
| 301 | - if( $show_submenu ) { |
|
| 301 | + if ( $show_submenu ) { |
|
| 302 | 302 | add_submenu_page( 'edit.php?post_type=gravityview', __( 'Settings', 'gravityview' ), __( 'Settings', 'gravityview' ), $this->_capabilities_app_settings, $this->_slug . '_settings', array( $this, 'app_tab_page' ) ); |
| 303 | 303 | } |
| 304 | 304 | } |
@@ -329,7 +329,7 @@ discard block |
||
| 329 | 329 | /** |
| 330 | 330 | * Backward compatibility with Redux |
| 331 | 331 | */ |
| 332 | - if( $setting_name === 'license' ) { |
|
| 332 | + if ( $setting_name === 'license' ) { |
|
| 333 | 333 | return array( |
| 334 | 334 | 'license' => parent::get_app_setting( 'license_key' ), |
| 335 | 335 | 'status' => parent::get_app_setting( 'license_key_status' ), |
@@ -393,7 +393,7 @@ discard block |
||
| 393 | 393 | |
| 394 | 394 | $return = $text . $activation; |
| 395 | 395 | |
| 396 | - if( $echo ) { |
|
| 396 | + if ( $echo ) { |
|
| 397 | 397 | echo $return; |
| 398 | 398 | } |
| 399 | 399 | |
@@ -420,15 +420,15 @@ discard block |
||
| 420 | 420 | */ |
| 421 | 421 | public function settings_submit( $field, $echo = true ) { |
| 422 | 422 | |
| 423 | - $field['type'] = ( isset($field['type']) && in_array( $field['type'], array('submit','reset','button') ) ) ? $field['type'] : 'submit'; |
|
| 423 | + $field[ 'type' ] = ( isset( $field[ 'type' ] ) && in_array( $field[ 'type' ], array( 'submit', 'reset', 'button' ) ) ) ? $field[ 'type' ] : 'submit'; |
|
| 424 | 424 | |
| 425 | 425 | $attributes = $this->get_field_attributes( $field ); |
| 426 | 426 | $default_value = rgar( $field, 'value' ) ? rgar( $field, 'value' ) : rgar( $field, 'default_value' ); |
| 427 | - $value = $this->get_setting( $field['name'], $default_value ); |
|
| 427 | + $value = $this->get_setting( $field[ 'name' ], $default_value ); |
|
| 428 | 428 | |
| 429 | 429 | |
| 430 | - $attributes['class'] = isset( $attributes['class'] ) ? esc_attr( $attributes['class'] ) : 'button-primary gfbutton'; |
|
| 431 | - $name = ( $field['name'] === 'gform-settings-save' ) ? $field['name'] : '_gaddon_setting_'.$field['name']; |
|
| 430 | + $attributes[ 'class' ] = isset( $attributes[ 'class' ] ) ? esc_attr( $attributes[ 'class' ] ) : 'button-primary gfbutton'; |
|
| 431 | + $name = ( $field[ 'name' ] === 'gform-settings-save' ) ? $field[ 'name' ] : '_gaddon_setting_' . $field[ 'name' ]; |
|
| 432 | 432 | |
| 433 | 433 | if ( empty( $value ) ) { |
| 434 | 434 | $value = __( 'Update Settings', 'gravityview' ); |
@@ -437,7 +437,7 @@ discard block |
||
| 437 | 437 | $attributes = $this->get_field_attributes( $field ); |
| 438 | 438 | |
| 439 | 439 | $html = '<input |
| 440 | - type="' . $field['type'] . '" |
|
| 440 | + type="' . $field[ 'type' ] . '" |
|
| 441 | 441 | name="' . esc_attr( $name ) . '" |
| 442 | 442 | value="' . $value . '" ' . |
| 443 | 443 | implode( ' ', $attributes ) . |
@@ -459,16 +459,16 @@ discard block |
||
| 459 | 459 | * @return string |
| 460 | 460 | */ |
| 461 | 461 | public function settings_save( $field, $echo = true ) { |
| 462 | - $field['type'] = 'submit'; |
|
| 463 | - $field['name'] = 'gform-settings-save'; |
|
| 464 | - $field['class'] = isset( $field['class'] ) ? $field['class'] : 'button-primary gfbutton'; |
|
| 462 | + $field[ 'type' ] = 'submit'; |
|
| 463 | + $field[ 'name' ] = 'gform-settings-save'; |
|
| 464 | + $field[ 'class' ] = isset( $field[ 'class' ] ) ? $field[ 'class' ] : 'button-primary gfbutton'; |
|
| 465 | 465 | |
| 466 | 466 | if ( ! rgar( $field, 'value' ) ) |
| 467 | - $field['value'] = __( 'Update Settings', 'gravityview' ); |
|
| 467 | + $field[ 'value' ] = __( 'Update Settings', 'gravityview' ); |
|
| 468 | 468 | |
| 469 | 469 | $output = $this->settings_submit( $field, false ); |
| 470 | 470 | |
| 471 | - if( $echo ) { |
|
| 471 | + if ( $echo ) { |
|
| 472 | 472 | echo $output; |
| 473 | 473 | } |
| 474 | 474 | |
@@ -485,8 +485,8 @@ discard block |
||
| 485 | 485 | parent::single_setting_label( $field ); |
| 486 | 486 | |
| 487 | 487 | // Added by GravityView |
| 488 | - if ( isset( $field['description'] ) ) { |
|
| 489 | - echo '<span class="description">'. $field['description'] .'</span>'; |
|
| 488 | + if ( isset( $field[ 'description' ] ) ) { |
|
| 489 | + echo '<span class="description">' . $field[ 'description' ] . '</span>'; |
|
| 490 | 490 | } |
| 491 | 491 | |
| 492 | 492 | } |
@@ -548,11 +548,11 @@ discard block |
||
| 548 | 548 | |
| 549 | 549 | // If the posted key doesn't match the activated/deactivated key (set using the Activate License button, AJAX response), |
| 550 | 550 | // then we assume it's changed. If it's changed, unset the status and the previous response. |
| 551 | - if( $local_key !== $response_key ) { |
|
| 551 | + if ( $local_key !== $response_key ) { |
|
| 552 | 552 | |
| 553 | - unset( $posted_settings['license_key_response'] ); |
|
| 554 | - unset( $posted_settings['license_key_status'] ); |
|
| 555 | - GFCommon::add_error_message( __('The license key you entered has been saved, but not activated. Please activate the license.', 'gravityview' ) ); |
|
| 553 | + unset( $posted_settings[ 'license_key_response' ] ); |
|
| 554 | + unset( $posted_settings[ 'license_key_status' ] ); |
|
| 555 | + GFCommon::add_error_message( __( 'The license key you entered has been saved, but not activated. Please activate the license.', 'gravityview' ) ); |
|
| 556 | 556 | } |
| 557 | 557 | |
| 558 | 558 | return $posted_settings; |
@@ -587,25 +587,25 @@ discard block |
||
| 587 | 587 | 'label' => __( 'License Key', 'gravityview' ), |
| 588 | 588 | 'description' => __( 'Enter the license key that was sent to you on purchase. This enables plugin updates & support.', 'gravityview' ), |
| 589 | 589 | 'type' => 'edd_license', |
| 590 | - 'data-pending-text' => __('Verifying license…', 'gravityview'), |
|
| 591 | - 'default_value' => $default_settings['license_key'], |
|
| 590 | + 'data-pending-text' => __( 'Verifying license…', 'gravityview' ), |
|
| 591 | + 'default_value' => $default_settings[ 'license_key' ], |
|
| 592 | 592 | 'class' => ( '' == $this->get_app_setting( 'license_key' ) ) ? 'activate code regular-text edd-license-key' : 'deactivate code regular-text edd-license-key', |
| 593 | 593 | ), |
| 594 | 594 | array( |
| 595 | 595 | 'name' => 'license_key_response', |
| 596 | - 'default_value' => $default_settings['license_key_response'], |
|
| 596 | + 'default_value' => $default_settings[ 'license_key_response' ], |
|
| 597 | 597 | 'type' => 'hidden', |
| 598 | 598 | ), |
| 599 | 599 | array( |
| 600 | 600 | 'name' => 'license_key_status', |
| 601 | - 'default_value' => $default_settings['license_key_status'], |
|
| 601 | + 'default_value' => $default_settings[ 'license_key_status' ], |
|
| 602 | 602 | 'type' => 'hidden', |
| 603 | 603 | ), |
| 604 | 604 | array( |
| 605 | 605 | 'name' => 'support-email', |
| 606 | 606 | 'type' => 'text', |
| 607 | 607 | 'validate' => 'email', |
| 608 | - 'default_value' => $default_settings['support-email'], |
|
| 608 | + 'default_value' => $default_settings[ 'support-email' ], |
|
| 609 | 609 | 'label' => __( 'Support Email', 'gravityview' ), |
| 610 | 610 | 'description' => __( 'In order to provide responses to your support requests, please provide your email address.', 'gravityview' ), |
| 611 | 611 | 'class' => 'code regular-text', |
@@ -617,44 +617,44 @@ discard block |
||
| 617 | 617 | 'name' => 'support_port', |
| 618 | 618 | 'type' => 'radio', |
| 619 | 619 | 'label' => __( 'Show Support Port?', 'gravityview' ), |
| 620 | - 'default_value' => $default_settings['support_port'], |
|
| 620 | + 'default_value' => $default_settings[ 'support_port' ], |
|
| 621 | 621 | 'horizontal' => 1, |
| 622 | 622 | 'choices' => array( |
| 623 | 623 | array( |
| 624 | - 'label' => _x('Show', 'Setting: Show or Hide', 'gravityview'), |
|
| 624 | + 'label' => _x( 'Show', 'Setting: Show or Hide', 'gravityview' ), |
|
| 625 | 625 | 'value' => '1', |
| 626 | 626 | ), |
| 627 | 627 | array( |
| 628 | - 'label' => _x('Hide', 'Setting: Show or Hide', 'gravityview'), |
|
| 628 | + 'label' => _x( 'Hide', 'Setting: Show or Hide', 'gravityview' ), |
|
| 629 | 629 | 'value' => '0', |
| 630 | 630 | ), |
| 631 | 631 | ), |
| 632 | - 'tooltip' => '<p><img src="' . esc_url_raw( plugins_url('assets/images/screenshots/beacon.png', GRAVITYVIEW_FILE ) ) . '" alt="' . esc_attr__( 'The Support Port looks like this.', 'gravityview' ) . '" class="alignright" style="max-width:40px; margin:.5em;" />' . esc_html__('The Support Port provides quick access to how-to articles and tutorials. For administrators, it also makes it easy to contact support.', 'gravityview') . '</p>', |
|
| 632 | + 'tooltip' => '<p><img src="' . esc_url_raw( plugins_url( 'assets/images/screenshots/beacon.png', GRAVITYVIEW_FILE ) ) . '" alt="' . esc_attr__( 'The Support Port looks like this.', 'gravityview' ) . '" class="alignright" style="max-width:40px; margin:.5em;" />' . esc_html__( 'The Support Port provides quick access to how-to articles and tutorials. For administrators, it also makes it easy to contact support.', 'gravityview' ) . '</p>', |
|
| 633 | 633 | 'description' => __( 'Show the Support Port on GravityView pages?', 'gravityview' ), |
| 634 | 634 | ), |
| 635 | 635 | array( |
| 636 | 636 | 'name' => 'no-conflict-mode', |
| 637 | 637 | 'type' => 'radio', |
| 638 | 638 | 'label' => __( 'No-Conflict Mode', 'gravityview' ), |
| 639 | - 'default_value' => $default_settings['no-conflict-mode'], |
|
| 639 | + 'default_value' => $default_settings[ 'no-conflict-mode' ], |
|
| 640 | 640 | 'horizontal' => 1, |
| 641 | 641 | 'choices' => array( |
| 642 | 642 | array( |
| 643 | - 'label' => _x('On', 'Setting: On or off', 'gravityview'), |
|
| 643 | + 'label' => _x( 'On', 'Setting: On or off', 'gravityview' ), |
|
| 644 | 644 | 'value' => '1', |
| 645 | 645 | ), |
| 646 | 646 | array( |
| 647 | - 'label' => _x('Off', 'Setting: On or off', 'gravityview'), |
|
| 647 | + 'label' => _x( 'Off', 'Setting: On or off', 'gravityview' ), |
|
| 648 | 648 | 'value' => '0', |
| 649 | 649 | ), |
| 650 | 650 | ), |
| 651 | - 'description' => __( 'Set this to ON to prevent extraneous scripts and styles from being printed on GravityView admin pages, reducing conflicts with other plugins and themes.', 'gravityview' ) . ' ' . __('If your Edit View tabs are ugly, enable this setting.', 'gravityview'), |
|
| 651 | + 'description' => __( 'Set this to ON to prevent extraneous scripts and styles from being printed on GravityView admin pages, reducing conflicts with other plugins and themes.', 'gravityview' ) . ' ' . __( 'If your Edit View tabs are ugly, enable this setting.', 'gravityview' ), |
|
| 652 | 652 | ), |
| 653 | 653 | array( |
| 654 | 654 | 'name' => 'delete-on-uninstall', |
| 655 | 655 | 'type' => 'radio', |
| 656 | 656 | 'label' => __( 'Remove Data on Delete?', 'gravityview' ), |
| 657 | - 'default_value' => $default_settings['delete-on-uninstall'], |
|
| 657 | + 'default_value' => $default_settings[ 'delete-on-uninstall' ], |
|
| 658 | 658 | 'horizontal' => 1, |
| 659 | 659 | 'choices' => array( |
| 660 | 660 | array( |
@@ -680,20 +680,20 @@ discard block |
||
| 680 | 680 | * @since 1.7.4 |
| 681 | 681 | */ |
| 682 | 682 | foreach ( $fields as &$field ) { |
| 683 | - $field['name'] = isset( $field['name'] ) ? $field['name'] : rgget('id', $field ); |
|
| 684 | - $field['label'] = isset( $field['label'] ) ? $field['label'] : rgget('title', $field ); |
|
| 685 | - $field['default_value'] = isset( $field['default_value'] ) ? $field['default_value'] : rgget('default', $field ); |
|
| 686 | - $field['description'] = isset( $field['description'] ) ? $field['description'] : rgget('subtitle', $field ); |
|
| 683 | + $field[ 'name' ] = isset( $field[ 'name' ] ) ? $field[ 'name' ] : rgget( 'id', $field ); |
|
| 684 | + $field[ 'label' ] = isset( $field[ 'label' ] ) ? $field[ 'label' ] : rgget( 'title', $field ); |
|
| 685 | + $field[ 'default_value' ] = isset( $field[ 'default_value' ] ) ? $field[ 'default_value' ] : rgget( 'default', $field ); |
|
| 686 | + $field[ 'description' ] = isset( $field[ 'description' ] ) ? $field[ 'description' ] : rgget( 'subtitle', $field ); |
|
| 687 | 687 | |
| 688 | - if( $disabled_attribute ) { |
|
| 689 | - $field['disabled'] = $disabled_attribute; |
|
| 688 | + if ( $disabled_attribute ) { |
|
| 689 | + $field[ 'disabled' ] = $disabled_attribute; |
|
| 690 | 690 | } |
| 691 | 691 | } |
| 692 | 692 | |
| 693 | 693 | |
| 694 | 694 | $sections = array( |
| 695 | 695 | array( |
| 696 | - 'description' => sprintf( '<span class="version-info description">%s</span>', sprintf( __('You are running GravityView version %s', 'gravityview'), GravityView_Plugin::version ) ), |
|
| 696 | + 'description' => sprintf( '<span class="version-info description">%s</span>', sprintf( __( 'You are running GravityView version %s', 'gravityview' ), GravityView_Plugin::version ) ), |
|
| 697 | 697 | 'fields' => $fields, |
| 698 | 698 | ) |
| 699 | 699 | ); |
@@ -704,8 +704,8 @@ discard block |
||
| 704 | 704 | 'type' => 'save', |
| 705 | 705 | ); |
| 706 | 706 | |
| 707 | - if( $disabled_attribute ) { |
|
| 708 | - $button['disabled'] = $disabled_attribute; |
|
| 707 | + if ( $disabled_attribute ) { |
|
| 708 | + $button[ 'disabled' ] = $disabled_attribute; |
|
| 709 | 709 | } |
| 710 | 710 | |
| 711 | 711 | |
@@ -725,20 +725,20 @@ discard block |
||
| 725 | 725 | // If there are extensions, add a section for them |
| 726 | 726 | if ( ! empty( $extension_sections ) ) { |
| 727 | 727 | |
| 728 | - if( $disabled_attribute ) { |
|
| 728 | + if ( $disabled_attribute ) { |
|
| 729 | 729 | foreach ( $extension_sections as &$section ) { |
| 730 | - foreach ( $section['fields'] as &$field ) { |
|
| 731 | - $field['disabled'] = $disabled_attribute; |
|
| 730 | + foreach ( $section[ 'fields' ] as &$field ) { |
|
| 731 | + $field[ 'disabled' ] = $disabled_attribute; |
|
| 732 | 732 | } |
| 733 | 733 | } |
| 734 | 734 | } |
| 735 | 735 | |
| 736 | - $k = count( $extension_sections ) - 1 ; |
|
| 737 | - $extension_sections[ $k ]['fields'][] = $button; |
|
| 736 | + $k = count( $extension_sections ) - 1; |
|
| 737 | + $extension_sections[ $k ][ 'fields' ][ ] = $button; |
|
| 738 | 738 | $sections = array_merge( $sections, $extension_sections ); |
| 739 | 739 | } else { |
| 740 | 740 | // add the 'update settings' button to the general section |
| 741 | - $sections[0]['fields'][] = $button; |
|
| 741 | + $sections[ 0 ][ 'fields' ][ ] = $button; |
|
| 742 | 742 | } |
| 743 | 743 | |
| 744 | 744 | return $sections; |
@@ -10,21 +10,21 @@ discard block |
||
| 10 | 10 | */ |
| 11 | 11 | |
| 12 | 12 | if ( ! defined( 'WPINC' ) ) { |
| 13 | - die; |
|
| 13 | + die; |
|
| 14 | 14 | } |
| 15 | 15 | |
| 16 | 16 | |
| 17 | 17 | class GravityView_Edit_Entry_Render { |
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * @var GravityView_Edit_Entry |
|
| 21 | - */ |
|
| 22 | - protected $loader; |
|
| 19 | + /** |
|
| 20 | + * @var GravityView_Edit_Entry |
|
| 21 | + */ |
|
| 22 | + protected $loader; |
|
| 23 | 23 | |
| 24 | 24 | /** |
| 25 | 25 | * @var string String used to generate unique nonce for the entry/form/view combination. Allows access to edit page. |
| 26 | 26 | */ |
| 27 | - static $nonce_key; |
|
| 27 | + static $nonce_key; |
|
| 28 | 28 | |
| 29 | 29 | /** |
| 30 | 30 | * @since 1.9 |
@@ -44,142 +44,142 @@ discard block |
||
| 44 | 44 | */ |
| 45 | 45 | private static $supports_product_fields = false; |
| 46 | 46 | |
| 47 | - /** |
|
| 48 | - * Gravity Forms entry array |
|
| 49 | - * |
|
| 50 | - * @var array |
|
| 51 | - */ |
|
| 52 | - var $entry; |
|
| 53 | - |
|
| 54 | - /** |
|
| 55 | - * Gravity Forms form array (GravityView modifies the content through this class lifecycle) |
|
| 56 | - * |
|
| 57 | - * @var array |
|
| 58 | - */ |
|
| 59 | - var $form; |
|
| 60 | - |
|
| 61 | - /** |
|
| 62 | - * Gravity Forms form array (it won't get changed during this class lifecycle) |
|
| 63 | - * @since 1.16.2.1 |
|
| 64 | - * @var array |
|
| 65 | - */ |
|
| 66 | - var $original_form; |
|
| 67 | - |
|
| 68 | - /** |
|
| 69 | - * Gravity Forms form array after the form validation process |
|
| 70 | - * @since 1.13 |
|
| 71 | - * @var array |
|
| 72 | - */ |
|
| 73 | - var $form_after_validation = null; |
|
| 74 | - |
|
| 75 | - /** |
|
| 76 | - * Hold an array of GF field objects that have calculation rules |
|
| 77 | - * @var array |
|
| 78 | - */ |
|
| 79 | - var $fields_with_calculation = array(); |
|
| 80 | - |
|
| 81 | - /** |
|
| 82 | - * Hold an array of GF field objects with type 'total' |
|
| 83 | - * @var array |
|
| 84 | - */ |
|
| 85 | - var $total_fields = array(); |
|
| 86 | - |
|
| 87 | - /** |
|
| 88 | - * Gravity Forms form id |
|
| 89 | - * |
|
| 90 | - * @var int |
|
| 91 | - */ |
|
| 92 | - var $form_id; |
|
| 93 | - |
|
| 94 | - /** |
|
| 95 | - * ID of the current view |
|
| 96 | - * |
|
| 97 | - * @var int |
|
| 98 | - */ |
|
| 99 | - var $view_id; |
|
| 100 | - |
|
| 101 | - /** |
|
| 102 | - * Updated entry is valid (GF Validation object) |
|
| 103 | - * |
|
| 104 | - * @var array |
|
| 105 | - */ |
|
| 106 | - var $is_valid = NULL; |
|
| 107 | - |
|
| 108 | - function __construct( GravityView_Edit_Entry $loader ) { |
|
| 109 | - $this->loader = $loader; |
|
| 110 | - } |
|
| 111 | - |
|
| 112 | - function load() { |
|
| 113 | - |
|
| 114 | - /** @define "GRAVITYVIEW_DIR" "../../../" */ |
|
| 115 | - include_once( GRAVITYVIEW_DIR .'includes/class-admin-approve-entries.php' ); |
|
| 116 | - |
|
| 117 | - // Don't display an embedded form when editing an entry |
|
| 118 | - add_action( 'wp_head', array( $this, 'prevent_render_form' ) ); |
|
| 119 | - add_action( 'wp_footer', array( $this, 'prevent_render_form' ) ); |
|
| 120 | - |
|
| 121 | - // Stop Gravity Forms processing what is ours! |
|
| 122 | - add_filter( 'wp', array( $this, 'prevent_maybe_process_form'), 8 ); |
|
| 123 | - |
|
| 124 | - add_filter( 'gravityview_is_edit_entry', array( $this, 'is_edit_entry') ); |
|
| 125 | - |
|
| 126 | - add_action( 'gravityview_edit_entry', array( $this, 'init' ) ); |
|
| 127 | - |
|
| 128 | - // Disable conditional logic if needed (since 1.9) |
|
| 129 | - add_filter( 'gform_has_conditional_logic', array( $this, 'manage_conditional_logic' ), 10, 2 ); |
|
| 130 | - |
|
| 131 | - // Make sure GF doesn't validate max files (since 1.9) |
|
| 132 | - add_filter( 'gform_plupload_settings', array( $this, 'modify_fileupload_settings' ), 10, 3 ); |
|
| 133 | - |
|
| 134 | - // Add fields expected by GFFormDisplay::validate() |
|
| 135 | - add_filter( 'gform_pre_validation', array( $this, 'gform_pre_validation') ); |
|
| 136 | - |
|
| 137 | - } |
|
| 138 | - |
|
| 139 | - /** |
|
| 140 | - * Don't show any forms embedded on a page when GravityView is in Edit Entry mode |
|
| 141 | - * |
|
| 142 | - * Adds a `__return_empty_string` filter on the Gravity Forms shortcode on the `wp_head` action |
|
| 143 | - * And then removes it on the `wp_footer` action |
|
| 144 | - * |
|
| 145 | - * @since 1.16.1 |
|
| 146 | - * |
|
| 147 | - * @return void |
|
| 148 | - */ |
|
| 149 | - function prevent_render_form() { |
|
| 150 | - if( $this->is_edit_entry() ) { |
|
| 151 | - if( 'wp_head' === current_filter() ) { |
|
| 152 | - add_filter( 'gform_shortcode_form', '__return_empty_string' ); |
|
| 153 | - } else { |
|
| 154 | - remove_filter( 'gform_shortcode_form', '__return_empty_string' ); |
|
| 155 | - } |
|
| 156 | - } |
|
| 157 | - } |
|
| 158 | - |
|
| 159 | - /** |
|
| 160 | - * Because we're mimicking being a front-end Gravity Forms form while using a Gravity Forms |
|
| 161 | - * backend form, we need to prevent them from saving twice. |
|
| 162 | - * @return void |
|
| 163 | - */ |
|
| 164 | - function prevent_maybe_process_form() { |
|
| 165 | - |
|
| 166 | - do_action('gravityview_log_debug', 'GravityView_Edit_Entry[prevent_maybe_process_form] $_POSTed data (sanitized): ', esc_html( print_r( $_POST, true ) ) ); |
|
| 167 | - |
|
| 168 | - if( $this->is_edit_entry_submission() && $this->verify_nonce() ) { |
|
| 169 | - remove_action( 'wp', array( 'RGForms', 'maybe_process_form'), 9 ); |
|
| 170 | - } |
|
| 171 | - } |
|
| 172 | - |
|
| 173 | - /** |
|
| 174 | - * Is the current page an Edit Entry page? |
|
| 175 | - * @return boolean |
|
| 176 | - */ |
|
| 177 | - public function is_edit_entry() { |
|
| 178 | - |
|
| 179 | - $gf_page = class_exists('rgpost') && ( 'entry' === rgget( 'view' ) && isset( $_GET['edit'] ) || rgpost( 'action' ) === 'update' ); |
|
| 47 | + /** |
|
| 48 | + * Gravity Forms entry array |
|
| 49 | + * |
|
| 50 | + * @var array |
|
| 51 | + */ |
|
| 52 | + var $entry; |
|
| 53 | + |
|
| 54 | + /** |
|
| 55 | + * Gravity Forms form array (GravityView modifies the content through this class lifecycle) |
|
| 56 | + * |
|
| 57 | + * @var array |
|
| 58 | + */ |
|
| 59 | + var $form; |
|
| 60 | + |
|
| 61 | + /** |
|
| 62 | + * Gravity Forms form array (it won't get changed during this class lifecycle) |
|
| 63 | + * @since 1.16.2.1 |
|
| 64 | + * @var array |
|
| 65 | + */ |
|
| 66 | + var $original_form; |
|
| 67 | + |
|
| 68 | + /** |
|
| 69 | + * Gravity Forms form array after the form validation process |
|
| 70 | + * @since 1.13 |
|
| 71 | + * @var array |
|
| 72 | + */ |
|
| 73 | + var $form_after_validation = null; |
|
| 74 | + |
|
| 75 | + /** |
|
| 76 | + * Hold an array of GF field objects that have calculation rules |
|
| 77 | + * @var array |
|
| 78 | + */ |
|
| 79 | + var $fields_with_calculation = array(); |
|
| 80 | + |
|
| 81 | + /** |
|
| 82 | + * Hold an array of GF field objects with type 'total' |
|
| 83 | + * @var array |
|
| 84 | + */ |
|
| 85 | + var $total_fields = array(); |
|
| 86 | + |
|
| 87 | + /** |
|
| 88 | + * Gravity Forms form id |
|
| 89 | + * |
|
| 90 | + * @var int |
|
| 91 | + */ |
|
| 92 | + var $form_id; |
|
| 93 | + |
|
| 94 | + /** |
|
| 95 | + * ID of the current view |
|
| 96 | + * |
|
| 97 | + * @var int |
|
| 98 | + */ |
|
| 99 | + var $view_id; |
|
| 100 | + |
|
| 101 | + /** |
|
| 102 | + * Updated entry is valid (GF Validation object) |
|
| 103 | + * |
|
| 104 | + * @var array |
|
| 105 | + */ |
|
| 106 | + var $is_valid = NULL; |
|
| 107 | + |
|
| 108 | + function __construct( GravityView_Edit_Entry $loader ) { |
|
| 109 | + $this->loader = $loader; |
|
| 110 | + } |
|
| 111 | + |
|
| 112 | + function load() { |
|
| 113 | + |
|
| 114 | + /** @define "GRAVITYVIEW_DIR" "../../../" */ |
|
| 115 | + include_once( GRAVITYVIEW_DIR .'includes/class-admin-approve-entries.php' ); |
|
| 116 | + |
|
| 117 | + // Don't display an embedded form when editing an entry |
|
| 118 | + add_action( 'wp_head', array( $this, 'prevent_render_form' ) ); |
|
| 119 | + add_action( 'wp_footer', array( $this, 'prevent_render_form' ) ); |
|
| 120 | + |
|
| 121 | + // Stop Gravity Forms processing what is ours! |
|
| 122 | + add_filter( 'wp', array( $this, 'prevent_maybe_process_form'), 8 ); |
|
| 123 | + |
|
| 124 | + add_filter( 'gravityview_is_edit_entry', array( $this, 'is_edit_entry') ); |
|
| 125 | + |
|
| 126 | + add_action( 'gravityview_edit_entry', array( $this, 'init' ) ); |
|
| 127 | + |
|
| 128 | + // Disable conditional logic if needed (since 1.9) |
|
| 129 | + add_filter( 'gform_has_conditional_logic', array( $this, 'manage_conditional_logic' ), 10, 2 ); |
|
| 130 | + |
|
| 131 | + // Make sure GF doesn't validate max files (since 1.9) |
|
| 132 | + add_filter( 'gform_plupload_settings', array( $this, 'modify_fileupload_settings' ), 10, 3 ); |
|
| 133 | + |
|
| 134 | + // Add fields expected by GFFormDisplay::validate() |
|
| 135 | + add_filter( 'gform_pre_validation', array( $this, 'gform_pre_validation') ); |
|
| 136 | + |
|
| 137 | + } |
|
| 138 | + |
|
| 139 | + /** |
|
| 140 | + * Don't show any forms embedded on a page when GravityView is in Edit Entry mode |
|
| 141 | + * |
|
| 142 | + * Adds a `__return_empty_string` filter on the Gravity Forms shortcode on the `wp_head` action |
|
| 143 | + * And then removes it on the `wp_footer` action |
|
| 144 | + * |
|
| 145 | + * @since 1.16.1 |
|
| 146 | + * |
|
| 147 | + * @return void |
|
| 148 | + */ |
|
| 149 | + function prevent_render_form() { |
|
| 150 | + if( $this->is_edit_entry() ) { |
|
| 151 | + if( 'wp_head' === current_filter() ) { |
|
| 152 | + add_filter( 'gform_shortcode_form', '__return_empty_string' ); |
|
| 153 | + } else { |
|
| 154 | + remove_filter( 'gform_shortcode_form', '__return_empty_string' ); |
|
| 155 | + } |
|
| 156 | + } |
|
| 157 | + } |
|
| 158 | + |
|
| 159 | + /** |
|
| 160 | + * Because we're mimicking being a front-end Gravity Forms form while using a Gravity Forms |
|
| 161 | + * backend form, we need to prevent them from saving twice. |
|
| 162 | + * @return void |
|
| 163 | + */ |
|
| 164 | + function prevent_maybe_process_form() { |
|
| 165 | + |
|
| 166 | + do_action('gravityview_log_debug', 'GravityView_Edit_Entry[prevent_maybe_process_form] $_POSTed data (sanitized): ', esc_html( print_r( $_POST, true ) ) ); |
|
| 167 | + |
|
| 168 | + if( $this->is_edit_entry_submission() && $this->verify_nonce() ) { |
|
| 169 | + remove_action( 'wp', array( 'RGForms', 'maybe_process_form'), 9 ); |
|
| 170 | + } |
|
| 171 | + } |
|
| 172 | + |
|
| 173 | + /** |
|
| 174 | + * Is the current page an Edit Entry page? |
|
| 175 | + * @return boolean |
|
| 176 | + */ |
|
| 177 | + public function is_edit_entry() { |
|
| 178 | + |
|
| 179 | + $gf_page = class_exists('rgpost') && ( 'entry' === rgget( 'view' ) && isset( $_GET['edit'] ) || rgpost( 'action' ) === 'update' ); |
|
| 180 | 180 | |
| 181 | - return $gf_page; |
|
| 182 | - } |
|
| 181 | + return $gf_page; |
|
| 182 | + } |
|
| 183 | 183 | |
| 184 | 184 | /** |
| 185 | 185 | * Is the current page an Edit Entry page? |
@@ -190,528 +190,528 @@ discard block |
||
| 190 | 190 | return !empty( $_POST[ self::$nonce_field ] ); |
| 191 | 191 | } |
| 192 | 192 | |
| 193 | - /** |
|
| 194 | - * When Edit entry view is requested setup the vars |
|
| 195 | - */ |
|
| 196 | - function setup_vars() { |
|
| 197 | - $gravityview_view = GravityView_View::getInstance(); |
|
| 193 | + /** |
|
| 194 | + * When Edit entry view is requested setup the vars |
|
| 195 | + */ |
|
| 196 | + function setup_vars() { |
|
| 197 | + $gravityview_view = GravityView_View::getInstance(); |
|
| 198 | 198 | |
| 199 | 199 | |
| 200 | - $entries = $gravityview_view->getEntries(); |
|
| 201 | - $this->entry = $entries[0]; |
|
| 200 | + $entries = $gravityview_view->getEntries(); |
|
| 201 | + $this->entry = $entries[0]; |
|
| 202 | 202 | |
| 203 | - $this->original_form = $this->form = $gravityview_view->getForm(); |
|
| 204 | - $this->form_id = $gravityview_view->getFormId(); |
|
| 205 | - $this->view_id = $gravityview_view->getViewId(); |
|
| 203 | + $this->original_form = $this->form = $gravityview_view->getForm(); |
|
| 204 | + $this->form_id = $gravityview_view->getFormId(); |
|
| 205 | + $this->view_id = $gravityview_view->getViewId(); |
|
| 206 | 206 | |
| 207 | - self::$nonce_key = GravityView_Edit_Entry::get_nonce_key( $this->view_id, $this->form_id, $this->entry['id'] ); |
|
| 208 | - } |
|
| 207 | + self::$nonce_key = GravityView_Edit_Entry::get_nonce_key( $this->view_id, $this->form_id, $this->entry['id'] ); |
|
| 208 | + } |
|
| 209 | 209 | |
| 210 | 210 | |
| 211 | - /** |
|
| 212 | - * Load required files and trigger edit flow |
|
| 213 | - * |
|
| 214 | - * Run when the is_edit_entry returns true. |
|
| 215 | - * |
|
| 216 | - * @param GravityView_View_Data $gv_data GravityView Data object |
|
| 217 | - * @return void |
|
| 218 | - */ |
|
| 219 | - function init( $gv_data ) { |
|
| 211 | + /** |
|
| 212 | + * Load required files and trigger edit flow |
|
| 213 | + * |
|
| 214 | + * Run when the is_edit_entry returns true. |
|
| 215 | + * |
|
| 216 | + * @param GravityView_View_Data $gv_data GravityView Data object |
|
| 217 | + * @return void |
|
| 218 | + */ |
|
| 219 | + function init( $gv_data ) { |
|
| 220 | 220 | |
| 221 | - require_once( GFCommon::get_base_path() . '/form_display.php' ); |
|
| 222 | - require_once( GFCommon::get_base_path() . '/entry_detail.php' ); |
|
| 221 | + require_once( GFCommon::get_base_path() . '/form_display.php' ); |
|
| 222 | + require_once( GFCommon::get_base_path() . '/entry_detail.php' ); |
|
| 223 | 223 | |
| 224 | - $this->setup_vars(); |
|
| 224 | + $this->setup_vars(); |
|
| 225 | 225 | |
| 226 | - // Multiple Views embedded, don't proceed if nonce fails |
|
| 227 | - if( $gv_data->has_multiple_views() && ! wp_verify_nonce( $_GET['edit'], self::$nonce_key ) ) { |
|
| 228 | - return; |
|
| 229 | - } |
|
| 226 | + // Multiple Views embedded, don't proceed if nonce fails |
|
| 227 | + if( $gv_data->has_multiple_views() && ! wp_verify_nonce( $_GET['edit'], self::$nonce_key ) ) { |
|
| 228 | + return; |
|
| 229 | + } |
|
| 230 | 230 | |
| 231 | - // Sorry, you're not allowed here. |
|
| 232 | - if( false === $this->user_can_edit_entry( true ) ) { |
|
| 233 | - return; |
|
| 234 | - } |
|
| 231 | + // Sorry, you're not allowed here. |
|
| 232 | + if( false === $this->user_can_edit_entry( true ) ) { |
|
| 233 | + return; |
|
| 234 | + } |
|
| 235 | 235 | |
| 236 | - $this->print_scripts(); |
|
| 236 | + $this->print_scripts(); |
|
| 237 | 237 | |
| 238 | - $this->process_save(); |
|
| 238 | + $this->process_save(); |
|
| 239 | 239 | |
| 240 | - $this->edit_entry_form(); |
|
| 240 | + $this->edit_entry_form(); |
|
| 241 | 241 | |
| 242 | - } |
|
| 242 | + } |
|
| 243 | 243 | |
| 244 | 244 | |
| 245 | - /** |
|
| 246 | - * Force Gravity Forms to output scripts as if it were in the admin |
|
| 247 | - * @return void |
|
| 248 | - */ |
|
| 249 | - function print_scripts() { |
|
| 250 | - $gravityview_view = GravityView_View::getInstance(); |
|
| 245 | + /** |
|
| 246 | + * Force Gravity Forms to output scripts as if it were in the admin |
|
| 247 | + * @return void |
|
| 248 | + */ |
|
| 249 | + function print_scripts() { |
|
| 250 | + $gravityview_view = GravityView_View::getInstance(); |
|
| 251 | 251 | |
| 252 | - wp_register_script( 'gform_gravityforms', GFCommon::get_base_url().'/js/gravityforms.js', array( 'jquery', 'gform_json', 'gform_placeholder', 'sack', 'plupload-all', 'gravityview-fe-view' ) ); |
|
| 252 | + wp_register_script( 'gform_gravityforms', GFCommon::get_base_url().'/js/gravityforms.js', array( 'jquery', 'gform_json', 'gform_placeholder', 'sack', 'plupload-all', 'gravityview-fe-view' ) ); |
|
| 253 | 253 | |
| 254 | - GFFormDisplay::enqueue_form_scripts($gravityview_view->getForm(), false); |
|
| 254 | + GFFormDisplay::enqueue_form_scripts($gravityview_view->getForm(), false); |
|
| 255 | 255 | |
| 256 | - // Sack is required for images |
|
| 257 | - wp_print_scripts( array( 'sack', 'gform_gravityforms' ) ); |
|
| 258 | - } |
|
| 256 | + // Sack is required for images |
|
| 257 | + wp_print_scripts( array( 'sack', 'gform_gravityforms' ) ); |
|
| 258 | + } |
|
| 259 | 259 | |
| 260 | 260 | |
| 261 | - /** |
|
| 262 | - * Process edit entry form save |
|
| 263 | - */ |
|
| 264 | - function process_save() { |
|
| 261 | + /** |
|
| 262 | + * Process edit entry form save |
|
| 263 | + */ |
|
| 264 | + function process_save() { |
|
| 265 | 265 | |
| 266 | - if( empty( $_POST ) ) { |
|
| 267 | - return; |
|
| 268 | - } |
|
| 266 | + if( empty( $_POST ) ) { |
|
| 267 | + return; |
|
| 268 | + } |
|
| 269 | 269 | |
| 270 | - // Make sure the entry, view, and form IDs are all correct |
|
| 271 | - $valid = $this->verify_nonce(); |
|
| 270 | + // Make sure the entry, view, and form IDs are all correct |
|
| 271 | + $valid = $this->verify_nonce(); |
|
| 272 | 272 | |
| 273 | - if( !$valid ) { |
|
| 274 | - do_action('gravityview_log_error', __METHOD__ . ' Nonce validation failed.' ); |
|
| 275 | - return; |
|
| 276 | - } |
|
| 273 | + if( !$valid ) { |
|
| 274 | + do_action('gravityview_log_error', __METHOD__ . ' Nonce validation failed.' ); |
|
| 275 | + return; |
|
| 276 | + } |
|
| 277 | 277 | |
| 278 | - if( $this->entry['id'] !== $_POST['lid'] ) { |
|
| 279 | - do_action('gravityview_log_error', __METHOD__ . ' Entry ID did not match posted entry ID.' ); |
|
| 280 | - return; |
|
| 281 | - } |
|
| 278 | + if( $this->entry['id'] !== $_POST['lid'] ) { |
|
| 279 | + do_action('gravityview_log_error', __METHOD__ . ' Entry ID did not match posted entry ID.' ); |
|
| 280 | + return; |
|
| 281 | + } |
|
| 282 | 282 | |
| 283 | - do_action('gravityview_log_debug', 'GravityView_Edit_Entry[process_save] $_POSTed data (sanitized): ', esc_html( print_r( $_POST, true ) ) ); |
|
| 283 | + do_action('gravityview_log_debug', 'GravityView_Edit_Entry[process_save] $_POSTed data (sanitized): ', esc_html( print_r( $_POST, true ) ) ); |
|
| 284 | 284 | |
| 285 | - $this->process_save_process_files( $this->form_id ); |
|
| 285 | + $this->process_save_process_files( $this->form_id ); |
|
| 286 | 286 | |
| 287 | - $this->validate(); |
|
| 287 | + $this->validate(); |
|
| 288 | 288 | |
| 289 | - if( $this->is_valid ) { |
|
| 289 | + if( $this->is_valid ) { |
|
| 290 | 290 | |
| 291 | - do_action('gravityview_log_debug', 'GravityView_Edit_Entry[process_save] Submission is valid.' ); |
|
| 291 | + do_action('gravityview_log_debug', 'GravityView_Edit_Entry[process_save] Submission is valid.' ); |
|
| 292 | 292 | |
| 293 | - /** |
|
| 294 | - * @hack This step is needed to unset the adminOnly from form fields, to add the calculation fields |
|
| 295 | - */ |
|
| 296 | - $form = $this->form_prepare_for_save(); |
|
| 293 | + /** |
|
| 294 | + * @hack This step is needed to unset the adminOnly from form fields, to add the calculation fields |
|
| 295 | + */ |
|
| 296 | + $form = $this->form_prepare_for_save(); |
|
| 297 | 297 | |
| 298 | - /** |
|
| 299 | - * @hack to avoid the capability validation of the method save_lead for GF 1.9+ |
|
| 300 | - */ |
|
| 301 | - unset( $_GET['page'] ); |
|
| 298 | + /** |
|
| 299 | + * @hack to avoid the capability validation of the method save_lead for GF 1.9+ |
|
| 300 | + */ |
|
| 301 | + unset( $_GET['page'] ); |
|
| 302 | 302 | |
| 303 | - GFFormsModel::save_lead( $form, $this->entry ); |
|
| 303 | + GFFormsModel::save_lead( $form, $this->entry ); |
|
| 304 | 304 | |
| 305 | - // If there's a post associated with the entry, process post fields |
|
| 306 | - if( !empty( $this->entry['post_id'] ) ) { |
|
| 307 | - $this->maybe_update_post_fields( $form ); |
|
| 308 | - } |
|
| 305 | + // If there's a post associated with the entry, process post fields |
|
| 306 | + if( !empty( $this->entry['post_id'] ) ) { |
|
| 307 | + $this->maybe_update_post_fields( $form ); |
|
| 308 | + } |
|
| 309 | 309 | |
| 310 | - // Process calculation fields |
|
| 311 | - $this->update_calculation_fields(); |
|
| 310 | + // Process calculation fields |
|
| 311 | + $this->update_calculation_fields(); |
|
| 312 | 312 | |
| 313 | - // Perform actions normally performed after updating a lead |
|
| 314 | - $this->after_update(); |
|
| 313 | + // Perform actions normally performed after updating a lead |
|
| 314 | + $this->after_update(); |
|
| 315 | 315 | |
| 316 | - /** |
|
| 317 | - * @action `gravityview/edit_entry/after_update` Perform an action after the entry has been updated using Edit Entry |
|
| 318 | - * @param array $form Gravity Forms form array |
|
| 319 | - * @param string $entry_id Numeric ID of the entry that was updated |
|
| 320 | - */ |
|
| 321 | - do_action( 'gravityview/edit_entry/after_update', $this->form, $this->entry['id'] ); |
|
| 322 | - } |
|
| 316 | + /** |
|
| 317 | + * @action `gravityview/edit_entry/after_update` Perform an action after the entry has been updated using Edit Entry |
|
| 318 | + * @param array $form Gravity Forms form array |
|
| 319 | + * @param string $entry_id Numeric ID of the entry that was updated |
|
| 320 | + */ |
|
| 321 | + do_action( 'gravityview/edit_entry/after_update', $this->form, $this->entry['id'] ); |
|
| 322 | + } |
|
| 323 | 323 | |
| 324 | - } // process_save |
|
| 324 | + } // process_save |
|
| 325 | 325 | |
| 326 | 326 | |
| 327 | - /** |
|
| 328 | - * Have GF handle file uploads |
|
| 329 | - * |
|
| 330 | - * Copy of code from GFFormDisplay::process_form() |
|
| 331 | - * |
|
| 332 | - * @param int $form_id |
|
| 333 | - */ |
|
| 334 | - function process_save_process_files( $form_id ) { |
|
| 327 | + /** |
|
| 328 | + * Have GF handle file uploads |
|
| 329 | + * |
|
| 330 | + * Copy of code from GFFormDisplay::process_form() |
|
| 331 | + * |
|
| 332 | + * @param int $form_id |
|
| 333 | + */ |
|
| 334 | + function process_save_process_files( $form_id ) { |
|
| 335 | 335 | |
| 336 | - //Loading files that have been uploaded to temp folder |
|
| 337 | - $files = GFCommon::json_decode( stripslashes( RGForms::post( 'gform_uploaded_files' ) ) ); |
|
| 338 | - if ( ! is_array( $files ) ) { |
|
| 339 | - $files = array(); |
|
| 340 | - } |
|
| 336 | + //Loading files that have been uploaded to temp folder |
|
| 337 | + $files = GFCommon::json_decode( stripslashes( RGForms::post( 'gform_uploaded_files' ) ) ); |
|
| 338 | + if ( ! is_array( $files ) ) { |
|
| 339 | + $files = array(); |
|
| 340 | + } |
|
| 341 | 341 | |
| 342 | - RGFormsModel::$uploaded_files[ $form_id ] = $files; |
|
| 343 | - } |
|
| 344 | - |
|
| 345 | - /** |
|
| 346 | - * Remove max_files validation (done on gravityforms.js) to avoid conflicts with GravityView |
|
| 347 | - * Late validation done on self::custom_validation |
|
| 348 | - * |
|
| 349 | - * @param $plupload_init array Plupload settings |
|
| 350 | - * @param $form_id |
|
| 351 | - * @param $instance |
|
| 352 | - * @return mixed |
|
| 353 | - */ |
|
| 354 | - public function modify_fileupload_settings( $plupload_init, $form_id, $instance ) { |
|
| 355 | - if( ! $this->is_edit_entry() ) { |
|
| 356 | - return $plupload_init; |
|
| 357 | - } |
|
| 358 | - |
|
| 359 | - $plupload_init['gf_vars']['max_files'] = 0; |
|
| 360 | - |
|
| 361 | - return $plupload_init; |
|
| 362 | - } |
|
| 363 | - |
|
| 364 | - |
|
| 365 | - /** |
|
| 366 | - * Unset adminOnly and convert field input key to string |
|
| 367 | - * @return array $form |
|
| 368 | - */ |
|
| 369 | - private function form_prepare_for_save() { |
|
| 342 | + RGFormsModel::$uploaded_files[ $form_id ] = $files; |
|
| 343 | + } |
|
| 370 | 344 | |
| 371 | - $form = $this->form; |
|
| 345 | + /** |
|
| 346 | + * Remove max_files validation (done on gravityforms.js) to avoid conflicts with GravityView |
|
| 347 | + * Late validation done on self::custom_validation |
|
| 348 | + * |
|
| 349 | + * @param $plupload_init array Plupload settings |
|
| 350 | + * @param $form_id |
|
| 351 | + * @param $instance |
|
| 352 | + * @return mixed |
|
| 353 | + */ |
|
| 354 | + public function modify_fileupload_settings( $plupload_init, $form_id, $instance ) { |
|
| 355 | + if( ! $this->is_edit_entry() ) { |
|
| 356 | + return $plupload_init; |
|
| 357 | + } |
|
| 372 | 358 | |
| 373 | - foreach( $form['fields'] as $k => &$field ) { |
|
| 359 | + $plupload_init['gf_vars']['max_files'] = 0; |
|
| 374 | 360 | |
| 375 | - // Remove the fields with calculation formulas before save to avoid conflicts with GF logic |
|
| 376 | - // @since 1.16.3 |
|
| 377 | - if( $field->has_calculation() ) { |
|
| 378 | - unset( $form['fields'][ $k ] ); |
|
| 379 | - } |
|
| 361 | + return $plupload_init; |
|
| 362 | + } |
|
| 380 | 363 | |
| 381 | - $field->adminOnly = false; |
|
| 382 | 364 | |
| 383 | - if( isset( $field->inputs ) && is_array( $field->inputs ) ) { |
|
| 384 | - foreach( $field->inputs as $key => $input ) { |
|
| 385 | - $field->inputs[ $key ][ 'id' ] = (string)$input['id']; |
|
| 386 | - } |
|
| 387 | - } |
|
| 388 | - } |
|
| 389 | - |
|
| 390 | - return $form; |
|
| 391 | - } |
|
| 392 | - |
|
| 393 | - private function update_calculation_fields() { |
|
| 394 | - |
|
| 395 | - $form = $this->original_form; |
|
| 396 | - $update = false; |
|
| 397 | - |
|
| 398 | - // get the most up to date entry values |
|
| 399 | - $entry = GFAPI::get_entry( $this->entry['id'] ); |
|
| 400 | - |
|
| 401 | - if( !empty( $this->fields_with_calculation ) ) { |
|
| 402 | - $update = true; |
|
| 403 | - foreach ( $this->fields_with_calculation as $calc_field ) { |
|
| 404 | - $inputs = $calc_field->get_entry_inputs(); |
|
| 405 | - if ( is_array( $inputs ) ) { |
|
| 406 | - foreach ( $inputs as $input ) { |
|
| 407 | - $input_name = 'input_' . str_replace( '.', '_', $input['id'] ); |
|
| 408 | - $entry[ strval( $input['id'] ) ] = RGFormsModel::prepare_value( $form, $calc_field, '', $input_name, $entry['id'], $entry ); |
|
| 409 | - } |
|
| 410 | - } else { |
|
| 411 | - $input_name = 'input_' . str_replace( '.', '_', $calc_field->id); |
|
| 412 | - $entry[ strval( $calc_field->id ) ] = RGFormsModel::prepare_value( $form, $calc_field, '', $input_name, $entry['id'], $entry ); |
|
| 413 | - } |
|
| 414 | - } |
|
| 415 | - |
|
| 416 | - } |
|
| 417 | - |
|
| 418 | - //saving total field as the last field of the form. |
|
| 419 | - if ( ! empty( $this->total_fields ) ) { |
|
| 420 | - $update = true; |
|
| 421 | - foreach ( $this->total_fields as $total_field ) { |
|
| 422 | - $input_name = 'input_' . str_replace( '.', '_', $total_field->id); |
|
| 423 | - $entry[ strval( $total_field->id ) ] = RGFormsModel::prepare_value( $form, $total_field, '', $input_name, $entry['id'], $entry ); |
|
| 424 | - } |
|
| 425 | - } |
|
| 426 | - |
|
| 427 | - if( $update ) { |
|
| 428 | - |
|
| 429 | - $return_entry = GFAPI::update_entry( $entry ); |
|
| 430 | - |
|
| 431 | - if( is_wp_error( $return_entry ) ) { |
|
| 432 | - do_action( 'gravityview_log_error', 'Updating the entry calculation and total fields failed', $return_entry ); |
|
| 433 | - } else { |
|
| 434 | - do_action( 'gravityview_log_debug', 'Updating the entry calculation and total fields succeeded' ); |
|
| 435 | - } |
|
| 436 | - } |
|
| 437 | - } |
|
| 438 | - |
|
| 439 | - |
|
| 440 | - /** |
|
| 441 | - * Loop through the fields being edited and if they include Post fields, update the Entry's post object |
|
| 442 | - * |
|
| 443 | - * @param array $form Gravity Forms form |
|
| 444 | - * |
|
| 445 | - * @return void |
|
| 446 | - */ |
|
| 447 | - function maybe_update_post_fields( $form ) { |
|
| 448 | - |
|
| 449 | - $post_id = $this->entry['post_id']; |
|
| 365 | + /** |
|
| 366 | + * Unset adminOnly and convert field input key to string |
|
| 367 | + * @return array $form |
|
| 368 | + */ |
|
| 369 | + private function form_prepare_for_save() { |
|
| 450 | 370 | |
| 451 | - // Security check |
|
| 452 | - if( false === GVCommon::has_cap( 'edit_post', $post_id ) ) { |
|
| 453 | - do_action( 'gravityview_log_error', 'The current user does not have the ability to edit Post #'.$post_id ); |
|
| 454 | - return; |
|
| 455 | - } |
|
| 371 | + $form = $this->form; |
|
| 456 | 372 | |
| 457 | - $update_entry = false; |
|
| 373 | + foreach( $form['fields'] as $k => &$field ) { |
|
| 458 | 374 | |
| 459 | - $updated_post = $original_post = get_post( $post_id ); |
|
| 375 | + // Remove the fields with calculation formulas before save to avoid conflicts with GF logic |
|
| 376 | + // @since 1.16.3 |
|
| 377 | + if( $field->has_calculation() ) { |
|
| 378 | + unset( $form['fields'][ $k ] ); |
|
| 379 | + } |
|
| 460 | 380 | |
| 461 | - // get the most up to date entry values |
|
| 462 | - $entry = GFAPI::get_entry( $this->entry['id'] ); |
|
| 381 | + $field->adminOnly = false; |
|
| 463 | 382 | |
| 464 | - foreach ( $entry as $field_id => $value ) { |
|
| 465 | - |
|
| 466 | - //todo: only run through the edit entry configured fields |
|
| 383 | + if( isset( $field->inputs ) && is_array( $field->inputs ) ) { |
|
| 384 | + foreach( $field->inputs as $key => $input ) { |
|
| 385 | + $field->inputs[ $key ][ 'id' ] = (string)$input['id']; |
|
| 386 | + } |
|
| 387 | + } |
|
| 388 | + } |
|
| 467 | 389 | |
| 468 | - $field = RGFormsModel::get_field( $form, $field_id ); |
|
| 390 | + return $form; |
|
| 391 | + } |
|
| 469 | 392 | |
| 470 | - if( class_exists('GF_Fields') ) { |
|
| 471 | - $field = GF_Fields::create( $field ); |
|
| 472 | - } |
|
| 393 | + private function update_calculation_fields() { |
|
| 394 | + |
|
| 395 | + $form = $this->original_form; |
|
| 396 | + $update = false; |
|
| 397 | + |
|
| 398 | + // get the most up to date entry values |
|
| 399 | + $entry = GFAPI::get_entry( $this->entry['id'] ); |
|
| 400 | + |
|
| 401 | + if( !empty( $this->fields_with_calculation ) ) { |
|
| 402 | + $update = true; |
|
| 403 | + foreach ( $this->fields_with_calculation as $calc_field ) { |
|
| 404 | + $inputs = $calc_field->get_entry_inputs(); |
|
| 405 | + if ( is_array( $inputs ) ) { |
|
| 406 | + foreach ( $inputs as $input ) { |
|
| 407 | + $input_name = 'input_' . str_replace( '.', '_', $input['id'] ); |
|
| 408 | + $entry[ strval( $input['id'] ) ] = RGFormsModel::prepare_value( $form, $calc_field, '', $input_name, $entry['id'], $entry ); |
|
| 409 | + } |
|
| 410 | + } else { |
|
| 411 | + $input_name = 'input_' . str_replace( '.', '_', $calc_field->id); |
|
| 412 | + $entry[ strval( $calc_field->id ) ] = RGFormsModel::prepare_value( $form, $calc_field, '', $input_name, $entry['id'], $entry ); |
|
| 413 | + } |
|
| 414 | + } |
|
| 473 | 415 | |
| 474 | - if( GFCommon::is_post_field( $field ) ) { |
|
| 416 | + } |
|
| 475 | 417 | |
| 476 | - // Get the value of the field, including $_POSTed value |
|
| 477 | - $value = RGFormsModel::get_field_value( $field ); |
|
| 418 | + //saving total field as the last field of the form. |
|
| 419 | + if ( ! empty( $this->total_fields ) ) { |
|
| 420 | + $update = true; |
|
| 421 | + foreach ( $this->total_fields as $total_field ) { |
|
| 422 | + $input_name = 'input_' . str_replace( '.', '_', $total_field->id); |
|
| 423 | + $entry[ strval( $total_field->id ) ] = RGFormsModel::prepare_value( $form, $total_field, '', $input_name, $entry['id'], $entry ); |
|
| 424 | + } |
|
| 425 | + } |
|
| 478 | 426 | |
| 479 | - switch( $field->type ) { |
|
| 427 | + if( $update ) { |
|
| 480 | 428 | |
| 481 | - case 'post_title': |
|
| 482 | - case 'post_content': |
|
| 483 | - case 'post_excerpt': |
|
| 484 | - $updated_post->{$field->type} = $value; |
|
| 485 | - break; |
|
| 486 | - case 'post_tags': |
|
| 487 | - wp_set_post_tags( $post_id, $value, false ); |
|
| 488 | - break; |
|
| 489 | - case 'post_category': |
|
| 429 | + $return_entry = GFAPI::update_entry( $entry ); |
|
| 490 | 430 | |
| 491 | - $categories = is_array( $value ) ? array_values( $value ) : (array)$value; |
|
| 492 | - $categories = array_filter( $categories ); |
|
| 431 | + if( is_wp_error( $return_entry ) ) { |
|
| 432 | + do_action( 'gravityview_log_error', 'Updating the entry calculation and total fields failed', $return_entry ); |
|
| 433 | + } else { |
|
| 434 | + do_action( 'gravityview_log_debug', 'Updating the entry calculation and total fields succeeded' ); |
|
| 435 | + } |
|
| 436 | + } |
|
| 437 | + } |
|
| 438 | + |
|
| 439 | + |
|
| 440 | + /** |
|
| 441 | + * Loop through the fields being edited and if they include Post fields, update the Entry's post object |
|
| 442 | + * |
|
| 443 | + * @param array $form Gravity Forms form |
|
| 444 | + * |
|
| 445 | + * @return void |
|
| 446 | + */ |
|
| 447 | + function maybe_update_post_fields( $form ) { |
|
| 448 | + |
|
| 449 | + $post_id = $this->entry['post_id']; |
|
| 450 | + |
|
| 451 | + // Security check |
|
| 452 | + if( false === GVCommon::has_cap( 'edit_post', $post_id ) ) { |
|
| 453 | + do_action( 'gravityview_log_error', 'The current user does not have the ability to edit Post #'.$post_id ); |
|
| 454 | + return; |
|
| 455 | + } |
|
| 456 | + |
|
| 457 | + $update_entry = false; |
|
| 458 | + |
|
| 459 | + $updated_post = $original_post = get_post( $post_id ); |
|
| 460 | + |
|
| 461 | + // get the most up to date entry values |
|
| 462 | + $entry = GFAPI::get_entry( $this->entry['id'] ); |
|
| 493 | 463 | |
| 494 | - wp_set_post_categories( $post_id, $categories, false ); |
|
| 464 | + foreach ( $entry as $field_id => $value ) { |
|
| 495 | 465 | |
| 496 | - // if post_category is type checkbox, then value is an array of inputs |
|
| 497 | - if( isset( $value[ strval( $field_id ) ] ) ) { |
|
| 498 | - foreach( $value as $input_id => $val ) { |
|
| 499 | - $input_name = 'input_' . str_replace( '.', '_', $input_id ); |
|
| 500 | - $entry[ strval( $input_id ) ] = RGFormsModel::prepare_value( $form, $field, $val, $input_name, $entry['id'], $entry ); |
|
| 501 | - } |
|
| 502 | - } else { |
|
| 503 | - $input_name = 'input_' . str_replace( '.', '_', $field_id ); |
|
| 504 | - $entry[ strval( $field_id ) ] = RGFormsModel::prepare_value( $form, $field, $value, $input_name, $entry['id'], $entry ); |
|
| 505 | - } |
|
| 466 | + //todo: only run through the edit entry configured fields |
|
| 506 | 467 | |
| 507 | - break; |
|
| 508 | - case 'post_custom_field': |
|
| 468 | + $field = RGFormsModel::get_field( $form, $field_id ); |
|
| 509 | 469 | |
| 510 | - $input_type = RGFormsModel::get_input_type( $field ); |
|
| 511 | - $custom_field_name = $field->postCustomFieldName; |
|
| 470 | + if( class_exists('GF_Fields') ) { |
|
| 471 | + $field = GF_Fields::create( $field ); |
|
| 472 | + } |
|
| 473 | + |
|
| 474 | + if( GFCommon::is_post_field( $field ) ) { |
|
| 475 | + |
|
| 476 | + // Get the value of the field, including $_POSTed value |
|
| 477 | + $value = RGFormsModel::get_field_value( $field ); |
|
| 478 | + |
|
| 479 | + switch( $field->type ) { |
|
| 480 | + |
|
| 481 | + case 'post_title': |
|
| 482 | + case 'post_content': |
|
| 483 | + case 'post_excerpt': |
|
| 484 | + $updated_post->{$field->type} = $value; |
|
| 485 | + break; |
|
| 486 | + case 'post_tags': |
|
| 487 | + wp_set_post_tags( $post_id, $value, false ); |
|
| 488 | + break; |
|
| 489 | + case 'post_category': |
|
| 490 | + |
|
| 491 | + $categories = is_array( $value ) ? array_values( $value ) : (array)$value; |
|
| 492 | + $categories = array_filter( $categories ); |
|
| 493 | + |
|
| 494 | + wp_set_post_categories( $post_id, $categories, false ); |
|
| 512 | 495 | |
| 513 | - // Only certain custom field types are supported |
|
| 514 | - switch( $input_type ) { |
|
| 515 | - case 'fileupload': |
|
| 516 | - /** @noinspection PhpMissingBreakStatementInspection */ |
|
| 517 | - case 'list': |
|
| 518 | - if( ! is_string( $value ) ) { |
|
| 519 | - $value = function_exists('wp_json_encode') ? wp_json_encode( $value ) : json_encode( $value ); |
|
| 520 | - } |
|
| 521 | - // break; left intentionally out |
|
| 522 | - default: |
|
| 523 | - update_post_meta( $post_id, $custom_field_name, $value ); |
|
| 524 | - } |
|
| 496 | + // if post_category is type checkbox, then value is an array of inputs |
|
| 497 | + if( isset( $value[ strval( $field_id ) ] ) ) { |
|
| 498 | + foreach( $value as $input_id => $val ) { |
|
| 499 | + $input_name = 'input_' . str_replace( '.', '_', $input_id ); |
|
| 500 | + $entry[ strval( $input_id ) ] = RGFormsModel::prepare_value( $form, $field, $val, $input_name, $entry['id'], $entry ); |
|
| 501 | + } |
|
| 502 | + } else { |
|
| 503 | + $input_name = 'input_' . str_replace( '.', '_', $field_id ); |
|
| 504 | + $entry[ strval( $field_id ) ] = RGFormsModel::prepare_value( $form, $field, $value, $input_name, $entry['id'], $entry ); |
|
| 505 | + } |
|
| 525 | 506 | |
| 526 | - break; |
|
| 507 | + break; |
|
| 508 | + case 'post_custom_field': |
|
| 527 | 509 | |
| 528 | - case 'post_image': |
|
| 510 | + $input_type = RGFormsModel::get_input_type( $field ); |
|
| 511 | + $custom_field_name = $field->postCustomFieldName; |
|
| 529 | 512 | |
| 530 | - $input_name = 'input_' . $field_id; |
|
| 513 | + // Only certain custom field types are supported |
|
| 514 | + switch( $input_type ) { |
|
| 515 | + case 'fileupload': |
|
| 516 | + /** @noinspection PhpMissingBreakStatementInspection */ |
|
| 517 | + case 'list': |
|
| 518 | + if( ! is_string( $value ) ) { |
|
| 519 | + $value = function_exists('wp_json_encode') ? wp_json_encode( $value ) : json_encode( $value ); |
|
| 520 | + } |
|
| 521 | + // break; left intentionally out |
|
| 522 | + default: |
|
| 523 | + update_post_meta( $post_id, $custom_field_name, $value ); |
|
| 524 | + } |
|
| 531 | 525 | |
| 532 | - if ( !empty( $_FILES[ $input_name ]['name'] ) ) { |
|
| 526 | + break; |
|
| 533 | 527 | |
| 534 | - // We have a new image |
|
| 528 | + case 'post_image': |
|
| 535 | 529 | |
| 536 | - $value = RGFormsModel::prepare_value( $form, $field, $value, $input_name, $entry['id'] ); |
|
| 530 | + $input_name = 'input_' . $field_id; |
|
| 537 | 531 | |
| 538 | - // is this field set as featured image, if not, leave |
|
| 539 | - if ( ! $field->postFeaturedImage ) { |
|
| 540 | - break; |
|
| 541 | - } |
|
| 532 | + if ( !empty( $_FILES[ $input_name ]['name'] ) ) { |
|
| 542 | 533 | |
| 543 | - $ary = ! empty( $value ) ? explode( '|:|', $value ) : array(); |
|
| 544 | - $img_url = rgar( $ary, 0 ); |
|
| 534 | + // We have a new image |
|
| 545 | 535 | |
| 546 | - $img_title = count( $ary ) > 1 ? $ary[1] : ''; |
|
| 547 | - $img_caption = count( $ary ) > 2 ? $ary[2] : ''; |
|
| 548 | - $img_description = count( $ary ) > 3 ? $ary[3] : ''; |
|
| 536 | + $value = RGFormsModel::prepare_value( $form, $field, $value, $input_name, $entry['id'] ); |
|
| 549 | 537 | |
| 550 | - $image_meta = array( |
|
| 551 | - 'post_excerpt' => $img_caption, |
|
| 552 | - 'post_content' => $img_description, |
|
| 553 | - ); |
|
| 538 | + // is this field set as featured image, if not, leave |
|
| 539 | + if ( ! $field->postFeaturedImage ) { |
|
| 540 | + break; |
|
| 541 | + } |
|
| 554 | 542 | |
| 555 | - //adding title only if it is not empty. It will default to the file name if it is not in the array |
|
| 556 | - if ( ! empty( $img_title ) ) { |
|
| 557 | - $image_meta['post_title'] = $img_title; |
|
| 558 | - } |
|
| 543 | + $ary = ! empty( $value ) ? explode( '|:|', $value ) : array(); |
|
| 544 | + $img_url = rgar( $ary, 0 ); |
|
| 559 | 545 | |
| 560 | - //todo: As soon as \GFFormsModel::media_handle_upload becomes a public method, move this call to \GFFormsModel::media_handle_upload and remove the hack from this class. |
|
| 561 | - require_once GRAVITYVIEW_DIR . 'includes/class-gravityview-gfformsmodel.php'; |
|
| 562 | - $media_id = GravityView_GFFormsModel::media_handle_upload( $img_url, $post_id, $image_meta ); |
|
| 546 | + $img_title = count( $ary ) > 1 ? $ary[1] : ''; |
|
| 547 | + $img_caption = count( $ary ) > 2 ? $ary[2] : ''; |
|
| 548 | + $img_description = count( $ary ) > 3 ? $ary[3] : ''; |
|
| 563 | 549 | |
| 564 | - if ( $media_id ) { |
|
| 565 | - set_post_thumbnail( $post_id, $media_id ); |
|
| 566 | - } |
|
| 550 | + $image_meta = array( |
|
| 551 | + 'post_excerpt' => $img_caption, |
|
| 552 | + 'post_content' => $img_description, |
|
| 553 | + ); |
|
| 567 | 554 | |
| 568 | - break; |
|
| 555 | + //adding title only if it is not empty. It will default to the file name if it is not in the array |
|
| 556 | + if ( ! empty( $img_title ) ) { |
|
| 557 | + $image_meta['post_title'] = $img_title; |
|
| 558 | + } |
|
| 569 | 559 | |
| 570 | - } elseif ( !empty( $_POST[ $input_name ] ) && is_array( $value ) ) { |
|
| 560 | + //todo: As soon as \GFFormsModel::media_handle_upload becomes a public method, move this call to \GFFormsModel::media_handle_upload and remove the hack from this class. |
|
| 561 | + require_once GRAVITYVIEW_DIR . 'includes/class-gravityview-gfformsmodel.php'; |
|
| 562 | + $media_id = GravityView_GFFormsModel::media_handle_upload( $img_url, $post_id, $image_meta ); |
|
| 571 | 563 | |
| 572 | - // Same image although the image title, caption or description might have changed |
|
| 564 | + if ( $media_id ) { |
|
| 565 | + set_post_thumbnail( $post_id, $media_id ); |
|
| 566 | + } |
|
| 573 | 567 | |
| 574 | - $ary = ! empty( $entry[ $field_id ] ) ? explode( '|:|', $entry[ $field_id ] ) : array(); |
|
| 575 | - $img_url = rgar( $ary, 0 ); |
|
| 568 | + break; |
|
| 576 | 569 | |
| 577 | - // is this really the same image or something went wrong ? |
|
| 578 | - if( $img_url === $_POST[ $input_name ] ) { |
|
| 570 | + } elseif ( !empty( $_POST[ $input_name ] ) && is_array( $value ) ) { |
|
| 579 | 571 | |
| 580 | - $img_title = isset( $value[ $field_id .'.1' ] ) ? $value[ $field_id .'.1' ] : ''; |
|
| 581 | - $img_caption = isset( $value[ $field_id .'.4' ] ) ? $value[ $field_id .'.4' ] : ''; |
|
| 582 | - $img_description = isset( $value[ $field_id .'.7' ] ) ? $value[ $field_id .'.7' ] : ''; |
|
| 572 | + // Same image although the image title, caption or description might have changed |
|
| 583 | 573 | |
| 584 | - $value = ! empty( $img_url ) ? $img_url . "|:|" . $img_title . "|:|" . $img_caption . "|:|" . $img_description : ''; |
|
| 574 | + $ary = ! empty( $entry[ $field_id ] ) ? explode( '|:|', $entry[ $field_id ] ) : array(); |
|
| 575 | + $img_url = rgar( $ary, 0 ); |
|
| 585 | 576 | |
| 586 | - if ( $field->postFeaturedImage ) { |
|
| 577 | + // is this really the same image or something went wrong ? |
|
| 578 | + if( $img_url === $_POST[ $input_name ] ) { |
|
| 587 | 579 | |
| 588 | - $image_meta = array( |
|
| 589 | - 'ID' => get_post_thumbnail_id( $post_id ), |
|
| 590 | - 'post_title' => $img_title, |
|
| 591 | - 'post_excerpt' => $img_caption, |
|
| 592 | - 'post_content' => $img_description, |
|
| 593 | - ); |
|
| 580 | + $img_title = isset( $value[ $field_id .'.1' ] ) ? $value[ $field_id .'.1' ] : ''; |
|
| 581 | + $img_caption = isset( $value[ $field_id .'.4' ] ) ? $value[ $field_id .'.4' ] : ''; |
|
| 582 | + $img_description = isset( $value[ $field_id .'.7' ] ) ? $value[ $field_id .'.7' ] : ''; |
|
| 594 | 583 | |
| 595 | - // update image title, caption or description |
|
| 596 | - wp_update_post( $image_meta ); |
|
| 597 | - } |
|
| 584 | + $value = ! empty( $img_url ) ? $img_url . "|:|" . $img_title . "|:|" . $img_caption . "|:|" . $img_description : ''; |
|
| 598 | 585 | |
| 599 | - break; |
|
| 600 | - } |
|
| 586 | + if ( $field->postFeaturedImage ) { |
|
| 601 | 587 | |
| 602 | - } |
|
| 588 | + $image_meta = array( |
|
| 589 | + 'ID' => get_post_thumbnail_id( $post_id ), |
|
| 590 | + 'post_title' => $img_title, |
|
| 591 | + 'post_excerpt' => $img_caption, |
|
| 592 | + 'post_content' => $img_description, |
|
| 593 | + ); |
|
| 603 | 594 | |
| 604 | - // if we get here, image was removed or not set. |
|
| 595 | + // update image title, caption or description |
|
| 596 | + wp_update_post( $image_meta ); |
|
| 597 | + } |
|
| 605 | 598 | |
| 606 | - $value = ''; |
|
| 607 | - if ( $field->postFeaturedImage ) { |
|
| 608 | - delete_post_thumbnail( $post_id ); |
|
| 609 | - } |
|
| 599 | + break; |
|
| 600 | + } |
|
| 610 | 601 | |
| 611 | - break; |
|
| 602 | + } |
|
| 612 | 603 | |
| 613 | - } |
|
| 604 | + // if we get here, image was removed or not set. |
|
| 614 | 605 | |
| 615 | - //ignore fields that have not changed |
|
| 616 | - if ( $value === rgget( (string) $field_id, $entry ) ) { |
|
| 617 | - continue; |
|
| 618 | - } |
|
| 606 | + $value = ''; |
|
| 607 | + if ( $field->postFeaturedImage ) { |
|
| 608 | + delete_post_thumbnail( $post_id ); |
|
| 609 | + } |
|
| 619 | 610 | |
| 620 | - // update entry |
|
| 621 | - if( 'post_category' !== $field->type ) { |
|
| 622 | - $entry[ strval( $field_id ) ] = $value; |
|
| 623 | - } |
|
| 611 | + break; |
|
| 624 | 612 | |
| 625 | - $update_entry = true; |
|
| 613 | + } |
|
| 626 | 614 | |
| 627 | - } |
|
| 615 | + //ignore fields that have not changed |
|
| 616 | + if ( $value === rgget( (string) $field_id, $entry ) ) { |
|
| 617 | + continue; |
|
| 618 | + } |
|
| 628 | 619 | |
| 629 | - } |
|
| 620 | + // update entry |
|
| 621 | + if( 'post_category' !== $field->type ) { |
|
| 622 | + $entry[ strval( $field_id ) ] = $value; |
|
| 623 | + } |
|
| 630 | 624 | |
| 631 | - if( $update_entry ) { |
|
| 625 | + $update_entry = true; |
|
| 632 | 626 | |
| 633 | - $return_entry = GFAPI::update_entry( $entry ); |
|
| 627 | + } |
|
| 628 | + |
|
| 629 | + } |
|
| 630 | + |
|
| 631 | + if( $update_entry ) { |
|
| 634 | 632 | |
| 635 | - if( is_wp_error( $return_entry ) ) { |
|
| 636 | - do_action( 'gravityview_log_error', 'Updating the entry post fields failed', $return_entry ); |
|
| 637 | - } else { |
|
| 638 | - do_action( 'gravityview_log_debug', 'Updating the entry post fields for post #'.$post_id.' succeeded' ); |
|
| 639 | - } |
|
| 633 | + $return_entry = GFAPI::update_entry( $entry ); |
|
| 640 | 634 | |
| 641 | - } |
|
| 635 | + if( is_wp_error( $return_entry ) ) { |
|
| 636 | + do_action( 'gravityview_log_error', 'Updating the entry post fields failed', $return_entry ); |
|
| 637 | + } else { |
|
| 638 | + do_action( 'gravityview_log_debug', 'Updating the entry post fields for post #'.$post_id.' succeeded' ); |
|
| 639 | + } |
|
| 640 | + |
|
| 641 | + } |
|
| 642 | 642 | |
| 643 | - $return_post = wp_update_post( $updated_post, true ); |
|
| 643 | + $return_post = wp_update_post( $updated_post, true ); |
|
| 644 | 644 | |
| 645 | - if( is_wp_error( $return_post ) ) { |
|
| 646 | - $return_post->add_data( $updated_post, '$updated_post' ); |
|
| 647 | - do_action( 'gravityview_log_error', 'Updating the post content failed', $return_post ); |
|
| 648 | - } else { |
|
| 649 | - do_action( 'gravityview_log_debug', 'Updating the post content for post #'.$post_id.' succeeded', $updated_post ); |
|
| 650 | - } |
|
| 645 | + if( is_wp_error( $return_post ) ) { |
|
| 646 | + $return_post->add_data( $updated_post, '$updated_post' ); |
|
| 647 | + do_action( 'gravityview_log_error', 'Updating the post content failed', $return_post ); |
|
| 648 | + } else { |
|
| 649 | + do_action( 'gravityview_log_debug', 'Updating the post content for post #'.$post_id.' succeeded', $updated_post ); |
|
| 650 | + } |
|
| 651 | 651 | |
| 652 | - } |
|
| 652 | + } |
|
| 653 | 653 | |
| 654 | 654 | |
| 655 | - /** |
|
| 656 | - * Perform actions normally performed after updating a lead |
|
| 657 | - * |
|
| 658 | - * @since 1.8 |
|
| 659 | - * |
|
| 660 | - * @see GFEntryDetail::lead_detail_page() |
|
| 661 | - * |
|
| 662 | - * @return void |
|
| 663 | - */ |
|
| 664 | - function after_update() { |
|
| 655 | + /** |
|
| 656 | + * Perform actions normally performed after updating a lead |
|
| 657 | + * |
|
| 658 | + * @since 1.8 |
|
| 659 | + * |
|
| 660 | + * @see GFEntryDetail::lead_detail_page() |
|
| 661 | + * |
|
| 662 | + * @return void |
|
| 663 | + */ |
|
| 664 | + function after_update() { |
|
| 665 | 665 | |
| 666 | - do_action( 'gform_after_update_entry', $this->form, $this->entry['id'] ); |
|
| 667 | - do_action( "gform_after_update_entry_{$this->form['id']}", $this->form, $this->entry['id'] ); |
|
| 666 | + do_action( 'gform_after_update_entry', $this->form, $this->entry['id'] ); |
|
| 667 | + do_action( "gform_after_update_entry_{$this->form['id']}", $this->form, $this->entry['id'] ); |
|
| 668 | 668 | |
| 669 | - // Re-define the entry now that we've updated it. |
|
| 670 | - $entry = RGFormsModel::get_lead( $this->entry['id'] ); |
|
| 669 | + // Re-define the entry now that we've updated it. |
|
| 670 | + $entry = RGFormsModel::get_lead( $this->entry['id'] ); |
|
| 671 | 671 | |
| 672 | - $entry = GFFormsModel::set_entry_meta( $entry, $this->form ); |
|
| 672 | + $entry = GFFormsModel::set_entry_meta( $entry, $this->form ); |
|
| 673 | 673 | |
| 674 | - // We need to clear the cache because Gravity Forms caches the field values, which |
|
| 675 | - // we have just updated. |
|
| 676 | - foreach ($this->form['fields'] as $key => $field) { |
|
| 677 | - GFFormsModel::refresh_lead_field_value( $entry['id'], $field->id ); |
|
| 678 | - } |
|
| 674 | + // We need to clear the cache because Gravity Forms caches the field values, which |
|
| 675 | + // we have just updated. |
|
| 676 | + foreach ($this->form['fields'] as $key => $field) { |
|
| 677 | + GFFormsModel::refresh_lead_field_value( $entry['id'], $field->id ); |
|
| 678 | + } |
|
| 679 | 679 | |
| 680 | - $this->entry = $entry; |
|
| 681 | - } |
|
| 680 | + $this->entry = $entry; |
|
| 681 | + } |
|
| 682 | 682 | |
| 683 | 683 | |
| 684 | - /** |
|
| 685 | - * Display the Edit Entry form |
|
| 686 | - * |
|
| 687 | - * @return [type] [description] |
|
| 688 | - */ |
|
| 689 | - public function edit_entry_form() { |
|
| 684 | + /** |
|
| 685 | + * Display the Edit Entry form |
|
| 686 | + * |
|
| 687 | + * @return [type] [description] |
|
| 688 | + */ |
|
| 689 | + public function edit_entry_form() { |
|
| 690 | 690 | |
| 691 | - ?> |
|
| 691 | + ?> |
|
| 692 | 692 | |
| 693 | 693 | <div class="gv-edit-entry-wrapper"><?php |
| 694 | 694 | |
| 695 | - $javascript = gravityview_ob_include( GravityView_Edit_Entry::$file .'/partials/inline-javascript.php', $this ); |
|
| 695 | + $javascript = gravityview_ob_include( GravityView_Edit_Entry::$file .'/partials/inline-javascript.php', $this ); |
|
| 696 | 696 | |
| 697 | - /** |
|
| 698 | - * Fixes weird wpautop() issue |
|
| 699 | - * @see https://github.com/katzwebservices/GravityView/issues/451 |
|
| 700 | - */ |
|
| 701 | - echo gravityview_strip_whitespace( $javascript ); |
|
| 697 | + /** |
|
| 698 | + * Fixes weird wpautop() issue |
|
| 699 | + * @see https://github.com/katzwebservices/GravityView/issues/451 |
|
| 700 | + */ |
|
| 701 | + echo gravityview_strip_whitespace( $javascript ); |
|
| 702 | 702 | |
| 703 | - ?><h2 class="gv-edit-entry-title"> |
|
| 703 | + ?><h2 class="gv-edit-entry-title"> |
|
| 704 | 704 | <span><?php |
| 705 | 705 | |
| 706 | - /** |
|
| 707 | - * @filter `gravityview_edit_entry_title` Modify the edit entry title |
|
| 708 | - * @param string $edit_entry_title Modify the "Edit Entry" title |
|
| 709 | - * @param GravityView_Edit_Entry_Render $this This object |
|
| 710 | - */ |
|
| 711 | - $edit_entry_title = apply_filters('gravityview_edit_entry_title', __('Edit Entry', 'gravityview'), $this ); |
|
| 706 | + /** |
|
| 707 | + * @filter `gravityview_edit_entry_title` Modify the edit entry title |
|
| 708 | + * @param string $edit_entry_title Modify the "Edit Entry" title |
|
| 709 | + * @param GravityView_Edit_Entry_Render $this This object |
|
| 710 | + */ |
|
| 711 | + $edit_entry_title = apply_filters('gravityview_edit_entry_title', __('Edit Entry', 'gravityview'), $this ); |
|
| 712 | 712 | |
| 713 | - echo esc_attr( $edit_entry_title ); |
|
| 714 | - ?></span> |
|
| 713 | + echo esc_attr( $edit_entry_title ); |
|
| 714 | + ?></span> |
|
| 715 | 715 | </h2> |
| 716 | 716 | |
| 717 | 717 | <?php $this->maybe_print_message(); ?> |
@@ -722,733 +722,733 @@ discard block |
||
| 722 | 722 | |
| 723 | 723 | <?php |
| 724 | 724 | |
| 725 | - wp_nonce_field( self::$nonce_key, self::$nonce_key ); |
|
| 725 | + wp_nonce_field( self::$nonce_key, self::$nonce_key ); |
|
| 726 | 726 | |
| 727 | - wp_nonce_field( self::$nonce_field, self::$nonce_field, false ); |
|
| 727 | + wp_nonce_field( self::$nonce_field, self::$nonce_field, false ); |
|
| 728 | 728 | |
| 729 | - // Print the actual form HTML |
|
| 730 | - $this->render_edit_form(); |
|
| 729 | + // Print the actual form HTML |
|
| 730 | + $this->render_edit_form(); |
|
| 731 | 731 | |
| 732 | - ?> |
|
| 732 | + ?> |
|
| 733 | 733 | </form> |
| 734 | 734 | |
| 735 | 735 | </div> |
| 736 | 736 | |
| 737 | 737 | <?php |
| 738 | - } |
|
| 739 | - |
|
| 740 | - /** |
|
| 741 | - * Display success or error message if the form has been submitted |
|
| 742 | - * |
|
| 743 | - * @uses GVCommon::generate_notice |
|
| 744 | - * |
|
| 745 | - * @since 1.16.2.2 |
|
| 746 | - * |
|
| 747 | - * @return void |
|
| 748 | - */ |
|
| 749 | - private function maybe_print_message() { |
|
| 750 | - |
|
| 751 | - if( rgpost('action') === 'update' ) { |
|
| 752 | - |
|
| 753 | - $back_link = esc_url( remove_query_arg( array( 'page', 'view', 'edit' ) ) ); |
|
| 754 | - |
|
| 755 | - if( ! $this->is_valid ){ |
|
| 756 | - |
|
| 757 | - // Keeping this compatible with Gravity Forms. |
|
| 758 | - $validation_message = "<div class='validation_error'>" . __('There was a problem with your submission.', 'gravityview') . " " . __('Errors have been highlighted below.', 'gravityview') . "</div>"; |
|
| 759 | - $message = apply_filters("gform_validation_message_{$this->form['id']}", apply_filters("gform_validation_message", $validation_message, $this->form), $this->form); |
|
| 760 | - |
|
| 761 | - echo GVCommon::generate_notice( $message , 'gv-error' ); |
|
| 762 | - |
|
| 763 | - } else { |
|
| 764 | - $entry_updated_message = sprintf( esc_attr__('Entry Updated. %sReturn to Entry%s', 'gravityview'), '<a href="'. $back_link .'">', '</a>' ); |
|
| 765 | - |
|
| 766 | - /** |
|
| 767 | - * @filter `gravityview/edit_entry/success` Modify the edit entry success message (including the anchor link) |
|
| 768 | - * @since 1.5.4 |
|
| 769 | - * @param string $entry_updated_message Existing message |
|
| 770 | - * @param int $view_id View ID |
|
| 771 | - * @param array $entry Gravity Forms entry array |
|
| 772 | - * @param string $back_link URL to return to the original entry. @since 1.6 |
|
| 773 | - */ |
|
| 774 | - $message = apply_filters( 'gravityview/edit_entry/success', $entry_updated_message , $this->view_id, $this->entry, $back_link ); |
|
| 775 | - |
|
| 776 | - echo GVCommon::generate_notice( $message ); |
|
| 777 | - } |
|
| 778 | - |
|
| 779 | - } |
|
| 780 | - } |
|
| 781 | - |
|
| 782 | - /** |
|
| 783 | - * Display the Edit Entry form in the original Gravity Forms format |
|
| 784 | - * |
|
| 785 | - * @since 1.9 |
|
| 786 | - * |
|
| 787 | - * @return void |
|
| 788 | - */ |
|
| 789 | - private function render_edit_form() { |
|
| 790 | - |
|
| 791 | - add_filter( 'gform_pre_render', array( $this, 'filter_modify_form_fields'), 5000, 3 ); |
|
| 792 | - add_filter( 'gform_submit_button', array( $this, 'render_form_buttons') ); |
|
| 793 | - add_filter( 'gform_disable_view_counter', '__return_true' ); |
|
| 794 | - |
|
| 795 | - add_filter( 'gform_field_input', array( $this, 'verify_user_can_edit_post' ), 5, 5 ); |
|
| 796 | - add_filter( 'gform_field_input', array( $this, 'modify_edit_field_input' ), 10, 5 ); |
|
| 797 | - |
|
| 798 | - add_filter( 'gform_field_value', array( $this, 'fix_survey_fields_value'), 10, 3 ); |
|
| 799 | - |
|
| 800 | - // We need to remove the fake $_GET['page'] arg to avoid rendering form as if in admin. |
|
| 801 | - unset( $_GET['page'] ); |
|
| 802 | - |
|
| 803 | - // TODO: Verify multiple-page forms |
|
| 804 | - // TODO: Product fields are not editable |
|
| 805 | - |
|
| 806 | - $html = GFFormDisplay::get_form( $this->form['id'], false, false, true, $this->entry ); |
|
| 807 | - |
|
| 808 | - remove_filter( 'gform_field_value', array( $this, 'fix_survey_fields_value'), 10 ); |
|
| 809 | - remove_filter( 'gform_pre_render', array( $this, 'filter_modify_form_fields' ), 5000 ); |
|
| 810 | - remove_filter( 'gform_submit_button', array( $this, 'render_form_buttons' ) ); |
|
| 811 | - remove_filter( 'gform_disable_view_counter', '__return_true' ); |
|
| 812 | - remove_filter( 'gform_field_input', array( $this, 'verify_user_can_edit_post' ), 5 ); |
|
| 813 | - remove_filter( 'gform_field_input', array( $this, 'modify_edit_field_input' ), 10 ); |
|
| 814 | - |
|
| 815 | - echo $html; |
|
| 816 | - } |
|
| 817 | - |
|
| 818 | - /** |
|
| 819 | - * Survey fields inject their output using `gform_field_input` filter, but in Edit Entry, the values were empty. |
|
| 820 | - * We filter the values here because it was the easiest access point: tell the survey field the correct value, GF outputs it. |
|
| 821 | - * |
|
| 822 | - * @since 1.16.4 |
|
| 823 | - * |
|
| 824 | - * @param string $value Existing value |
|
| 825 | - * @param GF_Field $field |
|
| 826 | - * @param string $name Field custom parameter name, normally blank. |
|
| 827 | - * |
|
| 828 | - * @return mixed |
|
| 829 | - */ |
|
| 830 | - function fix_survey_fields_value( $value, $field, $name ) { |
|
| 738 | + } |
|
| 739 | + |
|
| 740 | + /** |
|
| 741 | + * Display success or error message if the form has been submitted |
|
| 742 | + * |
|
| 743 | + * @uses GVCommon::generate_notice |
|
| 744 | + * |
|
| 745 | + * @since 1.16.2.2 |
|
| 746 | + * |
|
| 747 | + * @return void |
|
| 748 | + */ |
|
| 749 | + private function maybe_print_message() { |
|
| 750 | + |
|
| 751 | + if( rgpost('action') === 'update' ) { |
|
| 752 | + |
|
| 753 | + $back_link = esc_url( remove_query_arg( array( 'page', 'view', 'edit' ) ) ); |
|
| 754 | + |
|
| 755 | + if( ! $this->is_valid ){ |
|
| 756 | + |
|
| 757 | + // Keeping this compatible with Gravity Forms. |
|
| 758 | + $validation_message = "<div class='validation_error'>" . __('There was a problem with your submission.', 'gravityview') . " " . __('Errors have been highlighted below.', 'gravityview') . "</div>"; |
|
| 759 | + $message = apply_filters("gform_validation_message_{$this->form['id']}", apply_filters("gform_validation_message", $validation_message, $this->form), $this->form); |
|
| 760 | + |
|
| 761 | + echo GVCommon::generate_notice( $message , 'gv-error' ); |
|
| 762 | + |
|
| 763 | + } else { |
|
| 764 | + $entry_updated_message = sprintf( esc_attr__('Entry Updated. %sReturn to Entry%s', 'gravityview'), '<a href="'. $back_link .'">', '</a>' ); |
|
| 765 | + |
|
| 766 | + /** |
|
| 767 | + * @filter `gravityview/edit_entry/success` Modify the edit entry success message (including the anchor link) |
|
| 768 | + * @since 1.5.4 |
|
| 769 | + * @param string $entry_updated_message Existing message |
|
| 770 | + * @param int $view_id View ID |
|
| 771 | + * @param array $entry Gravity Forms entry array |
|
| 772 | + * @param string $back_link URL to return to the original entry. @since 1.6 |
|
| 773 | + */ |
|
| 774 | + $message = apply_filters( 'gravityview/edit_entry/success', $entry_updated_message , $this->view_id, $this->entry, $back_link ); |
|
| 775 | + |
|
| 776 | + echo GVCommon::generate_notice( $message ); |
|
| 777 | + } |
|
| 778 | + |
|
| 779 | + } |
|
| 780 | + } |
|
| 781 | + |
|
| 782 | + /** |
|
| 783 | + * Display the Edit Entry form in the original Gravity Forms format |
|
| 784 | + * |
|
| 785 | + * @since 1.9 |
|
| 786 | + * |
|
| 787 | + * @return void |
|
| 788 | + */ |
|
| 789 | + private function render_edit_form() { |
|
| 790 | + |
|
| 791 | + add_filter( 'gform_pre_render', array( $this, 'filter_modify_form_fields'), 5000, 3 ); |
|
| 792 | + add_filter( 'gform_submit_button', array( $this, 'render_form_buttons') ); |
|
| 793 | + add_filter( 'gform_disable_view_counter', '__return_true' ); |
|
| 794 | + |
|
| 795 | + add_filter( 'gform_field_input', array( $this, 'verify_user_can_edit_post' ), 5, 5 ); |
|
| 796 | + add_filter( 'gform_field_input', array( $this, 'modify_edit_field_input' ), 10, 5 ); |
|
| 797 | + |
|
| 798 | + add_filter( 'gform_field_value', array( $this, 'fix_survey_fields_value'), 10, 3 ); |
|
| 799 | + |
|
| 800 | + // We need to remove the fake $_GET['page'] arg to avoid rendering form as if in admin. |
|
| 801 | + unset( $_GET['page'] ); |
|
| 802 | + |
|
| 803 | + // TODO: Verify multiple-page forms |
|
| 804 | + // TODO: Product fields are not editable |
|
| 805 | + |
|
| 806 | + $html = GFFormDisplay::get_form( $this->form['id'], false, false, true, $this->entry ); |
|
| 807 | + |
|
| 808 | + remove_filter( 'gform_field_value', array( $this, 'fix_survey_fields_value'), 10 ); |
|
| 809 | + remove_filter( 'gform_pre_render', array( $this, 'filter_modify_form_fields' ), 5000 ); |
|
| 810 | + remove_filter( 'gform_submit_button', array( $this, 'render_form_buttons' ) ); |
|
| 811 | + remove_filter( 'gform_disable_view_counter', '__return_true' ); |
|
| 812 | + remove_filter( 'gform_field_input', array( $this, 'verify_user_can_edit_post' ), 5 ); |
|
| 813 | + remove_filter( 'gform_field_input', array( $this, 'modify_edit_field_input' ), 10 ); |
|
| 814 | + |
|
| 815 | + echo $html; |
|
| 816 | + } |
|
| 817 | + |
|
| 818 | + /** |
|
| 819 | + * Survey fields inject their output using `gform_field_input` filter, but in Edit Entry, the values were empty. |
|
| 820 | + * We filter the values here because it was the easiest access point: tell the survey field the correct value, GF outputs it. |
|
| 821 | + * |
|
| 822 | + * @since 1.16.4 |
|
| 823 | + * |
|
| 824 | + * @param string $value Existing value |
|
| 825 | + * @param GF_Field $field |
|
| 826 | + * @param string $name Field custom parameter name, normally blank. |
|
| 827 | + * |
|
| 828 | + * @return mixed |
|
| 829 | + */ |
|
| 830 | + function fix_survey_fields_value( $value, $field, $name ) { |
|
| 831 | 831 | |
| 832 | - if( 'survey' === $field->type && '' === $value && 'likert' === rgar( $field, 'inputType' ) ) { |
|
| 833 | - |
|
| 834 | - // We need to run through each survey row until we find a match for expected values |
|
| 835 | - foreach ( $this->entry as $field_id => $field_value ) { |
|
| 836 | - |
|
| 837 | - if ( floor( $field_id ) !== floor( $field->id ) ) { |
|
| 838 | - continue; |
|
| 839 | - } |
|
| 840 | - |
|
| 841 | - if( rgar( $field, 'gsurveyLikertEnableMultipleRows' ) ) { |
|
| 842 | - list( $row_val, $col_val ) = explode( ':', $field_value, 2 ); |
|
| 843 | - |
|
| 844 | - // If the $name matches the $row_val, we are processing the correct row |
|
| 845 | - if( $row_val === $name ) { |
|
| 846 | - $value = $field_value; |
|
| 847 | - break; |
|
| 848 | - } |
|
| 849 | - } else { |
|
| 850 | - // When not processing multiple rows, the value is the $entry[ $field_id ] value. |
|
| 851 | - $value = $field_value; |
|
| 852 | - break; |
|
| 853 | - } |
|
| 832 | + if( 'survey' === $field->type && '' === $value && 'likert' === rgar( $field, 'inputType' ) ) { |
|
| 833 | + |
|
| 834 | + // We need to run through each survey row until we find a match for expected values |
|
| 835 | + foreach ( $this->entry as $field_id => $field_value ) { |
|
| 836 | + |
|
| 837 | + if ( floor( $field_id ) !== floor( $field->id ) ) { |
|
| 838 | + continue; |
|
| 839 | + } |
|
| 840 | + |
|
| 841 | + if( rgar( $field, 'gsurveyLikertEnableMultipleRows' ) ) { |
|
| 842 | + list( $row_val, $col_val ) = explode( ':', $field_value, 2 ); |
|
| 843 | + |
|
| 844 | + // If the $name matches the $row_val, we are processing the correct row |
|
| 845 | + if( $row_val === $name ) { |
|
| 846 | + $value = $field_value; |
|
| 847 | + break; |
|
| 848 | + } |
|
| 849 | + } else { |
|
| 850 | + // When not processing multiple rows, the value is the $entry[ $field_id ] value. |
|
| 851 | + $value = $field_value; |
|
| 852 | + break; |
|
| 853 | + } |
|
| 854 | + } |
|
| 855 | + } |
|
| 856 | + |
|
| 857 | + return $value; |
|
| 858 | + } |
|
| 859 | + |
|
| 860 | + /** |
|
| 861 | + * Display the Update/Cancel/Delete buttons for the Edit Entry form |
|
| 862 | + * @since 1.8 |
|
| 863 | + * @return string |
|
| 864 | + */ |
|
| 865 | + public function render_form_buttons() { |
|
| 866 | + return gravityview_ob_include( GravityView_Edit_Entry::$file .'/partials/form-buttons.php', $this ); |
|
| 867 | + } |
|
| 868 | + |
|
| 869 | + |
|
| 870 | + /** |
|
| 871 | + * Modify the form fields that are shown when using GFFormDisplay::get_form() |
|
| 872 | + * |
|
| 873 | + * By default, all fields will be shown. We only want the Edit Tab configured fields to be shown. |
|
| 874 | + * |
|
| 875 | + * @param array $form |
|
| 876 | + * @param boolean $ajax Whether in AJAX mode |
|
| 877 | + * @param array|string $field_values Passed parameters to the form |
|
| 878 | + * |
|
| 879 | + * @since 1.9 |
|
| 880 | + * |
|
| 881 | + * @return array Modified form array |
|
| 882 | + */ |
|
| 883 | + public function filter_modify_form_fields( $form, $ajax = false, $field_values = '' ) { |
|
| 884 | + |
|
| 885 | + // In case we have validated the form, use it to inject the validation results into the form render |
|
| 886 | + if( isset( $this->form_after_validation ) ) { |
|
| 887 | + $form = $this->form_after_validation; |
|
| 888 | + } else { |
|
| 889 | + $form['fields'] = $this->get_configured_edit_fields( $form, $this->view_id ); |
|
| 890 | + } |
|
| 891 | + |
|
| 892 | + $form = $this->filter_conditional_logic( $form ); |
|
| 893 | + |
|
| 894 | + // for now we don't support Save and Continue feature. |
|
| 895 | + if( ! self::$supports_save_and_continue ) { |
|
| 896 | + unset( $form['save'] ); |
|
| 897 | + } |
|
| 898 | + |
|
| 899 | + return $form; |
|
| 900 | + } |
|
| 901 | + |
|
| 902 | + /** |
|
| 903 | + * When displaying a field, check if it's a Post Field, and if so, make sure the post exists and current user has edit rights. |
|
| 904 | + * |
|
| 905 | + * @since 1.16.2.2 |
|
| 906 | + * |
|
| 907 | + * @param string $field_content Always empty. Returning not-empty overrides the input. |
|
| 908 | + * @param GF_Field $field |
|
| 909 | + * @param string|array $value If array, it's a field with multiple inputs. If string, single input. |
|
| 910 | + * @param int $lead_id Lead ID. Always 0 for the `gform_field_input` filter. |
|
| 911 | + * @param int $form_id Form ID |
|
| 912 | + * |
|
| 913 | + * @return string If error, the error message. If no error, blank string (modify_edit_field_input() runs next) |
|
| 914 | + */ |
|
| 915 | + function verify_user_can_edit_post( $field_content = '', $field, $value, $lead_id = 0, $form_id ) { |
|
| 916 | + |
|
| 917 | + if( GFCommon::is_post_field( $field ) ) { |
|
| 918 | + |
|
| 919 | + $message = null; |
|
| 920 | + |
|
| 921 | + // First, make sure they have the capability to edit the post. |
|
| 922 | + if( false === current_user_can( 'edit_post', $this->entry['post_id'] ) ) { |
|
| 923 | + |
|
| 924 | + /** |
|
| 925 | + * @filter `gravityview/edit_entry/unsupported_post_field_text` Modify the message when someone isn't able to edit a post |
|
| 926 | + * @param string $message The existing "You don't have permission..." text |
|
| 927 | + */ |
|
| 928 | + $message = apply_filters('gravityview/edit_entry/unsupported_post_field_text', __('You don’t have permission to edit this post.', 'gravityview') ); |
|
| 929 | + |
|
| 930 | + } elseif( null === get_post( $this->entry['post_id'] ) ) { |
|
| 931 | + /** |
|
| 932 | + * @filter `gravityview/edit_entry/no_post_text` Modify the message when someone is editing an entry attached to a post that no longer exists |
|
| 933 | + * @param string $message The existing "This field is not editable; the post no longer exists." text |
|
| 934 | + */ |
|
| 935 | + $message = apply_filters('gravityview/edit_entry/no_post_text', __('This field is not editable; the post no longer exists.', 'gravityview' ) ); |
|
| 936 | + } |
|
| 937 | + |
|
| 938 | + if( $message ) { |
|
| 939 | + $field_content = sprintf('<div class="ginput_container ginput_container_' . $field->type . '">%s</div>', wpautop( $message ) ); |
|
| 854 | 940 | } |
| 855 | - } |
|
| 856 | - |
|
| 857 | - return $value; |
|
| 858 | - } |
|
| 859 | - |
|
| 860 | - /** |
|
| 861 | - * Display the Update/Cancel/Delete buttons for the Edit Entry form |
|
| 862 | - * @since 1.8 |
|
| 863 | - * @return string |
|
| 864 | - */ |
|
| 865 | - public function render_form_buttons() { |
|
| 866 | - return gravityview_ob_include( GravityView_Edit_Entry::$file .'/partials/form-buttons.php', $this ); |
|
| 867 | - } |
|
| 868 | - |
|
| 869 | - |
|
| 870 | - /** |
|
| 871 | - * Modify the form fields that are shown when using GFFormDisplay::get_form() |
|
| 872 | - * |
|
| 873 | - * By default, all fields will be shown. We only want the Edit Tab configured fields to be shown. |
|
| 874 | - * |
|
| 875 | - * @param array $form |
|
| 876 | - * @param boolean $ajax Whether in AJAX mode |
|
| 877 | - * @param array|string $field_values Passed parameters to the form |
|
| 878 | - * |
|
| 879 | - * @since 1.9 |
|
| 880 | - * |
|
| 881 | - * @return array Modified form array |
|
| 882 | - */ |
|
| 883 | - public function filter_modify_form_fields( $form, $ajax = false, $field_values = '' ) { |
|
| 884 | - |
|
| 885 | - // In case we have validated the form, use it to inject the validation results into the form render |
|
| 886 | - if( isset( $this->form_after_validation ) ) { |
|
| 887 | - $form = $this->form_after_validation; |
|
| 888 | - } else { |
|
| 889 | - $form['fields'] = $this->get_configured_edit_fields( $form, $this->view_id ); |
|
| 890 | - } |
|
| 891 | - |
|
| 892 | - $form = $this->filter_conditional_logic( $form ); |
|
| 893 | - |
|
| 894 | - // for now we don't support Save and Continue feature. |
|
| 895 | - if( ! self::$supports_save_and_continue ) { |
|
| 896 | - unset( $form['save'] ); |
|
| 897 | - } |
|
| 898 | - |
|
| 899 | - return $form; |
|
| 900 | - } |
|
| 901 | - |
|
| 902 | - /** |
|
| 903 | - * When displaying a field, check if it's a Post Field, and if so, make sure the post exists and current user has edit rights. |
|
| 904 | - * |
|
| 905 | - * @since 1.16.2.2 |
|
| 906 | - * |
|
| 907 | - * @param string $field_content Always empty. Returning not-empty overrides the input. |
|
| 908 | - * @param GF_Field $field |
|
| 909 | - * @param string|array $value If array, it's a field with multiple inputs. If string, single input. |
|
| 910 | - * @param int $lead_id Lead ID. Always 0 for the `gform_field_input` filter. |
|
| 911 | - * @param int $form_id Form ID |
|
| 912 | - * |
|
| 913 | - * @return string If error, the error message. If no error, blank string (modify_edit_field_input() runs next) |
|
| 914 | - */ |
|
| 915 | - function verify_user_can_edit_post( $field_content = '', $field, $value, $lead_id = 0, $form_id ) { |
|
| 916 | - |
|
| 917 | - if( GFCommon::is_post_field( $field ) ) { |
|
| 918 | - |
|
| 919 | - $message = null; |
|
| 920 | - |
|
| 921 | - // First, make sure they have the capability to edit the post. |
|
| 922 | - if( false === current_user_can( 'edit_post', $this->entry['post_id'] ) ) { |
|
| 923 | - |
|
| 924 | - /** |
|
| 925 | - * @filter `gravityview/edit_entry/unsupported_post_field_text` Modify the message when someone isn't able to edit a post |
|
| 926 | - * @param string $message The existing "You don't have permission..." text |
|
| 927 | - */ |
|
| 928 | - $message = apply_filters('gravityview/edit_entry/unsupported_post_field_text', __('You don’t have permission to edit this post.', 'gravityview') ); |
|
| 929 | - |
|
| 930 | - } elseif( null === get_post( $this->entry['post_id'] ) ) { |
|
| 931 | - /** |
|
| 932 | - * @filter `gravityview/edit_entry/no_post_text` Modify the message when someone is editing an entry attached to a post that no longer exists |
|
| 933 | - * @param string $message The existing "This field is not editable; the post no longer exists." text |
|
| 934 | - */ |
|
| 935 | - $message = apply_filters('gravityview/edit_entry/no_post_text', __('This field is not editable; the post no longer exists.', 'gravityview' ) ); |
|
| 936 | - } |
|
| 937 | - |
|
| 938 | - if( $message ) { |
|
| 939 | - $field_content = sprintf('<div class="ginput_container ginput_container_' . $field->type . '">%s</div>', wpautop( $message ) ); |
|
| 940 | - } |
|
| 941 | - } |
|
| 942 | - |
|
| 943 | - return $field_content; |
|
| 944 | - } |
|
| 945 | - |
|
| 946 | - /** |
|
| 947 | - * |
|
| 948 | - * Fill-in the saved values into the form inputs |
|
| 949 | - * |
|
| 950 | - * @param string $field_content Always empty. Returning not-empty overrides the input. |
|
| 951 | - * @param GF_Field $field |
|
| 952 | - * @param string|array $value If array, it's a field with multiple inputs. If string, single input. |
|
| 953 | - * @param int $lead_id Lead ID. Always 0 for the `gform_field_input` filter. |
|
| 954 | - * @param int $form_id Form ID |
|
| 955 | - * |
|
| 956 | - * @return mixed |
|
| 957 | - */ |
|
| 958 | - function modify_edit_field_input( $field_content = '', $field, $value, $lead_id = 0, $form_id ) { |
|
| 959 | - |
|
| 960 | - $gv_field = GravityView_Fields::get_associated_field( $field ); |
|
| 961 | - |
|
| 962 | - // If the form has been submitted, then we don't need to pre-fill the values, |
|
| 963 | - // Except for fileupload type and when a field input is overridden- run always!! |
|
| 964 | - if( |
|
| 965 | - ( $this->is_edit_entry_submission() && !in_array( $field->type, array( 'fileupload', 'post_image' ) ) ) |
|
| 966 | - && false === ( $gv_field && is_callable( array( $gv_field, 'get_field_input' ) ) ) |
|
| 967 | - || ! empty( $field_content ) |
|
| 968 | - || GFCommon::is_product_field( $field->type ) // Prevent product fields from appearing editable |
|
| 969 | - ) { |
|
| 970 | - return $field_content; |
|
| 971 | - } |
|
| 972 | - |
|
| 973 | - // Turn on Admin-style display for file upload fields only |
|
| 974 | - if( 'fileupload' === $field->type ) { |
|
| 975 | - $_GET['page'] = 'gf_entries'; |
|
| 976 | - } |
|
| 977 | - |
|
| 978 | - // SET SOME FIELD DEFAULTS TO PREVENT ISSUES |
|
| 979 | - $field->adminOnly = false; /** @see GFFormDisplay::get_counter_init_script() need to prevent adminOnly */ |
|
| 980 | - |
|
| 981 | - // add categories as choices for Post Category field |
|
| 982 | - if ( 'post_category' === $field->type ) { |
|
| 983 | - $field = GFCommon::add_categories_as_choices( $field, $value ); |
|
| 984 | - } |
|
| 985 | - |
|
| 986 | - $field_value = $this->get_field_value( $field ); |
|
| 987 | - |
|
| 988 | - /** |
|
| 989 | - * @filter `gravityview/edit_entry/field_value` Change the value of an Edit Entry field, if needed |
|
| 990 | - * @since 1.11 |
|
| 991 | - * @param mixed $field_value field value used to populate the input |
|
| 992 | - * @param object $field Gravity Forms field object ( Class GF_Field ) |
|
| 993 | - */ |
|
| 994 | - $field_value = apply_filters( 'gravityview/edit_entry/field_value', $field_value, $field ); |
|
| 995 | - |
|
| 996 | - // Prevent any PHP warnings, like undefined index |
|
| 997 | - ob_start(); |
|
| 998 | - |
|
| 999 | - if( $gv_field && is_callable( array( $gv_field, 'get_field_input' ) ) ) { |
|
| 1000 | - /** @var GF_Field $gv_field */ |
|
| 1001 | - $return = $gv_field->get_field_input( $this->form, $field_value, $this->entry, $field ); |
|
| 1002 | - } else { |
|
| 1003 | - $return = $field->get_field_input( $this->form, $field_value, $this->entry ); |
|
| 1004 | - } |
|
| 1005 | - |
|
| 1006 | - |
|
| 1007 | - // If there was output, it's an error |
|
| 1008 | - $warnings = ob_get_clean(); |
|
| 1009 | - |
|
| 1010 | - if( !empty( $warnings ) ) { |
|
| 1011 | - do_action( 'gravityview_log_error', __METHOD__ . $warnings, $field_value ); |
|
| 1012 | - } |
|
| 1013 | - |
|
| 1014 | - /** |
|
| 1015 | - * Unset hack $_GET['page'] = 'gf_entries' |
|
| 1016 | - * We need the fileupload html field to render with the proper id |
|
| 1017 | - * ( <li id="field_80_16" ... > ) |
|
| 1018 | - */ |
|
| 1019 | - unset( $_GET['page'] ); |
|
| 1020 | - |
|
| 1021 | - return $return; |
|
| 1022 | - } |
|
| 1023 | - |
|
| 1024 | - /** |
|
| 1025 | - * Modify the value for the current field input |
|
| 1026 | - * |
|
| 1027 | - * @param GF_Field $field |
|
| 1028 | - * |
|
| 1029 | - * @return array|mixed|string|void |
|
| 1030 | - */ |
|
| 1031 | - private function get_field_value( $field ) { |
|
| 1032 | - |
|
| 1033 | - /** |
|
| 1034 | - * @filter `gravityview/edit_entry/pre_populate/override` Allow the pre-populated value to override saved value in Edit Entry form. By default, pre-populate mechanism only kicks on empty fields. |
|
| 1035 | - * @param boolean True: override saved values; False: don't override (default) |
|
| 1036 | - * @param $field GF_Field object Gravity Forms field object |
|
| 1037 | - * @since 1.13 |
|
| 1038 | - */ |
|
| 1039 | - $override_saved_value = apply_filters( 'gravityview/edit_entry/pre_populate/override', false, $field ); |
|
| 1040 | - |
|
| 1041 | - // We're dealing with multiple inputs (e.g. checkbox) but not time or date (as it doesn't store data in input IDs) |
|
| 1042 | - if( isset( $field->inputs ) && is_array( $field->inputs ) && !in_array( $field->type, array( 'time', 'date' ) ) ) { |
|
| 1043 | - |
|
| 1044 | - $field_value = array(); |
|
| 1045 | - |
|
| 1046 | - // only accept pre-populated values if the field doesn't have any choice selected. |
|
| 1047 | - $allow_pre_populated = $field->allowsPrepopulate; |
|
| 1048 | - |
|
| 1049 | - foreach ( (array)$field->inputs as $input ) { |
|
| 1050 | - |
|
| 1051 | - $input_id = strval( $input['id'] ); |
|
| 941 | + } |
|
| 942 | + |
|
| 943 | + return $field_content; |
|
| 944 | + } |
|
| 945 | + |
|
| 946 | + /** |
|
| 947 | + * |
|
| 948 | + * Fill-in the saved values into the form inputs |
|
| 949 | + * |
|
| 950 | + * @param string $field_content Always empty. Returning not-empty overrides the input. |
|
| 951 | + * @param GF_Field $field |
|
| 952 | + * @param string|array $value If array, it's a field with multiple inputs. If string, single input. |
|
| 953 | + * @param int $lead_id Lead ID. Always 0 for the `gform_field_input` filter. |
|
| 954 | + * @param int $form_id Form ID |
|
| 955 | + * |
|
| 956 | + * @return mixed |
|
| 957 | + */ |
|
| 958 | + function modify_edit_field_input( $field_content = '', $field, $value, $lead_id = 0, $form_id ) { |
|
| 959 | + |
|
| 960 | + $gv_field = GravityView_Fields::get_associated_field( $field ); |
|
| 961 | + |
|
| 962 | + // If the form has been submitted, then we don't need to pre-fill the values, |
|
| 963 | + // Except for fileupload type and when a field input is overridden- run always!! |
|
| 964 | + if( |
|
| 965 | + ( $this->is_edit_entry_submission() && !in_array( $field->type, array( 'fileupload', 'post_image' ) ) ) |
|
| 966 | + && false === ( $gv_field && is_callable( array( $gv_field, 'get_field_input' ) ) ) |
|
| 967 | + || ! empty( $field_content ) |
|
| 968 | + || GFCommon::is_product_field( $field->type ) // Prevent product fields from appearing editable |
|
| 969 | + ) { |
|
| 970 | + return $field_content; |
|
| 971 | + } |
|
| 972 | + |
|
| 973 | + // Turn on Admin-style display for file upload fields only |
|
| 974 | + if( 'fileupload' === $field->type ) { |
|
| 975 | + $_GET['page'] = 'gf_entries'; |
|
| 976 | + } |
|
| 977 | + |
|
| 978 | + // SET SOME FIELD DEFAULTS TO PREVENT ISSUES |
|
| 979 | + $field->adminOnly = false; /** @see GFFormDisplay::get_counter_init_script() need to prevent adminOnly */ |
|
| 980 | + |
|
| 981 | + // add categories as choices for Post Category field |
|
| 982 | + if ( 'post_category' === $field->type ) { |
|
| 983 | + $field = GFCommon::add_categories_as_choices( $field, $value ); |
|
| 984 | + } |
|
| 985 | + |
|
| 986 | + $field_value = $this->get_field_value( $field ); |
|
| 987 | + |
|
| 988 | + /** |
|
| 989 | + * @filter `gravityview/edit_entry/field_value` Change the value of an Edit Entry field, if needed |
|
| 990 | + * @since 1.11 |
|
| 991 | + * @param mixed $field_value field value used to populate the input |
|
| 992 | + * @param object $field Gravity Forms field object ( Class GF_Field ) |
|
| 993 | + */ |
|
| 994 | + $field_value = apply_filters( 'gravityview/edit_entry/field_value', $field_value, $field ); |
|
| 995 | + |
|
| 996 | + // Prevent any PHP warnings, like undefined index |
|
| 997 | + ob_start(); |
|
| 998 | + |
|
| 999 | + if( $gv_field && is_callable( array( $gv_field, 'get_field_input' ) ) ) { |
|
| 1000 | + /** @var GF_Field $gv_field */ |
|
| 1001 | + $return = $gv_field->get_field_input( $this->form, $field_value, $this->entry, $field ); |
|
| 1002 | + } else { |
|
| 1003 | + $return = $field->get_field_input( $this->form, $field_value, $this->entry ); |
|
| 1004 | + } |
|
| 1005 | + |
|
| 1006 | + |
|
| 1007 | + // If there was output, it's an error |
|
| 1008 | + $warnings = ob_get_clean(); |
|
| 1009 | + |
|
| 1010 | + if( !empty( $warnings ) ) { |
|
| 1011 | + do_action( 'gravityview_log_error', __METHOD__ . $warnings, $field_value ); |
|
| 1012 | + } |
|
| 1013 | + |
|
| 1014 | + /** |
|
| 1015 | + * Unset hack $_GET['page'] = 'gf_entries' |
|
| 1016 | + * We need the fileupload html field to render with the proper id |
|
| 1017 | + * ( <li id="field_80_16" ... > ) |
|
| 1018 | + */ |
|
| 1019 | + unset( $_GET['page'] ); |
|
| 1020 | + |
|
| 1021 | + return $return; |
|
| 1022 | + } |
|
| 1023 | + |
|
| 1024 | + /** |
|
| 1025 | + * Modify the value for the current field input |
|
| 1026 | + * |
|
| 1027 | + * @param GF_Field $field |
|
| 1028 | + * |
|
| 1029 | + * @return array|mixed|string|void |
|
| 1030 | + */ |
|
| 1031 | + private function get_field_value( $field ) { |
|
| 1032 | + |
|
| 1033 | + /** |
|
| 1034 | + * @filter `gravityview/edit_entry/pre_populate/override` Allow the pre-populated value to override saved value in Edit Entry form. By default, pre-populate mechanism only kicks on empty fields. |
|
| 1035 | + * @param boolean True: override saved values; False: don't override (default) |
|
| 1036 | + * @param $field GF_Field object Gravity Forms field object |
|
| 1037 | + * @since 1.13 |
|
| 1038 | + */ |
|
| 1039 | + $override_saved_value = apply_filters( 'gravityview/edit_entry/pre_populate/override', false, $field ); |
|
| 1040 | + |
|
| 1041 | + // We're dealing with multiple inputs (e.g. checkbox) but not time or date (as it doesn't store data in input IDs) |
|
| 1042 | + if( isset( $field->inputs ) && is_array( $field->inputs ) && !in_array( $field->type, array( 'time', 'date' ) ) ) { |
|
| 1043 | + |
|
| 1044 | + $field_value = array(); |
|
| 1045 | + |
|
| 1046 | + // only accept pre-populated values if the field doesn't have any choice selected. |
|
| 1047 | + $allow_pre_populated = $field->allowsPrepopulate; |
|
| 1048 | + |
|
| 1049 | + foreach ( (array)$field->inputs as $input ) { |
|
| 1050 | + |
|
| 1051 | + $input_id = strval( $input['id'] ); |
|
| 1052 | 1052 | |
| 1053 | - if ( isset( $this->entry[ $input_id ] ) && ! gv_empty( $this->entry[ $input_id ], false, false ) ) { |
|
| 1054 | - $field_value[ $input_id ] = 'post_category' === $field->type ? GFCommon::format_post_category( $this->entry[ $input_id ], true ) : $this->entry[ $input_id ]; |
|
| 1055 | - $allow_pre_populated = false; |
|
| 1056 | - } |
|
| 1053 | + if ( isset( $this->entry[ $input_id ] ) && ! gv_empty( $this->entry[ $input_id ], false, false ) ) { |
|
| 1054 | + $field_value[ $input_id ] = 'post_category' === $field->type ? GFCommon::format_post_category( $this->entry[ $input_id ], true ) : $this->entry[ $input_id ]; |
|
| 1055 | + $allow_pre_populated = false; |
|
| 1056 | + } |
|
| 1057 | 1057 | |
| 1058 | - } |
|
| 1058 | + } |
|
| 1059 | 1059 | |
| 1060 | - $pre_value = $field->get_value_submission( array(), false ); |
|
| 1060 | + $pre_value = $field->get_value_submission( array(), false ); |
|
| 1061 | 1061 | |
| 1062 | - $field_value = ! $allow_pre_populated && ! ( $override_saved_value && !gv_empty( $pre_value, false, false ) ) ? $field_value : $pre_value; |
|
| 1062 | + $field_value = ! $allow_pre_populated && ! ( $override_saved_value && !gv_empty( $pre_value, false, false ) ) ? $field_value : $pre_value; |
|
| 1063 | 1063 | |
| 1064 | - } else { |
|
| 1064 | + } else { |
|
| 1065 | 1065 | |
| 1066 | - $id = intval( $field->id ); |
|
| 1066 | + $id = intval( $field->id ); |
|
| 1067 | 1067 | |
| 1068 | - // get pre-populated value if exists |
|
| 1069 | - $pre_value = $field->allowsPrepopulate ? GFFormsModel::get_parameter_value( $field->inputName, array(), $field ) : ''; |
|
| 1068 | + // get pre-populated value if exists |
|
| 1069 | + $pre_value = $field->allowsPrepopulate ? GFFormsModel::get_parameter_value( $field->inputName, array(), $field ) : ''; |
|
| 1070 | 1070 | |
| 1071 | - // saved field entry value (if empty, fallback to the pre-populated value, if exists) |
|
| 1072 | - // or pre-populated value if not empty and set to override saved value |
|
| 1073 | - $field_value = !gv_empty( $this->entry[ $id ], false, false ) && ! ( $override_saved_value && !gv_empty( $pre_value, false, false ) ) ? $this->entry[ $id ] : $pre_value; |
|
| 1071 | + // saved field entry value (if empty, fallback to the pre-populated value, if exists) |
|
| 1072 | + // or pre-populated value if not empty and set to override saved value |
|
| 1073 | + $field_value = !gv_empty( $this->entry[ $id ], false, false ) && ! ( $override_saved_value && !gv_empty( $pre_value, false, false ) ) ? $this->entry[ $id ] : $pre_value; |
|
| 1074 | 1074 | |
| 1075 | - // in case field is post_category but inputType is select, multi-select or radio, convert value into array of category IDs. |
|
| 1076 | - if ( 'post_category' === $field->type && !gv_empty( $field_value, false, false ) ) { |
|
| 1077 | - $categories = array(); |
|
| 1078 | - foreach ( explode( ',', $field_value ) as $cat_string ) { |
|
| 1079 | - $categories[] = GFCommon::format_post_category( $cat_string, true ); |
|
| 1080 | - } |
|
| 1081 | - $field_value = 'multiselect' === $field->get_input_type() ? $categories : implode( '', $categories ); |
|
| 1082 | - } |
|
| 1075 | + // in case field is post_category but inputType is select, multi-select or radio, convert value into array of category IDs. |
|
| 1076 | + if ( 'post_category' === $field->type && !gv_empty( $field_value, false, false ) ) { |
|
| 1077 | + $categories = array(); |
|
| 1078 | + foreach ( explode( ',', $field_value ) as $cat_string ) { |
|
| 1079 | + $categories[] = GFCommon::format_post_category( $cat_string, true ); |
|
| 1080 | + } |
|
| 1081 | + $field_value = 'multiselect' === $field->get_input_type() ? $categories : implode( '', $categories ); |
|
| 1082 | + } |
|
| 1083 | 1083 | |
| 1084 | - } |
|
| 1084 | + } |
|
| 1085 | 1085 | |
| 1086 | - // if value is empty get the default value if defined |
|
| 1087 | - $field_value = $field->get_value_default_if_empty( $field_value ); |
|
| 1086 | + // if value is empty get the default value if defined |
|
| 1087 | + $field_value = $field->get_value_default_if_empty( $field_value ); |
|
| 1088 | 1088 | |
| 1089 | - return $field_value; |
|
| 1090 | - } |
|
| 1089 | + return $field_value; |
|
| 1090 | + } |
|
| 1091 | 1091 | |
| 1092 | 1092 | |
| 1093 | - // ---- Entry validation |
|
| 1093 | + // ---- Entry validation |
|
| 1094 | 1094 | |
| 1095 | - /** |
|
| 1096 | - * Add field keys that Gravity Forms expects. |
|
| 1097 | - * |
|
| 1098 | - * @see GFFormDisplay::validate() |
|
| 1099 | - * @param array $form GF Form |
|
| 1100 | - * @return array Modified GF Form |
|
| 1101 | - */ |
|
| 1102 | - function gform_pre_validation( $form ) { |
|
| 1095 | + /** |
|
| 1096 | + * Add field keys that Gravity Forms expects. |
|
| 1097 | + * |
|
| 1098 | + * @see GFFormDisplay::validate() |
|
| 1099 | + * @param array $form GF Form |
|
| 1100 | + * @return array Modified GF Form |
|
| 1101 | + */ |
|
| 1102 | + function gform_pre_validation( $form ) { |
|
| 1103 | 1103 | |
| 1104 | - if( ! $this->verify_nonce() ) { |
|
| 1105 | - return $form; |
|
| 1106 | - } |
|
| 1104 | + if( ! $this->verify_nonce() ) { |
|
| 1105 | + return $form; |
|
| 1106 | + } |
|
| 1107 | 1107 | |
| 1108 | - // Fix PHP warning regarding undefined index. |
|
| 1109 | - foreach ( $form['fields'] as &$field) { |
|
| 1108 | + // Fix PHP warning regarding undefined index. |
|
| 1109 | + foreach ( $form['fields'] as &$field) { |
|
| 1110 | 1110 | |
| 1111 | - // This is because we're doing admin form pretending to be front-end, so Gravity Forms |
|
| 1112 | - // expects certain field array items to be set. |
|
| 1113 | - foreach ( array( 'noDuplicates', 'adminOnly', 'inputType', 'isRequired', 'enablePrice', 'inputs', 'allowedExtensions' ) as $key ) { |
|
| 1114 | - $field->{$key} = isset( $field->{$key} ) ? $field->{$key} : NULL; |
|
| 1115 | - } |
|
| 1111 | + // This is because we're doing admin form pretending to be front-end, so Gravity Forms |
|
| 1112 | + // expects certain field array items to be set. |
|
| 1113 | + foreach ( array( 'noDuplicates', 'adminOnly', 'inputType', 'isRequired', 'enablePrice', 'inputs', 'allowedExtensions' ) as $key ) { |
|
| 1114 | + $field->{$key} = isset( $field->{$key} ) ? $field->{$key} : NULL; |
|
| 1115 | + } |
|
| 1116 | 1116 | |
| 1117 | - // unset emailConfirmEnabled for email type fields |
|
| 1118 | - /* if( 'email' === $field['type'] && !empty( $field['emailConfirmEnabled'] ) ) { |
|
| 1117 | + // unset emailConfirmEnabled for email type fields |
|
| 1118 | + /* if( 'email' === $field['type'] && !empty( $field['emailConfirmEnabled'] ) ) { |
|
| 1119 | 1119 | $field['emailConfirmEnabled'] = ''; |
| 1120 | 1120 | }*/ |
| 1121 | 1121 | |
| 1122 | - switch( RGFormsModel::get_input_type( $field ) ) { |
|
| 1122 | + switch( RGFormsModel::get_input_type( $field ) ) { |
|
| 1123 | 1123 | |
| 1124 | - /** |
|
| 1125 | - * this whole fileupload hack is because in the admin, Gravity Forms simply doesn't update any fileupload field if it's empty, but it DOES in the frontend. |
|
| 1126 | - * |
|
| 1127 | - * What we have to do is set the value so that it doesn't get overwritten as empty on save and appears immediately in the Edit Entry screen again. |
|
| 1128 | - * |
|
| 1129 | - * @hack |
|
| 1130 | - */ |
|
| 1131 | - case 'fileupload': |
|
| 1132 | - |
|
| 1133 | - // Set the previous value |
|
| 1134 | - $entry = $this->get_entry(); |
|
| 1135 | - |
|
| 1136 | - $input_name = 'input_'.$field->id; |
|
| 1137 | - $form_id = $form['id']; |
|
| 1138 | - |
|
| 1139 | - $value = NULL; |
|
| 1140 | - |
|
| 1141 | - // Use the previous entry value as the default. |
|
| 1142 | - if( isset( $entry[ $field->id ] ) ) { |
|
| 1143 | - $value = $entry[ $field->id ]; |
|
| 1144 | - } |
|
| 1124 | + /** |
|
| 1125 | + * this whole fileupload hack is because in the admin, Gravity Forms simply doesn't update any fileupload field if it's empty, but it DOES in the frontend. |
|
| 1126 | + * |
|
| 1127 | + * What we have to do is set the value so that it doesn't get overwritten as empty on save and appears immediately in the Edit Entry screen again. |
|
| 1128 | + * |
|
| 1129 | + * @hack |
|
| 1130 | + */ |
|
| 1131 | + case 'fileupload': |
|
| 1145 | 1132 | |
| 1146 | - // If this is a single upload file |
|
| 1147 | - if( !empty( $_FILES[ $input_name ] ) && !empty( $_FILES[ $input_name ]['name'] ) ) { |
|
| 1148 | - $file_path = GFFormsModel::get_file_upload_path( $form['id'], $_FILES[ $input_name ]['name'] ); |
|
| 1149 | - $value = $file_path['url']; |
|
| 1133 | + // Set the previous value |
|
| 1134 | + $entry = $this->get_entry(); |
|
| 1150 | 1135 | |
| 1151 | - } else { |
|
| 1152 | - |
|
| 1153 | - // Fix PHP warning on line 1498 of form_display.php for post_image fields |
|
| 1154 | - // Fix PHP Notice: Undefined index: size in form_display.php on line 1511 |
|
| 1155 | - $_FILES[ $input_name ] = array('name' => '', 'size' => '' ); |
|
| 1156 | - |
|
| 1157 | - } |
|
| 1158 | - |
|
| 1159 | - if( rgar($field, "multipleFiles") ) { |
|
| 1160 | - |
|
| 1161 | - // If there are fresh uploads, process and merge them. |
|
| 1162 | - // Otherwise, use the passed values, which should be json-encoded array of URLs |
|
| 1163 | - if( isset( GFFormsModel::$uploaded_files[$form_id][$input_name] ) ) { |
|
| 1164 | - $value = empty( $value ) ? '[]' : $value; |
|
| 1165 | - $value = stripslashes_deep( $value ); |
|
| 1166 | - $value = GFFormsModel::prepare_value( $form, $field, $value, $input_name, $entry['id'], array()); |
|
| 1167 | - } |
|
| 1136 | + $input_name = 'input_'.$field->id; |
|
| 1137 | + $form_id = $form['id']; |
|
| 1168 | 1138 | |
| 1169 | - } else { |
|
| 1139 | + $value = NULL; |
|
| 1170 | 1140 | |
| 1171 | - // A file already exists when editing an entry |
|
| 1172 | - // We set this to solve issue when file upload fields are required. |
|
| 1173 | - GFFormsModel::$uploaded_files[ $form_id ][ $input_name ] = $value; |
|
| 1141 | + // Use the previous entry value as the default. |
|
| 1142 | + if( isset( $entry[ $field->id ] ) ) { |
|
| 1143 | + $value = $entry[ $field->id ]; |
|
| 1144 | + } |
|
| 1174 | 1145 | |
| 1175 | - } |
|
| 1146 | + // If this is a single upload file |
|
| 1147 | + if( !empty( $_FILES[ $input_name ] ) && !empty( $_FILES[ $input_name ]['name'] ) ) { |
|
| 1148 | + $file_path = GFFormsModel::get_file_upload_path( $form['id'], $_FILES[ $input_name ]['name'] ); |
|
| 1149 | + $value = $file_path['url']; |
|
| 1176 | 1150 | |
| 1177 | - $this->entry[ $input_name ] = $value; |
|
| 1178 | - $_POST[ $input_name ] = $value; |
|
| 1151 | + } else { |
|
| 1179 | 1152 | |
| 1180 | - break; |
|
| 1153 | + // Fix PHP warning on line 1498 of form_display.php for post_image fields |
|
| 1154 | + // Fix PHP Notice: Undefined index: size in form_display.php on line 1511 |
|
| 1155 | + $_FILES[ $input_name ] = array('name' => '', 'size' => '' ); |
|
| 1181 | 1156 | |
| 1182 | - case 'number': |
|
| 1183 | - // Fix "undefined index" issue at line 1286 in form_display.php |
|
| 1184 | - if( !isset( $_POST['input_'.$field->id ] ) ) { |
|
| 1185 | - $_POST['input_'.$field->id ] = NULL; |
|
| 1186 | - } |
|
| 1187 | - break; |
|
| 1188 | - case 'captcha': |
|
| 1189 | - // Fix issue with recaptcha_check_answer() on line 1458 in form_display.php |
|
| 1190 | - $_POST['recaptcha_challenge_field'] = NULL; |
|
| 1191 | - $_POST['recaptcha_response_field'] = NULL; |
|
| 1192 | - break; |
|
| 1193 | - } |
|
| 1157 | + } |
|
| 1194 | 1158 | |
| 1195 | - } |
|
| 1159 | + if( rgar($field, "multipleFiles") ) { |
|
| 1196 | 1160 | |
| 1197 | - return $form; |
|
| 1198 | - } |
|
| 1161 | + // If there are fresh uploads, process and merge them. |
|
| 1162 | + // Otherwise, use the passed values, which should be json-encoded array of URLs |
|
| 1163 | + if( isset( GFFormsModel::$uploaded_files[$form_id][$input_name] ) ) { |
|
| 1164 | + $value = empty( $value ) ? '[]' : $value; |
|
| 1165 | + $value = stripslashes_deep( $value ); |
|
| 1166 | + $value = GFFormsModel::prepare_value( $form, $field, $value, $input_name, $entry['id'], array()); |
|
| 1167 | + } |
|
| 1199 | 1168 | |
| 1169 | + } else { |
|
| 1200 | 1170 | |
| 1201 | - /** |
|
| 1202 | - * Process validation for a edit entry submission |
|
| 1203 | - * |
|
| 1204 | - * Sets the `is_valid` object var |
|
| 1205 | - * |
|
| 1206 | - * @return void |
|
| 1207 | - */ |
|
| 1208 | - function validate() { |
|
| 1171 | + // A file already exists when editing an entry |
|
| 1172 | + // We set this to solve issue when file upload fields are required. |
|
| 1173 | + GFFormsModel::$uploaded_files[ $form_id ][ $input_name ] = $value; |
|
| 1209 | 1174 | |
| 1210 | - /** |
|
| 1211 | - * If using GF User Registration Add-on, remove the validation step, otherwise generates error when updating the entry |
|
| 1212 | - * GF User Registration Add-on version > 3.x has a different class name |
|
| 1213 | - * @since 1.16.2 |
|
| 1214 | - */ |
|
| 1215 | - if ( class_exists( 'GF_User_Registration' ) ) { |
|
| 1216 | - remove_filter( 'gform_validation', array( GF_User_Registration::get_instance(), 'validate' ) ); |
|
| 1217 | - } else if ( class_exists( 'GFUser' ) ) { |
|
| 1218 | - remove_filter( 'gform_validation', array( 'GFUser', 'user_registration_validation' ) ); |
|
| 1219 | - } |
|
| 1175 | + } |
|
| 1220 | 1176 | |
| 1177 | + $this->entry[ $input_name ] = $value; |
|
| 1178 | + $_POST[ $input_name ] = $value; |
|
| 1221 | 1179 | |
| 1222 | - /** |
|
| 1223 | - * For some crazy reason, Gravity Forms doesn't validate Edit Entry form submissions. |
|
| 1224 | - * You can enter whatever you want! |
|
| 1225 | - * We try validating, and customize the results using `self::custom_validation()` |
|
| 1226 | - */ |
|
| 1227 | - add_filter( 'gform_validation_'. $this->form_id, array( $this, 'custom_validation' ), 10, 4); |
|
| 1180 | + break; |
|
| 1228 | 1181 | |
| 1229 | - // Needed by the validate funtion |
|
| 1230 | - $failed_validation_page = NULL; |
|
| 1231 | - $field_values = RGForms::post( 'gform_field_values' ); |
|
| 1182 | + case 'number': |
|
| 1183 | + // Fix "undefined index" issue at line 1286 in form_display.php |
|
| 1184 | + if( !isset( $_POST['input_'.$field->id ] ) ) { |
|
| 1185 | + $_POST['input_'.$field->id ] = NULL; |
|
| 1186 | + } |
|
| 1187 | + break; |
|
| 1188 | + case 'captcha': |
|
| 1189 | + // Fix issue with recaptcha_check_answer() on line 1458 in form_display.php |
|
| 1190 | + $_POST['recaptcha_challenge_field'] = NULL; |
|
| 1191 | + $_POST['recaptcha_response_field'] = NULL; |
|
| 1192 | + break; |
|
| 1193 | + } |
|
| 1232 | 1194 | |
| 1233 | - // Prevent entry limit from running when editing an entry, also |
|
| 1234 | - // prevent form scheduling from preventing editing |
|
| 1235 | - unset( $this->form['limitEntries'], $this->form['scheduleForm'] ); |
|
| 1195 | + } |
|
| 1236 | 1196 | |
| 1237 | - // Hide fields depending on Edit Entry settings |
|
| 1238 | - $this->form['fields'] = $this->get_configured_edit_fields( $this->form, $this->view_id ); |
|
| 1197 | + return $form; |
|
| 1198 | + } |
|
| 1199 | + |
|
| 1200 | + |
|
| 1201 | + /** |
|
| 1202 | + * Process validation for a edit entry submission |
|
| 1203 | + * |
|
| 1204 | + * Sets the `is_valid` object var |
|
| 1205 | + * |
|
| 1206 | + * @return void |
|
| 1207 | + */ |
|
| 1208 | + function validate() { |
|
| 1209 | + |
|
| 1210 | + /** |
|
| 1211 | + * If using GF User Registration Add-on, remove the validation step, otherwise generates error when updating the entry |
|
| 1212 | + * GF User Registration Add-on version > 3.x has a different class name |
|
| 1213 | + * @since 1.16.2 |
|
| 1214 | + */ |
|
| 1215 | + if ( class_exists( 'GF_User_Registration' ) ) { |
|
| 1216 | + remove_filter( 'gform_validation', array( GF_User_Registration::get_instance(), 'validate' ) ); |
|
| 1217 | + } else if ( class_exists( 'GFUser' ) ) { |
|
| 1218 | + remove_filter( 'gform_validation', array( 'GFUser', 'user_registration_validation' ) ); |
|
| 1219 | + } |
|
| 1220 | + |
|
| 1221 | + |
|
| 1222 | + /** |
|
| 1223 | + * For some crazy reason, Gravity Forms doesn't validate Edit Entry form submissions. |
|
| 1224 | + * You can enter whatever you want! |
|
| 1225 | + * We try validating, and customize the results using `self::custom_validation()` |
|
| 1226 | + */ |
|
| 1227 | + add_filter( 'gform_validation_'. $this->form_id, array( $this, 'custom_validation' ), 10, 4); |
|
| 1228 | + |
|
| 1229 | + // Needed by the validate funtion |
|
| 1230 | + $failed_validation_page = NULL; |
|
| 1231 | + $field_values = RGForms::post( 'gform_field_values' ); |
|
| 1232 | + |
|
| 1233 | + // Prevent entry limit from running when editing an entry, also |
|
| 1234 | + // prevent form scheduling from preventing editing |
|
| 1235 | + unset( $this->form['limitEntries'], $this->form['scheduleForm'] ); |
|
| 1236 | + |
|
| 1237 | + // Hide fields depending on Edit Entry settings |
|
| 1238 | + $this->form['fields'] = $this->get_configured_edit_fields( $this->form, $this->view_id ); |
|
| 1239 | 1239 | |
| 1240 | - $this->is_valid = GFFormDisplay::validate( $this->form, $field_values, 1, $failed_validation_page ); |
|
| 1240 | + $this->is_valid = GFFormDisplay::validate( $this->form, $field_values, 1, $failed_validation_page ); |
|
| 1241 | 1241 | |
| 1242 | - remove_filter( 'gform_validation_'. $this->form_id, array( $this, 'custom_validation' ), 10 ); |
|
| 1243 | - } |
|
| 1242 | + remove_filter( 'gform_validation_'. $this->form_id, array( $this, 'custom_validation' ), 10 ); |
|
| 1243 | + } |
|
| 1244 | 1244 | |
| 1245 | 1245 | |
| 1246 | - /** |
|
| 1247 | - * Make validation work for Edit Entry |
|
| 1248 | - * |
|
| 1249 | - * Because we're calling the GFFormDisplay::validate() in an unusual way (as a front-end |
|
| 1250 | - * form pretending to be a back-end form), validate() doesn't know we _can't_ edit post |
|
| 1251 | - * fields. This goes through all the fields and if they're an invalid post field, we |
|
| 1252 | - * set them as valid. If there are still issues, we'll return false. |
|
| 1253 | - * |
|
| 1254 | - * @param [type] $validation_results [description] |
|
| 1255 | - * @return [type] [description] |
|
| 1256 | - */ |
|
| 1257 | - function custom_validation( $validation_results ) { |
|
| 1246 | + /** |
|
| 1247 | + * Make validation work for Edit Entry |
|
| 1248 | + * |
|
| 1249 | + * Because we're calling the GFFormDisplay::validate() in an unusual way (as a front-end |
|
| 1250 | + * form pretending to be a back-end form), validate() doesn't know we _can't_ edit post |
|
| 1251 | + * fields. This goes through all the fields and if they're an invalid post field, we |
|
| 1252 | + * set them as valid. If there are still issues, we'll return false. |
|
| 1253 | + * |
|
| 1254 | + * @param [type] $validation_results [description] |
|
| 1255 | + * @return [type] [description] |
|
| 1256 | + */ |
|
| 1257 | + function custom_validation( $validation_results ) { |
|
| 1258 | 1258 | |
| 1259 | - do_action('gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] Validation results: ', $validation_results ); |
|
| 1259 | + do_action('gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] Validation results: ', $validation_results ); |
|
| 1260 | 1260 | |
| 1261 | - do_action('gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] $_POSTed data (sanitized): ', esc_html( print_r( $_POST, true ) ) ); |
|
| 1261 | + do_action('gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] $_POSTed data (sanitized): ', esc_html( print_r( $_POST, true ) ) ); |
|
| 1262 | 1262 | |
| 1263 | - $gv_valid = true; |
|
| 1263 | + $gv_valid = true; |
|
| 1264 | 1264 | |
| 1265 | - foreach ( $validation_results['form']['fields'] as $key => &$field ) { |
|
| 1265 | + foreach ( $validation_results['form']['fields'] as $key => &$field ) { |
|
| 1266 | 1266 | |
| 1267 | - $value = RGFormsModel::get_field_value( $field ); |
|
| 1268 | - $field_type = RGFormsModel::get_input_type( $field ); |
|
| 1267 | + $value = RGFormsModel::get_field_value( $field ); |
|
| 1268 | + $field_type = RGFormsModel::get_input_type( $field ); |
|
| 1269 | 1269 | |
| 1270 | - // Validate always |
|
| 1271 | - switch ( $field_type ) { |
|
| 1270 | + // Validate always |
|
| 1271 | + switch ( $field_type ) { |
|
| 1272 | 1272 | |
| 1273 | 1273 | |
| 1274 | - case 'fileupload' : |
|
| 1275 | - case 'post_image': |
|
| 1274 | + case 'fileupload' : |
|
| 1275 | + case 'post_image': |
|
| 1276 | 1276 | |
| 1277 | - // in case nothing is uploaded but there are already files saved |
|
| 1278 | - if( !empty( $field->failed_validation ) && !empty( $field->isRequired ) && !empty( $value ) ) { |
|
| 1279 | - $field->failed_validation = false; |
|
| 1280 | - unset( $field->validation_message ); |
|
| 1281 | - } |
|
| 1277 | + // in case nothing is uploaded but there are already files saved |
|
| 1278 | + if( !empty( $field->failed_validation ) && !empty( $field->isRequired ) && !empty( $value ) ) { |
|
| 1279 | + $field->failed_validation = false; |
|
| 1280 | + unset( $field->validation_message ); |
|
| 1281 | + } |
|
| 1282 | 1282 | |
| 1283 | - // validate if multi file upload reached max number of files [maxFiles] => 2 |
|
| 1284 | - if( rgobj( $field, 'maxFiles') && rgobj( $field, 'multipleFiles') ) { |
|
| 1283 | + // validate if multi file upload reached max number of files [maxFiles] => 2 |
|
| 1284 | + if( rgobj( $field, 'maxFiles') && rgobj( $field, 'multipleFiles') ) { |
|
| 1285 | 1285 | |
| 1286 | - $input_name = 'input_' . $field->id; |
|
| 1287 | - //uploaded |
|
| 1288 | - $file_names = isset( GFFormsModel::$uploaded_files[ $validation_results['form']['id'] ][ $input_name ] ) ? GFFormsModel::$uploaded_files[ $validation_results['form']['id'] ][ $input_name ] : array(); |
|
| 1286 | + $input_name = 'input_' . $field->id; |
|
| 1287 | + //uploaded |
|
| 1288 | + $file_names = isset( GFFormsModel::$uploaded_files[ $validation_results['form']['id'] ][ $input_name ] ) ? GFFormsModel::$uploaded_files[ $validation_results['form']['id'] ][ $input_name ] : array(); |
|
| 1289 | 1289 | |
| 1290 | - //existent |
|
| 1291 | - $entry = $this->get_entry(); |
|
| 1292 | - $value = NULL; |
|
| 1293 | - if( isset( $entry[ $field->id ] ) ) { |
|
| 1294 | - $value = json_decode( $entry[ $field->id ], true ); |
|
| 1295 | - } |
|
| 1290 | + //existent |
|
| 1291 | + $entry = $this->get_entry(); |
|
| 1292 | + $value = NULL; |
|
| 1293 | + if( isset( $entry[ $field->id ] ) ) { |
|
| 1294 | + $value = json_decode( $entry[ $field->id ], true ); |
|
| 1295 | + } |
|
| 1296 | 1296 | |
| 1297 | - // count uploaded files and existent entry files |
|
| 1298 | - $count_files = count( $file_names ) + count( $value ); |
|
| 1297 | + // count uploaded files and existent entry files |
|
| 1298 | + $count_files = count( $file_names ) + count( $value ); |
|
| 1299 | 1299 | |
| 1300 | - if( $count_files > $field->maxFiles ) { |
|
| 1301 | - $field->validation_message = __( 'Maximum number of files reached', 'gravityview' ); |
|
| 1302 | - $field->failed_validation = 1; |
|
| 1303 | - $gv_valid = false; |
|
| 1300 | + if( $count_files > $field->maxFiles ) { |
|
| 1301 | + $field->validation_message = __( 'Maximum number of files reached', 'gravityview' ); |
|
| 1302 | + $field->failed_validation = 1; |
|
| 1303 | + $gv_valid = false; |
|
| 1304 | 1304 | |
| 1305 | - // in case of error make sure the newest upload files are removed from the upload input |
|
| 1306 | - GFFormsModel::$uploaded_files[ $validation_results['form']['id'] ] = null; |
|
| 1307 | - } |
|
| 1305 | + // in case of error make sure the newest upload files are removed from the upload input |
|
| 1306 | + GFFormsModel::$uploaded_files[ $validation_results['form']['id'] ] = null; |
|
| 1307 | + } |
|
| 1308 | 1308 | |
| 1309 | - } |
|
| 1309 | + } |
|
| 1310 | 1310 | |
| 1311 | 1311 | |
| 1312 | - break; |
|
| 1312 | + break; |
|
| 1313 | 1313 | |
| 1314 | - } |
|
| 1314 | + } |
|
| 1315 | 1315 | |
| 1316 | - // This field has failed validation. |
|
| 1317 | - if( !empty( $field->failed_validation ) ) { |
|
| 1316 | + // This field has failed validation. |
|
| 1317 | + if( !empty( $field->failed_validation ) ) { |
|
| 1318 | 1318 | |
| 1319 | - do_action( 'gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] Field is invalid.', array( 'field' => $field, 'value' => $value ) ); |
|
| 1319 | + do_action( 'gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] Field is invalid.', array( 'field' => $field, 'value' => $value ) ); |
|
| 1320 | 1320 | |
| 1321 | - switch ( $field_type ) { |
|
| 1321 | + switch ( $field_type ) { |
|
| 1322 | 1322 | |
| 1323 | - // Captchas don't need to be re-entered. |
|
| 1324 | - case 'captcha': |
|
| 1323 | + // Captchas don't need to be re-entered. |
|
| 1324 | + case 'captcha': |
|
| 1325 | 1325 | |
| 1326 | - // Post Image fields aren't editable, so we un-fail them. |
|
| 1327 | - case 'post_image': |
|
| 1328 | - $field->failed_validation = false; |
|
| 1329 | - unset( $field->validation_message ); |
|
| 1330 | - break; |
|
| 1326 | + // Post Image fields aren't editable, so we un-fail them. |
|
| 1327 | + case 'post_image': |
|
| 1328 | + $field->failed_validation = false; |
|
| 1329 | + unset( $field->validation_message ); |
|
| 1330 | + break; |
|
| 1331 | 1331 | |
| 1332 | - } |
|
| 1332 | + } |
|
| 1333 | 1333 | |
| 1334 | - // You can't continue inside a switch, so we do it after. |
|
| 1335 | - if( empty( $field->failed_validation ) ) { |
|
| 1336 | - continue; |
|
| 1337 | - } |
|
| 1334 | + // You can't continue inside a switch, so we do it after. |
|
| 1335 | + if( empty( $field->failed_validation ) ) { |
|
| 1336 | + continue; |
|
| 1337 | + } |
|
| 1338 | 1338 | |
| 1339 | - // checks if the No Duplicates option is not validating entry against itself, since |
|
| 1340 | - // we're editing a stored entry, it would also assume it's a duplicate. |
|
| 1341 | - if( !empty( $field->noDuplicates ) ) { |
|
| 1339 | + // checks if the No Duplicates option is not validating entry against itself, since |
|
| 1340 | + // we're editing a stored entry, it would also assume it's a duplicate. |
|
| 1341 | + if( !empty( $field->noDuplicates ) ) { |
|
| 1342 | 1342 | |
| 1343 | - $entry = $this->get_entry(); |
|
| 1343 | + $entry = $this->get_entry(); |
|
| 1344 | 1344 | |
| 1345 | - // If the value of the entry is the same as the stored value |
|
| 1346 | - // Then we can assume it's not a duplicate, it's the same. |
|
| 1347 | - if( !empty( $entry ) && $value == $entry[ $field->id ] ) { |
|
| 1348 | - //if value submitted was not changed, then don't validate |
|
| 1349 | - $field->failed_validation = false; |
|
| 1345 | + // If the value of the entry is the same as the stored value |
|
| 1346 | + // Then we can assume it's not a duplicate, it's the same. |
|
| 1347 | + if( !empty( $entry ) && $value == $entry[ $field->id ] ) { |
|
| 1348 | + //if value submitted was not changed, then don't validate |
|
| 1349 | + $field->failed_validation = false; |
|
| 1350 | 1350 | |
| 1351 | - unset( $field->validation_message ); |
|
| 1351 | + unset( $field->validation_message ); |
|
| 1352 | 1352 | |
| 1353 | - do_action('gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] Field not a duplicate; it is the same entry.', $entry ); |
|
| 1353 | + do_action('gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] Field not a duplicate; it is the same entry.', $entry ); |
|
| 1354 | 1354 | |
| 1355 | - continue; |
|
| 1356 | - } |
|
| 1357 | - } |
|
| 1355 | + continue; |
|
| 1356 | + } |
|
| 1357 | + } |
|
| 1358 | 1358 | |
| 1359 | - // if here then probably we are facing the validation 'At least one field must be filled out' |
|
| 1360 | - if( GFFormDisplay::is_empty( $field, $this->form_id ) && empty( $field->isRequired ) ) { |
|
| 1361 | - unset( $field->validation_message ); |
|
| 1362 | - $field->validation_message = false; |
|
| 1363 | - continue; |
|
| 1364 | - } |
|
| 1359 | + // if here then probably we are facing the validation 'At least one field must be filled out' |
|
| 1360 | + if( GFFormDisplay::is_empty( $field, $this->form_id ) && empty( $field->isRequired ) ) { |
|
| 1361 | + unset( $field->validation_message ); |
|
| 1362 | + $field->validation_message = false; |
|
| 1363 | + continue; |
|
| 1364 | + } |
|
| 1365 | 1365 | |
| 1366 | - $gv_valid = false; |
|
| 1366 | + $gv_valid = false; |
|
| 1367 | 1367 | |
| 1368 | - } |
|
| 1368 | + } |
|
| 1369 | 1369 | |
| 1370 | - } |
|
| 1370 | + } |
|
| 1371 | 1371 | |
| 1372 | - $validation_results['is_valid'] = $gv_valid; |
|
| 1372 | + $validation_results['is_valid'] = $gv_valid; |
|
| 1373 | 1373 | |
| 1374 | - do_action('gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] Validation results.', $validation_results ); |
|
| 1374 | + do_action('gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] Validation results.', $validation_results ); |
|
| 1375 | 1375 | |
| 1376 | - // We'll need this result when rendering the form ( on GFFormDisplay::get_form ) |
|
| 1377 | - $this->form_after_validation = $validation_results['form']; |
|
| 1376 | + // We'll need this result when rendering the form ( on GFFormDisplay::get_form ) |
|
| 1377 | + $this->form_after_validation = $validation_results['form']; |
|
| 1378 | 1378 | |
| 1379 | - return $validation_results; |
|
| 1380 | - } |
|
| 1379 | + return $validation_results; |
|
| 1380 | + } |
|
| 1381 | 1381 | |
| 1382 | 1382 | |
| 1383 | - /** |
|
| 1384 | - * TODO: This seems to be hacky... we should remove it. Entry is set when updating the form using setup_vars()! |
|
| 1385 | - * Get the current entry and set it if it's not yet set. |
|
| 1386 | - * @return array Gravity Forms entry array |
|
| 1387 | - */ |
|
| 1388 | - private function get_entry() { |
|
| 1383 | + /** |
|
| 1384 | + * TODO: This seems to be hacky... we should remove it. Entry is set when updating the form using setup_vars()! |
|
| 1385 | + * Get the current entry and set it if it's not yet set. |
|
| 1386 | + * @return array Gravity Forms entry array |
|
| 1387 | + */ |
|
| 1388 | + private function get_entry() { |
|
| 1389 | 1389 | |
| 1390 | - if( empty( $this->entry ) ) { |
|
| 1391 | - // Get the database value of the entry that's being edited |
|
| 1392 | - $this->entry = gravityview_get_entry( GravityView_frontend::is_single_entry() ); |
|
| 1393 | - } |
|
| 1390 | + if( empty( $this->entry ) ) { |
|
| 1391 | + // Get the database value of the entry that's being edited |
|
| 1392 | + $this->entry = gravityview_get_entry( GravityView_frontend::is_single_entry() ); |
|
| 1393 | + } |
|
| 1394 | 1394 | |
| 1395 | - return $this->entry; |
|
| 1396 | - } |
|
| 1395 | + return $this->entry; |
|
| 1396 | + } |
|
| 1397 | 1397 | |
| 1398 | 1398 | |
| 1399 | 1399 | |
| 1400 | - // --- Filters |
|
| 1400 | + // --- Filters |
|
| 1401 | 1401 | |
| 1402 | - /** |
|
| 1403 | - * Get the Edit Entry fields as configured in the View |
|
| 1404 | - * |
|
| 1405 | - * @since 1.8 |
|
| 1406 | - * |
|
| 1407 | - * @param int $view_id |
|
| 1408 | - * |
|
| 1409 | - * @return array Array of fields that are configured in the Edit tab in the Admin |
|
| 1410 | - */ |
|
| 1411 | - private function get_configured_edit_fields( $form, $view_id ) { |
|
| 1402 | + /** |
|
| 1403 | + * Get the Edit Entry fields as configured in the View |
|
| 1404 | + * |
|
| 1405 | + * @since 1.8 |
|
| 1406 | + * |
|
| 1407 | + * @param int $view_id |
|
| 1408 | + * |
|
| 1409 | + * @return array Array of fields that are configured in the Edit tab in the Admin |
|
| 1410 | + */ |
|
| 1411 | + private function get_configured_edit_fields( $form, $view_id ) { |
|
| 1412 | 1412 | |
| 1413 | - // Get all fields for form |
|
| 1414 | - $properties = GravityView_View_Data::getInstance()->get_fields( $view_id ); |
|
| 1413 | + // Get all fields for form |
|
| 1414 | + $properties = GravityView_View_Data::getInstance()->get_fields( $view_id ); |
|
| 1415 | 1415 | |
| 1416 | - // If edit tab not yet configured, show all fields |
|
| 1417 | - $edit_fields = !empty( $properties['edit_edit-fields'] ) ? $properties['edit_edit-fields'] : NULL; |
|
| 1416 | + // If edit tab not yet configured, show all fields |
|
| 1417 | + $edit_fields = !empty( $properties['edit_edit-fields'] ) ? $properties['edit_edit-fields'] : NULL; |
|
| 1418 | 1418 | |
| 1419 | - // Show hidden fields as text fields |
|
| 1420 | - $form = $this->fix_hidden_fields( $form ); |
|
| 1419 | + // Show hidden fields as text fields |
|
| 1420 | + $form = $this->fix_hidden_fields( $form ); |
|
| 1421 | 1421 | |
| 1422 | - // Show hidden fields as text fields |
|
| 1423 | - $form = $this->fix_survey_fields( $form ); |
|
| 1422 | + // Show hidden fields as text fields |
|
| 1423 | + $form = $this->fix_survey_fields( $form ); |
|
| 1424 | 1424 | |
| 1425 | - // Hide fields depending on admin settings |
|
| 1426 | - $fields = $this->filter_fields( $form['fields'], $edit_fields ); |
|
| 1425 | + // Hide fields depending on admin settings |
|
| 1426 | + $fields = $this->filter_fields( $form['fields'], $edit_fields ); |
|
| 1427 | 1427 | |
| 1428 | - // If Edit Entry fields are configured, remove adminOnly field settings. Otherwise, don't. |
|
| 1429 | - $fields = $this->filter_admin_only_fields( $fields, $edit_fields, $form, $view_id ); |
|
| 1428 | + // If Edit Entry fields are configured, remove adminOnly field settings. Otherwise, don't. |
|
| 1429 | + $fields = $this->filter_admin_only_fields( $fields, $edit_fields, $form, $view_id ); |
|
| 1430 | 1430 | |
| 1431 | - return $fields; |
|
| 1432 | - } |
|
| 1431 | + return $fields; |
|
| 1432 | + } |
|
| 1433 | 1433 | |
| 1434 | - /** |
|
| 1435 | - * Make sure Survey fields accept pre-populating values; otherwise existing values won't be filled-in |
|
| 1436 | - * |
|
| 1437 | - * @since 1.16.4 |
|
| 1438 | - * |
|
| 1439 | - * @param array $form |
|
| 1440 | - * |
|
| 1441 | - * @return array Form, with all fields set to `allowsPrepopulate => true` |
|
| 1442 | - */ |
|
| 1443 | - private function fix_survey_fields( $form ) { |
|
| 1434 | + /** |
|
| 1435 | + * Make sure Survey fields accept pre-populating values; otherwise existing values won't be filled-in |
|
| 1436 | + * |
|
| 1437 | + * @since 1.16.4 |
|
| 1438 | + * |
|
| 1439 | + * @param array $form |
|
| 1440 | + * |
|
| 1441 | + * @return array Form, with all fields set to `allowsPrepopulate => true` |
|
| 1442 | + */ |
|
| 1443 | + private function fix_survey_fields( $form ) { |
|
| 1444 | 1444 | |
| 1445 | - /** @var GF_Field $field */ |
|
| 1446 | - foreach( $form['fields'] as &$field ) { |
|
| 1447 | - $field->allowsPrepopulate = true; |
|
| 1448 | - } |
|
| 1445 | + /** @var GF_Field $field */ |
|
| 1446 | + foreach( $form['fields'] as &$field ) { |
|
| 1447 | + $field->allowsPrepopulate = true; |
|
| 1448 | + } |
|
| 1449 | 1449 | |
| 1450 | - return $form; |
|
| 1451 | - } |
|
| 1450 | + return $form; |
|
| 1451 | + } |
|
| 1452 | 1452 | |
| 1453 | 1453 | /** |
| 1454 | 1454 | * @since 1.9.2 |
@@ -1472,383 +1472,383 @@ discard block |
||
| 1472 | 1472 | } |
| 1473 | 1473 | |
| 1474 | 1474 | |
| 1475 | - /** |
|
| 1476 | - * Filter area fields based on specified conditions |
|
| 1477 | - * - This filter removes the fields that have calculation configured |
|
| 1478 | - * |
|
| 1479 | - * @uses GravityView_Edit_Entry::user_can_edit_field() Check caps |
|
| 1480 | - * @access private |
|
| 1481 | - * @param GF_Field[] $fields |
|
| 1482 | - * @param array $configured_fields |
|
| 1483 | - * @since 1.5 |
|
| 1484 | - * @return array $fields |
|
| 1485 | - */ |
|
| 1486 | - private function filter_fields( $fields, $configured_fields ) { |
|
| 1487 | - |
|
| 1488 | - if( empty( $fields ) || !is_array( $fields ) ) { |
|
| 1489 | - return $fields; |
|
| 1490 | - } |
|
| 1491 | - |
|
| 1492 | - $edit_fields = array(); |
|
| 1493 | - |
|
| 1494 | - $field_type_blacklist = array( |
|
| 1495 | - 'page', |
|
| 1496 | - ); |
|
| 1497 | - |
|
| 1498 | - /** |
|
| 1499 | - * @filter `gravityview/edit_entry/hide-product-fields` Hide product fields from being editable. |
|
| 1500 | - * @since 1.9.1 |
|
| 1501 | - * @param boolean $hide_product_fields Whether to hide product fields in the editor. Default: false |
|
| 1502 | - */ |
|
| 1503 | - $hide_product_fields = apply_filters( 'gravityview/edit_entry/hide-product-fields', empty( self::$supports_product_fields ) ); |
|
| 1504 | - |
|
| 1505 | - if( $hide_product_fields ) { |
|
| 1506 | - $field_type_blacklist[] = 'option'; |
|
| 1507 | - $field_type_blacklist[] = 'quantity'; |
|
| 1508 | - $field_type_blacklist[] = 'product'; |
|
| 1509 | - $field_type_blacklist[] = 'total'; |
|
| 1510 | - $field_type_blacklist[] = 'shipping'; |
|
| 1511 | - $field_type_blacklist[] = 'calculation'; |
|
| 1512 | - } |
|
| 1513 | - |
|
| 1514 | - // First, remove blacklist or calculation fields |
|
| 1515 | - foreach ( $fields as $key => $field ) { |
|
| 1516 | - |
|
| 1517 | - // Remove the fields that have calculation properties and keep them to be used later |
|
| 1518 | - // @since 1.16.2 |
|
| 1519 | - if( $field->has_calculation() ) { |
|
| 1520 | - $this->fields_with_calculation[] = $field; |
|
| 1521 | - // don't remove the calculation fields on form render. |
|
| 1522 | - } |
|
| 1523 | - |
|
| 1524 | - // process total field after all fields have been saved |
|
| 1525 | - if ( $field->type == 'total' ) { |
|
| 1526 | - $this->total_fields[] = $field; |
|
| 1527 | - unset( $fields[ $key ] ); |
|
| 1528 | - } |
|
| 1529 | - |
|
| 1530 | - if( in_array( $field->type, $field_type_blacklist ) ) { |
|
| 1531 | - unset( $fields[ $key ] ); |
|
| 1532 | - } |
|
| 1533 | - } |
|
| 1534 | - |
|
| 1535 | - // The Edit tab has not been configured, so we return all fields by default. |
|
| 1536 | - if( empty( $configured_fields ) ) { |
|
| 1537 | - return $fields; |
|
| 1538 | - } |
|
| 1539 | - |
|
| 1540 | - // The edit tab has been configured, so we loop through to configured settings |
|
| 1541 | - foreach ( $configured_fields as $configured_field ) { |
|
| 1542 | - |
|
| 1543 | - /** @var GF_Field $field */ |
|
| 1544 | - foreach ( $fields as $field ) { |
|
| 1545 | - |
|
| 1546 | - if( intval( $configured_field['id'] ) === intval( $field->id ) && $this->user_can_edit_field( $configured_field, false ) ) { |
|
| 1547 | - $edit_fields[] = $this->merge_field_properties( $field, $configured_field ); |
|
| 1548 | - break; |
|
| 1549 | - } |
|
| 1550 | - |
|
| 1551 | - } |
|
| 1552 | - |
|
| 1553 | - } |
|
| 1554 | - |
|
| 1555 | - return $edit_fields; |
|
| 1556 | - |
|
| 1557 | - } |
|
| 1558 | - |
|
| 1559 | - /** |
|
| 1560 | - * Override GF Form field properties with the ones defined on the View |
|
| 1561 | - * @param GF_Field $field GF Form field object |
|
| 1562 | - * @param array $setting GV field options |
|
| 1563 | - * @since 1.5 |
|
| 1564 | - * @return array |
|
| 1565 | - */ |
|
| 1566 | - private function merge_field_properties( $field, $field_setting ) { |
|
| 1567 | - |
|
| 1568 | - $return_field = $field; |
|
| 1569 | - |
|
| 1570 | - if( empty( $field_setting['show_label'] ) ) { |
|
| 1571 | - $return_field->label = ''; |
|
| 1572 | - } elseif ( !empty( $field_setting['custom_label'] ) ) { |
|
| 1573 | - $return_field->label = $field_setting['custom_label']; |
|
| 1574 | - } |
|
| 1575 | - |
|
| 1576 | - if( !empty( $field_setting['custom_class'] ) ) { |
|
| 1577 | - $return_field->cssClass .= ' '. gravityview_sanitize_html_class( $field_setting['custom_class'] ); |
|
| 1578 | - } |
|
| 1579 | - |
|
| 1580 | - /** |
|
| 1581 | - * Normalize page numbers - avoid conflicts with page validation |
|
| 1582 | - * @since 1.6 |
|
| 1583 | - */ |
|
| 1584 | - $return_field->pageNumber = 1; |
|
| 1585 | - |
|
| 1586 | - return $return_field; |
|
| 1587 | - |
|
| 1588 | - } |
|
| 1589 | - |
|
| 1590 | - /** |
|
| 1591 | - * Remove fields that shouldn't be visible based on the Gravity Forms adminOnly field property |
|
| 1592 | - * |
|
| 1593 | - * @since 1.9.1 |
|
| 1594 | - * |
|
| 1595 | - * @param array|GF_Field[] $fields Gravity Forms form fields |
|
| 1596 | - * @param array|null $edit_fields Fields for the Edit Entry tab configured in the View Configuration |
|
| 1597 | - * @param array $form GF Form array |
|
| 1598 | - * @param int $view_id View ID |
|
| 1599 | - * |
|
| 1600 | - * @return array Possibly modified form array |
|
| 1601 | - */ |
|
| 1602 | - function filter_admin_only_fields( $fields = array(), $edit_fields = null, $form = array(), $view_id = 0 ) { |
|
| 1603 | - |
|
| 1604 | - /** |
|
| 1605 | - * @filter `gravityview/edit_entry/use_gf_admin_only_setting` When Edit tab isn't configured, should the Gravity Forms "Admin Only" field settings be used to control field display to non-admins? Default: true |
|
| 1606 | - * If the Edit Entry tab is not configured, adminOnly fields will not be shown to non-administrators. |
|
| 1607 | - * If the Edit Entry tab *is* configured, adminOnly fields will be shown to non-administrators, using the configured GV permissions |
|
| 1608 | - * @since 1.9.1 |
|
| 1609 | - * @param boolean $use_gf_adminonly_setting True: Hide field if set to Admin Only in GF and the user is not an admin. False: show field based on GV permissions, ignoring GF permissions. |
|
| 1610 | - * @param array $form GF Form array |
|
| 1611 | - * @param int $view_id View ID |
|
| 1612 | - */ |
|
| 1613 | - $use_gf_adminonly_setting = apply_filters( 'gravityview/edit_entry/use_gf_admin_only_setting', empty( $edit_fields ), $form, $view_id ); |
|
| 1614 | - |
|
| 1615 | - if( $use_gf_adminonly_setting && false === GVCommon::has_cap( 'gravityforms_edit_entries', $this->entry['id'] ) ) { |
|
| 1616 | - foreach( $fields as $k => $field ) { |
|
| 1617 | - if( $field->adminOnly ) { |
|
| 1618 | - unset( $fields[ $k ] ); |
|
| 1619 | - } |
|
| 1620 | - } |
|
| 1621 | - return $fields; |
|
| 1622 | - } |
|
| 1623 | - |
|
| 1624 | - foreach( $fields as &$field ) { |
|
| 1625 | - $field->adminOnly = false; |
|
| 1626 | - } |
|
| 1627 | - |
|
| 1628 | - return $fields; |
|
| 1629 | - } |
|
| 1630 | - |
|
| 1631 | - // --- Conditional Logic |
|
| 1632 | - |
|
| 1633 | - /** |
|
| 1634 | - * Remove the conditional logic rules from the form button and the form fields, if needed. |
|
| 1635 | - * |
|
| 1636 | - * @since 1.9 |
|
| 1637 | - * |
|
| 1638 | - * @param array $form Gravity Forms form |
|
| 1639 | - * @return array Modified form, if not using Conditional Logic |
|
| 1640 | - */ |
|
| 1641 | - function filter_conditional_logic( $form ) { |
|
| 1642 | - |
|
| 1643 | - /** |
|
| 1644 | - * @filter `gravityview/edit_entry/conditional_logic` Should the Edit Entry form use Gravity Forms conditional logic showing/hiding of fields? |
|
| 1645 | - * @since 1.9 |
|
| 1646 | - * @param bool $use_conditional_logic True: Gravity Forms will show/hide fields just like in the original form; False: conditional logic will be disabled and fields will be shown based on configuration. Default: true |
|
| 1647 | - * @param array $form Gravity Forms form |
|
| 1648 | - */ |
|
| 1649 | - $use_conditional_logic = apply_filters( 'gravityview/edit_entry/conditional_logic', true, $form ); |
|
| 1650 | - |
|
| 1651 | - if( $use_conditional_logic ) { |
|
| 1652 | - return $form; |
|
| 1653 | - } |
|
| 1654 | - |
|
| 1655 | - foreach( $form['fields'] as &$field ) { |
|
| 1656 | - /* @var GF_Field $field */ |
|
| 1657 | - $field->conditionalLogic = null; |
|
| 1658 | - } |
|
| 1659 | - |
|
| 1660 | - unset( $form['button']['conditionalLogic'] ); |
|
| 1661 | - |
|
| 1662 | - return $form; |
|
| 1663 | - |
|
| 1664 | - } |
|
| 1665 | - |
|
| 1666 | - /** |
|
| 1667 | - * Disable the Gravity Forms conditional logic script and features on the Edit Entry screen |
|
| 1668 | - * |
|
| 1669 | - * @since 1.9 |
|
| 1670 | - * |
|
| 1671 | - * @param $has_conditional_logic |
|
| 1672 | - * @param $form |
|
| 1673 | - * @return mixed|void |
|
| 1674 | - */ |
|
| 1675 | - function manage_conditional_logic( $has_conditional_logic, $form ) { |
|
| 1676 | - |
|
| 1677 | - if( ! $this->is_edit_entry() ) { |
|
| 1678 | - return $has_conditional_logic; |
|
| 1679 | - } |
|
| 1680 | - |
|
| 1681 | - return apply_filters( 'gravityview/edit_entry/conditional_logic', $has_conditional_logic, $form ); |
|
| 1682 | - } |
|
| 1683 | - |
|
| 1684 | - |
|
| 1685 | - // --- User checks and nonces |
|
| 1686 | - |
|
| 1687 | - /** |
|
| 1688 | - * Check if the user can edit the entry |
|
| 1689 | - * |
|
| 1690 | - * - Is the nonce valid? |
|
| 1691 | - * - Does the user have the right caps for the entry |
|
| 1692 | - * - Is the entry in the trash? |
|
| 1693 | - * |
|
| 1694 | - * @todo Move to GVCommon |
|
| 1695 | - * |
|
| 1696 | - * @param boolean $echo Show error messages in the form? |
|
| 1697 | - * @return boolean True: can edit form. False: nope. |
|
| 1698 | - */ |
|
| 1699 | - function user_can_edit_entry( $echo = false ) { |
|
| 1700 | - |
|
| 1701 | - $error = NULL; |
|
| 1702 | - |
|
| 1703 | - /** |
|
| 1704 | - * 1. Permalinks are turned off |
|
| 1705 | - * 2. There are two entries embedded using oEmbed |
|
| 1706 | - * 3. One of the entries has just been saved |
|
| 1707 | - */ |
|
| 1708 | - if( !empty( $_POST['lid'] ) && !empty( $_GET['entry'] ) && ( $_POST['lid'] !== $_GET['entry'] ) ) { |
|
| 1709 | - |
|
| 1710 | - $error = true; |
|
| 1711 | - |
|
| 1712 | - } |
|
| 1713 | - |
|
| 1714 | - if( !empty( $_GET['entry'] ) && (string)$this->entry['id'] !== $_GET['entry'] ) { |
|
| 1715 | - |
|
| 1716 | - $error = true; |
|
| 1717 | - |
|
| 1718 | - } elseif( ! $this->verify_nonce() ) { |
|
| 1719 | - |
|
| 1720 | - /** |
|
| 1721 | - * If the Entry is embedded, there may be two entries on the same page. |
|
| 1722 | - * If that's the case, and one is being edited, the other should fail gracefully and not display an error. |
|
| 1723 | - */ |
|
| 1724 | - if( GravityView_oEmbed::getInstance()->get_entry_id() ) { |
|
| 1725 | - $error = true; |
|
| 1726 | - } else { |
|
| 1727 | - $error = __( 'The link to edit this entry is not valid; it may have expired.', 'gravityview'); |
|
| 1728 | - } |
|
| 1475 | + /** |
|
| 1476 | + * Filter area fields based on specified conditions |
|
| 1477 | + * - This filter removes the fields that have calculation configured |
|
| 1478 | + * |
|
| 1479 | + * @uses GravityView_Edit_Entry::user_can_edit_field() Check caps |
|
| 1480 | + * @access private |
|
| 1481 | + * @param GF_Field[] $fields |
|
| 1482 | + * @param array $configured_fields |
|
| 1483 | + * @since 1.5 |
|
| 1484 | + * @return array $fields |
|
| 1485 | + */ |
|
| 1486 | + private function filter_fields( $fields, $configured_fields ) { |
|
| 1729 | 1487 | |
| 1730 | - } |
|
| 1731 | - |
|
| 1732 | - if( ! GravityView_Edit_Entry::check_user_cap_edit_entry( $this->entry ) ) { |
|
| 1733 | - $error = __( 'You do not have permission to edit this entry.', 'gravityview'); |
|
| 1734 | - } |
|
| 1735 | - |
|
| 1736 | - if( $this->entry['status'] === 'trash' ) { |
|
| 1737 | - $error = __('You cannot edit the entry; it is in the trash.', 'gravityview' ); |
|
| 1738 | - } |
|
| 1488 | + if( empty( $fields ) || !is_array( $fields ) ) { |
|
| 1489 | + return $fields; |
|
| 1490 | + } |
|
| 1739 | 1491 | |
| 1740 | - // No errors; everything's fine here! |
|
| 1741 | - if( empty( $error ) ) { |
|
| 1742 | - return true; |
|
| 1743 | - } |
|
| 1492 | + $edit_fields = array(); |
|
| 1493 | + |
|
| 1494 | + $field_type_blacklist = array( |
|
| 1495 | + 'page', |
|
| 1496 | + ); |
|
| 1497 | + |
|
| 1498 | + /** |
|
| 1499 | + * @filter `gravityview/edit_entry/hide-product-fields` Hide product fields from being editable. |
|
| 1500 | + * @since 1.9.1 |
|
| 1501 | + * @param boolean $hide_product_fields Whether to hide product fields in the editor. Default: false |
|
| 1502 | + */ |
|
| 1503 | + $hide_product_fields = apply_filters( 'gravityview/edit_entry/hide-product-fields', empty( self::$supports_product_fields ) ); |
|
| 1504 | + |
|
| 1505 | + if( $hide_product_fields ) { |
|
| 1506 | + $field_type_blacklist[] = 'option'; |
|
| 1507 | + $field_type_blacklist[] = 'quantity'; |
|
| 1508 | + $field_type_blacklist[] = 'product'; |
|
| 1509 | + $field_type_blacklist[] = 'total'; |
|
| 1510 | + $field_type_blacklist[] = 'shipping'; |
|
| 1511 | + $field_type_blacklist[] = 'calculation'; |
|
| 1512 | + } |
|
| 1744 | 1513 | |
| 1745 | - if( $echo && $error !== true ) { |
|
| 1514 | + // First, remove blacklist or calculation fields |
|
| 1515 | + foreach ( $fields as $key => $field ) { |
|
| 1746 | 1516 | |
| 1747 | - $error = esc_html( $error ); |
|
| 1517 | + // Remove the fields that have calculation properties and keep them to be used later |
|
| 1518 | + // @since 1.16.2 |
|
| 1519 | + if( $field->has_calculation() ) { |
|
| 1520 | + $this->fields_with_calculation[] = $field; |
|
| 1521 | + // don't remove the calculation fields on form render. |
|
| 1522 | + } |
|
| 1748 | 1523 | |
| 1749 | - /** |
|
| 1750 | - * @since 1.9 |
|
| 1751 | - */ |
|
| 1752 | - if ( ! empty( $this->entry ) ) { |
|
| 1753 | - $error .= ' ' . gravityview_get_link( '#', _x('Go back.', 'Link shown when invalid Edit Entry link is clicked', 'gravityview' ), array( 'onclick' => "window.history.go(-1); return false;" ) ); |
|
| 1754 | - } |
|
| 1524 | + // process total field after all fields have been saved |
|
| 1525 | + if ( $field->type == 'total' ) { |
|
| 1526 | + $this->total_fields[] = $field; |
|
| 1527 | + unset( $fields[ $key ] ); |
|
| 1528 | + } |
|
| 1755 | 1529 | |
| 1756 | - echo GVCommon::generate_notice( wpautop( $error ), 'gv-error error'); |
|
| 1757 | - } |
|
| 1530 | + if( in_array( $field->type, $field_type_blacklist ) ) { |
|
| 1531 | + unset( $fields[ $key ] ); |
|
| 1532 | + } |
|
| 1533 | + } |
|
| 1758 | 1534 | |
| 1759 | - do_action('gravityview_log_error', 'GravityView_Edit_Entry[user_can_edit_entry]' . $error ); |
|
| 1535 | + // The Edit tab has not been configured, so we return all fields by default. |
|
| 1536 | + if( empty( $configured_fields ) ) { |
|
| 1537 | + return $fields; |
|
| 1538 | + } |
|
| 1760 | 1539 | |
| 1761 | - return false; |
|
| 1762 | - } |
|
| 1540 | + // The edit tab has been configured, so we loop through to configured settings |
|
| 1541 | + foreach ( $configured_fields as $configured_field ) { |
|
| 1763 | 1542 | |
| 1543 | + /** @var GF_Field $field */ |
|
| 1544 | + foreach ( $fields as $field ) { |
|
| 1764 | 1545 | |
| 1765 | - /** |
|
| 1766 | - * Check whether a field is editable by the current user, and optionally display an error message |
|
| 1767 | - * @uses GravityView_Edit_Entry->check_user_cap_edit_field() Check user capabilities |
|
| 1768 | - * @param array $field Field or field settings array |
|
| 1769 | - * @param boolean $echo Whether to show error message telling user they aren't allowed |
|
| 1770 | - * @return boolean True: user can edit the current field; False: nope, they can't. |
|
| 1771 | - */ |
|
| 1772 | - private function user_can_edit_field( $field, $echo = false ) { |
|
| 1773 | - |
|
| 1774 | - $error = NULL; |
|
| 1546 | + if( intval( $configured_field['id'] ) === intval( $field->id ) && $this->user_can_edit_field( $configured_field, false ) ) { |
|
| 1547 | + $edit_fields[] = $this->merge_field_properties( $field, $configured_field ); |
|
| 1548 | + break; |
|
| 1549 | + } |
|
| 1775 | 1550 | |
| 1776 | - if( ! $this->check_user_cap_edit_field( $field ) ) { |
|
| 1777 | - $error = __( 'You do not have permission to edit this field.', 'gravityview'); |
|
| 1778 | - } |
|
| 1551 | + } |
|
| 1779 | 1552 | |
| 1780 | - // No errors; everything's fine here! |
|
| 1781 | - if( empty( $error ) ) { |
|
| 1782 | - return true; |
|
| 1783 | - } |
|
| 1553 | + } |
|
| 1784 | 1554 | |
| 1785 | - if( $echo ) { |
|
| 1786 | - echo GVCommon::generate_notice( wpautop( esc_html( $error ) ), 'gv-error error'); |
|
| 1787 | - } |
|
| 1788 | - |
|
| 1789 | - do_action('gravityview_log_error', 'GravityView_Edit_Entry[user_can_edit_field]' . $error ); |
|
| 1555 | + return $edit_fields; |
|
| 1790 | 1556 | |
| 1791 | - return false; |
|
| 1557 | + } |
|
| 1792 | 1558 | |
| 1793 | - } |
|
| 1559 | + /** |
|
| 1560 | + * Override GF Form field properties with the ones defined on the View |
|
| 1561 | + * @param GF_Field $field GF Form field object |
|
| 1562 | + * @param array $setting GV field options |
|
| 1563 | + * @since 1.5 |
|
| 1564 | + * @return array |
|
| 1565 | + */ |
|
| 1566 | + private function merge_field_properties( $field, $field_setting ) { |
|
| 1567 | + |
|
| 1568 | + $return_field = $field; |
|
| 1569 | + |
|
| 1570 | + if( empty( $field_setting['show_label'] ) ) { |
|
| 1571 | + $return_field->label = ''; |
|
| 1572 | + } elseif ( !empty( $field_setting['custom_label'] ) ) { |
|
| 1573 | + $return_field->label = $field_setting['custom_label']; |
|
| 1574 | + } |
|
| 1575 | + |
|
| 1576 | + if( !empty( $field_setting['custom_class'] ) ) { |
|
| 1577 | + $return_field->cssClass .= ' '. gravityview_sanitize_html_class( $field_setting['custom_class'] ); |
|
| 1578 | + } |
|
| 1579 | + |
|
| 1580 | + /** |
|
| 1581 | + * Normalize page numbers - avoid conflicts with page validation |
|
| 1582 | + * @since 1.6 |
|
| 1583 | + */ |
|
| 1584 | + $return_field->pageNumber = 1; |
|
| 1585 | + |
|
| 1586 | + return $return_field; |
|
| 1587 | + |
|
| 1588 | + } |
|
| 1589 | + |
|
| 1590 | + /** |
|
| 1591 | + * Remove fields that shouldn't be visible based on the Gravity Forms adminOnly field property |
|
| 1592 | + * |
|
| 1593 | + * @since 1.9.1 |
|
| 1594 | + * |
|
| 1595 | + * @param array|GF_Field[] $fields Gravity Forms form fields |
|
| 1596 | + * @param array|null $edit_fields Fields for the Edit Entry tab configured in the View Configuration |
|
| 1597 | + * @param array $form GF Form array |
|
| 1598 | + * @param int $view_id View ID |
|
| 1599 | + * |
|
| 1600 | + * @return array Possibly modified form array |
|
| 1601 | + */ |
|
| 1602 | + function filter_admin_only_fields( $fields = array(), $edit_fields = null, $form = array(), $view_id = 0 ) { |
|
| 1603 | + |
|
| 1604 | + /** |
|
| 1605 | + * @filter `gravityview/edit_entry/use_gf_admin_only_setting` When Edit tab isn't configured, should the Gravity Forms "Admin Only" field settings be used to control field display to non-admins? Default: true |
|
| 1606 | + * If the Edit Entry tab is not configured, adminOnly fields will not be shown to non-administrators. |
|
| 1607 | + * If the Edit Entry tab *is* configured, adminOnly fields will be shown to non-administrators, using the configured GV permissions |
|
| 1608 | + * @since 1.9.1 |
|
| 1609 | + * @param boolean $use_gf_adminonly_setting True: Hide field if set to Admin Only in GF and the user is not an admin. False: show field based on GV permissions, ignoring GF permissions. |
|
| 1610 | + * @param array $form GF Form array |
|
| 1611 | + * @param int $view_id View ID |
|
| 1612 | + */ |
|
| 1613 | + $use_gf_adminonly_setting = apply_filters( 'gravityview/edit_entry/use_gf_admin_only_setting', empty( $edit_fields ), $form, $view_id ); |
|
| 1614 | + |
|
| 1615 | + if( $use_gf_adminonly_setting && false === GVCommon::has_cap( 'gravityforms_edit_entries', $this->entry['id'] ) ) { |
|
| 1616 | + foreach( $fields as $k => $field ) { |
|
| 1617 | + if( $field->adminOnly ) { |
|
| 1618 | + unset( $fields[ $k ] ); |
|
| 1619 | + } |
|
| 1620 | + } |
|
| 1621 | + return $fields; |
|
| 1622 | + } |
|
| 1623 | + |
|
| 1624 | + foreach( $fields as &$field ) { |
|
| 1625 | + $field->adminOnly = false; |
|
| 1626 | + } |
|
| 1627 | + |
|
| 1628 | + return $fields; |
|
| 1629 | + } |
|
| 1630 | + |
|
| 1631 | + // --- Conditional Logic |
|
| 1632 | + |
|
| 1633 | + /** |
|
| 1634 | + * Remove the conditional logic rules from the form button and the form fields, if needed. |
|
| 1635 | + * |
|
| 1636 | + * @since 1.9 |
|
| 1637 | + * |
|
| 1638 | + * @param array $form Gravity Forms form |
|
| 1639 | + * @return array Modified form, if not using Conditional Logic |
|
| 1640 | + */ |
|
| 1641 | + function filter_conditional_logic( $form ) { |
|
| 1642 | + |
|
| 1643 | + /** |
|
| 1644 | + * @filter `gravityview/edit_entry/conditional_logic` Should the Edit Entry form use Gravity Forms conditional logic showing/hiding of fields? |
|
| 1645 | + * @since 1.9 |
|
| 1646 | + * @param bool $use_conditional_logic True: Gravity Forms will show/hide fields just like in the original form; False: conditional logic will be disabled and fields will be shown based on configuration. Default: true |
|
| 1647 | + * @param array $form Gravity Forms form |
|
| 1648 | + */ |
|
| 1649 | + $use_conditional_logic = apply_filters( 'gravityview/edit_entry/conditional_logic', true, $form ); |
|
| 1650 | + |
|
| 1651 | + if( $use_conditional_logic ) { |
|
| 1652 | + return $form; |
|
| 1653 | + } |
|
| 1654 | + |
|
| 1655 | + foreach( $form['fields'] as &$field ) { |
|
| 1656 | + /* @var GF_Field $field */ |
|
| 1657 | + $field->conditionalLogic = null; |
|
| 1658 | + } |
|
| 1659 | + |
|
| 1660 | + unset( $form['button']['conditionalLogic'] ); |
|
| 1661 | + |
|
| 1662 | + return $form; |
|
| 1663 | + |
|
| 1664 | + } |
|
| 1665 | + |
|
| 1666 | + /** |
|
| 1667 | + * Disable the Gravity Forms conditional logic script and features on the Edit Entry screen |
|
| 1668 | + * |
|
| 1669 | + * @since 1.9 |
|
| 1670 | + * |
|
| 1671 | + * @param $has_conditional_logic |
|
| 1672 | + * @param $form |
|
| 1673 | + * @return mixed|void |
|
| 1674 | + */ |
|
| 1675 | + function manage_conditional_logic( $has_conditional_logic, $form ) { |
|
| 1676 | + |
|
| 1677 | + if( ! $this->is_edit_entry() ) { |
|
| 1678 | + return $has_conditional_logic; |
|
| 1679 | + } |
|
| 1680 | + |
|
| 1681 | + return apply_filters( 'gravityview/edit_entry/conditional_logic', $has_conditional_logic, $form ); |
|
| 1682 | + } |
|
| 1683 | + |
|
| 1684 | + |
|
| 1685 | + // --- User checks and nonces |
|
| 1686 | + |
|
| 1687 | + /** |
|
| 1688 | + * Check if the user can edit the entry |
|
| 1689 | + * |
|
| 1690 | + * - Is the nonce valid? |
|
| 1691 | + * - Does the user have the right caps for the entry |
|
| 1692 | + * - Is the entry in the trash? |
|
| 1693 | + * |
|
| 1694 | + * @todo Move to GVCommon |
|
| 1695 | + * |
|
| 1696 | + * @param boolean $echo Show error messages in the form? |
|
| 1697 | + * @return boolean True: can edit form. False: nope. |
|
| 1698 | + */ |
|
| 1699 | + function user_can_edit_entry( $echo = false ) { |
|
| 1700 | + |
|
| 1701 | + $error = NULL; |
|
| 1794 | 1702 | |
| 1703 | + /** |
|
| 1704 | + * 1. Permalinks are turned off |
|
| 1705 | + * 2. There are two entries embedded using oEmbed |
|
| 1706 | + * 3. One of the entries has just been saved |
|
| 1707 | + */ |
|
| 1708 | + if( !empty( $_POST['lid'] ) && !empty( $_GET['entry'] ) && ( $_POST['lid'] !== $_GET['entry'] ) ) { |
|
| 1795 | 1709 | |
| 1796 | - /** |
|
| 1797 | - * checks if user has permissions to edit a specific field |
|
| 1798 | - * |
|
| 1799 | - * Needs to be used combined with GravityView_Edit_Entry::user_can_edit_field for maximum security!! |
|
| 1800 | - * |
|
| 1801 | - * @param [type] $field [description] |
|
| 1802 | - * @return bool |
|
| 1803 | - */ |
|
| 1804 | - private function check_user_cap_edit_field( $field ) { |
|
| 1710 | + $error = true; |
|
| 1805 | 1711 | |
| 1806 | - // If they can edit any entries (as defined in Gravity Forms), we're good. |
|
| 1807 | - if( GVCommon::has_cap( array( 'gravityforms_edit_entries', 'gravityview_edit_others_entries' ) ) ) { |
|
| 1808 | - return true; |
|
| 1809 | - } |
|
| 1712 | + } |
|
| 1713 | + |
|
| 1714 | + if( !empty( $_GET['entry'] ) && (string)$this->entry['id'] !== $_GET['entry'] ) { |
|
| 1715 | + |
|
| 1716 | + $error = true; |
|
| 1717 | + |
|
| 1718 | + } elseif( ! $this->verify_nonce() ) { |
|
| 1719 | + |
|
| 1720 | + /** |
|
| 1721 | + * If the Entry is embedded, there may be two entries on the same page. |
|
| 1722 | + * If that's the case, and one is being edited, the other should fail gracefully and not display an error. |
|
| 1723 | + */ |
|
| 1724 | + if( GravityView_oEmbed::getInstance()->get_entry_id() ) { |
|
| 1725 | + $error = true; |
|
| 1726 | + } else { |
|
| 1727 | + $error = __( 'The link to edit this entry is not valid; it may have expired.', 'gravityview'); |
|
| 1728 | + } |
|
| 1729 | + |
|
| 1730 | + } |
|
| 1731 | + |
|
| 1732 | + if( ! GravityView_Edit_Entry::check_user_cap_edit_entry( $this->entry ) ) { |
|
| 1733 | + $error = __( 'You do not have permission to edit this entry.', 'gravityview'); |
|
| 1734 | + } |
|
| 1735 | + |
|
| 1736 | + if( $this->entry['status'] === 'trash' ) { |
|
| 1737 | + $error = __('You cannot edit the entry; it is in the trash.', 'gravityview' ); |
|
| 1738 | + } |
|
| 1739 | + |
|
| 1740 | + // No errors; everything's fine here! |
|
| 1741 | + if( empty( $error ) ) { |
|
| 1742 | + return true; |
|
| 1743 | + } |
|
| 1744 | + |
|
| 1745 | + if( $echo && $error !== true ) { |
|
| 1746 | + |
|
| 1747 | + $error = esc_html( $error ); |
|
| 1748 | + |
|
| 1749 | + /** |
|
| 1750 | + * @since 1.9 |
|
| 1751 | + */ |
|
| 1752 | + if ( ! empty( $this->entry ) ) { |
|
| 1753 | + $error .= ' ' . gravityview_get_link( '#', _x('Go back.', 'Link shown when invalid Edit Entry link is clicked', 'gravityview' ), array( 'onclick' => "window.history.go(-1); return false;" ) ); |
|
| 1754 | + } |
|
| 1755 | + |
|
| 1756 | + echo GVCommon::generate_notice( wpautop( $error ), 'gv-error error'); |
|
| 1757 | + } |
|
| 1758 | + |
|
| 1759 | + do_action('gravityview_log_error', 'GravityView_Edit_Entry[user_can_edit_entry]' . $error ); |
|
| 1760 | + |
|
| 1761 | + return false; |
|
| 1762 | + } |
|
| 1763 | + |
|
| 1764 | + |
|
| 1765 | + /** |
|
| 1766 | + * Check whether a field is editable by the current user, and optionally display an error message |
|
| 1767 | + * @uses GravityView_Edit_Entry->check_user_cap_edit_field() Check user capabilities |
|
| 1768 | + * @param array $field Field or field settings array |
|
| 1769 | + * @param boolean $echo Whether to show error message telling user they aren't allowed |
|
| 1770 | + * @return boolean True: user can edit the current field; False: nope, they can't. |
|
| 1771 | + */ |
|
| 1772 | + private function user_can_edit_field( $field, $echo = false ) { |
|
| 1773 | + |
|
| 1774 | + $error = NULL; |
|
| 1810 | 1775 | |
| 1811 | - $field_cap = isset( $field['allow_edit_cap'] ) ? $field['allow_edit_cap'] : false; |
|
| 1776 | + if( ! $this->check_user_cap_edit_field( $field ) ) { |
|
| 1777 | + $error = __( 'You do not have permission to edit this field.', 'gravityview'); |
|
| 1778 | + } |
|
| 1779 | + |
|
| 1780 | + // No errors; everything's fine here! |
|
| 1781 | + if( empty( $error ) ) { |
|
| 1782 | + return true; |
|
| 1783 | + } |
|
| 1784 | + |
|
| 1785 | + if( $echo ) { |
|
| 1786 | + echo GVCommon::generate_notice( wpautop( esc_html( $error ) ), 'gv-error error'); |
|
| 1787 | + } |
|
| 1788 | + |
|
| 1789 | + do_action('gravityview_log_error', 'GravityView_Edit_Entry[user_can_edit_field]' . $error ); |
|
| 1790 | + |
|
| 1791 | + return false; |
|
| 1792 | + |
|
| 1793 | + } |
|
| 1794 | + |
|
| 1795 | + |
|
| 1796 | + /** |
|
| 1797 | + * checks if user has permissions to edit a specific field |
|
| 1798 | + * |
|
| 1799 | + * Needs to be used combined with GravityView_Edit_Entry::user_can_edit_field for maximum security!! |
|
| 1800 | + * |
|
| 1801 | + * @param [type] $field [description] |
|
| 1802 | + * @return bool |
|
| 1803 | + */ |
|
| 1804 | + private function check_user_cap_edit_field( $field ) { |
|
| 1805 | + |
|
| 1806 | + // If they can edit any entries (as defined in Gravity Forms), we're good. |
|
| 1807 | + if( GVCommon::has_cap( array( 'gravityforms_edit_entries', 'gravityview_edit_others_entries' ) ) ) { |
|
| 1808 | + return true; |
|
| 1809 | + } |
|
| 1810 | + |
|
| 1811 | + $field_cap = isset( $field['allow_edit_cap'] ) ? $field['allow_edit_cap'] : false; |
|
| 1812 | 1812 | |
| 1813 | - // If the field has custom editing capaibilities set, check those |
|
| 1814 | - if( $field_cap ) { |
|
| 1815 | - return GVCommon::has_cap( $field['allow_edit_cap'] ); |
|
| 1816 | - } |
|
| 1817 | - |
|
| 1818 | - return false; |
|
| 1819 | - } |
|
| 1813 | + // If the field has custom editing capaibilities set, check those |
|
| 1814 | + if( $field_cap ) { |
|
| 1815 | + return GVCommon::has_cap( $field['allow_edit_cap'] ); |
|
| 1816 | + } |
|
| 1817 | + |
|
| 1818 | + return false; |
|
| 1819 | + } |
|
| 1820 | 1820 | |
| 1821 | 1821 | |
| 1822 | - /** |
|
| 1823 | - * Is the current nonce valid for editing the entry? |
|
| 1824 | - * @return boolean |
|
| 1825 | - */ |
|
| 1826 | - public function verify_nonce() { |
|
| 1822 | + /** |
|
| 1823 | + * Is the current nonce valid for editing the entry? |
|
| 1824 | + * @return boolean |
|
| 1825 | + */ |
|
| 1826 | + public function verify_nonce() { |
|
| 1827 | 1827 | |
| 1828 | - // Verify form submitted for editing single |
|
| 1829 | - if( $this->is_edit_entry_submission() ) { |
|
| 1830 | - $valid = wp_verify_nonce( $_POST[ self::$nonce_field ], self::$nonce_field ); |
|
| 1831 | - } |
|
| 1828 | + // Verify form submitted for editing single |
|
| 1829 | + if( $this->is_edit_entry_submission() ) { |
|
| 1830 | + $valid = wp_verify_nonce( $_POST[ self::$nonce_field ], self::$nonce_field ); |
|
| 1831 | + } |
|
| 1832 | 1832 | |
| 1833 | - // Verify |
|
| 1834 | - else if( ! $this->is_edit_entry() ) { |
|
| 1835 | - $valid = false; |
|
| 1836 | - } |
|
| 1833 | + // Verify |
|
| 1834 | + else if( ! $this->is_edit_entry() ) { |
|
| 1835 | + $valid = false; |
|
| 1836 | + } |
|
| 1837 | 1837 | |
| 1838 | - else { |
|
| 1839 | - $valid = wp_verify_nonce( $_GET['edit'], self::$nonce_key ); |
|
| 1840 | - } |
|
| 1838 | + else { |
|
| 1839 | + $valid = wp_verify_nonce( $_GET['edit'], self::$nonce_key ); |
|
| 1840 | + } |
|
| 1841 | 1841 | |
| 1842 | - /** |
|
| 1843 | - * @filter `gravityview/edit_entry/verify_nonce` Override Edit Entry nonce validation. Return true to declare nonce valid. |
|
| 1844 | - * @since 1.13 |
|
| 1845 | - * @param int|boolean $valid False if invalid; 1 or 2 when nonce was generated |
|
| 1846 | - * @param string $nonce_field Key used when validating submissions. Default: is_gv_edit_entry |
|
| 1847 | - */ |
|
| 1848 | - $valid = apply_filters( 'gravityview/edit_entry/verify_nonce', $valid, self::$nonce_field ); |
|
| 1842 | + /** |
|
| 1843 | + * @filter `gravityview/edit_entry/verify_nonce` Override Edit Entry nonce validation. Return true to declare nonce valid. |
|
| 1844 | + * @since 1.13 |
|
| 1845 | + * @param int|boolean $valid False if invalid; 1 or 2 when nonce was generated |
|
| 1846 | + * @param string $nonce_field Key used when validating submissions. Default: is_gv_edit_entry |
|
| 1847 | + */ |
|
| 1848 | + $valid = apply_filters( 'gravityview/edit_entry/verify_nonce', $valid, self::$nonce_field ); |
|
| 1849 | 1849 | |
| 1850 | - return $valid; |
|
| 1851 | - } |
|
| 1850 | + return $valid; |
|
| 1851 | + } |
|
| 1852 | 1852 | |
| 1853 | 1853 | |
| 1854 | 1854 | |
@@ -112,16 +112,16 @@ discard block |
||
| 112 | 112 | function load() { |
| 113 | 113 | |
| 114 | 114 | /** @define "GRAVITYVIEW_DIR" "../../../" */ |
| 115 | - include_once( GRAVITYVIEW_DIR .'includes/class-admin-approve-entries.php' ); |
|
| 115 | + include_once( GRAVITYVIEW_DIR . 'includes/class-admin-approve-entries.php' ); |
|
| 116 | 116 | |
| 117 | 117 | // Don't display an embedded form when editing an entry |
| 118 | 118 | add_action( 'wp_head', array( $this, 'prevent_render_form' ) ); |
| 119 | 119 | add_action( 'wp_footer', array( $this, 'prevent_render_form' ) ); |
| 120 | 120 | |
| 121 | 121 | // Stop Gravity Forms processing what is ours! |
| 122 | - add_filter( 'wp', array( $this, 'prevent_maybe_process_form'), 8 ); |
|
| 122 | + add_filter( 'wp', array( $this, 'prevent_maybe_process_form' ), 8 ); |
|
| 123 | 123 | |
| 124 | - add_filter( 'gravityview_is_edit_entry', array( $this, 'is_edit_entry') ); |
|
| 124 | + add_filter( 'gravityview_is_edit_entry', array( $this, 'is_edit_entry' ) ); |
|
| 125 | 125 | |
| 126 | 126 | add_action( 'gravityview_edit_entry', array( $this, 'init' ) ); |
| 127 | 127 | |
@@ -132,7 +132,7 @@ discard block |
||
| 132 | 132 | add_filter( 'gform_plupload_settings', array( $this, 'modify_fileupload_settings' ), 10, 3 ); |
| 133 | 133 | |
| 134 | 134 | // Add fields expected by GFFormDisplay::validate() |
| 135 | - add_filter( 'gform_pre_validation', array( $this, 'gform_pre_validation') ); |
|
| 135 | + add_filter( 'gform_pre_validation', array( $this, 'gform_pre_validation' ) ); |
|
| 136 | 136 | |
| 137 | 137 | } |
| 138 | 138 | |
@@ -147,8 +147,8 @@ discard block |
||
| 147 | 147 | * @return void |
| 148 | 148 | */ |
| 149 | 149 | function prevent_render_form() { |
| 150 | - if( $this->is_edit_entry() ) { |
|
| 151 | - if( 'wp_head' === current_filter() ) { |
|
| 150 | + if ( $this->is_edit_entry() ) { |
|
| 151 | + if ( 'wp_head' === current_filter() ) { |
|
| 152 | 152 | add_filter( 'gform_shortcode_form', '__return_empty_string' ); |
| 153 | 153 | } else { |
| 154 | 154 | remove_filter( 'gform_shortcode_form', '__return_empty_string' ); |
@@ -163,10 +163,10 @@ discard block |
||
| 163 | 163 | */ |
| 164 | 164 | function prevent_maybe_process_form() { |
| 165 | 165 | |
| 166 | - do_action('gravityview_log_debug', 'GravityView_Edit_Entry[prevent_maybe_process_form] $_POSTed data (sanitized): ', esc_html( print_r( $_POST, true ) ) ); |
|
| 166 | + do_action( 'gravityview_log_debug', 'GravityView_Edit_Entry[prevent_maybe_process_form] $_POSTed data (sanitized): ', esc_html( print_r( $_POST, true ) ) ); |
|
| 167 | 167 | |
| 168 | - if( $this->is_edit_entry_submission() && $this->verify_nonce() ) { |
|
| 169 | - remove_action( 'wp', array( 'RGForms', 'maybe_process_form'), 9 ); |
|
| 168 | + if ( $this->is_edit_entry_submission() && $this->verify_nonce() ) { |
|
| 169 | + remove_action( 'wp', array( 'RGForms', 'maybe_process_form' ), 9 ); |
|
| 170 | 170 | } |
| 171 | 171 | } |
| 172 | 172 | |
@@ -176,7 +176,7 @@ discard block |
||
| 176 | 176 | */ |
| 177 | 177 | public function is_edit_entry() { |
| 178 | 178 | |
| 179 | - $gf_page = class_exists('rgpost') && ( 'entry' === rgget( 'view' ) && isset( $_GET['edit'] ) || rgpost( 'action' ) === 'update' ); |
|
| 179 | + $gf_page = class_exists( 'rgpost' ) && ( 'entry' === rgget( 'view' ) && isset( $_GET[ 'edit' ] ) || rgpost( 'action' ) === 'update' ); |
|
| 180 | 180 | |
| 181 | 181 | return $gf_page; |
| 182 | 182 | } |
@@ -187,7 +187,7 @@ discard block |
||
| 187 | 187 | * @return boolean |
| 188 | 188 | */ |
| 189 | 189 | public function is_edit_entry_submission() { |
| 190 | - return !empty( $_POST[ self::$nonce_field ] ); |
|
| 190 | + return ! empty( $_POST[ self::$nonce_field ] ); |
|
| 191 | 191 | } |
| 192 | 192 | |
| 193 | 193 | /** |
@@ -198,13 +198,13 @@ discard block |
||
| 198 | 198 | |
| 199 | 199 | |
| 200 | 200 | $entries = $gravityview_view->getEntries(); |
| 201 | - $this->entry = $entries[0]; |
|
| 201 | + $this->entry = $entries[ 0 ]; |
|
| 202 | 202 | |
| 203 | 203 | $this->original_form = $this->form = $gravityview_view->getForm(); |
| 204 | 204 | $this->form_id = $gravityview_view->getFormId(); |
| 205 | 205 | $this->view_id = $gravityview_view->getViewId(); |
| 206 | 206 | |
| 207 | - self::$nonce_key = GravityView_Edit_Entry::get_nonce_key( $this->view_id, $this->form_id, $this->entry['id'] ); |
|
| 207 | + self::$nonce_key = GravityView_Edit_Entry::get_nonce_key( $this->view_id, $this->form_id, $this->entry[ 'id' ] ); |
|
| 208 | 208 | } |
| 209 | 209 | |
| 210 | 210 | |
@@ -224,12 +224,12 @@ discard block |
||
| 224 | 224 | $this->setup_vars(); |
| 225 | 225 | |
| 226 | 226 | // Multiple Views embedded, don't proceed if nonce fails |
| 227 | - if( $gv_data->has_multiple_views() && ! wp_verify_nonce( $_GET['edit'], self::$nonce_key ) ) { |
|
| 227 | + if ( $gv_data->has_multiple_views() && ! wp_verify_nonce( $_GET[ 'edit' ], self::$nonce_key ) ) { |
|
| 228 | 228 | return; |
| 229 | 229 | } |
| 230 | 230 | |
| 231 | 231 | // Sorry, you're not allowed here. |
| 232 | - if( false === $this->user_can_edit_entry( true ) ) { |
|
| 232 | + if ( false === $this->user_can_edit_entry( true ) ) { |
|
| 233 | 233 | return; |
| 234 | 234 | } |
| 235 | 235 | |
@@ -249,9 +249,9 @@ discard block |
||
| 249 | 249 | function print_scripts() { |
| 250 | 250 | $gravityview_view = GravityView_View::getInstance(); |
| 251 | 251 | |
| 252 | - wp_register_script( 'gform_gravityforms', GFCommon::get_base_url().'/js/gravityforms.js', array( 'jquery', 'gform_json', 'gform_placeholder', 'sack', 'plupload-all', 'gravityview-fe-view' ) ); |
|
| 252 | + wp_register_script( 'gform_gravityforms', GFCommon::get_base_url() . '/js/gravityforms.js', array( 'jquery', 'gform_json', 'gform_placeholder', 'sack', 'plupload-all', 'gravityview-fe-view' ) ); |
|
| 253 | 253 | |
| 254 | - GFFormDisplay::enqueue_form_scripts($gravityview_view->getForm(), false); |
|
| 254 | + GFFormDisplay::enqueue_form_scripts( $gravityview_view->getForm(), false ); |
|
| 255 | 255 | |
| 256 | 256 | // Sack is required for images |
| 257 | 257 | wp_print_scripts( array( 'sack', 'gform_gravityforms' ) ); |
@@ -263,32 +263,32 @@ discard block |
||
| 263 | 263 | */ |
| 264 | 264 | function process_save() { |
| 265 | 265 | |
| 266 | - if( empty( $_POST ) ) { |
|
| 266 | + if ( empty( $_POST ) ) { |
|
| 267 | 267 | return; |
| 268 | 268 | } |
| 269 | 269 | |
| 270 | 270 | // Make sure the entry, view, and form IDs are all correct |
| 271 | 271 | $valid = $this->verify_nonce(); |
| 272 | 272 | |
| 273 | - if( !$valid ) { |
|
| 274 | - do_action('gravityview_log_error', __METHOD__ . ' Nonce validation failed.' ); |
|
| 273 | + if ( ! $valid ) { |
|
| 274 | + do_action( 'gravityview_log_error', __METHOD__ . ' Nonce validation failed.' ); |
|
| 275 | 275 | return; |
| 276 | 276 | } |
| 277 | 277 | |
| 278 | - if( $this->entry['id'] !== $_POST['lid'] ) { |
|
| 279 | - do_action('gravityview_log_error', __METHOD__ . ' Entry ID did not match posted entry ID.' ); |
|
| 278 | + if ( $this->entry[ 'id' ] !== $_POST[ 'lid' ] ) { |
|
| 279 | + do_action( 'gravityview_log_error', __METHOD__ . ' Entry ID did not match posted entry ID.' ); |
|
| 280 | 280 | return; |
| 281 | 281 | } |
| 282 | 282 | |
| 283 | - do_action('gravityview_log_debug', 'GravityView_Edit_Entry[process_save] $_POSTed data (sanitized): ', esc_html( print_r( $_POST, true ) ) ); |
|
| 283 | + do_action( 'gravityview_log_debug', 'GravityView_Edit_Entry[process_save] $_POSTed data (sanitized): ', esc_html( print_r( $_POST, true ) ) ); |
|
| 284 | 284 | |
| 285 | 285 | $this->process_save_process_files( $this->form_id ); |
| 286 | 286 | |
| 287 | 287 | $this->validate(); |
| 288 | 288 | |
| 289 | - if( $this->is_valid ) { |
|
| 289 | + if ( $this->is_valid ) { |
|
| 290 | 290 | |
| 291 | - do_action('gravityview_log_debug', 'GravityView_Edit_Entry[process_save] Submission is valid.' ); |
|
| 291 | + do_action( 'gravityview_log_debug', 'GravityView_Edit_Entry[process_save] Submission is valid.' ); |
|
| 292 | 292 | |
| 293 | 293 | /** |
| 294 | 294 | * @hack This step is needed to unset the adminOnly from form fields, to add the calculation fields |
@@ -298,12 +298,12 @@ discard block |
||
| 298 | 298 | /** |
| 299 | 299 | * @hack to avoid the capability validation of the method save_lead for GF 1.9+ |
| 300 | 300 | */ |
| 301 | - unset( $_GET['page'] ); |
|
| 301 | + unset( $_GET[ 'page' ] ); |
|
| 302 | 302 | |
| 303 | 303 | GFFormsModel::save_lead( $form, $this->entry ); |
| 304 | 304 | |
| 305 | 305 | // If there's a post associated with the entry, process post fields |
| 306 | - if( !empty( $this->entry['post_id'] ) ) { |
|
| 306 | + if ( ! empty( $this->entry[ 'post_id' ] ) ) { |
|
| 307 | 307 | $this->maybe_update_post_fields( $form ); |
| 308 | 308 | } |
| 309 | 309 | |
@@ -318,7 +318,7 @@ discard block |
||
| 318 | 318 | * @param array $form Gravity Forms form array |
| 319 | 319 | * @param string $entry_id Numeric ID of the entry that was updated |
| 320 | 320 | */ |
| 321 | - do_action( 'gravityview/edit_entry/after_update', $this->form, $this->entry['id'] ); |
|
| 321 | + do_action( 'gravityview/edit_entry/after_update', $this->form, $this->entry[ 'id' ] ); |
|
| 322 | 322 | } |
| 323 | 323 | |
| 324 | 324 | } // process_save |
@@ -352,11 +352,11 @@ discard block |
||
| 352 | 352 | * @return mixed |
| 353 | 353 | */ |
| 354 | 354 | public function modify_fileupload_settings( $plupload_init, $form_id, $instance ) { |
| 355 | - if( ! $this->is_edit_entry() ) { |
|
| 355 | + if ( ! $this->is_edit_entry() ) { |
|
| 356 | 356 | return $plupload_init; |
| 357 | 357 | } |
| 358 | 358 | |
| 359 | - $plupload_init['gf_vars']['max_files'] = 0; |
|
| 359 | + $plupload_init[ 'gf_vars' ][ 'max_files' ] = 0; |
|
| 360 | 360 | |
| 361 | 361 | return $plupload_init; |
| 362 | 362 | } |
@@ -370,19 +370,19 @@ discard block |
||
| 370 | 370 | |
| 371 | 371 | $form = $this->form; |
| 372 | 372 | |
| 373 | - foreach( $form['fields'] as $k => &$field ) { |
|
| 373 | + foreach ( $form[ 'fields' ] as $k => &$field ) { |
|
| 374 | 374 | |
| 375 | 375 | // Remove the fields with calculation formulas before save to avoid conflicts with GF logic |
| 376 | 376 | // @since 1.16.3 |
| 377 | - if( $field->has_calculation() ) { |
|
| 378 | - unset( $form['fields'][ $k ] ); |
|
| 377 | + if ( $field->has_calculation() ) { |
|
| 378 | + unset( $form[ 'fields' ][ $k ] ); |
|
| 379 | 379 | } |
| 380 | 380 | |
| 381 | 381 | $field->adminOnly = false; |
| 382 | 382 | |
| 383 | - if( isset( $field->inputs ) && is_array( $field->inputs ) ) { |
|
| 384 | - foreach( $field->inputs as $key => $input ) { |
|
| 385 | - $field->inputs[ $key ][ 'id' ] = (string)$input['id']; |
|
| 383 | + if ( isset( $field->inputs ) && is_array( $field->inputs ) ) { |
|
| 384 | + foreach ( $field->inputs as $key => $input ) { |
|
| 385 | + $field->inputs[ $key ][ 'id' ] = (string)$input[ 'id' ]; |
|
| 386 | 386 | } |
| 387 | 387 | } |
| 388 | 388 | } |
@@ -396,20 +396,20 @@ discard block |
||
| 396 | 396 | $update = false; |
| 397 | 397 | |
| 398 | 398 | // get the most up to date entry values |
| 399 | - $entry = GFAPI::get_entry( $this->entry['id'] ); |
|
| 399 | + $entry = GFAPI::get_entry( $this->entry[ 'id' ] ); |
|
| 400 | 400 | |
| 401 | - if( !empty( $this->fields_with_calculation ) ) { |
|
| 401 | + if ( ! empty( $this->fields_with_calculation ) ) { |
|
| 402 | 402 | $update = true; |
| 403 | 403 | foreach ( $this->fields_with_calculation as $calc_field ) { |
| 404 | 404 | $inputs = $calc_field->get_entry_inputs(); |
| 405 | 405 | if ( is_array( $inputs ) ) { |
| 406 | 406 | foreach ( $inputs as $input ) { |
| 407 | - $input_name = 'input_' . str_replace( '.', '_', $input['id'] ); |
|
| 408 | - $entry[ strval( $input['id'] ) ] = RGFormsModel::prepare_value( $form, $calc_field, '', $input_name, $entry['id'], $entry ); |
|
| 407 | + $input_name = 'input_' . str_replace( '.', '_', $input[ 'id' ] ); |
|
| 408 | + $entry[ strval( $input[ 'id' ] ) ] = RGFormsModel::prepare_value( $form, $calc_field, '', $input_name, $entry[ 'id' ], $entry ); |
|
| 409 | 409 | } |
| 410 | 410 | } else { |
| 411 | - $input_name = 'input_' . str_replace( '.', '_', $calc_field->id); |
|
| 412 | - $entry[ strval( $calc_field->id ) ] = RGFormsModel::prepare_value( $form, $calc_field, '', $input_name, $entry['id'], $entry ); |
|
| 411 | + $input_name = 'input_' . str_replace( '.', '_', $calc_field->id ); |
|
| 412 | + $entry[ strval( $calc_field->id ) ] = RGFormsModel::prepare_value( $form, $calc_field, '', $input_name, $entry[ 'id' ], $entry ); |
|
| 413 | 413 | } |
| 414 | 414 | } |
| 415 | 415 | |
@@ -419,16 +419,16 @@ discard block |
||
| 419 | 419 | if ( ! empty( $this->total_fields ) ) { |
| 420 | 420 | $update = true; |
| 421 | 421 | foreach ( $this->total_fields as $total_field ) { |
| 422 | - $input_name = 'input_' . str_replace( '.', '_', $total_field->id); |
|
| 423 | - $entry[ strval( $total_field->id ) ] = RGFormsModel::prepare_value( $form, $total_field, '', $input_name, $entry['id'], $entry ); |
|
| 422 | + $input_name = 'input_' . str_replace( '.', '_', $total_field->id ); |
|
| 423 | + $entry[ strval( $total_field->id ) ] = RGFormsModel::prepare_value( $form, $total_field, '', $input_name, $entry[ 'id' ], $entry ); |
|
| 424 | 424 | } |
| 425 | 425 | } |
| 426 | 426 | |
| 427 | - if( $update ) { |
|
| 427 | + if ( $update ) { |
|
| 428 | 428 | |
| 429 | 429 | $return_entry = GFAPI::update_entry( $entry ); |
| 430 | 430 | |
| 431 | - if( is_wp_error( $return_entry ) ) { |
|
| 431 | + if ( is_wp_error( $return_entry ) ) { |
|
| 432 | 432 | do_action( 'gravityview_log_error', 'Updating the entry calculation and total fields failed', $return_entry ); |
| 433 | 433 | } else { |
| 434 | 434 | do_action( 'gravityview_log_debug', 'Updating the entry calculation and total fields succeeded' ); |
@@ -446,11 +446,11 @@ discard block |
||
| 446 | 446 | */ |
| 447 | 447 | function maybe_update_post_fields( $form ) { |
| 448 | 448 | |
| 449 | - $post_id = $this->entry['post_id']; |
|
| 449 | + $post_id = $this->entry[ 'post_id' ]; |
|
| 450 | 450 | |
| 451 | 451 | // Security check |
| 452 | - if( false === GVCommon::has_cap( 'edit_post', $post_id ) ) { |
|
| 453 | - do_action( 'gravityview_log_error', 'The current user does not have the ability to edit Post #'.$post_id ); |
|
| 452 | + if ( false === GVCommon::has_cap( 'edit_post', $post_id ) ) { |
|
| 453 | + do_action( 'gravityview_log_error', 'The current user does not have the ability to edit Post #' . $post_id ); |
|
| 454 | 454 | return; |
| 455 | 455 | } |
| 456 | 456 | |
@@ -459,7 +459,7 @@ discard block |
||
| 459 | 459 | $updated_post = $original_post = get_post( $post_id ); |
| 460 | 460 | |
| 461 | 461 | // get the most up to date entry values |
| 462 | - $entry = GFAPI::get_entry( $this->entry['id'] ); |
|
| 462 | + $entry = GFAPI::get_entry( $this->entry[ 'id' ] ); |
|
| 463 | 463 | |
| 464 | 464 | foreach ( $entry as $field_id => $value ) { |
| 465 | 465 | |
@@ -467,16 +467,16 @@ discard block |
||
| 467 | 467 | |
| 468 | 468 | $field = RGFormsModel::get_field( $form, $field_id ); |
| 469 | 469 | |
| 470 | - if( class_exists('GF_Fields') ) { |
|
| 470 | + if ( class_exists( 'GF_Fields' ) ) { |
|
| 471 | 471 | $field = GF_Fields::create( $field ); |
| 472 | 472 | } |
| 473 | 473 | |
| 474 | - if( GFCommon::is_post_field( $field ) ) { |
|
| 474 | + if ( GFCommon::is_post_field( $field ) ) { |
|
| 475 | 475 | |
| 476 | 476 | // Get the value of the field, including $_POSTed value |
| 477 | 477 | $value = RGFormsModel::get_field_value( $field ); |
| 478 | 478 | |
| 479 | - switch( $field->type ) { |
|
| 479 | + switch ( $field->type ) { |
|
| 480 | 480 | |
| 481 | 481 | case 'post_title': |
| 482 | 482 | case 'post_content': |
@@ -494,14 +494,14 @@ discard block |
||
| 494 | 494 | wp_set_post_categories( $post_id, $categories, false ); |
| 495 | 495 | |
| 496 | 496 | // if post_category is type checkbox, then value is an array of inputs |
| 497 | - if( isset( $value[ strval( $field_id ) ] ) ) { |
|
| 498 | - foreach( $value as $input_id => $val ) { |
|
| 497 | + if ( isset( $value[ strval( $field_id ) ] ) ) { |
|
| 498 | + foreach ( $value as $input_id => $val ) { |
|
| 499 | 499 | $input_name = 'input_' . str_replace( '.', '_', $input_id ); |
| 500 | - $entry[ strval( $input_id ) ] = RGFormsModel::prepare_value( $form, $field, $val, $input_name, $entry['id'], $entry ); |
|
| 500 | + $entry[ strval( $input_id ) ] = RGFormsModel::prepare_value( $form, $field, $val, $input_name, $entry[ 'id' ], $entry ); |
|
| 501 | 501 | } |
| 502 | 502 | } else { |
| 503 | 503 | $input_name = 'input_' . str_replace( '.', '_', $field_id ); |
| 504 | - $entry[ strval( $field_id ) ] = RGFormsModel::prepare_value( $form, $field, $value, $input_name, $entry['id'], $entry ); |
|
| 504 | + $entry[ strval( $field_id ) ] = RGFormsModel::prepare_value( $form, $field, $value, $input_name, $entry[ 'id' ], $entry ); |
|
| 505 | 505 | } |
| 506 | 506 | |
| 507 | 507 | break; |
@@ -511,12 +511,12 @@ discard block |
||
| 511 | 511 | $custom_field_name = $field->postCustomFieldName; |
| 512 | 512 | |
| 513 | 513 | // Only certain custom field types are supported |
| 514 | - switch( $input_type ) { |
|
| 514 | + switch ( $input_type ) { |
|
| 515 | 515 | case 'fileupload': |
| 516 | 516 | /** @noinspection PhpMissingBreakStatementInspection */ |
| 517 | 517 | case 'list': |
| 518 | - if( ! is_string( $value ) ) { |
|
| 519 | - $value = function_exists('wp_json_encode') ? wp_json_encode( $value ) : json_encode( $value ); |
|
| 518 | + if ( ! is_string( $value ) ) { |
|
| 519 | + $value = function_exists( 'wp_json_encode' ) ? wp_json_encode( $value ) : json_encode( $value ); |
|
| 520 | 520 | } |
| 521 | 521 | // break; left intentionally out |
| 522 | 522 | default: |
@@ -529,11 +529,11 @@ discard block |
||
| 529 | 529 | |
| 530 | 530 | $input_name = 'input_' . $field_id; |
| 531 | 531 | |
| 532 | - if ( !empty( $_FILES[ $input_name ]['name'] ) ) { |
|
| 532 | + if ( ! empty( $_FILES[ $input_name ][ 'name' ] ) ) { |
|
| 533 | 533 | |
| 534 | 534 | // We have a new image |
| 535 | 535 | |
| 536 | - $value = RGFormsModel::prepare_value( $form, $field, $value, $input_name, $entry['id'] ); |
|
| 536 | + $value = RGFormsModel::prepare_value( $form, $field, $value, $input_name, $entry[ 'id' ] ); |
|
| 537 | 537 | |
| 538 | 538 | // is this field set as featured image, if not, leave |
| 539 | 539 | if ( ! $field->postFeaturedImage ) { |
@@ -543,9 +543,9 @@ discard block |
||
| 543 | 543 | $ary = ! empty( $value ) ? explode( '|:|', $value ) : array(); |
| 544 | 544 | $img_url = rgar( $ary, 0 ); |
| 545 | 545 | |
| 546 | - $img_title = count( $ary ) > 1 ? $ary[1] : ''; |
|
| 547 | - $img_caption = count( $ary ) > 2 ? $ary[2] : ''; |
|
| 548 | - $img_description = count( $ary ) > 3 ? $ary[3] : ''; |
|
| 546 | + $img_title = count( $ary ) > 1 ? $ary[ 1 ] : ''; |
|
| 547 | + $img_caption = count( $ary ) > 2 ? $ary[ 2 ] : ''; |
|
| 548 | + $img_description = count( $ary ) > 3 ? $ary[ 3 ] : ''; |
|
| 549 | 549 | |
| 550 | 550 | $image_meta = array( |
| 551 | 551 | 'post_excerpt' => $img_caption, |
@@ -554,7 +554,7 @@ discard block |
||
| 554 | 554 | |
| 555 | 555 | //adding title only if it is not empty. It will default to the file name if it is not in the array |
| 556 | 556 | if ( ! empty( $img_title ) ) { |
| 557 | - $image_meta['post_title'] = $img_title; |
|
| 557 | + $image_meta[ 'post_title' ] = $img_title; |
|
| 558 | 558 | } |
| 559 | 559 | |
| 560 | 560 | //todo: As soon as \GFFormsModel::media_handle_upload becomes a public method, move this call to \GFFormsModel::media_handle_upload and remove the hack from this class. |
@@ -567,7 +567,7 @@ discard block |
||
| 567 | 567 | |
| 568 | 568 | break; |
| 569 | 569 | |
| 570 | - } elseif ( !empty( $_POST[ $input_name ] ) && is_array( $value ) ) { |
|
| 570 | + } elseif ( ! empty( $_POST[ $input_name ] ) && is_array( $value ) ) { |
|
| 571 | 571 | |
| 572 | 572 | // Same image although the image title, caption or description might have changed |
| 573 | 573 | |
@@ -575,11 +575,11 @@ discard block |
||
| 575 | 575 | $img_url = rgar( $ary, 0 ); |
| 576 | 576 | |
| 577 | 577 | // is this really the same image or something went wrong ? |
| 578 | - if( $img_url === $_POST[ $input_name ] ) { |
|
| 578 | + if ( $img_url === $_POST[ $input_name ] ) { |
|
| 579 | 579 | |
| 580 | - $img_title = isset( $value[ $field_id .'.1' ] ) ? $value[ $field_id .'.1' ] : ''; |
|
| 581 | - $img_caption = isset( $value[ $field_id .'.4' ] ) ? $value[ $field_id .'.4' ] : ''; |
|
| 582 | - $img_description = isset( $value[ $field_id .'.7' ] ) ? $value[ $field_id .'.7' ] : ''; |
|
| 580 | + $img_title = isset( $value[ $field_id . '.1' ] ) ? $value[ $field_id . '.1' ] : ''; |
|
| 581 | + $img_caption = isset( $value[ $field_id . '.4' ] ) ? $value[ $field_id . '.4' ] : ''; |
|
| 582 | + $img_description = isset( $value[ $field_id . '.7' ] ) ? $value[ $field_id . '.7' ] : ''; |
|
| 583 | 583 | |
| 584 | 584 | $value = ! empty( $img_url ) ? $img_url . "|:|" . $img_title . "|:|" . $img_caption . "|:|" . $img_description : ''; |
| 585 | 585 | |
@@ -613,12 +613,12 @@ discard block |
||
| 613 | 613 | } |
| 614 | 614 | |
| 615 | 615 | //ignore fields that have not changed |
| 616 | - if ( $value === rgget( (string) $field_id, $entry ) ) { |
|
| 616 | + if ( $value === rgget( (string)$field_id, $entry ) ) { |
|
| 617 | 617 | continue; |
| 618 | 618 | } |
| 619 | 619 | |
| 620 | 620 | // update entry |
| 621 | - if( 'post_category' !== $field->type ) { |
|
| 621 | + if ( 'post_category' !== $field->type ) { |
|
| 622 | 622 | $entry[ strval( $field_id ) ] = $value; |
| 623 | 623 | } |
| 624 | 624 | |
@@ -628,25 +628,25 @@ discard block |
||
| 628 | 628 | |
| 629 | 629 | } |
| 630 | 630 | |
| 631 | - if( $update_entry ) { |
|
| 631 | + if ( $update_entry ) { |
|
| 632 | 632 | |
| 633 | 633 | $return_entry = GFAPI::update_entry( $entry ); |
| 634 | 634 | |
| 635 | - if( is_wp_error( $return_entry ) ) { |
|
| 635 | + if ( is_wp_error( $return_entry ) ) { |
|
| 636 | 636 | do_action( 'gravityview_log_error', 'Updating the entry post fields failed', $return_entry ); |
| 637 | 637 | } else { |
| 638 | - do_action( 'gravityview_log_debug', 'Updating the entry post fields for post #'.$post_id.' succeeded' ); |
|
| 638 | + do_action( 'gravityview_log_debug', 'Updating the entry post fields for post #' . $post_id . ' succeeded' ); |
|
| 639 | 639 | } |
| 640 | 640 | |
| 641 | 641 | } |
| 642 | 642 | |
| 643 | 643 | $return_post = wp_update_post( $updated_post, true ); |
| 644 | 644 | |
| 645 | - if( is_wp_error( $return_post ) ) { |
|
| 645 | + if ( is_wp_error( $return_post ) ) { |
|
| 646 | 646 | $return_post->add_data( $updated_post, '$updated_post' ); |
| 647 | 647 | do_action( 'gravityview_log_error', 'Updating the post content failed', $return_post ); |
| 648 | 648 | } else { |
| 649 | - do_action( 'gravityview_log_debug', 'Updating the post content for post #'.$post_id.' succeeded', $updated_post ); |
|
| 649 | + do_action( 'gravityview_log_debug', 'Updating the post content for post #' . $post_id . ' succeeded', $updated_post ); |
|
| 650 | 650 | } |
| 651 | 651 | |
| 652 | 652 | } |
@@ -663,18 +663,18 @@ discard block |
||
| 663 | 663 | */ |
| 664 | 664 | function after_update() { |
| 665 | 665 | |
| 666 | - do_action( 'gform_after_update_entry', $this->form, $this->entry['id'] ); |
|
| 667 | - do_action( "gform_after_update_entry_{$this->form['id']}", $this->form, $this->entry['id'] ); |
|
| 666 | + do_action( 'gform_after_update_entry', $this->form, $this->entry[ 'id' ] ); |
|
| 667 | + do_action( "gform_after_update_entry_{$this->form[ 'id' ]}", $this->form, $this->entry[ 'id' ] ); |
|
| 668 | 668 | |
| 669 | 669 | // Re-define the entry now that we've updated it. |
| 670 | - $entry = RGFormsModel::get_lead( $this->entry['id'] ); |
|
| 670 | + $entry = RGFormsModel::get_lead( $this->entry[ 'id' ] ); |
|
| 671 | 671 | |
| 672 | 672 | $entry = GFFormsModel::set_entry_meta( $entry, $this->form ); |
| 673 | 673 | |
| 674 | 674 | // We need to clear the cache because Gravity Forms caches the field values, which |
| 675 | 675 | // we have just updated. |
| 676 | - foreach ($this->form['fields'] as $key => $field) { |
|
| 677 | - GFFormsModel::refresh_lead_field_value( $entry['id'], $field->id ); |
|
| 676 | + foreach ( $this->form[ 'fields' ] as $key => $field ) { |
|
| 677 | + GFFormsModel::refresh_lead_field_value( $entry[ 'id' ], $field->id ); |
|
| 678 | 678 | } |
| 679 | 679 | |
| 680 | 680 | $this->entry = $entry; |
@@ -692,7 +692,7 @@ discard block |
||
| 692 | 692 | |
| 693 | 693 | <div class="gv-edit-entry-wrapper"><?php |
| 694 | 694 | |
| 695 | - $javascript = gravityview_ob_include( GravityView_Edit_Entry::$file .'/partials/inline-javascript.php', $this ); |
|
| 695 | + $javascript = gravityview_ob_include( GravityView_Edit_Entry::$file . '/partials/inline-javascript.php', $this ); |
|
| 696 | 696 | |
| 697 | 697 | /** |
| 698 | 698 | * Fixes weird wpautop() issue |
@@ -708,7 +708,7 @@ discard block |
||
| 708 | 708 | * @param string $edit_entry_title Modify the "Edit Entry" title |
| 709 | 709 | * @param GravityView_Edit_Entry_Render $this This object |
| 710 | 710 | */ |
| 711 | - $edit_entry_title = apply_filters('gravityview_edit_entry_title', __('Edit Entry', 'gravityview'), $this ); |
|
| 711 | + $edit_entry_title = apply_filters( 'gravityview_edit_entry_title', __( 'Edit Entry', 'gravityview' ), $this ); |
|
| 712 | 712 | |
| 713 | 713 | echo esc_attr( $edit_entry_title ); |
| 714 | 714 | ?></span> |
@@ -748,20 +748,20 @@ discard block |
||
| 748 | 748 | */ |
| 749 | 749 | private function maybe_print_message() { |
| 750 | 750 | |
| 751 | - if( rgpost('action') === 'update' ) { |
|
| 751 | + if ( rgpost( 'action' ) === 'update' ) { |
|
| 752 | 752 | |
| 753 | 753 | $back_link = esc_url( remove_query_arg( array( 'page', 'view', 'edit' ) ) ); |
| 754 | 754 | |
| 755 | - if( ! $this->is_valid ){ |
|
| 755 | + if ( ! $this->is_valid ) { |
|
| 756 | 756 | |
| 757 | 757 | // Keeping this compatible with Gravity Forms. |
| 758 | - $validation_message = "<div class='validation_error'>" . __('There was a problem with your submission.', 'gravityview') . " " . __('Errors have been highlighted below.', 'gravityview') . "</div>"; |
|
| 759 | - $message = apply_filters("gform_validation_message_{$this->form['id']}", apply_filters("gform_validation_message", $validation_message, $this->form), $this->form); |
|
| 758 | + $validation_message = "<div class='validation_error'>" . __( 'There was a problem with your submission.', 'gravityview' ) . " " . __( 'Errors have been highlighted below.', 'gravityview' ) . "</div>"; |
|
| 759 | + $message = apply_filters( "gform_validation_message_{$this->form[ 'id' ]}", apply_filters( "gform_validation_message", $validation_message, $this->form ), $this->form ); |
|
| 760 | 760 | |
| 761 | - echo GVCommon::generate_notice( $message , 'gv-error' ); |
|
| 761 | + echo GVCommon::generate_notice( $message, 'gv-error' ); |
|
| 762 | 762 | |
| 763 | 763 | } else { |
| 764 | - $entry_updated_message = sprintf( esc_attr__('Entry Updated. %sReturn to Entry%s', 'gravityview'), '<a href="'. $back_link .'">', '</a>' ); |
|
| 764 | + $entry_updated_message = sprintf( esc_attr__( 'Entry Updated. %sReturn to Entry%s', 'gravityview' ), '<a href="' . $back_link . '">', '</a>' ); |
|
| 765 | 765 | |
| 766 | 766 | /** |
| 767 | 767 | * @filter `gravityview/edit_entry/success` Modify the edit entry success message (including the anchor link) |
@@ -771,7 +771,7 @@ discard block |
||
| 771 | 771 | * @param array $entry Gravity Forms entry array |
| 772 | 772 | * @param string $back_link URL to return to the original entry. @since 1.6 |
| 773 | 773 | */ |
| 774 | - $message = apply_filters( 'gravityview/edit_entry/success', $entry_updated_message , $this->view_id, $this->entry, $back_link ); |
|
| 774 | + $message = apply_filters( 'gravityview/edit_entry/success', $entry_updated_message, $this->view_id, $this->entry, $back_link ); |
|
| 775 | 775 | |
| 776 | 776 | echo GVCommon::generate_notice( $message ); |
| 777 | 777 | } |
@@ -788,24 +788,24 @@ discard block |
||
| 788 | 788 | */ |
| 789 | 789 | private function render_edit_form() { |
| 790 | 790 | |
| 791 | - add_filter( 'gform_pre_render', array( $this, 'filter_modify_form_fields'), 5000, 3 ); |
|
| 792 | - add_filter( 'gform_submit_button', array( $this, 'render_form_buttons') ); |
|
| 791 | + add_filter( 'gform_pre_render', array( $this, 'filter_modify_form_fields' ), 5000, 3 ); |
|
| 792 | + add_filter( 'gform_submit_button', array( $this, 'render_form_buttons' ) ); |
|
| 793 | 793 | add_filter( 'gform_disable_view_counter', '__return_true' ); |
| 794 | 794 | |
| 795 | 795 | add_filter( 'gform_field_input', array( $this, 'verify_user_can_edit_post' ), 5, 5 ); |
| 796 | 796 | add_filter( 'gform_field_input', array( $this, 'modify_edit_field_input' ), 10, 5 ); |
| 797 | 797 | |
| 798 | - add_filter( 'gform_field_value', array( $this, 'fix_survey_fields_value'), 10, 3 ); |
|
| 798 | + add_filter( 'gform_field_value', array( $this, 'fix_survey_fields_value' ), 10, 3 ); |
|
| 799 | 799 | |
| 800 | 800 | // We need to remove the fake $_GET['page'] arg to avoid rendering form as if in admin. |
| 801 | - unset( $_GET['page'] ); |
|
| 801 | + unset( $_GET[ 'page' ] ); |
|
| 802 | 802 | |
| 803 | 803 | // TODO: Verify multiple-page forms |
| 804 | 804 | // TODO: Product fields are not editable |
| 805 | 805 | |
| 806 | - $html = GFFormDisplay::get_form( $this->form['id'], false, false, true, $this->entry ); |
|
| 806 | + $html = GFFormDisplay::get_form( $this->form[ 'id' ], false, false, true, $this->entry ); |
|
| 807 | 807 | |
| 808 | - remove_filter( 'gform_field_value', array( $this, 'fix_survey_fields_value'), 10 ); |
|
| 808 | + remove_filter( 'gform_field_value', array( $this, 'fix_survey_fields_value' ), 10 ); |
|
| 809 | 809 | remove_filter( 'gform_pre_render', array( $this, 'filter_modify_form_fields' ), 5000 ); |
| 810 | 810 | remove_filter( 'gform_submit_button', array( $this, 'render_form_buttons' ) ); |
| 811 | 811 | remove_filter( 'gform_disable_view_counter', '__return_true' ); |
@@ -829,7 +829,7 @@ discard block |
||
| 829 | 829 | */ |
| 830 | 830 | function fix_survey_fields_value( $value, $field, $name ) { |
| 831 | 831 | |
| 832 | - if( 'survey' === $field->type && '' === $value && 'likert' === rgar( $field, 'inputType' ) ) { |
|
| 832 | + if ( 'survey' === $field->type && '' === $value && 'likert' === rgar( $field, 'inputType' ) ) { |
|
| 833 | 833 | |
| 834 | 834 | // We need to run through each survey row until we find a match for expected values |
| 835 | 835 | foreach ( $this->entry as $field_id => $field_value ) { |
@@ -838,11 +838,11 @@ discard block |
||
| 838 | 838 | continue; |
| 839 | 839 | } |
| 840 | 840 | |
| 841 | - if( rgar( $field, 'gsurveyLikertEnableMultipleRows' ) ) { |
|
| 841 | + if ( rgar( $field, 'gsurveyLikertEnableMultipleRows' ) ) { |
|
| 842 | 842 | list( $row_val, $col_val ) = explode( ':', $field_value, 2 ); |
| 843 | 843 | |
| 844 | 844 | // If the $name matches the $row_val, we are processing the correct row |
| 845 | - if( $row_val === $name ) { |
|
| 845 | + if ( $row_val === $name ) { |
|
| 846 | 846 | $value = $field_value; |
| 847 | 847 | break; |
| 848 | 848 | } |
@@ -863,7 +863,7 @@ discard block |
||
| 863 | 863 | * @return string |
| 864 | 864 | */ |
| 865 | 865 | public function render_form_buttons() { |
| 866 | - return gravityview_ob_include( GravityView_Edit_Entry::$file .'/partials/form-buttons.php', $this ); |
|
| 866 | + return gravityview_ob_include( GravityView_Edit_Entry::$file . '/partials/form-buttons.php', $this ); |
|
| 867 | 867 | } |
| 868 | 868 | |
| 869 | 869 | |
@@ -883,17 +883,17 @@ discard block |
||
| 883 | 883 | public function filter_modify_form_fields( $form, $ajax = false, $field_values = '' ) { |
| 884 | 884 | |
| 885 | 885 | // In case we have validated the form, use it to inject the validation results into the form render |
| 886 | - if( isset( $this->form_after_validation ) ) { |
|
| 886 | + if ( isset( $this->form_after_validation ) ) { |
|
| 887 | 887 | $form = $this->form_after_validation; |
| 888 | 888 | } else { |
| 889 | - $form['fields'] = $this->get_configured_edit_fields( $form, $this->view_id ); |
|
| 889 | + $form[ 'fields' ] = $this->get_configured_edit_fields( $form, $this->view_id ); |
|
| 890 | 890 | } |
| 891 | 891 | |
| 892 | 892 | $form = $this->filter_conditional_logic( $form ); |
| 893 | 893 | |
| 894 | 894 | // for now we don't support Save and Continue feature. |
| 895 | - if( ! self::$supports_save_and_continue ) { |
|
| 896 | - unset( $form['save'] ); |
|
| 895 | + if ( ! self::$supports_save_and_continue ) { |
|
| 896 | + unset( $form[ 'save' ] ); |
|
| 897 | 897 | } |
| 898 | 898 | |
| 899 | 899 | return $form; |
@@ -914,29 +914,29 @@ discard block |
||
| 914 | 914 | */ |
| 915 | 915 | function verify_user_can_edit_post( $field_content = '', $field, $value, $lead_id = 0, $form_id ) { |
| 916 | 916 | |
| 917 | - if( GFCommon::is_post_field( $field ) ) { |
|
| 917 | + if ( GFCommon::is_post_field( $field ) ) { |
|
| 918 | 918 | |
| 919 | 919 | $message = null; |
| 920 | 920 | |
| 921 | 921 | // First, make sure they have the capability to edit the post. |
| 922 | - if( false === current_user_can( 'edit_post', $this->entry['post_id'] ) ) { |
|
| 922 | + if ( false === current_user_can( 'edit_post', $this->entry[ 'post_id' ] ) ) { |
|
| 923 | 923 | |
| 924 | 924 | /** |
| 925 | 925 | * @filter `gravityview/edit_entry/unsupported_post_field_text` Modify the message when someone isn't able to edit a post |
| 926 | 926 | * @param string $message The existing "You don't have permission..." text |
| 927 | 927 | */ |
| 928 | - $message = apply_filters('gravityview/edit_entry/unsupported_post_field_text', __('You don’t have permission to edit this post.', 'gravityview') ); |
|
| 928 | + $message = apply_filters( 'gravityview/edit_entry/unsupported_post_field_text', __( 'You don’t have permission to edit this post.', 'gravityview' ) ); |
|
| 929 | 929 | |
| 930 | - } elseif( null === get_post( $this->entry['post_id'] ) ) { |
|
| 930 | + } elseif ( null === get_post( $this->entry[ 'post_id' ] ) ) { |
|
| 931 | 931 | /** |
| 932 | 932 | * @filter `gravityview/edit_entry/no_post_text` Modify the message when someone is editing an entry attached to a post that no longer exists |
| 933 | 933 | * @param string $message The existing "This field is not editable; the post no longer exists." text |
| 934 | 934 | */ |
| 935 | - $message = apply_filters('gravityview/edit_entry/no_post_text', __('This field is not editable; the post no longer exists.', 'gravityview' ) ); |
|
| 935 | + $message = apply_filters( 'gravityview/edit_entry/no_post_text', __( 'This field is not editable; the post no longer exists.', 'gravityview' ) ); |
|
| 936 | 936 | } |
| 937 | 937 | |
| 938 | - if( $message ) { |
|
| 939 | - $field_content = sprintf('<div class="ginput_container ginput_container_' . $field->type . '">%s</div>', wpautop( $message ) ); |
|
| 938 | + if ( $message ) { |
|
| 939 | + $field_content = sprintf( '<div class="ginput_container ginput_container_' . $field->type . '">%s</div>', wpautop( $message ) ); |
|
| 940 | 940 | } |
| 941 | 941 | } |
| 942 | 942 | |
@@ -961,8 +961,8 @@ discard block |
||
| 961 | 961 | |
| 962 | 962 | // If the form has been submitted, then we don't need to pre-fill the values, |
| 963 | 963 | // Except for fileupload type and when a field input is overridden- run always!! |
| 964 | - if( |
|
| 965 | - ( $this->is_edit_entry_submission() && !in_array( $field->type, array( 'fileupload', 'post_image' ) ) ) |
|
| 964 | + if ( |
|
| 965 | + ( $this->is_edit_entry_submission() && ! in_array( $field->type, array( 'fileupload', 'post_image' ) ) ) |
|
| 966 | 966 | && false === ( $gv_field && is_callable( array( $gv_field, 'get_field_input' ) ) ) |
| 967 | 967 | || ! empty( $field_content ) |
| 968 | 968 | || GFCommon::is_product_field( $field->type ) // Prevent product fields from appearing editable |
@@ -971,8 +971,8 @@ discard block |
||
| 971 | 971 | } |
| 972 | 972 | |
| 973 | 973 | // Turn on Admin-style display for file upload fields only |
| 974 | - if( 'fileupload' === $field->type ) { |
|
| 975 | - $_GET['page'] = 'gf_entries'; |
|
| 974 | + if ( 'fileupload' === $field->type ) { |
|
| 975 | + $_GET[ 'page' ] = 'gf_entries'; |
|
| 976 | 976 | } |
| 977 | 977 | |
| 978 | 978 | // SET SOME FIELD DEFAULTS TO PREVENT ISSUES |
@@ -996,7 +996,7 @@ discard block |
||
| 996 | 996 | // Prevent any PHP warnings, like undefined index |
| 997 | 997 | ob_start(); |
| 998 | 998 | |
| 999 | - if( $gv_field && is_callable( array( $gv_field, 'get_field_input' ) ) ) { |
|
| 999 | + if ( $gv_field && is_callable( array( $gv_field, 'get_field_input' ) ) ) { |
|
| 1000 | 1000 | /** @var GF_Field $gv_field */ |
| 1001 | 1001 | $return = $gv_field->get_field_input( $this->form, $field_value, $this->entry, $field ); |
| 1002 | 1002 | } else { |
@@ -1007,7 +1007,7 @@ discard block |
||
| 1007 | 1007 | // If there was output, it's an error |
| 1008 | 1008 | $warnings = ob_get_clean(); |
| 1009 | 1009 | |
| 1010 | - if( !empty( $warnings ) ) { |
|
| 1010 | + if ( ! empty( $warnings ) ) { |
|
| 1011 | 1011 | do_action( 'gravityview_log_error', __METHOD__ . $warnings, $field_value ); |
| 1012 | 1012 | } |
| 1013 | 1013 | |
@@ -1016,7 +1016,7 @@ discard block |
||
| 1016 | 1016 | * We need the fileupload html field to render with the proper id |
| 1017 | 1017 | * ( <li id="field_80_16" ... > ) |
| 1018 | 1018 | */ |
| 1019 | - unset( $_GET['page'] ); |
|
| 1019 | + unset( $_GET[ 'page' ] ); |
|
| 1020 | 1020 | |
| 1021 | 1021 | return $return; |
| 1022 | 1022 | } |
@@ -1039,7 +1039,7 @@ discard block |
||
| 1039 | 1039 | $override_saved_value = apply_filters( 'gravityview/edit_entry/pre_populate/override', false, $field ); |
| 1040 | 1040 | |
| 1041 | 1041 | // We're dealing with multiple inputs (e.g. checkbox) but not time or date (as it doesn't store data in input IDs) |
| 1042 | - if( isset( $field->inputs ) && is_array( $field->inputs ) && !in_array( $field->type, array( 'time', 'date' ) ) ) { |
|
| 1042 | + if ( isset( $field->inputs ) && is_array( $field->inputs ) && ! in_array( $field->type, array( 'time', 'date' ) ) ) { |
|
| 1043 | 1043 | |
| 1044 | 1044 | $field_value = array(); |
| 1045 | 1045 | |
@@ -1048,10 +1048,10 @@ discard block |
||
| 1048 | 1048 | |
| 1049 | 1049 | foreach ( (array)$field->inputs as $input ) { |
| 1050 | 1050 | |
| 1051 | - $input_id = strval( $input['id'] ); |
|
| 1051 | + $input_id = strval( $input[ 'id' ] ); |
|
| 1052 | 1052 | |
| 1053 | 1053 | if ( isset( $this->entry[ $input_id ] ) && ! gv_empty( $this->entry[ $input_id ], false, false ) ) { |
| 1054 | - $field_value[ $input_id ] = 'post_category' === $field->type ? GFCommon::format_post_category( $this->entry[ $input_id ], true ) : $this->entry[ $input_id ]; |
|
| 1054 | + $field_value[ $input_id ] = 'post_category' === $field->type ? GFCommon::format_post_category( $this->entry[ $input_id ], true ) : $this->entry[ $input_id ]; |
|
| 1055 | 1055 | $allow_pre_populated = false; |
| 1056 | 1056 | } |
| 1057 | 1057 | |
@@ -1059,7 +1059,7 @@ discard block |
||
| 1059 | 1059 | |
| 1060 | 1060 | $pre_value = $field->get_value_submission( array(), false ); |
| 1061 | 1061 | |
| 1062 | - $field_value = ! $allow_pre_populated && ! ( $override_saved_value && !gv_empty( $pre_value, false, false ) ) ? $field_value : $pre_value; |
|
| 1062 | + $field_value = ! $allow_pre_populated && ! ( $override_saved_value && ! gv_empty( $pre_value, false, false ) ) ? $field_value : $pre_value; |
|
| 1063 | 1063 | |
| 1064 | 1064 | } else { |
| 1065 | 1065 | |
@@ -1070,13 +1070,13 @@ discard block |
||
| 1070 | 1070 | |
| 1071 | 1071 | // saved field entry value (if empty, fallback to the pre-populated value, if exists) |
| 1072 | 1072 | // or pre-populated value if not empty and set to override saved value |
| 1073 | - $field_value = !gv_empty( $this->entry[ $id ], false, false ) && ! ( $override_saved_value && !gv_empty( $pre_value, false, false ) ) ? $this->entry[ $id ] : $pre_value; |
|
| 1073 | + $field_value = ! gv_empty( $this->entry[ $id ], false, false ) && ! ( $override_saved_value && ! gv_empty( $pre_value, false, false ) ) ? $this->entry[ $id ] : $pre_value; |
|
| 1074 | 1074 | |
| 1075 | 1075 | // in case field is post_category but inputType is select, multi-select or radio, convert value into array of category IDs. |
| 1076 | - if ( 'post_category' === $field->type && !gv_empty( $field_value, false, false ) ) { |
|
| 1076 | + if ( 'post_category' === $field->type && ! gv_empty( $field_value, false, false ) ) { |
|
| 1077 | 1077 | $categories = array(); |
| 1078 | 1078 | foreach ( explode( ',', $field_value ) as $cat_string ) { |
| 1079 | - $categories[] = GFCommon::format_post_category( $cat_string, true ); |
|
| 1079 | + $categories[ ] = GFCommon::format_post_category( $cat_string, true ); |
|
| 1080 | 1080 | } |
| 1081 | 1081 | $field_value = 'multiselect' === $field->get_input_type() ? $categories : implode( '', $categories ); |
| 1082 | 1082 | } |
@@ -1101,12 +1101,12 @@ discard block |
||
| 1101 | 1101 | */ |
| 1102 | 1102 | function gform_pre_validation( $form ) { |
| 1103 | 1103 | |
| 1104 | - if( ! $this->verify_nonce() ) { |
|
| 1104 | + if ( ! $this->verify_nonce() ) { |
|
| 1105 | 1105 | return $form; |
| 1106 | 1106 | } |
| 1107 | 1107 | |
| 1108 | 1108 | // Fix PHP warning regarding undefined index. |
| 1109 | - foreach ( $form['fields'] as &$field) { |
|
| 1109 | + foreach ( $form[ 'fields' ] as &$field ) { |
|
| 1110 | 1110 | |
| 1111 | 1111 | // This is because we're doing admin form pretending to be front-end, so Gravity Forms |
| 1112 | 1112 | // expects certain field array items to be set. |
@@ -1119,7 +1119,7 @@ discard block |
||
| 1119 | 1119 | $field['emailConfirmEnabled'] = ''; |
| 1120 | 1120 | }*/ |
| 1121 | 1121 | |
| 1122 | - switch( RGFormsModel::get_input_type( $field ) ) { |
|
| 1122 | + switch ( RGFormsModel::get_input_type( $field ) ) { |
|
| 1123 | 1123 | |
| 1124 | 1124 | /** |
| 1125 | 1125 | * this whole fileupload hack is because in the admin, Gravity Forms simply doesn't update any fileupload field if it's empty, but it DOES in the frontend. |
@@ -1133,37 +1133,37 @@ discard block |
||
| 1133 | 1133 | // Set the previous value |
| 1134 | 1134 | $entry = $this->get_entry(); |
| 1135 | 1135 | |
| 1136 | - $input_name = 'input_'.$field->id; |
|
| 1137 | - $form_id = $form['id']; |
|
| 1136 | + $input_name = 'input_' . $field->id; |
|
| 1137 | + $form_id = $form[ 'id' ]; |
|
| 1138 | 1138 | |
| 1139 | 1139 | $value = NULL; |
| 1140 | 1140 | |
| 1141 | 1141 | // Use the previous entry value as the default. |
| 1142 | - if( isset( $entry[ $field->id ] ) ) { |
|
| 1142 | + if ( isset( $entry[ $field->id ] ) ) { |
|
| 1143 | 1143 | $value = $entry[ $field->id ]; |
| 1144 | 1144 | } |
| 1145 | 1145 | |
| 1146 | 1146 | // If this is a single upload file |
| 1147 | - if( !empty( $_FILES[ $input_name ] ) && !empty( $_FILES[ $input_name ]['name'] ) ) { |
|
| 1148 | - $file_path = GFFormsModel::get_file_upload_path( $form['id'], $_FILES[ $input_name ]['name'] ); |
|
| 1149 | - $value = $file_path['url']; |
|
| 1147 | + if ( ! empty( $_FILES[ $input_name ] ) && ! empty( $_FILES[ $input_name ][ 'name' ] ) ) { |
|
| 1148 | + $file_path = GFFormsModel::get_file_upload_path( $form[ 'id' ], $_FILES[ $input_name ][ 'name' ] ); |
|
| 1149 | + $value = $file_path[ 'url' ]; |
|
| 1150 | 1150 | |
| 1151 | 1151 | } else { |
| 1152 | 1152 | |
| 1153 | 1153 | // Fix PHP warning on line 1498 of form_display.php for post_image fields |
| 1154 | 1154 | // Fix PHP Notice: Undefined index: size in form_display.php on line 1511 |
| 1155 | - $_FILES[ $input_name ] = array('name' => '', 'size' => '' ); |
|
| 1155 | + $_FILES[ $input_name ] = array( 'name' => '', 'size' => '' ); |
|
| 1156 | 1156 | |
| 1157 | 1157 | } |
| 1158 | 1158 | |
| 1159 | - if( rgar($field, "multipleFiles") ) { |
|
| 1159 | + if ( rgar( $field, "multipleFiles" ) ) { |
|
| 1160 | 1160 | |
| 1161 | 1161 | // If there are fresh uploads, process and merge them. |
| 1162 | 1162 | // Otherwise, use the passed values, which should be json-encoded array of URLs |
| 1163 | - if( isset( GFFormsModel::$uploaded_files[$form_id][$input_name] ) ) { |
|
| 1163 | + if ( isset( GFFormsModel::$uploaded_files[ $form_id ][ $input_name ] ) ) { |
|
| 1164 | 1164 | $value = empty( $value ) ? '[]' : $value; |
| 1165 | 1165 | $value = stripslashes_deep( $value ); |
| 1166 | - $value = GFFormsModel::prepare_value( $form, $field, $value, $input_name, $entry['id'], array()); |
|
| 1166 | + $value = GFFormsModel::prepare_value( $form, $field, $value, $input_name, $entry[ 'id' ], array() ); |
|
| 1167 | 1167 | } |
| 1168 | 1168 | |
| 1169 | 1169 | } else { |
@@ -1181,14 +1181,14 @@ discard block |
||
| 1181 | 1181 | |
| 1182 | 1182 | case 'number': |
| 1183 | 1183 | // Fix "undefined index" issue at line 1286 in form_display.php |
| 1184 | - if( !isset( $_POST['input_'.$field->id ] ) ) { |
|
| 1185 | - $_POST['input_'.$field->id ] = NULL; |
|
| 1184 | + if ( ! isset( $_POST[ 'input_' . $field->id ] ) ) { |
|
| 1185 | + $_POST[ 'input_' . $field->id ] = NULL; |
|
| 1186 | 1186 | } |
| 1187 | 1187 | break; |
| 1188 | 1188 | case 'captcha': |
| 1189 | 1189 | // Fix issue with recaptcha_check_answer() on line 1458 in form_display.php |
| 1190 | - $_POST['recaptcha_challenge_field'] = NULL; |
|
| 1191 | - $_POST['recaptcha_response_field'] = NULL; |
|
| 1190 | + $_POST[ 'recaptcha_challenge_field' ] = NULL; |
|
| 1191 | + $_POST[ 'recaptcha_response_field' ] = NULL; |
|
| 1192 | 1192 | break; |
| 1193 | 1193 | } |
| 1194 | 1194 | |
@@ -1224,7 +1224,7 @@ discard block |
||
| 1224 | 1224 | * You can enter whatever you want! |
| 1225 | 1225 | * We try validating, and customize the results using `self::custom_validation()` |
| 1226 | 1226 | */ |
| 1227 | - add_filter( 'gform_validation_'. $this->form_id, array( $this, 'custom_validation' ), 10, 4); |
|
| 1227 | + add_filter( 'gform_validation_' . $this->form_id, array( $this, 'custom_validation' ), 10, 4 ); |
|
| 1228 | 1228 | |
| 1229 | 1229 | // Needed by the validate funtion |
| 1230 | 1230 | $failed_validation_page = NULL; |
@@ -1232,14 +1232,14 @@ discard block |
||
| 1232 | 1232 | |
| 1233 | 1233 | // Prevent entry limit from running when editing an entry, also |
| 1234 | 1234 | // prevent form scheduling from preventing editing |
| 1235 | - unset( $this->form['limitEntries'], $this->form['scheduleForm'] ); |
|
| 1235 | + unset( $this->form[ 'limitEntries' ], $this->form[ 'scheduleForm' ] ); |
|
| 1236 | 1236 | |
| 1237 | 1237 | // Hide fields depending on Edit Entry settings |
| 1238 | - $this->form['fields'] = $this->get_configured_edit_fields( $this->form, $this->view_id ); |
|
| 1238 | + $this->form[ 'fields' ] = $this->get_configured_edit_fields( $this->form, $this->view_id ); |
|
| 1239 | 1239 | |
| 1240 | 1240 | $this->is_valid = GFFormDisplay::validate( $this->form, $field_values, 1, $failed_validation_page ); |
| 1241 | 1241 | |
| 1242 | - remove_filter( 'gform_validation_'. $this->form_id, array( $this, 'custom_validation' ), 10 ); |
|
| 1242 | + remove_filter( 'gform_validation_' . $this->form_id, array( $this, 'custom_validation' ), 10 ); |
|
| 1243 | 1243 | } |
| 1244 | 1244 | |
| 1245 | 1245 | |
@@ -1256,13 +1256,13 @@ discard block |
||
| 1256 | 1256 | */ |
| 1257 | 1257 | function custom_validation( $validation_results ) { |
| 1258 | 1258 | |
| 1259 | - do_action('gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] Validation results: ', $validation_results ); |
|
| 1259 | + do_action( 'gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] Validation results: ', $validation_results ); |
|
| 1260 | 1260 | |
| 1261 | - do_action('gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] $_POSTed data (sanitized): ', esc_html( print_r( $_POST, true ) ) ); |
|
| 1261 | + do_action( 'gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] $_POSTed data (sanitized): ', esc_html( print_r( $_POST, true ) ) ); |
|
| 1262 | 1262 | |
| 1263 | 1263 | $gv_valid = true; |
| 1264 | 1264 | |
| 1265 | - foreach ( $validation_results['form']['fields'] as $key => &$field ) { |
|
| 1265 | + foreach ( $validation_results[ 'form' ][ 'fields' ] as $key => &$field ) { |
|
| 1266 | 1266 | |
| 1267 | 1267 | $value = RGFormsModel::get_field_value( $field ); |
| 1268 | 1268 | $field_type = RGFormsModel::get_input_type( $field ); |
@@ -1275,35 +1275,35 @@ discard block |
||
| 1275 | 1275 | case 'post_image': |
| 1276 | 1276 | |
| 1277 | 1277 | // in case nothing is uploaded but there are already files saved |
| 1278 | - if( !empty( $field->failed_validation ) && !empty( $field->isRequired ) && !empty( $value ) ) { |
|
| 1278 | + if ( ! empty( $field->failed_validation ) && ! empty( $field->isRequired ) && ! empty( $value ) ) { |
|
| 1279 | 1279 | $field->failed_validation = false; |
| 1280 | 1280 | unset( $field->validation_message ); |
| 1281 | 1281 | } |
| 1282 | 1282 | |
| 1283 | 1283 | // validate if multi file upload reached max number of files [maxFiles] => 2 |
| 1284 | - if( rgobj( $field, 'maxFiles') && rgobj( $field, 'multipleFiles') ) { |
|
| 1284 | + if ( rgobj( $field, 'maxFiles' ) && rgobj( $field, 'multipleFiles' ) ) { |
|
| 1285 | 1285 | |
| 1286 | 1286 | $input_name = 'input_' . $field->id; |
| 1287 | 1287 | //uploaded |
| 1288 | - $file_names = isset( GFFormsModel::$uploaded_files[ $validation_results['form']['id'] ][ $input_name ] ) ? GFFormsModel::$uploaded_files[ $validation_results['form']['id'] ][ $input_name ] : array(); |
|
| 1288 | + $file_names = isset( GFFormsModel::$uploaded_files[ $validation_results[ 'form' ][ 'id' ] ][ $input_name ] ) ? GFFormsModel::$uploaded_files[ $validation_results[ 'form' ][ 'id' ] ][ $input_name ] : array(); |
|
| 1289 | 1289 | |
| 1290 | 1290 | //existent |
| 1291 | 1291 | $entry = $this->get_entry(); |
| 1292 | 1292 | $value = NULL; |
| 1293 | - if( isset( $entry[ $field->id ] ) ) { |
|
| 1293 | + if ( isset( $entry[ $field->id ] ) ) { |
|
| 1294 | 1294 | $value = json_decode( $entry[ $field->id ], true ); |
| 1295 | 1295 | } |
| 1296 | 1296 | |
| 1297 | 1297 | // count uploaded files and existent entry files |
| 1298 | 1298 | $count_files = count( $file_names ) + count( $value ); |
| 1299 | 1299 | |
| 1300 | - if( $count_files > $field->maxFiles ) { |
|
| 1300 | + if ( $count_files > $field->maxFiles ) { |
|
| 1301 | 1301 | $field->validation_message = __( 'Maximum number of files reached', 'gravityview' ); |
| 1302 | 1302 | $field->failed_validation = 1; |
| 1303 | 1303 | $gv_valid = false; |
| 1304 | 1304 | |
| 1305 | 1305 | // in case of error make sure the newest upload files are removed from the upload input |
| 1306 | - GFFormsModel::$uploaded_files[ $validation_results['form']['id'] ] = null; |
|
| 1306 | + GFFormsModel::$uploaded_files[ $validation_results[ 'form' ][ 'id' ] ] = null; |
|
| 1307 | 1307 | } |
| 1308 | 1308 | |
| 1309 | 1309 | } |
@@ -1314,7 +1314,7 @@ discard block |
||
| 1314 | 1314 | } |
| 1315 | 1315 | |
| 1316 | 1316 | // This field has failed validation. |
| 1317 | - if( !empty( $field->failed_validation ) ) { |
|
| 1317 | + if ( ! empty( $field->failed_validation ) ) { |
|
| 1318 | 1318 | |
| 1319 | 1319 | do_action( 'gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] Field is invalid.', array( 'field' => $field, 'value' => $value ) ); |
| 1320 | 1320 | |
@@ -1332,32 +1332,32 @@ discard block |
||
| 1332 | 1332 | } |
| 1333 | 1333 | |
| 1334 | 1334 | // You can't continue inside a switch, so we do it after. |
| 1335 | - if( empty( $field->failed_validation ) ) { |
|
| 1335 | + if ( empty( $field->failed_validation ) ) { |
|
| 1336 | 1336 | continue; |
| 1337 | 1337 | } |
| 1338 | 1338 | |
| 1339 | 1339 | // checks if the No Duplicates option is not validating entry against itself, since |
| 1340 | 1340 | // we're editing a stored entry, it would also assume it's a duplicate. |
| 1341 | - if( !empty( $field->noDuplicates ) ) { |
|
| 1341 | + if ( ! empty( $field->noDuplicates ) ) { |
|
| 1342 | 1342 | |
| 1343 | 1343 | $entry = $this->get_entry(); |
| 1344 | 1344 | |
| 1345 | 1345 | // If the value of the entry is the same as the stored value |
| 1346 | 1346 | // Then we can assume it's not a duplicate, it's the same. |
| 1347 | - if( !empty( $entry ) && $value == $entry[ $field->id ] ) { |
|
| 1347 | + if ( ! empty( $entry ) && $value == $entry[ $field->id ] ) { |
|
| 1348 | 1348 | //if value submitted was not changed, then don't validate |
| 1349 | 1349 | $field->failed_validation = false; |
| 1350 | 1350 | |
| 1351 | 1351 | unset( $field->validation_message ); |
| 1352 | 1352 | |
| 1353 | - do_action('gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] Field not a duplicate; it is the same entry.', $entry ); |
|
| 1353 | + do_action( 'gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] Field not a duplicate; it is the same entry.', $entry ); |
|
| 1354 | 1354 | |
| 1355 | 1355 | continue; |
| 1356 | 1356 | } |
| 1357 | 1357 | } |
| 1358 | 1358 | |
| 1359 | 1359 | // if here then probably we are facing the validation 'At least one field must be filled out' |
| 1360 | - if( GFFormDisplay::is_empty( $field, $this->form_id ) && empty( $field->isRequired ) ) { |
|
| 1360 | + if ( GFFormDisplay::is_empty( $field, $this->form_id ) && empty( $field->isRequired ) ) { |
|
| 1361 | 1361 | unset( $field->validation_message ); |
| 1362 | 1362 | $field->validation_message = false; |
| 1363 | 1363 | continue; |
@@ -1369,12 +1369,12 @@ discard block |
||
| 1369 | 1369 | |
| 1370 | 1370 | } |
| 1371 | 1371 | |
| 1372 | - $validation_results['is_valid'] = $gv_valid; |
|
| 1372 | + $validation_results[ 'is_valid' ] = $gv_valid; |
|
| 1373 | 1373 | |
| 1374 | - do_action('gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] Validation results.', $validation_results ); |
|
| 1374 | + do_action( 'gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] Validation results.', $validation_results ); |
|
| 1375 | 1375 | |
| 1376 | 1376 | // We'll need this result when rendering the form ( on GFFormDisplay::get_form ) |
| 1377 | - $this->form_after_validation = $validation_results['form']; |
|
| 1377 | + $this->form_after_validation = $validation_results[ 'form' ]; |
|
| 1378 | 1378 | |
| 1379 | 1379 | return $validation_results; |
| 1380 | 1380 | } |
@@ -1387,7 +1387,7 @@ discard block |
||
| 1387 | 1387 | */ |
| 1388 | 1388 | private function get_entry() { |
| 1389 | 1389 | |
| 1390 | - if( empty( $this->entry ) ) { |
|
| 1390 | + if ( empty( $this->entry ) ) { |
|
| 1391 | 1391 | // Get the database value of the entry that's being edited |
| 1392 | 1392 | $this->entry = gravityview_get_entry( GravityView_frontend::is_single_entry() ); |
| 1393 | 1393 | } |
@@ -1414,7 +1414,7 @@ discard block |
||
| 1414 | 1414 | $properties = GravityView_View_Data::getInstance()->get_fields( $view_id ); |
| 1415 | 1415 | |
| 1416 | 1416 | // If edit tab not yet configured, show all fields |
| 1417 | - $edit_fields = !empty( $properties['edit_edit-fields'] ) ? $properties['edit_edit-fields'] : NULL; |
|
| 1417 | + $edit_fields = ! empty( $properties[ 'edit_edit-fields' ] ) ? $properties[ 'edit_edit-fields' ] : NULL; |
|
| 1418 | 1418 | |
| 1419 | 1419 | // Show hidden fields as text fields |
| 1420 | 1420 | $form = $this->fix_hidden_fields( $form ); |
@@ -1423,7 +1423,7 @@ discard block |
||
| 1423 | 1423 | $form = $this->fix_survey_fields( $form ); |
| 1424 | 1424 | |
| 1425 | 1425 | // Hide fields depending on admin settings |
| 1426 | - $fields = $this->filter_fields( $form['fields'], $edit_fields ); |
|
| 1426 | + $fields = $this->filter_fields( $form[ 'fields' ], $edit_fields ); |
|
| 1427 | 1427 | |
| 1428 | 1428 | // If Edit Entry fields are configured, remove adminOnly field settings. Otherwise, don't. |
| 1429 | 1429 | $fields = $this->filter_admin_only_fields( $fields, $edit_fields, $form, $view_id ); |
@@ -1443,7 +1443,7 @@ discard block |
||
| 1443 | 1443 | private function fix_survey_fields( $form ) { |
| 1444 | 1444 | |
| 1445 | 1445 | /** @var GF_Field $field */ |
| 1446 | - foreach( $form['fields'] as &$field ) { |
|
| 1446 | + foreach ( $form[ 'fields' ] as &$field ) { |
|
| 1447 | 1447 | $field->allowsPrepopulate = true; |
| 1448 | 1448 | } |
| 1449 | 1449 | |
@@ -1460,11 +1460,11 @@ discard block |
||
| 1460 | 1460 | private function fix_hidden_fields( $form ) { |
| 1461 | 1461 | |
| 1462 | 1462 | /** @var GF_Field $field */ |
| 1463 | - foreach( $form['fields'] as $key => $field ) { |
|
| 1464 | - if( 'hidden' === $field->type ) { |
|
| 1463 | + foreach ( $form[ 'fields' ] as $key => $field ) { |
|
| 1464 | + if ( 'hidden' === $field->type ) { |
|
| 1465 | 1465 | $text_field = new GF_Field_Text( $field ); |
| 1466 | 1466 | $text_field->type = 'text'; |
| 1467 | - $form['fields'][ $key ] = $text_field; |
|
| 1467 | + $form[ 'fields' ][ $key ] = $text_field; |
|
| 1468 | 1468 | } |
| 1469 | 1469 | } |
| 1470 | 1470 | |
@@ -1485,7 +1485,7 @@ discard block |
||
| 1485 | 1485 | */ |
| 1486 | 1486 | private function filter_fields( $fields, $configured_fields ) { |
| 1487 | 1487 | |
| 1488 | - if( empty( $fields ) || !is_array( $fields ) ) { |
|
| 1488 | + if ( empty( $fields ) || ! is_array( $fields ) ) { |
|
| 1489 | 1489 | return $fields; |
| 1490 | 1490 | } |
| 1491 | 1491 | |
@@ -1502,13 +1502,13 @@ discard block |
||
| 1502 | 1502 | */ |
| 1503 | 1503 | $hide_product_fields = apply_filters( 'gravityview/edit_entry/hide-product-fields', empty( self::$supports_product_fields ) ); |
| 1504 | 1504 | |
| 1505 | - if( $hide_product_fields ) { |
|
| 1506 | - $field_type_blacklist[] = 'option'; |
|
| 1507 | - $field_type_blacklist[] = 'quantity'; |
|
| 1508 | - $field_type_blacklist[] = 'product'; |
|
| 1509 | - $field_type_blacklist[] = 'total'; |
|
| 1510 | - $field_type_blacklist[] = 'shipping'; |
|
| 1511 | - $field_type_blacklist[] = 'calculation'; |
|
| 1505 | + if ( $hide_product_fields ) { |
|
| 1506 | + $field_type_blacklist[ ] = 'option'; |
|
| 1507 | + $field_type_blacklist[ ] = 'quantity'; |
|
| 1508 | + $field_type_blacklist[ ] = 'product'; |
|
| 1509 | + $field_type_blacklist[ ] = 'total'; |
|
| 1510 | + $field_type_blacklist[ ] = 'shipping'; |
|
| 1511 | + $field_type_blacklist[ ] = 'calculation'; |
|
| 1512 | 1512 | } |
| 1513 | 1513 | |
| 1514 | 1514 | // First, remove blacklist or calculation fields |
@@ -1516,24 +1516,24 @@ discard block |
||
| 1516 | 1516 | |
| 1517 | 1517 | // Remove the fields that have calculation properties and keep them to be used later |
| 1518 | 1518 | // @since 1.16.2 |
| 1519 | - if( $field->has_calculation() ) { |
|
| 1520 | - $this->fields_with_calculation[] = $field; |
|
| 1519 | + if ( $field->has_calculation() ) { |
|
| 1520 | + $this->fields_with_calculation[ ] = $field; |
|
| 1521 | 1521 | // don't remove the calculation fields on form render. |
| 1522 | 1522 | } |
| 1523 | 1523 | |
| 1524 | 1524 | // process total field after all fields have been saved |
| 1525 | 1525 | if ( $field->type == 'total' ) { |
| 1526 | - $this->total_fields[] = $field; |
|
| 1526 | + $this->total_fields[ ] = $field; |
|
| 1527 | 1527 | unset( $fields[ $key ] ); |
| 1528 | 1528 | } |
| 1529 | 1529 | |
| 1530 | - if( in_array( $field->type, $field_type_blacklist ) ) { |
|
| 1530 | + if ( in_array( $field->type, $field_type_blacklist ) ) { |
|
| 1531 | 1531 | unset( $fields[ $key ] ); |
| 1532 | 1532 | } |
| 1533 | 1533 | } |
| 1534 | 1534 | |
| 1535 | 1535 | // The Edit tab has not been configured, so we return all fields by default. |
| 1536 | - if( empty( $configured_fields ) ) { |
|
| 1536 | + if ( empty( $configured_fields ) ) { |
|
| 1537 | 1537 | return $fields; |
| 1538 | 1538 | } |
| 1539 | 1539 | |
@@ -1543,8 +1543,8 @@ discard block |
||
| 1543 | 1543 | /** @var GF_Field $field */ |
| 1544 | 1544 | foreach ( $fields as $field ) { |
| 1545 | 1545 | |
| 1546 | - if( intval( $configured_field['id'] ) === intval( $field->id ) && $this->user_can_edit_field( $configured_field, false ) ) { |
|
| 1547 | - $edit_fields[] = $this->merge_field_properties( $field, $configured_field ); |
|
| 1546 | + if ( intval( $configured_field[ 'id' ] ) === intval( $field->id ) && $this->user_can_edit_field( $configured_field, false ) ) { |
|
| 1547 | + $edit_fields[ ] = $this->merge_field_properties( $field, $configured_field ); |
|
| 1548 | 1548 | break; |
| 1549 | 1549 | } |
| 1550 | 1550 | |
@@ -1567,14 +1567,14 @@ discard block |
||
| 1567 | 1567 | |
| 1568 | 1568 | $return_field = $field; |
| 1569 | 1569 | |
| 1570 | - if( empty( $field_setting['show_label'] ) ) { |
|
| 1570 | + if ( empty( $field_setting[ 'show_label' ] ) ) { |
|
| 1571 | 1571 | $return_field->label = ''; |
| 1572 | - } elseif ( !empty( $field_setting['custom_label'] ) ) { |
|
| 1573 | - $return_field->label = $field_setting['custom_label']; |
|
| 1572 | + } elseif ( ! empty( $field_setting[ 'custom_label' ] ) ) { |
|
| 1573 | + $return_field->label = $field_setting[ 'custom_label' ]; |
|
| 1574 | 1574 | } |
| 1575 | 1575 | |
| 1576 | - if( !empty( $field_setting['custom_class'] ) ) { |
|
| 1577 | - $return_field->cssClass .= ' '. gravityview_sanitize_html_class( $field_setting['custom_class'] ); |
|
| 1576 | + if ( ! empty( $field_setting[ 'custom_class' ] ) ) { |
|
| 1577 | + $return_field->cssClass .= ' ' . gravityview_sanitize_html_class( $field_setting[ 'custom_class' ] ); |
|
| 1578 | 1578 | } |
| 1579 | 1579 | |
| 1580 | 1580 | /** |
@@ -1612,16 +1612,16 @@ discard block |
||
| 1612 | 1612 | */ |
| 1613 | 1613 | $use_gf_adminonly_setting = apply_filters( 'gravityview/edit_entry/use_gf_admin_only_setting', empty( $edit_fields ), $form, $view_id ); |
| 1614 | 1614 | |
| 1615 | - if( $use_gf_adminonly_setting && false === GVCommon::has_cap( 'gravityforms_edit_entries', $this->entry['id'] ) ) { |
|
| 1616 | - foreach( $fields as $k => $field ) { |
|
| 1617 | - if( $field->adminOnly ) { |
|
| 1615 | + if ( $use_gf_adminonly_setting && false === GVCommon::has_cap( 'gravityforms_edit_entries', $this->entry[ 'id' ] ) ) { |
|
| 1616 | + foreach ( $fields as $k => $field ) { |
|
| 1617 | + if ( $field->adminOnly ) { |
|
| 1618 | 1618 | unset( $fields[ $k ] ); |
| 1619 | 1619 | } |
| 1620 | 1620 | } |
| 1621 | 1621 | return $fields; |
| 1622 | 1622 | } |
| 1623 | 1623 | |
| 1624 | - foreach( $fields as &$field ) { |
|
| 1624 | + foreach ( $fields as &$field ) { |
|
| 1625 | 1625 | $field->adminOnly = false; |
| 1626 | 1626 | } |
| 1627 | 1627 | |
@@ -1648,16 +1648,16 @@ discard block |
||
| 1648 | 1648 | */ |
| 1649 | 1649 | $use_conditional_logic = apply_filters( 'gravityview/edit_entry/conditional_logic', true, $form ); |
| 1650 | 1650 | |
| 1651 | - if( $use_conditional_logic ) { |
|
| 1651 | + if ( $use_conditional_logic ) { |
|
| 1652 | 1652 | return $form; |
| 1653 | 1653 | } |
| 1654 | 1654 | |
| 1655 | - foreach( $form['fields'] as &$field ) { |
|
| 1655 | + foreach ( $form[ 'fields' ] as &$field ) { |
|
| 1656 | 1656 | /* @var GF_Field $field */ |
| 1657 | 1657 | $field->conditionalLogic = null; |
| 1658 | 1658 | } |
| 1659 | 1659 | |
| 1660 | - unset( $form['button']['conditionalLogic'] ); |
|
| 1660 | + unset( $form[ 'button' ][ 'conditionalLogic' ] ); |
|
| 1661 | 1661 | |
| 1662 | 1662 | return $form; |
| 1663 | 1663 | |
@@ -1674,7 +1674,7 @@ discard block |
||
| 1674 | 1674 | */ |
| 1675 | 1675 | function manage_conditional_logic( $has_conditional_logic, $form ) { |
| 1676 | 1676 | |
| 1677 | - if( ! $this->is_edit_entry() ) { |
|
| 1677 | + if ( ! $this->is_edit_entry() ) { |
|
| 1678 | 1678 | return $has_conditional_logic; |
| 1679 | 1679 | } |
| 1680 | 1680 | |
@@ -1705,44 +1705,44 @@ discard block |
||
| 1705 | 1705 | * 2. There are two entries embedded using oEmbed |
| 1706 | 1706 | * 3. One of the entries has just been saved |
| 1707 | 1707 | */ |
| 1708 | - if( !empty( $_POST['lid'] ) && !empty( $_GET['entry'] ) && ( $_POST['lid'] !== $_GET['entry'] ) ) { |
|
| 1708 | + if ( ! empty( $_POST[ 'lid' ] ) && ! empty( $_GET[ 'entry' ] ) && ( $_POST[ 'lid' ] !== $_GET[ 'entry' ] ) ) { |
|
| 1709 | 1709 | |
| 1710 | 1710 | $error = true; |
| 1711 | 1711 | |
| 1712 | 1712 | } |
| 1713 | 1713 | |
| 1714 | - if( !empty( $_GET['entry'] ) && (string)$this->entry['id'] !== $_GET['entry'] ) { |
|
| 1714 | + if ( ! empty( $_GET[ 'entry' ] ) && (string)$this->entry[ 'id' ] !== $_GET[ 'entry' ] ) { |
|
| 1715 | 1715 | |
| 1716 | 1716 | $error = true; |
| 1717 | 1717 | |
| 1718 | - } elseif( ! $this->verify_nonce() ) { |
|
| 1718 | + } elseif ( ! $this->verify_nonce() ) { |
|
| 1719 | 1719 | |
| 1720 | 1720 | /** |
| 1721 | 1721 | * If the Entry is embedded, there may be two entries on the same page. |
| 1722 | 1722 | * If that's the case, and one is being edited, the other should fail gracefully and not display an error. |
| 1723 | 1723 | */ |
| 1724 | - if( GravityView_oEmbed::getInstance()->get_entry_id() ) { |
|
| 1724 | + if ( GravityView_oEmbed::getInstance()->get_entry_id() ) { |
|
| 1725 | 1725 | $error = true; |
| 1726 | 1726 | } else { |
| 1727 | - $error = __( 'The link to edit this entry is not valid; it may have expired.', 'gravityview'); |
|
| 1727 | + $error = __( 'The link to edit this entry is not valid; it may have expired.', 'gravityview' ); |
|
| 1728 | 1728 | } |
| 1729 | 1729 | |
| 1730 | 1730 | } |
| 1731 | 1731 | |
| 1732 | - if( ! GravityView_Edit_Entry::check_user_cap_edit_entry( $this->entry ) ) { |
|
| 1733 | - $error = __( 'You do not have permission to edit this entry.', 'gravityview'); |
|
| 1732 | + if ( ! GravityView_Edit_Entry::check_user_cap_edit_entry( $this->entry ) ) { |
|
| 1733 | + $error = __( 'You do not have permission to edit this entry.', 'gravityview' ); |
|
| 1734 | 1734 | } |
| 1735 | 1735 | |
| 1736 | - if( $this->entry['status'] === 'trash' ) { |
|
| 1737 | - $error = __('You cannot edit the entry; it is in the trash.', 'gravityview' ); |
|
| 1736 | + if ( $this->entry[ 'status' ] === 'trash' ) { |
|
| 1737 | + $error = __( 'You cannot edit the entry; it is in the trash.', 'gravityview' ); |
|
| 1738 | 1738 | } |
| 1739 | 1739 | |
| 1740 | 1740 | // No errors; everything's fine here! |
| 1741 | - if( empty( $error ) ) { |
|
| 1741 | + if ( empty( $error ) ) { |
|
| 1742 | 1742 | return true; |
| 1743 | 1743 | } |
| 1744 | 1744 | |
| 1745 | - if( $echo && $error !== true ) { |
|
| 1745 | + if ( $echo && $error !== true ) { |
|
| 1746 | 1746 | |
| 1747 | 1747 | $error = esc_html( $error ); |
| 1748 | 1748 | |
@@ -1750,13 +1750,13 @@ discard block |
||
| 1750 | 1750 | * @since 1.9 |
| 1751 | 1751 | */ |
| 1752 | 1752 | if ( ! empty( $this->entry ) ) { |
| 1753 | - $error .= ' ' . gravityview_get_link( '#', _x('Go back.', 'Link shown when invalid Edit Entry link is clicked', 'gravityview' ), array( 'onclick' => "window.history.go(-1); return false;" ) ); |
|
| 1753 | + $error .= ' ' . gravityview_get_link( '#', _x( 'Go back.', 'Link shown when invalid Edit Entry link is clicked', 'gravityview' ), array( 'onclick' => "window.history.go(-1); return false;" ) ); |
|
| 1754 | 1754 | } |
| 1755 | 1755 | |
| 1756 | - echo GVCommon::generate_notice( wpautop( $error ), 'gv-error error'); |
|
| 1756 | + echo GVCommon::generate_notice( wpautop( $error ), 'gv-error error' ); |
|
| 1757 | 1757 | } |
| 1758 | 1758 | |
| 1759 | - do_action('gravityview_log_error', 'GravityView_Edit_Entry[user_can_edit_entry]' . $error ); |
|
| 1759 | + do_action( 'gravityview_log_error', 'GravityView_Edit_Entry[user_can_edit_entry]' . $error ); |
|
| 1760 | 1760 | |
| 1761 | 1761 | return false; |
| 1762 | 1762 | } |
@@ -1773,20 +1773,20 @@ discard block |
||
| 1773 | 1773 | |
| 1774 | 1774 | $error = NULL; |
| 1775 | 1775 | |
| 1776 | - if( ! $this->check_user_cap_edit_field( $field ) ) { |
|
| 1777 | - $error = __( 'You do not have permission to edit this field.', 'gravityview'); |
|
| 1776 | + if ( ! $this->check_user_cap_edit_field( $field ) ) { |
|
| 1777 | + $error = __( 'You do not have permission to edit this field.', 'gravityview' ); |
|
| 1778 | 1778 | } |
| 1779 | 1779 | |
| 1780 | 1780 | // No errors; everything's fine here! |
| 1781 | - if( empty( $error ) ) { |
|
| 1781 | + if ( empty( $error ) ) { |
|
| 1782 | 1782 | return true; |
| 1783 | 1783 | } |
| 1784 | 1784 | |
| 1785 | - if( $echo ) { |
|
| 1786 | - echo GVCommon::generate_notice( wpautop( esc_html( $error ) ), 'gv-error error'); |
|
| 1785 | + if ( $echo ) { |
|
| 1786 | + echo GVCommon::generate_notice( wpautop( esc_html( $error ) ), 'gv-error error' ); |
|
| 1787 | 1787 | } |
| 1788 | 1788 | |
| 1789 | - do_action('gravityview_log_error', 'GravityView_Edit_Entry[user_can_edit_field]' . $error ); |
|
| 1789 | + do_action( 'gravityview_log_error', 'GravityView_Edit_Entry[user_can_edit_field]' . $error ); |
|
| 1790 | 1790 | |
| 1791 | 1791 | return false; |
| 1792 | 1792 | |
@@ -1804,15 +1804,15 @@ discard block |
||
| 1804 | 1804 | private function check_user_cap_edit_field( $field ) { |
| 1805 | 1805 | |
| 1806 | 1806 | // If they can edit any entries (as defined in Gravity Forms), we're good. |
| 1807 | - if( GVCommon::has_cap( array( 'gravityforms_edit_entries', 'gravityview_edit_others_entries' ) ) ) { |
|
| 1807 | + if ( GVCommon::has_cap( array( 'gravityforms_edit_entries', 'gravityview_edit_others_entries' ) ) ) { |
|
| 1808 | 1808 | return true; |
| 1809 | 1809 | } |
| 1810 | 1810 | |
| 1811 | - $field_cap = isset( $field['allow_edit_cap'] ) ? $field['allow_edit_cap'] : false; |
|
| 1811 | + $field_cap = isset( $field[ 'allow_edit_cap' ] ) ? $field[ 'allow_edit_cap' ] : false; |
|
| 1812 | 1812 | |
| 1813 | 1813 | // If the field has custom editing capaibilities set, check those |
| 1814 | - if( $field_cap ) { |
|
| 1815 | - return GVCommon::has_cap( $field['allow_edit_cap'] ); |
|
| 1814 | + if ( $field_cap ) { |
|
| 1815 | + return GVCommon::has_cap( $field[ 'allow_edit_cap' ] ); |
|
| 1816 | 1816 | } |
| 1817 | 1817 | |
| 1818 | 1818 | return false; |
@@ -1826,17 +1826,17 @@ discard block |
||
| 1826 | 1826 | public function verify_nonce() { |
| 1827 | 1827 | |
| 1828 | 1828 | // Verify form submitted for editing single |
| 1829 | - if( $this->is_edit_entry_submission() ) { |
|
| 1829 | + if ( $this->is_edit_entry_submission() ) { |
|
| 1830 | 1830 | $valid = wp_verify_nonce( $_POST[ self::$nonce_field ], self::$nonce_field ); |
| 1831 | 1831 | } |
| 1832 | 1832 | |
| 1833 | 1833 | // Verify |
| 1834 | - else if( ! $this->is_edit_entry() ) { |
|
| 1834 | + else if ( ! $this->is_edit_entry() ) { |
|
| 1835 | 1835 | $valid = false; |
| 1836 | 1836 | } |
| 1837 | 1837 | |
| 1838 | 1838 | else { |
| 1839 | - $valid = wp_verify_nonce( $_GET['edit'], self::$nonce_key ); |
|
| 1839 | + $valid = wp_verify_nonce( $_GET[ 'edit' ], self::$nonce_key ); |
|
| 1840 | 1840 | } |
| 1841 | 1841 | |
| 1842 | 1842 | /** |
@@ -42,12 +42,12 @@ discard block |
||
| 42 | 42 | |
| 43 | 43 | add_action( 'wp', array( $this, 'process_delete' ), 10000 ); |
| 44 | 44 | |
| 45 | - add_filter( 'gravityview_entry_default_fields', array( $this, 'add_default_field'), 10, 3 ); |
|
| 45 | + add_filter( 'gravityview_entry_default_fields', array( $this, 'add_default_field' ), 10, 3 ); |
|
| 46 | 46 | |
| 47 | 47 | add_action( 'gravityview_before', array( $this, 'display_message' ) ); |
| 48 | 48 | |
| 49 | 49 | // For the Delete Entry Link, you don't want visible to all users. |
| 50 | - add_filter( 'gravityview_field_visibility_caps', array( $this, 'modify_visibility_caps'), 10, 5 ); |
|
| 50 | + add_filter( 'gravityview_field_visibility_caps', array( $this, 'modify_visibility_caps' ), 10, 5 ); |
|
| 51 | 51 | |
| 52 | 52 | // Modify the field options based on the name of the field type |
| 53 | 53 | add_filter( 'gravityview_template_delete_link_options', array( $this, 'delete_link_field_options' ), 10, 5 ); |
@@ -55,7 +55,7 @@ discard block |
||
| 55 | 55 | // add template path to check for field |
| 56 | 56 | add_filter( 'gravityview_template_paths', array( $this, 'add_template_path' ) ); |
| 57 | 57 | |
| 58 | - add_action( 'gravityview/edit-entry/publishing-action/after', array( $this, 'add_delete_button'), 10, 3 ); |
|
| 58 | + add_action( 'gravityview/edit-entry/publishing-action/after', array( $this, 'add_delete_button' ), 10, 3 ); |
|
| 59 | 59 | } |
| 60 | 60 | |
| 61 | 61 | /** |
@@ -66,7 +66,7 @@ discard block |
||
| 66 | 66 | */ |
| 67 | 67 | static function getInstance() { |
| 68 | 68 | |
| 69 | - if( empty( self::$instance ) ) { |
|
| 69 | + if ( empty( self::$instance ) ) { |
|
| 70 | 70 | self::$instance = new self; |
| 71 | 71 | } |
| 72 | 72 | |
@@ -102,20 +102,20 @@ discard block |
||
| 102 | 102 | function delete_link_field_options( $field_options, $template_id, $field_id, $context, $input_type ) { |
| 103 | 103 | |
| 104 | 104 | // Always a link, never a filter |
| 105 | - unset( $field_options['show_as_link'], $field_options['search_filter'] ); |
|
| 105 | + unset( $field_options[ 'show_as_link' ], $field_options[ 'search_filter' ] ); |
|
| 106 | 106 | |
| 107 | 107 | // Delete Entry link should only appear to visitors capable of editing entries |
| 108 | - unset( $field_options['only_loggedin'], $field_options['only_loggedin_cap'] ); |
|
| 108 | + unset( $field_options[ 'only_loggedin' ], $field_options[ 'only_loggedin_cap' ] ); |
|
| 109 | 109 | |
| 110 | - $add_option['delete_link'] = array( |
|
| 110 | + $add_option[ 'delete_link' ] = array( |
|
| 111 | 111 | 'type' => 'text', |
| 112 | 112 | 'label' => __( 'Delete Link Text', 'gravityview' ), |
| 113 | 113 | 'desc' => NULL, |
| 114 | - 'value' => __('Delete Entry', 'gravityview'), |
|
| 114 | + 'value' => __( 'Delete Entry', 'gravityview' ), |
|
| 115 | 115 | 'merge_tags' => true, |
| 116 | 116 | ); |
| 117 | 117 | |
| 118 | - $field_options['allow_edit_cap'] = array( |
|
| 118 | + $field_options[ 'allow_edit_cap' ] = array( |
|
| 119 | 119 | 'type' => 'select', |
| 120 | 120 | 'label' => __( 'Allow the following users to delete the entry:', 'gravityview' ), |
| 121 | 121 | 'choices' => GravityView_Render_Settings::get_cap_choices( $template_id, $field_id, $context, $input_type ), |
@@ -139,10 +139,10 @@ discard block |
||
| 139 | 139 | */ |
| 140 | 140 | function add_default_field( $entry_default_fields, $form = array(), $zone = '' ) { |
| 141 | 141 | |
| 142 | - $entry_default_fields['delete_link'] = array( |
|
| 143 | - 'label' => __('Delete Entry', 'gravityview'), |
|
| 142 | + $entry_default_fields[ 'delete_link' ] = array( |
|
| 143 | + 'label' => __( 'Delete Entry', 'gravityview' ), |
|
| 144 | 144 | 'type' => 'delete_link', |
| 145 | - 'desc' => __('A link to delete the entry. Respects the Delete Entry permissions.', 'gravityview'), |
|
| 145 | + 'desc' => __( 'A link to delete the entry. Respects the Delete Entry permissions.', 'gravityview' ), |
|
| 146 | 146 | ); |
| 147 | 147 | |
| 148 | 148 | return $entry_default_fields; |
@@ -155,7 +155,7 @@ discard block |
||
| 155 | 155 | */ |
| 156 | 156 | function add_available_field( $available_fields = array() ) { |
| 157 | 157 | |
| 158 | - $available_fields['delete_link'] = array( |
|
| 158 | + $available_fields[ 'delete_link' ] = array( |
|
| 159 | 159 | 'label_text' => __( 'Delete Entry', 'gravityview' ), |
| 160 | 160 | 'field_id' => 'delete_link', |
| 161 | 161 | 'label_type' => 'field', |
@@ -183,12 +183,12 @@ discard block |
||
| 183 | 183 | $caps = $visibility_caps; |
| 184 | 184 | |
| 185 | 185 | // If we're configuring fields in the edit context, we want a limited selection |
| 186 | - if( $field_id === 'delete_link' ) { |
|
| 186 | + if ( $field_id === 'delete_link' ) { |
|
| 187 | 187 | |
| 188 | 188 | // Remove other built-in caps. |
| 189 | - unset( $caps['publish_posts'], $caps['gravityforms_view_entries'], $caps['delete_others_posts'] ); |
|
| 189 | + unset( $caps[ 'publish_posts' ], $caps[ 'gravityforms_view_entries' ], $caps[ 'delete_others_posts' ] ); |
|
| 190 | 190 | |
| 191 | - $caps['read'] = _x('Entry Creator', 'User capability', 'gravityview'); |
|
| 191 | + $caps[ 'read' ] = _x( 'Entry Creator', 'User capability', 'gravityview' ); |
|
| 192 | 192 | } |
| 193 | 193 | |
| 194 | 194 | return $caps; |
@@ -201,7 +201,7 @@ discard block |
||
| 201 | 201 | * @param [type] $entry [description] |
| 202 | 202 | */ |
| 203 | 203 | function set_entry( $entry = null ) { |
| 204 | - $this->entry = empty( $entry ) ? GravityView_View::getInstance()->entries[0] : $entry; |
|
| 204 | + $this->entry = empty( $entry ) ? GravityView_View::getInstance()->entries[ 0 ] : $entry; |
|
| 205 | 205 | } |
| 206 | 206 | |
| 207 | 207 | /** |
@@ -231,13 +231,13 @@ discard block |
||
| 231 | 231 | |
| 232 | 232 | $base = GravityView_API::directory_link( $post_id, true ); |
| 233 | 233 | |
| 234 | - if( empty( $base ) ) { |
|
| 235 | - do_action( 'gravityview_log_error', __METHOD__ . ' - Post ID does not exist: '.$post_id ); |
|
| 234 | + if ( empty( $base ) ) { |
|
| 235 | + do_action( 'gravityview_log_error', __METHOD__ . ' - Post ID does not exist: ' . $post_id ); |
|
| 236 | 236 | return NULL; |
| 237 | 237 | } |
| 238 | 238 | |
| 239 | 239 | // Use the slug instead of the ID for consistent security |
| 240 | - $entry_slug = GravityView_API::get_entry_slug( $entry['id'], $entry ); |
|
| 240 | + $entry_slug = GravityView_API::get_entry_slug( $entry[ 'id' ], $entry ); |
|
| 241 | 241 | |
| 242 | 242 | $view_id = empty( $view_id ) ? gravityview_get_view_id() : $view_id; |
| 243 | 243 | |
@@ -248,7 +248,7 @@ discard block |
||
| 248 | 248 | 'view_id' => $view_id, |
| 249 | 249 | ), $base ); |
| 250 | 250 | |
| 251 | - $url = wp_nonce_url( $actionurl, 'delete_'.$entry_slug, 'delete' ); |
|
| 251 | + $url = wp_nonce_url( $actionurl, 'delete_' . $entry_slug, 'delete' ); |
|
| 252 | 252 | |
| 253 | 253 | return $url; |
| 254 | 254 | } |
@@ -265,7 +265,7 @@ discard block |
||
| 265 | 265 | function add_delete_button( $form = array(), $entry = array(), $view_id = NULL ) { |
| 266 | 266 | |
| 267 | 267 | // Only show the link to those who are allowed to see it. |
| 268 | - if( !self::check_user_cap_delete_entry( $entry ) ) { |
|
| 268 | + if ( ! self::check_user_cap_delete_entry( $entry ) ) { |
|
| 269 | 269 | return; |
| 270 | 270 | } |
| 271 | 271 | |
@@ -276,7 +276,7 @@ discard block |
||
| 276 | 276 | $show_delete_button = apply_filters( 'gravityview/delete-entry/show-delete-button', true ); |
| 277 | 277 | |
| 278 | 278 | // If the button is hidden by the filter, don't show. |
| 279 | - if( !$show_delete_button ) { |
|
| 279 | + if ( ! $show_delete_button ) { |
|
| 280 | 280 | return; |
| 281 | 281 | } |
| 282 | 282 | |
@@ -306,27 +306,27 @@ discard block |
||
| 306 | 306 | function process_delete() { |
| 307 | 307 | |
| 308 | 308 | // If the form is submitted |
| 309 | - if( isset( $_GET['action'] ) && 'delete' === $_GET['action'] && isset( $_GET['entry_id'] ) ) { |
|
| 309 | + if ( isset( $_GET[ 'action' ] ) && 'delete' === $_GET[ 'action' ] && isset( $_GET[ 'entry_id' ] ) ) { |
|
| 310 | 310 | |
| 311 | 311 | // Make sure it's a GravityView request |
| 312 | - $valid_nonce_key = wp_verify_nonce( $_GET['delete'], self::get_nonce_key( $_GET['entry_id'] ) ); |
|
| 312 | + $valid_nonce_key = wp_verify_nonce( $_GET[ 'delete' ], self::get_nonce_key( $_GET[ 'entry_id' ] ) ); |
|
| 313 | 313 | |
| 314 | - if( ! $valid_nonce_key ) { |
|
| 315 | - do_action('gravityview_log_debug', __METHOD__ . ' Delete entry not processed: nonce validation failed.' ); |
|
| 314 | + if ( ! $valid_nonce_key ) { |
|
| 315 | + do_action( 'gravityview_log_debug', __METHOD__ . ' Delete entry not processed: nonce validation failed.' ); |
|
| 316 | 316 | return; |
| 317 | 317 | } |
| 318 | 318 | |
| 319 | 319 | // Get the entry slug |
| 320 | - $entry_slug = esc_attr( $_GET['entry_id'] ); |
|
| 320 | + $entry_slug = esc_attr( $_GET[ 'entry_id' ] ); |
|
| 321 | 321 | |
| 322 | 322 | // See if there's an entry there |
| 323 | 323 | $entry = gravityview_get_entry( $entry_slug ); |
| 324 | 324 | |
| 325 | - if( $entry ) { |
|
| 325 | + if ( $entry ) { |
|
| 326 | 326 | |
| 327 | 327 | $has_permission = $this->user_can_delete_entry( $entry ); |
| 328 | 328 | |
| 329 | - if( is_wp_error( $has_permission ) ) { |
|
| 329 | + if ( is_wp_error( $has_permission ) ) { |
|
| 330 | 330 | |
| 331 | 331 | $messages = array( |
| 332 | 332 | 'message' => urlencode( $has_permission->get_error_message() ), |
@@ -336,9 +336,9 @@ discard block |
||
| 336 | 336 | } else { |
| 337 | 337 | |
| 338 | 338 | // Delete the entry |
| 339 | - $delete_response = $this->delete_or_trash_entry( $entry['id'] ); |
|
| 339 | + $delete_response = $this->delete_or_trash_entry( $entry[ 'id' ] ); |
|
| 340 | 340 | |
| 341 | - if( is_wp_error( $delete_response ) ) { |
|
| 341 | + if ( is_wp_error( $delete_response ) ) { |
|
| 342 | 342 | |
| 343 | 343 | $messages = array( |
| 344 | 344 | 'message' => urlencode( $delete_response->get_error_message() ), |
@@ -357,10 +357,10 @@ discard block |
||
| 357 | 357 | |
| 358 | 358 | } else { |
| 359 | 359 | |
| 360 | - do_action('gravityview_log_debug', __METHOD__ . ' Delete entry failed: there was no entry with the entry slug '. $entry_slug ); |
|
| 360 | + do_action( 'gravityview_log_debug', __METHOD__ . ' Delete entry failed: there was no entry with the entry slug ' . $entry_slug ); |
|
| 361 | 361 | |
| 362 | 362 | $messages = array( |
| 363 | - 'message' => urlencode( __('The entry does not exist.', 'gravityview') ), |
|
| 363 | + 'message' => urlencode( __( 'The entry does not exist.', 'gravityview' ) ), |
|
| 364 | 364 | 'status' => 'error', |
| 365 | 365 | ); |
| 366 | 366 | } |
@@ -402,14 +402,14 @@ discard block |
||
| 402 | 402 | |
| 403 | 403 | $mode = $this->get_delete_mode(); |
| 404 | 404 | |
| 405 | - if( 'delete' === $mode ) { |
|
| 405 | + if ( 'delete' === $mode ) { |
|
| 406 | 406 | |
| 407 | 407 | do_action( 'gravityview_log_debug', __METHOD__ . ' Starting delete entry: ', $entry_id ); |
| 408 | 408 | |
| 409 | 409 | // Delete the entry |
| 410 | 410 | $delete_response = GFAPI::delete_entry( $entry_id ); |
| 411 | 411 | |
| 412 | - if( ! is_wp_error( $delete_response ) ) { |
|
| 412 | + if ( ! is_wp_error( $delete_response ) ) { |
|
| 413 | 413 | $delete_response = 'deleted'; |
| 414 | 414 | |
| 415 | 415 | /** |
@@ -429,8 +429,8 @@ discard block |
||
| 429 | 429 | $trashed = GFAPI::update_entry_property( $entry_id, 'status', 'trash' ); |
| 430 | 430 | new GravityView_Cache; |
| 431 | 431 | |
| 432 | - if( ! $trashed ) { |
|
| 433 | - $delete_response = new WP_Error( 'trash_entry_failed', __('Moving the entry to the trash failed.', 'gravityview' ) ); |
|
| 432 | + if ( ! $trashed ) { |
|
| 433 | + $delete_response = new WP_Error( 'trash_entry_failed', __( 'Moving the entry to the trash failed.', 'gravityview' ) ); |
|
| 434 | 434 | } else { |
| 435 | 435 | |
| 436 | 436 | /** |
@@ -458,13 +458,13 @@ discard block |
||
| 458 | 458 | public function verify_nonce() { |
| 459 | 459 | |
| 460 | 460 | // No delete entry request was made |
| 461 | - if( empty( $_GET['entry_id'] ) || empty( $_GET['delete'] ) ) { |
|
| 461 | + if ( empty( $_GET[ 'entry_id' ] ) || empty( $_GET[ 'delete' ] ) ) { |
|
| 462 | 462 | return false; |
| 463 | 463 | } |
| 464 | 464 | |
| 465 | - $nonce_key = self::get_nonce_key( $_GET['entry_id'] ); |
|
| 465 | + $nonce_key = self::get_nonce_key( $_GET[ 'entry_id' ] ); |
|
| 466 | 466 | |
| 467 | - $valid = wp_verify_nonce( $_GET['delete'], $nonce_key ); |
|
| 467 | + $valid = wp_verify_nonce( $_GET[ 'delete' ], $nonce_key ); |
|
| 468 | 468 | |
| 469 | 469 | /** |
| 470 | 470 | * @filter `gravityview/delete-entry/verify_nonce` Override Delete Entry nonce validation. Return true to declare nonce valid. |
@@ -486,7 +486,7 @@ discard block |
||
| 486 | 486 | */ |
| 487 | 487 | public static function get_confirm_dialog() { |
| 488 | 488 | |
| 489 | - $confirm = __('Are you sure you want to delete this entry? This cannot be undone.', 'gravityview'); |
|
| 489 | + $confirm = __( 'Are you sure you want to delete this entry? This cannot be undone.', 'gravityview' ); |
|
| 490 | 490 | |
| 491 | 491 | /** |
| 492 | 492 | * @filter `gravityview/delete-entry/confirm-text` Modify the Delete Entry Javascript confirmation text |
@@ -494,7 +494,7 @@ discard block |
||
| 494 | 494 | */ |
| 495 | 495 | $confirm = apply_filters( 'gravityview/delete-entry/confirm-text', $confirm ); |
| 496 | 496 | |
| 497 | - return 'return window.confirm(\''. esc_js( $confirm ) .'\');'; |
|
| 497 | + return 'return window.confirm(\'' . esc_js( $confirm ) . '\');'; |
|
| 498 | 498 | } |
| 499 | 499 | |
| 500 | 500 | /** |
@@ -512,16 +512,16 @@ discard block |
||
| 512 | 512 | |
| 513 | 513 | $error = NULL; |
| 514 | 514 | |
| 515 | - if( ! $this->verify_nonce() ) { |
|
| 516 | - $error = __( 'The link to delete this entry is not valid; it may have expired.', 'gravityview'); |
|
| 515 | + if ( ! $this->verify_nonce() ) { |
|
| 516 | + $error = __( 'The link to delete this entry is not valid; it may have expired.', 'gravityview' ); |
|
| 517 | 517 | } |
| 518 | 518 | |
| 519 | - if( ! self::check_user_cap_delete_entry( $entry ) ) { |
|
| 520 | - $error = __( 'You do not have permission to delete this entry.', 'gravityview'); |
|
| 519 | + if ( ! self::check_user_cap_delete_entry( $entry ) ) { |
|
| 520 | + $error = __( 'You do not have permission to delete this entry.', 'gravityview' ); |
|
| 521 | 521 | } |
| 522 | 522 | |
| 523 | - if( $entry['status'] === 'trash' ) { |
|
| 524 | - if( 'trash' === $this->get_delete_mode() ) { |
|
| 523 | + if ( $entry[ 'status' ] === 'trash' ) { |
|
| 524 | + if ( 'trash' === $this->get_delete_mode() ) { |
|
| 525 | 525 | $error = __( 'The entry is already in the trash.', 'gravityview' ); |
| 526 | 526 | } else { |
| 527 | 527 | $error = __( 'You cannot delete the entry; it is already in the trash.', 'gravityview' ); |
@@ -529,11 +529,11 @@ discard block |
||
| 529 | 529 | } |
| 530 | 530 | |
| 531 | 531 | // No errors; everything's fine here! |
| 532 | - if( empty( $error ) ) { |
|
| 532 | + if ( empty( $error ) ) { |
|
| 533 | 533 | return true; |
| 534 | 534 | } |
| 535 | 535 | |
| 536 | - do_action('gravityview_log_error', 'GravityView_Delete_Entry[user_can_delete_entry]' . $error ); |
|
| 536 | + do_action( 'gravityview_log_error', 'GravityView_Delete_Entry[user_can_delete_entry]' . $error ); |
|
| 537 | 537 | |
| 538 | 538 | return new WP_Error( 'gravityview-delete-entry-permissions', $error ); |
| 539 | 539 | } |
@@ -555,32 +555,32 @@ discard block |
||
| 555 | 555 | |
| 556 | 556 | $current_user = wp_get_current_user(); |
| 557 | 557 | |
| 558 | - $entry_id = isset( $entry['id'] ) ? $entry['id'] : NULL; |
|
| 558 | + $entry_id = isset( $entry[ 'id' ] ) ? $entry[ 'id' ] : NULL; |
|
| 559 | 559 | |
| 560 | 560 | // Or if they can delete any entries (as defined in Gravity Forms), we're good. |
| 561 | - if( GVCommon::has_cap( array( 'gravityforms_delete_entries', 'gravityview_delete_others_entries' ), $entry_id ) ) { |
|
| 561 | + if ( GVCommon::has_cap( array( 'gravityforms_delete_entries', 'gravityview_delete_others_entries' ), $entry_id ) ) { |
|
| 562 | 562 | |
| 563 | - do_action('gravityview_log_debug', 'GravityView_Delete_Entry[check_user_cap_delete_entry] Current user has `gravityforms_delete_entries` or `gravityview_delete_others_entries` capability.' ); |
|
| 563 | + do_action( 'gravityview_log_debug', 'GravityView_Delete_Entry[check_user_cap_delete_entry] Current user has `gravityforms_delete_entries` or `gravityview_delete_others_entries` capability.' ); |
|
| 564 | 564 | |
| 565 | 565 | return true; |
| 566 | 566 | } |
| 567 | 567 | |
| 568 | 568 | |
| 569 | 569 | // If field options are passed, check if current user can view the link |
| 570 | - if( !empty( $field ) ) { |
|
| 570 | + if ( ! empty( $field ) ) { |
|
| 571 | 571 | |
| 572 | 572 | // If capability is not defined, something is not right! |
| 573 | - if( empty( $field['allow_edit_cap'] ) ) { |
|
| 573 | + if ( empty( $field[ 'allow_edit_cap' ] ) ) { |
|
| 574 | 574 | |
| 575 | 575 | do_action( 'gravityview_log_error', 'GravityView_Delete_Entry[check_user_cap_delete_entry] Cannot read delete entry field caps', $field ); |
| 576 | 576 | |
| 577 | 577 | return false; |
| 578 | 578 | } |
| 579 | 579 | |
| 580 | - if( GVCommon::has_cap( $field['allow_edit_cap'] ) ) { |
|
| 580 | + if ( GVCommon::has_cap( $field[ 'allow_edit_cap' ] ) ) { |
|
| 581 | 581 | |
| 582 | 582 | // Do not return true if cap is read, as we need to check if the current user created the entry |
| 583 | - if( $field['allow_edit_cap'] !== 'read' ) { |
|
| 583 | + if ( $field[ 'allow_edit_cap' ] !== 'read' ) { |
|
| 584 | 584 | return true; |
| 585 | 585 | } |
| 586 | 586 | |
@@ -593,9 +593,9 @@ discard block |
||
| 593 | 593 | |
| 594 | 594 | } |
| 595 | 595 | |
| 596 | - if( !isset( $entry['created_by'] ) ) { |
|
| 596 | + if ( ! isset( $entry[ 'created_by' ] ) ) { |
|
| 597 | 597 | |
| 598 | - do_action('gravityview_log_error', 'GravityView_Delete_Entry[check_user_cap_delete_entry] Entry `created_by` doesn\'t exist.'); |
|
| 598 | + do_action( 'gravityview_log_error', 'GravityView_Delete_Entry[check_user_cap_delete_entry] Entry `created_by` doesn\'t exist.' ); |
|
| 599 | 599 | |
| 600 | 600 | return false; |
| 601 | 601 | } |
@@ -603,24 +603,24 @@ discard block |
||
| 603 | 603 | $view_id = empty( $view_id ) ? $gravityview_view->getViewId() : $view_id; |
| 604 | 604 | |
| 605 | 605 | // Only checks user_delete view option if view is already set |
| 606 | - if( $view_id ) { |
|
| 606 | + if ( $view_id ) { |
|
| 607 | 607 | |
| 608 | 608 | $current_view = gravityview_get_current_view_data( $view_id ); |
| 609 | 609 | |
| 610 | - $user_delete = isset( $current_view['atts']['user_delete'] ) ? $current_view['atts']['user_delete'] : false; |
|
| 610 | + $user_delete = isset( $current_view[ 'atts' ][ 'user_delete' ] ) ? $current_view[ 'atts' ][ 'user_delete' ] : false; |
|
| 611 | 611 | |
| 612 | - if( empty( $user_delete ) ) { |
|
| 612 | + if ( empty( $user_delete ) ) { |
|
| 613 | 613 | |
| 614 | - do_action('gravityview_log_debug', 'GravityView_Delete_Entry[check_user_cap_delete_entry] User Delete is disabled. Returning false.' ); |
|
| 614 | + do_action( 'gravityview_log_debug', 'GravityView_Delete_Entry[check_user_cap_delete_entry] User Delete is disabled. Returning false.' ); |
|
| 615 | 615 | |
| 616 | 616 | return false; |
| 617 | 617 | } |
| 618 | 618 | } |
| 619 | 619 | |
| 620 | 620 | // If the logged-in user is the same as the user who created the entry, we're good. |
| 621 | - if( is_user_logged_in() && intval( $current_user->ID ) === intval( $entry['created_by'] ) ) { |
|
| 621 | + if ( is_user_logged_in() && intval( $current_user->ID ) === intval( $entry[ 'created_by' ] ) ) { |
|
| 622 | 622 | |
| 623 | - do_action('gravityview_log_debug', sprintf( 'GravityView_Delete_Entry[check_user_cap_delete_entry] User %s created the entry.', $current_user->ID ) ); |
|
| 623 | + do_action( 'gravityview_log_debug', sprintf( 'GravityView_Delete_Entry[check_user_cap_delete_entry] User %s created the entry.', $current_user->ID ) ); |
|
| 624 | 624 | |
| 625 | 625 | return true; |
| 626 | 626 | } |
@@ -643,31 +643,31 @@ discard block |
||
| 643 | 643 | */ |
| 644 | 644 | public function display_message( $current_view_id = 0 ) { |
| 645 | 645 | |
| 646 | - if( empty( $_GET['status'] ) || ! self::verify_nonce() ) { |
|
| 646 | + if ( empty( $_GET[ 'status' ] ) || ! self::verify_nonce() ) { |
|
| 647 | 647 | return; |
| 648 | 648 | } |
| 649 | 649 | |
| 650 | 650 | // Entry wasn't deleted from current View |
| 651 | - if( intval( $_GET['gvid'] ) !== intval( $current_view_id ) ) { |
|
| 651 | + if ( intval( $_GET[ 'gvid' ] ) !== intval( $current_view_id ) ) { |
|
| 652 | 652 | return; |
| 653 | 653 | } |
| 654 | 654 | |
| 655 | - $status = esc_attr( $_GET['status'] ); |
|
| 656 | - $message_from_url = rgget('message'); |
|
| 655 | + $status = esc_attr( $_GET[ 'status' ] ); |
|
| 656 | + $message_from_url = rgget( 'message' ); |
|
| 657 | 657 | $message_from_url = urldecode( stripslashes_deep( $message_from_url ) ); |
| 658 | 658 | $class = ''; |
| 659 | 659 | |
| 660 | 660 | switch ( $status ) { |
| 661 | 661 | case 'error': |
| 662 | 662 | $class = ' gv-error error'; |
| 663 | - $error_message = __('There was an error deleting the entry: %s', 'gravityview'); |
|
| 663 | + $error_message = __( 'There was an error deleting the entry: %s', 'gravityview' ); |
|
| 664 | 664 | $message = sprintf( $error_message, $message_from_url ); |
| 665 | 665 | break; |
| 666 | 666 | case 'trashed': |
| 667 | - $message = __('The entry was successfully moved to the trash.', 'gravityview'); |
|
| 667 | + $message = __( 'The entry was successfully moved to the trash.', 'gravityview' ); |
|
| 668 | 668 | break; |
| 669 | 669 | default: |
| 670 | - $message = __('The entry was successfully deleted.', 'gravityview'); |
|
| 670 | + $message = __( 'The entry was successfully deleted.', 'gravityview' ); |
|
| 671 | 671 | break; |
| 672 | 672 | } |
| 673 | 673 | |
@@ -681,7 +681,7 @@ discard block |
||
| 681 | 681 | $message = apply_filters( 'gravityview/delete-entry/message', esc_attr( $message ), $status, $message_from_url ); |
| 682 | 682 | |
| 683 | 683 | // DISPLAY ERROR/SUCCESS MESSAGE |
| 684 | - echo '<div class="gv-notice' . esc_attr( $class ) .'">'. $message .'</div>'; |
|
| 684 | + echo '<div class="gv-notice' . esc_attr( $class ) . '">' . $message . '</div>'; |
|
| 685 | 685 | } |
| 686 | 686 | |
| 687 | 687 | |